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