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 a bluetooth system that provides basic bluetooth connection and profile functions, 21 * including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc. 22 * 23 * @since 6 24 */ 25 26 /** 27 * @file bluetooth_hfp_ag.h 28 * 29 * @brief Declares HFP AG role framework functions, including basic and observer functions. 30 * 31 * @since 6 32 */ 33 34 #ifndef BLUETOOTH_HFP_AG_H 35 #define BLUETOOTH_HFP_AG_H 36 37 #include <string> 38 #include <vector> 39 #include <memory> 40 #include <list> 41 42 #include "bluetooth_def.h" 43 #include "bluetooth_types.h" 44 #include "bluetooth_remote_device.h" 45 46 namespace OHOS { 47 namespace Bluetooth { 48 /** 49 * @brief Class for HandsFree AudioGateway observer functions. 50 * 51 * @since 6 52 */ 53 class HandsFreeAudioGatewayObserver { 54 public: 55 /** 56 * @brief The observer function to notify connection state changed. 57 * 58 * @param device Remote device object. 59 * @param state Connection state. 60 * @since 6 61 */ OnConnectionStateChanged(const BluetoothRemoteDevice & device,int32_t state)62 virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int32_t state) 63 {} 64 65 /** 66 * @brief The observer function to notify audio connection state changed. 67 * 68 * @param device Remote device object. 69 * @param state Audio connection state. 70 * @since 6 71 */ OnScoStateChanged(const BluetoothRemoteDevice & device,int32_t state)72 virtual void OnScoStateChanged(const BluetoothRemoteDevice &device, int32_t state) 73 {} 74 75 /** 76 * @brief The observer function to notify active device changed. 77 * 78 * @param device Remote active device object. 79 * @since 6 80 */ OnActiveDeviceChanged(const BluetoothRemoteDevice & device)81 virtual void OnActiveDeviceChanged(const BluetoothRemoteDevice &device) 82 {} 83 84 /** 85 * @brief The observer function to notify enhanced driver safety changed. 86 * 87 * @param device Remote device object. 88 * @param indValue Enhanced driver safety value. 89 * @since 6 90 */ OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice & device,int32_t indValue)91 virtual void OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice &device, int32_t indValue) 92 {} 93 94 /** 95 * @brief The observer function to notify audio framework the hfp stack changed. 96 * 97 * @param device Remote device object. 98 * @param action Action on the device. 99 * @since 11 100 */ OnHfpStackChanged(const BluetoothRemoteDevice & device,int32_t action)101 virtual void OnHfpStackChanged(const BluetoothRemoteDevice &device, int32_t action) 102 {} 103 104 /** 105 * @brief Destroy the HandsFreeAudioGateway Observer object. 106 * 107 * @since 6 108 */ ~HandsFreeAudioGatewayObserver()109 virtual ~HandsFreeAudioGatewayObserver() 110 {} 111 }; 112 113 /** 114 * @brief Class for HandsFree AudioGateway API. 115 * 116 * @since 6 117 */ 118 class BLUETOOTH_API HandsFreeAudioGateway { 119 public: 120 /** 121 * @brief Get the instance of HandsFreeAudioGateway object. 122 * 123 * @return Returns the pointer to the HandsFreeAudioGateway instance. 124 * @since 6 125 */ 126 static HandsFreeAudioGateway *GetProfile(); 127 128 /** 129 * @brief Get remote HF device list which are in the connected state. 130 * 131 * @return Returns the list of devices. 132 * @since 6 133 */ 134 int32_t GetConnectedDevices(std::vector<BluetoothRemoteDevice>& devices); 135 136 /** 137 * @brief Get remote HF device list which are in the specified states. 138 * 139 * @param states List of remote device states. 140 * @return Returns the list of devices. 141 * @since 6 142 */ 143 std::vector<BluetoothRemoteDevice> GetDevicesByStates(std::vector<int> states); 144 145 /** 146 * @brief Get the connection state of the specified remote HF device. 147 * 148 * @param device Remote device object. 149 * @return Returns the connection state of the remote device. 150 * @since 6 151 */ 152 int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state); 153 154 /** 155 * @brief Initiate the establishment of a service level connection to remote HF device. 156 * 157 * @param device Remote device object. 158 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 159 * @since 6 160 */ 161 int32_t Connect(const BluetoothRemoteDevice &device); 162 163 /** 164 * @brief Release the audio connection from remote HF device. 165 * 166 * @param device Remote device object. 167 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 168 * @since 6 169 */ 170 int32_t Disconnect(const BluetoothRemoteDevice &device); 171 172 /** 173 * @brief Get the Audio connection state of the specified remote HF device. 174 * 175 * @param device Remote device object. 176 * @return Returns the Audio connection state. 177 * @since 6 178 */ 179 int GetScoState(const BluetoothRemoteDevice &device) const; 180 181 /** 182 * @brief Initiate the establishment of an audio connection to remote active HF device. 183 * 184 * @param callType the type of the call, Refer to enum BtCallType 185 * @return Returns <b>0</b> if the operation is successful; returns <b>Other</b> if the operation fails. 186 * @since 10 187 */ 188 int32_t ConnectSco(uint8_t callType); 189 190 /** 191 * @brief Release the audio connection from remote active HF device. 192 * 193 * @param callType the type of the call, Refer to enum BtCallType 194 * @return Returns <b>0</b> if the operation is successful; returns <b>Other</b> if the operation fails. 195 * @since 10 196 */ 197 int32_t DisconnectSco(uint8_t callType); 198 199 /** 200 * @brief Initiate the establishment of an audio connection to remote active HF device. 201 * 202 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 203 * @since 6 204 */ 205 bool ConnectSco(); 206 207 /** 208 * @brief Release the audio connection from remote active HF device. 209 * 210 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 211 * @since 6 212 */ 213 bool DisconnectSco(); 214 215 /** 216 * @brief This function used to Update changed phone call informations. 217 * 218 * @param numActive Active call number. 219 * @param numHeld Held call number. 220 * @param callState Current call state. 221 * @param number Phone call number. 222 * @param type Type of phone call number. 223 * @param name Name of phone call number. 224 * @since 6 225 */ 226 void PhoneStateChanged( 227 int numActive, int numHeld, int callState, const std::string &number, int type, const std::string &name); 228 229 /** 230 * @brief Send response for querying standard list current calls by remote Hf device. 231 * 232 * @param index Index of the current call. 233 * @param direction Direction of the current call. 234 * @param status Status of the current call. 235 * @param mode Source Mode of the current call. 236 * @param mpty Is this call a member of a conference call. 237 * @param number Phone call number. 238 * @param type Type of phone call number. 239 * @since 6 240 */ 241 void ClccResponse(int index, int direction, int status, int mode, bool mpty, const std::string &number, int type); 242 243 /** 244 * @brief Open the voice recognition. 245 * 246 * @param device Remote device object. 247 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 248 * @since 6 249 */ 250 bool OpenVoiceRecognition(const BluetoothRemoteDevice &device); 251 252 /** 253 * @brief Close the voice recognition. 254 * 255 * @param device Remote device object. 256 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 257 * @since 6 258 */ 259 bool CloseVoiceRecognition(const BluetoothRemoteDevice &device); 260 261 /** 262 * @brief Set the active device for audio connection. 263 * 264 * @param device Remote device object. 265 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 266 * @since 6 267 */ 268 bool SetActiveDevice(const BluetoothRemoteDevice &device); 269 270 bool IntoMock(const BluetoothRemoteDevice &device, int state); 271 bool SendNoCarrier(const BluetoothRemoteDevice &device); 272 273 /** 274 * @brief Get the active device object. 275 * 276 * @param device Remote active device object. 277 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 278 * @since 6 279 */ 280 BluetoothRemoteDevice GetActiveDevice() const; 281 282 /** 283 * @brief Set connection strategy for peer bluetooth device. 284 * If peer device is connected and the policy is set not allowed,then perform disconnect operation. 285 * If peer device is disconnected and the policy is set allowed,then perform connect operation. 286 * 287 * @param device The address of the peer bluetooth device. 288 * @param strategy The device connect strategy. 289 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 290 * Returns <b>BT_ERR_PERMISSION_FAILED</b> Permission denied. 291 * Returns <b>BT_ERR_INVALID_PARAM</b> Input error. 292 * Returns <b>BT_ERR_INVALID_STATE</b> BT_ERR_INVALID_STATE. 293 * Returns <b>BT_ERR_INTERNAL_ERROR</b> Operation failed. 294 * @since 10.0 295 */ 296 int SetConnectStrategy(const BluetoothRemoteDevice &device, int strategy); 297 298 /** 299 * @brief Get connection strategy of peer bluetooth device. 300 * 301 * @param device The address of the peer bluetooth device. 302 * @param strategy The device connect strategy. 303 * @return Returns <b>RET_NO_ERROR</b> if the operation is successful. 304 * Returns <b>BT_ERR_PERMISSION_FAILED</b> Permission denied. 305 * Returns <b>BT_ERR_INVALID_PARAM</b> Input error. 306 * Returns <b>BT_ERR_INVALID_STATE</b> BT_ERR_INVALID_STATE. 307 * Returns <b>BT_ERR_INTERNAL_ERROR</b> Operation failed. 308 * @since 10.0 309 */ 310 int GetConnectStrategy(const BluetoothRemoteDevice &device, int &strategy) const; 311 312 /** 313 * @brief Register HandsFree AudioGateway observer instance. 314 * 315 * @param observer HandsFree AudioGateway observer instance. 316 * @since 6 317 */ 318 void RegisterObserver(std::shared_ptr<HandsFreeAudioGatewayObserver> observer); 319 320 /** 321 * @brief Deregister HandsFree AudioGateway observer instance. 322 * 323 * @param observer HandsFree AudioGateway observer instance. 324 * @since 6 325 */ 326 void DeregisterObserver(std::shared_ptr<HandsFreeAudioGatewayObserver> observer); 327 328 /** 329 * @brief Get remote HF device list which are in the connected state. 330 * 331 * @return Returns the list of devices. 332 * @since 6 333 */ 334 std::vector<BluetoothRemoteDevice> GetConnectedDevices() const; 335 336 /** 337 * @brief Check whether in-band-ringing is enabled 338 * 339 * @return Returns <b>true</b> if the in-band-ringing is enbale; 340 * returns <b>false</b> if the in-band-ringing is disable. 341 * @since 11 342 */ 343 int IsInbandRingingEnabled(bool &isEnabled) const; 344 345 /** 346 * @brief Static HandsFree AudioGateway observer instance. 347 * 348 * @since 6 349 */ 350 static HandsFreeAudioGateway *instance_; 351 352 /** 353 * @brief The external process calls the HfpAg profile interface before the Bluetooth process starts. At this 354 * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the 355 * HfpAg proflie. 356 */ 357 void Init(); 358 359 private: 360 HandsFreeAudioGateway(); 361 ~HandsFreeAudioGateway(); 362 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(HandsFreeAudioGateway); 363 BLUETOOTH_DECLARE_IMPL(); 364 }; 365 } // namespace Bluetooth 366 } // namespace OHOS 367 #endif // BLUETOOTH_HFP_AG_H 368