ChooseLockSettingsHelper.java revision 47d380f1e6c823cea444004cb799d4c791145cc6
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.content.Intent; 21 22import com.android.internal.widget.LockPatternUtils; 23 24public class ChooseLockSettingsHelper { 25 private LockPatternUtils mLockPatternUtils; 26 private Activity mActivity; 27 28 public ChooseLockSettingsHelper(Activity activity) { 29 mActivity = activity; 30 mLockPatternUtils = new LockPatternUtils(activity); 31 } 32 33 public LockPatternUtils utils() { 34 return mLockPatternUtils; 35 } 36 37 /** 38 * If a pattern, password or PIN exists, prompt the user before allowing them to change it. 39 * @return true if one exists and we launched an activity to confirm it 40 * @see #onActivityResult(int, int, android.content.Intent) 41 */ 42 protected boolean launchConfirmationActivity(int request) { 43 boolean launched = false; 44 switch (mLockPatternUtils.getPasswordMode()) { 45 case LockPatternUtils.MODE_PATTERN: 46 launched = confirmPattern(request); 47 break; 48 case LockPatternUtils.MODE_PIN: 49 case LockPatternUtils.MODE_PASSWORD: 50 launched = confirmPassword(request); 51 break; 52 } 53 return launched; 54 } 55 56 /** 57 * Launch screen to confirm the existing lock pattern. 58 * @see #onActivityResult(int, int, android.content.Intent) 59 * @return true if we launched an activity to confirm pattern 60 */ 61 private boolean confirmPattern(int request) { 62 if (!mLockPatternUtils.isLockPatternEnabled() || !mLockPatternUtils.savedPatternExists()) { 63 return false; 64 } 65 final Intent intent = new Intent(); 66 intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPattern"); 67 mActivity.startActivityForResult(intent, request); 68 return true; 69 } 70 71 /** 72 * Launch screen to confirm the existing lock password. 73 * @see #onActivityResult(int, int, android.content.Intent) 74 * @return true if we launched an activity to confirm password 75 */ 76 private boolean confirmPassword(int request) { 77 if (!mLockPatternUtils.isLockPasswordEnabled()) return false; 78 final Intent intent = new Intent(); 79 intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPassword"); 80 mActivity.startActivityForResult(intent, request); 81 return true; 82 } 83 84 85} 86