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 interface_profile_hfp_hf.h 28 * 29 * @brief Declares HFP HF role interface profile functions, including basic and observer functions. 30 * 31 * @since 6 32 */ 33 34 #ifndef INTERFACE_PROFILE_HFP_HF_H 35 #define INTERFACE_PROFILE_HFP_HF_H 36 37 #include "interface_profile.h" 38 #include "hands_free_unit_calls.h" 39 #include <optional> 40 #include <vector> 41 42 namespace OHOS { 43 namespace bluetooth { 44 /** 45 * @brief Class for HfpHfServiceObserver functions. 46 * 47 * @since 6 48 */ 49 class HfpHfServiceObserver { 50 public: 51 /** 52 * @brief Destroy the HfpHfServiceObserver object as default. 53 * 54 * @since 6 55 */ 56 virtual ~HfpHfServiceObserver() = default; 57 58 /** 59 * @brief The observer function to notify connection state changed. 60 * 61 * @param device Remote device object. 62 * @param state Connection state. 63 * @since 6 64 */ OnConnectionStateChanged(const RawAddress & device,int state)65 virtual void OnConnectionStateChanged(const RawAddress &device, int state) 66 {} 67 68 /** 69 * @brief The observer function to notify audio connection state changed. 70 * 71 * @param device Remote device object. 72 * @param state Connection state. 73 * @since 6 74 */ OnScoStateChanged(const RawAddress & device,int state)75 virtual void OnScoStateChanged(const RawAddress &device, int state) 76 {} 77 78 /** 79 * @brief The observer function to notify call object changed. 80 * 81 * @param device Remote device object. 82 * @param call Call object. 83 * @since 6 84 */ OnCallChanged(const RawAddress & device,const HandsFreeUnitCalls & call)85 virtual void OnCallChanged(const RawAddress &device, const HandsFreeUnitCalls &call) 86 {} 87 88 /** 89 * @brief The observer function to notify battery level changed. 90 * 91 * @param device Remote device object. 92 * @param batteryLevel Battery level. 93 * @since 6 94 */ OnBatteryLevelChanged(const RawAddress & device,int batteryLevel)95 virtual void OnBatteryLevelChanged(const RawAddress &device, int batteryLevel) 96 {} 97 98 /** 99 * @brief The observer function to notify signal strength changed. 100 * 101 * @param device Remote device object. 102 * @param batteryLevel Signal strength. 103 * @since 6 104 */ OnSignalStrengthChanged(const RawAddress & device,int signal)105 virtual void OnSignalStrengthChanged(const RawAddress &device, int signal) 106 {} 107 108 /** 109 * @brief The observer function to notify registration status changed. 110 * 111 * @param device Remote device object. 112 * @param status Registration status. 113 * @since 6 114 */ OnRegistrationStatusChanged(const RawAddress & device,int status)115 virtual void OnRegistrationStatusChanged(const RawAddress &device, int status) 116 {} 117 118 /** 119 * @brief The observer function to notify roaming status changed. 120 * 121 * @param device Remote device object. 122 * @param status Roaming status. 123 * @since 6 124 */ OnRoamingStatusChanged(const RawAddress & device,int status)125 virtual void OnRoamingStatusChanged(const RawAddress &device, int status) 126 {} 127 128 /** 129 * @brief The observer function to notify operator selection name changed. 130 * 131 * @param device Remote device object. 132 * @param name Operator selection name. 133 * @since 6 134 */ OnOperatorSelectionChanged(const RawAddress & device,const std::string & name)135 virtual void OnOperatorSelectionChanged(const RawAddress &device, const std::string &name) 136 {} 137 138 /** 139 * @brief The observer function to notify subscriber number changed. 140 * 141 * @param device Remote device object. 142 * @param number Subscriber number. 143 * @since 6 144 */ OnSubscriberNumberChanged(const RawAddress & device,const std::string & number)145 virtual void OnSubscriberNumberChanged(const RawAddress &device, const std::string &number) 146 {} 147 148 /** 149 * @brief The observer function to notify voice recognition status changed. 150 * 151 * @param device Remote device object. 152 * @param status Voice recognition status. 153 * @since 6 154 */ OnVoiceRecognitionStatusChanged(const RawAddress & device,int status)155 virtual void OnVoiceRecognitionStatusChanged(const RawAddress &device, int status) 156 {} 157 158 /** 159 * @brief The observer function to notify inBand ring tone status changed. 160 * 161 * @param device Remote device object. 162 * @param status InBand ring tone status. 163 * @since 6 164 */ OnInBandRingToneChanged(const RawAddress & device,int status)165 virtual void OnInBandRingToneChanged(const RawAddress &device, int status) 166 {} 167 }; 168 169 /** 170 * @brief Class for IProfileHfpHf API. 171 * 172 * @since 6 173 */ 174 class IProfileHfpHf : public IProfile { 175 public: 176 /** 177 * @brief Destroy the IProfileHfpHf object as default. 178 * 179 * @since 6 180 */ 181 virtual ~IProfileHfpHf() = default; 182 183 /** 184 * @brief Initiate the establishment of an audio connection to remote AG device. 185 * 186 * @param device Remote device object. 187 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 188 * @since 6 189 */ 190 virtual bool ConnectSco(const RawAddress &device) = 0; 191 192 /** 193 * @brief Release the audio connection from remote HF device. 194 * 195 * @param device Remote device object. 196 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 197 * @since 6 198 */ 199 virtual bool DisconnectSco(const RawAddress &device) = 0; 200 201 /** 202 * @brief Get remote AG device list which are in the specified states. 203 * 204 * @param states List of remote device states. 205 * @return Returns the list of devices. 206 * @since 6 207 */ 208 virtual std::vector<RawAddress> GetDevicesByStates(std::vector<int> states) = 0; 209 210 /** 211 * @brief Get the connection state of the specified remote AG device. 212 * 213 * @param device Remote device object. 214 * @return Returns the connection state of the remote device. 215 * @since 6 216 */ 217 virtual int GetDeviceState(const RawAddress &device) = 0; 218 219 /** 220 * @brief Get the Audio connection state of the specified remote AG device. 221 * 222 * @param device Remote device object. 223 * @return Returns the Audio connection state. 224 * @since 6 225 */ 226 virtual int GetScoState(const RawAddress &device) = 0; 227 228 /** 229 * @brief Send DTMF tone code to remote AG device. 230 * 231 * @param device Remote device object. 232 * @param code DTMF tone code. 233 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 234 * @since 6 235 */ 236 virtual bool SendDTMFTone(const RawAddress &device, uint8_t code) = 0; 237 238 /** 239 * @brief Open voice recognition. 240 * 241 * @param device Remote device object. 242 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 243 * @since 6 244 */ 245 virtual bool OpenVoiceRecognition(const RawAddress &device) = 0; 246 247 /** 248 * @brief Close voice recognition. 249 * 250 * @param device Remote 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 virtual bool CloseVoiceRecognition(const RawAddress &device) = 0; 255 256 /** 257 * @brief Get a list of current all existing calls. 258 * 259 * @param device Remote device object. 260 * @return The list of all existing calls. 261 * @since 6 262 */ 263 virtual std::vector<HandsFreeUnitCalls> GetCurrentCallList(const RawAddress &device) = 0; 264 265 /** 266 * @brief Accept an incoming call. 267 * 268 * @param device Remote device object. 269 * @param flag Types of calls accepted. 270 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 271 * @since 6 272 */ 273 virtual bool AcceptIncomingCall(const RawAddress &device, int flag) = 0; 274 275 /** 276 * @brief Hold an active call. 277 * 278 * @param device Remote device object. 279 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 280 * @since 6 281 */ 282 virtual bool HoldActiveCall(const RawAddress &device) = 0; 283 284 /** 285 * @brief Reject an incoming call. 286 * 287 * @param device Remote device object. 288 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 289 * @since 6 290 */ 291 virtual bool RejectIncomingCall(const RawAddress &device) = 0; 292 293 /** 294 * @brief Send key pressed event. 295 * 296 * @param device Remote device object. 297 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 298 * @since 9 299 */ 300 virtual bool SendKeyPressed(const RawAddress &device) = 0; 301 302 /** 303 * @brief Handle an incoming call. 304 * 305 * @param device Remote device object. 306 * @param flag Types of calls handle. 307 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 308 * @since 9 309 */ 310 virtual bool HandleIncomingCall(const RawAddress &device, int flag) = 0; 311 312 /** 313 * @brief Handle multi call. 314 * 315 * @param device Remote device object. 316 * @param flag Types of calls handle. 317 * @param index call index 318 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 319 * @since 9 320 */ 321 virtual bool HandleMultiCall(const RawAddress &device, int flag, int index) = 0; 322 323 /** 324 * @brief Dial last number. 325 * 326 * @param device Remote device object. 327 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 328 * @since 9 329 */ 330 virtual bool DialLastNumber(const RawAddress &device) = 0; 331 332 /** 333 * @brief Dial memory number. 334 * 335 * @param device Remote device object. 336 * @param index Memory index. 337 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 338 * @since 9 339 */ 340 virtual bool DialMemory(const RawAddress &device, int index) = 0; 341 342 /** 343 * @brief Send voice tag. 344 * 345 * @param device Remote device object. 346 * @param index voice tag index. 347 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 348 * @since 9 349 */ 350 virtual bool SendVoiceTag(const RawAddress &device, int index) = 0; 351 352 /** 353 * @brief Finish a specified active call. 354 * 355 * @param device Remote device object. 356 * @param call Call object. 357 * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails. 358 * @since 6 359 */ 360 virtual bool FinishActiveCall(const RawAddress &device, const HandsFreeUnitCalls &call) = 0; 361 362 /** 363 * @brief Start dial with specified call number. 364 * 365 * @param device Remote device object. 366 * @param number Call's number to dial. 367 * @return The object of dial out call or nullopt. 368 * @since 6 369 */ 370 virtual std::optional<HandsFreeUnitCalls> StartDial(const RawAddress &device, const std::string &number) = 0; 371 372 /** 373 * @brief Register HandsFree Unit observer instance. 374 * 375 * @param observer HandsFreeUnitObserver instance. 376 * @since 6 377 */ 378 virtual void RegisterObserver(HfpHfServiceObserver &observer) = 0; 379 380 /** 381 * @brief Deregister HandsFree Unit observer instance. 382 * 383 * @param observer HandsFreeUnitObserver instance. 384 * @since 6 385 */ 386 virtual void DeregisterObserver(HfpHfServiceObserver &observer) = 0; 387 }; 388 } // namespace bluetooth 389 } // namespace OHOS 390 #endif // INTERFACE_PROFILE_HFP_HF_H