am 0c32da7e: am 6f28e342: am 9f6a1933: am 0ffbbad5: am 60544e74: am 3dddd8cb: Ensure all active Device Admins are listed.

* commit '0c32da7ee01f7f523a889c5faf1a449e664f8bce':
  Ensure all active Device Admins are listed.
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index ff003c4..4824be6 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -142,7 +142,7 @@
                 </LinearLayout>
             </LinearLayout>
 
-            <LinearLayout
+            <LinearLayout android:id="@+id/password_layout"
                        style="@style/wifi_item" >
                 <TextView
                         style="@style/wifi_item_label"
@@ -154,7 +154,7 @@
                         android:password="true" />
             </LinearLayout>
 
-            <LinearLayout
+            <LinearLayout android:id="@+id/show_password_layout"
                     style="@style/wifi_item" >
                 <!--  Dummy to enable right-justification of checkbox -->
                 <TextView
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 14e1fc8..6c24503 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -298,12 +298,10 @@
 
    <!-- Wi-Fi AP settings.  The type of security a Wi-Fi AP supports. -->
    <!-- Note that adding/removing/moving the items will need wifi settings code change. -->
-    <string-array name="wifi_ap_security" translatable="false">
-        <item>Open</item>
-        <!-- Do not translate. -->
-        <item>WPA PSK</item>
-        <!-- Do not translate. -->
-        <item>WPA2 PSK</item>
+    <string-array name="wifi_ap_security">
+        <item>@string/wifi_security_none</item>
+        <item>@string/wifi_security_wpa</item>
+        <item>@string/wifi_security_wpa2</item>
     </string-array>
 
     <!-- Match this with the constants in WifiDialog. --> <skip />
@@ -429,7 +427,14 @@
         <item>PWD</item>
     </string-array>
 
-    <!-- Phase 2 options -->
+    <!-- Phase 2 options for PEAP -->
+    <string-array name="wifi_peap_phase2_entries">
+        <item>None</item>
+        <item>MSCHAPV2</item>
+        <item>GTC</item>
+    </string-array>
+
+    <!-- Phase 2 options for rest of EAP methods -->
     <string-array name="wifi_phase2_entries">
         <item>None</item>
         <item>PAP</item>
@@ -534,6 +539,29 @@
         <item>0</item>
     </string-array>
 
+    <!-- MVNO Info used in APN editor -->
+    <string-array name="mvno_type_entries">
+        <!-- Do not translate. -->
+        <item>None</item>
+        <!-- Do not translate. -->
+        <item>SPN</item>
+        <!-- Do not translate. -->
+        <item>IMSI</item>
+        <!-- Do not translate. -->
+        <item>GID</item>
+    </string-array>
+
+    <string-array translatable="false" name="mvno_type_values">
+        <!-- Do not translate. -->
+        <item></item>
+        <!-- Do not translate. -->
+        <item>spn</item>
+        <!-- Do not translate. -->
+        <item>imsi</item>
+        <!-- Do not translate. -->
+        <item>gid</item>
+    </string-array>
+
     <!-- Apps on SD instalaltion location options in ApplicationSettings -->
     <string-array name="app_install_location_entries">
         <item>Internal device storage</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b5c04b0..caca2b9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2117,6 +2117,10 @@
     <string name="carrier_enabled_summaryOff">APN disabled</string>
     <!-- Edit Beaerer Info of APN -->
     <string name="bearer">Bearer</string>
+    <!-- Edit Mvno Type Info of APN -->
+    <string name="mvno_type">MVNO type</string>
+    <!-- Edit Mvno Match Data Info of APN -->
+    <string name="mvno_match_data">MVNO value</string>
     <!-- Edit access point screen menu option to delete this APN -->
     <string name="menu_delete">Delete APN</string>
     <!-- APNs screen menu option to create a brand spanking new APN -->
diff --git a/res/xml/apn_editor.xml b/res/xml/apn_editor.xml
index 604a349..745a83e 100644
--- a/res/xml/apn_editor.xml
+++ b/res/xml/apn_editor.xml
@@ -141,4 +141,17 @@
         android:entries="@array/bearer_entries"
         android:entryValues="@array/bearer_values"
         />
+    <ListPreference
+        android:title="@string/mvno_type"
+        android:key="mvno_type"
+        android:entries="@array/mvno_type_entries"
+        android:entryValues="@array/mvno_type_values"
+        />
+    <EditTextPreference
+        android:title="@string/mvno_match_data"
+        android:dialogTitle="@string/mvno_match_data"
+        android:key="mvno_match_data"
+        android:singleLine="true"
+        android:inputType="text"
+        />
 </PreferenceScreen>   
diff --git a/src/com/android/settings/ApnEditor.java b/src/com/android/settings/ApnEditor.java
index 79b6d15..f34abfa 100644
--- a/src/com/android/settings/ApnEditor.java
+++ b/src/com/android/settings/ApnEditor.java
@@ -57,6 +57,7 @@
     private final static String KEY_ROAMING_PROTOCOL = "apn_roaming_protocol";
     private final static String KEY_CARRIER_ENABLED = "carrier_enabled";
     private final static String KEY_BEARER = "bearer";
+    private final static String KEY_MVNO_TYPE = "mvno_type";
 
     private static final int MENU_DELETE = Menu.FIRST;
     private static final int MENU_SAVE = Menu.FIRST + 1;
@@ -82,6 +83,8 @@
     private ListPreference mRoamingProtocol;
     private CheckBoxPreference mCarrierEnabled;
     private ListPreference mBearer;
+    private ListPreference mMvnoType;
+    private EditTextPreference mMvnoMatchData;
 
     private String mCurMnc;
     private String mCurMcc;
@@ -115,7 +118,9 @@
             Telephony.Carriers.PROTOCOL, // 16
             Telephony.Carriers.CARRIER_ENABLED, // 17
             Telephony.Carriers.BEARER, // 18
-            Telephony.Carriers.ROAMING_PROTOCOL // 19
+            Telephony.Carriers.ROAMING_PROTOCOL, // 19
+            Telephony.Carriers.MVNO_TYPE,   // 20
+            Telephony.Carriers.MVNO_MATCH_DATA  // 21
     };
 
     private static final int ID_INDEX = 0;
@@ -137,6 +142,8 @@
     private static final int CARRIER_ENABLED_INDEX = 17;
     private static final int BEARER_INDEX = 18;
     private static final int ROAMING_PROTOCOL_INDEX = 19;
+    private static final int MVNO_TYPE_INDEX = 20;
+    private static final int MVNO_MATCH_DATA_INDEX = 21;
 
 
     @Override
@@ -174,6 +181,10 @@
         mBearer = (ListPreference) findPreference(KEY_BEARER);
         mBearer.setOnPreferenceChangeListener(this);
 
+        mMvnoType = (ListPreference) findPreference(KEY_MVNO_TYPE);
+        mMvnoType.setOnPreferenceChangeListener(this);
+        mMvnoMatchData = (EditTextPreference) findPreference("mvno_match_data");
+
         mRes = getResources();
 
         final Intent intent = getIntent();
@@ -274,6 +285,9 @@
             mRoamingProtocol.setValue(mCursor.getString(ROAMING_PROTOCOL_INDEX));
             mCarrierEnabled.setChecked(mCursor.getInt(CARRIER_ENABLED_INDEX)==1);
             mBearer.setValue(mCursor.getString(BEARER_INDEX));
