OSDN Git Service

btaa: introduce Bluetooth Activity Attribution skeleton
authorMichael Sun <michaelfsun@google.com>
Thu, 5 Nov 2020 06:33:48 +0000 (06:33 +0000)
committerMichael Sun <michaelfsun@google.com>
Tue, 10 Nov 2020 08:27:33 +0000 (08:27 +0000)
This change added skeleton implementation of Bluetooth Activity
Attribution (BTAA) into the Bluetooth stack.

Tag: #feature
Bug: 170315554
Test: verified locally BTAA module get initialized

Change-Id: Iab3b976370e4d1866e9a308d4e6f9a11cdff037c

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

diff --git a/btaa/Android.bp b/btaa/Android.bp
new file mode 100755 (executable)
index 0000000..2a27c79
--- /dev/null
@@ -0,0 +1,16 @@
+// libbtaa static library for target
+// ========================================================
+cc_library_static {
+    name: "libbtaa",
+    defaults: ["fluoride_defaults"],
+    local_include_dirs: [
+        "include",
+    ],
+    srcs: [
+        "src/activity_attribution.cc",
+    ],
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.bluetooth.updatable",
+    ],
+}
diff --git a/btaa/include/activity_attribution.h b/btaa/include/activity_attribution.h
new file mode 100644 (file)
index 0000000..377d24b
--- /dev/null
@@ -0,0 +1,34 @@
+/******************************************************************************
+ *
+ *  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.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <hardware/bt_activity_attribution.h>
+
+namespace bluetooth {
+namespace activity_attribution {
+class ActivityAttribution {
+ public:
+  virtual ~ActivityAttribution() = default;
+
+  static void CleanUp();
+  static void Initialize(ActivityAttributionCallbacks* callbacks);
+};
+
+}  // namespace activity_attribution
+}  // namespace bluetooth
diff --git a/btaa/src/activity_attribution.cc b/btaa/src/activity_attribution.cc
new file mode 100644 (file)
index 0000000..2f8a2b0
--- /dev/null
@@ -0,0 +1,53 @@
+/******************************************************************************
+ *
+ *  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 "activity_attribution.h"
+
+#include <base/logging.h>
+
+namespace bluetooth {
+namespace activity_attribution {
+
+class ActivityAttributionImpl;
+static std::unique_ptr<ActivityAttributionImpl> instance;
+
+class ActivityAttributionImpl : public ActivityAttribution {
+ public:
+  ~ActivityAttributionImpl() override = default;
+  ActivityAttributionImpl(ActivityAttributionCallbacks* callbacks);
+
+ private:
+  [[maybe_unused]] ActivityAttributionCallbacks* mCallbacks;
+};
+
+ActivityAttributionImpl::ActivityAttributionImpl(
+    ActivityAttributionCallbacks* callbacks)
+    : mCallbacks(callbacks) {}
+
+void ActivityAttribution::CleanUp() { instance.reset(); };
+
+void ActivityAttribution::Initialize(ActivityAttributionCallbacks* callbacks) {
+  if (instance) {
+    LOG(ERROR) << __func__ << " Already initialized!";
+    return;
+  }
+  instance.reset(new ActivityAttributionImpl(callbacks));
+}
+
+}  // namespace activity_attribution
+}  // namespace bluetooth
index 4975a54..68b38b7 100755 (executable)
@@ -109,9 +109,10 @@ cc_library_static {
     ],
     whole_static_libs: [
         "avrcp-target-service",
-        "libaudio-a2dp-hw-utils",
         "lib-bt-packets",
+        "libaudio-a2dp-hw-utils",
         "libbt-audio-hal-interface",
+        "libbtaa",
     ],
     cflags: [
         "-DBUILDCFG",
index a618ae6..21a12a4 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <hardware/bt_activity_attribution.h>
 
+#include "btaa/include/activity_attribution.h"
 #include "btif/include/btif_common.h"
 #include "stack/include/btu.h"
 
@@ -37,6 +38,7 @@ class ActivityAttributionInterfaceImpl : public ActivityAttributionCallbacks,
 
   void Init(ActivityAttributionCallbacks* callbacks) override {
     this->callbacks = callbacks;
+    ActivityAttribution::Initialize(this);
   }
 
   void OnWakeup(Activity activity, const RawAddress& address) override {
@@ -46,7 +48,9 @@ class ActivityAttributionInterfaceImpl : public ActivityAttributionCallbacks,
                                      Unretained(callbacks), activity, address));
   }
 
-  void Cleanup(void) override {}
+  void Cleanup(void) override {
+    do_in_main_thread(FROM_HERE, Bind(&ActivityAttribution::CleanUp));
+  }
 
  private:
   ActivityAttributionCallbacks* callbacks;