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

Commit 9a2b78e4 authored by Arman Uguray's avatar Arman Uguray Committed by Android Git Automerger
Browse files

am 7c8c09d5: service: Add IBluetoothGattServer stubs

* commit '7c8c09d5':
  service: Add IBluetoothGattServer stubs
parents 10f603da 7c8c09d5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -39,9 +39,12 @@ btserviceCommonSrc := \

btserviceBinderSrc := \
	ipc/binder/bluetooth_binder_server.cpp \
	ipc/binder/bluetooth_gatt_server_binder_server.cpp \
	ipc/binder/bluetooth_low_energy_binder_server.cpp \
	ipc/binder/IBluetooth.cpp \
	ipc/binder/IBluetoothCallback.cpp \
	ipc/binder/IBluetoothGattServer.cpp \
	ipc/binder/IBluetoothGattServerCallback.cpp \
	ipc/binder/IBluetoothLowEnergy.cpp \
	ipc/binder/IBluetoothLowEnergyCallback.cpp \
	ipc/binder/interface_with_clients_base.cpp \
+17 −6
Original line number Diff line number Diff line
@@ -62,10 +62,7 @@ sp<IBluetooth> IBluetooth::getClientInterface() {
// ========================================================

status_t BnBluetooth::onTransact(
    uint32_t code,
    const Parcel& data,
    Parcel* reply,
    uint32_t flags) {
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
  VLOG(2) << "IBluetooth transaction: " << code;
  if (!data.checkInterface(this))
    return android::PERMISSION_DENIED;
@@ -132,6 +129,11 @@ status_t BnBluetooth::onTransact(
      reply->writeStrongBinder(IInterface::asBinder(ble_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()));
      return android::NO_ERROR;
    }
    default:
      return BBinder::onTransact(code, data, reply, flags);
  }
@@ -261,9 +263,18 @@ sp<IBluetoothLowEnergy> BpBluetooth::GetLowEnergyInterface() {
  remote()->transact(IBluetooth::GET_LOW_ENERGY_INTERFACE_TRANSACTION,
                     data, &reply);

  sp<IBinder> ble_iface = reply.readStrongBinder();
  return interface_cast<IBluetoothLowEnergy>(reply.readStrongBinder());
}

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

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

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

  return interface_cast<IBluetoothLowEnergy>(ble_iface);
  return interface_cast<IBluetoothGattServer>(reply.readStrongBinder());
}

IMPLEMENT_META_INTERFACE(Bluetooth, IBluetooth::kServiceName);
+4 −0
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/IBluetoothGattServer.h"
#include "service/ipc/binder/IBluetoothLowEnergy.h"
#include "service/uuid.h"

@@ -121,6 +122,7 @@ class IBluetooth : public android::IInterface {
    ON_BR_EDR_DOWN_TRANSACTION,

    GET_LOW_ENERGY_INTERFACE_TRANSACTION,
    GET_GATT_SERVER_INTERFACE_TRANSACTION,
  };

  // Returns a handle to the IBluetooth Binder from the Android ServiceManager.
