OSDN Git Service

Bluetooth: Make notifications local-only am: 1138397336
[android-x86/packages-apps-Settings.git] / src / com / android / settings / password / SetupChooseLockGeneric.java
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
53     protected boolean isValidFragment(String fragmentName) {
54         return SetupChooseLockGenericFragment.class.getName().equals(fragmentName);
55     }
56
57     @Override
58     /* package */ Class<? extends PreferenceFragment> getFragmentClass() {
59         return SetupChooseLockGenericFragment.class;
60     }
61
62     @Override
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
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
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
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
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
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         /***
133          * Disables preferences that are less secure than required quality and shows only secure
134          * screen lock options here.
135          *
136          * @param quality the requested quality.
137          */
138         @Override
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 */);
148         }
149
150         @Override
151         protected void addPreferences() {
152             if (mForFingerprint) {
153                 super.addPreferences();
154             } else {
155                 addPreferencesFromResource(R.xml.setup_security_settings_picker);
156             }
157         }
158
159         @Override
160         public boolean onPreferenceTreeClick(Preference preference) {
161             final String key = preference.getKey();
162             if (KEY_UNLOCK_SET_DO_LATER.equals(key)) {
163                 // show warning.
164                 SetupSkipDialog dialog = SetupSkipDialog.newInstance(getActivity().getIntent()
165                         .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
166                 dialog.show(getFragmentManager());
167                 return true;
168             }
169             return super.onPreferenceTreeClick(preference);
170         }
171
172         @Override
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);
177             return intent;
178         }
179
180         @Override
181         protected Intent getLockPatternIntent() {
182             final Intent intent = SetupChooseLockPattern.modifyIntentForSetup(
183                     getContext(), super.getLockPatternIntent());
184             SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
185             return intent;
186         }
187
188         @Override
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);
194             return intent;
195         }
196
197         @Override
198         protected Intent getFindSensorIntent(Context context) {
199             final Intent intent = new Intent(context, SetupFingerprintEnrollFindSensor.class);
200             SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
201             return intent;
202         }
203     }
204 }