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