+            mMvnoType.setValue(mCursor.getString(MVNO_TYPE_INDEX));
+            mMvnoMatchData.setEnabled(false);
+            mMvnoMatchData.setText(mCursor.getString(MVNO_MATCH_DATA_INDEX));
         }
 
         mName.setSummary(checkNull(mName.getText()));
@@ -307,6 +321,9 @@
                 checkNull(protocolDescription(mRoamingProtocol.getValue(), mRoamingProtocol)));
         mBearer.setSummary(
                 checkNull(bearerDescription(mBearer.getValue())));
+        mMvnoType.setSummary(
+                checkNull(mvnoDescription(mMvnoType.getValue())));
+        mMvnoMatchData.setSummary(checkNull(mMvnoMatchData.getText()));
     }
 
     /**
@@ -342,6 +359,27 @@
         }
     }
 
+    private String mvnoDescription(String raw) {
+        int mvnoIndex = mMvnoType.findIndexOfValue(raw);
+        if (mvnoIndex == -1) {
+            return null;
+        } else {
+            String[] values = mRes.getStringArray(R.array.mvno_type_entries);
+            if (values[mvnoIndex].equals("None")) {
+                mMvnoMatchData.setEnabled(false);
+                mMvnoMatchData.setText("");
+            } else {
+                mMvnoMatchData.setEnabled(true);
+            }
+
+            try {
+                return values[mvnoIndex];
+            } catch (ArrayIndexOutOfBoundsException e) {
+                return null;
+            }
+        }
+    }
+
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         String key = preference.getKey();
         if (KEY_AUTH_TYPE.equals(key)) {
@@ -375,6 +413,13 @@
             }
             mBearer.setValue((String) newValue);
             mBearer.setSummary(bearer);
+        } else if (KEY_MVNO_TYPE.equals(key)) {
+            String mvno = mvnoDescription((String) newValue);
+            if (mvno == null) {
+                return false;
+            }
+            mMvnoType.setValue((String) newValue);
+            mMvnoType.setSummary(mvno);
         }
 
         return true;
@@ -508,6 +553,9 @@
             values.put(Telephony.Carriers.BEARER, Integer.parseInt(bearerVal));
         }
 
+        values.put(Telephony.Carriers.MVNO_TYPE, checkNotSet(mMvnoType.getValue()));
+        values.put(Telephony.Carriers.MVNO_MATCH_DATA, checkNotSet(mMvnoMatchData.getText()));
+
         getContentResolver().update(mUri, values, null, null);
 
         return true;
diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java
index 56ee7a9..3fbb5e3 100644
--- a/src/com/android/settings/ApnSettings.java
+++ b/src/com/android/settings/ApnSettings.java
@@ -164,43 +164,45 @@
                 "_id", "name", "apn", "type"}, where, null,
                 Telephony.Carriers.DEFAULT_SORT_ORDER);
 
-        PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
-        apnList.removeAll();
+        if (cursor != null) {
+            PreferenceGroup apnList = (PreferenceGroup) findPreference("apn_list");
+            apnList.removeAll();
 
-        ArrayList<Preference> mmsApnList = new ArrayList<Preference>();
+            ArrayList<Preference> mmsApnList = new ArrayList<Preference>();
 
-        mSelectedKey = getSelectedApnKey();
-        cursor.moveToFirst();
-        while (!cursor.isAfterLast()) {
-            String name = cursor.getString(NAME_INDEX);
-            String apn = cursor.getString(APN_INDEX);
-            String key = cursor.getString(ID_INDEX);
-            String type = cursor.getString(TYPES_INDEX);
+            mSelectedKey = getSelectedApnKey();
+            cursor.moveToFirst();
+            while (!cursor.isAfterLast()) {
+                String name = cursor.getString(NAME_INDEX);
+                String apn = cursor.getString(APN_INDEX);
+                String key = cursor.getString(ID_INDEX);
+                String type = cursor.getString(TYPES_INDEX);
 
-            ApnPreference pref = new ApnPreference(this);
+                ApnPreference pref = new ApnPreference(this);
 
-            pref.setKey(key);
-            pref.setTitle(name);
-            pref.setSummary(apn);
-            pref.setPersistent(false);
-            pref.setOnPreferenceChangeListener(this);
+                pref.setKey(key);
+                pref.setTitle(name);
+                pref.setSummary(apn);
+                pref.setPersistent(false);
+                pref.setOnPreferenceChangeListener(this);
 
-            boolean selectable = ((type == null) || !type.equals("mms"));
-            pref.setSelectable(selectable);
-            if (selectable) {
-                if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
-                    pref.setChecked();
+                boolean selectable = ((type == null) || !type.equals("mms"));
+                pref.setSelectable(selectable);
+                if (selectable) {
+                    if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
+                        pref.setChecked();
+                    }
+                    apnList.addPreference(pref);
+                } else {
+                    mmsApnList.add(pref);
                 }
-                apnList.addPreference(pref);
-            } else {
-                mmsApnList.add(pref);
+                cursor.moveToNext();
             }
-            cursor.moveToNext();
-        }
-        cursor.close();
+            cursor.close();
 
-        for (Preference preference : mmsApnList) {
-            apnList.addPreference(preference);
+            for (Preference preference : mmsApnList) {
+                apnList.addPreference(preference);
+            }
         }
     }
 
@@ -209,7 +211,8 @@
         super.onCreateOptionsMenu(menu);
         menu.add(0, MENU_NEW, 0,
                 getResources().getString(R.string.menu_new))
-                .setIcon(android.R.drawable.ic_menu_add);
+                .setIcon(android.R.drawable.ic_menu_add)
+                .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
         menu.add(0, MENU_RESTORE, 0,
                 getResources().getString(R.string.menu_restore))
                 .setIcon(android.R.drawable.ic_menu_upload);
@@ -329,7 +332,7 @@
             switch (msg.what) {
                 case EVENT_RESTORE_DEFAULTAPN_START:
                     ContentResolver resolver = getContentResolver();
-                    resolver.delete(DEFAULTAPN_URI, null, null);                    
+                    resolver.delete(DEFAULTAPN_URI, null, null);
                     mRestoreApnUiHandler
                         .sendEmptyMessage(EVENT_RESTORE_DEFAULTAPN_COMPLETE);
                     break;
diff --git a/src/com/android/settings/BatteryInfo.java b/src/com/android/settings/BatteryInfo.java
index ccad236..3f88277 100644
--- a/src/com/android/settings/BatteryInfo.java
+++ b/src/com/android/settings/BatteryInfo.java
@@ -63,11 +63,12 @@
 
     /**
      * Format a number of tenths-units as a decimal string without using a
-     * conversion to float.  E.g. 347 -> "34.7"
+     * conversion to float.  E.g. 347 -> "34.7", -99 -> "-9.9"
      */
     private final String tenthsToFixedString(int x) {
         int tens = x / 10;
-        return Integer.toString(tens) + "." + (x - 10 * tens);
+        // use Math.abs to avoid "-9.-9" about -99
+        return Integer.toString(tens) + "." + Math.abs(x - 10 * tens);
     }
 
    /**
diff --git a/src/com/android/settings/BrightnessPreference.java b/src/com/android/settings/BrightnessPreference.java
index 2cf6b43..62f716f 100644
--- a/src/com/android/settings/BrightnessPreference.java
+++ b/src/com/android/settings/BrightnessPreference.java
@@ -120,6 +120,7 @@
             mCheckBox.setChecked(mAutomaticMode);
             mSeekBar.setEnabled(!mAutomaticMode || USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT);
         } else {
+            mCheckBox.setVisibility(View.GONE);
             mSeekBar.setEnabled(true);
         }
         mSeekBar.setOnSeekBarChangeListener(this);
diff --git a/src/com/android/settings/CredentialStorage.java b/src/com/android/settings/CredentialStorage.java
index c737c7d..1444a73 100644
--- a/src/com/android/settings/CredentialStorage.java
+++ b/src/com/android/settings/CredentialStorage.java
@@ -197,12 +197,14 @@
             Bundle bundle = mInstallBundle;
             mInstallBundle = null;
 
+            final int uid = bundle.getInt(Credentials.EXTRA_INSTALL_AS_UID, -1);
+
             if (bundle.containsKey(Credentials.EXTRA_USER_PRIVATE_KEY_NAME)) {
                 String key = bundle.getString(Credentials.EXTRA_USER_PRIVATE_KEY_NAME);
                 byte[] value = bundle.getByteArray(Credentials.EXTRA_USER_PRIVATE_KEY_DATA);
 
-                if (!mKeyStore.importKey(key, value)) {
-                    Log.e(TAG, "Failed to install " + key);
+                if (!mKeyStore.importKey(key, value, uid)) {
+                    Log.e(TAG, "Failed to install " + key + " as user " + uid);
                     return;
                 }
             }
@@ -211,8 +213,8 @@
                 String certName = bundle.getString(Credentials.EXTRA_USER_CERTIFICATE_NAME);
                 byte[] certData = bundle.getByteArray(Credentials.EXTRA_USER_CERTIFICATE_DATA);
 
-                if (!mKeyStore.put(certName, certData)) {
-                    Log.e(TAG, "Failed to install " + certName);
+                if (!mKeyStore.put(certName, certData, uid)) {
+                    Log.e(TAG, "Failed to install " + certName + " as user " + uid);
                     return;
                 }
             }
@@ -221,11 +223,10 @@
                 String caListName = bundle.getString(Credentials.EXTRA_CA_CERTIFICATES_NAME);
                 byte[] caListData = bundle.getByteArray(Credentials.EXTRA_CA_CERTIFICATES_DATA);
 
-                if (!mKeyStore.put(caListName, caListData)) {
-                    Log.e(TAG, "Failed to install " + caListName);
+                if (!mKeyStore.put(caListName, caListData, uid)) {
+                    Log.e(TAG, "Failed to install " + caListName + " as user " + uid);
                     return;
                 }
-
             }
 
             setResult(RESULT_OK);
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java
index ae67d3a..963f864 100644
--- a/src/com/android/settings/DataUsageSummary.java
+++ b/src/com/android/settings/DataUsageSummary.java
@@ -277,13 +277,19 @@
         mPolicyEditor = new NetworkPolicyEditor(mPolicyManager);
         mPolicyEditor.read();
 
+        try {
+            mStatsSession = mStatsService.openSession();
+        } catch (RemoteException e) {
+            throw new RuntimeException(e);
+        }
+
         mShowWifi = mPrefs.getBoolean(PREF_SHOW_WIFI, false);
         mShowEthernet = mPrefs.getBoolean(PREF_SHOW_ETHERNET, false);
 
         // override preferences when no mobile radio
         if (!hasReadyMobileRadio(context)) {
-            mShowWifi = hasWifiRadio(context);
-            mShowEthernet = hasEthernet(context);
+            mShowWifi = true;
+            mShowEthernet = true;
         }
 
         setHasOptionsMenu(true);
@@ -298,12 +304,6 @@
 
         mUidDetailProvider = new UidDetailProvider(context);
 
-        try {
-            mStatsSession = mStatsService.openSession();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-
         mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
         mTabsContainer = (ViewGroup) view.findViewById(R.id.tabs_container);
         mTabWidget = (TabWidget) view.findViewById(android.R.id.tabs);
diff --git a/src/com/android/settings/DateTimeSettings.java b/src/com/android/settings/DateTimeSettings.java
index 65a34f4..ab87527 100644
--- a/src/com/android/settings/DateTimeSettings.java
+++ b/src/com/android/settings/DateTimeSettings.java
@@ -119,6 +119,10 @@
         if (currentFormat == null) {
             currentFormat = "";
         }
+
+        // Prevents duplicated values on date format selector.
+        mDummyDate.set(mDummyDate.get(Calendar.YEAR), mDummyDate.DECEMBER, 31, 13, 0, 0);
+
         for (int i = 0; i < formattedDates.length; i++) {
             String formatted =
                     DateFormat.getDateFormatForSetting(getActivity(), dateFormats[i])
@@ -240,6 +244,15 @@
                 calendar.get(Calendar.YEAR),
                 calendar.get(Calendar.MONTH),
                 calendar.get(Calendar.DAY_OF_MONTH));
+            // The system clock can't represent dates outside this range.
+            DatePickerDialog datePicker = (DatePickerDialog)d;
+            Calendar t = Calendar.getInstance();
+            t.clear();
+            t.set(1970, Calendar.JANUARY, 1);
+            datePicker.getDatePicker().setMinDate(t.getTimeInMillis());
+            t.clear();
+            t.set(2037, Calendar.DECEMBER, 31);
+            datePicker.getDatePicker().setMaxDate(t.getTimeInMillis());
             break;
         }
         case DIALOG_TIMEPICKER: {
diff --git a/src/com/android/settings/DreamSettings.java b/src/com/android/settings/DreamSettings.java
index 32328d9..23285c0 100644
--- a/src/com/android/settings/DreamSettings.java
+++ b/src/com/android/settings/DreamSettings.java
@@ -316,7 +316,7 @@
 
             ImageView settingsButton = (ImageView) row.findViewById(android.R.id.button2);
             settingsButton.setVisibility(showSettings ? View.VISIBLE : View.INVISIBLE);
-            settingsButton.setAlpha(dreamInfo.isActive ? 1f : 0.33f);
+            settingsButton.setAlpha(dreamInfo.isActive ? 1f : Utils.DISABLED_ALPHA);
             settingsButton.setEnabled(dreamInfo.isActive);
             settingsButton.setOnClickListener(new OnClickListener(){
                 @Override
diff --git a/src/com/android/settings/LocationSettings.java b/src/com/android/settings/LocationSettings.java
index cfbbe26..0e50188 100644
--- a/src/com/android/settings/LocationSettings.java
+++ b/src/com/android/settings/LocationSettings.java
@@ -76,6 +76,7 @@
         if (mSettingsObserver != null) {
             mContentQueryMap.deleteObserver(mSettingsObserver);
         }
+        mContentQueryMap.close();
     }
 
     private PreferenceScreen createPreferenceHierarchy() {
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 59cd110..b51f2f3 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -407,9 +407,9 @@
                     Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
         }
 
-        KeyStore.State state = KeyStore.getInstance().state();
         if (mResetCredentials != null) {
-            mResetCredentials.setEnabled(state != KeyStore.State.UNINITIALIZED);
+            KeyStore keyStore = KeyStore.getInstance();
+            mResetCredentials.setEnabled(!keyStore.isUnlocked());
         }
     }
 
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index a5e2005..dc49ba8 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -464,14 +464,14 @@
                 }
             }
 
-            if (target.get(i) == header
+            if (i < target.size() && target.get(i) == header
                     && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
                     && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
                 target.remove(i);
             }
 
             // Increment if the current one wasn't removed by the Utils code.
-            if (target.get(i) == header) {
+            if (i < target.size() && target.get(i) == header) {
                 // Hold on to the first header, when we need to reset to the top-level
                 if (mFirstHeader == null &&
                         HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) {
diff --git a/src/com/android/settings/SoundSettings.java b/src/com/android/settings/SoundSettings.java
index 7e46171..931858c 100644
--- a/src/com/android/settings/SoundSettings.java
+++ b/src/com/android/settings/SoundSettings.java
@@ -78,7 +78,7 @@
 
     private static final String[] NEED_VOICE_CAPABILITY = {
             KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS,
-            KEY_EMERGENCY_TONE
+            KEY_EMERGENCY_TONE, KEY_VIBRATE
     };
 
     private static final int MSG_UPDATE_RINGTONE_SUMMARY = 1;
@@ -175,9 +175,6 @@
             removePreference(KEY_VIBRATE);
             removePreference(KEY_HAPTIC_FEEDBACK);
         }
-        if (!Utils.isVoiceCapable(getActivity())) {
-            removePreference(KEY_VIBRATE);
-        }
 
         if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) {
             ListPreference emergencyTonePreference =
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index df44e91..d2c99dc 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -388,7 +388,7 @@
         int btState = adapter.getState();
         if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
             mBluetoothTether.setEnabled(false);
-            mBluetoothTether.setSummary(R.string.wifi_stopping);
+            mBluetoothTether.setSummary(R.string.bluetooth_turning_off);
         } else if (btState == BluetoothAdapter.STATE_TURNING_ON) {
             mBluetoothTether.setEnabled(false);
             mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index e6d63bd..8829825 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -80,6 +80,11 @@
     public static final int UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY = 1;
 
     /**
+     * The opacity level of a disabled icon.
+     */
+    public static final float DISABLED_ALPHA = 0.4f;
+
+    /**
      * Name of the meta-data item that should be set in the AndroidManifest.xml
      * to specify the icon that should be displayed for the preference.
      */
