1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup Bluetooth 18 * @{ 19 * 20 * @brief Defines adapter manager, including observer and common functions. 21 * 22 * @since 6 23 */ 24 25 /** 26 * @file interface_adapter_manager.h 27 * 28 * @brief Adapter manager interface. 29 * 30 * @since 6 31 */ 32 33 #ifndef INTERFACE_ADAPTER_MANAGER 34 #define INTERFACE_ADAPTER_MANAGER 35 36 #include <memory> 37 #include "interface_adapter_ble.h" 38 #include "interface_adapter_classic.h" 39 40 namespace OHOS { 41 namespace bluetooth { 42 /** 43 * @brief Represents adapter state change observer during enable/disable. 44 * 45 * @since 6 46 */ 47 class IAdapterStateObserver { 48 public: 49 /** 50 * @brief A destructor used to delete the <b>IAdapterStateObserver</b> instance. 51 * 52 * @since 6 53 */ 54 virtual ~IAdapterStateObserver() = default; 55 56 /** 57 * @brief IAdapterStateObserver state change function. 58 * 59 * @param transport Transport type when state change. 60 * @param state Change to the new state. 61 * @since 6 62 */ 63 virtual void OnStateChange(const BTTransport transport, const BTStateID state) = 0; 64 }; 65 66 /** 67 * @brief System state define, using to OnSystemChange()... 68 */ 69 enum class BTSystemState : int { 70 ON, 71 OFF, 72 }; 73 74 /** 75 * @brief Represents system state change observer during start/stop/factoryReset/reset. 76 * 77 * @since 6 78 */ 79 class ISystemStateObserver { 80 public: 81 /** 82 * @brief A destructor used to delete the <b>ISystemStateObserver</b> instance. 83 * 84 * @since 6 85 */ 86 virtual ~ISystemStateObserver() = default; 87 88 /** 89 * @brief OnSystemStateChange state change function. 90 * 91 * @param transport Transport type when state change. 92 * @param state Change to 93 * @since 6 94 */ 95 virtual void OnSystemStateChange(const BTSystemState state) = 0; 96 }; 97 98 /** 99 * @brief Represents interface adapter manager. 100 * 101 * @since 6 102 */ 103 class BLUETOOTH_API IAdapterManager { 104 public: 105 /** 106 * @brief A destructor used to delete the <b>IAdapterManager</b> instance. 107 * 108 * @since 6 109 */ 110 virtual ~IAdapterManager() = default; 111 112 /** 113 * @brief Get adapter manager singleton instance pointer. 114 * 115 * @return Returns the singleton instance pointer. 116 * @since 6 117 */ 118 static IAdapterManager *GetInstance(); 119 120 /** 121 * @brief Reset bluetooth service. 122 * 123 * @return Returns <b>true</b> if the operation is successful; 124 * returns <b>false</b> if the operation fails. 125 * @since 6 126 */ 127 virtual void Reset() const = 0; 128 129 /** 130 * @brief Start bluetooth service. 131 * 132 * @return Returns <b>true</b> if the operation is successful; 133 * returns <b>false</b> if the operation fails. 134 * @since 6 135 */ 136 virtual bool Start() = 0; 137 138 /** 139 * @brief Stop bluetooth service. 140 * 141 * @since 6 142 */ 143 virtual void Stop() const = 0; 144 145 /** 146 * @brief Factory reset bluetooth service. 147 * 148 * @return Returns <b>true</b> if the operation is successful; 149 * returns <b>false</b> if the operation fails. 150 * @since 6 151 */ 152 virtual bool FactoryReset() const = 0; 153 154 /** 155 * @brief Enable bluetooth service. 156 * 157 * @param transport Enable classic or ble. 158 * @return Returns <b>true</b> if the operation is accepted; 159 * returns <b>false</b> if the operation is rejected. 160 * @since 6 161 */ 162 virtual bool Enable(const BTTransport transport) const = 0; 163 164 /** 165 * @brief Disable bluetooth service. 166 * 167 * @param transport Disable classic or ble. 168 * @return Returns <b>true</b> if the operation is accepted; 169 * returns <b>false</b> if the operation is rejected. 170 * @since 6 171 */ 172 virtual bool Disable(const BTTransport transport) const = 0; 173 174 /** 175 * @brief Get adapter enable/disable state. 176 * 177 * @param transport Disable classic or ble. 178 * @return Returns adapter enable/disable state. 179 * @since 6 180 */ 181 virtual BTStateID GetState(const BTTransport transport) const = 0; 182 183 /** 184 * @brief Get adapter connects state. 185 * 186 * @return Returns adapter connects state. 187 * @since 6 188 */ 189 virtual BTConnectState GetAdapterConnectState() const = 0; 190 191 /** 192 * @brief Register adapter state observer. 193 * 194 * @param observer Class IAdapterStateObserver pointer to register observer. 195 * @return Returns <b>true</b> if the operation is successful; 196 * returns <b>false</b> if the operation fails. 197 * @since 6 198 */ 199 virtual bool RegisterStateObserver(IAdapterStateObserver &observer) const = 0; 200 201 /** 202 * @brief Deregister adapter state observer. 203 * 204 * @param observer Class IAdapterStateObserver pointer to deregister observer. 205 * @return Returns <b>true</b> if the operation is successful; 206 * returns <b>false</b> if the operation fails. 207 * @since 6 208 */ 209 virtual bool DeregisterStateObserver(IAdapterStateObserver &observer) const = 0; 210 211 /** 212 * @brief Register system state observer. 213 * 214 * @param observer Class ISystemStateObserver pointer to register observer. 215 * @return Returns <b>true</b> if the operation is successful; 216 * returns <b>false</b> if the operation fails. 217 * @since 6 218 */ 219 virtual bool RegisterSystemStateObserver(ISystemStateObserver &observer) const = 0; 220 221 /** 222 * @brief Deregister system state observer. 223 * 224 * @param observer Class ISystemStateObserver pointer to deregister observer. 225 * @return Returns <b>true</b> if the operation is successful; 226 * returns <b>false</b> if the operation fails. 227 * @since 6 228 */ 229 virtual bool DeregisterSystemStateObserver(ISystemStateObserver &observer) const = 0; 230 231 /** 232 * @brief Get max audio connected devices number. 233 * 234 * @return Returns max device number that audio can connect. 235 * @since 6 236 */ 237 virtual int GetMaxNumConnectedAudioDevices() const = 0; 238 239 /** 240 * @brief Set phonebook permission for device. 241 * 242 * @param address Device address which is setted permission. 243 * @param permission Permission grade. 244 * @return Returns <b>true</b> if the operation is successful; 245 * returns <b>false</b> if the operation fails. 246 * @since 6 247 */ 248 virtual bool SetPhonebookPermission(const std::string &address, BTPermissionType permission) const = 0; 249 250 /** 251 * @brief Get phonebook permission for device. 252 * 253 * @param address Device address which is setted permission. 254 * @return Returns Permission grade. 255 * @since 6 256 */ 257 virtual BTPermissionType GetPhonebookPermission(const std::string &address) const = 0; 258 259 /** 260 * @brief Set message permission for device. 261 * 262 * @param address Device address which is setted permission. 263 * @param permission Permission grade. 264 * @return Returns <b>true</b> if the operation is successful; 265 * returns <b>false</b> if the operation fails. 266 * @since 6 267 */ 268 virtual bool SetMessagePermission(const std::string &address, BTPermissionType permission) const = 0; 269 270 /** 271 * @brief Get message permission for device. 272 * 273 * @param address Device address which is setted permission. 274 * @return Returns Permission grade. 275 * @since 6 276 */ 277 virtual BTPermissionType GetMessagePermission(const std::string &address) const = 0; 278 279 /** 280 * @brief Get classic adapter. 281 * 282 * @return Returns IAdapterClassic pointer. 283 * @since 6 284 */ 285 virtual std::shared_ptr<IAdapterClassic> GetClassicAdapterInterface(void) const = 0; 286 287 /** 288 * @brief Get ble adapter. 289 * 290 * @return Returns IAdapterBle pointer. 291 * @since 6 292 */ 293 virtual std::shared_ptr<IAdapterBle> GetBleAdapterInterface(void) const = 0; 294 295 /** 296 * @brief Get power mode. 297 * 298 * @param address Device address. 299 * @return Returns power mode grade. 300 * BTPowerMode::MODE_INVALID = 0x00, 301 * BTPowerMode::MODE_ACTIVE = 0x100, 302 * BTPowerMode::MODE_SNIFF_LEVEL_LOW = 0x201, 303 * BTPowerMode::MODE_SNIFF_LEVEL_MID = 0x202, 304 * BTPowerMode::MODE_SNIFF_LEVEL_HIG = 0x203, 305 * @since 6 306 */ 307 virtual int GetPowerMode(const std::string &address) const = 0; 308 }; 309 } // namespace bluetooth 310 } // namespace OHOS 311 312 #endif // INTERFACE_ADAPTER_MANAGER