am 0b326a6f: Merge "Fix 2579923: Make changing lock screen method more discoverable." into froyo

Merge commit '0b326a6fad8caf250b61cc49b962495202562a5c' into kraken

* commit '0b326a6fad8caf250b61cc49b962495202562a5c':
  Fix 2579923: Make changing lock screen method more discoverable.
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3499a42..78c0f5b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -491,8 +491,7 @@
             android:theme="@android:style/Theme.NoTitleBar">
         </activity>
 
-        <activity android:name="ChooseLockGeneric"
-                android:theme="@android:style/Theme.NoDisplay">
+        <activity android:name="ChooseLockGeneric">
             <intent-filter>
                 <action android:name="android.app.action.SET_NEW_PASSWORD" />
                 <category android:name="android.intent.category.DEFAULT" />
@@ -500,12 +499,14 @@
         </activity>
 
         <activity android:name="ChooseLockPattern"
-                android:label="@string/lockpattern_change_lock_pattern_label">
+                android:label="@string/lockpattern_change_lock_pattern_label"
+                android:exported="false">
         </activity>
 
         <activity android:name="ChooseLockPassword"
                 android:label="@string/lockpattern_change_lock_pin_label"
-            android:theme="@android:style/Theme.NoTitleBar">
+            android:theme="@android:style/Theme.NoTitleBar"
+            android:exported="false">
         </activity>
 
         <activity android:name="ChooseLockPatternTutorial"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b4c4047..633e9a8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -514,6 +514,8 @@
     <!-- Menu item on Select time zone screen -->
     <string name="zone_list_menu_sort_by_timezone">Sort by time zone</string>
 
+    <!-- Security Settings --><skip />
+
     <!-- Main Settings screen setting option title for the item to take you the security and location screen -->
     <string name="security_settings_title">Location &amp; security</string>
     <!-- Location & security settings screen title -->
@@ -525,23 +527,49 @@
     <!-- In the security screen, the header title for settings related to  Passwords-->
     <string name="security_passwords_title">Passwords</string>
 
+    <!-- Unlock Picker Settings --><skip />
 
-    <!-- Unlock settings --><skip />
+    <!-- Security Picker --><skip />
+    <!--  Title for security picker to choose the unlock method: None/Pattern/PIN/Password -->
+    <string name="lock_settings_picker_title">Screen unlock security</string>
 
-    <!-- Title for preference that will guide the user through creating an unlock pattern -->
-    <string name="unlock_set_unlock_pattern_title">Set unlock pattern</string>
+    <!--  Main Security lock settings --><skip />
+    <!--  Title for PreferenceScreen to launch picker for security method when there is none -->
+    <string name="unlock_set_unlock_launch_picker_title">Set up screen lock</string>
+
+    <!--  Summary for PreferenceScreen to launch picker for security method when there is none -->
+    <string name="unlock_set_unlock_launch_picker_summary">Lock screen with a pattern, PIN, or password</string>
+
+    <!--  Title for PreferenceScreen to change security method: None/Pattern/PIN/Password  -->
+    <string name="unlock_set_unlock_launch_picker_change_title">Change screen lock</string>
+
+    <!--  Summary for PreferenceScreen to changeecurity method: None/Pattern/PIN/Password  -->
+    <string name="unlock_set_unlock_launch_picker_change_summary">Change or disable pattern, PIN, or password security</string>
+
+
+    <!-- Title for preference that disables unlock security -->
+    <string name="unlock_set_unlock_none_title">None</string>
+    <!-- Summary for preference that disables unlock security -->
+    <string name="unlock_set_unlock_none_summary">Disable screen unlock security</string>
+
+    <!-- Title for preference that guides the user through creating an unlock pattern -->
+    <string name="unlock_set_unlock_pattern_title">Pattern</string>
     <!-- Summary for preference that guides the user through creating an unlock pattern -->
