ChooseLockSettingsHelper.java revision af366a3ed66dcb3c3ecb1dd101e5d8869b518598
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 * @return true if one exists and we launched an activity to confirm it 41 * @see #onActivityResult(int, int, android.content.Intent) 42 */ 43 protected boolean launchConfirmationActivity(int request) { 44 boolean launched = false; 45 switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) { 46 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: 47 launched = confirmPattern(request); 48 break; 49 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: 50 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: 51 launched = confirmPassword(request); 52 break; 53 } 54 return launched; 55 } 56 57 /** 58 * Launch screen to confirm the existing lock pattern. 59 * @see #onActivityResult(int, int, android.content.Intent) 60 * @return true if we launched an activity to confirm pattern 61 */ 62 private boolean confirmPattern(int request) { 63 if (!mLockPatternUtils.isLockPatternEnabled() || !mLockPatternUtils.savedPatternExists()) { 64 return false; 65 } 66 final Intent intent = new Intent(); 67 intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPattern"); 68 mActivity.startActivityForResult(intent, request); 69 return true; 70 } 71 72 /** 73 * Launch screen to confirm the existing lock password. 74 * @see #onActivityResult(int, int, android.content.Intent) 75 * @return true if we launched an activity to confirm password 76 */ 77 private boolean confirmPassword(int request) { 78 if (!mLockPatternUtils.isLockPasswordEnabled()) return false; 79 final Intent intent = new Intent(); 80 intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPassword"); 81 mActivity.startActivityForResult(intent, request); 82 return true; 83 } 84 85 86} 87