Merge change I25f2afba into eclair

* changes:
  Check if a device is added to the cache before returning.
diff --git a/res/drawable-hdpi/appwidget_bg.9.png b/res/drawable-hdpi/appwidget_bg.9.png
index 78fb89a..6861664 100644
--- a/res/drawable-hdpi/appwidget_bg.9.png
+++ b/res/drawable-hdpi/appwidget_bg.9.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_settings_bluetooth.png b/res/drawable-hdpi/ic_settings_bluetooth.png
new file mode 100644
index 0000000..3d9015f
--- /dev/null
+++ b/res/drawable-hdpi/ic_settings_bluetooth.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_settings_cell_standby.png b/res/drawable-hdpi/ic_settings_cell_standby.png
new file mode 100644
index 0000000..262a860
--- /dev/null
+++ b/res/drawable-hdpi/ic_settings_cell_standby.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_settings_display.png b/res/drawable-hdpi/ic_settings_display.png
new file mode 100644
index 0000000..20568d2
--- /dev/null
+++ b/res/drawable-hdpi/ic_settings_display.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_settings_phone_idle.png b/res/drawable-hdpi/ic_settings_phone_idle.png
new file mode 100644
index 0000000..fd66f84
--- /dev/null
+++ b/res/drawable-hdpi/ic_settings_phone_idle.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_settings_voice_calls.png b/res/drawable-hdpi/ic_settings_voice_calls.png
new file mode 100644
index 0000000..3cb7e49
--- /dev/null
+++ b/res/drawable-hdpi/ic_settings_voice_calls.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_settings_wifi.png b/res/drawable-hdpi/ic_settings_wifi.png
new file mode 100644
index 0000000..b8c3eaa
--- /dev/null
+++ b/res/drawable-hdpi/ic_settings_wifi.png
Binary files differ
diff --git a/res/drawable-mdpi/appwidget_bg.9.png b/res/drawable-mdpi/appwidget_bg.9.png
index 688d131..8e7e3d7 100644
--- a/res/drawable-mdpi/appwidget_bg.9.png
+++ b/res/drawable-mdpi/appwidget_bg.9.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_bluetooth.png b/res/drawable-mdpi/ic_settings_bluetooth.png
new file mode 100644
index 0000000..8cf80c0
--- /dev/null
+++ b/res/drawable-mdpi/ic_settings_bluetooth.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_cell_standby.png b/res/drawable-mdpi/ic_settings_cell_standby.png
new file mode 100644
index 0000000..0ac7b5d
--- /dev/null
+++ b/res/drawable-mdpi/ic_settings_cell_standby.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_display.png b/res/drawable-mdpi/ic_settings_display.png
new file mode 100644
index 0000000..b676b85
--- /dev/null
+++ b/res/drawable-mdpi/ic_settings_display.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_phone_idle.png b/res/drawable-mdpi/ic_settings_phone_idle.png
new file mode 100644
index 0000000..7734b09
--- /dev/null
+++ b/res/drawable-mdpi/ic_settings_phone_idle.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_voice_calls.png b/res/drawable-mdpi/ic_settings_voice_calls.png
new file mode 100644
index 0000000..89d04d7
--- /dev/null
+++ b/res/drawable-mdpi/ic_settings_voice_calls.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_settings_wifi.png b/res/drawable-mdpi/ic_settings_wifi.png
new file mode 100644
index 0000000..e8f3129
--- /dev/null
+++ b/res/drawable-mdpi/ic_settings_wifi.png
Binary files differ
diff --git a/res/drawable/ic_power_system.png b/res/drawable/ic_power_system.png
new file mode 100755
index 0000000..cce5187
--- /dev/null
+++ b/res/drawable/ic_power_system.png
Binary files differ
diff --git a/res/layout/cstor_set_password_dialog_view.xml b/res/layout/credentials_password_dialog.xml
similarity index 62%
rename from res/layout/cstor_set_password_dialog_view.xml
rename to res/layout/credentials_password_dialog.xml
index eda317a..c23cc68 100644
--- a/res/layout/cstor_set_password_dialog_view.xml
+++ b/res/layout/credentials_password_dialog.xml
@@ -24,40 +24,37 @@
             android:layout_height="fill_parent"
             android:padding="15dip">
 
-        <TextView android:id="@+id/cstor_first_time_hint"
+        <TextView android:id="@+id/hint"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:textSize="@dimen/vpn_connect_normal_text_size"
-                android:text="@string/cstor_first_time_hint"
-                android:layout_marginBottom="10sp" />
+                android:text="@string/credentials_first_time_hint"
+                android:layout_marginBottom="10sp"
+                android:visibility="gone"/>
 
-        <TextView android:id="@+id/cstor_error"
+        <TextView android:id="@+id/error"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:textColor="@color/red"
                 android:textStyle="bold"
-                android:text="@string/cstor_password_empty_error" />
+                android:visibility="gone"/>
 
-        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-                android:id="@+id/cstor_old_password_block"
-                android:orientation="vertical"
+        <TextView android:id="@+id/old_password_prompt"
+        	android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/credentials_old_password"
+                android:visibility="gone"/>
+        <EditText android:id="@+id/old_password"
                 android:layout_width="fill_parent"
-                android:layout_height="fill_parent"
-                >
-            <TextView android:layout_width="fill_parent"
-                    android:layout_height="wrap_content"
-                    android:text="@string/cstor_old_password" />
-            <EditText android:id="@+id/cstor_old_password"
-                    android:layout_width="fill_parent"
-                    android:layout_height="wrap_content"
-                    android:password="True"
-                    android:singleLine="True"/>
-        </LinearLayout>
+                android:layout_height="wrap_content"
+                android:password="True"
+                android:singleLine="True"
+                android:visibility="gone"/>
 
         <TextView android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:text="@string/cstor_new_password" />
-        <EditText android:id="@+id/cstor_new_password"
+                android:text="@string/credentials_new_password" />
+        <EditText android:id="@+id/new_password"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:password="True"
@@ -65,8 +62,8 @@
 
         <TextView android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:text="@string/cstor_confirm_password" />
-        <EditText android:id="@+id/cstor_confirm_password"
+                android:text="@string/credentials_confirm_password" />
+        <EditText android:id="@+id/confirm_password"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:password="True"
diff --git a/res/layout/cstor_unlock_dialog_view.xml b/res/layout/credentials_unlock_dialog.xml
similarity index 81%
rename from res/layout/cstor_unlock_dialog_view.xml
rename to res/layout/credentials_unlock_dialog.xml
index 895306a..2ba2ace 100644
--- a/res/layout/cstor_unlock_dialog_view.xml
+++ b/res/layout/credentials_unlock_dialog.xml
@@ -24,20 +24,22 @@
             android:layout_height="fill_parent"
             android:padding="15dip">
 
-        <TextView android:id="@+id/cstor_access_dialog_hint_from_action"
+        <TextView android:id="@+id/hint"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:textSize="@dimen/vpn_connect_normal_text_size"
-                android:text="@string/cstor_access_dialog_hint_from_action"
-                android:layout_marginBottom="10sp" />
+                android:text="@string/credentials_unlock_hint"
+                android:layout_marginBottom="10sp"
+                android:visibility="gone"/>
 
-        <TextView android:id="@+id/cstor_error"
+        <TextView android:id="@+id/error"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:textColor="@color/red"
-                android:textStyle="bold" />
+                android:textStyle="bold"
+                android:visibility="gone"/>
 