-    <string name="unlock_set_unlock_pattern_summary">Must draw pattern to unlock screen</string>
+    <string name="unlock_set_unlock_pattern_summary">Draw pattern to unlock screen</string>
 
     <!-- Title for preference that guides the user through creating an unlock PIN (Personal Identification Number)  -->
-    <string name="unlock_set_unlock_pin_title">Set unlock PIN</string>
+    <string name="unlock_set_unlock_pin_title">PIN</string>
     <!-- Summary for preference that guides the user through creating an unlock PIN (Personal Identification Number)  -->
-    <string name="unlock_set_unlock_pin_summary">Must use a numeric PIN to unlock screen</string>
+    <string name="unlock_set_unlock_pin_summary">Enter a numeric PIN to unlock screen</string>
 
     <!-- Title for preference that guides the user through creating an unlock password -->
-    <string name="unlock_set_unlock_password_title">Set unlock password</string>
+    <string name="unlock_set_unlock_password_title">Password</string>
     <!-- Title for preference that guides the user through creating an unlock password -->
-    <string name="unlock_set_unlock_password_summary">Must use a password to unlock screen</string>
+    <string name="unlock_set_unlock_password_summary">Enter a password to unlock screen</string>
+
+    <!-- Summary for preference that has been disabled by DevicePolicyAdmin -->
+    <string name="unlock_set_unlock_disabled_summary">Disable by device policy</string>
+
 
     <!-- Title for option to turn of password/pin/pattern unlock. -->
     <string name="unlock_disable_lock_title">Turn off screen lock</string>
diff --git a/res/xml/security_settings_chooser.xml b/res/xml/security_settings_chooser.xml
index 4f5797f4..095c69f 100644
--- a/res/xml/security_settings_chooser.xml
+++ b/res/xml/security_settings_chooser.xml
@@ -21,21 +21,9 @@
         android:title="@string/lock_settings_title">
 
         <PreferenceScreen
-            android:key="unlock_set_pattern"
-            android:title="@string/unlock_set_unlock_pattern_title"
-            android:summary="@string/unlock_set_unlock_pattern_summary"
-            android:persistent="false"/>
-
-        <PreferenceScreen
-            android:key="unlock_set_pin"
-            android:title="@string/unlock_set_unlock_pin_title"
-            android:summary="@string/unlock_set_unlock_pin_summary"
-            android:persistent="false"/>
-
-        <PreferenceScreen
-            android:key="unlock_set_password"
-            android:title="@string/unlock_set_unlock_password_title"
-            android:summary="@string/unlock_set_unlock_password_summary"
+            android:key="unlock_set_or_change"
+            android:title="@string/unlock_set_unlock_launch_picker_title"
+            android:summary="@string/unlock_set_unlock_launch_picker_summary"
             android:persistent="false"/>
 
     </PreferenceCategory>
diff --git a/res/xml/security_settings_password.xml b/res/xml/security_settings_password.xml
index 9addee4..ac06711 100644
--- a/res/xml/security_settings_password.xml
+++ b/res/xml/security_settings_password.xml
@@ -21,14 +21,9 @@
         android:title="@string/lock_settings_title">
 
         <PreferenceScreen
-            android:key="unlock_method_disable"
-            android:title="@string/unlock_disable_lock_title"
-            android:summary="@string/unlock_disable_lock_password_summary"
-            android:persistent="false"/>
-
-        <PreferenceScreen
-            android:key="unlock_method_change_current"
-            android:title="@string/unlock_change_lock_password_title"
+            android:key="unlock_set_or_change"
+            android:title="@string/unlock_set_unlock_launch_picker_change_title"
+            android:summary="@string/unlock_set_unlock_launch_picker_change_summary"
             android:persistent="false"/>
 
         <CheckBoxPreference
diff --git a/res/xml/security_settings_pattern.xml b/res/xml/security_settings_pattern.xml
index 467fbd7..095828a 100644
--- a/res/xml/security_settings_pattern.xml
+++ b/res/xml/security_settings_pattern.xml
@@ -21,14 +21,9 @@
         android:title="@string/lock_settings_title">
 
         <PreferenceScreen
