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

Commit 9e1a16e5 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6969923 from e0201301 to sc-release

Change-Id: Ic9b3e28e2a6451c1dd430026cff6e3d8dc6aef18
parents b01e6414 e0201301
Loading
Loading
Loading
Loading

btaa/Android.bp

0 → 100644
+28 −0
Original line number Diff line number Diff line
// libbtaa static library for target
// ========================================================
cc_library_static {
    name: "libbtaa",
    defaults: ["fluoride_defaults"],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/hci/include",
        "packages/modules/Bluetooth/system/stack/include",
    ],
    local_include_dirs: [
        "include",
    ],
    srcs: [
        "src/activity_attribution.cc",
    ],
    static_libs: [
        "libbt-hci",
    ],
    shared_libs: [
        "android.system.suspend.control-ndk",
        "libbinder_ndk",
    ],
    apex_available: [
        "//apex_available:platform",
        "com.android.bluetooth.updatable",
    ],
}
+52 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  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 <aidl/android/system/suspend/BnSuspendCallback.h>
#include <aidl/android/system/suspend/BnWakelockCallback.h>
#include <hardware/bt_activity_attribution.h>

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

namespace bluetooth {
namespace activity_attribution {
class ActivityAttribution {
 public:
  virtual ~ActivityAttribution() = default;

  static void CleanUp();
  static void Initialize(ActivityAttributionCallbacks* callbacks);
};

class WakelockCallback : public BnWakelockCallback {
 public:
  Status notifyAcquired(void) override;
  Status notifyReleased(void) override;
};

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

}  // namespace activity_attribution
}  // namespace bluetooth
+123 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  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 <aidl/android/system/suspend/ISuspendControlService.h>
#include <android/binder_manager.h>
#include <base/logging.h>

#include "btsnoop_mem.h"

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

namespace bluetooth {
namespace activity_attribution {

static const std::string kBtWakelockName("hal_bluetooth_lock");

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

class ActivityAttributionImpl : public ActivityAttribution {
 public:
  ~ActivityAttributionImpl() override = default;
  ActivityAttributionImpl(ActivityAttributionCallbacks* callbacks);

  static void onHciCaptured(const uint16_t type, const uint8_t* data,
                            const size_t length, const uint64_t timestamp_us);
  void onWakelockAcquired(void);
  void onWakelockReleased(void);
  void onWakeup(bool success, const std::vector<std::string>& wakeupReasons);

 private:
  [[maybe_unused]] ActivityAttributionCallbacks* mCallbacks;
};

ActivityAttributionImpl::ActivityAttributionImpl(
    ActivityAttributionCallbacks* callbacks)
    : mCallbacks(callbacks) {}

void ActivityAttributionImpl::onHciCaptured(const uint16_t type,
                                            const uint8_t* data,
                                            const size_t length,
                                            const uint64_t timestamp_us) {}

void ActivityAttributionImpl::onWakelockAcquired(void) {}

void ActivityAttributionImpl::onWakelockReleased(void) {}

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

Status WakelockCallback::notifyAcquired(void) {
  instance->onWakelockAcquired();
  return Status::ok();
}

Status WakelockCallback::notifyReleased(void) {
  instance->onWakelockReleased();
  return Status::ok();
}

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));

  activity_attribution_set_callback(instance->onHciCaptured);

  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;
  }

  register_callback_status = controlService->registerWakelockCallback(
      SharedRefBase::make<WakelockCallback>(), kBtWakelockName, &is_registered);
  if (!is_registered || !register_callback_status.isOk()) {
    LOG(ERROR) << __func__ << " Fail to register wakelock callback";
    return;
  }
}

}  // namespace activity_attribution
}  // namespace bluetooth
+7 −2
Original line number Diff line number Diff line
@@ -527,12 +527,11 @@ void bta_gattc_close(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_DATA* p_data) {
  tBTA_GATTC_RCB* p_clreg = p_clcb->p_rcb;
  tBTA_GATTC cb_data;

  VLOG(1) << __func__ << ": conn_id=" << loghex(p_clcb->bta_conn_id);

  cb_data.close.client_if = p_clcb->p_rcb->client_if;
  cb_data.close.conn_id = p_clcb->bta_conn_id;
  cb_data.close.reason = p_clcb->reason;
  cb_data.close.remote_bda = p_clcb->bda;
  cb_data.close.status = GATT_SUCCESS;

  if (p_clcb->transport == BT_TRANSPORT_BR_EDR)
    bta_sys_conn_close(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
@@ -541,8 +540,14 @@ void bta_gattc_close(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_DATA* p_data) {

  if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT) {
    GATT_Disconnect(p_data->hdr.layer_specific);
    LOG_DEBUG("Local close event client_if:%hu conn_id:%hu reason:%hu",
              cb_data.close.client_if, cb_data.close.conn_id,
              cb_data.close.reason);
  } else if (p_data->hdr.event == BTA_GATTC_INT_DISCONN_EVT) {
    cb_data.close.reason = p_data->int_conn.reason;
    LOG_DEBUG(
        "Peer close disconnect event client_if:%hu conn_id:%hu reason:%hu",
        cb_data.close.client_if, cb_data.close.conn_id, cb_data.close.reason);
  }

  if (p_cback) (*p_cback)(BTA_GATTC_CLOSE_EVT, &cb_data);
+1 −0
Original line number Diff line number Diff line
@@ -191,6 +191,7 @@ typedef struct {

typedef struct {
  uint16_t conn_id;
  tGATT_STATUS status;
  tGATT_IF client_if;
  RawAddress remote_bda;
  tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect
Loading