Merge "Part of effort to remove "failure" messaging to end-users. Bug: 5165745"
diff --git a/res/layout-land/crypt_keeper_progress.xml b/res/layout-land/crypt_keeper_progress.xml
new file mode 100644
index 0000000..62fb297
--- /dev/null
+++ b/res/layout-land/crypt_keeper_progress.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+  -->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:padding="16dip"
+    android:orientation="vertical"
+>
+
+    <TextView
+        android:id="@+id/title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:minHeight="48dip"
+        android:layout_alignParentLeft="true"
+        android:layout_centerVertical="true"
+        android:textSize="30dip"
+        android:textColor="#ff99cc00"
+        android:text="@string/crypt_keeper_setup_title"
+        android:gravity="bottom"
+    />
+
+    <!-- Divider -->
+    <RelativeLayout
+        android:id="@+id/top_divider"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+    >
+        <ProgressBar
+            android:id="@+id/progress_bar"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            style="?android:attr/progressBarStyleHorizontal"
+        />
+    </RelativeLayout>
+
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="0dip"
+        android:layout_weight="1"
+        android:orientation="horizontal"
+    >
+        <TextView
+            android:id="@+id/status"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:layout_width="0dip"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+        />
+
+        <ImageView
+            android:id="@+id/encroid"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:src="@drawable/encroid_waiting"
+        />
+
+        <Button
+            android:id="@+id/factory_reset"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_margin="32dip"
+            android:text="@string/master_clear_button_text"
+            android:visibility="gone"
+        />
+    </LinearLayout>
+
+</LinearLayout>
+
diff --git a/res/layout/crypt_keeper_password_entry.xml b/res/layout/crypt_keeper_password_entry.xml
index 60dcf6a..a7799fc 100644
--- a/res/layout/crypt_keeper_password_entry.xml
+++ b/res/layout/crypt_keeper_password_entry.xml
@@ -34,12 +34,12 @@
    <EditText android:id="@+id/passwordEntry"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
+       android:layout_marginLeft="8dip"
+       android:layout_marginRight="8dip"
        android:singleLine="true"
-       android:textStyle="normal"
        android:inputType="textPassword"
-       android:textSize="24sp"
+       android:textSize="18sp"
        android:textAppearance="?android:attr/textAppearanceMedium"
-       android:textColor="#ffffffff"
     />
 
    <!-- Emergency call button.
@@ -47,8 +47,8 @@
    <Button android:id="@+id/emergencyCallButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
-       android:layout_gravity="left"
-       android:layout_marginTop="10dip"
+       android:layout_gravity="center"
+       android:layout_marginTop="16dip"
        style="@*android:style/Widget.Button.Transparent"
        android:textSize="14sp"
        android:drawablePadding="6dip"
diff --git a/res/layout/crypt_keeper_progress.xml b/res/layout/crypt_keeper_progress.xml
index f8e3a1a..9677c3d 100644
--- a/res/layout/crypt_keeper_progress.xml
+++ b/res/layout/crypt_keeper_progress.xml
@@ -18,20 +18,17 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:paddingTop="60dip"
-    android:paddingLeft="128dip"
-    android:paddingRight="128dip"
-    android:paddingBottom="0dip" 
+    android:padding="16dip"
     android:orientation="vertical"
 >
 
     <TextView
+        android:id="@+id/title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:minHeight="48dip"
         android:layout_alignParentLeft="true"
         android:layout_centerVertical="true"
-        android:layout_marginLeft="16dip"
         android:textSize="30dip"
         android:textColor="#ff99cc00"
         android:text="@string/crypt_keeper_setup_title"
@@ -51,14 +48,32 @@
             style="?android:attr/progressBarStyleHorizontal"
         />
     </RelativeLayout>
-    
-    
+
+
     <TextView
         android:id="@+id/status"
+        android:textAppearance="?android:attr/textAppearanceMedium"
         android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+    />
+
+    <ImageView
+        android:id="@+id/encroid"
+        android:layout_width="wrap_content"
         android:layout_height="0dip"
         android:layout_weight="1"
-        android:layout_marginLeft="16dip"
+        android:layout_gravity="bottom|right"
+        android:src="@drawable/encroid_waiting"
+    />
+
+    <Button
+        android:id="@+id/factory_reset"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_margin="32dip"
+        android:layout_gravity="center"
+        android:text="@string/master_clear_button_text"
+        android:visibility="gone"
     />
 
 </LinearLayout>
diff --git a/res/layout/crypt_keeper_status.xml b/res/layout/crypt_keeper_status.xml
index d106c69..b830b57 100644
--- a/res/layout/crypt_keeper_status.xml
+++ b/res/layout/crypt_keeper_status.xml
@@ -91,7 +91,9 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginTop="10dip"
-        android:textSize="22sp"
+        android:layout_marginLeft="8dip"
+        android:layout_marginRight="8dip"
+        android:textSize="18sp"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:text="@string/enter_password"
         android:drawableLeft="@*android:drawable/ic_lock_idle_lock"