-            android:key="unlock_method_disable"
-            android:title="@string/unlock_disable_lock_title"
-            android:summary="@string/unlock_disable_lock_pattern_summary"
-            android:persistent="false"/>
-
-        <PreferenceScreen
-            android:key="unlock_method_change_current"
-            android:title="@string/unlock_change_lock_pattern_title"
+            android:key="unlock_set_or_change"
+            android:title="@string/unlock_set_unlock_launch_picker_change_title"
+            android:summary="@string/unlock_set_unlock_launch_picker_change_summary"
             android:persistent="false"/>
 
         <CheckBoxPreference
diff --git a/res/xml/security_settings_picker.xml b/res/xml/security_settings_picker.xml
new file mode 100644
index 0000000..cbed209
--- /dev/null
+++ b/res/xml/security_settings_picker.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+     <PreferenceCategory
+        android:key="security_picker_category"
+        android:title="@string/lock_settings_picker_title">
+
+        <PreferenceScreen
+            android:key="unlock_set_none"
+            android:title="@string/unlock_set_unlock_none_title"
+            android:summary="@string/unlock_set_unlock_none_summary"
+            android:persistent="false"/>
+
+        <PreferenceScreen
+            android:key="unlock_set_pattern"
+            android:title="@string/unlock_set_unlock_pattern_title"
+            android:summary="@string/unlock_set_unlock_pattern_summary"
+            android:persistent="false"/>
+
+        <PreferenceScreen
+            android:key="unlock_set_pin"
+            android:title="@string/unlock_set_unlock_pin_title"
+            android:summary="@string/unlock_set_unlock_pin_summary"
+            android:persistent="false"/>
+
+        <PreferenceScreen
+            android:key="unlock_set_password"
+            android:title="@string/unlock_set_unlock_password_title"
+            android:summary="@string/unlock_set_unlock_password_summary"
+            android:persistent="false"/>
+
+    </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/res/xml/security_settings_pin.xml b/res/xml/security_settings_pin.xml
index fb77714..ac06711 100644
--- a/res/xml/security_settings_pin.xml
+++ b/res/xml/security_settings_pin.xml
@@ -21,14 +21,9 @@
         android:title="@string/lock_settings_title">
 
         <PreferenceScreen
-            android:key="unlock_method_disable"
-            android:title="@string/unlock_disable_lock_title"
-            android:summary="@string/unlock_disable_lock_pin_summary"
-            android:persistent="false"/>
-
-        <PreferenceScreen
-            android:key="unlock_method_change_current"
-            android:title="@string/unlock_change_lock_pin_title"
+            android:key="unlock_set_or_change"
+            android:title="@string/unlock_set_unlock_launch_picker_change_title"
+            android:summary="@string/unlock_set_unlock_launch_picker_change_summary"
             android:persistent="false"/>
 
         <CheckBoxPreference
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index 2c611f0..7578078 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -18,52 +18,180 @@
 
 import com.android.internal.widget.LockPatternUtils;
 
-import android.app.Activity;
 import android.app.admin.DevicePolicyManager;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceScreen;
 
