OSDN Git Service

am 8815f032: Merge "Always set right auth_type value in apn."
[android-x86/packages-apps-Settings.git] / src / com / android / settings / ChooseLockSettingsHelper.java
1 /*
2  * Copyright (C) 2010 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.Intent;
22
23 import com.android.internal.widget.LockPatternUtils;
24
25 public class ChooseLockSettingsHelper {
26     private LockPatternUtils mLockPatternUtils;
27     private Activity mActivity;
28
29     public ChooseLockSettingsHelper(Activity activity) {
30         mActivity = activity;
31         mLockPatternUtils = new LockPatternUtils(activity);
32     }
33
34     public LockPatternUtils utils() {
35         return mLockPatternUtils;
36     }
37
38     /**
39      * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
40      * @param message optional message to display about the action about to be done
41      * @param details optional detail message to display
42      * @return true if one exists and we launched an activity to confirm it
43      * @see #onActivityResult(int, int, android.content.Intent)
44      */
45     protected boolean launchConfirmationActivity(int request,
46             CharSequence message, CharSequence details) {
47         boolean launched = false;
48         switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) {
49             case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
50                 launched = confirmPattern(request, message, details);
51                 break;
52             case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
53             case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
54             case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
55                 // TODO: update UI layout for ConfirmPassword to show message and details
56                 launched = confirmPassword(request);
57                 break;
58         }
59         return launched;
60     }
61
62     /**
63      * Launch screen to confirm the existing lock pattern.
64      * @param message shown in header of ConfirmLockPattern if not null
65      * @param details shown in footer of ConfirmLockPattern if not null
66      * @see #onActivityResult(int, int, android.content.Intent)
67      * @return true if we launched an activity to confirm pattern
68      */
69     private boolean confirmPattern(int request, CharSequence message, CharSequence details) {
70         if (!mLockPatternUtils.isLockPatternEnabled() || !mLockPatternUtils.savedPatternExists()) {
71             return false;
72         }
73         final Intent intent = new Intent();
74         // supply header and footer text in the intent
75         intent.putExtra(ConfirmLockPattern.HEADER_TEXT, message);
76         intent.putExtra(ConfirmLockPattern.FOOTER_TEXT, details);
77         intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPattern");
78         mActivity.startActivityForResult(intent, request);
79         return true;
80     }
81
82     /**
83      * Launch screen to confirm the existing lock password.
84      * @see #onActivityResult(int, int, android.content.Intent)
85      * @return true if we launched an activity to confirm password
86      */
87     private boolean confirmPassword(int request) {
88         if (!mLockPatternUtils.isLockPasswordEnabled()) return false;
89         final Intent intent = new Intent();
90         intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPassword");
91         mActivity.startActivityForResult(intent, request);
92         return true;
93     }
94
95
96 }