-        <EditText android:id="@+id/cstor_password"
+        <EditText android:id="@+id/old_password"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:password="True"
diff --git a/res/layout/cstor_name_credential_dialog_view.xml b/res/layout/cstor_name_credential_dialog_view.xml
deleted file mode 100644
index 33688bd..0000000
--- a/res/layout/cstor_name_credential_dialog_view.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content">
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-            android:orientation="vertical"
-            android:layout_width="fill_parent"
-            android:layout_height="fill_parent"
-            android:padding="15dip">
-
-        <TextView android:id="@+id/cstor_name_credential_hint"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:textSize="@dimen/vpn_connect_normal_text_size"
-                android:text="@string/cstor_name_credential_hint"
-                android:layout_marginBottom="10sp" />
-
-        <TextView android:id="@+id/cstor_error"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:textColor="@color/red"
-                android:textStyle="bold" />
-
-        <TextView android:id="@+id/cstor_credential_name_title"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:text="@string/cstor_credential_name" />
-        <EditText android:id="@+id/cstor_credential_name"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:singleLine="True"/>
-
-        <LinearLayout android:id="@+id/cstor_credential_password_container"
-                xmlns:android="http://schemas.android.com/apk/res/android"
-                android:orientation="vertical"
-                android:layout_width="fill_parent"
-                android:layout_height="fill_parent"
-                android:padding="0dip">
-            <TextView android:layout_width="fill_parent"
-                    android:layout_height="wrap_content"
-                    android:text="@string/cstor_credential_password" />
-            <EditText android:id="@+id/cstor_credential_password"
-                    android:layout_width="fill_parent"
-                    android:layout_height="wrap_content"
-                    android:password="True"
-                    android:singleLine="True"/>
-        </LinearLayout>
-
-        <TextView android:id="@+id/cstor_credential_info_title"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:text="@string/cstor_credential_info" />
-        <TextView android:id="@+id/cstor_credential_info"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content" />
-
-    </LinearLayout>
-</ScrollView>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 68b194a..b01608a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2077,72 +2077,50 @@
     <string name="vpn_secret_not_set">(not set)</string>
 
     <!-- Title of preference group for credential storage settings -->
-    <string name="cstor_settings_category">Credential storage</string>
+    <string name="credentials_category">Credential storage</string>
     <!-- Title of preference to enable/dislable access to credential storage -->
-    <string name="cstor_access_title">Use secure credentials</string>
+    <string name="credentials_access">Use secure credentials</string>
     <!-- Summary of preference to enable/dislable access to credential storage -->
-    <string name="cstor_access_summary">Allow applications to access secure certificates and other credentials</string>
+    <string name="credentials_access_summary">Allow applications to access secure certificates and other credentials</string>
     <!-- Title of dialog to enable/dislable access to credential storage -->
-    <string name="cstor_access_dialog_title">Enter password</string>
-    <!-- Description of dialog to enable/dislable access to credential storage from an action that requires the credential storage -->
-    <string name="cstor_access_dialog_hint_from_action">Enter the credential storage password.</string>
-
-    <!-- Title of preference to install p12 cert from SD card -->
-    <string name="cstor_cert_install_title">Install from SD card</string>
-    <!-- Summary of preference to install p12 cert from SD card -->
-    <string name="cstor_cert_install_summary">Install encrypted certificates from SD card</string>
+    <string name="credentials_unlock">Enter password</string>
+    <!-- Description of dialog to enable/dislable access to credential storage -->
+    <string name="credentials_unlock_hint">Enter the credential storage password.</string>
+    <!-- Title of preference to install certificates from SD card -->
+    <string name="credentials_install_certificates">Install from SD card</string>
+    <!-- Summary of preference to install certificates from SD card -->
+    <string name="credentials_install_certificates_summary">Install encrypted certificates from SD card</string>
     <!-- Title of preference to set storage password -->
-    <string name="cstor_set_passwd_title">Set password</string>
+    <string name="credentials_set_password">Set password</string>
     <!-- Summary of preference to set storage password -->
-    <string name="cstor_set_passwd_summary">Set or change the credential storage password</string>
-    <!-- Title of dialog to set storage password -->
-    <string name="cstor_set_passwd_dialog_title">Set password</string>
-
-    <!-- Title of preference to reset storage -->
-    <string name="cstor_reset_title">Clear storage</string>
-    <!-- Summary of preference to reset storage -->
-    <string name="cstor_reset_summary">Clear credential storage of all contents and reset its password</string>
-    <string name="cstor_reset_hint">Are you sure you want to delete all credentials and reset the credential storage password?</string>
-
-    <!-- Title of dialog to name a credential -->
-    <string name="cstor_name_credential_dialog_title">Name the certificate</string>
-    <!-- Description for the credential name input box -->
-    <string name="cstor_credential_name">Certificate name:</string>
-    <!-- Title of the credential info -->
-    <!-- Description for the credential password input box -->
-    <string name="cstor_credential_password">Password to extract the certificate:</string>
-    <string name="cstor_credential_info">Certificate details:</string>
-    <string name="cstor_name_credential_hint">The name can contain only letters and numbers.</string>
-
-
+    <string name="credentials_set_password_summary">Set or change the credential storage password</string>
+    <!-- Title of preference to reset credential storage -->
+    <string name="credentials_reset">Clear storage</string>
+    <!-- Summary of preference to reset credential storage -->
+    <string name="credentials_reset_summary">Clear credential storage of all contents and reset its password</string>
+    <!-- Description of dialog to reset the credential storage -->
+    <string name="credentials_reset_hint">Are you sure you want to delete all credentials and reset the credential storage password?</string>
     <!-- Description for the old-password input box -->
-    <string name="cstor_old_password">Current password:</string>
+    <string name="credentials_old_password">Current password:</string>
     <!-- Description for the new-password input box -->
-    <string name="cstor_new_password">New password:</string>
+    <string name="credentials_new_password">New password:</string>
     <!-- Description for the confirm-new-password input box -->
-    <string name="cstor_confirm_password">Confirm new password:</string>
+    <string name="credentials_confirm_password">Confirm new password:</string>
     <!-- Description when user set up the storage for the very first time -->
-    <string name="cstor_first_time_hint">Set a password for the credential storage (at least 8 characters).</string>
-    <!-- Description when user set up the storage for the very first time from an action that requires the credential storage-->
-    <string name="cstor_first_time_hint_from_action">Set a password for the credential storage.</string>
-    <string name="cstor_password_error">Please enter the correct password.</string>
-    <string name="cstor_password_error_reset_warning">Please enter the correct password. You have one more try to enter the correct password before the credential storage is erased.</string>
-    <string name="cstor_password_error_reset_warning_plural">Please enter the correct password. You have <xliff:g id="number" example="5">%d</xliff:g> more tries to enter the correct password before the credential storage is erased.</string>
-    <string name="cstor_passwords_error">Passwords do not match.</string>
-    <string name="cstor_passwords_empty_error">You must enter and confirm a password.</string>
-    <string name="cstor_password_empty_error">Please enter the password.</string>
-    <string name="cstor_password_verification_error">Please enter the password again. The password must have at least 8 characters.</string>
-    <string name="cstor_name_empty_error">Please enter a name.</string>
-    <string name="cstor_name_char_error">Please enter a name that contains only letters and numbers.</string>
-    <string name="cstor_storage_error">Unable to save the certificate. Click OK to retry.</string>
-    <string name="cstor_unable_to_save_cert">Unable to save the certificate. The credential storage is not enabled or properly initialized.</string>
-    <string name="cstor_cert_not_saved">The certificate is not saved.</string>
-    <string name="cstor_is_reset">The credential storage is erased.</string>
-
+    <string name="credentials_first_time_hint">Set a password for the credential storage (at least 8 characters).</string>
+    <string name="credentials_wrong_password">Please enter the correct password.</string>
+    <string name="credentials_reset_warning">Please enter the correct password. You have one more try to enter the correct password before the credential storage is erased.</string>
+    <string name="credentials_reset_warning_plural">Please enter the correct password. You have <xliff:g id="number" example="5">%1$d</xliff:g> more tries to enter the correct password before the credential storage is erased.</string>
+    <string name="credentials_passwords_mismatch">Passwords do not match.</string>
+    <string name="credentials_passwords_empty">You must enter and confirm a password.</string>
+    <string name="credentials_password_empty">Please enter the password.</string>
+    <string name="credentials_password_too_short">The password must have at least 8 characters.</string>
     <!-- toast message -->