-public class ChooseLockGeneric extends Activity {
+public class ChooseLockGeneric extends PreferenceActivity {
+    private static final int MIN_PASSWORD_LENGTH = 4;
+    private static final String KEY_UNLOCK_SET_NONE = "unlock_set_none";
+    private static final String KEY_UNLOCK_SET_PIN = "unlock_set_pin";
+    private static final String KEY_UNLOCK_SET_PASSWORD = "unlock_set_password";
+    private static final String KEY_UNLOCK_SET_PATTERN = "unlock_set_pattern";
+    private static final int CONFIRM_EXISTING_REQUEST = 100;
+    private static final String PASSWORD_CONFIRMED = "password_confirmed";
+    private static final String CONFIRM_CREDENTIALS = "confirm_credentials";
+
     private ChooseLockSettingsHelper mChooseLockSettingsHelper;
-    DevicePolicyManager mDPM;
+    private DevicePolicyManager mDPM;
+    private boolean mPasswordConfirmed = false;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        
-        mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
+
+        mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
         mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
-        
-        final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
-        
+
+        if (savedInstanceState != null) {
+            mPasswordConfirmed = savedInstanceState.getBoolean(PASSWORD_CONFIRMED);
+        }
+
+        if (!mPasswordConfirmed) {
+            ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
+            if (!helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST)) {
+                mPasswordConfirmed = true; // no password set, so no need to confirm
+                updatePreferencesOrFinish();
+            }
+        } else {
+            updatePreferencesOrFinish();
+        }
+    }
+
+    @Override
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
+            Preference preference) {
+        final String key = preference.getKey();
+        boolean handled = true;
+        if (KEY_UNLOCK_SET_NONE.equals(key)) {
+            updateUnlockMethodAndFinish(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
+        } else if (KEY_UNLOCK_SET_PATTERN.equals(key)) {
+            updateUnlockMethodAndFinish(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
+        } else if (KEY_UNLOCK_SET_PIN.equals(key)) {
+            updateUnlockMethodAndFinish(DevicePolicyManager.PASSWORD_QUALITY_NUMERIC);
+        } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) {
+            updateUnlockMethodAndFinish(DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC);
+        } else {
+            handled = false;
+        }
+        return handled;
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        if (requestCode == CONFIRM_EXISTING_REQUEST && resultCode == RESULT_OK) {
+            mPasswordConfirmed = true;
+            updatePreferencesOrFinish();
+        } else {
+            setResult(RESULT_CANCELED);
+            finish();
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        // Saved so we don't force user to re-enter their password if configuration changes
+        outState.putBoolean(PASSWORD_CONFIRMED, mPasswordConfirmed);
+    }
+
+    private void updatePreferencesOrFinish() {
         int quality = getIntent().getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1);
         if (quality == -1) {
-            quality = lockPatternUtils.getKeyguardStoredPasswordQuality();
+            // If caller didn't specify password quality, show the UI and allow the user to choose.
+            quality = mChooseLockSettingsHelper.utils().getKeyguardStoredPasswordQuality();
+            final PreferenceScreen prefScreen = getPreferenceScreen();
+            if (prefScreen != null) {
+                prefScreen.removeAll();
+            }
+            addPreferencesFromResource(R.xml.security_settings_picker);
+            disableUnusablePreferences(mDPM.getPasswordQuality(null));
+        } else {
+            updateUnlockMethodAndFinish(quality);
         }
+    }
+
+    /***
+     * Disables preferences that are less secure than required quality.
+     *
+     * @param quality the requested quality.
+     */
+    private void disableUnusablePreferences(final int quality) {
+        final Preference picker = getPreferenceScreen().findPreference("security_picker_category");
+        final PreferenceCategory cat = (PreferenceCategory) picker;
+        final int preferenceCount = cat.getPreferenceCount();
+        for (int i = 0; i < preferenceCount; i++) {
+            Preference pref = cat.getPreference(i);
+            if (pref instanceof PreferenceScreen) {
+                final String key = ((PreferenceScreen) pref).getKey();
+                boolean enabled = true;
+                if (KEY_UNLOCK_SET_NONE.equals(key)) {
+                    enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+                } else if (KEY_UNLOCK_SET_PATTERN.equals(key)) {
+                    enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
+                } else if (KEY_UNLOCK_SET_PIN.equals(key)) {
+                    enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
+                } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) {
+                    enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC;
+                }
+                if (!enabled) {
+                    pref.setSummary(R.string.unlock_set_unlock_disabled_summary);
+                    pref.setEnabled(false);
+                }
+            }
+        }
+    }
+
+    /**
+     * Invokes an activity to change the user's pattern, password or PIN based on given quality
+     * and minimum quality specified by DevicePolicyManager. If quality is
+     * {@link DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED}, password is cleared.
+     *
+     * @param quality the desired quality. Ignored if DevicePolicyManager requires more security.
+     */
+    void updateUnlockMethodAndFinish(int quality) {
+        // Sanity check. We should never get here without confirming user's existing password first.
+        if (!mPasswordConfirmed) {
+            throw new IllegalStateException("Tried to update password without confirming first");
+        }
+
+        // Compare minimum allowed password quality and launch appropriate security setting method
         int minQuality = mDPM.getPasswordQuality(null);
         if (quality < minQuality) {
             quality = minQuality;
         }
         if (quality >= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC) {
             int minLength = mDPM.getPasswordMinimumLength(null);
-            if (minLength < 4) {
-                minLength = 4;
+            if (minLength < MIN_PASSWORD_LENGTH) {
+                minLength = MIN_PASSWORD_LENGTH;
             }
             final int maxLength = mDPM.getPasswordMaximumLength(quality);
             Intent intent = new Intent().setClass(this, ChooseLockPassword.class);
             intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, quality);
             intent.putExtra(ChooseLockPassword.PASSWORD_MIN_KEY, minLength);
             intent.putExtra(ChooseLockPassword.PASSWORD_MAX_KEY, maxLength);
+            intent.putExtra(CONFIRM_CREDENTIALS, false);
+            intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
             startActivity(intent);
-        } else {
-            boolean showTutorial = !lockPatternUtils.isPatternEverChosen();
+        } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
+            boolean showTutorial = !mChooseLockSettingsHelper.utils().isPatternEverChosen();
             Intent intent = new Intent();
             intent.setClass(this, showTutorial
                     ? ChooseLockPatternTutorial.class
                     : ChooseLockPattern.class);
+            intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
             intent.putExtra("key_lock_method", "pattern");
+            intent.putExtra(CONFIRM_CREDENTIALS, false);
             startActivity(intent);
+        } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
+            mChooseLockSettingsHelper.utils().clearLock();
+            setResult(RESULT_OK);
         }
         finish();
     }
