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

Commit 023694f3 authored by Arman Uguray's avatar Arman Uguray
Browse files

service: Add IBluetoothLowEnergy interface

Introduce the IBluetoothLowEnergy and IBluetoothLowEnergyCallback
interfaces with stub implementations for three methods only. Added
the definition and implementation for IBluetooth.GetLowEnergyInterface.

Bug: 23395353
Change-Id: Iba4d9aa20779956b486c0b46e752e0e00be3aeea
parent 8f7688e7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -37,8 +37,11 @@ btserviceCommonSrc := \

btserviceBinderSrc := \
	ipc/binder/bluetooth_binder_server.cpp \
	ipc/binder/bluetooth_low_energy_binder_server.cpp \
	ipc/binder/IBluetooth.cpp \
	ipc/binder/IBluetoothCallback.cpp \
	ipc/binder/IBluetoothLowEnergy.cpp \
	ipc/binder/IBluetoothLowEnergyCallback.cpp \
	ipc/binder/ipc_handler_binder.cpp

btserviceCommonIncludes := $(LOCAL_PATH)/../
+23 −4
Original line number Diff line number Diff line
@@ -26,13 +26,14 @@ using android::interface_cast;
using android::IServiceManager;
using android::Parcel;
using android::sp;
using android::status_t;
using android::String16;

namespace ipc {
namespace binder {

// static
const char IBluetooth::kBluetoothServiceName[] = "bluetooth-service";
const char IBluetooth::kServiceName[] = "bluetooth-service";

// static
sp<IBluetooth> IBluetooth::getClientInterface() {
@@ -42,7 +43,7 @@ sp<IBluetooth> IBluetooth::getClientInterface() {
    return nullptr;
  }

  sp<IBinder> binder = sm->getService(String16(kBluetoothServiceName));
  sp<IBinder> binder = sm->getService(String16(kServiceName));
  if (!binder.get()) {
    LOG(ERROR) << "Failed to obtain a handle to the Bluetooth service";
    return nullptr;
@@ -60,7 +61,7 @@ sp<IBluetooth> IBluetooth::getClientInterface() {
// BnBluetooth (server) implementation
// ========================================================

android::status_t BnBluetooth::onTransact(
status_t BnBluetooth::onTransact(
    uint32_t code,
    const Parcel& data,
    Parcel* reply,
@@ -126,6 +127,11 @@ android::status_t BnBluetooth::onTransact(
      reply->writeInt32(result);
      return android::NO_ERROR;
    }
    case GET_LOW_ENERGY_INTERFACE_TRANSACTION: {
      sp<IBluetoothLowEnergy> ble_iface = GetLowEnergyInterface();
      reply->writeStrongBinder(IInterface::asBinder(ble_iface.get()));
      return android::NO_ERROR;
    }
    default:
      return BBinder::onTransact(code, data, reply, flags);
  }
@@ -247,7 +253,20 @@ bool BpBluetooth::IsMultiAdvertisementSupported() {
  return reply.readInt32();
}

IMPLEMENT_META_INTERFACE(Bluetooth, IBluetooth::kBluetoothServiceName);
sp<IBluetoothLowEnergy> BpBluetooth::GetLowEnergyInterface() {
  Parcel data, reply;

  data.writeInterfaceToken(IBluetooth::getInterfaceDescriptor());

  remote()->transact(IBluetooth::GET_LOW_ENERGY_INTERFACE_TRANSACTION,
                     data, &reply);

  sp<IBinder> ble_iface = reply.readStrongBinder();

  return interface_cast<IBluetoothLowEnergy>(ble_iface);
}

IMPLEMENT_META_INTERFACE(Bluetooth, IBluetooth::kServiceName);

}  // namespace binder
}  // namespace ipc
+9 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <binder/IInterface.h>

#include "service/ipc/binder/IBluetoothCallback.h"
#include "service/ipc/binder/IBluetoothLowEnergy.h"
#include "service/uuid.h"

namespace ipc {
@@ -39,7 +40,7 @@ class IBluetooth : public android::IInterface {
 public:
  DECLARE_META_INTERFACE(Bluetooth);

  static const char kBluetoothServiceName[];
  static const char kServiceName[];

  // Transaction codes for interface methods.
  enum {
@@ -118,6 +119,8 @@ class IBluetooth : public android::IInterface {
    DUMP_TRANSACTION,
    ON_LE_SERVICE_UP_TRANSACTION,
    ON_BR_EDR_DOWN_TRANSACTION,

    GET_LOW_ENERGY_INTERFACE_TRANSACTION,
  };

  // Returns a handle to the IBluetooth Binder from the Android ServiceManager.
@@ -144,14 +147,14 @@ class IBluetooth : public android::IInterface {

  virtual bool IsMultiAdvertisementSupported() = 0;

  virtual android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() = 0;

  // TODO(armansito): Complete the API definition.

 private:
  DISALLOW_COPY_AND_ASSIGN(IBluetooth);
};

// TODO(armansito): Implement notification for when the process dies.

// The Binder server interface to IBluetooth. A class that implements IBluetooth
// must inherit from this class.
class BnBluetooth : public android::BnInterface<IBluetooth> {
@@ -172,7 +175,7 @@ class BnBluetooth : public android::BnInterface<IBluetooth> {
// The Binder client interface to IBluetooth.
class BpBluetooth : public android::BpInterface<IBluetooth> {
 public:
  BpBluetooth(const android::sp<android::IBinder>& impl);
  explicit BpBluetooth(const android::sp<android::IBinder>& impl);
  virtual ~BpBluetooth() = default;

  // IBluetooth overrides:
@@ -194,6 +197,8 @@ class BpBluetooth : public android::BpInterface<IBluetooth> {

  bool IsMultiAdvertisementSupported() override;

  android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() override;

 private:
  DISALLOW_COPY_AND_ASSIGN(BpBluetooth);
};
+4 −4
Original line number Diff line number Diff line
@@ -22,18 +22,19 @@
using android::IBinder;
using android::Parcel;
using android::sp;
using android::status_t;

namespace ipc {
namespace binder {

// static
const char IBluetoothCallback::kBluetoothCallbackServiceName[] =
const char IBluetoothCallback::kServiceName[] =
    "bluetooth-callback-service";

// BnBluetoothCallback (server) implementation
// ========================================================

android::status_t BnBluetoothCallback::onTransact(
status_t BnBluetoothCallback::onTransact(
    uint32_t code,
    const Parcel& data,
    Parcel* reply,
@@ -79,8 +80,7 @@ void BpBluetoothCallback::OnBluetoothStateChange(
                     data, &reply);
}

IMPLEMENT_META_INTERFACE(BluetoothCallback,
                         IBluetoothCallback::kBluetoothCallbackServiceName);
IMPLEMENT_META_INTERFACE(BluetoothCallback, IBluetoothCallback::kServiceName);

}  // namespace binder
}  // namespace ipc
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ class IBluetoothCallback : public android::IInterface {
 public:
  DECLARE_META_INTERFACE(BluetoothCallback);

  static const char kBluetoothCallbackServiceName[];
  static const char kServiceName[];

  // Transaction codes for interface methods.
  enum {
Loading