ChooseLockSettingsHelper.java revision 57fbf694a53afb9c1924d81272179dceb3acfa4d
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
17package com.android.settings;
18
19import android.app.Activity;
20import android.app.admin.DevicePolicyManager;
21import android.content.Intent;
22
23import com.android.internal.widget.LockPatternUtils;
24
25public 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            case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
56                // TODO: update UI layout for ConfirmPassword to show message and details
57                launched = confirmPassword(request);
58                break;
59        }
60        return launched;
61    }
62
63    /**
64     * Launch screen to confirm the existing lock pattern.
65     * @param message shown in header of ConfirmLockPattern if not null
66     * @param details shown in footer of ConfirmLockPattern if not null
67     * @see #onActivityResult(int, int, android.content.Intent)
68     * @return true if we launched an activity to confirm pattern
69     */
70    private boolean confirmPattern(int request, CharSequence message, CharSequence details) {
71        if (!mLockPatternUtils.isLockPatternEnabled() || !mLockPatternUtils.savedPatternExists()) {
72            return false;
73        }
74        final Intent intent = new Intent();
75        // supply header and footer text in the intent
76        intent.putExtra(ConfirmLockPattern.HEADER_TEXT, message);
77        intent.putExtra(ConfirmLockPattern.FOOTER_TEXT, details);
78        intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPattern");
79        mActivity.startActivityForResult(intent, request);
80        return true;
81    }
82
83    /**
84     * Launch screen to confirm the existing lock password.
85     * @see #onActivityResult(int, int, android.content.Intent)
86     * @return true if we launched an activity to confirm password
87     */
88    private boolean confirmPassword(int request) {
89        if (!mLockPatternUtils.isLockPasswordEnabled()) return false;
90        final Intent intent = new Intent();
91        intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPassword");
92        mActivity.startActivityForResult(intent, request);
93        return true;
94    }
95
96
97}
98