diff --git a/src/com/android/settings/ChooseLockPassword.java b/src/com/android/settings/ChooseLockPassword.java
index 2271a31..63c7896 100644
--- a/src/com/android/settings/ChooseLockPassword.java
+++ b/src/com/android/settings/ChooseLockPassword.java
@@ -104,6 +104,8 @@
         mRequestedQuality = getIntent().getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, mRequestedQuality);
         mPasswordMinLength = getIntent().getIntExtra(PASSWORD_MIN_KEY, mPasswordMinLength);
         mPasswordMaxLength = getIntent().getIntExtra(PASSWORD_MAX_KEY, mPasswordMaxLength);
+
+        final boolean confirmCredentials = getIntent().getBooleanExtra("confirm_credentials", true);
         int minMode = mLockPatternUtils.getRequestedPasswordQuality();
         if (mRequestedQuality < minMode) {
             mRequestedQuality = minMode;
@@ -116,7 +118,9 @@
         mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
         if (savedInstanceState == null) {
             updateStage(Stage.Introduction);
-            mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
+            if (confirmCredentials) {
+                mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
+            }
         }
     }
 
diff --git a/src/com/android/settings/ChooseLockPattern.java b/src/com/android/settings/ChooseLockPattern.java
index 859d96b..786d563 100644
--- a/src/com/android/settings/ChooseLockPattern.java
+++ b/src/com/android/settings/ChooseLockPattern.java
@@ -280,11 +280,19 @@
                 R.id.topLayout);
         topLayout.setDefaultTouchRecepient(mLockPatternView);
 
