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

Commit 1fbf2dd2 authored by Arman Uguray's avatar Arman Uguray Committed by Jakub Pawlowski
Browse files

service: Add LE scan result support to Binder API

Added Binder API documentation, bindings, and logic for BLE device
scan result.

Bug: 25744656
Change-Id: I5130a6b47438e266fab4a7b52b5372909824bc81
parent 530f58d0
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -55,6 +55,12 @@ status_t BnBluetoothLowEnergyCallback::onTransact(
    OnClientRegistered(status, client_if);
    return android::NO_ERROR;
  }
  case ON_SCAN_RESULT_TRANSACTION: {
    auto scan_result = CreateScanResultFromParcel(data);
    CHECK(scan_result.get());
    OnScanResult(*scan_result);
    return android::NO_ERROR;
  }
  case ON_MULTI_ADVERTISE_CALLBACK_TRANSACTION: {
    int status = data.readInt32();
    bool is_start = data.readInt32();
@@ -91,6 +97,20 @@ void BpBluetoothLowEnergyCallback::OnClientRegistered(
      IBinder::FLAG_ONEWAY);
}

void BpBluetoothLowEnergyCallback::OnScanResult(
    const bluetooth::ScanResult& scan_result) {
  Parcel data, reply;

  data.writeInterfaceToken(
      IBluetoothLowEnergyCallback::getInterfaceDescriptor());
  WriteScanResultToParcel(scan_result, &data);

  remote()->transact(
      IBluetoothLowEnergyCallback::ON_SCAN_RESULT_TRANSACTION,
      data, &reply,
      IBinder::FLAG_ONEWAY);
}

void BpBluetoothLowEnergyCallback::OnMultiAdvertiseCallback(
    int status, bool is_start,
    const AdvertiseSettings& settings) {
+3 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

#include <bluetooth/advertise_data.h>
#include <bluetooth/advertise_settings.h>
#include <bluetooth/scan_result.h>

namespace ipc {
namespace binder {
@@ -54,7 +55,7 @@ namespace binder {
  };

  virtual void OnClientRegistered(int status, int client_if) = 0;

  virtual void OnScanResult(const bluetooth::ScanResult& scan_result) = 0;
  virtual void OnMultiAdvertiseCallback(
      int status, bool is_start,
      const bluetooth::AdvertiseSettings& settings) = 0;
@@ -92,6 +93,7 @@ class BpBluetoothLowEnergyCallback

  // IBluetoothLowEnergyCallback overrides:
  void OnClientRegistered(int status, int client_if) override;
  void OnScanResult(const bluetooth::ScanResult& scan_result) override;
  void OnMultiAdvertiseCallback(
      int status, bool is_start,
      const bluetooth::AdvertiseSettings& settings) override;
+7 −0
Original line number Diff line number Diff line
@@ -28,6 +28,13 @@ oneway interface IBluetoothLowEnergyCallback {
   */
  void onClientRegistered(in int status, in int client_if);

  /**
   * Called to report BLE device scan results once a scan session is started for
   * this client using IBluetoothLowEnergy.startScan. |scan_result| contains all
   * the data related to the discovered BLE device.
   */
  void onScanResult(in ScanResult scan_result);

  /**
   * Called to report the result of a call to
   * IBluetoothLowEnergy.startMultiAdvertising or stopMultiAdvertising.
+19 −0
Original line number Diff line number Diff line
@@ -168,6 +168,22 @@ bool BluetoothLowEnergyBinderServer::StopMultiAdvertising(int client_id) {
  return true;
}

void BluetoothLowEnergyBinderServer::OnScanResult(
    bluetooth::LowEnergyClient* client,
    const bluetooth::ScanResult& result) {
  VLOG(2) << __func__;
  std::lock_guard<std::mutex> lock(*maps_lock());

  int client_id = client->GetInstanceId();
  auto cb = GetLECallback(client->GetInstanceId());
  if (!cb.get()) {
    VLOG(2) << "Client was unregistered - client_id: " << client_id;
    return;
  }

  cb->OnScanResult(result);
}

android::sp<IBluetoothLowEnergyCallback>
BluetoothLowEnergyBinderServer::GetLECallback(int client_id) {
  auto cb = GetCallback(client_id);
@@ -186,6 +202,9 @@ void BluetoothLowEnergyBinderServer::OnRegisterInstanceImpl(
    android::sp<IInterface> callback,
    bluetooth::BluetoothInstance* instance) {
  VLOG(1) << __func__ << " status: " << status;
  bluetooth::LowEnergyClient* le_client =
      static_cast<bluetooth::LowEnergyClient*>(instance);
  le_client->SetDelegate(this);

  android::sp<IBluetoothLowEnergyCallback> cb(
      static_cast<IBluetoothLowEnergyCallback*>(callback.get()));
+6 −1
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ namespace binder {
// Implements the server side of the IBluetoothLowEnergy interface.
class BluetoothLowEnergyBinderServer
    : public BnBluetoothLowEnergy,
      public InterfaceWithInstancesBase {
      public InterfaceWithInstancesBase,
      public bluetooth::LowEnergyClient::Delegate {
 public:
  explicit BluetoothLowEnergyBinderServer(bluetooth::Adapter* adapter);
  ~BluetoothLowEnergyBinderServer() override;
@@ -58,6 +59,10 @@ class BluetoothLowEnergyBinderServer
      const bluetooth::AdvertiseSettings& settings) override;
  bool StopMultiAdvertising(int client_id) override;

  // bluetooth::LowEnergyClient::Delegate overrides:
  void OnScanResult(bluetooth::LowEnergyClient* client,
                    const bluetooth::ScanResult& result) override;

 private:
  // Returns a pointer to the IBluetoothLowEnergyCallback instance associated
  // with |client_id|. Returns NULL if such a callback cannot be found.