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.
22 #include <base/macros.h>
23 #include <binder/IBinder.h>
24 #include <binder/IInterface.h>
26 #include "service/ipc/binder/IBluetoothCallback.h"
27 #include "service/uuid.h"
32 // This class defines the Binder IPC interface for accessing the Bluetooth
33 // service. This class was written based on the corresponding AIDL file at
34 // /frameworks/base/core/java/android/bluetooth/IBluetooth.aidl.
36 // NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this
37 // won't be compatible with the Android framework.
38 class IBluetooth : public android::IInterface {
40 DECLARE_META_INTERFACE(Bluetooth);
42 static const char kBluetoothServiceName[];
44 // Transaction codes for interface methods.
46 IS_ENABLED_TRANSACTION = android::IBinder::FIRST_CALL_TRANSACTION,
47 GET_STATE_TRANSACTION,
49 ENABLE_NO_AUTO_CONNECT_TRANSACTION,
52 GET_ADDRESS_TRANSACTION,
53 GET_UUIDS_TRANSACTION, // TODO(armansito): Support this
57 // TODO(armansito): Support the functions below.
59 GET_SCAN_MODE_TRANSACTION,
60 SET_SCAN_MODE_TRANSACTION,
62 GET_DISCOVERABLE_TIMEOUT_TRANSACTION,
63 SET_DISCOVERABLE_TIMEOUT_TRANSACTION,
65 START_DISCOVERY_TRANSACTION,
66 CANCEL_DISCOVERY_TRANSACTION,
67 IS_DISCOVERING_TRANSACTION,
69 GET_ADAPTER_CONNECTION_STATE_TRANSACTION,
70 GET_PROFILE_CONNECTION_STATE_TRANSACTION,
72 GET_BONDED_DEVICES_TRANSACTION,
73 CREATE_BOND_TRANSACTION,
74 CANCEL_BOND_PROCESS_TRANSACTION,
75 REMOVE_BOND_TRANSACTION,
76 GET_BOND_STATE_TRANSACTION,
77 GET_CONNECTION_STATE_TRANSACTION,
79 GET_REMOTE_NAME_TRANSACTION,
80 GET_REMOTE_TYPE_TRANSACTION,
81 GET_REMOTE_ALIAS_TRANSACTION,
82 SET_REMOTE_ALIAS_TRANSACTION,
83 GET_REMOTE_CLASS_TRANSACTION,
84 GET_REMOTE_UUIDS_TRANSACTION,
85 FETCH_REMOTE_UUIDS_TRANSACTION,
86 SDP_SEARCH_TRANSACTION,
89 SET_PASSKEY_TRANSACTION,
90 SET_PAIRING_CONFIRMATION_TRANSACTION,
92 GET_PHONEBOOK_ACCESS_PERMISSION_TRANSACTION,
93 SET_PHONEBOOK_ACCESS_PERMISSION_TRANSACTION,
94 GET_MESSAGE_ACCESS_PERMISSION_TRANSACTION,
95 SET_MESSAGE_ACCESS_PERMISSION_TRANSACTION,
96 GET_SIM_ACCESS_PERMISSION_TRANSACTION,
97 SET_SIM_ACCESS_PERMISSION_TRANSACTION,
99 SEND_CONNECTION_STATE_CHANGE_TRANSACTION,
101 REGISTER_CALLBACK_TRANSACTION,
102 UNREGISTER_CALLBACK_TRANSACTION,
104 CONNECT_SOCKET_TRANSACTION,
105 CREATE_SOCKET_CHANNEL_TRANSACTION,
107 CONFIG_HCI_SNOOP_LOG,
108 FACTORY_RESET_TRANSACTION,
110 IS_MULTI_ADVERTISEMENT_SUPPORTED_TRANSACTION,
111 IS_PERIPHERAL_MODE_SUPPORTED_TRANSACTION,
112 IS_OFFLOADED_FILTERING_SUPPORTED_TRANSACTION,
113 IS_OFFLOADED_SCAN_BATCHING_SUPPORTED_TRANSACTION,
114 IS_ACTIVITY_AND_ENERGY_REPORTING_SUPPORTED_TRANSACTION,
115 GET_ACTIVITY_ENERGY_INFO_FROM_CONTROLLER_TRANSACTION,
116 REPORT_ACTIVITY_INFO_TRANSACTION,
119 ON_LE_SERVICE_UP_TRANSACTION,
120 ON_BR_EDR_DOWN_TRANSACTION,
123 // Returns a handle to the IBluetooth Binder from the Android ServiceManager.
124 // Binder client code can use this to make calls to the service.
125 static android::sp<IBluetooth> getClientInterface();
127 // Methods declared in IBluetooth.aidl.
129 virtual bool IsEnabled() = 0;
130 virtual int GetState() = 0;
131 virtual bool Enable() = 0;
132 virtual bool EnableNoAutoConnect() = 0;
133 virtual bool Disable() = 0;
135 virtual std::string GetAddress() = 0;
136 virtual std::vector<bluetooth::UUID> GetUUIDs() = 0;
137 virtual bool SetName(const std::string& name) = 0;
138 virtual std::string GetName() = 0;
140 virtual void RegisterCallback(
141 const android::sp<IBluetoothCallback>& callback) = 0;
142 virtual void UnregisterCallback(
143 const android::sp<IBluetoothCallback>& callback) = 0;
145 virtual bool IsMultiAdvertisementSupported() = 0;
147 // TODO(armansito): Complete the API definition.
150 DISALLOW_COPY_AND_ASSIGN(IBluetooth);
153 // TODO(armansito): Implement notification for when the process dies.
155 // The Binder server interface to IBluetooth. A class that implements IBluetooth
156 // must inherit from this class.
157 class BnBluetooth : public android::BnInterface<IBluetooth> {
159 BnBluetooth() = default;
160 virtual ~BnBluetooth() = default;
163 virtual android::status_t onTransact(
165 const android::Parcel& data,
166 android::Parcel* reply,
169 DISALLOW_COPY_AND_ASSIGN(BnBluetooth);
172 // The Binder client interface to IBluetooth.
173 class BpBluetooth : public android::BpInterface<IBluetooth> {
175 BpBluetooth(const android::sp<android::IBinder>& impl);
176 virtual ~BpBluetooth() = default;
178 // IBluetooth overrides:
179 bool IsEnabled() override;
180 int GetState() override;
181 bool Enable() override;
182 bool EnableNoAutoConnect() override;
183 bool Disable() override;
185 std::string GetAddress() override;
186 std::vector<bluetooth::UUID> GetUUIDs() override;
187 bool SetName(const std::string& name) override;
188 std::string GetName() override;
190 void RegisterCallback(
191 const android::sp<IBluetoothCallback>& callback) override;
192 void UnregisterCallback(
193 const android::sp<IBluetoothCallback>& callback) override;
195 bool IsMultiAdvertisementSupported() override;
198 DISALLOW_COPY_AND_ASSIGN(BpBluetooth);
201 } // namespace binder