+        final boolean confirmCredentials = getIntent().getBooleanExtra("confirm_credentials", true);
+
         if (savedInstanceState == null) {
-            // first launch. As a security measure, we're in NeedToConfirm mode until we know
-            // there isn't an existing password or the user confirms their password.
-            updateStage(Stage.NeedToConfirm);
-            if (!mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST)) {
+            if (confirmCredentials) {
+                // first launch. As a security measure, we're in NeedToConfirm mode until we know
+                // there isn't an existing password or the user confirms their password.
+                updateStage(Stage.NeedToConfirm);
+                boolean launchedConfirmationActivity =
+                    mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
+                if (!launchedConfirmationActivity) {
+                    updateStage(Stage.Introduction);
+                }
+            } else {
                 updateStage(Stage.Introduction);
             }
         } else {
diff --git a/src/com/android/settings/ChooseLockPatternExample.java b/src/com/android/settings/ChooseLockPatternExample.java
index 77517b9..cba88b0 100644
--- a/src/com/android/settings/ChooseLockPatternExample.java
+++ b/src/com/android/settings/ChooseLockPatternExample.java
@@ -25,7 +25,6 @@
 import android.widget.ImageView;
 
 public class ChooseLockPatternExample extends Activity implements View.OnClickListener {
-    private static final int REQUESTCODE_CHOOSE = 1;
     private static final long START_DELAY = 1000;
     protected static final String TAG = "Settings";
     private View mNextButton;
@@ -38,26 +37,26 @@
             startAnimation(mAnimation);
         }
     };
-   
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.choose_lock_pattern_example);
         initViews();
     }
-    
+
     @Override
     protected void onResume() {
         super.onResume();
         mHandler.postDelayed(mRunnable, START_DELAY);
     }
-    
+
     @Override
     protected void onPause() {
         super.onPause();
         stopAnimation(mAnimation);
     }
-    
+
     public void onClick(View v) {
         if (v == mSkipButton) {
             // Canceling, so finish all
@@ -66,37 +65,31 @@
         } else if (v == mNextButton) {
             stopAnimation(mAnimation);
             Intent intent = new Intent(this, ChooseLockPattern.class);
-            startActivityForResult(intent, REQUESTCODE_CHOOSE);
-        }
-    }
-    
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (requestCode == REQUESTCODE_CHOOSE && resultCode == ChooseLockPattern.RESULT_FINISHED) {
-            setResult(resultCode);
+            intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+            startActivity(intent);
             finish();
         }
     }
-    
+
     private void initViews() {
         mNextButton = findViewById(R.id.next_button);
         mNextButton.setOnClickListener(this);
-        
+
         mSkipButton = findViewById(R.id.skip_button);
         mSkipButton.setOnClickListener(this);
-        
+
         mImageView = (ImageView) findViewById(R.id.lock_anim);
         mImageView.setBackgroundResource(R.drawable.lock_anim);
         mImageView.setOnClickListener(this);
         mAnimation = (AnimationDrawable) mImageView.getBackground();
     }
-    
+
     protected void startAnimation(final AnimationDrawable animation) {
         if (animation != null && !animation.isRunning()) {
             animation.run();
         }
     }
-   
+
     protected void stopAnimation(final AnimationDrawable animation) {
         if (animation != null && animation.isRunning()) animation.stop();
     }
diff --git a/src/com/android/settings/ChooseLockPatternTutorial.java b/src/com/android/settings/ChooseLockPatternTutorial.java
index aa6213e..ee0019f 100644
--- a/src/com/android/settings/ChooseLockPatternTutorial.java
+++ b/src/com/android/settings/ChooseLockPatternTutorial.java
@@ -24,8 +24,6 @@
 import android.view.View;
 
 public class ChooseLockPatternTutorial extends Activity implements View.OnClickListener {
-    private static final int REQUESTCODE_EXAMPLE = 1;
-
     private View mNextButton;
     private View mSkipButton;
 
@@ -35,8 +33,8 @@
         // Don't show the tutorial if the user has seen it before.
         LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
         if (savedInstanceState == null && lockPatternUtils.isPatternEverChosen()) {
-            Intent intent = new Intent();
-            intent.setClass(this, ChooseLockPattern.class);
+            Intent intent = new Intent(this, ChooseLockPattern.class);
+            intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
             startActivity(intent);
             finish();
         } else {
@@ -58,18 +56,11 @@
             setResult(ChooseLockPattern.RESULT_FINISHED);
             finish();
         } else if (v == mNextButton) {
-            startActivityForResult(new Intent(this, ChooseLockPatternExample.class),
-                    REQUESTCODE_EXAMPLE);
-        }
-    }
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (requestCode == REQUESTCODE_EXAMPLE && resultCode == ChooseLockPattern.RESULT_FINISHED) {
-            setResult(resultCode);
+            Intent intent = new Intent(this, ChooseLockPatternExample.class);
+            intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+            startActivity(intent);
             finish();
         }
     }