-    <string name="cstor_is_enabled">Credential storage is enabled.</string>
+    <string name="credentials_erased">The credential storage is erased.</string>
     <!-- toast message -->
-    <string name="cstor_is_added"><xliff:g id="credential">%s</xliff:g> is added.</string>
+    <string name="credentials_enabled">Credential storage is enabled.</string>
+    <!-- toast message -->
+    <string name="credentials_disabled">Credential storage is disabled.</string>
 
     <!-- Sound settings screen, setting check box label -->
     <string name="emergency_tone_title">Emergency tone</string>
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 5a4d26b..fcacccc 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -93,7 +93,7 @@
     private static final int CSTOR_UNLOCK_DIALOG = 3;
     private static final int CSTOR_RESET_DIALOG = 4;
 
-    private CstorHelper mCstorHelper = new CstorHelper();
+    private CredentialStorage mCredentialStorage = new CredentialStorage();
 
     private CheckBoxPreference mNetwork;
     private CheckBoxPreference mGps;
@@ -132,7 +132,7 @@
         mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null);
         mContentQueryMap.addObserver(new SettingsObserver());
 
-        mCstorHelper.handleIntent(getIntent());
+        mCredentialStorage.handleIntent(getIntent());
     }
 
     private PreferenceScreen createPreferenceHierarchy() {
@@ -203,10 +203,10 @@
         passwordsCat.addPreference(showPassword);
 
         // Credential storage
-        PreferenceCategory credStoreCat = new PreferenceCategory(this);
-        credStoreCat.setTitle(R.string.cstor_settings_category);
-        root.addPreference(credStoreCat);
-        mCstorHelper.createPreferences(credStoreCat);
+        PreferenceCategory credentialsCat = new PreferenceCategory(this);
+        credentialsCat.setTitle(R.string.credentials_category);
+        root.addPreference(credentialsCat);
+        mCredentialStorage.createPreferences(credentialsCat);
 
         return root;
     }