diff --git a/res/layout/preference_dialog_ringervolume.xml b/res/layout/preference_dialog_ringervolume.xml
index 66067b3..2c83f12 100644
--- a/res/layout/preference_dialog_ringervolume.xml
+++ b/res/layout/preference_dialog_ringervolume.xml
@@ -68,8 +68,7 @@
                         android:layout_height="wrap_content"
                         android:layout_weight="1"
                         android:paddingTop="2dip"
-                        android:paddingLeft="12dip"
-                        android:paddingRight="20dip" />
+                        android:layout_marginRight="@dimen/volume_seekbar_side_margin" />
         </LinearLayout>
 
         <!-- Used for the ringer/notification volume -->
@@ -109,8 +108,7 @@
                             android:layout_height="wrap_content"
                             android:layout_weight="1"
                             android:paddingTop="2dip"
-                            android:paddingLeft="12dip"
-                            android:paddingRight="20dip" />
+                            android:layout_marginRight="@dimen/volume_seekbar_side_margin" />
             </LinearLayout>
 
         </LinearLayout>
@@ -152,8 +150,7 @@
                             android:layout_height="wrap_content"
                             android:layout_weight="1"
                             android:paddingTop="2dip"
-                            android:paddingLeft="12dip"
-                            android:paddingRight="20dip" />
+                            android:layout_marginRight="@dimen/volume_seekbar_side_margin" />
             </LinearLayout>
 
         </LinearLayout>
@@ -187,8 +184,7 @@
                         android:layout_height="wrap_content"
                         android:layout_weight="1"
                         android:paddingTop="2dip"
-                        android:paddingLeft="12dip"
-                        android:paddingRight="20dip" />
+                        android:layout_marginRight="@dimen/volume_seekbar_side_margin" />
         </LinearLayout>
 
     </LinearLayout>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 8546e6b..09d94de 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -291,16 +291,27 @@
     </string-array>
 
     <!-- Match this with the constants in AccessPoint. --> <skip />
-    <!-- Wi-Fi settings.  The type of security a Wi-Fi network has. -->
+    <!-- Wi-Fi security choices used when manually added a Wi-Fi network -->
     <string-array name="wifi_security">
         <!-- The Wi-Fi network does not have any security. -->
-        <item>Open</item>
+        <item>@string/wifi_security_none</item>
         <!-- Do not translate. -->
-        <item>WEP</item>
+        <item>@string/wifi_security_wep</item>
         <!-- Do not translate. -->
-        <item>WPA/WPA2 PSK</item>
+        <item>@string/wifi_security_psk_generic</item>
         <!-- Do not translate. -->
-        <item>802.1x EAP</item>
+        <item>@string/wifi_security_eap</item>
+    </string-array>
+
+    <!-- Match this with the constants in AccessPoint. --> <skip />
+    <!-- Wi-Fi security types for New User Dialog. EAP is not configurable. -->
+    <string-array name="wifi_security_no_eap">
+        <!-- The Wi-Fi network does not have any security. -->
+        <item>@string/wifi_security_none</item>
+        <!-- Do not translate. -->
+        <item>@string/wifi_security_wep</item>
+        <!-- Do not translate. -->
+        <item>@string/wifi_security_psk_generic</item>
     </string-array>
 
    <!-- Wi-Fi AP settings.  The type of security a Wi-Fi AP supports. -->
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 4b576eb..dbe4c32 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -30,4 +30,6 @@
 
     <dimen name="data_usage_chart_height">220dip</dimen>
     <dimen name="data_usage_chart_optimalWidth">440dip</dimen>
+
+    <dimen name="volume_seekbar_side_margin">8dip</dimen>
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e024b33..b777fd7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1213,19 +1213,59 @@
     <!-- Hint for unspecified fields -->
     <string name="wifi_unspecified">(unspecified)</string>
     <!-- Summary for the remembered network. -->
-    <string name="wifi_remembered">Remembered</string>
-    <!-- Summary for the disabled network. -->
-    <string name="wifi_disabled">Disabled</string>
+    <string name="wifi_remembered">Saved</string>
+    <!-- Status for networks disabled for unknown reason -->
+    <string name="wifi_disabled_generic">Disabled</string>
+    <!-- Status for networked disabled from a DNS or DHCP failure -->
+    <string name="wifi_disabled_network_failure">Avoided poor connection</string>
+    <!-- Status for networks disabled from authentication failure (wrong password
+         or certificate). -->
+    <string name="wifi_disabled_password_failure">Authentication problem</string>
     <!-- Summary for the remembered network but currently not in range. -->
     <string name="wifi_not_in_range">Not in range</string>