-
 }
 
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 0848af9..05a655a 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -56,25 +56,15 @@
  * Gesture lock pattern settings.
  */
 public class SecuritySettings extends PreferenceActivity {
+    private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
 
-    private static final String KEY_UNLOCK_SET_PASSWORD = "unlock_set_password";
-    private static final String KEY_UNLOCK_SET_PIN = "unlock_set_pin";
-    private static final String KEY_UNLOCK_SET_PATTERN = "unlock_set_pattern";
-    private static final String KEY_UNLOCK_METHOD_CHANGE_CURRENT = "unlock_method_change_current";
-    private static final String KEY_UNLOCK_METHOD_DISABLE = "unlock_method_disable";
     // Lock Settings
     private static final String PACKAGE = "com.android.settings";
-    private static final String LOCK_PATTERN_TUTORIAL = PACKAGE + ".ChooseLockPatternTutorial";
     private static final String ICC_LOCK_SETTINGS = PACKAGE + ".IccLockSettings";
-    private static final String CHOOSE_LOCK_PATTERN = PACKAGE + ".ChooseLockPattern";
-    private static final String CHOOSE_LOCK_PIN = PACKAGE + ".ChooseLockPassword";
 
     private static final String KEY_LOCK_ENABLED = "lockenabled";
     private static final String KEY_VISIBLE_PATTERN = "visiblepattern";
     private static final String KEY_TACTILE_FEEDBACK_ENABLED = "unlock_tactile_feedback";
-    private static final String KEY_UNLOCK_METHOD = "unlock_method";
-    private static final int UPDATE_PASSWORD_REQUEST = 56;
-    private static final int CONFIRM_EXISTING_REQUEST = 57;
 
     // Encrypted File Systems constants
     private static final String PROPERTY_EFS_ENABLED = "persist.security.efs.enabled";
@@ -86,14 +76,10 @@
     private CheckBoxPreference mShowPassword;
 
     // Location Settings
-    private static final String LOCATION_CATEGORY = "location_category";
     private static final String LOCATION_NETWORK = "location_network";
     private static final String LOCATION_GPS = "location_gps";
     private static final String ASSISTED_GPS = "assisted_gps";
-
-    // Default password lengths if device policy isn't in effect. Ignored otherwise.
-    private static final int PASSWORD_MIN_LENGTH = 4;
-    private static final int PASSWORD_MAX_LENGTH = 16;
+    private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
 
     // Credential storage
     private CredentialStorage mCredentialStorage = new CredentialStorage();
@@ -113,8 +99,6 @@
     private ContentQueryMap mContentQueryMap;
     private ChooseLockSettingsHelper mChooseLockSettingsHelper;
     private LockPatternUtils mLockPatternUtils;
-    private PreferenceScreen mDisableUnlock;
-    private PreferenceScreen mChangeCurrent;
     private final class SettingsObserver implements Observer {
         public void update(Observable o, Object arg) {
             updateToggles();
@@ -176,11 +160,8 @@
             }
         }
 
-        // disable current pattern. Should be common to all unlock preference screens.
-        mDisableUnlock = (PreferenceScreen) pm.findPreference(KEY_UNLOCK_METHOD_DISABLE);
-
-        // change current. Should be common to all unlock preference screens
-        mChangeCurrent = (PreferenceScreen) pm.findPreference(KEY_UNLOCK_METHOD_CHANGE_CURRENT);
+        // set or change current. Should be common to all unlock preference screens
+        // mSetOrChange = (PreferenceScreen) pm.findPreference(KEY_UNLOCK_SET_OR_CHANGE);
 
         // visible pattern
         mVisiblePattern = (CheckBoxPreference) pm.findPreference(KEY_VISIBLE_PATTERN);
@@ -188,7 +169,6 @@
         // tactile feedback. Should be common to all unlock preference screens.
         mTactileFeedback = (CheckBoxPreference) pm.findPreference(KEY_TACTILE_FEEDBACK_ENABLED);
 
-
         int activePhoneType = TelephonyManager.getDefault().getPhoneType();
 
         // do not display SIM lock for CDMA phone
@@ -244,46 +224,6 @@
         return root;
     }
 