@@ -232,7 +232,7 @@
         mShowPassword.setChecked(Settings.System.getInt(getContentResolver(),
                 Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
 
-        mCstorHelper.resume();
+        mCredentialStorage.resume();
     }
 
     @Override
@@ -341,138 +341,159 @@
 
     @Override
     protected Dialog onCreateDialog(int id) {
-        switch (id) {
-            case CSTOR_INIT_DIALOG:
-            case CSTOR_CHANGE_PASSWORD_DIALOG:
-                return mCstorHelper.createSetPasswordDialog(id);
-
-            case CSTOR_UNLOCK_DIALOG:
-                return mCstorHelper.createUnlockDialog();
-
-            case CSTOR_RESET_DIALOG:
-                return mCstorHelper.createResetDialog();
-
-            default:
-                return null;
-        }
+        return mCredentialStorage.createDialog(id);
     }
 
-    private class CstorHelper implements DialogInterface.OnClickListener,
-            DialogInterface.OnDismissListener {
-        private KeyStore mKeyStore = KeyStore.getInstance();
-        private int mState;
+    private class CredentialStorage implements DialogInterface.OnClickListener,
+            DialogInterface.OnDismissListener, Preference.OnPreferenceChangeListener,
+            Preference.OnPreferenceClickListener {
+        private static final int MINIMUM_PASSWORD_LENGTH = 8;
+        private static final int UNLOCK_DIALOG = 1;
+        private static final int PASSWORD_DIALOG = 2;
+        private static final int RESET_DIALOG = 3;
 
-        private View mView;
+        private KeyStore mKeyStore = KeyStore.getInstance();
+        private int mState = mKeyStore.test();
         private int mDialogId;
-        private boolean mRetry;
+        private boolean mSubmit;
+
         private CheckBoxPreference mAccessCheckBox;
+        private Preference mInstallButton;
+        private Preference mPasswordButton;
         private Preference mResetButton;
 
         private Intent mExternalIntent;
 
-        CstorHelper() {
-            mState = mKeyStore.test();
-        }
-
         void handleIntent(Intent intent) {
-            if (intent == null) return;
-            String action = intent.getAction();
-
-            if (Credentials.UNLOCK_ACTION.equals(action)) {
-                mExternalIntent = intent;
-                showCstorDialog(mState == KeyStore.UNINITIALIZED
-                        ? CSTOR_INIT_DIALOG : CSTOR_UNLOCK_DIALOG);
-            }
-        }
-
-        void resume() {
-            if (mExternalIntent != null) return;
-            updatePreferences(mKeyStore.test());
-        }
-
-        private void updatePreferences(int state) {
-            mAccessCheckBox.setEnabled(state != KeyStore.UNINITIALIZED);
-            mAccessCheckBox.setChecked(state == KeyStore.NO_ERROR);
-            mResetButton.setEnabled(state != KeyStore.UNINITIALIZED);
-
-            // Show a toast message if the state is changed.
-            if (mState == state) return;
-            if (state == KeyStore.NO_ERROR) {
-                Toast.makeText(SecuritySettings.this, R.string.cstor_is_enabled,
-                        Toast.LENGTH_SHORT).show();
-            } else if (state == KeyStore.UNINITIALIZED) {
-                Toast.makeText(SecuritySettings.this, R.string.cstor_is_reset,
-                        Toast.LENGTH_LONG).show();
-            }
-            // TODO: disabled?
-            mState = state;
-        }
-
-        private void lockCstor() {
-            mKeyStore.lock();
-            updatePreferences(KeyStore.LOCKED);
-        }
-
-        private int unlockCstor(String passwd) {
-            mKeyStore.unlock(passwd);
-            return mKeyStore.getLastError();
-        }
-
-        private int changeCstorPassword(String oldPasswd, String newPasswd) {
-            mKeyStore.password(oldPasswd, newPasswd);
-            return mKeyStore.getLastError();
-        }
-
-        private void initCstor(String passwd) {
-            mKeyStore.password(passwd);
-            updatePreferences(KeyStore.NO_ERROR);
-        }
-
-        private void resetCstor() {
-            mKeyStore.reset();
-            updatePreferences(KeyStore.UNINITIALIZED);
-        }
-
-        private void showCstorDialog(int dialogId) {
-            mDialogId = dialogId;
-            mRetry = false;
-            showDialog(dialogId);
-        }
-
-        public void onClick(DialogInterface dialog, int which) {
-            if (which == DialogInterface.BUTTON_NEGATIVE) return;
-
-            switch (mDialogId) {
-                case CSTOR_INIT_DIALOG:
-                case CSTOR_CHANGE_PASSWORD_DIALOG:
-                    mRetry = !checkPasswords((Dialog) dialog);
-                    break;
-
-                case CSTOR_UNLOCK_DIALOG:
-                    mRetry = !checkPassword((Dialog) dialog);
-                    break;
-
-                case CSTOR_RESET_DIALOG:
-                    resetCstor();
-                    break;
-            }
-        }
-
-        public void onDismiss(DialogInterface dialog) {
-            if (mRetry) {
-                showCstorDialog(mDialogId);
-            } else {
-                removeDialog(mDialogId);
-                updatePreferences(mState); // may revert checkbox
-
-                if (mExternalIntent != null) {
-                    finish();
+            if (intent != null) {
+                if (Credentials.UNLOCK_ACTION.equals(intent.getAction())) {
+                    mExternalIntent = intent;
+                    showDialog((mState == KeyStore.UNINITIALIZED) ?
+                            PASSWORD_DIALOG : UNLOCK_DIALOG);
                 }
             }
         }
 
-        // returns false if there is no error.
-        private boolean checkError(int error) {
+        void resume() {
+            mState = mKeyStore.test();
+            updatePreferences(mState);
+        }
+
+        Dialog createDialog(int id) {
+            mDialogId = id;
+            switch (id) {
+                case UNLOCK_DIALOG:
+                    return createUnlockDialog();
+                case PASSWORD_DIALOG:
+                    return createPasswordDialog();
+                case RESET_DIALOG:
+                    return createResetDialog();
+            }
+            return null;
+        }
+
+        private void initialize(String password) {
+            mKeyStore.password(password);
+            updatePreferences(KeyStore.NO_ERROR);
+        }
+
+        private void reset() {
+            mKeyStore.reset();
+            updatePreferences(KeyStore.UNINITIALIZED);
+        }
+
+        private void lock() {
+            mKeyStore.lock();
+            updatePreferences(KeyStore.LOCKED);
+        }
+
+        private int unlock(String password) {
+            mKeyStore.unlock(password);
+            return mKeyStore.getLastError();
+        }
+
+        private int changePassword(String oldPassword, String newPassword) {
+            mKeyStore.password(oldPassword, newPassword);
+            return mKeyStore.getLastError();
+        }
+
+        public boolean onPreferenceChange(Preference preference, Object value) {
+            if (preference == mAccessCheckBox) {
+                if ((Boolean) value) {
+                    showDialog((mState == KeyStore.UNINITIALIZED) ?
+                            PASSWORD_DIALOG : UNLOCK_DIALOG);
+                } else {
+                    lock();
+                }
+                return true;
+            }
+            return false;
+        }
+
+        public boolean onPreferenceClick(Preference preference) {
+            if (preference == mInstallButton) {
+                Credentials.getInstance().installFromSdCard(SecuritySettings.this);
+            } else if (preference == mPasswordButton) {
+                showDialog(PASSWORD_DIALOG);
+            } else if (preference == mResetButton) {
+                showDialog(RESET_DIALOG);
+            } else {
+                return false;
+            }
+            return true;
+        }
+
+        public void onClick(DialogInterface dialog, int button) {
+            mSubmit = (button == DialogInterface.BUTTON_POSITIVE);
+            if (button == DialogInterface.BUTTON_NEUTRAL) {
+                reset();
+            }
+        }
+
+        public void onDismiss(DialogInterface dialog) {
+            if (mSubmit && !isFinishing()) {
+                mSubmit = false;
+                if (!checkPassword((Dialog) dialog)) {
+                    showDialog(mDialogId);
+                    return;
+                }
+            }
+            removeDialog(mDialogId);
+            updatePreferences(mState);
+            if (mExternalIntent != null) {
+                mExternalIntent = null;
+                finish();
+            }
+        }
+
+        // Return true if there is no error.
+        private boolean checkPassword(Dialog dialog) {
+            String oldPassword = getText(dialog, R.id.old_password);
+            String newPassword = getText(dialog, R.id.new_password);
+            String confirmPassword = getText(dialog, R.id.confirm_password);
+
+            if (oldPassword != null && oldPassword.length() == 0) {
+                showError(dialog, R.string.credentials_password_empty);
+                return false;
+            } else if (newPassword == null) {
+                return !checkError(dialog, unlock(oldPassword));
+            } else if (newPassword.length() == 0 || confirmPassword.length() == 0) {
+                showError(dialog, R.string.credentials_passwords_empty);
+            } else if (newPassword.length() < MINIMUM_PASSWORD_LENGTH) {
+                showError(dialog, R.string.credentials_password_too_short);
+            } else if (!newPassword.equals(confirmPassword)) {
+                showError(dialog, R.string.credentials_passwords_mismatch);
+            } else if (oldPassword == null) {
+                initialize(newPassword);
+                return true;
+            } else {
+                return !checkError(dialog, changePassword(oldPassword, newPassword));
+            }
+            return false;
+        }
+
+        // Return false if there is no error.
+        private boolean checkError(Dialog dialog, int error) {
             if (error == KeyStore.NO_ERROR) {
                 updatePreferences(KeyStore.NO_ERROR);
                 return false;
@@ -486,199 +507,126 @@
             }
             int count = error - KeyStore.WRONG_PASSWORD + 1;
             if (count > 3) {
-                showError(R.string.cstor_password_error);
-                return true;
-            }
-            TextView v = showError(R.string.cstor_password_error_reset_warning);
-            if (count == 1) {
-                v.setText(R.string.cstor_password_error_reset_warning);
+                showError(dialog, R.string.credentials_wrong_password);
+            } else if (count == 1) {
+                showError(dialog, R.string.credentials_reset_warning);
             } else {
-                String format = getString(
-                        R.string.cstor_password_error_reset_warning_plural);
-                v.setText(String.format(format, count));
+                showError(dialog, R.string.credentials_reset_warning_plural, count);
             }
             return true;
         }
 
-        // returns true if the password is correct
-        private boolean checkPassword(Dialog d) {
-            hideError();
-
-            String passwd = getText(R.id.cstor_password);
-            if (TextUtils.isEmpty(passwd)) {
-                showError(R.string.cstor_password_empty_error);
-                return false;
-            }
-
-            return !checkError(unlockCstor(passwd));
+        private String getText(Dialog dialog, int viewId) {
+            TextView view = (TextView) dialog.findViewById(viewId);
+            return (view == null || view.getVisibility() == View.GONE) ? null :
+                            view.getText().toString();
         }
 
-        // returns true if the passwords are correct
-        private boolean checkPasswords(Dialog d) {
-            hideError();
-
-            String oldPasswd = getText(R.id.cstor_old_password);
-            String newPasswd = getText(R.id.cstor_new_password);
-            String confirmPasswd = getText(R.id.cstor_confirm_password);
-
-            if ((mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG)
-                    && TextUtils.isEmpty(oldPasswd)) {
-                showError(R.string.cstor_password_empty_error);
-            } else if (TextUtils.isEmpty(newPasswd)
-                    || TextUtils.isEmpty(confirmPasswd)) {
-                showError(R.string.cstor_passwords_empty_error);
-            } else if (newPasswd.length() < CSTOR_MIN_PASSWORD_LENGTH) {
-                showError(R.string.cstor_password_verification_error);
-            } else if (!newPasswd.equals(confirmPasswd)) {
-                showError(R.string.cstor_passwords_error);
-            } else {
-                if (mDialogId == CSTOR_CHANGE_PASSWORD_DIALOG) {
-                    return !checkError(changeCstorPassword(oldPasswd, newPasswd));
+        private void showError(Dialog dialog, int stringId, Object... formatArgs) {
+            TextView view = (TextView) dialog.findViewById(R.id.error);
+            if (view != null) {
+                if (formatArgs == null || formatArgs.length == 0) {
+                    view.setText(stringId);
                 } else {
-                    initCstor(newPasswd);
-                    return true;
+                    view.setText(dialog.getContext().getString(stringId, formatArgs));
                 }
+                view.setVisibility(View.VISIBLE);
             }
-            return false;
-        }
-
-        private TextView showError(int messageId) {
-            TextView v = (TextView) mView.findViewById(R.id.cstor_error);
-            v.setText(messageId);
-            if (v != null) v.setVisibility(View.VISIBLE);
-            return v;
-        }
-
-        private void hideError() {
-            hide(R.id.cstor_error);
-        }
-
-        private void hide(int viewId) {
-            View v = mView.findViewById(viewId);
-            if (v != null) v.setVisibility(View.GONE);
-        }
-
-        private String getText(int viewId) {
-            return ((TextView) mView.findViewById(viewId)).getText().toString();
         }
 
         private void createPreferences(PreferenceCategory category) {
             mAccessCheckBox = new CheckBoxPreference(SecuritySettings.this);
-            mAccessCheckBox.setTitle(R.string.cstor_access_title);
-            mAccessCheckBox.setSummary(R.string.cstor_access_summary);
-            mAccessCheckBox.setOnPreferenceChangeListener(
-                    new Preference.OnPreferenceChangeListener() {
-                        public boolean onPreferenceChange(
-                                Preference pref, Object value) {
-                            if (((Boolean) value)) {
-                                showCstorDialog(CSTOR_UNLOCK_DIALOG);
-                            } else {
-                                lockCstor();
-                            }
-                            return true;
-                        }
-                    });
+            mAccessCheckBox.setTitle(R.string.credentials_access);
+            mAccessCheckBox.setSummary(R.string.credentials_access_summary);
+            mAccessCheckBox.setOnPreferenceChangeListener(this);
             category.addPreference(mAccessCheckBox);
 
-            Preference install = new Preference(SecuritySettings.this);
-            install.setTitle(R.string.cstor_cert_install_title);
-            install.setSummary(R.string.cstor_cert_install_summary);
-            install.setOnPreferenceClickListener(
-                    new Preference.OnPreferenceClickListener() {
-                        public boolean onPreferenceClick(Preference pref) {
-                            Credentials.getInstance().installFromSdCard(
-                                            SecuritySettings.this);
-                            return true;
-                        }
-                    });
-            category.addPreference(install);
+            mInstallButton = new Preference(SecuritySettings.this);
+            mInstallButton.setTitle(R.string.credentials_install_certificates);
+            mInstallButton.setSummary(R.string.credentials_install_certificates_summary);
+            mInstallButton.setOnPreferenceClickListener(this);
+            category.addPreference(mInstallButton);
 
-            Preference password = new Preference(SecuritySettings.this);
-            password.setTitle(R.string.cstor_set_passwd_title);
-            password.setSummary(R.string.cstor_set_passwd_summary);
-            password.setOnPreferenceClickListener(
-                    new Preference.OnPreferenceClickListener() {
-                        public boolean onPreferenceClick(Preference pref) {
-                            showCstorDialog(mState == KeyStore.UNINITIALIZED
-                                    ? CSTOR_INIT_DIALOG
-                                    : CSTOR_CHANGE_PASSWORD_DIALOG);
-                            return true;
-                        }
-                    });
-            category.addPreference(password);
+            mPasswordButton = new Preference(SecuritySettings.this);
+            mPasswordButton.setTitle(R.string.credentials_set_password);
+            mPasswordButton.setSummary(R.string.credentials_set_password_summary);
+            mPasswordButton.setOnPreferenceClickListener(this);
+            category.addPreference(mPasswordButton);
 
             mResetButton = new Preference(SecuritySettings.this);
-            mResetButton.setTitle(R.string.cstor_reset_title);
-            mResetButton.setSummary(R.string.cstor_reset_summary);
-            mResetButton.setOnPreferenceClickListener(
-                    new Preference.OnPreferenceClickListener() {
-                        public boolean onPreferenceClick(Preference pref) {
-                            showCstorDialog(CSTOR_RESET_DIALOG);
-                            return true;
-                        }
-                    });
+            mResetButton.setTitle(R.string.credentials_reset);
+            mResetButton.setSummary(R.string.credentials_reset_summary);
+            mResetButton.setOnPreferenceClickListener(this);
             category.addPreference(mResetButton);
+        }
 
-            updatePreferences(mState);
+        private void updatePreferences(int state) {
+            mAccessCheckBox.setEnabled(state != KeyStore.UNINITIALIZED);
+            mAccessCheckBox.setChecked(state == KeyStore.NO_ERROR);
+            mResetButton.setEnabled(state != KeyStore.UNINITIALIZED);
+
+            // Show a toast message if the state is changed.
+            if (mState == state) {
+                return;
+            } else if (state == KeyStore.NO_ERROR) {
+                Toast.makeText(SecuritySettings.this, R.string.credentials_enabled,
+                        Toast.LENGTH_SHORT).show();
+            } else if (state == KeyStore.UNINITIALIZED) {
+                Toast.makeText(SecuritySettings.this, R.string.credentials_erased,
+                        Toast.LENGTH_SHORT).show();
+            } else if (state == KeyStore.LOCKED) {
+                Toast.makeText(SecuritySettings.this, R.string.credentials_disabled,
+                        Toast.LENGTH_SHORT).show();
+            }
+            mState = state;
         }
 
         private Dialog createUnlockDialog() {
-            mView = View.inflate(SecuritySettings.this,
-                    R.layout.cstor_unlock_dialog_view, null);
-            hideError();
+            View view = View.inflate(SecuritySettings.this,
+                    R.layout.credentials_unlock_dialog, null);
 
             // show extra hint only when the action comes from outside
-            if (mExternalIntent == null) {
-                hide(R.id.cstor_access_dialog_hint_from_action);
+            if (mExternalIntent != null) {
+                view.findViewById(R.id.hint).setVisibility(View.VISIBLE);
             }
 
-            Dialog d = new AlertDialog.Builder(SecuritySettings.this)
-                    .setView(mView)
-                    .setTitle(R.string.cstor_access_dialog_title)
+            Dialog dialog = new AlertDialog.Builder(SecuritySettings.this)
+                    .setView(view)
+                    .setTitle(R.string.credentials_unlock)
                     .setPositiveButton(android.R.string.ok, this)
                     .setNegativeButton(android.R.string.cancel, this)
                     .create();
-            d.setOnDismissListener(this);
-            return d;
+            dialog.setOnDismissListener(this);
+            return dialog;
         }
 
-        private Dialog createSetPasswordDialog(int id) {
-            mView = View.inflate(SecuritySettings.this,
-                    R.layout.cstor_set_password_dialog_view, null);
-            hideError();
+        private Dialog createPasswordDialog() {
+            View view = View.inflate(SecuritySettings.this,
+                    R.layout.credentials_password_dialog, null);
 
-            switch (id) {
-                case CSTOR_INIT_DIALOG:
-                    mView.findViewById(R.id.cstor_old_password_block)
-                            .setVisibility(View.GONE);
-                    break;
-
-                case CSTOR_CHANGE_PASSWORD_DIALOG:
-                    mView.findViewById(R.id.cstor_first_time_hint)
-                            .setVisibility(View.GONE);
-                    break;
-
-                default:
-                    throw new RuntimeException(
-                            "Unknown dialog id: " + mDialogId);
+            if (mState == KeyStore.UNINITIALIZED) {
+                view.findViewById(R.id.hint).setVisibility(View.VISIBLE);
+            } else {
+                view.findViewById(R.id.old_password_prompt).setVisibility(View.VISIBLE);
+                view.findViewById(R.id.old_password).setVisibility(View.VISIBLE);
             }
 
-            Dialog d = new AlertDialog.Builder(SecuritySettings.this)
-                    .setView(mView)
-                    .setTitle(R.string.cstor_set_passwd_dialog_title)
+            Dialog dialog = new AlertDialog.Builder(SecuritySettings.this)
+                    .setView(view)
+                    .setTitle(R.string.credentials_set_password)
                     .setPositiveButton(android.R.string.ok, this)
                     .setNegativeButton(android.R.string.cancel, this)
                     .create();
-            d.setOnDismissListener(this);
-            return d;
+            dialog.setOnDismissListener(this);
+            return dialog;
         }
 
         private Dialog createResetDialog() {
             return new AlertDialog.Builder(SecuritySettings.this)
                     .setTitle(android.R.string.dialog_alert_title)
                     .setIcon(android.R.drawable.ic_dialog_alert)
-                    .setMessage(R.string.cstor_reset_hint)
-                    .setPositiveButton(getString(android.R.string.ok), this)
+                    .setMessage(R.string.credentials_reset_hint)
+                    .setNeutralButton(getString(android.R.string.ok), this)
                     .setNegativeButton(getString(android.R.string.cancel), this)
                     .create();
         }
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index 237e4ab..5b0218f 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -32,15 +32,15 @@
     private static final String TAG = "BluetoothDevicePreference";
 
     private static int sDimAlpha = Integer.MIN_VALUE;
-    
+
     private CachedBluetoothDevice mCachedDevice;
-    
+
     /**
      * Cached local copy of whether the device is busy. This is only updated
      * from {@link #onDeviceAttributesChanged(CachedBluetoothDevice)}.
-     */ 
+     */
     private boolean mIsBusy;
-    
+
     public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
         super(context);
 
@@ -49,16 +49,16 @@
             context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
             sDimAlpha = (int) (outValue.getFloat() * 255);
         }
-            
+
         mCachedDevice = cachedDevice;
-        
+
         setLayoutResource(R.layout.preference_bluetooth);
-        
+
         cachedDevice.registerCallback(this);
-        
+
         onDeviceAttributesChanged(cachedDevice);
     }
-    
+
     public CachedBluetoothDevice getCachedDevice() {
         return mCachedDevice;
     }
@@ -75,9 +75,9 @@
          * The preference framework takes care of making sure the value has
          * changed before proceeding.
          */
-        
+
         setTitle(mCachedDevice.getName());
-        
+
         /*
          * TODO: Showed "Paired" even though it was "Connected". This may be
          * related to BluetoothHeadset not bound to the actual
@@ -87,10 +87,10 @@
 
         // Used to gray out the item
         mIsBusy = mCachedDevice.isBusy();
-        
+
         // Data has changed
         notifyChanged();
-        
+
         // This could affect ordering, so notify that also
         notifyHierarchyChanged();
     }
@@ -113,7 +113,7 @@
 
         ImageView btClass = (ImageView) view.findViewById(R.id.btClass);
         btClass.setImageResource(mCachedDevice.getBtClassDrawable());
-        btClass.setAlpha(isEnabled() ? 255 : sDimAlpha);        
+        btClass.setAlpha(isEnabled() ? 255 : sDimAlpha);
     }
 
     @Override
@@ -122,8 +122,8 @@
             // Put other preference types above us
             return 1;
         }
-        
+
         return mCachedDevice.compareTo(((BluetoothDevicePreference) another).mCachedDevice);
     }
- 
+
 }
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index 2e7734b..b872916 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -34,14 +34,14 @@
  * preference reflects the current state.
  */
 public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
-    
+
     private static final boolean LOCAL_LOGD = Config.LOGD || false;
     private static final String TAG = "BluetoothEnabler";
-    
-    private final Context mContext; 
+
+    private final Context mContext;
     private final CheckBoxPreference mCheckBoxPreference;
     private final CharSequence mOriginalSummary;
-    
+
     private final LocalBluetoothManager mLocalManager;
 
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -55,10 +55,10 @@
     public BluetoothEnabler(Context context, CheckBoxPreference checkBoxPreference) {
         mContext = context;
         mCheckBoxPreference = checkBoxPreference;
-        
+
         mOriginalSummary = checkBoxPreference.getSummary();
         checkBoxPreference.setPersistent(false);
-        
+
         mLocalManager = LocalBluetoothManager.getInstance(context);
         if (mLocalManager == null) {
             // Bluetooth not supported
@@ -70,32 +70,32 @@
         if (mLocalManager == null) {
             return;
         }
-        
+
         int state = mLocalManager.getBluetoothState();
         // This is the widget enabled state, not the preference toggled state
         mCheckBoxPreference.setEnabled(state == BluetoothAdapter.STATE_ON ||
                 state == BluetoothAdapter.STATE_OFF);
         // BT state is not a sticky broadcast, so set it manually
         handleStateChanged(state);
-        
-        mContext.registerReceiver(mReceiver, 
+
+        mContext.registerReceiver(mReceiver,
                 new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
         mCheckBoxPreference.setOnPreferenceChangeListener(this);
     }
-    
+
     public void pause() {
         if (mLocalManager == null) {
             return;
         }
-        
+
         mContext.unregisterReceiver(mReceiver);
         mCheckBoxPreference.setOnPreferenceChangeListener(null);
     }
-    
+
     public boolean onPreferenceChange(Preference preference, Object value) {
         // Turn on/off BT
         setEnabled((Boolean) value);
-        
+
         // Don't update UI to opposite state until we're sure
         return false;
     }
@@ -103,10 +103,10 @@
     private void setEnabled(final boolean enable) {
         // Disable preference
         mCheckBoxPreference.setEnabled(false);
-        
+
         mLocalManager.setBluetoothEnabled(enable);
     }
-    
+
     private void handleStateChanged(int state) {
 
         if (state == BluetoothAdapter.STATE_OFF ||
@@ -125,13 +125,13 @@
             if (isEnabledByDependency()) {
                 mCheckBoxPreference.setEnabled(true);
             }
-            
+
         } else if (state == BluetoothAdapter.STATE_TURNING_ON ||
                 state == BluetoothAdapter.STATE_TURNING_OFF) {
             mCheckBoxPreference.setSummary(state == BluetoothAdapter.STATE_TURNING_ON
                     ? R.string.wifi_starting
                     : R.string.wifi_stopping);
-            
+
         } else {
             mCheckBoxPreference.setChecked(false);
             mCheckBoxPreference.setSummary(R.string.wifi_error);
@@ -144,17 +144,17 @@
         if (dep == null) {
             return true;
         }
-        
+
         return !dep.shouldDisableDependents();
     }
-    
+
     private Preference getDependencyPreference() {
         String depKey = mCheckBoxPreference.getDependency();
         if (TextUtils.isEmpty(depKey)) {
             return null;
         }
-        
+
         return mCheckBoxPreference.getPreferenceManager().findPreference(depKey);
     }
-    
+
 }
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index b4e7a4c..25c7f14 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -20,11 +20,11 @@
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
-import android.os.ParcelUuid;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.res.Resources;
+import android.os.ParcelUuid;
 import android.os.SystemClock;
 import android.text.TextUtils;
 import android.util.Log;
@@ -396,11 +396,13 @@
 
         int preferredProfiles = 0;
         for (Profile profile : mProfiles) {
-            LocalBluetoothProfileManager profileManager =
-                    LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
-            if (profileManager.isPreferred(mDevice)) {
-                ++preferredProfiles;
-                queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
+            if (isConnectableProfile(profile)) {
+                LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
+                        .getProfileManager(mLocalManager, profile);
+                if (profileManager.isPreferred(mDevice)) {
+                    ++preferredProfiles;
+                    queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
+                }
             }
         }
         if (DEBUG) Log.d(TAG, "Preferred profiles = " + preferredProfiles);
@@ -417,10 +419,12 @@
         mIsConnectingErrorPossible = true;
 
         for (Profile profile : mProfiles) {
-            LocalBluetoothProfileManager profileManager =
-                    LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
-            profileManager.setPreferred(mDevice, false);
-            queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
+            if (isConnectableProfile(profile)) {
+                LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
+                        .getProfileManager(mLocalManager, profile);
+                profileManager.setPreferred(mDevice, false);
+                queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
+            }
         }
     }
 
@@ -794,8 +798,18 @@
         }
     }
 
-    public List<Profile> getProfiles() {
-        return new ArrayList<Profile>(mProfiles);
+    public List<Profile> getConnectableProfiles() {
+        ArrayList<Profile> connectableProfiles = new ArrayList<Profile>();
+        for (Profile profile : mProfiles) {
+            if (isConnectableProfile(profile)) {
+                connectableProfiles.add(profile);
+            }
+        }
+        return connectableProfiles;
+    }
+
+    private boolean isConnectableProfile(Profile profile) {
+        return profile.equals(Profile.HEADSET) || profile.equals(Profile.A2DP);
     }
 
     public void onCreateContextMenu(ContextMenu menu) {
@@ -806,7 +820,14 @@
 
         int bondState = getBondState();
         boolean isConnected = isConnected();
-        boolean hasProfiles = mProfiles.size() > 0;
+        boolean hasConnectableProfiles = false;
+
+        for (Profile profile : mProfiles) {
+            if (isConnectableProfile(profile)) {
+                hasConnectableProfiles = true;
+                break;
+            }
+        }
 
         menu.setHeaderTitle(getName());
 
@@ -819,14 +840,14 @@
                 menu.add(0, CONTEXT_ITEM_UNPAIR, 0,
                         R.string.bluetooth_device_context_disconnect_unpair);
             } else { // Paired but not connected
-                if (hasProfiles) {
+                if (hasConnectableProfiles) {
                     menu.add(0, CONTEXT_ITEM_CONNECT, 0, R.string.bluetooth_device_context_connect);
                 }
                 menu.add(0, CONTEXT_ITEM_UNPAIR, 0, R.string.bluetooth_device_context_unpair);
             }
 
             // Show the connection options item
-            if (hasProfiles) {
+            if (hasConnectableProfiles) {
                 menu.add(0, CONTEXT_ITEM_CONNECT_ADVANCED, 0,
                         R.string.bluetooth_device_context_connect_advanced);
             }
diff --git a/src/com/android/settings/bluetooth/ConnectSpecificProfilesActivity.java b/src/com/android/settings/bluetooth/ConnectSpecificProfilesActivity.java
index 4f14390..08534f3 100644
--- a/src/com/android/settings/bluetooth/ConnectSpecificProfilesActivity.java
+++ b/src/com/android/settings/bluetooth/ConnectSpecificProfilesActivity.java
@@ -16,9 +16,6 @@
 
 package com.android.settings.bluetooth;
 
-import com.android.settings.R;
-import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
-
 import android.bluetooth.BluetoothDevice;
 import android.content.Intent;
 import android.os.Bundle;
@@ -29,7 +26,8 @@
 import android.text.TextUtils;
 import android.util.Log;
 
-import java.util.List;
+import com.android.settings.R;
+import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
 
 /**
  * ConnectSpecificProfilesActivity presents the user with all of the profiles
@@ -46,12 +44,9 @@
 
     public static final String EXTRA_DEVICE = "device";
 
-    public static final String CLASS_NAME_OPP_PROFILE_MANAGER =
-        "com.android.settings.bluetooth.LocalBluetoothProfileManager$OppProfileManager";
-
     private LocalBluetoothManager mManager;
     private CachedBluetoothDevice mCachedDevice;
-    
+
     private PreferenceGroup mProfileContainer;
     private CheckBoxPreference mOnlineModePreference;
 
@@ -63,11 +58,11 @@
      * profile.
      */
     private boolean mOnlineMode;
-    
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        
+
         BluetoothDevice device;
         if (savedInstanceState != null) {
             device = savedInstanceState.getParcelable(EXTRA_DEVICE);
@@ -80,7 +75,7 @@
             Log.w(TAG, "Activity started without a remote blueototh device");
             finish();
         }
-        
+
         mManager = LocalBluetoothManager.getInstance(this);
         mCachedDevice = mManager.getCachedDeviceManager().findDevice(device);
         if (mCachedDevice == null) {
@@ -90,7 +85,7 @@
 
         addPreferencesFromResource(R.xml.bluetooth_device_advanced);
         mProfileContainer = (PreferenceGroup) findPreference(KEY_PROFILE_CONTAINER);
-        
+
         // Set the title of the screen
         findPreference(KEY_TITLE).setTitle(
                 getString(R.string.bluetooth_device_advanced_title, mCachedDevice.getName()));
@@ -98,7 +93,7 @@
         // Listen for check/uncheck of the online mode checkbox
         mOnlineModePreference = (CheckBoxPreference) findPreference(KEY_ONLINE_MODE);
         mOnlineModePreference.setOnPreferenceChangeListener(this);
-        
+
         // Add a preference for each profile
         addPreferencesForProfiles();
     }
@@ -106,14 +101,14 @@
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
-        
+
         outState.putParcelable(EXTRA_DEVICE, mCachedDevice.getDevice());
     }
 
     @Override
     protected void onResume() {
         super.onResume();
-        
+
         mManager.setForegroundActivity(this);
         mCachedDevice.registerCallback(this);
 
@@ -123,13 +118,13 @@
     @Override
     protected void onPause() {
         super.onPause();
-        
+
         mCachedDevice.unregisterCallback(this);
         mManager.setForegroundActivity(null);
     }
 
     private void addPreferencesForProfiles() {
-        for (Profile profile : mCachedDevice.getProfiles()) {
+        for (Profile profile : mCachedDevice.getConnectableProfiles()) {
             Preference pref = createProfilePreference(profile);
             mProfileContainer.addPreference(pref);
         }
@@ -138,7 +133,7 @@
     /**
      * Creates a checkbox preference for the particular profile. The key will be
      * the profile's name.
-     * 
+     *
      * @param profile The profile for which the preference controls.
      * @return A preference that allows the user to choose whether this profile
      *         will be connected to.
@@ -154,27 +149,22 @@
                 .getProfileManager(mManager, profile);
 
         /**
-         * Gray out checkbox while connecting and disconnecting or this is OPP
-         * profile
+         * Gray out checkbox while connecting and disconnecting
          */
-        if (profileManager.getClass().getName().equals(CLASS_NAME_OPP_PROFILE_MANAGER)) {
-            pref.setEnabled(false);
-        } else {
-            pref.setEnabled(!mCachedDevice.isBusy());
-        }
+        pref.setEnabled(!mCachedDevice.isBusy());
 
         refreshProfilePreference(pref, profile);
-        
+
         return pref;
     }
 
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         String key = preference.getKey();
         if (TextUtils.isEmpty(key) || newValue == null) return true;
-        
+
         if (key.equals(KEY_ONLINE_MODE)) {
             onOnlineModeCheckedStateChanged((Boolean) newValue);
-            
+
         } else {
             Profile profile = getProfileOf(preference);
             if (profile == null) return false;
@@ -187,7 +177,7 @@
     private void onOnlineModeCheckedStateChanged(boolean checked) {
         setOnlineMode(checked, true);
     }
-    
+
     private void onProfileCheckedStateChanged(Profile profile, boolean checked) {
         if (mOnlineMode) {
             if (checked) {
@@ -196,12 +186,12 @@
                 mCachedDevice.disconnect(profile);
             }
         }
-        
+
         LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
                 .getProfileManager(mManager, profile);
         profileManager.setPreferred(mCachedDevice.getDevice(), checked);
     }
-    
+
     public void onDeviceAttributesChanged(CachedBluetoothDevice cachedDevice) {
         refresh();
     }
@@ -214,14 +204,14 @@
 
     /**
      * Switches between online/offline mode.
-     * 
+     *
      * @param onlineMode Whether to be in online mode, or offline mode.
      * @param takeAction Whether to take action (i.e., connect or disconnect)
      *            based on the new online mode.
      */
     private void setOnlineMode(boolean onlineMode, boolean takeAction) {
         mOnlineMode = onlineMode;
-            
+
         if (takeAction) {
             if (onlineMode) {
                 mCachedDevice.connect();
@@ -229,22 +219,16 @@
                 mCachedDevice.disconnect();
             }
         }
-            
+
         refreshOnlineModePreference();
     }
-    
+
     private void refreshOnlineModePreference() {
         mOnlineModePreference.setChecked(mOnlineMode);
 
         /* Gray out checkbox while connecting and disconnecting */
         mOnlineModePreference.setEnabled(!mCachedDevice.isBusy());
 
-        List<Profile> profiles = mCachedDevice.getProfiles();
-        if ((profiles.size() == 1) && (profiles.get(0).name().equals("OPP"))) {
-            Log.w(TAG, "there is only one profile: Opp, disable the connect button.");
-            mOnlineModePreference.setEnabled(false);
-        }
-
         /**
          * If the device is online, show status. Otherwise, show a summary that
          * describes what the checkbox does.
@@ -252,9 +236,9 @@
         mOnlineModePreference.setSummary(mOnlineMode ? mCachedDevice.getSummary()
                 : R.string.bluetooth_device_advanced_online_mode_summary);
     }
-    
+
     private void refreshProfiles() {
-        for (Profile profile : mCachedDevice.getProfiles()) {
+        for (Profile profile : mCachedDevice.getConnectableProfiles()) {
             CheckBoxPreference profilePref =
                     (CheckBoxPreference) findPreference(profile.toString());
             if (profilePref == null) {
@@ -265,27 +249,21 @@
             }
         }
     }
-    
+
     private void refreshProfilePreference(CheckBoxPreference profilePref, Profile profile) {
         BluetoothDevice device = mCachedDevice.getDevice();
         LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
                 .getProfileManager(mManager, profile);
-        
+
         int connectionStatus = profileManager.getConnectionStatus(device);
 
         /*
-         * Gray out checkbox while connecting and disconnecting or this is OPP
-         * profile
+         * Gray out checkbox while connecting and disconnecting
          */
-        if (profileManager.getClass().getName().equals(CLASS_NAME_OPP_PROFILE_MANAGER)) {
-            Log.w(TAG, "this is Opp profile");
-            profilePref.setEnabled(false);
-        } else {
-            profilePref.setEnabled(!mCachedDevice.isBusy());
-        }
+        profilePref.setEnabled(!mCachedDevice.isBusy());
         profilePref.setSummary(getProfileSummary(profileManager, profile, device,
                 connectionStatus, mOnlineMode));
-        
+
         profilePref.setChecked(profileManager.isPreferred(device));
     }
 
@@ -293,7 +271,7 @@
         if (!(pref instanceof CheckBoxPreference)) return null;
         String key = pref.getKey();
         if (TextUtils.isEmpty(key)) return null;
-        
+
         try {
             return Profile.valueOf(pref.getKey());
         } catch (IllegalArgumentException e) {
@@ -309,10 +287,10 @@
             return profileManager.getSummary(device);
         }
     }
-    
+
     /**
      * Gets the summary that describes when checked, it will become a preferred profile.
-     * 
+     *
      * @param profile The profile to get the summary for.
      * @return The summary.
      */
@@ -322,11 +300,9 @@
                 return R.string.bluetooth_a2dp_profile_summary_use_for;
             case HEADSET:
                 return R.string.bluetooth_headset_profile_summary_use_for;
-            case OPP:
-                return R.string.bluetooth_opp_profile_summary_use_for;
             default:
                 return 0;
         }
     }
-    
+
 }
diff --git a/src/com/android/settings/bluetooth/SettingsBtStatus.java b/src/com/android/settings/bluetooth/SettingsBtStatus.java
index 3a93931..e2285e9 100644
--- a/src/com/android/settings/bluetooth/SettingsBtStatus.java
+++ b/src/com/android/settings/bluetooth/SettingsBtStatus.java
@@ -26,9 +26,9 @@
  */
 public class SettingsBtStatus {
     private static final String TAG = "SettingsBtStatus";
-   
+
     // Connection status
-    
+
     public static final int CONNECTION_STATUS_UNKNOWN = 0;
     public static final int CONNECTION_STATUS_ACTIVE = 1;
     /** Use {@link #isConnected} to check for the connected state */
@@ -55,17 +55,17 @@
             return 0;
         }
     }
-    
+
     public static final boolean isConnectionStatusConnected(int connectionStatus) {
         return connectionStatus == CONNECTION_STATUS_ACTIVE
                 || connectionStatus == CONNECTION_STATUS_CONNECTED;
     }
-    
+
     public static final boolean isConnectionStatusBusy(int connectionStatus) {
         return connectionStatus == CONNECTION_STATUS_CONNECTING
                 || connectionStatus == CONNECTION_STATUS_DISCONNECTING;
     }
-    
+
     public static final int getPairingStatusSummary(int bondState) {
         switch (bondState) {
         case BluetoothDevice.BOND_BONDED:
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index a41cbf4..fecd1438 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -411,7 +411,7 @@
         double phoneOnPower = mPowerProfile.getAveragePower(PowerProfile.POWER_RADIO_ACTIVE)
                 * phoneOnTimeMs / 1000;
         addEntry(getString(R.string.power_phone), DrainType.PHONE, phoneOnTimeMs,
-                android.R.drawable.ic_menu_call, phoneOnPower);
+                R.drawable.ic_settings_voice_calls, phoneOnPower);
     }
 
     private void addScreenUsage(long uSecNow) {
@@ -432,7 +432,7 @@
         }
         power /= 1000; // To seconds
         addEntry(getString(R.string.power_screen), DrainType.SCREEN, screenOnTimeMs,
-                android.R.drawable.ic_menu_view, power);
+                R.drawable.ic_settings_display, power);
     }
 
     private void addRadioUsage(long uSecNow) {
@@ -447,7 +447,7 @@
         }
         BatterySipper bs =
                 addEntry(getString(R.string.power_cell), DrainType.CELL, signalTimeMs,
-                android.R.drawable.ic_menu_sort_by_size, power);
+                R.drawable.ic_settings_cell_standby, power);
         if (signalTimeMs != 0) {
             bs.noCoveragePercent = mStats.getPhoneSignalStrengthTime(0, uSecNow, mStatsType)
                     / 1000 * 100.0 / signalTimeMs;
@@ -461,7 +461,7 @@
                 * mPowerProfile.getAveragePower(PowerProfile.POWER_WIFI_ON)
             + runningTimeMs * mPowerProfile.getAveragePower(PowerProfile.POWER_WIFI_ON)) / 1000;
         addEntry(getString(R.string.power_wifi), DrainType.WIFI, runningTimeMs,
-                R.drawable.ic_wifi_signal_4, wifiPower);
+                R.drawable.ic_settings_wifi, wifiPower);
     }
 
     private void addIdleUsage(long uSecNow) {
@@ -469,7 +469,7 @@
         double idlePower = (idleTimeMs * mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_IDLE))
                 / 1000;
         addEntry(getString(R.string.power_idle), DrainType.IDLE, idleTimeMs,
-                android.R.drawable.ic_lock_power_off, idlePower);
+                R.drawable.ic_settings_phone_idle, idlePower);
     }
 
     private void addBluetoothUsage(long uSecNow) {
@@ -481,7 +481,7 @@
                 * mPowerProfile.getAveragePower(PowerProfile.POWER_BLUETOOTH_AT_CMD)) / 1000;
 
         addEntry(getString(R.string.power_bluetooth), DrainType.BLUETOOTH, btOnTimeMs,
-                com.android.internal.R.drawable.ic_volume_bluetooth_in_call, btPower);
+                R.drawable.ic_settings_bluetooth, btPower);
     }
 
     private double getAverageDataCost() {
@@ -619,6 +619,8 @@
                 } else if ("mediaserver".equals(name)) {
                     name = getResources().getString(R.string.process_mediaserver_label);
                 }
+                iconId = R.drawable.ic_power_system;
+                icon = getResources().getDrawable(iconId);
                 return;
             } else {
                 //name = packages[0];
diff --git a/src/com/android/settings/wifi/AccessPointDialog.java b/src/com/android/settings/wifi/AccessPointDialog.java
index bb5ee6f..4804d78 100644
--- a/src/com/android/settings/wifi/AccessPointDialog.java
+++ b/src/com/android/settings/wifi/AccessPointDialog.java
@@ -81,7 +81,7 @@
             AccessPointState.WEP_PASSWORD_HEX
     };
     private static final String NOT_APPLICABLE = "N/A";
-    private static final String BLOB_HEADER = "blob://";
+    private static final String KEYSTORE_HEADER = "keystore://";
 
     // Button positions, default to impossible values
     private int mConnectButtonPos = Integer.MAX_VALUE; 
@@ -641,16 +641,16 @@
         if (index != (spinner.getCount() - 1)) {
             String key = (String) spinner.getSelectedItem();
             mState.setEnterpriseField(AccessPointState.CLIENT_CERT,
-                    BLOB_HEADER + Credentials.USER_CERTIFICATE + key);
+                    KEYSTORE_HEADER + Credentials.USER_CERTIFICATE + key);
             mState.setEnterpriseField(AccessPointState.PRIVATE_KEY,
-                    BLOB_HEADER + Credentials.USER_PRIVATE_KEY + key);
+                    KEYSTORE_HEADER + Credentials.USER_PRIVATE_KEY + key);
         }
         spinner = mCaCertSpinner;
         index = spinner.getSelectedItemPosition();
         if (index != (spinner.getCount() - 1)) {
             String key = (String) spinner.getSelectedItem();
             mState.setEnterpriseField(AccessPointState.CA_CERT,
-                    BLOB_HEADER + Credentials.CA_CERTIFICATE + key);
+                    KEYSTORE_HEADER + Credentials.CA_CERTIFICATE + key);
         }
         mState.setSecurity(AccessPointState.EAP);
         mState.setEap(mEapSpinner.getSelectedItemPosition());