OSDN Git Service

btaa: introduce btif interface for btaa
authorMichael Sun <michaelfsun@google.com>
Mon, 2 Nov 2020 07:17:47 +0000 (07:17 +0000)
committerMichael Sun <michaelfsun@google.com>
Fri, 6 Nov 2020 05:17:55 +0000 (05:17 +0000)
Add a new btif interface for Activity Attribution to help communicate
between JNI and BTAA core module

Tag: #feature
Bug: 172501038
Test: m

Change-Id: Idc7fbb126040bc0b2757b871e9ff6ef8ae889dcf

btif/Android.bp
btif/include/btif_activity_attribution.h [new file with mode: 0644]
btif/src/bluetooth.cc
btif/src/btif_activity_attribution.cc [new file with mode: 0644]

index fde7089..4975a54 100755 (executable)
@@ -49,6 +49,7 @@ cc_library_static {
         "src/btif_a2dp_control.cc",
         "src/btif_a2dp_sink.cc",
         "src/btif_a2dp_source.cc",
+        "src/btif_activity_attribution.cc",
         "src/btif_av.cc",
         "src/btif_avrcp_audio_track.cc",
         "src/btif_ble_advertiser.cc",
diff --git a/btif/include/btif_activity_attribution.h b/btif/include/btif_activity_attribution.h
new file mode 100644 (file)
index 0000000..3194d33
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2020 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.
+ */
+
+#include <hardware/bt_activity_attribution.h>
+
+namespace bluetooth {
+namespace activity_attribution {
+
+ActivityAttributionInterface* getActivityAttributionInterface();
+
+}  // namespace activity_attribution
+}  // namespace bluetooth
\ No newline at end of file
index 07ed4cf..c272cf1 100644 (file)
@@ -49,6 +49,7 @@
 #include "bta/include/bta_hf_client_api.h"
 #include "btif/avrcp/avrcp_service.h"
 #include "btif_a2dp.h"
+#include "btif_activity_attribution.h"
 #include "btif_api.h"
 #include "btif_av.h"
 #include "btif_bqr.h"
@@ -430,6 +431,11 @@ static const void* get_profile_interface(const char* profile_id) {
 
   if (is_profile(profile_id, BT_KEYSTORE_ID))
     return bluetooth::bluetooth_keystore::getBluetoothKeystoreInterface();
+
+  if (is_profile(profile_id, BT_ACTIVITY_ATTRIBUTION_ID)) {
+    return bluetooth::activity_attribution::getActivityAttributionInterface();
+  }
+
   return NULL;
 }
 
diff --git a/btif/src/btif_activity_attribution.cc b/btif/src/btif_activity_attribution.cc
new file mode 100644 (file)
index 0000000..a618ae6
--- /dev/null
@@ -0,0 +1,63 @@
+/******************************************************************************
+ *
+ *  Copyright 2020 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.
+ *
+ ******************************************************************************/
+
+/* Activity Attribution Interface */
+
+#include <hardware/bt_activity_attribution.h>
+
+#include "btif/include/btif_common.h"
+#include "stack/include/btu.h"
+
+using base::Bind;
+using base::Unretained;
+
+namespace bluetooth {
+namespace activity_attribution {
+
+std::unique_ptr<ActivityAttributionInterface> activityAttributionInstance;
+
+class ActivityAttributionInterfaceImpl : public ActivityAttributionCallbacks,
+                                         public ActivityAttributionInterface {
+  ~ActivityAttributionInterfaceImpl() override = default;
+
+  void Init(ActivityAttributionCallbacks* callbacks) override {
+    this->callbacks = callbacks;
+  }
+
+  void OnWakeup(Activity activity, const RawAddress& address) override {
+    VLOG(2) << __func__ << " activity: " << (int)activity
+            << " address: " << address;
+    do_in_jni_thread(FROM_HERE, Bind(&ActivityAttributionCallbacks::OnWakeup,
+                                     Unretained(callbacks), activity, address));
+  }
+
+  void Cleanup(void) override {}
+
+ private:
+  ActivityAttributionCallbacks* callbacks;
+};
+
+ActivityAttributionInterface* getActivityAttributionInterface() {
+  if (!activityAttributionInstance)
+    activityAttributionInstance.reset(new ActivityAttributionInterfaceImpl());
+
+  return activityAttributionInstance.get();
+}
+
+}  // namespace activity_attribution
+}  // namespace bluetooth