am c25f8955: Link to bluetooth settings.

Merge commit 'c25f8955bee14a26520457fca2ab79c013f6196e'

* commit 'c25f8955bee14a26520457fca2ab79c013f6196e':
  Link to bluetooth settings.
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1500d8b..d5eec4a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -424,7 +424,7 @@
         <activity android:name=".bluetooth.ConnectSpecificProfilesActivity"
                   android:label="@string/bluetooth_connect_specific_profiles_title" />
 
-        <activity android:name=".bluetooth.BluetoothPinDialog"
+        <activity android:name=".bluetooth.BluetoothPairingDialog"
                   android:label="@string/bluetooth_pin_entry"
                   android:theme="@*android:style/Theme.Dialog.Alert">
             <intent-filter>
@@ -433,7 +433,7 @@
             </intent-filter>
         </activity>
 
-        <receiver android:name=".bluetooth.BluetoothPinRequest">
+        <receiver android:name=".bluetooth.BluetoothPairingRequest">
             <intent-filter>
                 <action android:name="android.bluetooth.intent.action.PAIRING_REQUEST" />
                 <action android:name="android.bluetooth.intent.action.PAIRING_CANCEL" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f63a0a6..4abbf2a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -508,15 +508,20 @@
     <string name="bluetooth_pin_entry">Bluetooth pairing request</string>
     <!-- Title for the bluetooth device info screen. -->
     <string name="bluetooth_device_info">Bluetooth device info</string>
-    <!-- Message when bluetooth dialog for pin entry is shwoing -->
+    <!-- Message when bluetooth dialog for pin entry is showing -->
     <string name="bluetooth_enter_pin_msg"><xliff:g id="device_name">%1$s</xliff:g>\n\nType PIN to pair.\n(Try 0000 or 1234.)</string>
+    <!-- Message when bluetooth dialog for passkey entry is showing -->
+    <string name="bluetooth_enter_passkey_msg"><xliff:g id="device_name">%1$s</xliff:g>\n\nType passkey to pair.\n</string>
+    <!-- Message when bluetooth dialog for confirmation of passkey is showing -->
+    <string name="bluetooth_confirm_passkey_msg">\n Passkey: <xliff:g id="passkey">%2$d</xliff:g>\n\nIs the same passkey displayed on: <xliff:g id="device_name">%1$s</xliff:g> ?\n</string>
 
     <!-- Title for BT error dialogs. -->
     <string name="bluetooth_error_title">Attention</string>
     <!-- Message for the error dialog when BT pairing fails generically. -->
     <string name="bluetooth_pairing_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g>.</string> 
-    <!-- Message for the error dialog when BT pairing fails because the PIN entered is incorrect. -->
-    <string name="bluetooth_pairing_pin_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g> because the typed PIN is incorrect.</string> 
+    <!-- Message for the error dialog when BT pairing fails because the PIN /
+    Passkey entered is incorrect. -->
+    <string name="bluetooth_pairing_pin_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g> because the typed PIN or Passkey is incorrect.</string>
     <!-- Message for the error dialog when BT pairing fails because the other device is down. -->
     <string name="bluetooth_pairing_device_down_error_message">Cannot establish communication with <xliff:g id="device_name">%1$s</xliff:g>.</string>
     <!-- Message for the error dialog when BT pairing fails because the other device rejected the pairing. -->
@@ -1142,6 +1147,12 @@
     <string name="location_street_level">When locating, accurate to street level (deselect to conserve battery)</string>
     <!-- Security & location settings screen, setting summary when Enable GPS satellites check box is clear -->
     <string name="location_gps_disabled">Locate to street-level (requires more battery plus view of sky)</string>
+    <!-- Security & location settings screen, setting check box label if Assisted GPS should be enabled -->
+    <string name="assisted_gps">Enable assisted GPS</string>
+    <!-- Security & location settings screen, setting summary when Assisted GPS check box is selected -->
+    <string name="assisted_gps_enabled">Use server to assist GPS (deselect to reduce network usage)</string>
+    <!-- Security & location settings screen, setting summary when Assisted GPS check box is clear -->
+    <string name="assisted_gps_disabled">Use server to assist GPS (select to improve GPS performance)</string>
     <!-- Setting title for allow sending location to google -->
     <string name="use_location_title">Share with Google</string>
     <!-- Title of dialog to user requesting use of location information to improve services -->
@@ -1372,7 +1383,7 @@
     <string name="computing_size">Computing\u2026</string>
     <string name="invalid_size_value">Unable to compute package size</string>
     <!-- String displayed when list is empty -->
-    <string name="empty_list_msg">You do not have any third-party apps installed.</string>
+    <string name="empty_list_msg">You do not have any third-party applications installed.</string>
     <!-- Manage applications, version string displayed in app snippet -->
     <string name="version_text">version <xliff:g id="version_num">%1$s</xliff:g></string>
 
@@ -1811,6 +1822,8 @@
 
     <!-- Power Control Widget -->
     <string name="gadget_title">Power Control</string>
+    <string name="gadget_toggle_wifi">Updating Wi-Fi setting</string>
+    <string name="gadget_toggle_bluetooth">Updating Bluetooth setting</string>
 
     <string name="vpn_settings_activity_title">VPN settings</string>
 
diff --git a/res/xml/security_settings.xml b/res/xml/security_settings.xml
index 8dd9d89..5b90dba 100644
--- a/res/xml/security_settings.xml
+++ b/res/xml/security_settings.xml
@@ -33,6 +33,12 @@
             android:summaryOff="@string/location_gps_disabled"/>
 
         <CheckBoxPreference
+            android:key="assisted_gps"
+            android:title="@string/assisted_gps"
+            android:summaryOn="@string/assisted_gps_enabled"
+            android:summaryOff="@string/assisted_gps_disabled"/>
+
+        <CheckBoxPreference
             android:key="use_location"
             android:title="@string/use_location_title"
             android:persistent="false"
diff --git a/src/com/android/settings/ApnPreference.java b/src/com/android/settings/ApnPreference.java
index 74fb902..710eda2 100644
--- a/src/com/android/settings/ApnPreference.java
+++ b/src/com/android/settings/ApnPreference.java
@@ -107,7 +107,7 @@
         return getKey().equals(mSelectedKey);
     }
 
-    public void setChecked(boolean checked) {
+    public void setChecked() {
         mSelectedKey = getKey();
     }
 
diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java
index 2624990..00ef3a7 100644
--- a/src/com/android/settings/ApnSettings.java
+++ b/src/com/android/settings/ApnSettings.java
@@ -178,7 +178,7 @@
             pref.setSelectable(selectable);
             if (selectable) {
                 if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
-                    pref.setChecked(true);
+                    pref.setChecked();
                 }
                 apnList.addPreference(pref);
             } else {
diff --git a/src/com/android/settings/BandMode.java b/src/com/android/settings/BandMode.java
index 1297cad..a8c7833 100644
--- a/src/com/android/settings/BandMode.java
+++ b/src/com/android/settings/BandMode.java
@@ -97,7 +97,7 @@
                 }
             };
 
