blob: 60bb0cdc30769b7a25ee72f185b16d0658c3330c [file] [log] [blame]
Maurice Lam6b19fa92014-11-25 19:25:56 -08001/*
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
Maurice Lam2eb170c2017-04-28 16:18:47 -070017package com.android.settings.password;
Maurice Lam6b19fa92014-11-25 19:25:56 -080018
Maurice Lamedb39442017-04-27 18:54:33 -070019import android.app.Activity;
Ajay Nadathur17d66be2017-07-07 18:04:14 -070020import android.app.admin.DevicePolicyManager;
Maurice Lam6b19fa92014-11-25 19:25:56 -080021import android.content.Context;
22import android.content.Intent;
Maurice Lam6b19fa92014-11-25 19:25:56 -080023import android.os.Bundle;
Ajay Nadathur17d66be2017-07-07 18:04:14 -070024import android.util.Log;
Maurice Lamedb39442017-04-27 18:54:33 -070025import android.view.View;
26import android.widget.Button;
Udam Saini71fde522016-03-30 13:38:05 -070027import android.widget.LinearLayout;
Maurice Lam6b19fa92014-11-25 19:25:56 -080028
Fan Zhang23f8d592018-08-28 15:11:40 -070029import androidx.annotation.Nullable;
30import androidx.fragment.app.Fragment;
31
Maurice Lam2eb170c2017-04-28 16:18:47 -070032import com.android.settings.R;
33import com.android.settings.SetupRedactionInterstitial;
Maurice Lamedb39442017-04-27 18:54:33 -070034import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener;
Maurice Lam2eb170c2017-04-28 16:18:47 -070035
Maurice Lamecd2b7b2014-12-01 10:41:49 -080036/**
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 */
Maurice Lam83301b52015-04-18 20:11:59 -070043public class SetupChooseLockPassword extends ChooseLockPassword {
Maurice Lam6b19fa92014-11-25 19:25:56 -080044
Ajay Nadathur17d66be2017-07-07 18:04:14 -070045 private static final String TAG = "SetupChooseLockPassword";
46
Maurice Lam2eb170c2017-04-28 16:18:47 -070047 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;
Maurice Lam38596432015-04-16 18:11:42 -070053 }
54
Maurice Lam6b19fa92014-11-25 19:25:56 -080055 @Override
56 protected boolean isValidFragment(String fragmentName) {
57 return SetupChooseLockPasswordFragment.class.getName().equals(fragmentName);
58 }
59
60 @Override
61 /* package */ Class<? extends Fragment> getFragmentClass() {
62 return SetupChooseLockPasswordFragment.class;
63 }
64
65 @Override
Udam Saini71fde522016-03-30 13:38:05 -070066 protected void onCreate(Bundle savedInstance) {
67 super.onCreate(savedInstance);
68 LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
69 layout.setFitsSystemWindows(false);
70 }
71
Maurice Lamedb39442017-04-27 18:54:33 -070072 public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment
73 implements OnLockTypeSelectedListener {
74
pastychang76ad11c2019-01-18 14:28:27 +080075 private static final String TAG_SKIP_SCREEN_LOCK_DIALOG = "skip_screen_lock_dialog";
76
Maurice Lam62c0c3c2017-07-10 18:15:10 -070077 @Nullable
78 private Button mOptionsButton;
pastychang76ad11c2019-01-18 14:28:27 +080079 private boolean mLeftButtonIsSkip;
Maurice Lam62c0c3c2017-07-10 18:15:10 -070080
Maurice Lamedb39442017-04-27 18:54:33 -070081 @Override
82 public void onViewCreated(View view, Bundle savedInstanceState) {
83 super.onViewCreated(view, savedInstanceState);
Ajay Nadathur17d66be2017-07-07 18:04:14 -070084 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(
Ajay Nadathura1314df2018-01-04 13:06:46 -080090 ChooseLockGeneric.ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
Ajay Nadathur17d66be2017-07-07 18:04:14 -070091 if (!anyOptionsShown) {
92 Log.w(TAG, "Visible screen lock types is empty!");
93 }
94
95 if (showOptionsButton && anyOptionsShown) {
Maurice Lam62c0c3c2017-07-10 18:15:10 -070096 mOptionsButton = view.findViewById(R.id.screen_lock_options);
97 mOptionsButton.setVisibility(View.VISIBLE);
pastychang76ad11c2019-01-18 14:28:27 +080098 mOptionsButton.setOnClickListener((btn) ->
99 ChooseLockTypeDialogFragment.newInstance(mUserId)
100 .show(getChildFragmentManager(), TAG_SKIP_SCREEN_LOCK_DIALOG));
Maurice Lamedb39442017-04-27 18:54:33 -0700101 }
102 }
103
104 @Override
pastychang76ad11c2019-01-18 14:28:27 +0800105 protected void onSkipOrClearButtonClick(View view) {
106 if (mLeftButtonIsSkip) {
107 SetupSkipDialog dialog = SetupSkipDialog.newInstance(
108 getActivity().getIntent()
pastychang5145dc12019-03-18 20:10:32 +0800109 .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 );
pastychang76ad11c2019-01-18 14:28:27 +0800119 dialog.show(getFragmentManager());
120 return;
Maurice Lamedb39442017-04-27 18:54:33 -0700121 }
pastychang76ad11c2019-01-18 14:28:27 +0800122 super.onSkipOrClearButtonClick(view);
Maurice Lamedb39442017-04-27 18:54:33 -0700123 }
124
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800125 @Override
126 protected Intent getRedactionInterstitialIntent(Context context) {
Maurice Lam957fc672017-03-30 16:18:08 -0700127 // 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);
Udam Sainidd05ab72016-03-21 17:35:08 -0700130 return null;
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800131 }
Maurice Lamedb39442017-04-27 18:54:33 -0700132
133 @Override
134 public void onLockTypeSelected(ScreenLockType lock) {
Ajay Nadathura5f73922017-06-19 16:13:31 -0700135 ScreenLockType currentLockType = mIsAlphaMode ?
136 ScreenLockType.PASSWORD : ScreenLockType.PIN;
Ajay Nadathura1314df2018-01-04 13:06:46 -0800137 if (lock == currentLockType) {
Ajay Nadathura5f73922017-06-19 16:13:31 -0700138 return;
139 }
Ajay Nadathura1314df2018-01-04 13:06:46 -0800140 startChooseLockActivity(lock, getActivity());
Maurice Lamedb39442017-04-27 18:54:33 -0700141 }
Maurice Lam62c0c3c2017-07-10 18:15:10 -0700142
143 @Override
pastychang7a083f82019-03-26 16:09:34 +0800144 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
Maurice Lam62c0c3c2017-07-10 18:15:10 -0700151 protected void updateUi() {
152 super.updateUi();
Kevin Chyn69e8a082018-12-17 18:42:52 -0800153 // Show the skip button during SUW but not during Settings > Biometric Enrollment
pastychang382d34d2018-12-24 17:16:14 +0800154 if (mUiStage == Stage.Introduction) {
pastychang76ad11c2019-01-18 14:28:27 +0800155 mSkipOrClearButton.setText(getActivity(), R.string.skip_label);
156 mLeftButtonIsSkip = true;
pastychang382d34d2018-12-24 17:16:14 +0800157 } else {
pastychang76ad11c2019-01-18 14:28:27 +0800158 mSkipOrClearButton.setText(getActivity(), R.string.lockpassword_clear_label);
159 mLeftButtonIsSkip = false;
pastychang382d34d2018-12-24 17:16:14 +0800160 }
161
Maurice Lam62c0c3c2017-07-10 18:15:10 -0700162 if (mOptionsButton != null) {
163 mOptionsButton.setVisibility(
164 mUiStage == Stage.Introduction ? View.VISIBLE : View.GONE);
165 }
166 }
Maurice Lam6b19fa92014-11-25 19:25:56 -0800167 }
168}