Merge "Fix UI checkbox issue while disabling "Phone Audio" in Blueotooth Settings." into mnc-dev
diff --git a/res/layout/wifi_ap_dialog.xml b/res/layout/wifi_ap_dialog.xml
index 5452cd0..168f9ae 100644
--- a/res/layout/wifi_ap_dialog.xml
+++ b/res/layout/wifi_ap_dialog.xml
@@ -27,92 +27,112 @@
         <LinearLayout android:id="@+id/info"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                style="@style/wifi_item"
-                android:orientation="vertical" />
+                style="@style/wifi_section" />
 
         <LinearLayout android:id="@+id/type"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                style="@style/wifi_item"
-                android:orientation="vertical"
+                style="@style/wifi_section"
                 android:visibility="gone">
 
-            <TextView
+            <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    style="@style/wifi_item_label"
-                    android:layout_marginTop="8dip"
-                    android:text="@string/wifi_ssid" />
+                    style="@style/wifi_item">
+                <TextView
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_label"
+                        android:layout_marginTop="8dip"
+                        android:text="@string/wifi_ssid" />
 
-            <EditText android:id="@+id/ssid"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    style="@style/wifi_item_edit_content"
-                    android:singleLine="true"
-                    android:hint="@string/wifi_ssid_hint"
-                    android:inputType="textNoSuggestions"
-                    android:maxLength="32" />
+                <EditText android:id="@+id/ssid"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_edit_content"
+                        android:singleLine="true"
+                        android:hint="@string/wifi_ssid_hint"
+                        android:inputType="textNoSuggestions"
+                        android:maxLength="32" />
+            </LinearLayout>
 
-            <TextView
+            <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    style="@style/wifi_item_label"
-                    android:layout_marginTop="8dip"
-                    android:text="@string/wifi_security" />
+                    style="@style/wifi_item">
+                <TextView
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_label"
+                        android:layout_marginTop="8dip"
+                        android:text="@string/wifi_security" />
 
-            <Spinner android:id="@+id/security"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    style="@style/wifi_item_content"
-                    android:prompt="@string/wifi_security"
-                    android:entries="@array/wifi_ap_security" />
+                <Spinner android:id="@+id/security"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_content"
+                        android:prompt="@string/wifi_security"
+                        android:entries="@array/wifi_ap_security" />
+            </LinearLayout>
 
         </LinearLayout>
 
         <LinearLayout android:id="@+id/fields"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                style="@style/wifi_item"
-                android:orientation="vertical"
+                style="@style/wifi_section"
                 android:visibility="gone">
 
-            <TextView
+            <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    style="@style/wifi_item_label"
-                    android:layout_marginTop="8dip"
-                    android:text="@string/wifi_password" />
+                    style="@style/wifi_item">
+                <TextView
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_label"
+                        android:layout_marginTop="8dip"
+                        android:text="@string/wifi_password" />
 
-            <EditText android:id="@+id/password"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    style="@style/wifi_item_edit_content"
-                    android:singleLine="true"
-                    android:password="true"
-                    android:maxLength="63"
-                    android:imeOptions="flagForceAscii" />
+                <EditText android:id="@+id/password"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_edit_content"
+                        android:singleLine="true"
+                        android:password="true"
+                        android:maxLength="63"
+                        android:imeOptions="flagForceAscii" />
+            </LinearLayout>
 
-            <TextView android:id="@+id/hint"
+            <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    style="@style/wifi_item_label"
-                    android:text="@string/credentials_password_too_short"
-                    android:layout_marginTop="8dip"
-                    android:layout_marginBottom="10sp"/>
+                    style="@style/wifi_item">
+                <TextView android:id="@+id/hint"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_label"
+                        android:text="@string/credentials_password_too_short"
+                        android:layout_marginTop="8dip"
+                        android:layout_marginBottom="10sp"/>
 
-            <CheckBox android:id="@+id/show_password"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    style="@style/wifi_item_content"
-                    android:text="@string/wifi_show_password" />
+                <CheckBox android:id="@+id/show_password"
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        style="@style/wifi_item_content"
+                        android:text="@string/wifi_show_password" />
+            </LinearLayout>
         </LinearLayout>
 
         <LinearLayout android:id="@+id/fields"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                style="@style/wifi_item"
-                android:orientation="vertical">
+                style="@style/wifi_section" >
 
+            <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    style="@style/wifi_item">
                 <TextView
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
@@ -125,6 +145,7 @@
                     android:layout_height="wrap_content"
                     style="@style/wifi_item_content"
                     android:prompt="@string/wifi_ap_band_config" />
+            </LinearLayout>
         </LinearLayout>
 
     </LinearLayout>
diff --git a/src/com/android/settings/ConfirmLockPattern.java b/src/com/android/settings/ConfirmLockPattern.java
index a7d0e4e..f53e7df 100644
--- a/src/com/android/settings/ConfirmLockPattern.java
+++ b/src/com/android/settings/ConfirmLockPattern.java
@@ -208,7 +208,7 @@
                     mLockPatternView.clearPattern();
                     break;
                 case NeedToUnlockWrong:
-                    mErrorTextView.setText(R.string.lockpattern_need_to_unlock_wrong);
+                    showError(R.string.lockpattern_need_to_unlock_wrong);
 
                     mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
                     mLockPatternView.setEnabled(true);
@@ -372,7 +372,6 @@
             }
         };
 