-    <!-- Summary for an open network with WPS being available [CHAR LIMIT=50]-->
-    <string name="wifi_open_with_wps">WPS available</string>
-    <!-- Summary for the secured network. -->
-    <string name="wifi_secured">Secured with <xliff:g id="wifi_security">%1$s</xliff:g></string>
-    <!-- Summary for the secured network with WPS being available [CHAR LIMIT=50]-->
-    <string name="wifi_secured_with_wps">Secured with <xliff:g id="wifi_security">%1$s</xliff:g> (WPS available)</string>
-    <!-- Summary for the secured and remembered network. Status can be "Remembered", "Disabled" or "Not in range". -->
-    <string name="wifi_secured_with_status"><xliff:g id="wifi_status">%2$s</xliff:g>, secured with <xliff:g id="wifi_security">%1$s</xliff:g></string>
+    <!-- Substring of status line when Wi-Fi Protected Setup (WPS) is available and
+         string is listed first -->
+    <string name="wifi_wps_available_first_item">WPS available</string>
+    <!-- Substring of wifi status when Wi-Fi Protected Setup (WPS) is available and
+         string is listed after a wifi_secured_* string-->
+    <string name="wifi_wps_available_second_item">\u0020(WPS available)</string>
+    <!-- Substring of wifi status for wifi with authentication.  This version is for when the
+         string is first in the list (titlecase in english) -->
+    <string name="wifi_secured_first_item">Secured with <xliff:g id="wifi_security_short">%1$s</xliff:g></string>
+    <!-- Substring of wifi status for wifi with authentication.  This version is for when the
+         string is not first in the list (lowercase in english) -->
+    <string name="wifi_secured_second_item">, secured with <xliff:g id="wifi_security_short">%1$s</xliff:g></string>
+
+    <!-- Do not translate.  Concise terminology for wifi with WEP security -->
+    <string name="wifi_security_short_wep">WEP</string>
+    <!-- Do not translate.  Concise terminology for wifi with WPA security -->
+    <string name="wifi_security_short_wpa">WPA</string>
+    <!-- Do not translate.  Concise terminology for wifi with WPA2 security -->
+    <string name="wifi_security_short_wpa2">WPA2</string>
+    <!-- Do not translate.  Concise terminology for wifi with both WPA/WPA2 security -->
+    <string name="wifi_security_short_wpa_wpa2">WPA/WPA2</string>
+    <!-- Do not translate.  Concise terminology for wifi with unknown PSK type -->
+    <string name="wifi_security_short_psk_generic">@string/wifi_security_short_wpa_wpa2</string>
+    <!-- Do not translate.  Concise terminology for wifi with 802.1x EAP security -->
+    <string name="wifi_security_short_eap">802.1x</string>
+
+    <!-- Used in Wi-Fi settings dialogs when Wi-Fi does not have any security. -->
+    <string name="wifi_security_none">None</string>
+
+    <!-- Do not translate.  Terminology for wifi with WEP security -->
+    <string name="wifi_security_wep">WEP</string>
+    <!-- Do not translate.  Terminology for wifi with WPA security -->
+    <string name="wifi_security_wpa">WPA PSK</string>
+    <!-- Do not translate.  Terminology for wifi with WPA2 security -->
+    <string name="wifi_security_wpa2">WPA2 PSK</string>
+    <!-- Do not translate.  Terminology for wifi with both WPA/WPA2 security, or unknown -->
+    <string name="wifi_security_wpa_wpa2">WPA/WPA2 PSK</string>
+    <!-- Do not translate.  Terminology for wifi with unknown PSK type -->
+    <string name="wifi_security_psk_generic">@string/wifi_security_wpa_wpa2</string>
+    <!-- Do not translate.  Concise terminology for wifi with 802.1x EAP security -->
+    <string name="wifi_security_eap">802.1x EAP</string>
+
+
     <!-- Button label to connect to a Wi-Fi network -->
     <string name="wifi_connect">Connect</string>
     <!-- Button label to delete a Wi-Fi network -->
@@ -1550,7 +1590,7 @@
     <!-- Sound & display settings screen, setting option summary displaying the currently selected font size -->
     <string name="summary_font_size" translatable="false">%1$s</string>
     <!-- [CHAR LIMIT=40] Sound & display settings screen, title of dialog for picking font size -->
-    <string name="dialog_title_font_size">Select font size</string>
+    <string name="dialog_title_font_size">Font size</string>
 
     <!-- SIM lock settings title -->
     <string name="sim_lock_settings">SIM card lock settings</string>
diff --git a/res/xml/manage_accounts_settings.xml b/res/xml/manage_accounts_settings.xml
index 8ddd7e7..ebb702a 100644
--- a/res/xml/manage_accounts_settings.xml
+++ b/res/xml/manage_accounts_settings.xml
@@ -19,14 +19,8 @@
     <PreferenceCategory
             android:title="@string/header_general_sync_settings" />
 
-    <CheckBoxPreference android:key="backgroundDataCheckBox"
-        android:persistent="false"
-        android:title="@string/background_data"
-        android:summary="@string/background_data_summary"/>
-
     <CheckBoxPreference android:key="syncAutomaticallyCheckBox"
         android:persistent="false"
-        android:dependency="backgroundDataCheckBox"
         android:title="@string/sync_automatically"
         android:summary="@string/sync_automatically_summary"/>
 
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index 612f4c0..297288b 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -16,10 +16,6 @@
 
 package com.android.settings;
 
-import com.android.internal.telephony.ITelephony;
-import com.android.internal.widget.PasswordEntryKeyboardHelper;
-import com.android.internal.widget.PasswordEntryKeyboardView;
-
 import android.app.Activity;
 import android.app.StatusBarManager;
 import android.content.ComponentName;
