• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.car.settings.security;
18 
19 import android.app.KeyguardManager;
20 import android.os.Bundle;
21 import android.support.v4.app.Fragment;
22 import android.support.v7.widget.Toolbar;
23 
24 import com.android.car.settings.R;
25 import com.android.car.settings.common.BaseFragment;
26 import com.android.car.settings.common.CarSettingActivity;
27 import com.android.car.settingslib.util.ResultCodes;
28 
29 /**
30  * Entry point Activity for Setup Wizard to set screen lock.
31  */
32 public class SetupWizardScreenLockActivity extends CarSettingActivity implements
33         LockTypeDialogFragment.OnLockSelectListener {
34 
35     @Override
launchFragment(BaseFragment fragment)36     public void launchFragment(BaseFragment fragment) {
37     }
38 
39     @Override
goBack()40     public void goBack() {
41         setResult(RESULT_CANCELED);
42         finish();
43     }
44 
45     @Override
onCreate(Bundle savedInstanceState)46     protected void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48 
49         // This activity is meant for Setup Wizard therefore doesn't ask the user for credentials.
50         // It's pointless to launch this activity as the lock can't be changed without current
51         // credential.
52         if (getSystemService(KeyguardManager.class).isKeyguardSecure()) {
53             setResult(RESULT_CANCELED);
54             finish();
55             return;
56         }
57 
58         setContentView(R.layout.suw_activity);
59         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
60         setSupportActionBar(toolbar);
61 
62         BaseFragment pinFragment = ChooseLockPinPasswordFragment.newPinInstance();
63         setFragmentArgs(pinFragment);
64 
65         getSupportFragmentManager()
66                 .beginTransaction()
67                 .add(R.id.fragment_container, pinFragment)
68                 .commit();
69     }
70 
71     /**
72      * Handler that will be invoked when Cancel button is clicked in the fragment.
73      */
onCancel()74     public void onCancel() {
75         setResult(ResultCodes.RESULT_SKIP);
76         finish();
77     }
78 
79     /**
80      * Handler that will be invoked when lock save is completed.
81      */
onComplete()82     public void onComplete() {
83         setResult(RESULT_OK);
84         finish();
85     }
86 
87     @Override
onLockTypeSelected(int position)88     public void onLockTypeSelected(int position) {
89         Fragment fragment = null;
90 
91         switch(position) {
92             case LockTypeDialogFragment.POSITION_NONE:
93                 setResult(ResultCodes.RESULT_NONE);
94                 finish();
95                 break;
96             case LockTypeDialogFragment.POSITION_PIN:
97                 fragment = ChooseLockPinPasswordFragment.newPinInstance();
98                 break;
99             case LockTypeDialogFragment.POSITION_PATTERN:
100                 fragment = ChooseLockPatternFragment.newInstance();
101                 break;
102             case LockTypeDialogFragment.POSITION_PASSWORD:
103                 fragment = ChooseLockPinPasswordFragment.newPasswordInstance();
104                 break;
105             default:
106                 // Do nothing
107         }
108         if (fragment != null) {
109             setFragmentArgs(fragment);
110 
111             getSupportFragmentManager()
112                     .beginTransaction()
113                     .replace(R.id.fragment_container, fragment)
114                     .commitNow();
115         }
116     }
117 
setFragmentArgs(Fragment fragment)118     private void setFragmentArgs(Fragment fragment) {
119         Bundle args = fragment.getArguments();
120         if (args == null) {
121             args = new Bundle();
122         }
123         args.putBoolean(BaseFragment.EXTRA_RUNNING_IN_SETUP_WIZARD, true);
124         fragment.setArguments(args);
125     }
126 }
127