-    private class BandListItem {
+    static private class BandListItem {
         private int mBandMode = Phone.BM_UNSPECIFIED;
 
         public BandListItem(int bm) {
diff --git a/src/com/android/settings/BatteryInfo.java b/src/com/android/settings/BatteryInfo.java
index eb7ddb4..4c25570 100644
--- a/src/com/android/settings/BatteryInfo.java
+++ b/src/com/android/settings/BatteryInfo.java
@@ -67,7 +67,7 @@
      */
     private final String tenthsToFixedString(int x) {
         int tens = x / 10;
-        return new String("" + tens + "." + (x - 10*tens));
+        return Integer.toString(tens) + "." + (x - 10 * tens);
     }
 
    /**
diff --git a/src/com/android/settings/LanguageSettings.java b/src/com/android/settings/LanguageSettings.java
index cbab390..4b805ed 100644
--- a/src/com/android/settings/LanguageSettings.java
+++ b/src/com/android/settings/LanguageSettings.java
@@ -54,8 +54,6 @@
     private String mLastInputMethodId;
     private String mLastTickedInputMethodId;
     
-    private String mRootDirectory;
-
     static public String getInputMethodIdFromKey(String key) {
         return key;
     }
diff --git a/src/com/android/settings/ManageApplications.java b/src/com/android/settings/ManageApplications.java
index 642a48e..b1743e9 100644
--- a/src/com/android/settings/ManageApplications.java
+++ b/src/com/android/settings/ManageApplications.java
@@ -755,7 +755,7 @@
     
     // internal structure used to track added and deleted packages when
     // the activity has focus
-    class AddRemoveInfo {
+    static class AddRemoveInfo {
         String pkgName;
         boolean add;
         public AddRemoveInfo(String pPkgName, boolean pAdd) {
diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java
index 257122b..27d8c7e 100644
--- a/src/com/android/settings/RadioInfo.java
+++ b/src/com/android/settings/RadioInfo.java
@@ -256,21 +256,21 @@
         }
     };
 
-    private class OemCommands {
+    static private class OemCommands {
 
-        public  final int OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE = 32;
-        public  final int OEM_QXDM_SDLOG_DEFAULT_MASK = 0;
-        public  final int OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX = 8;
+        public static final int OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE = 32;
+        public static final int OEM_QXDM_SDLOG_DEFAULT_MASK = 0;
+        public static final int OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX = 8;
 
-        final int SIZE_OF_INT = 4;
-        final int OEM_FEATURE_ENABLE = 1;
-        final int OEM_FEATURE_DISABLE = 0;
-        final int OEM_SIMPE_FEAUTURE_LEN = 1;
+        static final int SIZE_OF_INT = 4;
+        static final int OEM_FEATURE_ENABLE = 1;
+        static final int OEM_FEATURE_DISABLE = 0;
+        static final int OEM_SIMPE_FEAUTURE_LEN = 1;
 
-        final int OEM_QXDM_SDLOG_FUNCTAG = 0x00010000;
-        final int OEM_QXDM_SDLOG_LEN = 4;
-        final int OEM_PS_AUTO_ATTACH_FUNCTAG = 0x00020000;
-        final int OEM_CIPHERING_FUNCTAG = 0x00020001;
+        static final int OEM_QXDM_SDLOG_FUNCTAG = 0x00010000;
+        static final int OEM_QXDM_SDLOG_LEN = 4;
+        static final int OEM_PS_AUTO_ATTACH_FUNCTAG = 0x00020000;
+        static final int OEM_CIPHERING_FUNCTAG = 0x00020001;
         
         /**
          * The OEM interface to store QXDM to SD.
@@ -958,8 +958,7 @@
     private void displayQxdmEnableResult() {
         String status = mQxdmLogEnabled ? "Start QXDM Log" : "Stop QXDM Log";
 
-        DialogInterface mProgressPanel = new AlertDialog.
-                Builder(this).setMessage(status).show();
+        new AlertDialog.Builder(this).setMessage(status).show();
 
         mHandler.postDelayed(
                 new Runnable() {
diff --git a/src/com/android/settings/SdCardSettings.java b/src/com/android/settings/SdCardSettings.java
index 637babe..67f3550 100644
--- a/src/com/android/settings/SdCardSettings.java
+++ b/src/com/android/settings/SdCardSettings.java
@@ -108,48 +108,41 @@
         } catch (RemoteException ex) {
         }
 
-        String scanVolume = null; // this no longer exists: SystemProperties.get(MediaScanner.CURRENT_VOLUME_PROPERTY, "");
-        boolean scanning = "external".equals(scanVolume);
+        String status = Environment.getExternalStorageState();
+        boolean readOnly = false;
 
-        if (scanning) {
-            setLayout(mScanningLayout);
-        } else {
-            String status = Environment.getExternalStorageState();
-            boolean readOnly = false;
+        if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
+            status = Environment.MEDIA_MOUNTED;
+            readOnly = true;
+        }
 
-            if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
-                status = Environment.MEDIA_MOUNTED;
-                readOnly = true;
+        if (status.equals(Environment.MEDIA_MOUNTED)) {
+            try {
+                File path = Environment.getExternalStorageDirectory();
+                StatFs stat = new StatFs(path.getPath());
+                long blockSize = stat.getBlockSize();
+                long totalBlocks = stat.getBlockCount();
+                long availableBlocks = stat.getAvailableBlocks();
+
+                mTotalSize.setText(formatSize(totalBlocks * blockSize));
+                mUsedSize.setText(formatSize((totalBlocks - availableBlocks) * blockSize));
+                mAvailableSize.setText(formatSize(availableBlocks * blockSize));
+            } catch (IllegalArgumentException e) {
+                // this can occur if the SD card is removed, but we haven't received the
+                // ACTION_MEDIA_REMOVED Intent yet.
+                status = Environment.MEDIA_REMOVED;
             }
 
-            if (status.equals(Environment.MEDIA_MOUNTED)) {
-                try {
-                    File path = Environment.getExternalStorageDirectory();
-                    StatFs stat = new StatFs(path.getPath());
-                    long blockSize = stat.getBlockSize();
-                    long totalBlocks = stat.getBlockCount();
-                    long availableBlocks = stat.getAvailableBlocks();
-
-                    mTotalSize.setText(formatSize(totalBlocks * blockSize));
-                    mUsedSize.setText(formatSize((totalBlocks - availableBlocks) * blockSize));
-                    mAvailableSize.setText(formatSize(availableBlocks * blockSize));
-                } catch (IllegalArgumentException e) {
-                    // this can occur if the SD card is removed, but we haven't received the
-                    // ACTION_MEDIA_REMOVED Intent yet.
-                    status = Environment.MEDIA_REMOVED;
-                }
-
-                mReadOnlyStatus.setVisibility(readOnly ? View.VISIBLE : View.GONE);
-                setLayout(mMountedLayout);
-            } else if (status.equals(Environment.MEDIA_UNMOUNTED)) {
-                setLayout(mUnmountedLayout);
-            } else if (status.equals(Environment.MEDIA_REMOVED)) {
-                setLayout(mRemovedLayout);
-            } else if (status.equals(Environment.MEDIA_SHARED)) {
-                setLayout(mSharedLayout);
-            } else if (status.equals(Environment.MEDIA_BAD_REMOVAL)) {
-                setLayout(mBadRemovalLayout);
-            }
+            mReadOnlyStatus.setVisibility(readOnly ? View.VISIBLE : View.GONE);
+            setLayout(mMountedLayout);
+        } else if (status.equals(Environment.MEDIA_UNMOUNTED)) {
+            setLayout(mUnmountedLayout);
+        } else if (status.equals(Environment.MEDIA_REMOVED)) {
+            setLayout(mRemovedLayout);
+        } else if (status.equals(Environment.MEDIA_SHARED)) {
+            setLayout(mSharedLayout);
+        } else if (status.equals(Environment.MEDIA_BAD_REMOVAL)) {
+            setLayout(mBadRemovalLayout);
         }
     }
 
@@ -191,8 +184,6 @@
         }
     };
 
-
-    private int         mStatus;
     private IMountService   mMountService;
 
     private CheckBox    mMassStorage;
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 5a5804e..9e5629d 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -80,6 +80,7 @@
     private static final String LOCATION_CATEGORY = "location_category";
     private static final String LOCATION_NETWORK = "location_network";
     private static final String LOCATION_GPS = "location_gps";
+    private static final String ASSISTED_GPS = "assisted_gps";
 
     // Credential storage
     public static final String ACTION_ADD_CREDENTIAL =
@@ -110,6 +111,7 @@
 
     private CheckBoxPreference mNetwork;
     private CheckBoxPreference mGps;
+    private CheckBoxPreference mAssistedGps;
 
     // These provide support for receiving notification when Location Manager settings change.
     // This is necessary because the Network Location Provider can change settings
@@ -132,6 +134,7 @@
 
         mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK);
         mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS);
+        mAssistedGps = (CheckBoxPreference) getPreferenceScreen().findPreference(ASSISTED_GPS);
         mUseLocation = (CheckBoxPreference) getPreferenceScreen().findPreference(USE_LOCATION);
 
         // Vendor specific
@@ -298,8 +301,13 @@
             Settings.Secure.setLocationProviderEnabled(getContentResolver(),
                     LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
         } else if (preference == mGps) {
+            boolean enabled = mGps.isChecked();
             Settings.Secure.setLocationProviderEnabled(getContentResolver(),
-                    LocationManager.GPS_PROVIDER, mGps.isChecked());
+                    LocationManager.GPS_PROVIDER, enabled);
+            mAssistedGps.setEnabled(enabled);
+        } else if (preference == mAssistedGps) {
+            Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSISTED_GPS_ENABLED,
+                    mAssistedGps.isChecked() ? 1 : 0);
         } else if (preference == mUseLocation) {
             //normally called on the toggle click
             if (mUseLocation.isChecked()) {
@@ -341,10 +349,14 @@
      */
     private void updateToggles() {
         ContentResolver res = getContentResolver();
+        boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(
+                res, LocationManager.GPS_PROVIDER);
         mNetwork.setChecked(Settings.Secure.isLocationProviderEnabled(
                 res, LocationManager.NETWORK_PROVIDER));
-        mGps.setChecked(Settings.Secure.isLocationProviderEnabled(
-                res, LocationManager.GPS_PROVIDER));
+        mGps.setChecked(gpsEnabled);
+        mAssistedGps.setChecked(Settings.Secure.getInt(res,
+                Settings.Secure.ASSISTED_GPS_ENABLED, 2) == 1);
+        mAssistedGps.setEnabled(gpsEnabled);
         mUseLocation.setChecked(Settings.Secure.getInt(res,
                 Settings.Secure.USE_LOCATION_FOR_SERVICES, 2) == 1);
     }
diff --git a/src/com/android/settings/UsageStats.java b/src/com/android/settings/UsageStats.java
index 89caa54..fcb6990 100755
--- a/src/com/android/settings/UsageStats.java
+++ b/src/com/android/settings/UsageStats.java
@@ -187,7 +187,7 @@
                 holder.launchCount.setText(String.valueOf(pkgStats.launchCount));
                 holder.usageTime.setText(String.valueOf(pkgStats.usageTime)+" ms");
             } else {
-                Log.w(TAG, "No usage stats info for package:"+pkgStats.packageName);
+                Log.w(TAG, "No usage stats info for package:" + position);
             }
             return convertView;
         }
diff --git a/src/com/android/settings/ZoneList.java b/src/com/android/settings/ZoneList.java
index 2877f00..aaaf989 100644
--- a/src/com/android/settings/ZoneList.java
+++ b/src/com/android/settings/ZoneList.java
@@ -160,7 +160,7 @@
         try {
             XmlResourceParser xrp = getResources().getXml(R.xml.timezones);
             while (xrp.next() != XmlResourceParser.START_TAG)
-                ;
+                continue;
             xrp.next();
             while (xrp.getEventType() != XmlResourceParser.END_TAG) {
                 while (xrp.getEventType() != XmlResourceParser.START_TAG) {
diff --git a/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java b/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java
index 58fb569..665fba4 100644
--- a/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java
@@ -38,20 +38,20 @@
  */
 public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChangeListener {
     private static final String TAG = "BluetoothDiscoverableEnabler";
-    
+
     private static final String SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT =
             "debug.bt.discoverable_time";
-    private static final int DISCOVERABLE_TIMEOUT = 120; 
+    private static final int DISCOVERABLE_TIMEOUT = 120;
 
     private static final String SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP =
             "discoverable_end_timestamp";
-    
+
     private final Context mContext;
     private final Handler mUiHandler;
     private final CheckBoxPreference mCheckBoxPreference;
-    
+
     private final LocalBluetoothManager mLocalManager;
-    
+
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -66,17 +66,17 @@
 
     private final Runnable mUpdateCountdownSummaryRunnable = new Runnable() {
         public void run() {
-            updateCountdownSummary();        
-        } 
+            updateCountdownSummary();
+        }
     };
 
     public BluetoothDiscoverableEnabler(Context context, CheckBoxPreference checkBoxPreference) {
         mContext = context;
         mUiHandler = new Handler();
         mCheckBoxPreference = checkBoxPreference;
-        
+
         checkBoxPreference.setPersistent(false);
-        
+
         mLocalManager = LocalBluetoothManager.getInstance(context);
         if (mLocalManager == null) {
             // Bluetooth not supported
@@ -92,30 +92,30 @@
         IntentFilter filter = new IntentFilter(BluetoothIntent.SCAN_MODE_CHANGED_ACTION);
         mContext.registerReceiver(mReceiver, filter);
         mCheckBoxPreference.setOnPreferenceChangeListener(this);
-        
+
         handleModeChanged(mLocalManager.getBluetoothManager().getScanMode());
     }
-    
+
     public void pause() {
         if (mLocalManager == null) {
             return;
         }
-        
+
         mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
         mCheckBoxPreference.setOnPreferenceChangeListener(null);
         mContext.unregisterReceiver(mReceiver);
     }
-    
+
     public boolean onPreferenceChange(Preference preference, Object value) {
         // Turn on/off BT discoverability
         setEnabled((Boolean) value);
-        
+
         return true;
     }
-    
+
     private void setEnabled(final boolean enable) {
         BluetoothDevice manager = mLocalManager.getBluetoothManager();
-        
+
         if (enable) {
 
             int timeout = getDiscoverableTimeout();
@@ -126,7 +126,7 @@
 
             long endTimestamp = System.currentTimeMillis() + timeout * 1000;
             persistDiscoverableEndTimestamp(endTimestamp);
-            
+
             manager.setScanMode(BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
         } else {
             manager.setScanMode(BluetoothDevice.SCAN_MODE_CONNECTABLE);
@@ -138,7 +138,7 @@
         if (timeout <= 0) {
             timeout = DISCOVERABLE_TIMEOUT;
         }
-        
+
         return timeout;
     }
 
@@ -147,44 +147,44 @@
         editor.putLong(SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP, endTimestamp);
         editor.commit();
     }
-    
+
     private void handleModeChanged(int mode) {
         if (mode == BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
             mCheckBoxPreference.setChecked(true);
             updateCountdownSummary();
-            
+
         } else {
             mCheckBoxPreference.setChecked(false);
         }
     }
-    
+
     private void updateCountdownSummary() {
         int mode = mLocalManager.getBluetoothManager().getScanMode();
         if (mode != BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
             return;
         }
-            
+
         long currentTimestamp = System.currentTimeMillis();
         long endTimestamp = mLocalManager.getSharedPreferences().getLong(
                 SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP, 0);
-            
+
         if (currentTimestamp > endTimestamp) {
             // We're still in discoverable mode, but maybe there isn't a timeout.
             mCheckBoxPreference.setSummaryOn(null);
             return;
         }
-        
+
         String formattedTimeLeft = String.valueOf((endTimestamp - currentTimestamp) / 1000);
-        
+
         mCheckBoxPreference.setSummaryOn(
                 mContext.getResources().getString(R.string.bluetooth_is_discoverable,
                         formattedTimeLeft));
-        
+
         synchronized (this) {
             mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
             mUiHandler.postDelayed(mUpdateCountdownSummaryRunnable, 1000);
         }
     }
-    
-        
+
+
 }
diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
index af64c98..55b2b77 100644
--- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
+++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java
@@ -17,6 +17,7 @@
 package com.android.settings.bluetooth;
 
 import android.bluetooth.BluetoothA2dp;
+import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
 import android.bluetooth.BluetoothError;
 import android.bluetooth.BluetoothHeadset;
@@ -37,39 +38,41 @@
 public class BluetoothEventRedirector {
     private static final String TAG = "BluetoothEventRedirector";
     private static final boolean V = LocalBluetoothManager.V;
-    
+
     private LocalBluetoothManager mManager;
-    
+
     private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
             if (V) {
                 Log.v(TAG, "Received " + intent.getAction());
             }
-            
+
             String action = intent.getAction();
             String address = intent.getStringExtra(BluetoothIntent.ADDRESS);
-                
+
             if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
                 int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
                                         BluetoothError.ERROR);
                 mManager.setBluetoothStateInt(state);
             } else if (action.equals(BluetoothIntent.DISCOVERY_STARTED_ACTION)) {
                 mManager.onScanningStateChanged(true);
-                
+
             } else if (action.equals(BluetoothIntent.DISCOVERY_COMPLETED_ACTION)) {
                 mManager.onScanningStateChanged(false);
-                    
+
             } else if (action.equals(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION)) {
                 short rssi = intent.getShortExtra(BluetoothIntent.RSSI, Short.MIN_VALUE);
-                mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi);
-                
+                int btClass = intent.getIntExtra(BluetoothIntent.CLASS, BluetoothClass.ERROR);
+                String name = intent.getStringExtra(BluetoothIntent.NAME);
+                mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi, btClass, name);
+
             } else if (action.equals(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION)) {
                 mManager.getLocalDeviceManager().onDeviceDisappeared(address);
-                
+
             } else if (action.equals(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION)) {
                 mManager.getLocalDeviceManager().onDeviceNameUpdated(address);
-                
+
             } else if (action.equals(BluetoothIntent.BOND_STATE_CHANGED_ACTION)) {
                 int bondState = intent.getIntExtra(BluetoothIntent.BOND_STATE,
                                                    BluetoothError.ERROR);
@@ -82,7 +85,7 @@
                         mManager.getLocalDeviceManager().onBondingError(address, reason);
                     }
                 }
-                
+
             } else if (action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION)) {
                 int newState = intent.getIntExtra(BluetoothIntent.HEADSET_STATE, 0);
                 int oldState = intent.getIntExtra(BluetoothIntent.HEADSET_PREVIOUS_STATE, 0);
@@ -107,7 +110,7 @@
 
             } else if (action.equals(BluetoothIntent.REMOTE_DEVICE_CLASS_UPDATED_ACTION)) {
                 mManager.getLocalDeviceManager().onBtClassChanged(address);
-                
+
             }
         }
     };