@@ -53,6 +49,23 @@
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
+import com.android.internal.telephony.ITelephony;
+import com.android.internal.widget.PasswordEntryKeyboardHelper;
+import com.android.internal.widget.PasswordEntryKeyboardView;
+
+/**
+ * Settings screens to show the UI flows for encrypting/decrypting the device.
+ *
+ * This may be started via adb for debugging the UI layout, without having to go through
+ * encryption flows everytime. It should be noted that starting the activity in this manner
+ * is only useful for verifying UI-correctness - the behavior will not be identical.
+ * <pre>
+ * $ adb shell pm enable com.android.settings/.CryptKeeper
+ * $ adb shell am start \
+ *     -e "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW" "progress" \
+ *     -n com.android.settings/.CryptKeeper
+ * </pre>
+ */
 public class CryptKeeper extends Activity implements TextView.OnEditorActionListener {
     private static final String TAG = "CryptKeeper";
 
@@ -68,6 +81,13 @@
     // Intent action for launching the Emergency Dialer activity.
     static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL";
 
+    // Debug Intent extras so that this Activity may be started via adb for debugging UI layouts
+    private static final String EXTRA_FORCE_VIEW =
+            "com.android.settings.CryptKeeper.DEBUG_FORCE_VIEW";
+    private static final String FORCE_VIEW_PROGRESS = "progress";
+    private static final String FORCE_VIEW_ENTRY = "entry";
+    private static final String FORCE_VIEW_ERROR = "error";
+
     private int mCooldown;
     PowerManager.WakeLock mWakeLock;
     private EditText mPasswordEntry;
@@ -162,7 +182,7 @@
         }
     }
 
-    private Handler mHandler = new Handler() {
+    private final Handler mHandler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
             switch (msg.what) {
@@ -177,13 +197,23 @@
         }
     };
 
+    /** @return whether or not this Activity was started for debugging the UI only. */
+    private boolean isDebugView() {
+        return getIntent().hasExtra(EXTRA_FORCE_VIEW);
+    }
+
+    /** @return whether or not this Activity was started for debugging the specific UI view only. */
+    private boolean isDebugView(String viewType /* non-nullable */) {
+        return viewType.equals(getIntent().getStringExtra(EXTRA_FORCE_VIEW));
+    }
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         // If we are not encrypted or encrypting, get out quickly.
         String state = SystemProperties.get("vold.decrypt");
