summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/bluetooth
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2010-01-22 18:49:07 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2010-01-22 18:49:07 -0800
commit4691219ce55cddeab29a277da02eb1540f501ba4 (patch)
treebfbcb5cc09d7bbed0d3a5d9e8888c3f254cb558d /src/com/android/settings/bluetooth
parent6043f7f0b36b95648c6296c3fa0ba19eb8379551 (diff)
parentfcd4e7fec3c80d0a16630246c4942595d34c655c (diff)
downloadpackages_apps_settings-4691219ce55cddeab29a277da02eb1540f501ba4.zip
packages_apps_settings-4691219ce55cddeab29a277da02eb1540f501ba4.tar.gz
packages_apps_settings-4691219ce55cddeab29a277da02eb1540f501ba4.tar.bz2
am fcd4e7fe: am 04bdae75: Merge "b/2332395 Fixed a bug where BT is not disabled if the phone was inserted and removed quickly." into eclair
Merge commit 'fcd4e7fec3c80d0a16630246c4942595d34c655c' * commit 'fcd4e7fec3c80d0a16630246c4942595d34c655c': b/2332395 Fixed a bug where BT is not disabled if the phone was inserted and removed quickly.
Diffstat (limited to 'src/com/android/settings/bluetooth')
-rw-r--r--src/com/android/settings/bluetooth/DockService.java59
1 files changed, 46 insertions, 13 deletions
diff --git a/src/com/android/settings/bluetooth/DockService.java b/src/com/android/settings/bluetooth/DockService.java
index 2e07119..db5bcb8 100644
--- a/src/com/android/settings/bluetooth/DockService.java
+++ b/src/com/android/settings/bluetooth/DockService.java
@@ -84,6 +84,9 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
private static final String SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED =
"disable_bt_when_undock";
+ private static final String SHARED_PREFERENCES_KEY_DISABLE_BT =
+ "disable_bt";
+
private static final int INVALID_STARTID = -100;
// Created in OnCreate()
@@ -107,6 +110,7 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
private BluetoothDevice mPendingDevice;
private int mPendingStartId;
private int mPendingTurnOnStartId = INVALID_STARTID;
+ private int mPendingTurnOffStartId = INVALID_STARTID;
@Override
public void onCreate() {
@@ -219,6 +223,7 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
mServiceHandler.removeMessages(MSG_TYPE_UNDOCKED_PERMANENT);
mServiceHandler.removeMessages(MSG_TYPE_DISABLE_BT);
+ removeSetting(SHARED_PREFERENCES_KEY_DISABLE_BT);
if (!device.equals(mDevice)) {
if (mDevice != null) {
@@ -240,8 +245,13 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
case MSG_TYPE_UNDOCKED_PERMANENT:
// Grace period passed. Disconnect.
handleUndocked(mContext, mBtManager, device);
- if(DEBUG) Log.d(TAG, "getDisableBtSetting = " + getDisableBtSetting());
- if (getDisableBtSetting()) {
+
+ if (DEBUG) {
+ Log.d(TAG, "DISABLE_BT_WHEN_UNDOCKED = "
+ + getSetting(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED));
+ }
+
+ if (getSetting(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED)) {
// BT was disabled when we first docked
if (!hasOtherConnectedDevices(device)) {
if(DEBUG) Log.d(TAG, "QUEUED BT DISABLE");
@@ -252,7 +262,7 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
deferFinishCall = true;
} else {
// Don't disable BT if something is connected
- removeDisableBtSetting();
+ removeSetting(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED);
}
}
break;
@@ -266,8 +276,15 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
case MSG_TYPE_DISABLE_BT:
if(DEBUG) Log.d(TAG, "BT DISABLE");
- mBtManager.getBluetoothAdapter().disable();
- removeDisableBtSetting();
+ if (mBtManager.getBluetoothAdapter().disable()) {
+ removeSetting(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED);
+ } else {
+ // disable() returned an error. Persist a flag to disable BT later
+ setSetting(SHARED_PREFERENCES_KEY_DISABLE_BT, true);
+ mPendingTurnOffStartId = startId;
+ deferFinishCall = true;
+ if(DEBUG) Log.d(TAG, "disable failed. try again later " + startId);
+ }
break;
}
@@ -490,6 +507,10 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
mPendingDevice = null;
DockEventReceiver.finishStartingService(mContext, mPendingStartId);
} else {
+ if (DEBUG) {
+ Log.d(TAG, "A DISABLE_BT_WHEN_UNDOCKED = "
+ + getSetting(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED));
+ }
// Reconnect if docked and bluetooth was enabled by user.
Intent i = registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
if (i != null) {
@@ -501,6 +522,11 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
if (device != null) {
connectIfEnabled(device);
}
+ } else if (getSetting(SHARED_PREFERENCES_KEY_DISABLE_BT)
+ && mBtManager.getBluetoothAdapter().disable()) {
+ mPendingTurnOffStartId = startId;
+ removeSetting(SHARED_PREFERENCES_KEY_DISABLE_BT);
+ return;
}
}
}
@@ -516,12 +542,19 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
// The rational is that:
// a) if BT is off at undock time, no work needs to be done
// b) if BT is on at undock time, the user wants it on.
- removeDisableBtSetting();
+ removeSetting(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED);
DockEventReceiver.finishStartingService(this, startId);
} else if (btState == BluetoothAdapter.STATE_OFF) {
// Bluetooth was turning off as we were trying to turn it on.
// Let's try again
if(DEBUG) Log.d(TAG, "Bluetooth = OFF mPendingDevice = " + mPendingDevice);
+
+ if (mPendingTurnOffStartId != INVALID_STARTID) {
+ DockEventReceiver.finishStartingService(this, mPendingTurnOffStartId);
+ removeSetting(SHARED_PREFERENCES_KEY_DISABLE_BT);
+ mPendingTurnOffStartId = INVALID_STARTID;
+ }
+
if (mPendingDevice != null) {
mBtManager.getBluetoothAdapter().enable();
mPendingTurnOnStartId = startId;
@@ -579,7 +612,7 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
mPendingDevice = device;
mPendingStartId = startId;
if (btState != BluetoothAdapter.STATE_TURNING_ON) {
- setDisableBtSetting(true);
+ setSetting(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED, true);
}
return;
}
@@ -643,24 +676,24 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
return cachedBluetoothDevice;
}
- private boolean getDisableBtSetting() {
+ private boolean getSetting(String key) {
SharedPreferences sharedPref = getSharedPreferences(SHARED_PREFERENCES_NAME,
Context.MODE_PRIVATE);
- return sharedPref.getBoolean(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED, false);
+ return sharedPref.getBoolean(key, false);
}
- private void setDisableBtSetting(boolean disableBt) {
+ private void setSetting(String key, boolean disableBt) {
SharedPreferences.Editor editor = getSharedPreferences(SHARED_PREFERENCES_NAME,
Context.MODE_PRIVATE).edit();
- editor.putBoolean(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED, disableBt);
+ editor.putBoolean(key, disableBt);
editor.commit();
}
- private void removeDisableBtSetting() {
+ private void removeSetting(String key) {
SharedPreferences sharedPref = getSharedPreferences(SHARED_PREFERENCES_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
- editor.remove(SHARED_PREFERENCES_KEY_DISABLE_BT_WHEN_UNDOCKED);
+ editor.remove(key);
editor.commit();
return;
}