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

Commit d3f873cb authored by Arman Uguray's avatar Arman Uguray
Browse files

service: Add four more IBluetooth API definitions

Added bindings for the following IBluetooth API methods:

    String getAddress();
    ParcelUuid[] getUuids();
    boolean setName(in String name);
    String getName();

Bug: 23227962
Change-Id: Ia5f57056486bb832b2c9e7fc82837626716992ed
parent 6d443336
Loading
Loading
Loading
Loading
+54 −0
Original line number Original line Diff line number Diff line
@@ -90,6 +90,27 @@ android::status_t BnBluetooth::onTransact(
      reply->writeInt32(result);
      reply->writeInt32(result);
      return android::NO_ERROR;
      return android::NO_ERROR;
    }
    }
    case GET_ADDRESS_TRANSACTION: {
      std::string address = GetAddress();
      reply->writeCString(address.c_str());
      return android::NO_ERROR;
    }
    case GET_UUIDS_TRANSACTION:
      // TODO(armansito): Figure out how to handle a Java "ParcelUuid" natively.
      // Should we just change the code to pass strings or byte arrays?
      return android::INVALID_OPERATION;

    case SET_NAME_TRANSACTION: {
      std::string name(data.readCString());
      bool result = SetName(name);
      reply->writeInt32(result);
      return android::NO_ERROR;
    }
    case GET_NAME_TRANSACTION: {
      std::string name = GetName();
      reply->writeCString(name.c_str());
      return android::NO_ERROR;
    }
    default:
    default:
      return BBinder::onTransact(code, data, reply, flags);
      return BBinder::onTransact(code, data, reply, flags);
  }
  }
@@ -148,6 +169,39 @@ bool BpBluetooth::Disable() {
  return reply.readInt32();
  return reply.readInt32();
}
}


std::string BpBluetooth::GetAddress() {
  Parcel data, reply;

  data.writeInterfaceToken(IBluetooth::getInterfaceDescriptor());
  remote()->transact(IBluetooth::GET_ADDRESS_TRANSACTION, data, &reply);

  return reply.readCString();
}

std::vector<bluetooth::UUID> BpBluetooth::GetUUIDs() {
  // TODO(armansito): Figure out what to do here.
  return std::vector<bluetooth::UUID>();
}

bool BpBluetooth::SetName(const std::string& name) {
  Parcel data, reply;

  data.writeInterfaceToken(IBluetooth::getInterfaceDescriptor());
  data.writeCString(name.c_str());
  remote()->transact(IBluetooth::SET_NAME_TRANSACTION, data, &reply);

  return reply.readInt32();
}

std::string BpBluetooth::GetName() {
  Parcel data, reply;

  data.writeInterfaceToken(IBluetooth::getInterfaceDescriptor());
  remote()->transact(IBluetooth::GET_NAME_TRANSACTION, data, &reply);

  return reply.readCString();
}

IMPLEMENT_META_INTERFACE(Bluetooth, IBluetooth::kBluetoothServiceName);
IMPLEMENT_META_INTERFACE(Bluetooth, IBluetooth::kBluetoothServiceName);


}  // namespace binder
}  // namespace binder
+20 −0
Original line number Original line Diff line number Diff line
@@ -16,10 +16,15 @@


#pragma once
#pragma once


#include <string>
#include <vector>

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


#include "service/uuid.h"

namespace ipc {
namespace ipc {
namespace binder {
namespace binder {


@@ -39,18 +44,29 @@ class IBluetooth : public android::IInterface {
    ENABLE_TRANSACTION,
    ENABLE_TRANSACTION,
    ENABLE_NO_AUTO_CONNECT_TRANSACTION,
    ENABLE_NO_AUTO_CONNECT_TRANSACTION,
    DISABLE_TRANSACTION,
    DISABLE_TRANSACTION,
    GET_ADDRESS_TRANSACTION,
    GET_UUIDS_TRANSACTION,
    SET_NAME_TRANSACTION,
    GET_NAME_TRANSACTION,
  };
  };


