2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.password;
19 import android.app.admin.DevicePolicyManager;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.res.Resources;
23 import android.os.Bundle;
24 import android.os.UserHandle;
25 import android.support.v14.preference.PreferenceFragment;
26 import android.support.v7.preference.Preference;
27 import android.support.v7.widget.RecyclerView;
28 import android.view.LayoutInflater;
29 import android.view.View;
30 import android.view.ViewGroup;
31 import android.widget.LinearLayout;
33 import com.android.internal.widget.LockPatternUtils;
34 import com.android.settings.R;
35 import com.android.settings.SetupEncryptionInterstitial;
36 import com.android.settings.SetupWizardUtils;
37 import com.android.settings.fingerprint.SetupFingerprintEnrollFindSensor;
38 import com.android.settings.utils.SettingsDividerItemDecoration;
39 import com.android.setupwizardlib.GlifPreferenceLayout;
42 * Setup Wizard's version of ChooseLockGeneric screen. It inherits the logic and basic structure
43 * from ChooseLockGeneric class, and should remain similar to that behaviorally. This class should
44 * only overload base methods for minor theme and behavior differences specific to Setup Wizard.
45 * Other changes should be done to ChooseLockGeneric class instead and let this class inherit
48 public class SetupChooseLockGeneric extends ChooseLockGeneric {
50 private static final String KEY_UNLOCK_SET_DO_LATER = "unlock_set_do_later";
53 protected boolean isValidFragment(String fragmentName) {
54 return SetupChooseLockGenericFragment.class.getName().equals(fragmentName);
58 /* package */ Class<? extends PreferenceFragment> getFragmentClass() {
59 return SetupChooseLockGenericFragment.class;
63 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
64 resid = SetupWizardUtils.getTheme(getIntent());
65 super.onApplyThemeResource(theme, resid, first);
69 protected void onCreate(Bundle savedInstance) {
70 super.onCreate(savedInstance);
71 LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent);
72 layout.setFitsSystemWindows(false);
75 public static class SetupChooseLockGenericFragment extends ChooseLockGenericFragment {
77 public static final String EXTRA_PASSWORD_QUALITY = ":settings:password_quality";
80 public void onViewCreated(View view, Bundle savedInstanceState) {
81 super.onViewCreated(view, savedInstanceState);
83 GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
84 layout.setDividerItemDecoration(new SettingsDividerItemDecoration(getContext()));
85 layout.setDividerInset(getContext().getResources().getDimensionPixelSize(
86 R.dimen.suw_items_glif_text_divider_inset));
88 layout.setIcon(getContext().getDrawable(R.drawable.ic_lock));
90 int titleResource = mForFingerprint ?
91 R.string.lock_settings_picker_title : R.string.setup_lock_settings_picker_title;
92 if (getActivity() != null) {
93 getActivity().setTitle(titleResource);
96 layout.setHeaderText(titleResource);
97 // Use the dividers in SetupWizardRecyclerLayout. Suppress the dividers in
98 // PreferenceFragment.
103 protected void addHeaderView() {
104 if (mForFingerprint) {
105 setHeaderView(R.layout.setup_choose_lock_generic_fingerprint_header);
107 setHeaderView(R.layout.setup_choose_lock_generic_header);
112 public void onActivityResult(int requestCode, int resultCode, Intent data) {
116 // Add the password quality extra to the intent data that will be sent back for
118 LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity());
119 data.putExtra(EXTRA_PASSWORD_QUALITY,
120 lockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId()));
122 super.onActivityResult(requestCode, resultCode, data);
126 public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
127 Bundle savedInstanceState) {
128 GlifPreferenceLayout layout = (GlifPreferenceLayout) parent;
129 return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
133 * Disables preferences that are less secure than required quality and shows only secure
134 * screen lock options here.
136 * @param quality the requested quality.
139 protected void disableUnusablePreferences(final int quality, boolean hideDisabled) {
140 // At this part of the flow, the user has already indicated they want to add a pin,
141 // pattern or password, so don't show "None" or "Slide". We disable them here and set
142 // the HIDE_DISABLED flag to true to hide them. This only happens for setup wizard.
143 // We do the following max check here since the device may already have a Device Admin
144 // installed with a policy we need to honor.
145 final int newQuality = Math.max(quality,
146 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
147 super.disableUnusablePreferencesImpl(newQuality, true /* hideDisabled */);
151 protected void addPreferences() {
152 if (mForFingerprint) {
153 super.addPreferences();
155 addPreferencesFromResource(R.xml.setup_security_settings_picker);
160 public boolean onPreferenceTreeClick(Preference preference) {
161 final String key = preference.getKey();
162 if (KEY_UNLOCK_SET_DO_LATER.equals(key)) {
164 SetupSkipDialog dialog = SetupSkipDialog.newInstance(getActivity().getIntent()
165 .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
166 dialog.show(getFragmentManager());
169 return super.onPreferenceTreeClick(preference);
173 protected Intent getLockPasswordIntent(int quality, int minLength, int maxLength) {
174 final Intent intent = SetupChooseLockPassword.modifyIntentForSetup(
175 getContext(), super.getLockPasswordIntent(quality, minLength, maxLength));
176 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
181 protected Intent getLockPatternIntent() {
182 final Intent intent = SetupChooseLockPattern.modifyIntentForSetup(
183 getContext(), super.getLockPatternIntent());
184 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
189 protected Intent getEncryptionInterstitialIntent(Context context, int quality,
190 boolean required, Intent unlockMethodIntent) {
191 Intent intent = SetupEncryptionInterstitial.createStartIntent(context, quality,
192 required, unlockMethodIntent);
193 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
198 protected Intent getFindSensorIntent(Context context) {
199 final Intent intent = new Intent(context, SetupFingerprintEnrollFindSensor.class);
200 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);