summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/bluetooth/DockEventReceiver.java
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2010-04-06 14:49:30 -0700
committerMichael Chan <mchan@android.com>2010-04-06 15:42:04 -0700
commit732c1dad5a4871597652f17986b7a602897e5a76 (patch)
treedabca0273050ec87a48a963727714860c2f24a06 /src/com/android/settings/bluetooth/DockEventReceiver.java
parent6e74d41bd0525459c43ed010e8f049ffc20ca362 (diff)
downloadpackages_apps_Settings-732c1dad5a4871597652f17986b7a602897e5a76.zip
packages_apps_Settings-732c1dad5a4871597652f17986b7a602897e5a76.tar.gz
packages_apps_Settings-732c1dad5a4871597652f17986b7a602897e5a76.tar.bz2
b/2498180 b/2568119 Retry if BT dock disconnects unexpectedly
Change-Id: Ic4771e7c305192fee56f5f80c6cabeecf11a99dc
Diffstat (limited to 'src/com/android/settings/bluetooth/DockEventReceiver.java')
-rw-r--r--src/com/android/settings/bluetooth/DockEventReceiver.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/com/android/settings/bluetooth/DockEventReceiver.java b/src/com/android/settings/bluetooth/DockEventReceiver.java
index 2d634b2..6d11972 100644
--- a/src/com/android/settings/bluetooth/DockEventReceiver.java
+++ b/src/com/android/settings/bluetooth/DockEventReceiver.java
@@ -16,12 +16,17 @@
package com.android.settings.bluetooth;
+import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
+
import android.app.Service;
+import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothHeadset;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.os.PowerManager;
import android.util.Log;
@@ -75,6 +80,54 @@ public class DockEventReceiver extends BroadcastReceiver {
if (DEBUG) Log.e(TAG, "Unknown state");
break;
}
+ } else if (BluetoothHeadset.ACTION_STATE_CHANGED.equals(intent.getAction())) {
+ /*
+ * Reconnect to the dock if:
+ * 1) it is a dock
+ * 2) it is disconnected
+ * 3) the disconnect is initiated remotely
+ * 4) the dock is still docked (check can only be done in the Service)
+ */
+ if (device == null) {
+ if (DEBUG) Log.d(TAG, "Device is missing");
+ return;
+ }
+
+ int newState = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE,
+ BluetoothHeadset.STATE_CONNECTED);
+ if (newState != BluetoothHeadset.STATE_DISCONNECTED) return;
+
+ int source = intent.getIntExtra(BluetoothHeadset.EXTRA_DISCONNECT_INITIATOR,
+ BluetoothHeadset.LOCAL_DISCONNECT);
+ if (source != BluetoothHeadset.REMOTE_DISCONNECT) return;
+
+ // Too bad, the dock state can't be checked from a BroadcastReceiver.
+ Intent i = new Intent(intent);
+ i.setClass(context, DockService.class);
+ beginStartingService(context, i);
+
+ } else if (BluetoothA2dp.ACTION_SINK_STATE_CHANGED.equals(intent.getAction())) {
+ /*
+ * Reconnect to the dock if:
+ * 1) it is a dock
+ * 2) it is an unexpected disconnect i.e. didn't go through disconnecting state
+ * 3) the dock is still docked (check can only be done in the Service)
+ */
+ if (device == null) {
+ if (DEBUG) Log.d(TAG, "Device is missing");
+ return;
+ }
+
+ int newState = intent.getIntExtra(BluetoothA2dp.EXTRA_SINK_STATE, 0);
+ int oldState = intent.getIntExtra(BluetoothA2dp.EXTRA_PREVIOUS_SINK_STATE, 0);
+ if (newState == BluetoothA2dp.STATE_DISCONNECTED &&
+ oldState != BluetoothA2dp.STATE_DISCONNECTING) {
+ // Too bad, the dock state can't be checked from a BroadcastReceiver.
+ Intent i = new Intent(intent);
+ i.setClass(context, DockService.class);
+ beginStartingService(context, i);
+ }
+
} else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
int btState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if (btState != BluetoothAdapter.STATE_TURNING_ON) {