From 9e1c958d13978ebb8e91c4ecf1747e3304abc5ee Mon Sep 17 00:00:00 2001
From: Ajay Panicker <apanicke@google.com>
Date: Wed, 14 Mar 2018 23:45:54 -0700
Subject: [PATCH] Implement the JNI layer for the AVRCP Service (2/3)

Allows the AVRCP Service Interface to be retrieved via bt_interface_t.

Bug: 68854188
Test: Compile
Change-Id: I0d9464ea19d3bd382d07134bff057a5515501b95
---
 system/btif/Android.bp                         |  5 ++---
 system/btif/src/bluetooth.cc                   |  6 ++++++
 system/include/Android.bp                      |  8 ++++++++
 system/include/hardware/avrcp/avrcp.h          |  1 -
 system/include/hardware/bluetooth.h            | 10 ++++++++--
 system/service/hal/fake_bluetooth_interface.cc |  3 ++-
 system/vendor_libs/test_vendor_lib/Android.bp  |  3 +++
 7 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/system/btif/Android.bp b/system/btif/Android.bp
index 8514f9020c8..78f313f75aa 100644
--- a/system/btif/Android.bp
+++ b/system/btif/Android.bp
@@ -14,6 +14,7 @@ btifCommonIncludes = [
     "packages/modules/Bluetooth/system/stack/btm",
     "packages/modules/Bluetooth/system/stack/avdt",
     "packages/modules/Bluetooth/system/udrv/include",
+    "packages/modules/Bluetooth/system/btif/avrcp",
     "packages/modules/Bluetooth/system/btif/include",
     "packages/modules/Bluetooth/system/btif/co",
     "packages/modules/Bluetooth/system/hci/include",
@@ -101,12 +102,10 @@ cc_library_static {
         "libhwbinder",
         "libutils",
     ],
-    static_libs: [
-        "lib-bt-packets",
-    ],
     whole_static_libs: [
         "avrcp-target-service",
         "libaudio-a2dp-hw-utils",
+        "lib-bt-packets",
     ],
     cflags: ["-DBUILDCFG"],
 
diff --git a/system/btif/src/bluetooth.cc b/system/btif/src/bluetooth.cc
index edd6dab86c0..d10bbd15d32 100644
--- a/system/btif/src/bluetooth.cc
+++ b/system/btif/src/bluetooth.cc
@@ -47,6 +47,7 @@
 #include <hardware/bt_sdp.h>
 #include <hardware/bt_sock.h>
 
+#include "avrcp_service.h"
 #include "bt_utils.h"
 #include "bta/include/bta_hf_client_api.h"
 #include "btif_a2dp.h"
@@ -422,6 +423,10 @@ static int config_clear(void) {
   return btif_config_clear() ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
 }
 
+static bluetooth::avrcp::ServiceInterface* get_avrcp_service(void) {
+  return bluetooth::avrcp::AvrcpService::GetServiceInterface();
+}
+
 EXPORT_SYMBOL bt_interface_t bluetoothInterface = {
     sizeof(bluetoothInterface),
     init,
@@ -456,4 +461,5 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = {
     config_clear,
     interop_database_clear,
     interop_database_add,
+    get_avrcp_service,
 };
diff --git a/system/include/Android.bp b/system/include/Android.bp
index 3099ee34689..12494b1fa43 100644
--- a/system/include/Android.bp
+++ b/system/include/Android.bp
@@ -4,6 +4,12 @@ cc_library_headers {
     export_include_dirs: ["./hardware/avrcp/"],
     header_libs: ["internal_include_headers"],
     export_header_lib_headers: ["internal_include_headers"],
+
+    // We need this in case some file outside of the Bluetooth project includes
+    // bluetooth.h but doesn't include libchrome which avrcp.h depends on.
+    static_libs: ["libchrome"],
+    export_static_lib_headers: ["libchrome"],
+
     vendor_available: true,
     host_supported: true,
 }
@@ -11,9 +17,11 @@ cc_library_headers {
 cc_library_headers {
     name: "libbluetooth_headers",
     header_libs: [
+        "avrcp_headers",
         "libbluetooth-types-header",
     ],
     export_header_lib_headers: [
+        "avrcp_headers",
         "libbluetooth-types-header",
     ],
 
diff --git a/system/include/hardware/avrcp/avrcp.h b/system/include/hardware/avrcp/avrcp.h
index e1f48c2aa35..f3a5d40b8af 100644
--- a/system/include/hardware/avrcp/avrcp.h
+++ b/system/include/hardware/avrcp/avrcp.h
@@ -22,7 +22,6 @@
 #include <base/bind.h>
 
 #include "avrcp_common.h"
-#include "avrcp_logging_helper.h"
 #include "raw_address.h"
 
 namespace bluetooth {
diff --git a/system/include/hardware/bluetooth.h b/system/include/hardware/bluetooth.h
index e48e560b9b0..713ae4e1004 100644
--- a/system/include/hardware/bluetooth.h
+++ b/system/include/hardware/bluetooth.h
@@ -22,8 +22,9 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
-#include <bluetooth/uuid.h>
-#include <raw_address.h>
+#include "avrcp/avrcp.h"
+#include "bluetooth/uuid.h"
+#include "raw_address.h"
 
 /**
  * The Bluetooth Hardware Module ID
@@ -585,6 +586,11 @@ typedef struct {
    */
   void (*interop_database_add)(uint16_t feature, const RawAddress* addr,
                                size_t len);
+
+  /**
+   * Get the AvrcpTarget Service interface to interact with the Avrcp Service
+   */
+  bluetooth::avrcp::ServiceInterface* (*get_avrcp_service)(void);
 } bt_interface_t;
 
 #define BLUETOOTH_INTERFACE_STRING "bluetoothInterface"
diff --git a/system/service/hal/fake_bluetooth_interface.cc b/system/service/hal/fake_bluetooth_interface.cc
index 08751cd5308..eb550e7ce61 100644
--- a/system/service/hal/fake_bluetooth_interface.cc
+++ b/system/service/hal/fake_bluetooth_interface.cc
@@ -72,7 +72,8 @@ bt_interface_t fake_bt_iface = {
     nullptr, /* dumpMetrics */
     nullptr, /* config clear */
     nullptr, /* interop_database_clear */
-    nullptr  /* interop_database_add */
+    nullptr, /* interop_database_add */
+    nullptr, /* get_avrcp_service */
 };
 
 }  // namespace
diff --git a/system/vendor_libs/test_vendor_lib/Android.bp b/system/vendor_libs/test_vendor_lib/Android.bp
index 4cbba4894e6..06db1f70660 100644
--- a/system/vendor_libs/test_vendor_lib/Android.bp
+++ b/system/vendor_libs/test_vendor_lib/Android.bp
@@ -77,6 +77,9 @@ cc_test_host {
         "test/l2cap_test.cc",
         "test/l2cap_sdu_test.cc",
     ],
+    header_libs: [
+        "libbluetooth_headers",
+    ],
     local_include_dirs: [
         "include",
     ],
-- 
GitLab