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

Commit e77c60bd authored by Arman Uguray's avatar Arman Uguray Committed by android-build-merger
Browse files

Merge "service: Add IBluetoothGattClient IPC bindings"

am: 40411865

* commit '40411865':
  service: Add IBluetoothGattClient IPC bindings
parents ee0ee566 40411865
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ btserviceCommonSrc := \
btserviceCommonBinderSrc := \
	common/bluetooth/binder/IBluetooth.cpp \
	common/bluetooth/binder/IBluetoothCallback.cpp \
	common/bluetooth/binder/IBluetoothGattClient.cpp \
	common/bluetooth/binder/IBluetoothGattClientCallback.cpp \
	common/bluetooth/binder/IBluetoothGattServer.cpp \
	common/bluetooth/binder/IBluetoothGattServerCallback.cpp \
	common/bluetooth/binder/IBluetoothLowEnergy.cpp \
@@ -56,6 +58,7 @@ btserviceLinuxSrc := \

btserviceBinderDaemonImplSrc := \
	ipc/binder/bluetooth_binder_server.cpp \
	ipc/binder/bluetooth_gatt_client_binder_server.cpp \
	ipc/binder/bluetooth_gatt_server_binder_server.cpp \
	ipc/binder/bluetooth_low_energy_binder_server.cpp \
	ipc/binder/interface_with_clients_base.cpp \