@@ -148,6 +150,7 @@ class IBluetooth : public android::IInterface {
  virtual bool IsMultiAdvertisementSupported() = 0;

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

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

@@ -198,6 +201,7 @@ class BpBluetooth : public android::BpInterface<IBluetooth> {
  bool IsMultiAdvertisementSupported() override;

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

 private:
  DISALLOW_COPY_AND_ASSIGN(BpBluetooth);
+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/ipc/binder/IBluetoothGattServer.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 {

// statuc
const char IBluetoothGattServer::kServiceName[] =
    "bluetooth-gatt-server-service";

// BnBluetoothGattServer (server) implementation
// ========================================================

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

  switch (code) {
  case REGISTER_SERVER_TRANSACTION: {
    sp<IBinder> callback = data.readStrongBinder();
    bool result = RegisterServer(
        interface_cast<IBluetoothGattServerCallback>(callback));
    reply->writeInt32(result);
    return android::NO_ERROR;
  }
  case UNREGISTER_SERVER_TRANSACTION: {
    int server_if = data.readInt32();
    UnregisterServer(server_if);
    return android::NO_ERROR;
  }
  case UNREGISTER_ALL_TRANSACTION: {
    UnregisterAll();
    return android::NO_ERROR;
  }
  default:
    return BBinder::onTransact(code, data, reply, flags);
  }
}

// BpBluetoothGattServer (client) implementation
// ========================================================

BpBluetoothGattServer::BpBluetoothGattServer(const sp<IBinder>& impl)
    : BpInterface<IBluetoothGattServer>(impl) {
}

bool BpBluetoothGattServer::RegisterServer(
    const sp<IBluetoothGattServerCallback>& callback) {
  Parcel data, reply;

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

  remote()->transact(IBluetoothGattServer::REGISTER_SERVER_TRANSACTION,
                     data, &reply);

  return reply.readInt32();
}

void BpBluetoothGattServer::UnregisterServer(int server_if) {
  Parcel data, reply;

  data.writeInterfaceToken(IBluetoothGattServer::getInterfaceDescriptor());
  data.writeInt32(server_if);

  remote()->transact(IBluetoothGattServer::UNREGISTER_SERVER_TRANSACTION,
                     data, &reply);
}

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

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

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

IMPLEMENT_META_INTERFACE(BluetoothGattServer,
                         IBluetoothGattServer::kServiceName);

}  // namespace binder
}  // namespace ipc
+104 −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 <base/macros.h>
#include <binder/IBinder.h>
#include <binder/IInterface.h>

#include "service/ipc/binder/IBluetoothGattServerCallback.h"

namespace ipc {
namespace binder {

// This class defines the Binder IPC interface for interacting with Bluetooth
// GATT server-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 IBluetoothGattServer : public android::IInterface {
 public:
  DECLARE_META_INTERFACE(BluetoothGattServer);

  static const char kServiceName[];

  // Transaction codes for interface methods.
  enum {
    REGISTER_SERVER_TRANSACTION = android::IBinder::FIRST_CALL_TRANSACTION,
    UNREGISTER_SERVER_TRANSACTION,
    UNREGISTER_ALL_TRANSACTION,
    BEGIN_SERVICE_DECLARATION_TRANSACTION,
    ADD_INCLUDED_SERVICE_TRANSACTION,
    ADD_CHARACTERISTIC_TRANSACTION,
    ADD_DESCRIPTOR_TRANSACTION,
    END_SERVICE_DECLARATION_TRANSACTION,
    REMOVE_SERVICE_TRANSACTION,
    CLEAR_SERVICES_TRANSACTION,
    SEND_RESPONSE_TRANSACTION,
    SEND_NOTIFICATION_TRANSACTION,
  };

  virtual bool RegisterServer(
      const android::sp<IBluetoothGattServerCallback>& callback) = 0;
  virtual void UnregisterServer(int server_if) = 0;
  virtual void UnregisterAll() = 0;

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

 private:
  DISALLOW_COPY_AND_ASSIGN(IBluetoothGattServer);
};

// The Binder server interface to IBluetoothGattServer. A class that implements
// IBluetoothGattServer must inherit from this class.
class BnBluetoothGattServer
    : public android::BnInterface<IBluetoothGattServer> {
 public:
  BnBluetoothGattServer() = default;
  virtual ~BnBluetoothGattServer() = 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(BnBluetoothGattServer);
};

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

  // IBluetoothGattServer overrides:
  bool RegisterServer(
      const android::sp<IBluetoothGattServerCallback>& callback) override;
  void UnregisterServer(int server_if) override;
  void UnregisterAll() override;

 private:
  DISALLOW_COPY_AND_ASSIGN(BpBluetoothGattServer);
};

}  // namespace binder
}  // namespace ipc
Loading