Loading system/service/common/bluetooth/binder/IBluetoothLowEnergyCallback.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,12 @@ status_t BnBluetoothLowEnergyCallback::onTransact( OnClientRegistered(status, client_if); return android::NO_ERROR; } case ON_SCAN_RESULT_TRANSACTION: { auto scan_result = CreateScanResultFromParcel(data); CHECK(scan_result.get()); OnScanResult(*scan_result); return android::NO_ERROR; } case ON_MULTI_ADVERTISE_CALLBACK_TRANSACTION: { int status = data.readInt32(); bool is_start = data.readInt32(); Loading Loading @@ -91,6 +97,20 @@ void BpBluetoothLowEnergyCallback::OnClientRegistered( IBinder::FLAG_ONEWAY); } void BpBluetoothLowEnergyCallback::OnScanResult( const bluetooth::ScanResult& scan_result) { Parcel data, reply; data.writeInterfaceToken( IBluetoothLowEnergyCallback::getInterfaceDescriptor()); WriteScanResultToParcel(scan_result, &data); remote()->transact( IBluetoothLowEnergyCallback::ON_SCAN_RESULT_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); } void BpBluetoothLowEnergyCallback::OnMultiAdvertiseCallback( int status, bool is_start, const AdvertiseSettings& settings) { Loading system/service/common/bluetooth/binder/IBluetoothLowEnergyCallback.h +3 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <bluetooth/advertise_data.h> #include <bluetooth/advertise_settings.h> #include <bluetooth/scan_result.h> namespace ipc { namespace binder { Loading Loading @@ -54,7 +55,7 @@ namespace binder { }; virtual void OnClientRegistered(int status, int client_if) = 0; virtual void OnScanResult(const bluetooth::ScanResult& scan_result) = 0; virtual void OnMultiAdvertiseCallback( int status, bool is_start, const bluetooth::AdvertiseSettings& settings) = 0; Loading Loading @@ -92,6 +93,7 @@ class BpBluetoothLowEnergyCallback // IBluetoothLowEnergyCallback overrides: void OnClientRegistered(int status, int client_if) override; void OnScanResult(const bluetooth::ScanResult& scan_result) override; void OnMultiAdvertiseCallback( int status, bool is_start, const bluetooth::AdvertiseSettings& settings) override; Loading system/service/doc/IBluetoothLowEnergyCallback.txt +7 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,13 @@ oneway interface IBluetoothLowEnergyCallback { */ void onClientRegistered(in int status, in int client_if); /** * Called to report BLE device scan results once a scan session is started for * this client using IBluetoothLowEnergy.startScan. |scan_result| contains all * the data related to the discovered BLE device. */ void onScanResult(in ScanResult scan_result); /** * Called to report the result of a call to * IBluetoothLowEnergy.startMultiAdvertising or stopMultiAdvertising. Loading system/service/ipc/binder/bluetooth_low_energy_binder_server.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -168,6 +168,22 @@ bool BluetoothLowEnergyBinderServer::StopMultiAdvertising(int client_id) { return true; } void BluetoothLowEnergyBinderServer::OnScanResult( bluetooth::LowEnergyClient* client, const bluetooth::ScanResult& result) { VLOG(2) << __func__; std::lock_guard<std::mutex> lock(*maps_lock()); int client_id = client->GetInstanceId(); auto cb = GetLECallback(client->GetInstanceId()); if (!cb.get()) { VLOG(2) << "Client was unregistered - client_id: " << client_id; return; } cb->OnScanResult(result); } android::sp<IBluetoothLowEnergyCallback> BluetoothLowEnergyBinderServer::GetLECallback(int client_id) { auto cb = GetCallback(client_id); Loading @@ -186,6 +202,9 @@ void BluetoothLowEnergyBinderServer::OnRegisterInstanceImpl( android::sp<IInterface> callback, bluetooth::BluetoothInstance* instance) { VLOG(1) << __func__ << " status: " << status; bluetooth::LowEnergyClient* le_client = static_cast<bluetooth::LowEnergyClient*>(instance); le_client->SetDelegate(this); android::sp<IBluetoothLowEnergyCallback> cb( static_cast<IBluetoothLowEnergyCallback*>(callback.get())); Loading system/service/ipc/binder/bluetooth_low_energy_binder_server.h +6 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,8 @@ namespace binder { // Implements the server side of the IBluetoothLowEnergy interface. class BluetoothLowEnergyBinderServer : public BnBluetoothLowEnergy, public InterfaceWithInstancesBase { public InterfaceWithInstancesBase, public bluetooth::LowEnergyClient::Delegate { public: explicit BluetoothLowEnergyBinderServer(bluetooth::Adapter* adapter); ~BluetoothLowEnergyBinderServer() override; Loading @@ -58,6 +59,10 @@ class BluetoothLowEnergyBinderServer const bluetooth::AdvertiseSettings& settings) override; bool StopMultiAdvertising(int client_id) override; // bluetooth::LowEnergyClient::Delegate overrides: void OnScanResult(bluetooth::LowEnergyClient* client, const bluetooth::ScanResult& result) override; private: // Returns a pointer to the IBluetoothLowEnergyCallback instance associated // with |client_id|. Returns NULL if such a callback cannot be found. Loading Loading
system/service/common/bluetooth/binder/IBluetoothLowEnergyCallback.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,12 @@ status_t BnBluetoothLowEnergyCallback::onTransact( OnClientRegistered(status, client_if); return android::NO_ERROR; } case ON_SCAN_RESULT_TRANSACTION: { auto scan_result = CreateScanResultFromParcel(data); CHECK(scan_result.get()); OnScanResult(*scan_result); return android::NO_ERROR; } case ON_MULTI_ADVERTISE_CALLBACK_TRANSACTION: { int status = data.readInt32(); bool is_start = data.readInt32(); Loading Loading @@ -91,6 +97,20 @@ void BpBluetoothLowEnergyCallback::OnClientRegistered( IBinder::FLAG_ONEWAY); } void BpBluetoothLowEnergyCallback::OnScanResult( const bluetooth::ScanResult& scan_result) { Parcel data, reply; data.writeInterfaceToken( IBluetoothLowEnergyCallback::getInterfaceDescriptor()); WriteScanResultToParcel(scan_result, &data); remote()->transact( IBluetoothLowEnergyCallback::ON_SCAN_RESULT_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); } void BpBluetoothLowEnergyCallback::OnMultiAdvertiseCallback( int status, bool is_start, const AdvertiseSettings& settings) { Loading
system/service/common/bluetooth/binder/IBluetoothLowEnergyCallback.h +3 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <bluetooth/advertise_data.h> #include <bluetooth/advertise_settings.h> #include <bluetooth/scan_result.h> namespace ipc { namespace binder { Loading Loading @@ -54,7 +55,7 @@ namespace binder { }; virtual void OnClientRegistered(int status, int client_if) = 0; virtual void OnScanResult(const bluetooth::ScanResult& scan_result) = 0; virtual void OnMultiAdvertiseCallback( int status, bool is_start, const bluetooth::AdvertiseSettings& settings) = 0; Loading Loading @@ -92,6 +93,7 @@ class BpBluetoothLowEnergyCallback // IBluetoothLowEnergyCallback overrides: void OnClientRegistered(int status, int client_if) override; void OnScanResult(const bluetooth::ScanResult& scan_result) override; void OnMultiAdvertiseCallback( int status, bool is_start, const bluetooth::AdvertiseSettings& settings) override; Loading
system/service/doc/IBluetoothLowEnergyCallback.txt +7 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,13 @@ oneway interface IBluetoothLowEnergyCallback { */ void onClientRegistered(in int status, in int client_if); /** * Called to report BLE device scan results once a scan session is started for * this client using IBluetoothLowEnergy.startScan. |scan_result| contains all * the data related to the discovered BLE device. */ void onScanResult(in ScanResult scan_result); /** * Called to report the result of a call to * IBluetoothLowEnergy.startMultiAdvertising or stopMultiAdvertising. Loading
system/service/ipc/binder/bluetooth_low_energy_binder_server.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -168,6 +168,22 @@ bool BluetoothLowEnergyBinderServer::StopMultiAdvertising(int client_id) { return true; } void BluetoothLowEnergyBinderServer::OnScanResult( bluetooth::LowEnergyClient* client, const bluetooth::ScanResult& result) { VLOG(2) << __func__; std::lock_guard<std::mutex> lock(*maps_lock()); int client_id = client->GetInstanceId(); auto cb = GetLECallback(client->GetInstanceId()); if (!cb.get()) { VLOG(2) << "Client was unregistered - client_id: " << client_id; return; } cb->OnScanResult(result); } android::sp<IBluetoothLowEnergyCallback> BluetoothLowEnergyBinderServer::GetLECallback(int client_id) { auto cb = GetCallback(client_id); Loading @@ -186,6 +202,9 @@ void BluetoothLowEnergyBinderServer::OnRegisterInstanceImpl( android::sp<IInterface> callback, bluetooth::BluetoothInstance* instance) { VLOG(1) << __func__ << " status: " << status; bluetooth::LowEnergyClient* le_client = static_cast<bluetooth::LowEnergyClient*>(instance); le_client->SetDelegate(this); android::sp<IBluetoothLowEnergyCallback> cb( static_cast<IBluetoothLowEnergyCallback*>(callback.get())); Loading
system/service/ipc/binder/bluetooth_low_energy_binder_server.h +6 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,8 @@ namespace binder { // Implements the server side of the IBluetoothLowEnergy interface. class BluetoothLowEnergyBinderServer : public BnBluetoothLowEnergy, public InterfaceWithInstancesBase { public InterfaceWithInstancesBase, public bluetooth::LowEnergyClient::Delegate { public: explicit BluetoothLowEnergyBinderServer(bluetooth::Adapter* adapter); ~BluetoothLowEnergyBinderServer() override; Loading @@ -58,6 +59,10 @@ class BluetoothLowEnergyBinderServer const bluetooth::AdvertiseSettings& settings) override; bool StopMultiAdvertising(int client_id) override; // bluetooth::LowEnergyClient::Delegate overrides: void OnScanResult(bluetooth::LowEnergyClient* client, const bluetooth::ScanResult& result) override; private: // Returns a pointer to the IBluetoothLowEnergyCallback instance associated // with |client_id|. Returns NULL if such a callback cannot be found. Loading