OSDN Git Service

AdapterProperties: Track connection state change from more profiles
authorJack He <siyuanh@google.com>
Fri, 21 Apr 2017 01:53:11 +0000 (18:53 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Fri, 21 Apr 2017 23:29:59 +0000 (23:29 +0000)
* AdapterProperties should handle ACTION_CONNECTION_STATE_CHANGED intent
  from more profiles
* AdapterProperties sends BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED
  with STATE_CONNECTING and STATE_CONNECTED when first profile send out
  the same intent, and with STATE_DISCONNECTING and STATE_DISCONNECTED
  when last profile send out the same intent.
* At the same moment, AdapterProperties also update the return value for
  BluetoothAdapter.getConnectionState()
* Currently, we are only tracking HEADSET (HFP), HEADSET_CLIENT (HFP), A2DP,
  A2DP_SINK profiles, other profiles such as PAN, PBAP, HID profiles are
  not tracked properly and their state change could be missed by
  both intent users and BluetoothAdapter.getConnectionState()
* After this CL, the following profiles will be tracked:
  AVRCP_CONTROLLER, A2DP, A2DP_SINK, HEADSET, HEADSET_CLIENT,
  INPUT_HOST, INPUT_DEVICE, MAP, MAP_CLIENT, PAN, PBAP_CLIENT, SAP

Bug: 37546066
Test: make, test connect and disconnect each profiles
Change-Id: I2ef0e55f58e6f7891823137e2e4534e97a126c25
(cherry picked from commit cbdcb7e4fc76661793877f142f628864797cb970)

src/com/android/bluetooth/btservice/AdapterProperties.java

index dbb5bb3..7627f56 100644 (file)
@@ -19,10 +19,19 @@ package com.android.bluetooth.btservice;
 import android.bluetooth.BluetoothA2dp;
 import android.bluetooth.BluetoothA2dpSink;
 import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothAvrcpController;
 import android.bluetooth.BluetoothDevice;
 import android.bluetooth.BluetoothHeadset;
 import android.bluetooth.BluetoothHeadsetClient;
+import android.bluetooth.BluetoothInputDevice;
+import android.bluetooth.BluetoothInputHost;
+import android.bluetooth.BluetoothMap;
+import android.bluetooth.BluetoothMapClient;
+import android.bluetooth.BluetoothPan;
+import android.bluetooth.BluetoothPbap;
+import android.bluetooth.BluetoothPbapClient;
 import android.bluetooth.BluetoothProfile;
+import android.bluetooth.BluetoothSap;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -88,16 +97,31 @@ class AdapterProperties {
         @Override
         public void onReceive(Context context, Intent intent) {
             Log.d(TAG, "Received intent " + intent);
-            if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
+            String action = intent.getAction();
+            if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
                 sendConnectionStateChange(BluetoothProfile.HEADSET, intent);
-            } else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
+            } else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
                 sendConnectionStateChange(BluetoothProfile.A2DP, intent);
-            } else if (BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED.equals(
-                               intent.getAction())) {
+            } else if (BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
                 sendConnectionStateChange(BluetoothProfile.HEADSET_CLIENT, intent);
-            } else if (BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED.equals(
-                               intent.getAction())) {
+            } else if (BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
                 sendConnectionStateChange(BluetoothProfile.A2DP_SINK, intent);
+            } else if (BluetoothInputHost.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+                sendConnectionStateChange(BluetoothProfile.INPUT_HOST, intent);
+            } else if (BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+                sendConnectionStateChange(BluetoothProfile.INPUT_DEVICE, intent);
+            } else if (BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+                sendConnectionStateChange(BluetoothProfile.AVRCP_CONTROLLER, intent);
+            } else if (BluetoothPan.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+                sendConnectionStateChange(BluetoothProfile.PAN, intent);
+            } else if (BluetoothMap.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+                sendConnectionStateChange(BluetoothProfile.MAP, intent);
+            } else if (BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+                sendConnectionStateChange(BluetoothProfile.MAP_CLIENT, intent);
+            } else if (BluetoothSap.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+                sendConnectionStateChange(BluetoothProfile.SAP, intent);
+            } else if (BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
+                sendConnectionStateChange(BluetoothProfile.PBAP_CLIENT, intent);
             }
         }
     };
@@ -124,6 +148,14 @@ class AdapterProperties {
         filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
         filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
         filter.addAction(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED);
+        filter.addAction(BluetoothInputHost.ACTION_CONNECTION_STATE_CHANGED);
+        filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED);
+        filter.addAction(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED);
+        filter.addAction(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED);
+        filter.addAction(BluetoothMap.ACTION_CONNECTION_STATE_CHANGED);
+        filter.addAction(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED);
+        filter.addAction(BluetoothSap.ACTION_CONNECTION_STATE_CHANGED);
+        filter.addAction(BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED);
         filter.addAction(BluetoothDevice.ACTION_UUID);
         mService.registerReceiver(mReceiver, filter);
     }