-    protected void handleUpdateUnlockMethod(String value) {
-        // NULL means update the current password/pattern/pin
-        if (value == null) {
-            int mode = mLockPatternUtils.getKeyguardStoredPasswordQuality();
-            if (DevicePolicyManager.PASSWORD_QUALITY_SOMETHING == mode) {
-                value = "pattern";
-            } else if (DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == mode
-                    || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == mode) {
-                value = "password";
-            } else if (DevicePolicyManager.PASSWORD_QUALITY_NUMERIC == mode) {
-                value = "pin";
-            } else {
-                throw new IllegalStateException("Unknown password mode: " + value);
-            }
-        }
-
-        if ("none".equals(value)) {
-            if (mDPM.getPasswordQuality(null) == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
-                mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
-            }
-        } else {
-            int reqMode;
-            if ("password".equals(value)) {
-                reqMode = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
-            } else if ( "pin".equals(value)) {
-                reqMode = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
-            } else {
-                reqMode = DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
-            }
-            int minMode = mDPM.getPasswordQuality(null);
-            if (reqMode < minMode) {
-                reqMode = minMode;
-            }
-            Intent intent = new Intent();
-            intent.setClass(this, ChooseLockGeneric.class);
-            intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, reqMode);
-            startActivityForResult(intent, UPDATE_PASSWORD_REQUEST);
-        }
-    }
-
     @Override
     protected void onResume() {
         super.onResume();
@@ -308,16 +248,9 @@
         final String key = preference.getKey();
 
         final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
-        if (KEY_UNLOCK_SET_PATTERN.equals(key)) {
-            handleUpdateUnlockMethod("pattern");
-        } else if (KEY_UNLOCK_SET_PIN.equals(key)) {
-            handleUpdateUnlockMethod("pin");
-        } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) {
-            handleUpdateUnlockMethod("password");
-        } else if (KEY_UNLOCK_METHOD_DISABLE.equals(key)) {
-            handleUpdateUnlockMethod("none");
-        } else if (KEY_UNLOCK_METHOD_CHANGE_CURRENT.equals(key)) {
-            handleUpdateUnlockMethod(null);
+        if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
+            Intent intent = new Intent(this, ChooseLockGeneric.class);
+            startActivityForResult(intent, SET_OR_CHANGE_LOCK_METHOD_REQUEST);
         } else if (KEY_LOCK_ENABLED.equals(key)) {
             lockPatternUtils.setLockPatternEnabled(isToggled(preference));
         } else if (KEY_VISIBLE_PATTERN.equals(key)) {
@@ -372,13 +305,6 @@
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
-
-        final boolean resultOk = resultCode == Activity.RESULT_OK;
-
-        LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
-        if ((requestCode == CONFIRM_EXISTING_REQUEST) && resultOk) {
-            lockPatternUtils.clearLock();
-        }
         createPreferenceHierarchy();
     }