Loading system/service/ipc/binder/IBluetooth.cpp +54 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,27 @@ android::status_t BnBluetooth::onTransact( reply->writeInt32(result); 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: return BBinder::onTransact(code, data, reply, flags); } Loading Loading @@ -148,6 +169,39 @@ bool BpBluetooth::Disable() { 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); } // namespace binder Loading system/service/ipc/binder/IBluetooth.h +20 −0 Original line number Diff line number Diff line Loading @@ -16,10 +16,15 @@ #pragma once #include <string> #include <vector> #include <base/macros.h> #include <binder/IBinder.h> #include <binder/IInterface.h> #include "service/uuid.h" namespace ipc { namespace binder { Loading @@ -39,18 +44,29 @@ class IBluetooth : public android::IInterface { ENABLE_TRANSACTION, ENABLE_NO_AUTO_CONNECT_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. // Binder client code can use this to make calls to the service. static android::sp<IBluetooth> getClientInterface(); // Methods declared in IBluetooth.aidl. virtual bool IsEnabled() = 0; virtual int GetState() = 0; virtual bool Enable() = 0; virtual bool EnableNoAutoConnect() = 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. private: DISALLOW_COPY_AND_ASSIGN(IBluetooth); Loading Loading @@ -85,6 +101,10 @@ class BpBluetooth : public android::BpInterface<IBluetooth> { bool Enable() override; bool EnableNoAutoConnect() 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: DISALLOW_COPY_AND_ASSIGN(BpBluetooth); Loading system/service/ipc/binder/bluetooth_binder_server.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -57,4 +57,24 @@ bool BluetoothBinderServer::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 system/service/ipc/binder/bluetooth_binder_server.h +8 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,13 @@ #pragma once #include <string> #include <vector> #include <base/macros.h> #include "service/ipc/binder/IBluetooth.h" #include "service/uuid.h" namespace bluetooth { class Adapter; Loading @@ -38,6 +42,10 @@ class BluetoothBinderServer : public binder::BnBluetooth { bool Enable() override; bool EnableNoAutoConnect() 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: // Weak handle on the Adapter. Loading Loading
system/service/ipc/binder/IBluetooth.cpp +54 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,27 @@ android::status_t BnBluetooth::onTransact( reply->writeInt32(result); 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: return BBinder::onTransact(code, data, reply, flags); } Loading Loading @@ -148,6 +169,39 @@ bool BpBluetooth::Disable() { 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); } // namespace binder Loading
system/service/ipc/binder/IBluetooth.h +20 −0 Original line number Diff line number Diff line Loading @@ -16,10 +16,15 @@ #pragma once #include <string> #include <vector> #include <base/macros.h> #include <binder/IBinder.h> #include <binder/IInterface.h> #include "service/uuid.h" namespace ipc { namespace binder { Loading @@ -39,18 +44,29 @@ class IBluetooth : public android::IInterface { ENABLE_TRANSACTION, ENABLE_NO_AUTO_CONNECT_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. // Binder client code can use this to make calls to the service. static android::sp<IBluetooth> getClientInterface(); // Methods declared in IBluetooth.aidl. virtual bool IsEnabled() = 0; virtual int GetState() = 0; virtual bool Enable() = 0; virtual bool EnableNoAutoConnect() = 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. private: DISALLOW_COPY_AND_ASSIGN(IBluetooth); Loading Loading @@ -85,6 +101,10 @@ class BpBluetooth : public android::BpInterface<IBluetooth> { bool Enable() override; bool EnableNoAutoConnect() 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: DISALLOW_COPY_AND_ASSIGN(BpBluetooth); Loading
system/service/ipc/binder/bluetooth_binder_server.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -57,4 +57,24 @@ bool BluetoothBinderServer::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
system/service/ipc/binder/bluetooth_binder_server.h +8 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,13 @@ #pragma once #include <string> #include <vector> #include <base/macros.h> #include "service/ipc/binder/IBluetooth.h" #include "service/uuid.h" namespace bluetooth { class Adapter; Loading @@ -38,6 +42,10 @@ class BluetoothBinderServer : public binder::BnBluetooth { bool Enable() override; bool EnableNoAutoConnect() 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: // Weak handle on the Adapter. Loading