• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.settings.password;
18 
19 import android.app.Activity;
20 import android.app.admin.DevicePolicyManager;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.util.Log;
25 import android.view.View;
26 import android.widget.Button;
27 import android.widget.LinearLayout;
28 
29 import androidx.annotation.Nullable;
30 import androidx.fragment.app.Fragment;
31 
32 import com.android.settings.R;
33 import com.android.settings.SetupRedactionInterstitial;
34 import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener;
35 
36 /**
37  * Setup Wizard's version of ChooseLockPassword screen. It inherits the logic and basic structure
38  * from ChooseLockPassword class, and should remain similar to that behaviorally. This class should
39  * only overload base methods for minor theme and behavior differences specific to Setup Wizard.
40  * Other changes should be done to ChooseLockPassword class instead and let this class inherit
41  * those changes.
42  */
43 public class SetupChooseLockPassword extends ChooseLockPassword {
44 
45     private static final String TAG = "SetupChooseLockPassword";
46 
modifyIntentForSetup( Context context, Intent chooseLockPasswordIntent)47     public static Intent modifyIntentForSetup(
48             Context context,
49             Intent chooseLockPasswordIntent) {
50         chooseLockPasswordIntent.setClass(context, SetupChooseLockPassword.class);
51         chooseLockPasswordIntent.putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false);
52         return chooseLockPasswordIntent;
53     }
54 
55     @Override
isValidFragment(String fragmentName)56     protected boolean isValidFragment(String fragmentName) {
57         return SetupChooseLockPasswordFragment.class.getName().equals(fragmentName);
58     }
59 
60     @Override
getFragmentClass()61     /* package */ Class<? extends Fragment> getFragmentClass() {
62         return SetupChooseLockPasswordFragment.class;
63     }
64 
65     @Override
onCreate(Bundle savedInstance)66     protected void onCreate(Bundle savedInstance) {
67         super.onCreate(savedInstance);
68         LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
69         layout.setFitsSystemWindows(false);
70     }
71 
72     public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment
73             implements OnLockTypeSelectedListener {
74 
75         private static final String TAG_SKIP_SCREEN_LOCK_DIALOG = "skip_screen_lock_dialog";
76 
77         @Nullable
78         private Button mOptionsButton;
79         private boolean mLeftButtonIsSkip;
80 
81         @Override
onViewCreated(View view, Bundle savedInstanceState)82         public void onViewCreated(View view, Bundle savedInstanceState) {
83             super.onViewCreated(view, savedInstanceState);
84             final Activity activity = getActivity();
85             ChooseLockGenericController chooseLockGenericController =
86                     new ChooseLockGenericController(activity, mUserId);
87             boolean anyOptionsShown = chooseLockGenericController.getVisibleScreenLockTypes(
88                     DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, false).size() > 0;
89             boolean showOptionsButton = activity.getIntent().getBooleanExtra(
90                     ChooseLockGeneric.ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
91             if (!anyOptionsShown) {
92                 Log.w(TAG, "Visible screen lock types is empty!");
93             }
94 
95             if (showOptionsButton && anyOptionsShown) {
96                 mOptionsButton = view.findViewById(R.id.screen_lock_options);
97                 mOptionsButton.setVisibility(View.VISIBLE);
98                 mOptionsButton.setOnClickListener((btn) ->
99                         ChooseLockTypeDialogFragment.newInstance(mUserId)
100                                 .show(getChildFragmentManager(), TAG_SKIP_SCREEN_LOCK_DIALOG));
101             }
102         }
103 
104         @Override
onSkipOrClearButtonClick(View view)105         protected void onSkipOrClearButtonClick(View view) {
106             if (mLeftButtonIsSkip) {
107                 SetupSkipDialog dialog = SetupSkipDialog.newInstance(
108                         getActivity().getIntent()
109                                 .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false),
110                         /* isPatternMode= */ false,
111                         mIsAlphaMode,
112                         getActivity().getIntent()
113                                 .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT,
114                                         false),
115                         getActivity().getIntent()
116                                 .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false)
117 
118                 );
119                 dialog.show(getFragmentManager());
120                 return;
121             }
122             super.onSkipOrClearButtonClick(view);
123         }
124 
125         @Override
getRedactionInterstitialIntent(Context context)126         protected Intent getRedactionInterstitialIntent(Context context) {
127             // Setup wizard's redaction interstitial is deferred to optional step. Enable that
128             // optional step if the lock screen was set up.
129             SetupRedactionInterstitial.setEnabled(context, true);
130             return null;
131         }
132 
133         @Override
onLockTypeSelected(ScreenLockType lock)134         public void onLockTypeSelected(ScreenLockType lock) {
135             ScreenLockType currentLockType = mIsAlphaMode ?
136                     ScreenLockType.PASSWORD : ScreenLockType.PIN;
137             if (lock == currentLockType) {
138                 return;
139             }
140             startChooseLockActivity(lock, getActivity());
141         }
142 
143         @Override
getStageType()144         protected int getStageType() {
145             // Return TYPE_NONE to make generic lock screen launch in Setup wizard flow before
146             // fingerprint and face setup.
147             return Stage.TYPE_NONE;
148         }
149 
150         @Override
updateUi()151         protected void updateUi() {
152             super.updateUi();
153             // Show the skip button during SUW but not during Settings > Biometric Enrollment
154             if (mUiStage == Stage.Introduction) {
155                 mSkipOrClearButton.setText(getActivity(), R.string.skip_label);
156                 mLeftButtonIsSkip = true;
157             } else {
158                 mSkipOrClearButton.setText(getActivity(), R.string.lockpassword_clear_label);
159                 mLeftButtonIsSkip = false;
160             }
161 
162             if (mOptionsButton != null) {
163                 mOptionsButton.setVisibility(
164                         mUiStage == Stage.Introduction ? View.VISIBLE : View.GONE);
165             }
166         }
167     }
168 }
169