diff --git a/src/com/android/settings/deviceinfo/MiscFilesHandler.java b/src/com/android/settings/deviceinfo/MiscFilesHandler.java
index 1e0cc46..93e352b 100644
--- a/src/com/android/settings/deviceinfo/MiscFilesHandler.java
+++ b/src/com/android/settings/deviceinfo/MiscFilesHandler.java
@@ -144,8 +144,8 @@
         // Returns true if all deletions were successful.
         // If a deletion fails, the method stops attempting to delete and returns false.
         private boolean deleteDir(File dir) {
-            if (dir.isDirectory()) {
-                String[] children = dir.list();
+            String[] children = dir.list();
+            if (children != null) {
                 for (int i=0; i < children.length; i++) {
                     boolean success = deleteDir(new File(dir, children[i]));
                     if (!success) {
@@ -283,4 +283,4 @@
             return view;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/deviceinfo/Status.java b/src/com/android/settings/deviceinfo/Status.java
index 5297245..6a15027 100644
--- a/src/com/android/settings/deviceinfo/Status.java
+++ b/src/com/android/settings/deviceinfo/Status.java
@@ -381,8 +381,11 @@
 
     private void updateNetworkType() {
         // Whether EDGE, UMTS, etc...
-        setSummaryText(KEY_NETWORK_TYPE, mTelephonyManager.getNetworkTypeName() +
-                ":" + mTelephonyManager.getNetworkType());
+        String networktype = null;
+        if (TelephonyManager.NETWORK_TYPE_UNKNOWN != mTelephonyManager.getNetworkType()) {
+            networktype = mTelephonyManager.getNetworkTypeName();
+        }
+        setSummaryText(KEY_NETWORK_TYPE, networktype);
     }
 
     private void updateDataState() {
diff --git a/src/com/android/settings/deviceinfo/StorageMeasurement.java b/src/com/android/settings/deviceinfo/StorageMeasurement.java
index 772ac0d..a22ba77 100644
--- a/src/com/android/settings/deviceinfo/StorageMeasurement.java
+++ b/src/com/android/settings/deviceinfo/StorageMeasurement.java
@@ -422,7 +422,7 @@
             }
 
             // Measure misc files not counted under media
-            if (mIsInternal || mIsPrimary) {
+            if (measureMedia) {
                 final File path = mIsInternal ? currentEnv.getExternalStorageDirectory()
                         : mVolume.getPathFile();
                 details.miscSize = measureMisc(imcs, path);
diff --git a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
index 1599ec7..61188ec 100644
--- a/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
+++ b/src/com/android/settings/deviceinfo/StorageVolumePreferenceCategory.java
@@ -194,8 +194,9 @@
         }
 
         final boolean isRemovable = mVolume != null ? mVolume.isRemovable() : false;
+        // Always create the preference since many code rely on it existing
+        mMountTogglePreference = new Preference(context);
         if (isRemovable) {
-            mMountTogglePreference = new Preference(context);
             mMountTogglePreference.setTitle(R.string.sd_eject);
             mMountTogglePreference.setSummary(R.string.sd_eject_summary);
             addPreference(mMountTogglePreference);
@@ -240,12 +241,12 @@
         final String state = mStorageManager.getVolumeState(mVolume.getPath());
 
         if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
-            mItemAvailable.setSummary(R.string.memory_available_read_only);
+            mItemAvailable.setTitle(R.string.memory_available_read_only);
             if (mFormatPreference != null) {
                 removePreference(mFormatPreference);
             }
         } else {
-            mItemAvailable.setSummary(R.string.memory_available);
+            mItemAvailable.setTitle(R.string.memory_available);
         }
 
         if (Environment.MEDIA_MOUNTED.equals(state)
@@ -310,7 +311,9 @@
     private static long totalValues(HashMap<String, Long> map, String... keys) {
         long total = 0;
         for (String key : keys) {
-            total += map.get(key);
+            if (map.containsKey(key)) {
+                total += map.get(key);
+            }
         }
         return total;
     }
diff --git a/src/com/android/settings/fuelgauge/BatterySipper.java b/src/com/android/settings/fuelgauge/BatterySipper.java
index f11d6ca..ffc6651 100644
--- a/src/com/android/settings/fuelgauge/BatterySipper.java
+++ b/src/com/android/settings/fuelgauge/BatterySipper.java
@@ -93,7 +93,7 @@
 
     public int compareTo(BatterySipper other) {
         // Return the flipped value because we want the items in descending order
-        return (int) (other.getSortValue() - getSortValue());
+        return Double.compare(other.getSortValue(), getSortValue());
     }
 
     void getQuickNameIconForUid(Uid uidObj) {
diff --git a/src/com/android/settings/inputmethod/CheckBoxAndSettingsPreference.java b/src/com/android/settings/inputmethod/CheckBoxAndSettingsPreference.java
index 28b8616..f440bc8 100644
--- a/src/com/android/settings/inputmethod/CheckBoxAndSettingsPreference.java
+++ b/src/com/android/settings/inputmethod/CheckBoxAndSettingsPreference.java
@@ -18,6 +18,7 @@
 
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
 
 import android.content.Context;
 import android.content.Intent;
@@ -29,7 +30,6 @@
 import android.widget.TextView;
 
 public class CheckBoxAndSettingsPreference extends CheckBoxPreference {
-    private static final float DISABLED_ALPHA = 0.4f;
 
     private SettingsPreferenceFragment mFragment;
     private TextView mTitleText;
@@ -103,7 +103,7 @@
                 mSettingsButton.setClickable(checked);
                 mSettingsButton.setFocusable(checked);
                 if (!checked) {
-                    mSettingsButton.setAlpha(DISABLED_ALPHA);
+                    mSettingsButton.setAlpha(Utils.DISABLED_ALPHA);
                 }
             }
         }
diff --git a/src/com/android/settings/inputmethod/InputMethodPreference.java b/src/com/android/settings/inputmethod/InputMethodPreference.java
index 103481e..f064c08 100644
--- a/src/com/android/settings/inputmethod/InputMethodPreference.java
+++ b/src/com/android/settings/inputmethod/InputMethodPreference.java
@@ -18,6 +18,7 @@
 
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
 
 import android.app.AlertDialog;
 import android.app.Fragment;
@@ -47,7 +48,6 @@
 public class InputMethodPreference extends CheckBoxPreference
         implements Comparator<InputMethodPreference> {
     private static final String TAG = InputMethodPreference.class.getSimpleName();
-    private static final float DISABLED_ALPHA = 0.4f;
     private final SettingsPreferenceFragment mFragment;
     private final InputMethodInfo mImi;
     private final InputMethodManager mImm;
@@ -172,7 +172,7 @@
             mInputMethodSettingsButton.setClickable(checked);
             mInputMethodSettingsButton.setFocusable(checked);
             if (!checked) {
-                mInputMethodSettingsButton.setAlpha(DISABLED_ALPHA);
+                mInputMethodSettingsButton.setAlpha(Utils.DISABLED_ALPHA);
             }
         }
         if (mTitleText != null) {
diff --git a/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java b/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java
index 5b28142..5ea8bd7 100644
--- a/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java
+++ b/src/com/android/settings/inputmethod/SingleSpellCheckerPreference.java
@@ -17,6 +17,7 @@
 package com.android.settings.inputmethod;
 
 import com.android.settings.R;
+import com.android.settings.Utils;
 
 import android.app.AlertDialog;
 import android.content.ActivityNotFoundException;
@@ -37,7 +38,6 @@
 import android.widget.Toast;
 
 public class SingleSpellCheckerPreference extends Preference {
-    private static final float DISABLED_ALPHA = 0.4f;
     private static final String TAG = SingleSpellCheckerPreference.class.getSimpleName();
     private static final boolean DBG = false;
 
@@ -198,7 +198,7 @@
                 mSettingsButton.setClickable(enabled);
                 mSettingsButton.setFocusable(enabled);
                 if (!enabled) {
-                    mSettingsButton.setAlpha(DISABLED_ALPHA);
+                    mSettingsButton.setAlpha(Utils.DISABLED_ALPHA);
                 }
             }
         }
@@ -210,7 +210,7 @@
                 mSubtypeButton.setClickable(enabled);
                 mSubtypeButton.setFocusable(enabled);
                 if (!enabled) {
-                    mSubtypeButton.setAlpha(DISABLED_ALPHA);
+                    mSubtypeButton.setAlpha(Utils.DISABLED_ALPHA);
                 }
             }
         }
diff --git a/src/com/android/settings/tts/TtsEnginePreference.java b/src/com/android/settings/tts/TtsEnginePreference.java
index 3d612f0..21ef81d 100644
--- a/src/com/android/settings/tts/TtsEnginePreference.java
+++ b/src/com/android/settings/tts/TtsEnginePreference.java
@@ -30,6 +30,7 @@
 
 
 import com.android.settings.R;
+import com.android.settings.Utils;
 
 
 public class TtsEnginePreference extends Preference {
@@ -136,6 +137,9 @@
         // Will be enabled only the engine has passed the voice check, and
         // is currently enabled.
         mSettingsIcon.setEnabled(isChecked && mVoiceCheckData != null);
+        if (!isChecked) {
+            mSettingsIcon.setAlpha(Utils.DISABLED_ALPHA);
+        }
         mSettingsIcon.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -169,7 +173,12 @@
         // case mSettingsIcon && mRadioButton will be null. In this case
         // getView will set the right values.
         if (mSettingsIcon != null && mRadioButton != null) {
-            mSettingsIcon.setEnabled(mRadioButton.isChecked());
+            if (mRadioButton.isChecked()) {
+                mSettingsIcon.setEnabled(true);
+            } else {
+                mSettingsIcon.setEnabled(false);
+                mSettingsIcon.setAlpha(Utils.DISABLED_ALPHA);
+            }
         }
     }
 
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index 9d15435..96ac392 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -155,7 +155,7 @@
         super.onResume();
 
         // Check KeyStore here, so others do not need to deal with it.
-        if (mKeyStore.state() != KeyStore.State.UNLOCKED) {
+        if (!mKeyStore.isUnlocked()) {
             if (!mUnlocking) {
                 // Let us unlock KeyStore. See you later!
                 Credentials.getInstance().unlock(getActivity());
diff --git a/src/com/android/settings/wifi/AccessPoint.java b/src/com/android/settings/wifi/AccessPoint.java
index f6581a5..20146eb 100644
--- a/src/com/android/settings/wifi/AccessPoint.java
+++ b/src/com/android/settings/wifi/AccessPoint.java
@@ -338,11 +338,7 @@
         setTitle(ssid);
 
         Context context = getContext();
-        if (mState != null) { // This is the active connection
-            setSummary(Summary.get(context, mState));
-        } else if (mRssi == Integer.MAX_VALUE) { // Wifi out of range
-            setSummary(context.getString(R.string.wifi_not_in_range));
-        } else if (mConfig != null && mConfig.status == WifiConfiguration.Status.DISABLED) {
+        if (mConfig != null && mConfig.status == WifiConfiguration.Status.DISABLED) {
             switch (mConfig.disableReason) {
                 case WifiConfiguration.DISABLED_AUTH_FAILURE:
                     setSummary(context.getString(R.string.wifi_disabled_password_failure));
@@ -354,6 +350,10 @@
                 case WifiConfiguration.DISABLED_UNKNOWN_REASON:
                     setSummary(context.getString(R.string.wifi_disabled_generic));
             }
+        } else if (mRssi == Integer.MAX_VALUE) { // Wifi out of range
+            setSummary(context.getString(R.string.wifi_not_in_range));
+        } else if (mState != null) { // This is the active connection
+            setSummary(Summary.get(context, mState));
         } else { // In range, not disabled.
             StringBuilder summary = new StringBuilder();
             if (mConfig != null) { // Is saved network
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 2598a0e..60ab1ca 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -31,7 +31,9 @@
 import android.net.wifi.WifiConfiguration.IpAssignment;
 import android.net.wifi.WifiConfiguration.KeyMgmt;
 import android.net.wifi.WifiConfiguration.ProxySettings;
-import android.net.wifi.WifiConfiguration.Status;
+import android.net.wifi.WifiEnterpriseConfig;
+import android.net.wifi.WifiEnterpriseConfig.Eap;
+import android.net.wifi.WifiEnterpriseConfig.Phase2;
 import android.net.wifi.WifiInfo;
 import android.os.Handler;
 import android.security.Credentials;
@@ -63,10 +65,6 @@
  */
 public class WifiConfigController implements TextWatcher,
         View.OnClickListener, AdapterView.OnItemSelectedListener {
-    private static final String KEYSTORE_SPACE = WifiConfiguration.KEYSTORE_URI;
-
-    private static final String PHASE2_PREFIX = "auth=";
-
     private final WifiConfigUiBase mConfigUi;
     private final View mView;
     private final AccessPoint mAccessPoint;
@@ -79,10 +77,20 @@
     private int mAccessPointSecurity;
     private TextView mPasswordView;
 
+    private String unspecifiedCert = "unspecified";
+    private static final int unspecifiedCertIndex = 0;
+
+    /* Phase2 methods supported by PEAP are limited */
+    private final ArrayAdapter<String> PHASE2_PEAP_ADAPTER;
+    /* Full list of phase2 methods */
+    private final ArrayAdapter<String> PHASE2_FULL_ADAPTER;
+
     private Spinner mSecuritySpinner;
     private Spinner mEapMethodSpinner;
     private Spinner mEapCaCertSpinner;
     private Spinner mPhase2Spinner;
+    // Associated with mPhase2Spinner, one of PHASE2_FULL_ADAPTER or PHASE2_PEAP_ADAPTER
+    private ArrayAdapter<String> mPhase2Adapter;
     private Spinner mEapUserCertSpinner;
     private TextView mEapIdentityView;
     private TextView mEapAnonymousView;
@@ -95,12 +103,17 @@
     public static final int PROXY_NONE = 0;
     public static final int PROXY_STATIC = 1;
 
-    /* These values from from "wifi_eap_method" resource array */
+    /* These values come from "wifi_eap_method" resource array */
     public static final int WIFI_EAP_METHOD_PEAP = 0;
     public static final int WIFI_EAP_METHOD_TLS  = 1;
     public static final int WIFI_EAP_METHOD_TTLS = 2;
     public static final int WIFI_EAP_METHOD_PWD  = 3;
 
+    /* These values come from "wifi_peap_phase2_entries" resource array */
+    public static final int WIFI_PEAP_PHASE2_NONE 	    = 0;
+    public static final int WIFI_PEAP_PHASE2_MSCHAPV2 	= 1;
+    public static final int WIFI_PEAP_PHASE2_GTC        = 2;
+
     private static final String TAG = "WifiConfigController";
 
     private Spinner mIpSettingsSpinner;
@@ -124,22 +137,6 @@
 
     private final Handler mTextViewChangedHandler;
 
-    static boolean requireKeyStore(WifiConfiguration config) {
-        if (config == null) {
-            return false;
-        }
-        if (!TextUtils.isEmpty(config.key_id.value())) {
-            return true;
-        }
-        String values[] = { config.ca_cert.value(), config.client_cert.value() };
-        for (String value : values) {
-            if (value != null && value.startsWith(KEYSTORE_SPACE)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     public WifiConfigController(
             WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit) {
         mConfigUi = parent;
@@ -155,6 +152,17 @@
         final Context context = mConfigUi.getContext();
         final Resources resources = context.getResources();
 
+        PHASE2_PEAP_ADAPTER = new ArrayAdapter<String>(
+            context, android.R.layout.simple_spinner_item,
+            context.getResources().getStringArray(R.array.wifi_peap_phase2_entries));
+        PHASE2_PEAP_ADAPTER.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
+        PHASE2_FULL_ADAPTER = new ArrayAdapter<String>(
+                context, android.R.layout.simple_spinner_item,
+                context.getResources().getStringArray(R.array.wifi_phase2_entries));
+        PHASE2_FULL_ADAPTER.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+
+        unspecifiedCert = context.getString(R.string.wifi_unspecified);
         mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
         mIpSettingsSpinner.setOnItemSelectedListener(this);
         mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
@@ -356,33 +364,58 @@
             case AccessPoint.SECURITY_EAP:
                 config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
                 config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
-                config.eap.setValue((String) mEapMethodSpinner.getSelectedItem());
-
-                config.phase2.setValue((mPhase2Spinner.getSelectedItemPosition() == 0) ? "" :
-                        PHASE2_PREFIX + mPhase2Spinner.getSelectedItem());
-                config.ca_cert.setValue((mEapCaCertSpinner.getSelectedItemPosition() == 0) ? "" :
-                        KEYSTORE_SPACE + Credentials.CA_CERTIFICATE +
-                        (String) mEapCaCertSpinner.getSelectedItem());
-                config.client_cert.setValue((mEapUserCertSpinner.getSelectedItemPosition() == 0) ?
-                        "" : KEYSTORE_SPACE + Credentials.USER_CERTIFICATE +
-                        (String) mEapUserCertSpinner.getSelectedItem());
-                final boolean isEmptyKeyId = (mEapUserCertSpinner.getSelectedItemPosition() == 0);
-                config.key_id.setValue(isEmptyKeyId ? "" : Credentials.USER_PRIVATE_KEY +
-                        (String) mEapUserCertSpinner.getSelectedItem());
-                config.engine.setValue(isEmptyKeyId ? WifiConfiguration.ENGINE_DISABLE :
-                        WifiConfiguration.ENGINE_ENABLE);
-                config.engine_id.setValue(isEmptyKeyId ? "" : WifiConfiguration.KEYSTORE_ENGINE_ID);
-                config.identity.setValue((mEapIdentityView.length() == 0) ? "" :
-                        mEapIdentityView.getText().toString());
-                config.anonymous_identity.setValue((mEapAnonymousView.length() == 0) ? "" :
+                config.enterpriseConfig = new WifiEnterpriseConfig();
+                int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
+                int phase2Method = mPhase2Spinner.getSelectedItemPosition();
+                config.enterpriseConfig.setEapMethod(eapMethod);
+                switch (eapMethod) {
+                    case Eap.PEAP:
+                        // PEAP supports limited phase2 values
+                        // Map the index from the PHASE2_PEAP_ADAPTER to the one used
+                        // by the API which has the full list of PEAP methods.
+                        switch(phase2Method) {
+                            case WIFI_PEAP_PHASE2_NONE:
+                                config.enterpriseConfig.setPhase2Method(Phase2.NONE);
+                                break;
+                            case WIFI_PEAP_PHASE2_MSCHAPV2:
+                                config.enterpriseConfig.setPhase2Method(Phase2.MSCHAPV2);
+                                break;
+                            case WIFI_PEAP_PHASE2_GTC:
+                                config.enterpriseConfig.setPhase2Method(Phase2.GTC);
+                                break;
+                            default:
+                                Log.e(TAG, "Unknown phase2 method" + phase2Method);
+                                break;
+                        }
+                        break;
+                    default:
+                        // The default index from PHASE2_FULL_ADAPTER maps to the API
+                        config.enterpriseConfig.setPhase2Method(phase2Method);
+                        break;
+                }
+                String caCert = (String) mEapCaCertSpinner.getSelectedItem();
+                if (caCert.equals(unspecifiedCert)) caCert = "";
+                config.enterpriseConfig.setCaCertificateAlias(caCert);
+                String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
+                if (clientCert.equals(unspecifiedCert)) clientCert = "";
+                config.enterpriseConfig.setClientCertificateAlias(clientCert);
+                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
+                config.enterpriseConfig.setAnonymousIdentity(
                         mEapAnonymousView.getText().toString());
-                if (mPasswordView.length() != 0) {
-                    config.password.setValue(mPasswordView.getText().toString());
+
+                if (mPasswordView.isShown()) {
+                    // For security reasons, a previous password is not displayed to user.
+                    // Update only if it has been changed.
+                    if (mPasswordView.length() > 0) {
+                        config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
+                    }
+                } else {
+                    // clear password
+                    config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
                 }
                 break;
-
             default:
-                    return null;
+                return null;
         }
 
         config.proxySettings = mProxySettings;
@@ -547,42 +580,144 @@
             loadCertificates(mEapCaCertSpinner, Credentials.CA_CERTIFICATE);
             loadCertificates(mEapUserCertSpinner, Credentials.USER_PRIVATE_KEY);
 
+            // Modifying an existing network
             if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
-                WifiConfiguration config = mAccessPoint.getConfig();
-                setSelection(mEapMethodSpinner, config.eap.value());
-
-                final String phase2Method = config.phase2.value();
-                if (phase2Method != null && phase2Method.startsWith(PHASE2_PREFIX)) {
-                    setSelection(mPhase2Spinner, phase2Method.substring(PHASE2_PREFIX.length()));
-                } else {
-                    setSelection(mPhase2Spinner, phase2Method);
+                WifiEnterpriseConfig enterpriseConfig = mAccessPoint.getConfig().enterpriseConfig;
+                int eapMethod = enterpriseConfig.getEapMethod();
+                int phase2Method = enterpriseConfig.getPhase2Method();
+                mEapMethodSpinner.setSelection(eapMethod);
+                showEapFieldsByMethod(eapMethod);
+                switch (eapMethod) {
+                    case Eap.PEAP:
+                        switch (phase2Method) {
+                            case Phase2.NONE:
+                                mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_NONE);
+                                break;
+                            case Phase2.MSCHAPV2:
+                                mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_MSCHAPV2);
+                                break;
+                            case Phase2.GTC:
+                                mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_GTC);
+                                break;
+                            default:
+                                Log.e(TAG, "Invalid phase 2 method " + phase2Method);
+                                break;
+                        }
+                        break;
+                    default:
+                        mPhase2Spinner.setSelection(phase2Method);
+                        break;
                 }
-
-                setCertificate(mEapCaCertSpinner, KEYSTORE_SPACE + Credentials.CA_CERTIFICATE,
-                        config.ca_cert.value());
-                setCertificate(mEapUserCertSpinner, Credentials.USER_PRIVATE_KEY,
-                        config.key_id.value());
-                mEapIdentityView.setText(config.identity.value());
-                mEapAnonymousView.setText(config.anonymous_identity.value());
+                setSelection(mEapCaCertSpinner, enterpriseConfig.getCaCertificateAlias());
+                setSelection(mEapUserCertSpinner, enterpriseConfig.getClientCertificateAlias());
+                mEapIdentityView.setText(enterpriseConfig.getIdentity());
+                mEapAnonymousView.setText(enterpriseConfig.getAnonymousIdentity());
+            } else {
+                // Choose a default for a new network and show only appropriate
+                // fields
+                mEapMethodSpinner.setSelection(Eap.PEAP);
+                showEapFieldsByMethod(Eap.PEAP);
             }
+        } else {
+            showEapFieldsByMethod(mEapMethodSpinner.getSelectedItemPosition());
         }
+    }
 
+    /**
+     * EAP-PWD valid fields include
+     *   identity
+     *   password
+     * EAP-PEAP valid fields include
+     *   phase2: MSCHAPV2, GTC
+     *   ca_cert
+     *   identity
+     *   anonymous_identity
+     *   password
+     * EAP-TLS valid fields include
+     *   user_cert
+     *   ca_cert
+     *   identity
+     * EAP-TTLS valid fields include
+     *   phase2: PAP, MSCHAP, MSCHAPV2, GTC
+     *   ca_cert
+     *   identity
+     *   anonymous_identity
+     *   password
+     */
+    private void showEapFieldsByMethod(int eapMethod) {
+        // Common defaults
         mView.findViewById(R.id.l_method).setVisibility(View.VISIBLE);
         mView.findViewById(R.id.l_identity).setVisibility(View.VISIBLE);
 
-        if (mEapMethodSpinner.getSelectedItemPosition() == WIFI_EAP_METHOD_PWD){
-            mView.findViewById(R.id.l_phase2).setVisibility(View.GONE);
-            mView.findViewById(R.id.l_ca_cert).setVisibility(View.GONE);
-            mView.findViewById(R.id.l_user_cert).setVisibility(View.GONE);
-            mView.findViewById(R.id.l_anonymous).setVisibility(View.GONE);
-        } else {
-            mView.findViewById(R.id.l_phase2).setVisibility(View.VISIBLE);
-            mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
-            mView.findViewById(R.id.l_user_cert).setVisibility(View.VISIBLE);
-            mView.findViewById(R.id.l_anonymous).setVisibility(View.VISIBLE);
+        // Defaults for most of the EAP methods and over-riden by
+        // by certain EAP methods
+        mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
+        mView.findViewById(R.id.password_layout).setVisibility(View.VISIBLE);
+        mView.findViewById(R.id.show_password_layout).setVisibility(View.VISIBLE);
+
+        Context context = mConfigUi.getContext();
+        switch (eapMethod) {
+            case WIFI_EAP_METHOD_PWD:
+                setPhase2Invisible();
+                setCaCertInvisible();
+                setAnonymousIdentInvisible();
+                setUserCertInvisible();
+                break;
+            case WIFI_EAP_METHOD_TLS:
+                mView.findViewById(R.id.l_user_cert).setVisibility(View.VISIBLE);
+                setPhase2Invisible();
+                setAnonymousIdentInvisible();
+                setPasswordInvisible();
+                break;
+            case WIFI_EAP_METHOD_PEAP:
+                // Reset adapter if needed
+                if (mPhase2Adapter != PHASE2_PEAP_ADAPTER) {
+                    mPhase2Adapter = PHASE2_PEAP_ADAPTER;
+                    mPhase2Spinner.setAdapter(mPhase2Adapter);
+                }
+                mView.findViewById(R.id.l_phase2).setVisibility(View.VISIBLE);
+                mView.findViewById(R.id.l_anonymous).setVisibility(View.VISIBLE);
+                setUserCertInvisible();
+                break;
+            case WIFI_EAP_METHOD_TTLS:
+                // Reset adapter if needed
+                if (mPhase2Adapter != PHASE2_FULL_ADAPTER) {
+                    mPhase2Adapter = PHASE2_FULL_ADAPTER;
+                    mPhase2Spinner.setAdapter(mPhase2Adapter);
+                }
+                mView.findViewById(R.id.l_phase2).setVisibility(View.VISIBLE);
+                mView.findViewById(R.id.l_anonymous).setVisibility(View.VISIBLE);
+                setUserCertInvisible();
+                break;
         }
     }
 
+    private void setPhase2Invisible() {
+        mView.findViewById(R.id.l_phase2).setVisibility(View.GONE);
+        mPhase2Spinner.setSelection(Phase2.NONE);
+    }
+
+    private void setCaCertInvisible() {
+        mView.findViewById(R.id.l_ca_cert).setVisibility(View.GONE);
+        mEapCaCertSpinner.setSelection(unspecifiedCertIndex);
+    }
+
+    private void setUserCertInvisible() {
+        mView.findViewById(R.id.l_user_cert).setVisibility(View.GONE);
+        mEapUserCertSpinner.setSelection(unspecifiedCertIndex);
+    }
+
+    private void setAnonymousIdentInvisible() {
+        mView.findViewById(R.id.l_anonymous).setVisibility(View.GONE);
+        mEapAnonymousView.setText("");
+    }
+
+    private void setPasswordInvisible() {
+        mPasswordView.setText("");
+        mView.findViewById(R.id.password_layout).setVisibility(View.GONE);
+        mView.findViewById(R.id.show_password_layout).setVisibility(View.GONE);
+    }
+
     private void showIpConfigFields() {
         WifiConfiguration config = null;
 
@@ -675,14 +810,13 @@
 
     private void loadCertificates(Spinner spinner, String prefix) {
         final Context context = mConfigUi.getContext();
-        final String unspecified = context.getString(R.string.wifi_unspecified);
 
         String[] certs = KeyStore.getInstance().saw(prefix);
         if (certs == null || certs.length == 0) {
-            certs = new String[] {unspecified};
+            certs = new String[] {unspecifiedCert};
         } else {
             final String[] array = new String[certs.length + 1];
-            array[0] = unspecified;
+            array[0] = unspecifiedCert;
             System.arraycopy(certs, 0, array, 1, certs.length);
             certs = array;
         }
@@ -693,12 +827,6 @@
         spinner.setAdapter(adapter);
     }
 
-    private void setCertificate(Spinner spinner, String prefix, String cert) {
-        if (cert != null && cert.startsWith(prefix)) {
-            setSelection(spinner, cert.substring(prefix.length()));
-        }
-    }
-
     private void setSelection(Spinner spinner, String value) {
         if (value != null) {
             @SuppressWarnings("unchecked")
diff --git a/src/com/android/settings/wifi/WifiConfigInfo.java b/src/com/android/settings/wifi/WifiConfigInfo.java
index 2ed4f02..9b680a8 100644
--- a/src/com/android/settings/wifi/WifiConfigInfo.java
+++ b/src/com/android/settings/wifi/WifiConfigInfo.java
@@ -31,15 +31,9 @@
  */
 public class WifiConfigInfo extends Activity {
 
-    private static final String TAG = "WifiConfigInfo";
-
     private TextView mConfigList;
     private WifiManager mWifiManager;
 
-    //============================
-    // Activity lifecycle
-    //============================
-
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -52,12 +46,16 @@
     @Override
     protected void onResume() {
         super.onResume();
-        final List<WifiConfiguration> wifiConfigs = mWifiManager.getConfiguredNetworks();
-        StringBuffer configList  = new StringBuffer();
-        for (int i = wifiConfigs.size() - 1; i >= 0; i--) {
-            configList.append(wifiConfigs.get(i));
+        if (mWifiManager.isWifiEnabled()) {
+            final List<WifiConfiguration> wifiConfigs = mWifiManager.getConfiguredNetworks();
+            StringBuffer configList  = new StringBuffer();
+            for (int i = wifiConfigs.size() - 1; i >= 0; i--) {
+                configList.append(wifiConfigs.get(i));
+            }
+            mConfigList.setText(configList);
+        } else {
+            mConfigList.setText(R.string.wifi_state_disabled);
         }
-        mConfigList.setText(configList);
     }
 
 }
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index aedb79e..274d49e 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -46,7 +46,6 @@
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceScreen;
 import android.security.Credentials;
-import android.security.KeyStore;
 import android.telephony.TelephonyManager;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -135,8 +134,6 @@
 
     private AtomicBoolean mConnected = new AtomicBoolean(false);
 
-    private int mKeyStoreNetworkId = INVALID_NETWORK_ID;
-
     private WifiDialog mDialog;
 
     private TextView mEmptyView;
@@ -412,12 +409,6 @@
         }
 
         getActivity().registerReceiver(mReceiver, mFilter);
-        if (mKeyStoreNetworkId != INVALID_NETWORK_ID &&
-                KeyStore.getInstance().state() == KeyStore.State.UNLOCKED) {
-            mWifiManager.connect(mKeyStoreNetworkId, mConnectListener);
-        }
-        mKeyStoreNetworkId = INVALID_NETWORK_ID;
-
         updateAccessPoints();
     }
 
@@ -560,10 +551,8 @@
         switch (item.getItemId()) {
             case MENU_ID_CONNECT: {
                 if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
-                    if (!requireKeyStore(mSelectedAccessPoint.getConfig())) {
-                        mWifiManager.connect(mSelectedAccessPoint.networkId,
-                                mConnectListener);
-                    }
+                    mWifiManager.connect(mSelectedAccessPoint.networkId,
+                            mConnectListener);
                 } else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
                     /** Bypass dialog for unsecured networks */
                     mSelectedAccessPoint.generateOpenNetworkConfig();
@@ -700,16 +689,6 @@
                && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN;
    }
 
-    private boolean requireKeyStore(WifiConfiguration config) {
-        if (WifiConfigController.requireKeyStore(config) &&
-                KeyStore.getInstance().state() != KeyStore.State.UNLOCKED) {
-            mKeyStoreNetworkId = config.networkId;
-            Credentials.getInstance().unlock(getActivity());
-            return true;
-        }
-        return false;
-    }
-
     /**
      * Shows the latest access points available with supplimental information like
      * the strength of network and the security for it.
@@ -835,7 +814,12 @@
                     WifiManager.EXTRA_NEW_STATE);
             if (!mConnected.get() && SupplicantState.isHandshakeState(state)) {
                 updateConnectionState(WifiInfo.getDetailedStateOf(state));
-            }
+             } else {
+                 // During a connect, we may have the supplicant
+                 // state change affect the detailed network state.
+                 // Make sure a lost connection is updated as well.
+                 updateConnectionState(null);
+             }
         } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
             NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
                     WifiManager.EXTRA_NETWORK_INFO);
@@ -971,7 +955,6 @@
 
         if (config == null) {
             if (mSelectedAccessPoint != null
-                    && !requireKeyStore(mSelectedAccessPoint.getConfig())
                     && mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
                 mWifiManager.connect(mSelectedAccessPoint.networkId,
                         mConnectListener);
@@ -981,7 +964,7 @@
                 mWifiManager.save(config, mSaveListener);
             }
         } else {
-            if (configController.isEdit() || requireKeyStore(config)) {
+            if (configController.isEdit()) {
                 mWifiManager.save(config, mSaveListener);
             } else {
                 mWifiManager.connect(config, mConnectListener);
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
index 2496d8e..beae432 100644
--- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
+++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
@@ -28,6 +28,7 @@
 import android.content.IntentFilter;
 import android.net.NetworkInfo;
 import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pInfo;
 import android.net.wifi.p2p.WifiP2pDevice;
 import android.net.wifi.p2p.WifiP2pDeviceList;
 import android.net.wifi.p2p.WifiP2pGroup;
@@ -88,6 +89,7 @@
     private boolean mWifiP2pSearching;
     private int mConnectedDevices;
     private WifiP2pGroup mConnectedGroup;
+    private boolean mLastGroupFormed = false;
 
     private PreferenceGroup mPeersGroup;
     private PreferenceGroup mPersistentGroup;
@@ -123,15 +125,19 @@
                 if (mWifiP2pManager == null) return;
                 NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(
                         WifiP2pManager.EXTRA_NETWORK_INFO);
+                WifiP2pInfo wifip2pinfo = (WifiP2pInfo) intent.getParcelableExtra(
+                        WifiP2pManager.EXTRA_WIFI_P2P_INFO);
                 if (mWifiP2pManager != null) {
                     mWifiP2pManager.requestGroupInfo(mChannel, WifiP2pSettings.this);
                 }
                 if (networkInfo.isConnected()) {
                     if (DBG) Log.d(TAG, "Connected");
-                } else {
+                } else if (mLastGroupFormed != true) {
                     //start a search when we are disconnected
+                    //but not on group removed broadcast event
                     startSearch();
                 }
+                mLastGroupFormed = wifip2pinfo.groupFormed;
             } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
                 mThisDevice = (WifiP2pDevice) intent.getParcelableExtra(
                         WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);