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.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; 32 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; 40 41 /** 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 46 * those changes. 47 */ 48 public class SetupChooseLockGeneric extends ChooseLockGeneric { 49 50 private static final String KEY_UNLOCK_SET_DO_LATER = "unlock_set_do_later"; 51 52 @Override isValidFragment(String fragmentName)53 protected boolean isValidFragment(String fragmentName) { 54 return SetupChooseLockGenericFragment.class.getName().equals(fragmentName); 55 } 56 57 @Override getFragmentClass()58 /* package */ Class<? extends PreferenceFragment> getFragmentClass() { 59 return SetupChooseLockGenericFragment.class; 60 } 61 62 @Override onApplyThemeResource(Resources.Theme theme, int resid, boolean first)63 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 64 resid = SetupWizardUtils.getTheme(getIntent()); 65 super.onApplyThemeResource(theme, resid, first); 66 } 67 68 @Override onCreate(Bundle savedInstance)69 protected void onCreate(Bundle savedInstance) { 70 super.onCreate(savedInstance); 71 LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent); 72 layout.setFitsSystemWindows(false); 73 } 74 75 public static class SetupChooseLockGenericFragment extends ChooseLockGenericFragment { 76 77 public static final String EXTRA_PASSWORD_QUALITY = ":settings:password_quality"; 78 79 @Override onViewCreated(View view, Bundle savedInstanceState)80 public void onViewCreated(View view, Bundle savedInstanceState) { 81 super.onViewCreated(view, savedInstanceState); 82 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)); 87 88 layout.setIcon(getContext().getDrawable(R.drawable.ic_lock)); 89 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); 94 } 95 96 layout.setHeaderText(titleResource); 97 // Use the dividers in SetupWizardRecyclerLayout. Suppress the dividers in 98 // PreferenceFragment. 99 setDivider(null); 100 } 101 102 @Override addHeaderView()103 protected void addHeaderView() { 104 if (mForFingerprint) { 105 setHeaderView(R.layout.setup_choose_lock_generic_fingerprint_header); 106 } else { 107 setHeaderView(R.layout.setup_choose_lock_generic_header); 108 } 109 } 110 111 @Override onActivityResult(int requestCode, int resultCode, Intent data)112 public void onActivityResult(int requestCode, int resultCode, Intent data) { 113 if (data == null) { 114 data = new Intent(); 115 } 116 // Add the password quality extra to the intent data that will be sent back for 117 // Setup Wizard. 118 LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity()); 119 data.putExtra(EXTRA_PASSWORD_QUALITY, 120 lockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId())); 121 122 super.onActivityResult(requestCode, resultCode, data); 123 } 124 125 @Override onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)126 public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, 127 Bundle savedInstanceState) { 128 GlifPreferenceLayout layout = (GlifPreferenceLayout) parent; 129 return layout.onCreateRecyclerView(inflater, parent, savedInstanceState); 130 } 131 132 @Override canRunBeforeDeviceProvisioned()133 protected boolean canRunBeforeDeviceProvisioned() { 134 return true; 135 } 136 137 /*** 138 * Disables preferences that are less secure than required quality and shows only secure 139 * screen lock options here. 140 * 141 * @param quality the requested quality. 142 */ 143 @Override disableUnusablePreferences(final int quality, boolean hideDisabled)144 protected void disableUnusablePreferences(final int quality, boolean hideDisabled) { 145 // At this part of the flow, the user has already indicated they want to add a pin, 146 // pattern or password, so don't show "None" or "Slide". We disable them here and set 147 // the HIDE_DISABLED flag to true to hide them. This only happens for setup wizard. 148 // We do the following max check here since the device may already have a Device Admin 149 // installed with a policy we need to honor. 150 final int newQuality = Math.max(quality, 151 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); 152 super.disableUnusablePreferencesImpl(newQuality, true /* hideDisabled */); 153 } 154 155 @Override addPreferences()156 protected void addPreferences() { 157 if (mForFingerprint) { 158 super.addPreferences(); 159 } else { 160 addPreferencesFromResource(R.xml.setup_security_settings_picker); 161 } 162 } 163 164 @Override onPreferenceTreeClick(Preference preference)165 public boolean onPreferenceTreeClick(Preference preference) { 166 final String key = preference.getKey(); 167 if (KEY_UNLOCK_SET_DO_LATER.equals(key)) { 168 // show warning. 169 SetupSkipDialog dialog = SetupSkipDialog.newInstance(getActivity().getIntent() 170 .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false)); 171 dialog.show(getFragmentManager()); 172 return true; 173 } 174 return super.onPreferenceTreeClick(preference); 175 } 176 177 @Override getLockPasswordIntent(int quality, int minLength, int maxLength)178 protected Intent getLockPasswordIntent(int quality, int minLength, int maxLength) { 179 final Intent intent = SetupChooseLockPassword.modifyIntentForSetup( 180 getContext(), super.getLockPasswordIntent(quality, minLength, maxLength)); 181 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 182 return intent; 183 } 184 185 @Override getLockPatternIntent()186 protected Intent getLockPatternIntent() { 187 final Intent intent = SetupChooseLockPattern.modifyIntentForSetup( 188 getContext(), super.getLockPatternIntent()); 189 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 190 return intent; 191 } 192 193 @Override getEncryptionInterstitialIntent(Context context, int quality, boolean required, Intent unlockMethodIntent)194 protected Intent getEncryptionInterstitialIntent(Context context, int quality, 195 boolean required, Intent unlockMethodIntent) { 196 Intent intent = SetupEncryptionInterstitial.createStartIntent(context, quality, 197 required, unlockMethodIntent); 198 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 199 return intent; 200 } 201 202 @Override getFindSensorIntent(Context context)203 protected Intent getFindSensorIntent(Context context) { 204 final Intent intent = new Intent(context, SetupFingerprintEnrollFindSensor.class); 205 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 206 return intent; 207 } 208 } 209 } 210