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