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,int state)62 virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int 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,int state)72 virtual void OnScoStateChanged(const BluetoothRemoteDevice &device, int 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,int indValue)91 virtual void OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice &device, int indValue) 92 {} 93 94 /** 95 * @brief Destroy the HandsFreeAudioGateway Observer object. 96 * 97 * @since 6 98 */ ~HandsFreeAudioGatewayObserver()99 virtual ~HandsFreeAudioGatewayObserver() 100 {} 101 }; 102 103 /** 104 * @brief Class for HandsFree AudioGateway API. 105 * 106 * @since 6 107 */ 108 class BLUETOOTH_API HandsFreeAudioGateway { 109 public: 110 /** 111 * @brief Get the instance of HandsFreeAudioGateway object. 112 * 113 * @return Returns the pointer to the HandsFreeAudioGateway instance. 114 * @since 6 115 */ 116 static HandsFreeAudioGateway *GetProfile(); 117 118 /** 119 * @brief Get remote HF device list which are in the connected state. 120 * 121 * @return Returns the list of devices. 122 * @since 6 123 */ 124 int32_t GetConnectedDevices(std::vector<BluetoothRemoteDevice>& devices); 125 126 /** 127 * @brief Get remote HF device list which are in the specified states. 128 * 129 * @param states List of remote device states. 130 * @return Returns the list of devices. 131 * @since 6 132 */ 133 std::vector<BluetoothRemoteDevice> GetDevicesByStates(std::vector<int> states); 134 135 /** 136 * @brief Get the connection state of the specified remote HF device. 137 * 138 * @param device Remote device object. 139 * @return Returns the connection state of the remote device. 140 * @since 6 141 */ 142 int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state); 143 144 /** 145 * @brief Initiate the establishment of a service level connection to remote HF device. 146 * 147 * @param device Remote device object. 148 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 149 * @since 6 150 */ 151 int32_t Connect(const BluetoothRemoteDevice &device); 152 153 /** 154 * @brief Release the audio connection from remote HF device. 155 * 156 * @param device Remote device object. 157 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 158 * @since 6 159 */ 160 int32_t Disconnect(const BluetoothRemoteDevice &device); 161 162 /** 163 * @brief Get the Audio connection state of the specified remote HF device. 164 * 165 * @param device Remote device object. 166 * @return Returns the Audio connection state. 167 * @since 6 168 */ 169 int GetScoState(const BluetoothRemoteDevice &device) const; 170 171 /** 172 * @brief Initiate the establishment of an audio connection to remote active HF device. 173 * 174 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 175 * @since 6 176 */ 177 bool ConnectSco(); 178 179 /** 180 * @brief Release the audio connection from remote active HF device. 181 * 182 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 183 * @since 6 184 */ 185 bool DisconnectSco(); 186 187 /** 188 * @brief This function used to Update changed phone call informations. 189 * 190 * @param numActive Active call number. 191 * @param numHeld Held call number. 192 * @param callState Current call state. 193 * @param number Phone call number. 194 * @param type Type of phone call number. 195 * @param name Name of phone call number. 196 * @since 6 197 */ 198 void PhoneStateChanged( 199 int numActive, int numHeld, int callState, const std::string &number, int type, const std::string &name); 200 201 /** 202 * @brief Send response for querying standard list current calls by remote Hf device. 203 * 204 * @param index Index of the current call. 205 * @param direction Direction of the current call. 206 * @param status Status of the current call. 207 * @param mode Source Mode of the current call. 208 * @param mpty Is this call a member of a conference call. 209 * @param number Phone call number. 210 * @param type Type of phone call number. 211 * @since 6 212 */ 213 void ClccResponse(int index, int direction, int status, int mode, bool mpty, const std::string &number, int type); 214 215 /** 216 * @brief Open the voice recognition. 217 * 218 * @param device Remote device object. 219 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 220 * @since 6 221 */ 222 bool OpenVoiceRecognition(const BluetoothRemoteDevice &device); 223 224 /** 225 * @brief Close the voice recognition. 226 * 227 * @param device Remote device object. 228 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 229 * @since 6 230 */ 231 bool CloseVoiceRecognition(const BluetoothRemoteDevice &device); 232 233 /** 234 * @brief Set the active device for audio connection. 235 * 236 * @param device Remote device object. 237 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 238 * @since 6 239 */ 240 bool SetActiveDevice(const BluetoothRemoteDevice &device); 241 242 bool IntoMock(const BluetoothRemoteDevice &device, int state); 243 244 bool SendNoCarrier(const BluetoothRemoteDevice &device); 245 246 247 /** 248 * @brief Get the active device object. 249 * 250 * @param device Remote active device object. 251 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 252 * @since 6 253 */ 254 BluetoothRemoteDevice GetActiveDevice() const; 255 256 /** 257 * @brief Register HandsFree AudioGateway observer instance. 258 * 259 * @param observer HandsFree AudioGateway observer instance. 260 * @since 6 261 */ 262 void RegisterObserver(HandsFreeAudioGatewayObserver *observer); 263 264 /** 265 * @brief Deregister HandsFree AudioGateway observer instance. 266 * 267 * @param observer HandsFree AudioGateway observer instance. 268 * @since 6 269 */ 270 void DeregisterObserver(HandsFreeAudioGatewayObserver *observer); 271 272 /** 273 * @brief Get remote HF device list which are in the connected state. 274 * 275 * @return Returns the list of devices. 276 * @since 6 277 */ 278 std::vector<BluetoothRemoteDevice> GetConnectedDevices() const; 279 280 /** 281 * @brief Static HandsFree AudioGateway observer instance. 282 * 283 * @since 6 284 */ 285 static HandsFreeAudioGateway *instance_; 286 287 private: 288 HandsFreeAudioGateway(); 289 ~HandsFreeAudioGateway(); 290 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(HandsFreeAudioGateway); 291 BLUETOOTH_DECLARE_IMPL(); 292 }; 293 } // namespace Bluetooth 294 } // namespace OHOS 295 #endif // BLUETOOTH_HFP_AG_H 296