+16 −0
Original line number Diff line number Diff line
@@ -129,6 +129,11 @@ status_t BnBluetooth::onTransact(
      reply->writeStrongBinder(IInterface::asBinder(ble_iface.get()));
      return android::NO_ERROR;
    }
    case GET_GATT_CLIENT_INTERFACE_TRANSACTION: {
      sp<IBluetoothGattClient> gatt_client_iface = GetGattClientInterface();
      reply->writeStrongBinder(IInterface::asBinder(gatt_client_iface.get()));
      return android::NO_ERROR;
    }
    case GET_GATT_SERVER_INTERFACE_TRANSACTION: {
      sp<IBluetoothGattServer> gatt_server_iface = GetGattServerInterface();
      reply->writeStrongBinder(IInterface::asBinder(gatt_server_iface.get()));
@@ -266,6 +271,17 @@ sp<IBluetoothLowEnergy> BpBluetooth::GetLowEnergyInterface() {
  return interface_cast<IBluetoothLowEnergy>(reply.readStrongBinder());
}

sp<IBluetoothGattClient> BpBluetooth::GetGattClientInterface() {
  Parcel data, reply;

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

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

  return interface_cast<IBluetoothGattClient>(reply.readStrongBinder());
}

sp<IBluetoothGattServer> BpBluetooth::GetGattServerInterface() {
  Parcel data, reply;

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

#include <bluetooth/binder/IBluetoothCallback.h>
#include <bluetooth/binder/IBluetoothGattClient.h>
#include <bluetooth/binder/IBluetoothGattServer.h>
#include <bluetooth/binder/IBluetoothLowEnergy.h>
#include <bluetooth/uuid.h>
@@ -122,6 +123,7 @@ class IBluetooth : public android::IInterface {
    ON_BR_EDR_DOWN_TRANSACTION,

    GET_LOW_ENERGY_INTERFACE_TRANSACTION,
    GET_GATT_CLIENT_INTERFACE_TRANSACTION,
    GET_GATT_SERVER_INTERFACE_TRANSACTION,
  };

@@ -150,6 +152,7 @@ class IBluetooth : public android::IInterface {
  virtual bool IsMultiAdvertisementSupported() = 0;

  virtual android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() = 0;
  virtual android::sp<IBluetoothGattClient> GetGattClientInterface() = 0;
  virtual android::sp<IBluetoothGattServer> GetGattServerInterface() = 0;

  // TODO(armansito): Complete the API definition.
@@ -201,6 +204,7 @@ class BpBluetooth : public android::BpInterface<IBluetooth> {
  bool IsMultiAdvertisementSupported() override;

  android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() override;
  android::sp<IBluetoothGattClient> GetGattClientInterface() override;
  android::sp<IBluetoothGattServer> GetGattServerInterface() override;

 private:
+109 −0
Original line number Diff line number Diff line
//
//  Copyright (C) 2015 Google, Inc.
//
//  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 "service/common/bluetooth/binder/IBluetoothGattClient.h"

#include <base/logging.h>
#include <binder/Parcel.h>

using android::IBinder;
using android::interface_cast;
using android::Parcel;
using android::sp;
using android::status_t;

namespace ipc {
namespace binder {

// static
const char IBluetoothGattClient::kServiceName[] =
    "bluetooth-gatt-client-service";

// BnBluetoothGattClient (server) implementation
// ========================================================

status_t BnBluetoothGattClient::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
  VLOG(2) << "IBluetoothGattClient: " << code;
  if (!data.checkInterface(this))
    return android::PERMISSION_DENIED;

  switch (code) {
  case REGISTER_CLIENT_TRANSACTION: {
    sp<IBinder> callback = data.readStrongBinder();
    bool result = RegisterClient(
        interface_cast<IBluetoothGattClientCallback>(callback));
    reply->writeInt32(result);
    return android::NO_ERROR;
  }
  case UNREGISTER_CLIENT_TRANSACTION: {
    int client_id = data.readInt32();
    UnregisterClient(client_id);
    return android::NO_ERROR;
  }
  case UNREGISTER_ALL_TRANSACTION: {
    UnregisterAll();
    return android::NO_ERROR;
  }
  default:
    return BBinder::onTransact(code, data, reply, flags);
  }
}

// BpBluetoothGattClient (client) implementation
// ========================================================

BpBluetoothGattClient::BpBluetoothGattClient(const sp<IBinder>& impl)
    : BpInterface<IBluetoothGattClient>(impl) {
}

bool BpBluetoothGattClient::RegisterClient(
    const android::sp<IBluetoothGattClientCallback>& callback) {
  Parcel data, reply;

  data.writeInterfaceToken(IBluetoothGattClient::getInterfaceDescriptor());
  data.writeStrongBinder(IInterface::asBinder(callback.get()));

  remote()->transact(IBluetoothGattClient::REGISTER_CLIENT_TRANSACTION,
                     data, &reply);

  return reply.readInt32();
}

void BpBluetoothGattClient::UnregisterClient(int client_id) {
  Parcel data, reply;

  data.writeInterfaceToken(IBluetoothGattClient::getInterfaceDescriptor());
  data.writeInt32(client_id);

  remote()->transact(IBluetoothGattClient::UNREGISTER_CLIENT_TRANSACTION,
                     data, &reply);
}

void BpBluetoothGattClient::UnregisterAll() {
  Parcel data, reply;

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

  remote()->transact(IBluetoothGattClient::UNREGISTER_ALL_TRANSACTION,
                     data, &reply);
}

IMPLEMENT_META_INTERFACE(BluetoothGattClient,
                         IBluetoothGattClient::kServiceName);

}  // namespace binder
}  // namespace ipc
+108 −0
Original line number Diff line number Diff line
//
//  Copyright (C) 2015 Google, Inc.
//
//  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 <string>

#include <base/macros.h>
#include <binder/IBinder.h>
#include <binder/IInterface.h>

#include <bluetooth/binder/IBluetoothGattClientCallback.h>
#include <bluetooth/gatt_identifier.h>

namespace ipc {
namespace binder {

// This class defines the Binder IPC interface for interacting with Bluetooth
// GATT client-role features.
// TODO(armansito): This class was written based on a new design doc proposal.
// We need to add an AIDL for this to the framework code.
//
// NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this
// won't be compatible with the Android framework.
class IBluetoothGattClient : public android::IInterface {
 public:
  DECLARE_META_INTERFACE(BluetoothGattClient);

  static const char kServiceName[];

  // Transaction codes for interface methods.
  enum {
    REGISTER_CLIENT_TRANSACTION = android::IBinder::FIRST_CALL_TRANSACTION,
    UNREGISTER_CLIENT_TRANSACTION,
    UNREGISTER_ALL_TRANSACTION,
    REFRESH_DEVICE_TRANSACTION,
    DISCOVER_SERVICES_TRANSACTION,
    READ_CHARACTERISTIC_TRANSACTION,
    WRITE_CHARACTERISTIC_TRANSACTION,
    READ_DESCRIPTOR_TRANSACTION,
    WRITE_DESCRIPTOR_TRANSACTION,
    REGISTER_FOR_NOTIFICATIONS_TRANSACTION,
    UNREGISTER_FOR_NOTIFICATIONS_TRANSACTION,
    BEGIN_RELIABLE_WRITE_TRANSACTION,
    END_RELIABLE_WRITE_TRANSACTION,
  };

  virtual bool RegisterClient(
      const android::sp<IBluetoothGattClientCallback>& callback) = 0;
  virtual void UnregisterClient(int client_id) = 0;
  virtual void UnregisterAll() = 0;

  // TODO(armansito): Complete interface definition.

 private:
  DISALLOW_COPY_AND_ASSIGN(IBluetoothGattClient);
};

// The Binder server interface to IBluetoothGattClient. A class that implements
// IBluetoothGattClient must inherit from this class.
class BnBluetoothGattClient
    : public android::BnInterface<IBluetoothGattClient> {
 public:
  BnBluetoothGattClient() = default;
  virtual ~BnBluetoothGattClient() = default;

 private:
  virtual android::status_t onTransact(
      uint32_t code,
      const android::Parcel& data,
      android::Parcel* reply,
      uint32_t flags = 0);

  DISALLOW_COPY_AND_ASSIGN(BnBluetoothGattClient);
};

// The Binder client interface to IBluetoothGattClient.
class BpBluetoothGattClient
    : public android::BpInterface<IBluetoothGattClient> {
 public:
  explicit BpBluetoothGattClient(const android::sp<android::IBinder>& impl);
  virtual ~BpBluetoothGattClient() = default;

  // IBluetoothGattClient overrides:
  bool RegisterClient(
      const android::sp<IBluetoothGattClientCallback>& callback) override;
  void UnregisterClient(int client_id) override;
  void UnregisterAll() override;

 private:
  DISALLOW_COPY_AND_ASSIGN(BpBluetoothGattClient);
};

}  // namespace binder
}  // namespace ipc
Loading