@@ -118,29 +121,29 @@
 
     public void start() {
         IntentFilter filter = new IntentFilter();
-        
+
         // Bluetooth on/off broadcasts
         filter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
-        
+
         // Discovery broadcasts
         filter.addAction(BluetoothIntent.DISCOVERY_STARTED_ACTION);
         filter.addAction(BluetoothIntent.DISCOVERY_COMPLETED_ACTION);
         filter.addAction(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION);
         filter.addAction(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION);
         filter.addAction(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION);
-        
+
         // Pairing broadcasts
         filter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION);
-        
+
         // Fine-grained state broadcasts
         filter.addAction(BluetoothA2dp.SINK_STATE_CHANGED_ACTION);
         filter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION);
         filter.addAction(BluetoothIntent.REMOTE_DEVICE_CLASS_UPDATED_ACTION);
-        
+
         mManager.getContext().registerReceiver(mBroadcastReceiver, filter);
     }
-    
+
     public void stop() {
-        mManager.getContext().unregisterReceiver(mBroadcastReceiver);   
+        mManager.getContext().unregisterReceiver(mBroadcastReceiver);
     }
 }
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
new file mode 100644
index 0000000..bbe094f
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.bluetooth;
+
+import android.bluetooth.BluetoothClass;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.InputFilter;
+import android.text.InputType;
+import android.text.TextWatcher;
+import android.text.InputFilter.LengthFilter;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import com.android.internal.app.AlertActivity;
+import com.android.internal.app.AlertController;
+import com.android.settings.R;
+
+/**
+ * BluetoothPairingDialog asks the user to enter a PIN / Passkey / simple confirmation
+ * for pairing with a remote Bluetooth device. It is an activity that appears as a dialog.
+ */
+public class BluetoothPairingDialog extends AlertActivity implements DialogInterface.OnClickListener,
+        TextWatcher {
+    private static final String TAG = "BluetoothPairingDialog";
+
+    private final int BLUETOOTH_PIN_MAX_LENGTH = 16;
+    private final int BLUETOOTH_PASSKEY_MAX_LENGTH = 6;
+    private LocalBluetoothManager mLocalManager;
+    private String mAddress;
+    private int mType;
+    private int mConfirmationPasskey;
+    private EditText mPairingView;
+    private Button mOkButton;
+
+    private static final String INSTANCE_KEY_PAIRING_CANCELED = "received_pairing_canceled";
+    private boolean mReceivedPairingCanceled;
+
+    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (!BluetoothIntent.PAIRING_CANCEL_ACTION.equals(intent.getAction())) {
+                return;
+            }
+
+            String address = intent.getStringExtra(BluetoothIntent.ADDRESS);
+            if (address == null || address.equals(mAddress)) {
+                onReceivedPairingCanceled();
+            }
+        }
+    };
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        Intent intent = getIntent();
+        if (!intent.getAction().equals(BluetoothIntent.PAIRING_REQUEST_ACTION))
+        {
+            Log.e(TAG,
+                  "Error: this activity may be started only with intent " +
+                  BluetoothIntent.PAIRING_REQUEST_ACTION);
+            finish();
+        }
+
+        mLocalManager = LocalBluetoothManager.getInstance(this);
+        mAddress = intent.getStringExtra(BluetoothIntent.ADDRESS);
+        mType = intent.getIntExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothClass.ERROR);
+        if (mType == BluetoothDevice.PAIRING_VARIANT_PIN) {
+            createUserEntryDialog();
+        } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY) {
+            createUserEntryDialog();
+        } else if (mType == BluetoothDevice.PAIRING_VARIANT_CONFIRMATION){
+            mConfirmationPasskey =
+                intent.getIntExtra(BluetoothIntent.PASSKEY, BluetoothClass.ERROR);
+            if (mConfirmationPasskey == BluetoothClass.ERROR) {
+                Log.e(TAG, "Invalid ConfirmationPasskey received, not showing any dialog");
+                return;
+            }
+            createConfirmationDialog();
+        } else {
+            Log.e(TAG, "Incorrect pairing type received, not showing any dialog");
+        }
+
+        /*
+         * Leave this registered through pause/resume since we still want to
+         * finish the activity in the background if pairing is canceled.
+         */
+        registerReceiver(mReceiver, new IntentFilter(BluetoothIntent.PAIRING_CANCEL_ACTION));
+    }
+
+    private void createUserEntryDialog() {
+        final AlertController.AlertParams p = mAlertParams;
+        p.mIconId = android.R.drawable.ic_dialog_info;
+        p.mTitle = getString(R.string.bluetooth_pin_entry);
+        p.mView = createView();
+        p.mPositiveButtonText = getString(android.R.string.ok);
+        p.mPositiveButtonListener = this;
+        p.mNegativeButtonText = getString(android.R.string.cancel);
+        p.mNegativeButtonListener = this;
+        setupAlert();
+
+        mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
+        mOkButton.setEnabled(false);
+    }
+
+    private View createView() {
+        View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_entry, null);
+
+        String name = mLocalManager.getLocalDeviceManager().getName(mAddress);
+        TextView messageView = (TextView) view.findViewById(R.id.message);
+        mPairingView = (EditText) view.findViewById(R.id.text);
+        mPairingView.addTextChangedListener(this);
+
+        if (mType == BluetoothDevice.PAIRING_VARIANT_PIN) {
+            messageView.setText(getString(R.string.bluetooth_enter_pin_msg, name));
+            // Maximum of 16 characters in a PIN adb sync
+            mPairingView.setFilters(new InputFilter[] {
+                    new LengthFilter(BLUETOOTH_PIN_MAX_LENGTH) });
+        } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY){
+            messageView.setText(getString(R.string.bluetooth_enter_passkey_msg, name));
+            // Maximum of 6 digits for passkey
+            mPairingView.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED);
+            mPairingView.setFilters(new InputFilter[] {
+                    new LengthFilter(BLUETOOTH_PASSKEY_MAX_LENGTH)});
+        } else {
+            mPairingView.setVisibility(View.GONE);
+            messageView.setText(getString(R.string.bluetooth_confirm_passkey_msg, name,
+                    mConfirmationPasskey));
+        }
+        return view;
+    }
+
+    private void createConfirmationDialog() {
+        final AlertController.AlertParams p = mAlertParams;
+        p.mIconId = android.R.drawable.ic_dialog_info;
+        p.mTitle = getString(R.string.bluetooth_pin_entry);
+        p.mView = createView();
+        p.mPositiveButtonText = getString(android.R.string.yes);
+        p.mPositiveButtonListener = this;
+        p.mNegativeButtonText = getString(android.R.string.no);
+        p.mNegativeButtonListener = this;
+        setupAlert();
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+        super.onRestoreInstanceState(savedInstanceState);
+
+        mReceivedPairingCanceled = savedInstanceState.getBoolean(INSTANCE_KEY_PAIRING_CANCELED);
+        if (mReceivedPairingCanceled) {
+            onReceivedPairingCanceled();
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+
+        outState.putBoolean(INSTANCE_KEY_PAIRING_CANCELED, mReceivedPairingCanceled);
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+
+        unregisterReceiver(mReceiver);
+    }
+
+
+
+    public void afterTextChanged(Editable s) {
+        if (s.length() > 0) {
+            mOkButton.setEnabled(true);
+        }
+    }
+
+    private void onReceivedPairingCanceled() {
+        mReceivedPairingCanceled = true;
+
+        TextView messageView = (TextView) findViewById(R.id.message);
+        messageView.setText(getString(R.string.bluetooth_pairing_error_message,
+                mLocalManager.getLocalDeviceManager().getName(mAddress)));
+
+        mPairingView.setVisibility(View.GONE);
+        mPairingView.clearFocus();
+        mPairingView.removeTextChangedListener(this);
+
+        mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
+        mOkButton.setEnabled(true);
+        mAlert.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE);
+    }
+
+    private void onPair(String value) {
+        if (mType == BluetoothDevice.PAIRING_VARIANT_PIN) {
+            byte[] pinBytes = BluetoothDevice.convertPinToBytes(value);
+            if (pinBytes == null) {
+                return;
+            }
+            mLocalManager.getBluetoothManager().setPin(mAddress, pinBytes);
+        } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY) {
+            int passkey = Integer.getInteger(value);
+            mLocalManager.getBluetoothManager().setPasskey(mAddress, passkey);
+        } else {
+            mLocalManager.getBluetoothManager().setPairingConfirmation(mAddress, true);
+        }
+    }
+
+    private void onCancel() {
+        if (mType == BluetoothDevice.PAIRING_VARIANT_CONFIRMATION) {
+            mLocalManager.getBluetoothManager().setPairingConfirmation(mAddress, false);
+        } else {
+            mLocalManager.getBluetoothManager().cancelBondProcess(mAddress);
+        }
+    }
+
+    public void onClick(DialogInterface dialog, int which) {
+        switch (which) {
+            case DialogInterface.BUTTON_POSITIVE:
+                onPair(mPairingView.getText().toString());
+                break;
+
+            case DialogInterface.BUTTON_NEGATIVE:
+                onCancel();
+                break;
+        }
+    }
+
+    /* Not used */
+    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+    }
+
+    /* Not used */
+    public void onTextChanged(CharSequence s, int start, int before, int count) {
+    }
+
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothPinRequest.java b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
similarity index 69%
rename from src/com/android/settings/bluetooth/BluetoothPinRequest.java
rename to src/com/android/settings/bluetooth/BluetoothPairingRequest.java
index 619052d..d57628a 100644
--- a/src/com/android/settings/bluetooth/BluetoothPinRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
@@ -21,6 +21,7 @@
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
+import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
 import android.bluetooth.BluetoothIntent;
 import android.content.BroadcastReceiver;
