• 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 static com.android.internal.widget.LockPatternUtils.CREDENTIAL_TYPE_PATTERN;
20 
21 import android.content.Context;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.view.ContextThemeWrapper;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.Button;
29 
30 import androidx.annotation.Nullable;
31 import androidx.fragment.app.Fragment;
32 
33 import com.android.settings.R;
34 import com.android.settings.SetupRedactionInterstitial;
35 
36 import com.google.android.setupcompat.util.WizardManagerHelper;
37 
38 /**
39  * Setup Wizard's version of ChooseLockPattern screen. It inherits the logic and basic structure
40  * from ChooseLockPattern class, and should remain similar to that behaviorally. This class should
41  * only overload base methods for minor theme and behavior differences specific to Setup Wizard.
42  * Other changes should be done to ChooseLockPattern class instead and let this class inherit
43  * those changes.
44  */
45 public class SetupChooseLockPattern extends ChooseLockPattern {
46 
modifyIntentForSetup(Context context, Intent chooseLockPatternIntent)47     public static Intent modifyIntentForSetup(Context context, Intent chooseLockPatternIntent) {
48         chooseLockPatternIntent.setClass(context, SetupChooseLockPattern.class);
49         return chooseLockPatternIntent;
50     }
51 
52     @Override
isValidFragment(String fragmentName)53     protected boolean isValidFragment(String fragmentName) {
54         return SetupChooseLockPatternFragment.class.getName().equals(fragmentName);
55     }
56 
57     @Override
getFragmentClass()58     /* package */ Class<? extends Fragment> getFragmentClass() {
59         return SetupChooseLockPatternFragment.class;
60     }
61 
62     @Override
onCreate(Bundle savedInstanceState)63     protected void onCreate(Bundle savedInstanceState) {
64         super.onCreate(savedInstanceState);
65 
66         // Show generic pattern title when pattern lock screen launch in Setup wizard flow before
67         // fingerprint and face setup.
68         setTitle(R.string.lockpassword_choose_your_pattern_header);
69     }
70 
71     public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment
72             implements ChooseLockTypeDialogFragment.OnLockTypeSelectedListener {
73 
74         private static final String TAG_SKIP_SCREEN_LOCK_DIALOG = "skip_screen_lock_dialog";
75 
76         @Nullable
77         private Button mOptionsButton;
78         private boolean mLeftButtonIsSkip;
79 
80         @Override
onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)81         public View onCreateView(
82                 LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
83             View view = super.onCreateView(inflater, container, savedInstanceState);
84             if (!getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui)) {
85                 mOptionsButton = new Button(new ContextThemeWrapper(getActivity(),
86                         com.google.android.setupdesign.R.style.SudGlifButton_Tertiary));
87                 mOptionsButton.setId(R.id.screen_lock_options);
88                 PasswordUtils.setupScreenLockOptionsButton(getActivity(), view, mOptionsButton);
89                 mOptionsButton.setOnClickListener((btn) ->
90                         ChooseLockTypeDialogFragment.newInstance(mUserId)
91                                 .show(getChildFragmentManager(), TAG_SKIP_SCREEN_LOCK_DIALOG));
92             }
93             // Show the skip button during SUW but not during Settings > Biometric Enrollment
94             mSkipOrClearButton.setOnClickListener(this::onSkipOrClearButtonClick);
95             return view;
96         }
97 
98         @Override
onSkipOrClearButtonClick(View view)99         protected void onSkipOrClearButtonClick(View view) {
100             if (mLeftButtonIsSkip) {
101                 final Intent intent = getActivity().getIntent();
102                 final boolean frpSupported = intent
103                         .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false);
104                 final boolean forFingerprint = intent
105                         .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
106                 final boolean forFace = intent
107                         .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false);
108                 final boolean forBiometrics = intent
109                         .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_BIOMETRICS, false);
110                 final SetupSkipDialog dialog = SetupSkipDialog.newInstance(
111                         CREDENTIAL_TYPE_PATTERN,
112                         frpSupported,
113                         forFingerprint,
114                         forFace,
115                         forBiometrics,
116                         WizardManagerHelper.isAnySetupWizard(intent));
117                 dialog.show(getFragmentManager());
118                 return;
119             }
120             super.onSkipOrClearButtonClick(view);
121         }
122 
123         @Override
onLockTypeSelected(ScreenLockType lock)124         public void onLockTypeSelected(ScreenLockType lock) {
125             if (ScreenLockType.PATTERN == lock) {
126                 return;
127             }
128             startChooseLockActivity(lock, getActivity());
129         }
130 
showMinimalUi()131         private boolean showMinimalUi() {
132             return getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui);
133         }
134 
135         @Override
updateStage(Stage stage)136         protected void updateStage(Stage stage) {
137             super.updateStage(stage);
138             if (!showMinimalUi() && mOptionsButton != null) {
139                 mOptionsButton.setVisibility(
140                         (stage == Stage.Introduction || stage == Stage.HelpScreen ||
141                                 stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid)
142                                 ? View.VISIBLE : View.INVISIBLE);
143             }
144 
145             if (stage.leftMode == LeftButtonMode.Gone && stage == Stage.Introduction) {
146                 mSkipOrClearButton.setVisibility(View.VISIBLE);
147                 mSkipOrClearButton.setText(getActivity(), R.string.skip_label);
148                 mLeftButtonIsSkip = true;
149             } else {
150                 mLeftButtonIsSkip = false;
151             }
152         }
153 
154         @Override
shouldShowGenericTitle()155         protected boolean shouldShowGenericTitle() {
156             return true;
157         }
158 
159         @Override
getRedactionInterstitialIntent(Context context)160         protected Intent getRedactionInterstitialIntent(Context context) {
161             // Setup wizard's redaction interstitial is deferred to optional step. Enable that
162             // optional step if the lock screen was set up.
163             SetupRedactionInterstitial.setEnabled(context, true);
164             return null;
165         }
166     }
167 }
168