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 com.android.setupwizard.navigationbar.SetupWizardNavBar; 20 21 import android.app.admin.DevicePolicyManager; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.res.Resources; 25 import android.os.Bundle; 26 import android.preference.PreferenceFragment; 27 import android.util.MutableBoolean; 28 import android.view.LayoutInflater; 29 import android.view.View; 30 import android.view.ViewGroup; 31 import android.widget.ListView; 32 33 /** 34 * Setup Wizard's version of ChooseLockGeneric screen. It inherits the logic and basic structure 35 * from ChooseLockGeneric class, and should remain similar to that behaviorally. This class should 36 * only overload base methods for minor theme and behavior differences specific to Setup Wizard. 37 * Other changes should be done to ChooseLockGeneric class instead and let this class inherit 38 * those changes. 39 */ 40 public class SetupChooseLockGeneric extends ChooseLockGeneric 41 implements SetupWizardNavBar.NavigationBarListener { 42 43 @Override 44 protected boolean isValidFragment(String fragmentName) { 45 return SetupChooseLockGenericFragment.class.getName().equals(fragmentName); 46 } 47 48 @Override 49 /* package */ Class<? extends PreferenceFragment> getFragmentClass() { 50 return SetupChooseLockGenericFragment.class; 51 } 52 53 @Override 54 protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { 55 resid = SetupWizardUtils.getTheme(getIntent(), resid); 56 super.onApplyThemeResource(theme, resid, first); 57 } 58 59 @Override 60 public void onNavigationBarCreated(SetupWizardNavBar bar) { 61 SetupWizardUtils.setImmersiveMode(this, bar); 62 bar.getNextButton().setEnabled(false); 63 } 64 65 @Override 66 public void onNavigateBack() { 67 onBackPressed(); 68 } 69 70 @Override 71 public void onNavigateNext() { 72 } 73 74 public static class SetupChooseLockGenericFragment extends ChooseLockGenericFragment { 75 76 @Override 77 public View onCreateView(LayoutInflater inflater, ViewGroup container, 78 Bundle savedInstanceState) { 79 final View view = inflater.inflate(R.layout.setup_preference, container, false); 80 ListView list = (ListView) view.findViewById(android.R.id.list); 81 View title = view.findViewById(R.id.title); 82 if (title == null) { 83 final View header = inflater.inflate(R.layout.setup_wizard_header, list, false); 84 list.addHeaderView(header, null, false); 85 } 86 return view; 87 } 88 89 @Override 90 public void onViewCreated(View view, Bundle savedInstanceState) { 91 super.onViewCreated(view, savedInstanceState); 92 SetupWizardUtils.setIllustration(getActivity(), 93 R.drawable.setup_illustration_lock_screen); 94 SetupWizardUtils.setHeaderText(getActivity(), getActivity().getTitle()); 95 } 96 97 /*** 98 * Disables preferences that are less secure than required quality and shows only secure 99 * screen lock options here. 100 * 101 * @param quality the requested quality. 102 * @param allowBiometric whether to allow biometic screen lock 103 */ 104 @Override 105 protected void disableUnusablePreferences(final int quality, 106 MutableBoolean allowBiometric) { 107 // At this part of the flow, the user has already indicated they want to add a pin, 108 // pattern or password, so don't show "None" or "Slide". We disable them here and set 109 // the HIDE_DISABLED flag to true to hide them. This only happens for setup wizard. 110 // We do the following max check here since the device may already have a Device Admin 111 // installed with a policy we need to honor. 112 final int newQuality = Math.max(quality, 113 DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); 114 super.disableUnusablePreferencesImpl(newQuality, allowBiometric, 115 true /* hideDisabled */); 116 } 117 118 @Override 119 protected Intent getLockPasswordIntent(Context context, int quality, boolean isFallback, 120 int minLength, int maxLength, boolean requirePasswordToDecrypt, 121 boolean confirmCredentials) { 122 final Intent intent = SetupChooseLockPassword.createIntent(context, quality, 123 isFallback, minLength, maxLength, requirePasswordToDecrypt, confirmCredentials); 124 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 125 return intent; 126 } 127 128 @Override 129 protected Intent getLockPatternIntent(Context context, boolean isFallback, 130 boolean requirePassword, boolean confirmCredentials) { 131 final Intent intent = SetupChooseLockPattern.createIntent(context, isFallback, 132 requirePassword, confirmCredentials); 133 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 134 return intent; 135 } 136 137 @Override 138 protected Intent getEncryptionInterstitialIntent(Context context, int quality, 139 boolean required) { 140 Intent intent = SetupEncryptionInterstitial.createStartIntent(context, quality, 141 required); 142 SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); 143 return intent; 144 } 145 } 146 } 147