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 android.content.res.Configuration.ORIENTATION_LANDSCAPE; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.Button; 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 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 showMinimalUi()126 private boolean showMinimalUi() { 127 return getResources().getBoolean(R.bool.config_lock_pattern_minimal_ui); 128 } 129 130 @Override updateStage(Stage stage)131 protected void updateStage(Stage stage) { 132 super.updateStage(stage); 133 if (!showMinimalUi() && mOptionsButton != null) { 134 // In landscape, keep view stub to avoid pattern view shifting, but in portrait the 135 // header title and description could become multiple lines in confirm stage, 136 // gone the button view to reserve more room for growth height of header. 137 @View.Visibility 138 final int hideOrGone = 139 getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE 140 ? View.INVISIBLE : View.GONE; 141 mOptionsButton.setVisibility( 142 (stage == Stage.Introduction || stage == Stage.HelpScreen || 143 stage == Stage.ChoiceTooShort || stage == Stage.FirstChoiceValid) 144 ? View.VISIBLE : hideOrGone); 145 } 146 147 if (stage.leftMode == LeftButtonMode.Gone && stage == Stage.Introduction) { 148 mSkipOrClearButton.setVisibility(View.VISIBLE); 149 mSkipOrClearButton.setText(getActivity(), R.string.skip_label); 150 mLeftButtonIsSkip = true; 151 } else { 152 mLeftButtonIsSkip = false; 153 } 154 } 155 156 @Override getRedactionInterstitialIntent(Context context)157 protected Intent getRedactionInterstitialIntent(Context context) { 158 // Setup wizard's redaction interstitial is deferred to optional step. Enable that 159 // optional step if the lock screen was set up. 160 SetupRedactionInterstitial.setEnabled(context, true); 161 return null; 162 } 163 } 164 } 165