@@ -30,35 +31,41 @@
 import android.text.TextUtils;
 
 /**
- * BluetoothPinRequest is a receiver for any Bluetooth pairing PIN request. It
- * checks if the Bluetooth Settings is currently visible and brings up the PIN
- * entry dialog. Otherwise it puts a Notification in the status bar, which can
- * be clicked to bring up the PIN entry dialog.
+ * BluetoothPairingRequest is a receiver for any Bluetooth pairing request. It
+ * checks if the Bluetooth Settings is currently visible and brings up the PIN, the passkey or a
+ * confirmation entry dialog. Otherwise it puts a Notification in the status bar, which can
+ * be clicked to bring up the Pairing entry dialog.
  */
-public class BluetoothPinRequest extends BroadcastReceiver {
+public class BluetoothPairingRequest extends BroadcastReceiver {
 
     public static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth;
-    
+
     @Override
     public void onReceive(Context context, Intent intent) {
         String action = intent.getAction();
         if (action.equals(BluetoothIntent.PAIRING_REQUEST_ACTION)) {
 
-            LocalBluetoothManager localManager = LocalBluetoothManager.getInstance(context);        
-        
+            LocalBluetoothManager localManager = LocalBluetoothManager.getInstance(context);
+
             String address = intent.getStringExtra(BluetoothIntent.ADDRESS);
-            Intent pinIntent = new Intent();
-            pinIntent.setClass(context, BluetoothPinDialog.class);
-            pinIntent.putExtra(BluetoothIntent.ADDRESS, address); 
-            pinIntent.setAction(BluetoothIntent.PAIRING_REQUEST_ACTION);
-            pinIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            
+            int type = intent.getIntExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothClass.ERROR);
+            Intent pairingIntent = new Intent();
+            pairingIntent.setClass(context, BluetoothPairingDialog.class);
+            pairingIntent.putExtra(BluetoothIntent.ADDRESS, address);
+            pairingIntent.putExtra(BluetoothIntent.PAIRING_VARIANT, type);
+            if (type == BluetoothDevice.PAIRING_VARIANT_CONFIRMATION) {
+                int passkey = intent.getIntExtra(BluetoothIntent.PASSKEY, BluetoothClass.ERROR);
+                pairingIntent.putExtra(BluetoothIntent.PASSKEY, passkey);
+            }
+            pairingIntent.setAction(BluetoothIntent.PAIRING_REQUEST_ACTION);
+            pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
             if (localManager.getForegroundActivity() != null) {
                 // Since the BT-related activity is in the foreground, just open the dialog
-                context.startActivity(pinIntent);
-                
+                context.startActivity(pairingIntent);
+
             } else {
-                
+
                 // Put up a notification that leads to the dialog
                 Resources res = context.getResources();
                 Notification notification = new Notification(
@@ -66,27 +73,27 @@
                         res.getString(R.string.bluetooth_notif_ticker),
                         System.currentTimeMillis());
 
-                PendingIntent pending = PendingIntent.getActivity(context, 0, 
-                        pinIntent, PendingIntent.FLAG_ONE_SHOT);
-                
+                PendingIntent pending = PendingIntent.getActivity(context, 0,
+                        pairingIntent, PendingIntent.FLAG_ONE_SHOT);
+
                 String name = intent.getStringExtra(BluetoothIntent.NAME);
                 if (TextUtils.isEmpty(name)) {
                     name = localManager.getLocalDeviceManager().getName(address);
                 }
-                
-                notification.setLatestEventInfo(context, 
-                        res.getString(R.string.bluetooth_notif_title), 
-                        res.getString(R.string.bluetooth_notif_message) + name, 
+
+                notification.setLatestEventInfo(context,
+                        res.getString(R.string.bluetooth_notif_title),
+                        res.getString(R.string.bluetooth_notif_message) + name,
                         pending);
                 notification.flags |= Notification.FLAG_AUTO_CANCEL;
-                
-                NotificationManager manager = (NotificationManager) 
+
+                NotificationManager manager = (NotificationManager)
                         context.getSystemService(Context.NOTIFICATION_SERVICE);
                 manager.notify(NOTIFICATION_ID, notification);
             }
-            
+
         } else if (action.equals(BluetoothIntent.PAIRING_CANCEL_ACTION)) {
-            
+
             // Remove the notification
             NotificationManager manager = (NotificationManager) context
                     .getSystemService(Context.NOTIFICATION_SERVICE);
diff --git a/src/com/android/settings/bluetooth/BluetoothPinDialog.java b/src/com/android/settings/bluetooth/BluetoothPinDialog.java
deleted file mode 100644
index 087fbb2..0000000
--- a/src/com/android/settings/bluetooth/BluetoothPinDialog.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.bluetooth;
-
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Bundle;
-import android.text.Editable;
-import android.text.InputFilter;
-import android.text.TextWatcher;
-import android.text.InputFilter.LengthFilter;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.TextView;
-
-import com.android.internal.app.AlertActivity;
-import com.android.internal.app.AlertController;
-import com.android.settings.R;
-
-/**
- * BluetoothPinDialog asks the user to enter a PIN for pairing with a remote
- * Bluetooth device. It is an activity that appears as a dialog.
- */
-public class BluetoothPinDialog extends AlertActivity implements DialogInterface.OnClickListener,
-        TextWatcher {
-    private static final String TAG = "BluetoothPinDialog";
-
-    private final int BLUETOOTH_PIN_MAX_LENGTH = 16;
-    private LocalBluetoothManager mLocalManager;
-    private String mAddress;
-    private EditText mPinView;
-    private Button mOkButton;
-
-    private static final String INSTANCE_KEY_PAIRING_CANCELED = "received_pairing_canceled";
-    private boolean mReceivedPairingCanceled;
-    
-    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (!BluetoothIntent.PAIRING_CANCEL_ACTION.equals(intent.getAction())) {
-                return;
-            }
-            
-            String address = intent.getStringExtra(BluetoothIntent.ADDRESS);
-            if (address == null || address.equals(mAddress)) {
-                onReceivedPairingCanceled();
-            }
-        }
-    };
-    
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        Intent intent = getIntent();
-        if (!intent.getAction().equals(BluetoothIntent.PAIRING_REQUEST_ACTION))
-        {
-            Log.e(TAG,
-                  "Error: this activity may be started only with intent " +
-                  BluetoothIntent.PAIRING_REQUEST_ACTION);
-            finish();
-        }
-        
-        mLocalManager = LocalBluetoothManager.getInstance(this);
-        mAddress = intent.getStringExtra(BluetoothIntent.ADDRESS);
-        
-        // Set up the "dialog"
-        final AlertController.AlertParams p = mAlertParams;
-        p.mIconId = android.R.drawable.ic_dialog_info;
-        p.mTitle = getString(R.string.bluetooth_pin_entry);
-        p.mView = createView();
-        p.mPositiveButtonText = getString(android.R.string.ok);
-        p.mPositiveButtonListener = this;
-        p.mNegativeButtonText = getString(android.R.string.cancel);
-        p.mNegativeButtonListener = this;
-        setupAlert();
-        
-        mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
-        mOkButton.setEnabled(false);
-
-        /*
-         * Leave this registered through pause/resume since we still want to
-         * finish the activity in the background if pairing is canceled.
-         */
-        registerReceiver(mReceiver, new IntentFilter(BluetoothIntent.PAIRING_CANCEL_ACTION));
-    }
-
-    @Override
-    protected void onRestoreInstanceState(Bundle savedInstanceState) {
-        super.onRestoreInstanceState(savedInstanceState);
-        
-        mReceivedPairingCanceled = savedInstanceState.getBoolean(INSTANCE_KEY_PAIRING_CANCELED);
-        if (mReceivedPairingCanceled) {
-            onReceivedPairingCanceled();
-        }
-    }
-
-    @Override
-    protected void onSaveInstanceState(Bundle outState) {
-        super.onSaveInstanceState(outState);
-        
-        outState.putBoolean(INSTANCE_KEY_PAIRING_CANCELED, mReceivedPairingCanceled);
-    }
-
-    @Override
-    protected void onDestroy() {
-        super.onDestroy();
-        
-        unregisterReceiver(mReceiver);
-    }
-
-    private View createView() {
-        View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_entry, null);
-        
-        String name = mLocalManager.getLocalDeviceManager().getName(mAddress);
-        TextView messageView = (TextView) view.findViewById(R.id.message);
-        messageView.setText(getString(R.string.bluetooth_enter_pin_msg, name));
-        
-        mPinView = (EditText) view.findViewById(R.id.text);
-        mPinView.addTextChangedListener(this);
-        // Maximum of 16 characters in a PIN
-        mPinView.setFilters(new InputFilter[] { new LengthFilter(BLUETOOTH_PIN_MAX_LENGTH) });
-        
-        return view;
-    }
-
-    public void afterTextChanged(Editable s) {
-        if (s.length() > 0) {
-            mOkButton.setEnabled(true);
-        }
-    }
-
-    private void onReceivedPairingCanceled() {
-        mReceivedPairingCanceled = true;
-        
-        TextView messageView = (TextView) findViewById(R.id.message);
-        messageView.setText(getString(R.string.bluetooth_pairing_error_message,
-                mLocalManager.getLocalDeviceManager().getName(mAddress)));
-        
-        mPinView.setVisibility(View.GONE);
-        mPinView.clearFocus();
-        mPinView.removeTextChangedListener(this);
-
-        mOkButton.setEnabled(true);
-        mAlert.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE);
-    }
-    
-    private void onPair(String pin) {
-        byte[] pinBytes = BluetoothDevice.convertPinToBytes(pin);
-        
-        if (pinBytes == null) {
-            return;
-        }
-        
-        mLocalManager.getBluetoothManager().setPin(mAddress, pinBytes);
-    }
-
-    private void onCancel() {
-        mLocalManager.getBluetoothManager().cancelBondProcess(mAddress);
-    }
-    
-    public void onClick(DialogInterface dialog, int which) {
-        switch (which) {
-            case DialogInterface.BUTTON_POSITIVE:
-                onPair(mPinView.getText().toString());
-                break;
-                
-            case DialogInterface.BUTTON_NEGATIVE:
-                onCancel();
-                break;
-        }
-    }
-
-    /* Not used */
-    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-    }
-
-    /* Not used */
-    public void onTextChanged(CharSequence s, int start, int before, int count) {
-    }
-
-}
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothDevice.java b/src/com/android/settings/bluetooth/LocalBluetoothDevice.java
index 5259d7b..862a9bd 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothDevice.java
@@ -82,7 +82,7 @@
         CONNECT, DISCONNECT,
     }
 