-
         private void handleAttemptLockout(long elapsedRealtimeDeadline) {
             updateStage(Stage.LockedOut);
             long elapsedRealtime = SystemClock.elapsedRealtime();
@@ -383,7 +382,7 @@
                 @Override
                 public void onTick(long millisUntilFinished) {
                     final int secondsCountdown = (int) (millisUntilFinished / 1000);
-                    mErrorTextView.setText(getString(
+                    showError(getString(
                             R.string.lockpattern_too_many_failed_confirmation_attempts,
                             secondsCountdown));
                 }
@@ -395,5 +394,14 @@
                 }
             }.start();
         }
+
+        private void showError(CharSequence msg) {
+            mErrorTextView.setText(msg);
+            mErrorTextView.announceForAccessibility(mErrorTextView.getText());
+        }
+
+        private void showError(int msgid) {
+            showError(getText(msgid));
+        }
     }
 }
diff --git a/src/com/android/settings/MasterClearConfirm.java b/src/com/android/settings/MasterClearConfirm.java
index bc3656a..31f1bcc 100644
--- a/src/com/android/settings/MasterClearConfirm.java
+++ b/src/com/android/settings/MasterClearConfirm.java
@@ -65,14 +65,10 @@
 
             if (pdbManager != null && !pdbManager.getOemUnlockEnabled()) {
                 // if OEM unlock is enabled, this will be wiped during FR process.
-                final ProgressDialog progressDialog = getProgressDialog();
-                progressDialog.show();
-
-                // need to prevent orientation changes as we're about to go into
-                // a long IO request, so we won't be able to access inflate resources on flash
-                final int oldOrientation = getActivity().getRequestedOrientation();
-                getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
                 new AsyncTask<Void, Void, Void>() {
+                    int mOldOrientation;
+                    ProgressDialog mProgressDialog;
+
                     @Override
                     protected Void doInBackground(Void... params) {
                         pdbManager.wipe();
@@ -81,10 +77,21 @@
 
                     @Override
                     protected void onPostExecute(Void aVoid) {
-                        progressDialog.hide();
-                        getActivity().setRequestedOrientation(oldOrientation);
+                        mProgressDialog.hide();
+                        getActivity().setRequestedOrientation(mOldOrientation);
                         doMasterClear();
                     }
+
+                    @Override
+                    protected void onPreExecute() {
+                        mProgressDialog = getProgressDialog();
+                        mProgressDialog.show();
+
+                        // need to prevent orientation changes as we're about to go into
+                        // a long IO request, so we won't be able to access inflate resources on flash
+                        mOldOrientation = getActivity().getRequestedOrientation();
+                        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
+                    }
                 }.execute();
             } else {
                 doMasterClear();
@@ -143,7 +150,8 @@
         super.onCreate(savedInstanceState);
 
         Bundle args = getArguments();
-        mEraseSdCard = args != null && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
+        mEraseSdCard = args != null
+                && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
     }
 
     @Override
diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
index 372f9a5..074e0bd 100644
--- a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
@@ -117,6 +117,13 @@
                             context, deviceAddress)) {
                 context.startActivity(connectionAccessIntent);
             } else {
+                // Acquire wakelock so that LCD comes up since screen is off
+                PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK |
+                    PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
+                        "ConnectionAccessActivity");
+                wakeLock.setReferenceCounted(false);
+                wakeLock.acquire();
+
                 // Put up a notification that leads to the dialog
 
                 // Create an intent triggered by clicking on the
@@ -173,6 +180,7 @@
 
                 notificationManager.notify(getNotificationTag(mRequestType), NOTIFICATION_ID,
                         notification);
+                wakeLock.release();
             }
         } else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL)) {
             // Remove the notification
diff --git a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
index 7161929..59d6792 100755
--- a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
+++ b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
@@ -39,6 +39,7 @@
 import com.android.settingslib.bluetooth.LocalBluetoothProfile;
 import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
 import com.android.settingslib.bluetooth.MapProfile;
+import com.android.settingslib.bluetooth.PanProfile;
 import com.android.settingslib.bluetooth.PbapServerProfile;
 
 import java.util.HashMap;
@@ -244,8 +245,12 @@
             }
             if (profile.isPreferred(device)) {
                 // profile is preferred but not connected: disable auto-connect
-                profile.setPreferred(device, false);
-                refreshProfilePreference(profilePref, profile);
+                if (profile instanceof PanProfile) {
+                    mCachedDevice.connectProfile(profile);
+                } else {
+                    profile.setPreferred(device, false);
+                    refreshProfilePreference(profilePref, profile);
+                }
             } else {
                 profile.setPreferred(device, true);
                 mCachedDevice.connectProfile(profile);
@@ -330,10 +335,15 @@
         if (profile instanceof MapProfile) {
             profilePref.setChecked(mCachedDevice.getMessagePermissionChoice()
                     == CachedBluetoothDevice.ACCESS_ALLOWED);
+
         } else if (profile instanceof PbapServerProfile) {
-            // Handle PBAP specially.
             profilePref.setChecked(mCachedDevice.getPhonebookPermissionChoice()
                     == CachedBluetoothDevice.ACCESS_ALLOWED);
+
+        } else if (profile instanceof PanProfile) {
+            profilePref.setChecked(profile.getConnectionStatus(device) ==
+                    BluetoothProfile.STATE_CONNECTED);
+
         } else {
             profilePref.setChecked(profile.isPreferred(device));
         }
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index a82585d..a7d3b33 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -234,6 +234,7 @@
         // Mark out connections with a subtitle
         try {
             // Legacy VPNs
+            mConnectedLegacyVpn = null;
             LegacyVpnInfo info = mConnectivityService.getLegacyVpnInfo();
             if (info != null) {
                 ConfigPreference preference = mConfigPreferences.get(info.key);