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 <base/macros.h> 20 #include <binder/IBinder.h> 21 #include <binder/IInterface.h> 22 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> 28 29 namespace ipc { 30 namespace binder { 31 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. 36 // 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 { 40 public: 41 DECLARE_META_INTERFACE(BluetoothLowEnergy); 42 43 static const char kServiceName[]; 44 45 // Transaction codes for interface methods. 46 enum { 47 GET_DEVICES_MATCHING_CONNECTION_STATE_TRANSACTION = 48 android::IBinder::FIRST_CALL_TRANSACTION, 49 50 REGISTER_CLIENT_TRANSACTION, 51 UNREGISTER_CLIENT_TRANSACTION, 52 UNREGISTER_ALL_TRANSACTION, 53 54 START_SCAN_TRANSACTION, 55 STOP_SCAN_TRANSACTION, 56 FLUSH_PENDING_BATCH_RESULTS_TRANSACTION, 57 START_MULTI_ADVERTISING_TRANSACTION, 58 STOP_MULTI_ADVERTISING_TRANSACTION, 59 60 CONNECT_TRANSACTION, 61 DISCONNECT_TRANSACTION, 62 SET_MTU_TRANSACTION, 63 READ_REMOTE_RSSI_TRANSACTION, 64 CONFIGURE_ATT_MTU_TRANSACTION, 65 CONNECTION_PARAMETER_UPDATE_TRANSACTION, 66 DISCONNECT_ALL_TRANSACTION, 67 68 NUM_HW_TRACK_FILTERS_AVAILABLE, 69 }; 70 71 virtual bool RegisterClient( 72 const android::sp<IBluetoothLowEnergyCallback>& callback) = 0; 73 virtual void UnregisterClient(int client_if) = 0; 74 virtual void UnregisterAll() = 0; 75 76 virtual bool Connect(int client_id, const char* address, bool is_direct) = 0; 77 virtual bool Disconnect(int client_id, const char* address) = 0; 78 79 virtual bool SetMtu(int client_id, const char* address, int mtu) = 0; 80 81 virtual bool StartScan( 82 int client_id, 83 const bluetooth::ScanSettings& settings, 84 const std::vector<bluetooth::ScanFilter>& filters) = 0; 85 virtual bool StopScan(int client_id) = 0; 86 87 virtual bool StartMultiAdvertising( 88 int client_if, 89 const bluetooth::AdvertiseData& advertise_data, 90 const bluetooth::AdvertiseData& scan_response, 91 const bluetooth::AdvertiseSettings& settings) = 0; 92 virtual bool StopMultiAdvertising(int client_if) = 0; 93 94 // TODO(armansito): Complete the API definition. 95 96 private: 97 DISALLOW_COPY_AND_ASSIGN(IBluetoothLowEnergy); 98 }; 99 100 // The Binder server interface to IBluetoothLowEnergy. A class that implements 101 // IBluetoothLowEnergy must inherit from this class. 102 class BnBluetoothLowEnergy : public android::BnInterface<IBluetoothLowEnergy> { 103 public: 104 BnBluetoothLowEnergy() = default; 105 virtual ~BnBluetoothLowEnergy() = default; 106 107 private: 108 virtual android::status_t onTransact( 109 uint32_t code, 110 const android::Parcel& data, 111 android::Parcel* reply, 112 uint32_t flags = 0); 113 114 DISALLOW_COPY_AND_ASSIGN(BnBluetoothLowEnergy); 115 }; 116 117 // The Binder client interface to IBluetoothLowEnergy. 118 class BpBluetoothLowEnergy : public android::BpInterface<IBluetoothLowEnergy> { 119 public: 120 explicit BpBluetoothLowEnergy(const android::sp<android::IBinder>& impl); 121 virtual ~BpBluetoothLowEnergy() = default; 122 123 // IBluetoothLowEnergy overrides: 124 bool RegisterClient( 125 const android::sp<IBluetoothLowEnergyCallback>& callback) override; 126 void UnregisterClient(int client_if) override; 127 void UnregisterAll() override; 128 129 bool Connect(int client_id, const char* address, bool is_direct) override; 130 bool Disconnect(int client_id, const char* address) override; 131 132 bool SetMtu(int client_id, const char* address, int mtu) override; 133 134 bool StartScan( 135 int client_id, 136 const bluetooth::ScanSettings& settings, 137 const std::vector<bluetooth::ScanFilter>& filters) override; 138 bool StopScan(int client_id) override; 139 bool StartMultiAdvertising( 140 int client_if, 141 const bluetooth::AdvertiseData& advertise_data, 142 const bluetooth::AdvertiseData& scan_response, 143 const bluetooth::AdvertiseSettings& settings) override; 144 bool StopMultiAdvertising(int client_if) override; 145 146 private: 147 DISALLOW_COPY_AND_ASSIGN(BpBluetoothLowEnergy); 148 }; 149 150 } // namespace binder 151 } // namespace ipc 152