-    class BluetoothJob {
+    static class BluetoothJob {
         final BluetoothCommand command; // CONNECT, DISCONNECT
         final LocalBluetoothDevice device;
         final Profile profile; // HEADSET, A2DP, etc
@@ -96,7 +96,7 @@
             this.profile = profile;
             this.timeSent = 0;
         }
-        
+
         @Override
         public String toString() {
             StringBuilder sb = new StringBuilder();
@@ -147,7 +147,7 @@
             }
         }
     }
-    
+
     private boolean pruneQueue(BluetoothJob job) {
         boolean removedStaleItems = false;
         long now = System.currentTimeMillis();
@@ -186,7 +186,7 @@
     private boolean processCommand(BluetoothJob job) {
         boolean successful = false;
         if (job.timeSent == 0) {
-            job.timeSent = System.currentTimeMillis();                
+            job.timeSent = System.currentTimeMillis();
             switch (job.command) {
             case CONNECT:
                 successful = connectInt(job.device, job.profile);
@@ -349,7 +349,7 @@
             }
         };
 
-        AlertDialog ad = new AlertDialog.Builder(context)
+        new AlertDialog.Builder(context)
                 .setTitle(getName())
                 .setMessage(message)
                 .setPositiveButton(android.R.string.ok, disconnectListener)
@@ -363,7 +363,6 @@
         // Reset the only-show-one-error-dialog tracking variable
         mIsConnectingErrorPossible = true;
 
-        Context context = mLocalManager.getContext();
         boolean hasAtLeastOnePreferredProfile = false;
         for (Profile profile : mProfiles) {
             LocalBluetoothProfileManager profileManager =
@@ -385,7 +384,6 @@
         // Reset the only-show-one-error-dialog tracking variable
         mIsConnectingErrorPossible = true;
 
-        Context context = mLocalManager.getContext();
         for (Profile profile : mProfiles) {
             LocalBluetoothProfileManager profileManager =
                     LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
@@ -450,7 +448,7 @@
     public void unpair() {
         synchronized (workQueue) {
             // Remove any pending commands for this device
-            boolean processNow = false;            
+            boolean processNow = false;
             Iterator<BluetoothJob> it = workQueue.iterator();
             while (it.hasNext()) {
                 BluetoothJob job = it.next();
@@ -480,8 +478,6 @@
     }
 
     private void fillData() {
-        BluetoothDevice manager = mLocalManager.getBluetoothManager();
-
         fetchName();
         fetchBtClass();
 
@@ -498,6 +494,17 @@
         return mName;
     }
 
+    public void setName(String name) {
+        if (!mName.equals(name)) {
+            if (TextUtils.isEmpty(name)) {
+                mName = mAddress;
+            } else {
+                mName = name;
+            }
+            dispatchAttributesChanged();
+        }
+    }
+
     public void refreshName() {
         fetchName();
         dispatchAttributesChanged();
@@ -571,23 +578,19 @@
     }
 
     public int getBtClassDrawable() {
-
-        // First try looking at profiles
-        if (mProfiles.contains(Profile.A2DP)) {
-            return R.drawable.ic_bt_headphones_a2dp;
-        } else if (mProfiles.contains(Profile.HEADSET)) {
-            return R.drawable.ic_bt_headset_hfp;
-        }
-
-        // Fallback on class
         switch (BluetoothClass.Device.Major.getDeviceMajor(mBtClass)) {
         case BluetoothClass.Device.Major.COMPUTER:
             return R.drawable.ic_bt_laptop;
 
         case BluetoothClass.Device.Major.PHONE:
             return R.drawable.ic_bt_cellphone;
+        }
 
-        default:
+        if (mProfiles.contains(Profile.A2DP)) {
+            return R.drawable.ic_bt_headphones_a2dp;
+        } else if (mProfiles.contains(Profile.HEADSET)) {
+            return R.drawable.ic_bt_headset_hfp;
+        } else {
             return 0;
         }
     }
@@ -611,6 +614,14 @@
         dispatchAttributesChanged();
     }
 
+    public void setBtClass(int btClass) {
+        if (mBtClass != btClass && btClass != BluetoothClass.ERROR) {
+            mBtClass = btClass;
+            LocalBluetoothProfileManager.fill(mBtClass, mProfiles);
+            dispatchAttributesChanged();
+        }
+    }
+
     public int getSummary() {
         // TODO: clean up
         int oneOffSummary = getOneOffSummary();
@@ -726,7 +737,6 @@
                 break;
 
             case CONTEXT_ITEM_UNPAIR:
-                mLocalManager.getBluetoothManager().disconnectRemoteDeviceAcl(mAddress);
                 unpair();
                 break;
 
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java
index 2c70fd2..819d482 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java
@@ -34,7 +34,7 @@
 
     final LocalBluetoothManager mLocalManager;
     final List<Callback> mCallbacks;
-    
+
     final List<LocalBluetoothDevice> mDevices = new ArrayList<LocalBluetoothDevice>();
 
     public LocalBluetoothDeviceManager(LocalBluetoothManager localManager) {
@@ -47,7 +47,7 @@
         BluetoothDevice manager = mLocalManager.getBluetoothManager();
         String[] bondedAddresses = manager.listBonds();
         if (bondedAddresses == null) return false;
-        
+
         boolean deviceAdded = false;
         for (String address : bondedAddresses) {
             LocalBluetoothDevice device = findDevice(address);
@@ -58,55 +58,58 @@
                 deviceAdded = true;
             }
         }
-        
+
         return deviceAdded;
     }
-    
+
     public synchronized List<LocalBluetoothDevice> getDevicesCopy() {
         return new ArrayList<LocalBluetoothDevice>(mDevices);
     }
-    
+
     void onBluetoothStateChanged(boolean enabled) {
         if (enabled) {
             readPairedDevices();
         }
     }
 
-    public synchronized void onDeviceAppeared(String address, short rssi) {
+    public synchronized void onDeviceAppeared(String address, short rssi, int btClass,
+            String name) {
         boolean deviceAdded = false;
-        
+
         LocalBluetoothDevice device = findDevice(address);
         if (device == null) {
             device = new LocalBluetoothDevice(mLocalManager.getContext(), address);
             mDevices.add(device);
             deviceAdded = true;
         }
-        
+
         device.setRssi(rssi);
+        device.setBtClass(btClass);
+        device.setName(name);
         device.setVisible(true);
-        
+
         if (deviceAdded) {
             dispatchDeviceAdded(device);
         }
     }
-    
+
     public synchronized void onDeviceDisappeared(String address) {
         LocalBluetoothDevice device = findDevice(address);
         if (device == null) return;
-        
+
         device.setVisible(false);
         checkForDeviceRemoval(device);
     }
-    
+
     private void checkForDeviceRemoval(LocalBluetoothDevice device) {
         if (device.getBondState() == BluetoothDevice.BOND_NOT_BONDED &&
                 !device.isVisible()) {
             // If device isn't paired, remove it altogether
             mDevices.remove(device);
             dispatchDeviceDeleted(device);
-        }            
+        }
     }
-    
+
     public synchronized void onDeviceNameUpdated(String address) {
         LocalBluetoothDevice device = findDevice(address);
         if (device != null) {
@@ -115,21 +118,21 @@
     }
 
     public synchronized LocalBluetoothDevice findDevice(String address) {
-        
+
         for (int i = mDevices.size() - 1; i >= 0; i--) {
             LocalBluetoothDevice device = mDevices.get(i);
-            
+
             if (device.getAddress().equals(address)) {
                 return device;
             }
         }
-        
+
         return null;
     }
-    
+
     /**
      * Attempts to get the name of a remote device, otherwise returns the address.
-     * 
+     *
      * @param address The address.
      * @return The name, or if unavailable, the address.
      */
@@ -137,17 +140,17 @@
         LocalBluetoothDevice device = findDevice(address);
         return device != null ? device.getName() : address;
     }
-    
+
     private void dispatchDeviceAdded(LocalBluetoothDevice device) {
         synchronized (mCallbacks) {
             for (Callback callback : mCallbacks) {
                 callback.onDeviceAdded(device);
             }
         }
-        
+
         // TODO: divider between prev paired/connected and scanned
     }
-    
+
     private void dispatchDeviceDeleted(LocalBluetoothDevice device) {
         synchronized (mCallbacks) {
             for (Callback callback : mCallbacks) {
@@ -176,7 +179,7 @@
 
     /**
      * Called when there is a bonding error.
-     * 
+     *
      * @param address The address of the remote device.
      * @param reason The reason, one of the error reasons from
      *            BluetoothDevice.UNBOND_REASON_*
@@ -199,7 +202,7 @@
         }
         mLocalManager.showError(address, R.string.bluetooth_error_title, errorMsg);
     }
-    
+
     public synchronized void onProfileStateChanged(String address, Profile profile,
             int newProfileState) {
         LocalBluetoothDevice device = findDevice(address);
@@ -208,11 +211,11 @@
         device.onProfileStateChanged(profile, newProfileState);
         device.refresh();
     }
-    
+
     public synchronized void onConnectingError(String address) {
         LocalBluetoothDevice device = findDevice(address);
         if (device == null) return;
-        
+
         /*
          * Go through the device's delegate so we don't spam the user with
          * errors connecting to different profiles, and instead make sure the
@@ -220,10 +223,10 @@
          */
         device.showConnectingError();
     }
-    
+
     public synchronized void onScanningStateChanged(boolean started) {
         if (!started) return;
-        
+
         // If starting a new scan, clear old visibility
         for (int i = mDevices.size() - 1; i >= 0; i--) {
             LocalBluetoothDevice device = mDevices.get(i);
@@ -231,7 +234,7 @@
             checkForDeviceRemoval(device);
         }
     }
-    
+
     public synchronized void onBtClassChanged(String address) {
         LocalBluetoothDevice device = findDevice(address);
         if (device != null) {
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
index 2e84338..a6e9d50 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
@@ -42,15 +42,15 @@
 public class LocalBluetoothManager {
     private static final String TAG = "LocalBluetoothManager";
     static final boolean V = Config.LOGV;
-    static final boolean D = Config.LOGD && false;
-    
+    static final boolean D = Config.LOGD;
+
     private static final String SHARED_PREFERENCES_NAME = "bluetooth_settings";
-    
+
     private static LocalBluetoothManager INSTANCE;
     /** Used when obtaining a reference to the singleton instance. */
     private static Object INSTANCE_LOCK = new Object();
     private boolean mInitialized;
-    
+
     private Context mContext;
     /** If a BT-related activity is in the foreground, this will be it. */
     private Activity mForegroundActivity;
@@ -61,24 +61,24 @@
     private LocalBluetoothDeviceManager mLocalDeviceManager;
     private BluetoothEventRedirector mEventRedirector;
     private BluetoothA2dp mBluetoothA2dp;
-    
+
     private int mState = BluetoothError.ERROR;
 
     private List<Callback> mCallbacks = new ArrayList<Callback>();
-    
+
     private static final int SCAN_EXPIRATION_MS = 5 * 60 * 1000; // 5 mins
     private long mLastScan;
-    
+
     public static LocalBluetoothManager getInstance(Context context) {
         synchronized (INSTANCE_LOCK) {
             if (INSTANCE == null) {
                 INSTANCE = new LocalBluetoothManager();
             }
-            
+
             if (!INSTANCE.init(context)) {
                 return null;
             }
-            
+
             return INSTANCE;
         }
     }
@@ -86,15 +86,15 @@
     private boolean init(Context context) {
         if (mInitialized) return true;
         mInitialized = true;
-        
+
         // This will be around as long as this process is
         mContext = context.getApplicationContext();
-        
+
         mManager = (BluetoothDevice) context.getSystemService(Context.BLUETOOTH_SERVICE);
         if (mManager == null) {
             return false;
         }
-        
+
         mLocalDeviceManager = new LocalBluetoothDeviceManager(this);
 
         mEventRedirector = new BluetoothEventRedirector(this);
@@ -104,11 +104,11 @@
 
         return true;
     }
-    
+
     public BluetoothDevice getBluetoothManager() {
         return mManager;
     }
-    
+
     public Context getContext() {
         return mContext;
     }
@@ -116,7 +116,7 @@
     public Activity getForegroundActivity() {
         return mForegroundActivity;
     }
-    
+
     public void setForegroundActivity(Activity activity) {
         if (mErrorDialog != null) {
             mErrorDialog.dismiss();
@@ -124,31 +124,31 @@
         }
         mForegroundActivity = activity;
     }
-    
+
     public SharedPreferences getSharedPreferences() {
         return mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
     }
-    
+
     public LocalBluetoothDeviceManager getLocalDeviceManager() {
         return mLocalDeviceManager;
     }
-    
+
     List<Callback> getCallbacks() {
         return mCallbacks;
     }
-    
+
     public void registerCallback(Callback callback) {
         synchronized (mCallbacks) {
             mCallbacks.add(callback);
         }
     }
-    
+
     public void unregisterCallback(Callback callback) {
         synchronized (mCallbacks) {
             mCallbacks.remove(callback);
         }
     }
-    
+
     public void startScanning(boolean force) {
         if (mManager.isDiscovering()) {
             /*
@@ -156,7 +156,7 @@
              * Note: we only call the callbacks, not the same path as if the
              * scanning state had really changed (in that case the device
              * manager would clear its list of unpaired scanned devices).
-             */ 
+             */
             dispatchScanningStateChanged(true);
         } else {
             if (!force) {
@@ -176,22 +176,22 @@
                     }
                 }
             }
-            
-            if (mManager.startDiscovery(true)) {
+
+            if (mManager.startDiscovery()) {
                 mLastScan = System.currentTimeMillis();
             }
         }
     }
-    
+
     public int getBluetoothState() {
-        
+
         if (mState == BluetoothError.ERROR) {
             syncBluetoothState();
         }
-            
+
         return mState;
     }
-    
+
     void setBluetoothStateInt(int state) {
         mState = state;
         if (state == BluetoothDevice.BLUETOOTH_STATE_ON ||
@@ -199,7 +199,7 @@
             mLocalDeviceManager.onBluetoothStateChanged(state == BluetoothDevice.BLUETOOTH_STATE_ON);
         }
     }
-    
+
     private void syncBluetoothState() {
         int bluetoothState;
 
@@ -218,7 +218,7 @@
         boolean wasSetStateSuccessful = enabled
                 ? mManager.enable()
                 : mManager.disable();
-                
+
         if (wasSetStateSuccessful) {
             setBluetoothStateInt(enabled
                 ? BluetoothDevice.BLUETOOTH_STATE_TURNING_ON
@@ -229,11 +229,11 @@
                         "setBluetoothEnabled call, manager didn't return success for enabled: "
                                 + enabled);
             }
-            
+
             syncBluetoothState();
         }
     }
-    
+
     /**
      * @param started True if scanning started, false if scanning finished.
      */
@@ -242,7 +242,7 @@
         mLocalDeviceManager.onScanningStateChanged(started);
         dispatchScanningStateChanged(started);
     }
-    
+
     private void dispatchScanningStateChanged(boolean started) {
         synchronized (mCallbacks) {
             for (Callback callback : mCallbacks) {
@@ -267,7 +267,7 @@
                 .setPositiveButton(android.R.string.ok, null)
                 .show();
         } else {
-            // Fallback on a toast 
+            // Fallback on a toast
             Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
         }
     }
@@ -277,5 +277,5 @@
         void onDeviceAdded(LocalBluetoothDevice device);
         void onDeviceDeleted(LocalBluetoothDevice device);
     }
-    
+
 }
diff --git a/src/com/android/settings/deviceinfo/Status.java b/src/com/android/settings/deviceinfo/Status.java
index a165754..4b1cbbf 100644
--- a/src/com/android/settings/deviceinfo/Status.java
+++ b/src/com/android/settings/deviceinfo/Status.java
@@ -375,7 +375,6 @@
     void updateTimes() {
         long at = SystemClock.uptimeMillis() / 1000;
         long ut = SystemClock.elapsedRealtime() / 1000;
-        long st = ut - at;
 
         if (ut == 0) {
             ut = 1;
diff --git a/src/com/android/settings/quicklaunch/QuickLaunchSettings.java b/src/com/android/settings/quicklaunch/QuickLaunchSettings.java
index 40316b5..fb9fbcd 100644
--- a/src/com/android/settings/quicklaunch/QuickLaunchSettings.java
+++ b/src/com/android/settings/quicklaunch/QuickLaunchSettings.java
@@ -226,8 +226,7 @@
                 Log.w(TAG, "Result from bookmark picker does not have an intent.");
                 return;
             }
-            
-            String title = data.getStringExtra(BookmarkPicker.EXTRA_TITLE);
+
             char shortcut = data.getCharExtra(BookmarkPicker.EXTRA_SHORTCUT, (char) 0);
             updateShortcut(shortcut, data);
             
diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
index d8747c9..caffea2 100644
--- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java
+++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
@@ -36,6 +36,7 @@
 import android.provider.Settings;
 import android.util.Log;
 import android.widget.RemoteViews;
+import android.widget.Toast;
 import com.android.settings.R;
 import com.android.settings.bluetooth.LocalBluetoothManager;
 
@@ -175,7 +176,8 @@
                 views.setImageViewResource(R.id.btn_bluetooth, R.drawable.widget_btn_bluetooth);
                 break;
             case STATE_INTERMEDIATE:
-                views.setImageViewResource(R.id.btn_bluetooth, R.drawable.widget_btn_bluetooth_gray);
+                views.setImageViewResource(R.id.btn_bluetooth,
+                        R.drawable.widget_btn_bluetooth_gray);
                 break;
         }
     }
@@ -187,7 +189,8 @@
      * @param appWidgetId
      * @return
      */
-    private static PendingIntent getLaunchPendingIntent(Context context, int appWidgetId, int buttonId) {
+    private static PendingIntent getLaunchPendingIntent(Context context, int appWidgetId,
+            int buttonId) {
         Intent launchIntent = new Intent();
         launchIntent.setClass(context, SettingsAppWidgetProvider.class);
         launchIntent.addCategory(Intent.CATEGORY_ALTERNATIVE);
@@ -256,6 +259,7 @@
         } else if (wifiState == STATE_DISABLED) {
             wifiManager.setWifiEnabled(true);
         }
+        Toast.makeText(context, R.string.gadget_toggle_wifi, Toast.LENGTH_SHORT).show();
     }
 
     /**
@@ -265,7 +269,8 @@
      * @return true if enabled
      */
     private static boolean getBackgroundDataState(Context context) {
-        ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+        ConnectivityManager connManager =
+                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         return connManager.getBackgroundDataSetting();
     }
 
@@ -275,16 +280,11 @@
      * @param context
      */
     private void toggleBackgroundData(Context context) {
-        ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+        ConnectivityManager connManager =
+                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         boolean sync = getBackgroundDataState(context);
         connManager.setBackgroundDataSetting(!sync);
-
-        IContentService contentService = ContentResolver.getContentService();
-        try {
-            contentService.setListenForNetworkTickles(!sync);
-        } catch (RemoteException e) {
-            Log.d(TAG, "toggleBackgroundData: " + e);
-        }
+        ContentResolver.setMasterSyncAutomatically(!sync);
     }
 
     /**
@@ -306,7 +306,8 @@
     private void toggleGps(Context context) {
         ContentResolver resolver = context.getContentResolver();
         boolean enabled = getGpsState(context);
-        Settings.Secure.setLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER, !enabled);
+        Settings.Secure.setLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER,
+                !enabled);
     }
 
     /**
@@ -399,5 +400,6 @@
         } else if (state == STATE_DISABLED) {
             mLocalBluetoothManager.setBluetoothEnabled(true);
         }
+        Toast.makeText(context, R.string.gadget_toggle_bluetooth, Toast.LENGTH_SHORT).show();
     }
 }
diff --git a/src/com/android/settings/wifi/AccessPointDialog.java b/src/com/android/settings/wifi/AccessPointDialog.java
index 4152056..7e516cc 100644
--- a/src/com/android/settings/wifi/AccessPointDialog.java
+++ b/src/com/android/settings/wifi/AccessPointDialog.java
@@ -440,12 +440,12 @@
     }
 
     private void updatePasswordCaption(String security) {
-        
-        if (mPasswordText != null && security != null
-                && security.equals(AccessPointState.WEP)) {
-            mPasswordText.setText(R.string.please_type_hex_key);
-        } else {
-            mPasswordText.setText(R.string.please_type_passphrase);
+        if (mPasswordText != null) {
+            if (security != null && security.equals(AccessPointState.WEP)) {
+                mPasswordText.setText(R.string.please_type_hex_key);
+            } else {
+                mPasswordText.setText(R.string.please_type_passphrase);
+            }
         }
     }
     
diff --git a/src/com/android/settings/wifi/AccessPointPreference.java b/src/com/android/settings/wifi/AccessPointPreference.java
index 10e0947..6dd5492 100644
--- a/src/com/android/settings/wifi/AccessPointPreference.java
+++ b/src/com/android/settings/wifi/AccessPointPreference.java
@@ -33,14 +33,11 @@
     // Signal strength indicator
     private static final int UI_SIGNAL_LEVELS = 4;
 
-    private WifiSettings mWifiSettings;
-    
     private AccessPointState mState;
 
     public AccessPointPreference(WifiSettings wifiSettings, AccessPointState state) {
         super(wifiSettings, null);
         
-        mWifiSettings = wifiSettings;
         mState = state;
         
         setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
diff --git a/src/com/android/settings/wifi/AdvancedSettings.java b/src/com/android/settings/wifi/AdvancedSettings.java
index 323d5c7..f48e017 100644
--- a/src/com/android/settings/wifi/AdvancedSettings.java
+++ b/src/com/android/settings/wifi/AdvancedSettings.java
@@ -141,7 +141,7 @@
             try {
                 int numChannels = Integer.parseInt((String) newValue);
                 WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
-                if (!wifiManager.setNumAllowedChannels(numChannels)) {
+                if (!wifiManager.setNumAllowedChannels(numChannels, true)) {
                     Toast.makeText(this, R.string.wifi_setting_num_channels_error,
                             Toast.LENGTH_SHORT).show();
                 }
diff --git a/src/com/android/settings/wifi/WifiLayer.java b/src/com/android/settings/wifi/WifiLayer.java
index 5d896aa..ce518e1 100644
--- a/src/com/android/settings/wifi/WifiLayer.java
+++ b/src/com/android/settings/wifi/WifiLayer.java
@@ -774,7 +774,9 @@
              * We pass null for security since we have a network ID (i.e., it's
              * not a wildcard), and rely on it matching.
              */
-            return findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), ssid, null);
+            synchronized (this) {
+                return findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), ssid, null);
+            }
         } else {
             return null;
         }
@@ -1013,8 +1015,10 @@
              * We pass null for security since we have a network ID (i.e., it's
              * not a wildcard), and rely on it matching.
              */
-            ap = findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), wifiInfo
-                    .getSSID(), null);
+            synchronized (this) {
+                ap = findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), wifiInfo
+                        .getSSID(), null);
+            }
         }
 
         if (ap != null) {
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index a015534..d283fb3 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -373,8 +373,8 @@
         }
         
         mDialog = dialog;
-        dialog.setOnDismissListener(this);
         if (dialog != null) {
+            dialog.setOnDismissListener(this);
             dialog.show();
         }
     }