OSDN Git Service

Add a property to enable the New AVRCP Profile (1/2)
authorAjay Panicker <apanicke@google.com>
Sat, 17 Mar 2018 00:13:50 +0000 (17:13 -0700)
committerAjay Panicker <apanicke@google.com>
Tue, 20 Mar 2018 20:40:57 +0000 (13:40 -0700)
You can now use the new AVRCP Profile by setting
persist.bluetooth.enablenewavrcp to true.

Also fix a misundestanding with connection_handler.cc. AVRCP Control
callbacks return a null address when disconnecting.

Bug: 68854188
Test: Check to see that the profile is used when property is true and is
      not used when property is false.

Change-Id: I4aa285c6bf009716cc80a80b813ba0acd3d8f9d8

binder/Android.bp
binder/android/bluetooth/IBluetoothAvrcpTarget.aidl [new file with mode: 0644]
bta/Android.bp
bta/av/bta_av_aact.cc
bta/av/bta_av_act.cc
btif/avrcp/avrcp_service.h
profile/avrcp/connection_handler.cc

index 78cd70f..18428c2 100644 (file)
@@ -15,6 +15,7 @@ cc_library_shared {
         "android/bluetooth/IBluetoothA2dp.aidl",
         "android/bluetooth/IBluetoothA2dpSink.aidl",
         "android/bluetooth/IBluetoothAvrcpController.aidl",
+        "android/bluetooth/IBluetoothAvrcpTarget.aidl",
         "android/bluetooth/IBluetoothCallback.aidl",
         "android/bluetooth/IBluetoothProfileServiceConnection.aidl",
         "android/bluetooth/IBluetoothHeadset.aidl",
@@ -87,6 +88,7 @@ filegroup {
         "android/bluetooth/IBluetoothA2dp.aidl",
         "android/bluetooth/IBluetoothA2dpSink.aidl",
         "android/bluetooth/IBluetoothAvrcpController.aidl",
+        "android/bluetooth/IBluetoothAvrcpTarget.aidl",
         "android/bluetooth/IBluetoothCallback.aidl",
         "android/bluetooth/IBluetoothProfileServiceConnection.aidl",
         "android/bluetooth/IBluetoothHeadset.aidl",
diff --git a/binder/android/bluetooth/IBluetoothAvrcpTarget.aidl b/binder/android/bluetooth/IBluetoothAvrcpTarget.aidl
new file mode 100644 (file)
index 0000000..23f3608
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2018 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 android.bluetooth;
+
+/**
+ * API for Bluetooth AVRCP Target Interface
+ *
+ * @hide
+ */
+interface IBluetoothAvrcpTarget {
+    /**
+     * @hide
+     */
+    void sendVolumeChanged(in int volume);
+}
index 60c05a3..e406e60 100644 (file)
@@ -12,6 +12,7 @@ cc_defaults {
         "system/bt",
         "system/bt/bta/include",
         "system/bt/btcore/include",
+        "system/bt/btif/avrcp",
         "system/bt/hci/include",
         "system/bt/internal_include",
         "system/bt/stack/include",
@@ -109,7 +110,10 @@ cc_library_static {
         "sys/bta_sys_main.cc",
         "sys/utl.cc",
     ],
-
+    static_libs: [
+        "avrcp-target-service",
+        "lib-bt-packets",
+    ],
     whole_static_libs: [
         "libaudio-hearing-aid-hw-utils",
     ],
index fa2084c..17f958a 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "a2dp_sbc.h"
 #include "avdt_api.h"
+#include "avrcp_service.h"
 #include "bt_utils.h"
 #include "bta_av_int.h"
 #include "btif/include/btif_av_co.h"
@@ -2900,7 +2901,12 @@ void bta_av_open_rc(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
       }
     } else {
       /* use main SM for AVRC SDP activities */
-      bta_av_rc_disc((uint8_t)(p_scb->hdi + 1));
+      if (is_new_avrcp_enabled()) {
+        APPL_TRACE_WARNING("%s: Using the new AVRCP Profile", __func__);
+        bluetooth::avrcp::AvrcpService::Get()->ConnectDevice(p_scb->peer_addr);
+      } else {
+        bta_av_rc_disc((uint8_t)(p_scb->hdi + 1));
+      }
     }
   } else {
     if (BTA_AV_RC_HANDLE_NONE != p_scb->rc_handle) {
index a7d9022..38f1810 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 
 #include "avdt_api.h"
+#include "avrcp_service.h"
 #include "bta_av_api.h"
 #include "bta_av_int.h"
 #include "l2c_api.h"
@@ -303,6 +304,12 @@ static void bta_av_rc_msg_cback(uint8_t handle, uint8_t label, uint8_t opcode,
  ******************************************************************************/
 uint8_t bta_av_rc_create(tBTA_AV_CB* p_cb, uint8_t role, uint8_t shdl,
                          uint8_t lidx) {
+  if (is_new_avrcp_enabled()) {
+    APPL_TRACE_WARNING("%s: Skipping RC creation for the old AVRCP profile",
+                       __func__);
+    return BTA_AV_RC_HANDLE_NONE;
+  }
+
   tAVRC_CONN_CB ccb;
   RawAddress bda = RawAddress::kAny;
   uint8_t status = BTA_AV_RC_ROLE_ACP;
index 3c245ce..b2a5303 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "avrcp.h"
 #include "connection_handler.h"
+#include "osi/include/properties.h"
 #include "raw_address.h"
 
 namespace bluetooth {
@@ -92,4 +93,8 @@ class AvrcpService : public MediaCallbacks {
 };
 
 }  // namespace avrcp
-}  // namespace bluetooth
\ No newline at end of file
+}  // namespace bluetooth
+
+inline bool is_new_avrcp_enabled() {
+  return osi_property_get_bool("persist.bluetooth.enablenewavrcp", false);
+}
\ No newline at end of file
index 3ad1a3a..895ece5 100644 (file)
@@ -191,8 +191,6 @@ void ConnectionHandler::InitiatorControlCb(uint8_t handle, uint8_t event,
                                            uint16_t result,
                                            const RawAddress* peer_addr) {
   DCHECK(!connection_cb_.is_null());
-  CHECK(peer_addr != nullptr);  // FIXME: Maybe this should change? I'm not
-                                // totally when this can be null.
 
   LOG(INFO) << __PRETTY_FUNCTION__ << ": handle=" << loghex(handle)
             << " result=" << loghex(result)
@@ -242,7 +240,7 @@ void ConnectionHandler::InitiatorControlCb(uint8_t handle, uint8_t event,
             << "Connection Close received from device that doesn't exist";
         return;
       }
-      feature_map_.erase(*peer_addr);
+      feature_map_.erase(device_map_[handle]->GetAddress());
       device_map_[handle]->DeviceDisconnected();
       device_map_.erase(handle);
     } break;
@@ -267,8 +265,6 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event,
                                           uint16_t result,
                                           const RawAddress* peer_addr) {
   DCHECK(!connection_cb_.is_null());
-  CHECK(peer_addr != nullptr);  // FIXME: Maybe this should change? I'm not
-                                // totally when this can be null.
 
   LOG(INFO) << __PRETTY_FUNCTION__ << ": handle=" << loghex(handle)
             << " result=" << loghex(result)
@@ -322,7 +318,7 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event,
             << "Connection Close received from device that doesn't exist";
         return;
       }
-      feature_map_.erase(*peer_addr);
+      feature_map_.erase(device_map_[handle]->GetAddress());
       device_map_[handle]->DeviceDisconnected();
       device_map_.erase(handle);
     } break;