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; 18 19 import android.app.admin.DevicePolicyManager; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.pm.PackageManager; 24 import android.content.res.Resources; 25 import android.os.Bundle; 26 import android.os.UserHandle; 27 import android.support.v14.preference.PreferenceFragment; 28 import android.support.v7.preference.Preference; 29 import android.support.v7.widget.RecyclerView; 30 import android.view.LayoutInflater; 31 import android.view.View; 32 import android.view.ViewGroup; 33 import android.widget.LinearLayout; 34 35 import com.android.internal.widget.LockPatternUtils; 36 import com.android.settings.fingerprint.SetupSkipDialog; 37 import com.android.settings.utils.SettingsDividerItemDecoration; 38 import com.android.setupwizardlib.GlifPreferenceLayout; 39 40 /** 41 * Setup Wizard's version of ChooseLockGeneric screen. It inherits the logic and basic structure 42 * from ChooseLockGeneric 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 ChooseLockGeneric class instead and let this class inherit 45 * those changes. 46 */ 47 public class SetupChooseLockGeneric extends ChooseLockGeneric { 48 49 private static final String KEY_UNLOCK_SET_DO_LATER = "unlock_set_do_later"; 50 51 @Override isValidFragment(String fragmentName)52 protected boolean isValidFragment(String fragmentName) { 53 return SetupChooseLockGenericFragment.class.getName().equals(fragmentName); 54 } 55 56 @Override getFragmentClass()57 /* package */ Class<? extends PreferenceFragment> getFragmentClass() { 58 return SetupChooseLockGenericFragment.class; 59 } 60 61 @Override onApplyThemeResource(Resources.Theme theme, int resid, boolean first)62 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 63 resid = SetupWizardUtils.getTheme(getIntent()); 64 super.onApplyThemeResource(theme, resid, first); 65 } 66 67 @Override onCreate(Bundle savedInstance)68 protected void onCreate(Bundle savedInstance) { 69 super.onCreate(savedInstance); 70 LinearLayout layout = (LinearLayout) findViewById(R.id.content_parent); 71 layout.setFitsSystemWindows(false); 72 } 73 74 public static class SetupChooseLockGenericFragment extends ChooseLockGenericFragment { 75 76 public static final String EXTRA_PASSWORD_QUALITY = ":settings:password_quality"; 77 78 @Override onViewCreated(View view, Bundle savedInstanceState)79 public void onViewCreated(View view, Bundle savedInstanceState) { 80 super.onViewCreated(view, savedInstanceState); 81 82 GlifPreferenceLayout layout = (GlifPreferenceLayout) view; 83 layout.setDividerItemDecoration(new SettingsDividerItemDecoration(getContext())); 84 layout.setDividerInset(getContext().getResources().getDimensionPixelSize( 85 R.dimen.suw_items_glif_text_divider_inset)); 86 87 layout.setIcon(getContext().getDrawable(R.drawable.ic_lock)); 88 89 int titleResource = mForFingerprint ? 90 R.string.lock_settings_picker_title : R.string.setup_lock_settings_picker_title; 91 if (getActivity() != null) { 92 getActivity().setTitle(titleResource); 93 } 94 95 layout.setHeaderText(titleResource); 96 // Use the dividers in SetupWizardRecyclerLayout. Suppress the dividers in 97 // PreferenceFragment. 98 setDivider(null); 99 } 100 101 @Override addHeaderView()102 protected void addHeaderView() { 103 if (mForFingerprint) { 104 setHeaderView(R.layout.setup_choose_lock_generic_fingerprint_header); 105 } else { 106 setHeaderView(R.layout.setup_choose_lock_generic_header); 107 } 108 } 109 110 @Override onActivityResult(int requestCode, int resultCode, Intent data)111 public void onActivityResult(int requestCode, int resultCode, Intent data) { 112 if (resultCode != RESULT_CANCELED) { 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 PackageManager packageManager = getPackageManager(); 123 ComponentName componentName = new ComponentName("com.android.settings", 124 "com.android.settings.SetupRedactionInterstitial"); 125 packageManager.setComponentEnabledSetting(componentName, 126 PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 127 PackageManager.DONT_KILL_APP); 128 super.onActivityResult(requestCode, resultCode, data); 129 } 130 // If the started activity was cancelled (e.g. the user presses back), then this 131 // activity will be resumed to foreground. 132 } 133 134 @Override onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)135 public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, 136 Bundle savedInstanceState) { 137 GlifPreferenceLayout layout = (GlifPreferenceLayout) parent; 138 return layout.onCreateRecyclerView(inflater, parent, savedInstanceState); 139 } 140 141 /*** 142 * Disables preferences that are less secure than required quality and shows only secure 143 * screen lock options here. 144 * 145 * @param quality the requested quality. 146 */ 147 @Override disableUnusablePreferences(final int quality, boolean hideDisabled)148 protected void disableUnusablePreferences(final int quality, boolean hideDisabled) { 149 // At this part of the flow, the user has already indicated they want to add a pin, 150 // pattern or password, so don't show "None" or "Slide". We disable them here and set 151 // the HIDE_DISABLED flag to true to hide them. This only happens for setup wizard. 152 // We do the following max check here since the device may already have a Device Admin 153 // installed with a policy we need to honor. 154 final int newQuality = Math.max(quality, 155 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); 156 super.disableUnusablePreferencesImpl(newQuality, true /* hideDisabled */); 157 } 158 159 @Override addPreferences()160 protected void addPreferences() { 161 if (mForFingerprint) { 162 super.addPreferences(); 163 } else { 164 addPreferencesFromResource(R.xml.setup_security_settings_picker); 165 } 166 } 167 168 @Override onPreferenceTreeClick(Preference preference)169 public boolean onPreferenceTreeClick(Preference preference) { 170 final String key = preference.getKey(); 171 if (KEY_UNLOCK_SET_DO_LATER.equals(key)) { 172 // show warning. 173 SetupSkipDialog dialog = SetupSkipDialog.newInstance(getActivity().getIntent() 174 .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false)); 175 dialog.show(getFragmentManager()); 176 return true; 177 } 178 return super.onPreferenceTreeClick(preference); 179 } 180 181 @Override getLockPasswordIntent(Context context, int quality, int minLength, final int maxLength, boolean requirePasswordToDecrypt, boolean confirmCredentials, int userId)182 protected Intent getLockPasswordIntent(Context context, int quality, 183 int minLength, final int maxLength, 184 boolean requirePasswordToDecrypt, boolean confirmCredentials, int userId) { 185 final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength, 186 maxLength, requirePasswordToDecrypt, confirmCredentials); 187 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 188 return intent; 189 } 190 191 @Override getLockPasswordIntent(Context context, int quality, int minLength, final int maxLength, boolean requirePasswordToDecrypt, long challenge, int userId)192 protected Intent getLockPasswordIntent(Context context, int quality, 193 int minLength, final int maxLength, 194 boolean requirePasswordToDecrypt, long challenge, int userId) { 195 final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength, 196 maxLength, requirePasswordToDecrypt, challenge); 197 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 198 return intent; 199 } 200 201 @Override getLockPasswordIntent(Context context, int quality, int minLength, int maxLength, boolean requirePasswordToDecrypt, String password, int userId)202 protected Intent getLockPasswordIntent(Context context, int quality, int minLength, 203 int maxLength, boolean requirePasswordToDecrypt, String password, int userId) { 204 final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength, 205 maxLength, requirePasswordToDecrypt, password); 206 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 207 return intent; 208 } 209 210 @Override getLockPatternIntent(Context context, final boolean requirePassword, final boolean confirmCredentials, int userId)211 protected Intent getLockPatternIntent(Context context, final boolean requirePassword, 212 final boolean confirmCredentials, int userId) { 213 final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword, 214 confirmCredentials); 215 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 216 return intent; 217 } 218 219 @Override getLockPatternIntent(Context context, final boolean requirePassword, long challenge, int userId)220 protected Intent getLockPatternIntent(Context context, final boolean requirePassword, 221 long challenge, int userId) { 222 final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword, 223 challenge); 224 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 225 return intent; 226 } 227 228 @Override getLockPatternIntent(Context context, final boolean requirePassword, final String pattern, int userId)229 protected Intent getLockPatternIntent(Context context, final boolean requirePassword, 230 final String pattern, int userId) { 231 final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword, 232 pattern); 233 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 234 return intent; 235 } 236 237 @Override getEncryptionInterstitialIntent(Context context, int quality, boolean required, Intent unlockMethodIntent)238 protected Intent getEncryptionInterstitialIntent(Context context, int quality, 239 boolean required, Intent unlockMethodIntent) { 240 Intent intent = SetupEncryptionInterstitial.createStartIntent(context, quality, 241 required, unlockMethodIntent); 242 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 243 return intent; 244 } 245 } 246 } 247