1 // 2 // Copyright (C) 2015 Google, Inc. 3 // 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: 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 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. 15 // 16 17 #pragma once 18 19 #include <string> 20 #include <vector> 21 22 #include <base/macros.h> 23 #include <binder/IBinder.h> 24 #include <binder/IInterface.h> 25 26 #include <bluetooth/binder/IBluetoothCallback.h> 27 #include <bluetooth/binder/IBluetoothGattClient.h> 28 #include <bluetooth/binder/IBluetoothGattServer.h> 29 #include <bluetooth/binder/IBluetoothLowEnergy.h> 30 #include <bluetooth/uuid.h> 31 32 namespace ipc { 33 namespace binder { 34 35 // This class defines the Binder IPC interface for accessing the Bluetooth 36 // service. This class was written based on the corresponding AIDL file at 37 // /frameworks/base/core/java/android/bluetooth/IBluetooth.aidl. 38 // 39 // NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this 40 // won't be compatible with the Android framework. 41 class IBluetooth : public android::IInterface { 42 public: 43 DECLARE_META_INTERFACE(Bluetooth); 44 45 static const char kServiceName[]; 46 47 // Transaction codes for interface methods. 48 enum { 49 IS_ENABLED_TRANSACTION = android::IBinder::FIRST_CALL_TRANSACTION, 50 GET_STATE_TRANSACTION, 51 ENABLE_TRANSACTION, 52 ENABLE_NO_AUTO_CONNECT_TRANSACTION, 53 DISABLE_TRANSACTION, 54 55 GET_ADDRESS_TRANSACTION, 56 GET_UUIDS_TRANSACTION, // TODO(armansito): Support this 57 SET_NAME_TRANSACTION, 58 GET_NAME_TRANSACTION, 59 60 // TODO(armansito): Support the functions below. 61 62 GET_SCAN_MODE_TRANSACTION, 63 SET_SCAN_MODE_TRANSACTION, 64 65 GET_DISCOVERABLE_TIMEOUT_TRANSACTION, 66 SET_DISCOVERABLE_TIMEOUT_TRANSACTION, 67 68 START_DISCOVERY_TRANSACTION, 69 CANCEL_DISCOVERY_TRANSACTION, 70 IS_DISCOVERING_TRANSACTION, 71 72 GET_ADAPTER_CONNECTION_STATE_TRANSACTION, 73 GET_PROFILE_CONNECTION_STATE_TRANSACTION, 74 75 GET_BONDED_DEVICES_TRANSACTION, 76 CREATE_BOND_TRANSACTION, 77 CANCEL_BOND_PROCESS_TRANSACTION, 78 REMOVE_BOND_TRANSACTION, 79 GET_BOND_STATE_TRANSACTION, 80 GET_CONNECTION_STATE_TRANSACTION, 81 82 GET_REMOTE_NAME_TRANSACTION, 83 GET_REMOTE_TYPE_TRANSACTION, 84 GET_REMOTE_ALIAS_TRANSACTION, 85 SET_REMOTE_ALIAS_TRANSACTION, 86 GET_REMOTE_CLASS_TRANSACTION, 87 GET_REMOTE_UUIDS_TRANSACTION, 88 FETCH_REMOTE_UUIDS_TRANSACTION, 89 SDP_SEARCH_TRANSACTION, 90 91 SET_PIN_TRANSACTION, 92 SET_PASSKEY_TRANSACTION, 93 SET_PAIRING_CONFIRMATION_TRANSACTION, 94 95 GET_PHONEBOOK_ACCESS_PERMISSION_TRANSACTION, 96 SET_PHONEBOOK_ACCESS_PERMISSION_TRANSACTION, 97 GET_MESSAGE_ACCESS_PERMISSION_TRANSACTION, 98 SET_MESSAGE_ACCESS_PERMISSION_TRANSACTION, 99 GET_SIM_ACCESS_PERMISSION_TRANSACTION, 100 SET_SIM_ACCESS_PERMISSION_TRANSACTION, 101 102 SEND_CONNECTION_STATE_CHANGE_TRANSACTION, 103 104 REGISTER_CALLBACK_TRANSACTION, 105 UNREGISTER_CALLBACK_TRANSACTION, 106 107 CONNECT_SOCKET_TRANSACTION, 108 CREATE_SOCKET_CHANNEL_TRANSACTION, 109 110 CONFIG_HCI_SNOOP_LOG, 111 FACTORY_RESET_TRANSACTION, 112 113 IS_MULTI_ADVERTISEMENT_SUPPORTED_TRANSACTION, 114 IS_PERIPHERAL_MODE_SUPPORTED_TRANSACTION, 115 IS_OFFLOADED_FILTERING_SUPPORTED_TRANSACTION, 116 IS_OFFLOADED_SCAN_BATCHING_SUPPORTED_TRANSACTION, 117 IS_ACTIVITY_AND_ENERGY_REPORTING_SUPPORTED_TRANSACTION, 118 GET_ACTIVITY_ENERGY_INFO_FROM_CONTROLLER_TRANSACTION, 119 REPORT_ACTIVITY_INFO_TRANSACTION, 120 121 ON_LE_SERVICE_UP_TRANSACTION, 122 ON_BR_EDR_DOWN_TRANSACTION, 123 124 GET_LOW_ENERGY_INTERFACE_TRANSACTION, 125 GET_GATT_CLIENT_INTERFACE_TRANSACTION, 126 GET_GATT_SERVER_INTERFACE_TRANSACTION, 127 }; 128 129 // Returns a handle to the IBluetooth Binder from the Android ServiceManager. 130 // Binder client code can use this to make calls to the service. 131 static android::sp<IBluetooth> getClientInterface(); 132 133 // Methods declared in IBluetooth.aidl. 134 135 virtual bool IsEnabled() = 0; 136 virtual int GetState() = 0; 137 virtual bool Enable(bool start_restricted) = 0; 138 virtual bool EnableNoAutoConnect() = 0; 139 virtual bool Disable() = 0; 140 141 virtual std::string GetAddress() = 0; 142 virtual std::vector<bluetooth::UUID> GetUUIDs() = 0; 143 virtual bool SetName(const std::string& name) = 0; 144 virtual std::string GetName() = 0; 145 146 virtual void RegisterCallback( 147 const android::sp<IBluetoothCallback>& callback) = 0; 148 virtual void UnregisterCallback( 149 const android::sp<IBluetoothCallback>& callback) = 0; 150 151 virtual bool IsMultiAdvertisementSupported() = 0; 152 153 virtual android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() = 0; 154 virtual android::sp<IBluetoothGattClient> GetGattClientInterface() = 0; 155 virtual android::sp<IBluetoothGattServer> GetGattServerInterface() = 0; 156 157 private: 158 DISALLOW_COPY_AND_ASSIGN(IBluetooth); 159 }; 160 161 // The Binder server interface to IBluetooth. A class that implements IBluetooth 162 // must inherit from this class. 163 class BnBluetooth : public android::BnInterface<IBluetooth> { 164 public: 165 BnBluetooth() = default; 166 virtual ~BnBluetooth() = default; 167 168 private: 169 virtual android::status_t onTransact( 170 uint32_t code, 171 const android::Parcel& data, 172 android::Parcel* reply, 173 uint32_t flags = 0); 174 175 DISALLOW_COPY_AND_ASSIGN(BnBluetooth); 176 }; 177 178 // The Binder client interface to IBluetooth. 179 class BpBluetooth : public android::BpInterface<IBluetooth> { 180 public: 181 explicit BpBluetooth(const android::sp<android::IBinder>& impl); 182 virtual ~BpBluetooth() = default; 183 184 // IBluetooth overrides: 185 bool IsEnabled() override; 186 int GetState() override; 187 bool Enable(bool start_restricted) override; 188 bool EnableNoAutoConnect() override; 189 bool Disable() override; 190 191 std::string GetAddress() override; 192 std::vector<bluetooth::UUID> GetUUIDs() override; 193 bool SetName(const std::string& name) override; 194 std::string GetName() override; 195 196 void RegisterCallback( 197 const android::sp<IBluetoothCallback>& callback) override; 198 void UnregisterCallback( 199 const android::sp<IBluetoothCallback>& callback) override; 200 201 bool IsMultiAdvertisementSupported() override; 202 203 android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() override; 204 android::sp<IBluetoothGattClient> GetGattClientInterface() override; 205 android::sp<IBluetoothGattServer> GetGattServerInterface() override; 206 207 private: 208 DISALLOW_COPY_AND_ASSIGN(BpBluetooth); 209 }; 210 211 } // namespace binder 212 } // namespace ipc 213