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

Commit 7ccb2285 authored by Chienyuan Huang's avatar Chienyuan Huang
Browse files

RAS: create client module

Bug: 329037111
Bug: 324185011
Test: m com.android.btservices
Change-Id: I9a0436c2e298604ce8296b34804b54c487525e5e
parent fc9fdc88
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ cc_library_static {
        "pan/bta_pan_api.cc",
        "pan/bta_pan_ci.cc",
        "pan/bta_pan_main.cc",
        "ras/ras_client.cc",
        "ras/ras_server.cc",
        "ras/ras_utils.cc",
        "vc/device.cc",
+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ static_library("bta") {
    "pan/bta_pan_api.cc",
    "pan/bta_pan_ci.cc",
    "pan/bta_pan_main.cc",
    "ras/ras_client.cc",
    "ras/ras_server.cc",
    "ras/ras_utils.cc",
    "rfcomm/bta_rfcomm_scn.cc",
+8 −0
Original line number Diff line number Diff line
@@ -34,5 +34,13 @@ class RasServer {

RasServer* GetRasServer();

class RasClient {
 public:
  virtual ~RasClient() = default;
  virtual void Initialize() = 0;
};

RasClient* GetRasClient();

}  // namespace ras
}  // namespace bluetooth
+68 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 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 <base/functional/bind.h>

#include "bta/include/bta_gatt_api.h"
#include "bta/include/bta_ras_api.h"
#include "bta/ras/ras_types.h"

using namespace bluetooth;
using namespace ::ras;
using namespace ::ras::uuid;

namespace {

class RasClientImpl;
RasClientImpl* instance;

class RasClientImpl : public bluetooth::ras::RasClient {
 public:
  void Initialize() override {
    BTA_GATTC_AppRegister(
        [](tBTA_GATTC_EVT event, tBTA_GATTC* p_data) {
          if (instance && p_data) instance->GattcCallback(event, p_data);
        },
        base::Bind([](uint8_t client_id, uint8_t status) {
          if (status != GATT_SUCCESS) {
            log::error("Can't start Gatt client for Ranging Service");
            return;
          }
          log::info("Initialize, client_id {}", client_id);
          instance->gatt_if_ = client_id;
        }),
        true);
  }

  void GattcCallback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) {
    log::info("event: {}", gatt_client_event_text(event));
    switch (event) {
      default:
        log::warn("Unhandled event: {}", gatt_client_event_text(event).c_str());
    }
  }

 private:
  uint16_t gatt_if_;
};

}  // namespace

bluetooth::ras::RasClient* bluetooth::ras::GetRasClient() {
  if (instance == nullptr) {
    instance = new RasClientImpl();
  }
  return instance;
};
+1 −0
Original line number Diff line number Diff line
@@ -332,6 +332,7 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface,
  module_start_up(get_local_module(RUST_MODULE));
  if (IS_FLAG_ENABLED(channel_sounding_in_stack)) {
    bluetooth::ras::GetRasServer()->Initialize();
    bluetooth::ras::GetRasClient()->Initialize();
  }

  stack_is_running = true;
Loading