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

Commit 660a76ed authored by Marie Janssen's avatar Marie Janssen
Browse files

service: Implement IBinder.dump()

Add dump() support to BluetoothBinderServer and change IBluetooth
implementation to allow the system to call it correctly.

Bug: 26095165
Change-Id: I32ca78e37484b5d748b8caf4c293aafcf01dfbff
parent 61f6314c
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ using android::IBinder;
using android::interface_cast;
using android::IServiceManager;
using android::Parcel;
using android::PERMISSION_DENIED;
using android::sp;
using android::status_t;
using android::String16;
@@ -64,77 +65,89 @@ sp<IBluetooth> IBluetooth::getClientInterface() {
status_t BnBluetooth::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
  VLOG(2) << "IBluetooth transaction: " << code;
  if (!data.checkInterface(this))
    return android::PERMISSION_DENIED;

  switch (code) {
    case IS_ENABLED_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      bool is_enabled = IsEnabled();
      reply->writeInt32(is_enabled);
      return android::NO_ERROR;
    }
    case GET_STATE_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      int state = GetState();
      reply->writeInt32(state);
      return android::NO_ERROR;
    }
    case ENABLE_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      bool result = Enable();
      reply->writeInt32(result);
      return android::NO_ERROR;
    }
    case DISABLE_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      bool result = Disable();
      reply->writeInt32(result);
      return android::NO_ERROR;
    }
    case GET_ADDRESS_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      std::string address = GetAddress();
      reply->writeCString(address.c_str());
      return android::NO_ERROR;
    }
    case GET_UUIDS_TRANSACTION:
      CHECK_INTERFACE(IBluetooth, data, reply);
      // TODO(armansito): Figure out how to handle a Java "ParcelUuid" natively.
      // (see http://b/23316698).
      return android::INVALID_OPERATION;

    case SET_NAME_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      std::string name(data.readCString());
      bool result = SetName(name);
      reply->writeInt32(result);
      return android::NO_ERROR;
    }
    case GET_NAME_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      std::string name = GetName();
      reply->writeCString(name.c_str());
      return android::NO_ERROR;
    }
    case REGISTER_CALLBACK_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      sp<IBinder> callback = data.readStrongBinder();
      RegisterCallback(interface_cast<IBluetoothCallback>(callback));
      return android::NO_ERROR;
    }
    case UNREGISTER_CALLBACK_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      sp<IBinder> callback = data.readStrongBinder();
      UnregisterCallback(interface_cast<IBluetoothCallback>(callback));
      return android::NO_ERROR;
    }
    case IS_MULTI_ADVERTISEMENT_SUPPORTED_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      bool result = IsMultiAdvertisementSupported();
      reply->writeInt32(result);
      return android::NO_ERROR;
    }
    case GET_LOW_ENERGY_INTERFACE_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      sp<IBluetoothLowEnergy> ble_iface = GetLowEnergyInterface();
      reply->writeStrongBinder(IInterface::asBinder(ble_iface.get()));
      return android::NO_ERROR;
    }
    case GET_GATT_CLIENT_INTERFACE_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      sp<IBluetoothGattClient> gatt_client_iface = GetGattClientInterface();
      reply->writeStrongBinder(IInterface::asBinder(gatt_client_iface.get()));
      return android::NO_ERROR;
    }
    case GET_GATT_SERVER_INTERFACE_TRANSACTION: {
      CHECK_INTERFACE(IBluetooth, data, reply);
      sp<IBluetoothGattServer> gatt_server_iface = GetGattServerInterface();
      reply->writeStrongBinder(IInterface::asBinder(gatt_server_iface.get()));
      return android::NO_ERROR;
+0 −3
Original line number Diff line number Diff line
@@ -118,7 +118,6 @@ class IBluetooth : public android::IInterface {
    GET_ACTIVITY_ENERGY_INFO_FROM_CONTROLLER_TRANSACTION,
    REPORT_ACTIVITY_INFO_TRANSACTION,

    DUMP_TRANSACTION,
    ON_LE_SERVICE_UP_TRANSACTION,
    ON_BR_EDR_DOWN_TRANSACTION,

@@ -155,8 +154,6 @@ class IBluetooth : public android::IInterface {
  virtual android::sp<IBluetoothGattClient> GetGattClientInterface() = 0;
  virtual android::sp<IBluetoothGattServer> GetGattServerInterface() = 0;

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

 private:
  DISALLOW_COPY_AND_ASSIGN(IBluetooth);
};
+16 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@
#include "service/ipc/binder/bluetooth_gatt_server_binder_server.h"
#include "service/ipc/binder/bluetooth_low_energy_binder_server.h"

#include "service/hal/bluetooth_interface.h"

using android::sp;

namespace ipc {
@@ -155,6 +157,20 @@ BluetoothBinderServer::GetGattServerInterface() {
  return gatt_server_interface_;
}

android::status_t BluetoothBinderServer::dump(int fd, const android::Vector<android::String16>& args) {
  VLOG(2) << __func__ << " called with fd " << fd;
  if  (args.size() > 0) {
    // TODO (jamuraa): Parse arguments and switch on --proto, --proto_text
    for (auto x : args) {
      VLOG(2) << __func__ << "argument: " << x.string();
    }
  }
  // TODO (jamuraa): enumerate profiles and dump profile information
  const bt_interface_t *iface = bluetooth::hal::BluetoothInterface::Get()->GetHALInterface();
  iface->dump(fd);
  return android::NO_ERROR;
}

void BluetoothBinderServer::OnAdapterStateChanged(
    bluetooth::Adapter* adapter,
    bluetooth::AdapterState prev_state,
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#include <vector>

#include <base/macros.h>
#include <utils/String16.h>
#include <utils/Vector.h>

#include "service/adapter.h"
#include "service/common/bluetooth/binder/IBluetooth.h"
@@ -62,6 +64,8 @@ class BluetoothBinderServer : public BnBluetooth,
  android::sp<IBluetoothGattClient> GetGattClientInterface() override;
  android::sp<IBluetoothGattServer> GetGattServerInterface() override;

  android::status_t dump(int fd, const android::Vector<android::String16>& args) override;

  // bluetooth::Adapter::Observer overrides:
  void OnAdapterStateChanged(bluetooth::Adapter* adapter,
                             bluetooth::AdapterState prev_state,