OSDN Git Service

Changing the order of notification of connection state change, as it was causing...
authorSreenidhi T <nidhit@broadcom.com>
Mon, 21 May 2012 10:39:22 +0000 (03:39 -0700)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Tue, 17 Jul 2012 05:09:26 +0000 (22:09 -0700)
Change-Id: I6f4c75e4eac4ae798cb7918a4f1b7458e1eaa4b0

src/com/android/bluetooth/a2dp/A2dpStateMachine.java
src/com/android/bluetooth/hfp/HeadsetStateMachine.java
src/com/android/bluetooth/hid/HidService.java
src/com/android/bluetooth/pan/PanService.java

index c839d29..2e8d902 100755 (executable)
@@ -613,13 +613,17 @@ final class A2dpStateMachine extends StateMachine {
 
     // This method does not check for error conditon (newState == prevState)
     private void broadcastConnectionState(BluetoothDevice device, int newState, int prevState) {
+        /* Notifying the connection state change of the profile before sending the intent for
+           connection state change, as it was causing a race condition, with the UI not being
+           updated with the correct connection state. */
+        if (DBG) log("Connection state " + device + ": " + prevState + "->" + newState);
+        mService.notifyProfileConnectionStateChanged(device, BluetoothProfile.A2DP,
+                                                     newState, prevState);
         Intent intent = new Intent(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
         intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
         intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
         intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
         mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM);
-        if (DBG) log("Connection state " + device + ": " + prevState + "->" + newState);
-        mService.notifyProfileConnectionStateChanged(device, BluetoothProfile.A2DP, newState, prevState);
     }
 
     private void broadcastAudioState(BluetoothDevice device, int state, int prevState) {
index e6c1107..7e1f834 100755 (executable)
@@ -1177,13 +1177,17 @@ final class HeadsetStateMachine extends StateMachine {
 
     // This method does not check for error conditon (newState == prevState)
     private void broadcastConnectionState(BluetoothDevice device, int newState, int prevState) {
+        if (DBG) log("Connection state " + device + ": " + prevState + "->" + newState);
+        /* Notifying the connection state change of the profile before sending the intent for
+           connection state change, as it was causing a race condition, with the UI not being
+           updated with the correct connection state. */
+        mService.notifyProfileConnectionStateChanged(device, BluetoothProfile.HEADSET,
+                                                     newState, prevState);
         Intent intent = new Intent(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
         intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
         intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
         intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
         mService.sendBroadcast(intent, HeadsetService.BLUETOOTH_PERM);
-        if (DBG) log("Connection state " + device + ": " + prevState + "->" + newState);
-        mService.notifyProfileConnectionStateChanged(device, BluetoothProfile.HEADSET, newState, prevState);
     }
 
     private void broadcastAudioState(BluetoothDevice device, int newState, int prevState) {
index c522c66..e0d7be7 100755 (executable)
@@ -492,14 +492,18 @@ public class HidService extends ProfileService {
         }
         mInputDevices.put(device, newState);
 
+        /* Notifying the connection state change of the profile before sending the intent for
+           connection state change, as it was causing a race condition, with the UI not being
+           updated with the correct connection state. */
+        if (DBG) log("Connection state " + device + ": " + prevState + "->" + newState);
+        notifyProfileConnectionStateChanged(device, BluetoothProfile.INPUT_DEVICE,
+                                            newState, prevState);
         Intent intent = new Intent(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED);
         intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
         intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
         intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
         intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
         sendBroadcast(intent, BLUETOOTH_PERM);
-        if (DBG) log("Connection state " + device + ": " + prevState + "->" + newState);
-        notifyProfileConnectionStateChanged(device, BluetoothProfile.INPUT_DEVICE, newState, prevState);
     }
 
     private void broadcastProtocolMode(BluetoothDevice device, int protocolMode) {
index 6116ee8..7f1cc7c 100755 (executable)
@@ -411,16 +411,18 @@ public class PanService extends ProfileService {
             panDevice.mIface = iface;
         }
 
+        /* Notifying the connection state change of the profile before sending the intent for
+           connection state change, as it was causing a race condition, with the UI not being
+           updated with the correct connection state. */
+        if (DBG) Log.d(TAG, "Pan Device state : device: " + device + " State:" +
+                       prevState + "->" + state);
+        notifyProfileConnectionStateChanged(device, BluetoothProfile.PAN, state, prevState);
         Intent intent = new Intent(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED);
         intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
         intent.putExtra(BluetoothPan.EXTRA_PREVIOUS_STATE, prevState);
         intent.putExtra(BluetoothPan.EXTRA_STATE, state);
         intent.putExtra(BluetoothPan.EXTRA_LOCAL_ROLE, local_role);
         sendBroadcast(intent, BLUETOOTH_PERM);
-
-        if (DBG) Log.d(TAG, "Pan Device state : device: " + device + " State:" +
-                       prevState + "->" + state);
-        notifyProfileConnectionStateChanged(device, BluetoothProfile.PAN, state, prevState);
     }
 
     // configured when we start tethering