OSDN Git Service

fee68982350f7fceb84ef527367098b13bb80605
[android-x86/packages-apps-Settings.git] / src / com / android / settings / ChooseLockPatternSize.java
1 /*
2  * Copyright (C) 2012-2013 The CyanogenMod 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.content.Intent;
20 import android.os.Bundle;
21 import android.preference.PreferenceActivity;
22 import android.support.v7.preference.Preference;
23 import android.support.v7.preference.PreferenceScreen;
24
25 import com.android.internal.widget.LockPatternUtils;
26
27 import org.cyanogenmod.internal.logging.CMMetricsLogger;
28
29 public class ChooseLockPatternSize extends PreferenceActivity {
30
31     @Override
32     public Intent getIntent() {
33         Intent modIntent = new Intent(super.getIntent());
34         modIntent.putExtra(EXTRA_SHOW_FRAGMENT, ChooseLockPatternSizeFragment.class.getName());
35         modIntent.putExtra(EXTRA_NO_HEADERS, true);
36         return modIntent;
37     }
38
39     @Override
40     protected boolean isValidFragment(String fragmentName) {
41         if (ChooseLockPatternSizeFragment.class.getName().equals(fragmentName)) return true;
42         return false;
43     }
44
45     public static class ChooseLockPatternSizeFragment extends SettingsPreferenceFragment {
46         private ChooseLockSettingsHelper mChooseLockSettingsHelper;
47
48         @Override
49         public void onCreate(Bundle savedInstanceState) {
50             super.onCreate(savedInstanceState);
51             mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this.getActivity());
52             if (!(getActivity() instanceof ChooseLockPatternSize)) {
53                 throw new SecurityException("Fragment contained in wrong activity");
54             }
55             addPreferencesFromResource(R.xml.security_settings_pattern_size);
56         }
57
58         @Override
59         public boolean onPreferenceTreeClick(Preference preference) {
60             final String key = preference.getKey();
61
62             byte patternSize;
63             if ("lock_pattern_size_4".equals(key)) {
64                 patternSize = 4;
65             } else if ("lock_pattern_size_5".equals(key)) {
66                 patternSize = 5;
67             } else if ("lock_pattern_size_6".equals(key)) {
68                 patternSize = 6;
69             } else {
70                 patternSize = 3;
71             }
72
73             final boolean isFallback = getActivity().getIntent()
74                 .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false);
75
76             Intent intent = new Intent(getActivity(), ChooseLockPattern.class);
77             intent.putExtra("pattern_size", patternSize);
78             intent.putExtra("key_lock_method", "pattern");
79             intent.putExtra("confirm_credentials", false);
80             intent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK,
81                     isFallback);
82
83             Intent originatingIntent = getActivity().getIntent();
84             // Forward the challenge extras if available in originating intent.
85             if (originatingIntent.hasExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE)) {
86                 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE,
87                         originatingIntent.getBooleanExtra(
88                                 ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false));
89
90                 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE,
91                         originatingIntent.getLongExtra(
92                                 ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0));
93             }
94             // Forward the Encryption interstitial required password selection
95             if (originatingIntent.hasExtra(EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD)) {
96                 intent.putExtra(EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, originatingIntent
97                         .getBooleanExtra(EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true));
98             }
99             intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
100             startActivity(intent);
101
102             finish();
103             return true;
104         }
105
106         @Override
107         protected int getMetricsCategory() {
108             return CMMetricsLogger.CHOOSE_LOCK_PATTERN_SIZE;
109         }
110     }
111 }