2 // Copyright (C) 2015 Google, Inc.
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at:
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
19 #include <base/macros.h>
20 #include <binder/IBinder.h>
21 #include <binder/IInterface.h>
23 #include <bluetooth/advertise_data.h>
24 #include <bluetooth/advertise_settings.h>
25 #include <bluetooth/scan_filter.h>
26 #include <bluetooth/scan_settings.h>
27 #include <bluetooth/binder/IBluetoothLowEnergyCallback.h>
32 // This class defines the Binder IPC interface for interacting with Bluetooth
33 // Low-Energy features.
34 // TODO(armansito): This class was written based on a new design doc proposal.
35 // We need to add an AIDL for this to the framework code.
37 // NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this
38 // won't be compatible with the Android framework.
39 class IBluetoothLowEnergy : public android::IInterface {
41 DECLARE_META_INTERFACE(BluetoothLowEnergy);
43 static const char kServiceName[];
45 // Transaction codes for interface methods.
47 GET_DEVICES_MATCHING_CONNECTION_STATE_TRANSACTION =
48 android::IBinder::FIRST_CALL_TRANSACTION,
50 REGISTER_CLIENT_TRANSACTION,
51 UNREGISTER_CLIENT_TRANSACTION,
52 UNREGISTER_ALL_TRANSACTION,
54 START_SCAN_TRANSACTION,
55 STOP_SCAN_TRANSACTION,
56 FLUSH_PENDING_BATCH_RESULTS_TRANSACTION,
57 START_MULTI_ADVERTISING_TRANSACTION,
58 STOP_MULTI_ADVERTISING_TRANSACTION,
61 DISCONNECT_TRANSACTION,
62 READ_REMOTE_RSSI_TRANSACTION,
63 CONFIGURE_ATT_MTU_TRANSACTION,
64 CONNECTION_PARAMETER_UPDATE_TRANSACTION,
65 DISCONNECT_ALL_TRANSACTION,
67 NUM_HW_TRACK_FILTERS_AVAILABLE,
70 virtual bool RegisterClient(
71 const android::sp<IBluetoothLowEnergyCallback>& callback) = 0;
72 virtual void UnregisterClient(int client_if) = 0;
73 virtual void UnregisterAll() = 0;
75 virtual bool Connect(int client_id, const char* address, bool is_direct) = 0;
76 virtual bool Disconnect(int client_id, const char* address) = 0;
78 virtual bool StartScan(
80 const bluetooth::ScanSettings& settings,
81 const std::vector<bluetooth::ScanFilter>& filters) = 0;
82 virtual bool StopScan(int client_id) = 0;
84 virtual bool StartMultiAdvertising(
86 const bluetooth::AdvertiseData& advertise_data,
87 const bluetooth::AdvertiseData& scan_response,
88 const bluetooth::AdvertiseSettings& settings) = 0;
89 virtual bool StopMultiAdvertising(int client_if) = 0;
91 // TODO(armansito): Complete the API definition.
94 DISALLOW_COPY_AND_ASSIGN(IBluetoothLowEnergy);
97 // The Binder server interface to IBluetoothLowEnergy. A class that implements
98 // IBluetoothLowEnergy must inherit from this class.
99 class BnBluetoothLowEnergy : public android::BnInterface<IBluetoothLowEnergy> {
101 BnBluetoothLowEnergy() = default;
102 virtual ~BnBluetoothLowEnergy() = default;
105 virtual android::status_t onTransact(
107 const android::Parcel& data,
108 android::Parcel* reply,
111 DISALLOW_COPY_AND_ASSIGN(BnBluetoothLowEnergy);
114 // The Binder client interface to IBluetoothLowEnergy.
115 class BpBluetoothLowEnergy : public android::BpInterface<IBluetoothLowEnergy> {
117 explicit BpBluetoothLowEnergy(const android::sp<android::IBinder>& impl);
118 virtual ~BpBluetoothLowEnergy() = default;
120 // IBluetoothLowEnergy overrides:
122 const android::sp<IBluetoothLowEnergyCallback>& callback) override;
123 void UnregisterClient(int client_if) override;
124 void UnregisterAll() override;
126 bool Connect(int client_id, const char* address, bool is_direct) override;
127 bool Disconnect(int client_id, const char* address) override;
131 const bluetooth::ScanSettings& settings,
132 const std::vector<bluetooth::ScanFilter>& filters) override;
133 bool StopScan(int client_id) override;
134 bool StartMultiAdvertising(
136 const bluetooth::AdvertiseData& advertise_data,
137 const bluetooth::AdvertiseData& scan_response,
138 const bluetooth::AdvertiseSettings& settings) override;
139 bool StopMultiAdvertising(int client_if) override;
142 DISALLOW_COPY_AND_ASSIGN(BpBluetoothLowEnergy);
145 } // namespace binder