2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.Activity;
20 import android.app.admin.DevicePolicyManager;
21 import android.content.Intent;
23 import com.android.internal.widget.LockPatternUtils;
25 public class ChooseLockSettingsHelper {
26 private LockPatternUtils mLockPatternUtils;
27 private Activity mActivity;
29 public ChooseLockSettingsHelper(Activity activity) {
31 mLockPatternUtils = new LockPatternUtils(activity);
34 public LockPatternUtils utils() {
35 return mLockPatternUtils;
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)
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);
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);
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
69 private boolean confirmPattern(int request, CharSequence message, CharSequence details) {
70 if (!mLockPatternUtils.isLockPatternEnabled() || !mLockPatternUtils.savedPatternExists()) {
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);
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
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);