Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e67533c authored by Michael Sun's avatar Michael Sun
Browse files

btaa: subscribe to SystemSuspend for wakeup notification

This change initialize the SystemSuspend client at BTAA module and have
it subscribed to wakeup notification with wakeup reasons.

Tag: #feature
Bug: 170315554
Test: verified BTAA module receives wakeup notification
Change-Id: I6749a539f9a59f1893f4159cec6b7c9f517ead9d
parent 0f17844e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -9,6 +9,10 @@ cc_library_static {
    srcs: [
        "src/activity_attribution.cc",
    ],
    shared_libs: [
        "android.system.suspend.control-ndk",
        "libbinder_ndk",
    ],
    apex_available: [
        "//apex_available:platform",
        "com.android.bluetooth.updatable",
+10 −0
Original line number Diff line number Diff line
@@ -18,8 +18,12 @@

#pragma once

#include <aidl/android/system/suspend/BnSuspendCallback.h>
#include <hardware/bt_activity_attribution.h>

using aidl::android::system::suspend::BnSuspendCallback;
using Status = ::ndk::ScopedAStatus;

namespace bluetooth {
namespace activity_attribution {
class ActivityAttribution {
@@ -30,5 +34,11 @@ class ActivityAttribution {
  static void Initialize(ActivityAttributionCallbacks* callbacks);
};

class WakeupCallback : public BnSuspendCallback {
 public:
  Status notifyWakeup(bool success,
                      const std::vector<std::string>& wakeupReasons) override;
};

}  // namespace activity_attribution
}  // namespace bluetooth
+34 −0
Original line number Diff line number Diff line
@@ -18,12 +18,19 @@

#include "activity_attribution.h"

#include <aidl/android/system/suspend/ISuspendControlService.h>
#include <android/binder_manager.h>
#include <base/logging.h>

using aidl::android::system::suspend::ISuspendCallback;
using aidl::android::system::suspend::ISuspendControlService;
using namespace ndk;

namespace bluetooth {
namespace activity_attribution {

class ActivityAttributionImpl;
static std::shared_ptr<ISuspendControlService> controlService;
static std::unique_ptr<ActivityAttributionImpl> instance;

class ActivityAttributionImpl : public ActivityAttribution {
@@ -31,6 +38,8 @@ class ActivityAttributionImpl : public ActivityAttribution {
  ~ActivityAttributionImpl() override = default;
  ActivityAttributionImpl(ActivityAttributionCallbacks* callbacks);

  void onWakeup(bool success, const std::vector<std::string>& wakeupReasons);

 private:
  [[maybe_unused]] ActivityAttributionCallbacks* mCallbacks;
};
@@ -39,14 +48,39 @@ ActivityAttributionImpl::ActivityAttributionImpl(
    ActivityAttributionCallbacks* callbacks)
    : mCallbacks(callbacks) {}

void ActivityAttributionImpl::onWakeup(
    bool success, const std::vector<std::string>& wakeupReasons) {}

Status WakeupCallback::notifyWakeup(
    bool success, const std::vector<std::string>& wakeupReasons) {
  instance->onWakeup(success, wakeupReasons);
  return Status::ok();
}

void ActivityAttribution::CleanUp() { instance.reset(); };

void ActivityAttribution::Initialize(ActivityAttributionCallbacks* callbacks) {
  bool is_registered = false;

  if (instance) {
    LOG(ERROR) << __func__ << " Already initialized!";
    return;
  }
  instance.reset(new ActivityAttributionImpl(callbacks));

  controlService = ISuspendControlService::fromBinder(
      SpAIBinder(AServiceManager_getService("suspend_control")));
  if (!controlService) {
    LOG(ERROR) << __func__ << " Fail to obtain suspend_control";
    return;
  }

  Status register_callback_status = controlService->registerCallback(
      SharedRefBase::make<WakeupCallback>(), &is_registered);
  if (!is_registered || !register_callback_status.isOk()) {
    LOG(ERROR) << __func__ << " Fail to register wakeup callback";
    return;
  }
}

}  // namespace activity_attribution
+6 −5
Original line number Diff line number Diff line
@@ -95,17 +95,18 @@ cc_library_static {
        "libmedia_headers",
    ],
    shared_libs: [
        "android.hardware.bluetooth.a2dp@1.0",
        "android.hardware.bluetooth.audio@2.0",
        "android.system.suspend.control-ndk",
        "libaaudio",
        "libcrypto",
        "libcutils",
        "libfmq",
        "libhidlbase",
        "liblog",
        "libz",
        "libtinyxml2",
        "android.hardware.bluetooth.a2dp@1.0",
        "android.hardware.bluetooth.audio@2.0",
        "libhidlbase",
        "libutils",
        "libcrypto",
        "libz",
    ],
    whole_static_libs: [
        "avrcp-target-service",
+6 −4
Original line number Diff line number Diff line
@@ -83,11 +83,14 @@ cc_library_shared {
    ],
    logtags: ["../../EventLogTags.logtags"],
    shared_libs: [
        "android.hardware.bluetooth@1.0",
        "android.hardware.bluetooth@1.1",
        "android.hardware.bluetooth.a2dp@1.0",
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth@1.0",
        "android.hardware.bluetooth@1.1",
        "android.system.suspend.control-ndk",
        "libaaudio",
        "libbinder_ndk",
        "libcrypto",
        "libcutils",
        "libdl",
        "libflatbuffers-cpp",
@@ -96,10 +99,9 @@ cc_library_shared {
        "liblog",
        "libprocessgroup",
        "libprotobuf-cpp-lite",
        "libutils",
        "libtinyxml2",
        "libutils",
        "libz",
        "libcrypto",
    ],
    static_libs: [
        "libbte",
Loading