-        if ("".equals(state) || DECRYPT_STATE.equals(state)) {
+        if (!isDebugView() && ("".equals(state) || DECRYPT_STATE.equals(state))) {
             // Disable the crypt keeper.
             PackageManager pm = getPackageManager();
             ComponentName name = new ComponentName(this, CryptKeeper.class);
@@ -219,7 +249,9 @@
 
         // Check to see why we were started.
         String progress = SystemProperties.get("vold.encrypt_progress");
-        if (!"".equals(progress)) {
+        if (!"".equals(progress)
+                || isDebugView(FORCE_VIEW_PROGRESS)
+                || isDebugView(FORCE_VIEW_ERROR)) {
             setContentView(R.layout.crypt_keeper_progress);
             encryptionProgressInit();
         } else {
@@ -295,20 +327,23 @@
         tv.setText(R.string.crypt_keeper_failed_summary);
 
         View view = findViewById(R.id.bottom_divider);
-        view.setVisibility(View.VISIBLE);
+        if (view != null) {
+            view.setVisibility(View.VISIBLE);
+        }
     }
 
     private void updateProgress() {
         String state = SystemProperties.get("vold.encrypt_progress");
 
-        if ("error_partially_encrypted".equals(state)) {
+        if ("error_partially_encrypted".equals(state) || isDebugView(FORCE_VIEW_ERROR)) {
             showFactoryReset();
             return;
         }
 
         int progress = 0;
         try {
-            progress = Integer.parseInt(state);
+            // Force a 50% progress state when debugging the view.
+            progress = isDebugView() ? 50 : Integer.parseInt(state);
         } catch (Exception e) {
             Log.w(TAG, "Error parsing progress: " + e.toString());
         }
diff --git a/src/com/android/settings/accounts/ManageAccountsSettings.java b/src/com/android/settings/accounts/ManageAccountsSettings.java
index d9dea00..05f74dd 100644
--- a/src/com/android/settings/accounts/ManageAccountsSettings.java
+++ b/src/com/android/settings/accounts/ManageAccountsSettings.java
@@ -16,26 +16,17 @@
 
 package com.android.settings.accounts;
 
-import com.android.settings.AccountPreference;
-import com.android.settings.DialogCreatable;
-import com.android.settings.R;
-
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.accounts.AuthenticatorDescription;
 import android.accounts.OnAccountsUpdateListener;
 import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
 import android.content.ContentResolver;
-import android.content.Context;
-import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SyncAdapterType;
 import android.content.SyncInfo;
 import android.content.SyncStatusInfo;
 import android.graphics.drawable.Drawable;
-import android.net.ConnectivityManager;
 import android.os.Bundle;
 import android.preference.CheckBoxPreference;
 import android.preference.Preference;
@@ -52,6 +43,10 @@
 import android.widget.Button;
 import android.widget.TextView;
 
+import com.android.settings.AccountPreference;
+import com.android.settings.DialogCreatable;
+import com.android.settings.R;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -67,14 +62,11 @@
 
     private static final String AUTO_SYNC_CHECKBOX_KEY = "syncAutomaticallyCheckBox";
     private static final String MANAGE_ACCOUNTS_CATEGORY_KEY = "manageAccountsCategory";
-    private static final String BACKGROUND_DATA_CHECKBOX_KEY = "backgroundDataCheckBox";
-    private static final int DIALOG_DISABLE_BACKGROUND_DATA = 1;
 
     private static final int MENU_ADD_ACCOUNT = Menu.FIRST;
 
     private static final int REQUEST_SHOW_SYNC_SETTINGS = 1;
 
-    private CheckBoxPreference mBackgroundDataCheckBox;
     private PreferenceCategory mManageAccountsCategory;
     private String[] mAuthorities;
     private TextView mErrorInfoView;
@@ -122,7 +114,6 @@
                 activity.getResources().getDrawable(R.drawable.ic_list_syncerror),
                 null, null, null);
 
-        mBackgroundDataCheckBox = (CheckBoxPreference) findPreference(BACKGROUND_DATA_CHECKBOX_KEY);
         mAutoSyncCheckbox = (CheckBoxPreference) findPreference(AUTO_SYNC_CHECKBOX_KEY);
 
         mManageAccountsCategory = (PreferenceCategory)findPreference(MANAGE_ACCOUNTS_CATEGORY_KEY);
@@ -139,22 +130,7 @@
 
     @Override
     public boolean onPreferenceTreeClick(PreferenceScreen preferences, Preference preference) {
-        if (preference == mBackgroundDataCheckBox) {
-            final ConnectivityManager connManager = (ConnectivityManager)
-                    getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
-            final boolean oldBackgroundDataSetting = connManager.getBackgroundDataSetting();
-            final boolean backgroundDataSetting = mBackgroundDataCheckBox.isChecked();
-            if (oldBackgroundDataSetting != backgroundDataSetting) {
-                if (backgroundDataSetting) {
-                    setBackgroundDataInt(true);
-                    onSyncStateUpdated();
-                } else {
-                    // This will get unchecked only if the user hits "Ok"
-                    mBackgroundDataCheckBox.setChecked(true);
-                    showDialog(DIALOG_DISABLE_BACKGROUND_DATA);
-                }
-            }
-        } else if (preference == mAutoSyncCheckbox) {
+        if (preference == mAutoSyncCheckbox) {
             ContentResolver.setMasterSyncAutomatically(mAutoSyncCheckbox.isChecked());
             onSyncStateUpdated();
         } else if (preference instanceof AccountPreference) {
@@ -175,31 +151,6 @@
     }
 
     @Override
-    public Dialog onCreateDialog(int id) {
-        switch (id) {
-            case DIALOG_DISABLE_BACKGROUND_DATA:
-                final CheckBoxPreference pref =
-                    (CheckBoxPreference) findPreference(BACKGROUND_DATA_CHECKBOX_KEY);
-                return new AlertDialog.Builder(getActivity())
-                        .setTitle(R.string.background_data_dialog_title)
-                        .setIcon(android.R.drawable.ic_dialog_alert)
-                        .setMessage(R.string.background_data_dialog_message)
-                        .setPositiveButton(android.R.string.ok,
-                                    new DialogInterface.OnClickListener() {
-                                public void onClick(DialogInterface dialog, int which) {
-                                    setBackgroundDataInt(false);
-                                    pref.setChecked(false);
-                                    onSyncStateUpdated();
-                                }
-                            })
-                        .setNegativeButton(android.R.string.cancel, null)
-                        .create();
-        }
-
-        return null;
-    }
-
-    @Override
     public void showDialog(int dialogId) {
         if (mDialogFragment != null) {
             Log.e(TAG, "Old dialog fragment not null!");
@@ -226,22 +177,11 @@
         }
     }
 
-    private void setBackgroundDataInt(boolean enabled) {
-        if (getActivity() == null) return;
-        final ConnectivityManager connManager = (ConnectivityManager)
-                getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
-        connManager.setBackgroundDataSetting(enabled);
-    }
-
     @Override
     protected void onSyncStateUpdated() {
         // Catch any delayed delivery of update messages
         if (getActivity() == null) return;
         // Set background connection state
-        final ConnectivityManager connManager = (ConnectivityManager)
-                getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
-        final boolean backgroundDataSetting = connManager.getBackgroundDataSetting();
-        mBackgroundDataCheckBox.setChecked(backgroundDataSetting);
         boolean masterSyncAutomatically = ContentResolver.getMasterSyncAutomatically();
         mAutoSyncCheckbox.setChecked(masterSyncAutomatically);
 
@@ -275,7 +215,6 @@
                     SyncStatusInfo status = ContentResolver.getSyncStatus(account, authority);
                     boolean syncEnabled = ContentResolver.getSyncAutomatically(account, authority)
                             && masterSyncAutomatically
-                            && backgroundDataSetting
                             && (ContentResolver.getIsSyncable(account, authority) > 0);
                     boolean authorityIsPending = ContentResolver.isSyncPending(account, authority);
                     boolean activelySyncing = currentSync != null
diff --git a/src/com/android/settings/wifi/AccessPoint.java b/src/com/android/settings/wifi/AccessPoint.java
index 8181746..799a8da 100644
--- a/src/com/android/settings/wifi/AccessPoint.java
+++ b/src/com/android/settings/wifi/AccessPoint.java
@@ -16,8 +16,6 @@
 
 package com.android.settings.wifi;
 
-import com.android.settings.R;
-
 import android.content.Context;
 import android.net.NetworkInfo.DetailedState;
 import android.net.wifi.ScanResult;
@@ -27,35 +25,48 @@
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
 import android.preference.Preference;
+import android.util.Log;
 import android.view.View;
 import android.widget.ImageView;
 
-import java.util.Comparator;
+import com.android.settings.R;
 
 class AccessPoint extends Preference {
+    static final String TAG = "Settings.AccessPoint";
 
     private static final String KEY_DETAILEDSTATE = "key_detailedstate";
     private static final String KEY_WIFIINFO = "key_wifiinfo";
     private static final String KEY_SCANRESULT = "key_scanresult";
     private static final String KEY_CONFIG = "key_config";
 
-    private static final int[] STATE_SECURED = {R.attr.state_encrypted};
+    private static final int[] STATE_SECURED = {
+        R.attr.state_encrypted
+    };
     private static final int[] STATE_NONE = {};
 
-
+    /** These values are matched in string arrays -- changes must be kept in sync */
     static final int SECURITY_NONE = 0;
     static final int SECURITY_WEP = 1;
     static final int SECURITY_PSK = 2;
     static final int SECURITY_EAP = 3;
 
+    enum PskType {
+        UNKNOWN,
+        WPA,
+        WPA2,
+        WPA_WPA2
+    }
+
     String ssid;
     String bssid;
     int security;
     int networkId;
     boolean wpsAvailable = false;
 
+    PskType pskType = PskType.UNKNOWN;
+
     private WifiConfiguration mConfig;
-    /*package*/ScanResult mScanResult;
+    /* package */ScanResult mScanResult;
 
     private int mRssi;
     private WifiInfo mInfo;
@@ -84,6 +95,52 @@
         return SECURITY_NONE;
     }
 
+    public String getSecurityString(boolean concise) {
+        Context context = getContext();
+        switch(security) {
+            case SECURITY_EAP:
+                return concise ? context.getString(R.string.wifi_security_short_eap) :
+                    context.getString(R.string.wifi_security_eap);
+            case SECURITY_PSK:
+                switch (pskType) {
+                    case WPA:
+                        return concise ? context.getString(R.string.wifi_security_short_wpa) :
+                            context.getString(R.string.wifi_security_wpa);
+                    case WPA2:
+                        return concise ? context.getString(R.string.wifi_security_short_wpa2) :
+                            context.getString(R.string.wifi_security_wpa2);
+                    case WPA_WPA2:
+                        return concise ? context.getString(R.string.wifi_security_short_wpa_wpa2) :
+                            context.getString(R.string.wifi_security_wpa_wpa2);
+                    case UNKNOWN:
+                    default:
+                        return concise ? context.getString(R.string.wifi_security_short_psk_generic)
+                                : context.getString(R.string.wifi_security_psk_generic);
+                }
+            case SECURITY_WEP:
+                return concise ? context.getString(R.string.wifi_security_short_wep) :
+                    context.getString(R.string.wifi_security_wep);
+            case SECURITY_NONE:
+            default:
+                return concise ? "" : context.getString(R.string.wifi_security_none);
+        }
+    }
+
+    private static PskType getPskType(ScanResult result) {
+        boolean wpa = result.capabilities.contains("WPA-PSK");
+        boolean wpa2 = result.capabilities.contains("WPA2-PSK");
+        if (wpa2 && wpa) {
+            return PskType.WPA_WPA2;
+        } else if (wpa2) {
+            return PskType.WPA2;
+        } else if (wpa) {
+            return PskType.WPA;
+        } else {
+            Log.w(TAG, "Received abnormal flag string: " + result.capabilities);
+            return PskType.UNKNOWN;
+        }
+    }
+
     AccessPoint(Context context, WifiConfiguration config) {
         super(context);
         setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
@@ -138,6 +195,8 @@
         bssid = result.BSSID;
         security = getSecurity(result);
         wpsAvailable = security != SECURITY_EAP && result.capabilities.contains("WPS");
+        if (security == SECURITY_PSK)
+            pskType = getPskType(result);
         networkId = -1;
         mRssi = result.level;
         mScanResult = result;
@@ -185,13 +244,15 @@
         return ssid.compareToIgnoreCase(other.ssid);
     }
 
-
     boolean update(ScanResult result) {
         // We do not call refresh() since this is called before onBindView().
         if (ssid.equals(result.SSID) && security == getSecurity(result)) {
             if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) {
                 mRssi = result.level;
             }
+            // This flag only comes from scans, is not easily saved in config
+            if (security == SECURITY_PSK)
+                pskType = getPskType(result);
             return true;
         }
         return false;
@@ -255,34 +316,46 @@
         Context context = getContext();
         mSignal.setImageLevel(getLevel());
 
-        if (mState != null) {
+        if (mState != null) { // This is the active connection
             setSummary(Summary.get(context, mState));
-        } else {
-            String status = null;
-            if (mRssi == Integer.MAX_VALUE) {
-                status = context.getString(R.string.wifi_not_in_range);
-            } else if (mConfig != null) {
-                status = context.getString((mConfig.status == WifiConfiguration.Status.DISABLED) ?
-                        R.string.wifi_disabled : R.string.wifi_remembered);
+        } 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) {
+            switch (mConfig.disableReason) {
+                case WifiConfiguration.DISABLED_AUTH_FAILURE:
+                    setSummary(context.getString(R.string.wifi_disabled_password_failure));
+                    break;
+                case WifiConfiguration.DISABLED_DHCP_FAILURE:
+                case WifiConfiguration.DISABLED_DNS_FAILURE:
+                    setSummary(context.getString(R.string.wifi_disabled_network_failure));
+                    break;
+                case WifiConfiguration.DISABLED_UNKNOWN_REASON:
+                    setSummary(context.getString(R.string.wifi_disabled_generic));
+            }
+        } else { // In range, not disabled.
+            StringBuilder summary = new StringBuilder();
+            if (mConfig != null) { // Is saved network
+                summary.append(context.getString(R.string.wifi_remembered));
             }
 
-            if (security == SECURITY_NONE) {
-                if (wpsAvailable && mConfig == null) {
-                    setSummary(context.getString(R.string.wifi_open_with_wps));
+            if (security != SECURITY_NONE) {
+                String securityStrFormat;
+                if (summary.length() == 0) {
+                    securityStrFormat = context.getString(R.string.wifi_secured_first_item);
                 } else {
-                    setSummary(status);
+                    securityStrFormat = context.getString(R.string.wifi_secured_second_item);
                 }
-            } else {
-                String format;
-                if (wpsAvailable && mConfig == null) {
-                    format = context.getString(R.string.wifi_secured_with_wps);
-                } else {
-                    format = context.getString((status == null) ?
-                            R.string.wifi_secured : R.string.wifi_secured_with_status);
-                }
-                String[] type = context.getResources().getStringArray(R.array.wifi_security);
-                setSummary(String.format(format, type[security], status));
+                summary.append(String.format(securityStrFormat, getSecurityString(true)));
             }
+
+            if (mConfig == null && wpsAvailable) { // Only list WPS available for unsaved networks
+                if (summary.length() == 0) {
+                    summary.append(context.getString(R.string.wifi_wps_available_first_item));
+                } else {
+                    summary.append(context.getString(R.string.wifi_wps_available_second_item));
+                }
+            }
+            setSummary(summary.toString());
         }
     }
 }
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 876fd99..f879b85 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -158,10 +158,11 @@
                 mView.findViewById(R.id.type_ssid).setVisibility(View.VISIBLE);
                 mView.findViewById(R.id.type_security).setVisibility(View.VISIBLE);
                 // We want custom layout. The content must be same as the other cases.
-                mSecuritySpinner.setAdapter(
-                        new ArrayAdapter<String>(context, R.layout.wifi_setup_custom_list_item_1,
-                                android.R.id.text1,
-                                context.getResources().getStringArray(R.array.wifi_security)));
+
+                ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
+                        R.layout.wifi_setup_custom_list_item_1, android.R.id.text1,
+                        context.getResources().getStringArray(R.array.wifi_security_no_eap));
+                mSecuritySpinner.setAdapter(adapter);
             } else {
                 mView.findViewById(R.id.type).setVisibility(View.VISIBLE);
             }
@@ -181,8 +182,7 @@
                 addRow(group, R.string.wifi_status, Summary.get(mConfigUi.getContext(), state));
             }
 
-            String[] type = resources.getStringArray(R.array.wifi_security);
-            addRow(group, R.string.wifi_security, type[mAccessPoint.security]);
+            addRow(group, R.string.wifi_security, mAccessPoint.getSecurityString(false));
 
             int level = mAccessPoint.getLevel();
             if (level != -1) {
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index b3259e0..dff6d2a 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -511,6 +511,7 @@
                 for (AccessPoint accessPoint : accessPoints) {
                     if (accessPoint.update(result)) {
                         found = true;
+                        break;
                     }
                 }
                 if (!found) {
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pEnabler.java b/src/com/android/settings/wifi/p2p/WifiP2pEnabler.java
index fd79a58..608aa02 100644
--- a/src/com/android/settings/wifi/p2p/WifiP2pEnabler.java
+++ b/src/com/android/settings/wifi/p2p/WifiP2pEnabler.java
@@ -43,6 +43,7 @@
     private final IntentFilter mIntentFilter;
     private final Handler mHandler = new WifiP2pHandler();
     private WifiP2pManager mWifiP2pManager;
+    private WifiP2pManager.Channel mChannel;
 
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
@@ -61,11 +62,16 @@
         mSwitch = switch_;
 
         mWifiP2pManager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
-        if (!mWifiP2pManager.connectHandler(mContext, mHandler)) {
-            //Failure to set up connection
-            Log.e(TAG, "Failed to set up connection with wifi p2p service");
-            mWifiP2pManager = null;
-            mSwitch.setEnabled(false);
+        if (mWifiP2pManager != null) {
+            mChannel = mWifiP2pManager.initialize(mContext, mHandler);
+            if (mChannel == null) {
+                //Failure to set up connection
+                Log.e(TAG, "Failed to set up connection with wifi p2p service");
+                mWifiP2pManager = null;
+                mSwitch.setEnabled(false);
+            }
+        } else {
+            Log.e(TAG, "mWifiP2pManager is null!");
         }
         mIntentFilter = new IntentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
 
@@ -97,9 +103,9 @@
         if (mWifiP2pManager == null) return;
 
         if (isChecked) {
-            mWifiP2pManager.enableP2p();
+            mWifiP2pManager.enableP2p(mChannel);
         } else {
-            mWifiP2pManager.disableP2p();
+            mWifiP2pManager.disableP2p(mChannel);
         }
     }
 
diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
index 6ec3a1a..fe6d392 100644
--- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
+++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java
@@ -26,6 +26,7 @@
 import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.net.NetworkInfo;
 import android.net.wifi.p2p.WifiP2pConfig;
 import android.net.wifi.p2p.WifiP2pDevice;
 import android.net.wifi.p2p.WifiP2pDeviceList;
@@ -64,6 +65,7 @@
     private final IntentFilter mIntentFilter = new IntentFilter();
     private final Handler mHandler = new WifiP2pHandler();
     private WifiP2pManager mWifiP2pManager;
+    private WifiP2pManager.Channel mChannel;
     private WifiP2pEnabler mWifiP2pEnabler;
     private WifiP2pDialog mConnectDialog;
     private OnClickListener mConnectListener;
@@ -81,7 +83,18 @@
             if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
                 //TODO: nothing right now
             } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
-                if (mWifiP2pManager != null) mWifiP2pManager.requestPeers();
+                if (mWifiP2pManager != null) mWifiP2pManager.requestPeers(mChannel);
+            } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
+                if (mWifiP2pManager == null) return;
+                NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(
+                        WifiP2pManager.EXTRA_NETWORK_INFO);
+                if (networkInfo.isConnected()) {
+                    Log.d(TAG, "Start peer connections");
+                    mWifiP2pManager.startPeerCommunication();
+                } else {
+                    Log.d(TAG, "Stop peer connections");
+                    mWifiP2pManager.stopPeerCommunication();
+                }
             }
         }
     };
@@ -93,13 +106,19 @@
 
         mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
         mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
+        mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
 
         final Activity activity = getActivity();
         mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
-        if (!mWifiP2pManager.connectHandler(activity, mHandler)) {
-            //Failure to set up connection
-            Log.e(TAG, "Failed to set up connection with wifi p2p service");
-            mWifiP2pManager = null;
+        if (mWifiP2pManager != null) {
+            mChannel = mWifiP2pManager.initialize(activity, mHandler);
+            if (mChannel == null) {
+                //Failure to set up connection
+                Log.e(TAG, "Failed to set up connection with wifi p2p service");
+                mWifiP2pManager = null;
+            }
+        } else {
+            Log.e(TAG, "mWifiP2pManager is null !");
         }
 
         Switch actionBarSwitch = new Switch(activity);
@@ -128,7 +147,7 @@
                 if (which == DialogInterface.BUTTON_POSITIVE) {
                     WifiP2pConfig config = mConnectDialog.getConfig();
                     if (mWifiP2pManager != null) {
-                        mWifiP2pManager.connect(config);
+                        mWifiP2pManager.connect(mChannel, config);
                     }
                 }
             }
@@ -140,7 +159,7 @@
             public void onClick(DialogInterface dialog, int which) {
                 if (which == DialogInterface.BUTTON_POSITIVE) {
                     if (mWifiP2pManager != null) {
-                        mWifiP2pManager.disconnect();
+                        mWifiP2pManager.disconnect(mChannel);
                     }
                 }
             }
@@ -155,7 +174,8 @@
         if (mWifiP2pEnabler != null) {
             mWifiP2pEnabler.resume();
         }
-        if (mWifiP2pManager != null) mWifiP2pManager.discoverPeers();
+
+        if (mWifiP2pManager != null) mWifiP2pManager.discoverPeers(mChannel);
     }
 
     @Override
@@ -182,10 +202,14 @@
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case MENU_ID_SEARCH:
-                mWifiP2pManager.discoverPeers();
+                if (mWifiP2pManager != null) {
+                    mWifiP2pManager.discoverPeers(mChannel);
+                }
                 return true;
             case MENU_ID_CREATE_GROUP:
-                mWifiP2pManager.createGroup();
+                if (mWifiP2pManager != null) {
+                    mWifiP2pManager.createGroup(mChannel);
+                }
                 return true;
             case MENU_ID_ADVANCED:
                 //TODO: add advanced settings for p2p