  // Returns a handle to the IBluetooth Binder from the Android ServiceManager.
  // Returns a handle to the IBluetooth Binder from the Android ServiceManager.
  // Binder client code can use this to make calls to the service.
  // Binder client code can use this to make calls to the service.
  static android::sp<IBluetooth> getClientInterface();
  static android::sp<IBluetooth> getClientInterface();


  // Methods declared in IBluetooth.aidl.

  virtual bool IsEnabled() = 0;
  virtual bool IsEnabled() = 0;
  virtual int GetState() = 0;
  virtual int GetState() = 0;
  virtual bool Enable() = 0;
  virtual bool Enable() = 0;
  virtual bool EnableNoAutoConnect() = 0;
  virtual bool EnableNoAutoConnect() = 0;
  virtual bool Disable() = 0;
  virtual bool Disable() = 0;


  virtual std::string GetAddress() = 0;
  virtual std::vector<bluetooth::UUID> GetUUIDs() = 0;
  virtual bool SetName(const std::string& name) = 0;
  virtual std::string GetName() = 0;

  // TODO(armansito): Complete the API definition.
  // TODO(armansito): Complete the API definition.
 private:
 private:
  DISALLOW_COPY_AND_ASSIGN(IBluetooth);
  DISALLOW_COPY_AND_ASSIGN(IBluetooth);
@@ -85,6 +101,10 @@ class BpBluetooth : public android::BpInterface<IBluetooth> {
  bool Enable() override;
  bool Enable() override;
  bool EnableNoAutoConnect() override;
  bool EnableNoAutoConnect() override;
  bool Disable() override;
  bool Disable() override;
  std::string GetAddress() override;
  std::vector<bluetooth::UUID> GetUUIDs() override;
  bool SetName(const std::string& name) override;
  std::string GetName() override;


 private:
 private:
  DISALLOW_COPY_AND_ASSIGN(BpBluetooth);
  DISALLOW_COPY_AND_ASSIGN(BpBluetooth);
+20 −0
Original line number Original line Diff line number Diff line
@@ -57,4 +57,24 @@ bool BluetoothBinderServer::Disable() {
  return adapter_->Disable();
  return adapter_->Disable();
}
}


std::string BluetoothBinderServer::GetAddress() {
  // TODO(armansito): Implement.
  return "";
}

std::vector<bluetooth::UUID> BluetoothBinderServer::GetUUIDs() {
  // TODO(armansito): Implement.
  return std::vector<bluetooth::UUID>();
}

bool BluetoothBinderServer::SetName(const std::string& name) {
  // TODO(armansito): Implement.
  return false;
}

std::string BluetoothBinderServer::GetName() {
  // TODO(armansito): Implement.
  return "";
}

}  // namespace ipc
}  // namespace ipc
+8 −0
Original line number Original line Diff line number Diff line
@@ -16,9 +16,13 @@


#pragma once
#pragma once


#include <string>
#include <vector>

#include <base/macros.h>
#include <base/macros.h>


#include "service/ipc/binder/IBluetooth.h"
#include "service/ipc/binder/IBluetooth.h"
#include "service/uuid.h"


namespace bluetooth {
namespace bluetooth {
class Adapter;
class Adapter;
@@ -38,6 +42,10 @@ class BluetoothBinderServer : public binder::BnBluetooth {
  bool Enable() override;
  bool Enable() override;
  bool EnableNoAutoConnect() override;
  bool EnableNoAutoConnect() override;
  bool Disable() override;
  bool Disable() override;
  std::string GetAddress() override;
  std::vector<bluetooth::UUID> GetUUIDs() override;
  bool SetName(const std::string& name) override;
  std::string GetName() override;


 private:
 private:
  // Weak handle on the Adapter.
  // Weak handle on the Adapter.