1 /* 2 * Copyright (C) 2021-2022 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 #ifndef CELLULAR_CALL_CONNECTION_H 17 #define CELLULAR_CALL_CONNECTION_H 18 19 #include <mutex> 20 21 #include "call_status_callback.h" 22 #include "cellular_call_interface.h" 23 #include "i_call_status_callback.h" 24 #include "if_system_ability_manager.h" 25 #include "refbase.h" 26 #include "rwlock.h" 27 #include "singleton.h" 28 #include "system_ability_status_change_stub.h" 29 30 namespace OHOS { 31 namespace Telephony { 32 class CellularCallConnection : public std::enable_shared_from_this<CellularCallConnection> { 33 DECLARE_DELAYED_SINGLETON(CellularCallConnection) 34 35 public: 36 void Init(int32_t systemAbilityId); 37 void UnInit(); 38 39 /** 40 * Dial 41 * 42 * @brief Make a phone call 43 * @param callInfo[in], Call information. 44 * @return Returns callId when the value is greater than zero, others on failure. 45 */ 46 int Dial(const CellularCallInfo &callInfo); 47 48 /** 49 * HangUp 50 * 51 * @brief Hang up the phone 52 * @param callInfo[in], Call information. 53 * @param CallSupplementType 54 * @return Returns 0 on success, others on failure. 55 */ 56 int HangUp(const CellularCallInfo &callInfo, CallSupplementType type); 57 58 /** 59 * Reject 60 * 61 * @brief Reject a phone call 62 * @param callInfo[in], Call information. 63 * @return Returns 0 on success, others on failure. 64 */ 65 int Reject(const CellularCallInfo &callInfo); 66 67 /** 68 * Answer 69 * 70 * @brief Answer a phone call 71 * @param callInfo[in], Call information. 72 * @return Returns 0 on success, others on failure. 73 */ 74 int Answer(const CellularCallInfo &callInfo); 75 76 /** 77 * HoldCall 78 * 79 * @brief Park a phone call 80 * @param callInfo[in], Call information. 81 * @return Returns 0 on success, others on failure. 82 */ 83 int HoldCall(const CellularCallInfo &callInfo); 84 85 /** 86 * UnHoldCall 87 * 88 * @brief Activate a phone call 89 * @param callInfo[in], Call information. 90 * @return Returns 0 on success, others on failure. 91 */ 92 int UnHoldCall(const CellularCallInfo &callInfo); 93 94 /** 95 * SwitchCall 96 * 97 * @brief Switch the phone 98 * @param callInfo[in], Call information. 99 * @return Returns 0 on success, others on failure. 100 */ 101 int SwitchCall(const CellularCallInfo &callInfo); 102 103 /** 104 * IsEmergencyPhoneNumber 105 * 106 * @brief Is it an emergency call 107 * @param number[in], Phone number to be formatted 108 * @param slotId[in], The slot id 109 * @param enabled[out] true is emergency phonenumber, other is not 110 * @return Returns 0 on success, others on failure. 111 */ 112 int IsEmergencyPhoneNumber(const std::string &phoneNum, int32_t slotId, bool &enabled); 113 114 /** 115 * CombineConference 116 * 117 * @brief Merge calls to form a conference 118 * @param callInfo[in], Call information. 119 * @return Returns 0 on success, others on failure. 120 */ 121 int CombineConference(const CellularCallInfo &callInfo); 122 123 /** 124 * SeparateConference 125 * 126 * @brief Separates a specified call from a conference call 127 * @param callInfo[in], Call information. 128 * @return Returns 0 on success, others on failure. 129 */ 130 int SeparateConference(const CellularCallInfo &callInfo); 131 132 /** 133 * KickOutFromConference 134 * 135 * @brief Hangup a specified call from a conference call 136 * @param callInfo[in], Call information. 137 * @return Returns 0 on success, others on failure. 138 */ 139 int KickOutFromConference(const CellularCallInfo &callInfo); 140 141 /** 142 * StartDtmf 143 * 144 * @brief Enable and send DTMF 145 * @param cDTMFCode[in], Characters sent 146 * @param callInfo[in], Call information. 147 * @return Returns 0 on success, others on failure. 148 */ 149 int StartDtmf(char cDTMFCode, const CellularCallInfo &callInfo); 150 151 /** 152 * StopDtmf 153 * 154 * @brief Stop the DTMF 155 * @param callInfo[in], Call information. 156 * @return Returns 0 on success, others on failure. 157 */ 158 int StopDtmf(const CellularCallInfo &callInfo); 159 160 int PostDialProceed(const CellularCallInfo &callInfo, const bool proceed); 161 162 /** 163 * SendDtmf 164 * 165 * @brief Sending DTMF 166 * @param cDTMFCode[in], Characters sent 167 * @param phoneNum[in], Phone number corresponding to the call 168 * @return Returns 0 on success, others on failure. 169 */ 170 int SendDtmf(char cDTMFCode, const std::string &phoneNum); 171 172 /** 173 * SendDtmfString 174 * 175 * @brief Send a string of DTMFS 176 * @param dtmfCodeStr[in], Characters sent 177 * @param phoneNum[in], Phone number corresponding to the call 178 * @param phoneNetType[in]. 179 * @param switchOn[in]. 180 * @param switchOff[in]. 181 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 182 */ 183 int SendDtmfString(const std::string &dtmfCodeStr, const std::string &phoneNum, PhoneNetType phoneNetType, 184 int32_t switchOn, int32_t switchOff); 185 186 /** 187 * SetCallTransferInfo 188 * 189 * @brief Set the call transfer function for the current account 190 * @param info[in], Call Transfer Information 191 * @param slotId[in], The slot id 192 * @return Returns 0 on success, others on failure. 193 */ 194 int SetCallTransferInfo(const CallTransferInfo &info, int32_t slotId); 195 196 /** 197 * CanSetCallTransferTime 198 * 199 * @brief confirm whether IMS can set call transfer time. 200 * @param slotId[in], The slot id 201 * @param result[out], The result of can set or not 202 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 203 */ 204 int CanSetCallTransferTime(int32_t slotId, bool &result); 205 206 /** 207 * GetCallTransferInfo 208 * 209 * @brief Gets the call transfer information of the current account 210 * @param type[in], Call Transfer Type 211 * @param slotId[in], The slot id 212 * @return Returns 0 on success, others on failure. 213 */ 214 int GetCallTransferInfo(CallTransferType type, int32_t slotId); 215 216 /** 217 * SetCallWaiting 218 * 219 * @brief Set the call waiting function for the current account 220 * @param activate[in], Activation of switch 221 * @param slotId[in], The slot id 222 * @return Returns 0 on success, others on failure. 223 */ 224 int SetCallWaiting(bool activate, int32_t slotId); 225 226 /** 227 * GetCallWaiting 228 * 229 * @brief Gets whether the call waiting service of the current account is enabled 230 * @param slotId[in], The slot id 231 * @return Returns 0 on success, others on failure. 232 */ 233 int GetCallWaiting(int32_t slotId); 234 235 /** 236 * SetCallRestriction 237 * 238 * @brief Set the call restriction function for the current account 239 * @param info[in], Call restriction information 240 * @param slotId[in], The slot id 241 * @return Returns 0 on success, others on failure. 242 */ 243 int SetCallRestriction(const CallRestrictionInfo &info, int32_t slotId); 244 245 /** 246 * GetCallRestriction 247 * 248 * @brief Gets the call restriction information of the specified account 249 * @param facType[in], Call Restriction type 250 * @param slotId[in], The slot id 251 * @return Returns 0 on success, others on failure. 252 */ 253 int GetCallRestriction(CallRestrictionType facType, int32_t slotId); 254 255 /** 256 * SetCallRestrictionPassword 257 * 258 * @brief Set the call restriction password of the specified account 259 * @param slotId[in] the slot id 260 * @param fac[in] indicate the call restriction type, just like all incoming, all outgoing .etc 261 * @param oldPassword[in] indicate the call restriction old password 262 * @param newPassword[in] indicate the call restriction new password 263 * @return Returns 0 on success, others on failure. 264 */ 265 int32_t SetCallRestrictionPassword( 266 int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword); 267 268 /** 269 * SetCallPreferenceMode 270 * 271 * @brief Setting the Call Type 272 * @param slotId[in], The slot id 273 * @param mode[in], Preference Mode 274 * @return Returns 0 on success, others on failure. 275 */ 276 int SetCallPreferenceMode(int32_t slotId, int32_t mode); 277 278 /** 279 * StartRtt 280 * 281 * @brief Enable and send RTT information 282 * @param callInfo[in], Call information. 283 * @param msg[in], RTT information 284 * @return Returns 0 on success, others on failure. 285 */ 286 int StartRtt(const CellularCallInfo &callInfo, std::u16string &msg); 287 288 /** 289 * StopRtt 290 * 291 * @brief Close the RTT 292 * @param callInfo[in], Call information. 293 * @return Returns 0 on success, others on failure. 294 */ 295 int StopRtt(const CellularCallInfo &callInfo); 296 297 /** 298 * RegisterCallBack 299 * 300 * @brief Register callback 301 * @param callback[in], callback function pointer 302 * @return Returns 0 on success, others on failure. 303 */ 304 int RegisterCallBack(const sptr<ICallStatusCallback> &callback); 305 306 /** 307 * @brief UnRegister callback 308 * @return Returns 0 on success, others on failure. 309 */ 310 int32_t UnRegisterCallBack(); 311 312 /** 313 * ControlCamera 314 * 315 * @brief Open or close camera 316 * @param cameraId[in], The camera id 317 * @param callingUid[in] 318 * @param callingPid[in] 319 * @return Returns 0 on success, others on failure. 320 */ 321 int32_t ControlCamera(std::u16string cameraId, int32_t callingUid, int32_t); 322 323 /** 324 * SetPreviewWindow 325 * 326 * @brief Set the location and size of the preview window for videos captured by the local camera. 327 * @param window[in], Window information 328 * @return Returns 0 on success, others on failure. 329 */ 330 int32_t SetPreviewWindow(VideoWindow &window); 331 332 /** 333 * SetDisplayWindow 334 * 335 * @brief Sets the location and size of the remote video window. 336 * @param window[in], Window information 337 * @return Returns 0 on success, others on failure. 338 */ 339 int32_t SetDisplayWindow(VideoWindow &window); 340 341 /** 342 * SetCameraZoom 343 * 344 * @brief Sets the local camera zoom scale 345 * @param zoomRatio[in], Camera scale 346 * @return Returns 0 on success, others on failure. 347 */ 348 int32_t SetCameraZoom(float zoomRatio); 349 350 /** 351 * SetPausePicture 352 * 353 * @brief APP sets the screen of the remote video freeze immediately. 354 * If the APP does not call this interface when making a video call, 355 * the last frame before the remote video freeze is displayed by default 356 * @param path[in], Local Picture address 357 * @return Returns 0 on success, others on failure. 358 */ 359 int32_t SetPausePicture(std::u16string path); 360 361 /** 362 * SetDeviceDirection 363 * 364 * @brief Set the rotation Angle of the local device. The default value is 0 365 * @param rotation[in], Rotation Angle 366 * @return Returns 0 on success, others on failure. 367 */ 368 int32_t SetDeviceDirection(int32_t rotation); 369 370 /** 371 * SetImsSwitchStatus 372 * 373 * @brief Setting Ims Switch 374 * @param slotId[in], The slot id 375 * @param active[in], On or off 376 * @return Returns 0 on success, others on failure. 377 */ 378 int32_t SetImsSwitchStatus(int32_t slotId, bool active); 379 380 /** 381 * GetImsSwitchStatus 382 * 383 * @brief Getting Ims Switch 384 * @param slotId[in], The slot id 385 * @param enabled[out], The result of enable or not 386 * @return Returns 0 on success, others on failure. 387 */ 388 int32_t GetImsSwitchStatus(int32_t slotId, bool &enabled); 389 390 /** 391 * SetVoNRState 392 * 393 * @brief Setting VoNR Switch 394 * @param slotId[in], The slot id 395 * @param state[in], On or off 396 * @return Returns 0 on success, others on failure. 397 */ 398 int32_t SetVoNRState(int32_t slotId, int32_t state); 399 400 /** 401 * GetVoNRState 402 * 403 * @brief Getting VoNR Switch 404 * @param slotId[in], The slot id 405 * @param state[out], The result of ON or OFF 406 * @return Returns 0 on success, others on failure. 407 */ 408 int32_t GetVoNRState(int32_t slotId, int32_t &state); 409 410 /** 411 * SendUpdateCallMediaModeRequest 412 * 413 * @brief send update call media request 414 * @param callInfo[in], Call information. 415 * @param mode[in], Calling patterns 416 * @return Returns 0 on success, others on failure. 417 */ 418 int32_t SendUpdateCallMediaModeRequest(const CellularCallInfo &callInfo, ImsCallMode mode); 419 420 /** 421 * Set Ims Config 422 * 423 * @param ImsConfigItem 424 * @param value 425 * @param slotId 426 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 427 */ 428 int32_t SetImsConfig(ImsConfigItem item, const std::string &value, int32_t slotId); 429 430 /** 431 * Set Ims Config 432 * 433 * @param ImsConfigItem 434 * @param value 435 * @param slotId 436 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 437 */ 438 int32_t SetImsConfig(ImsConfigItem item, int32_t value, int32_t slotId); 439 440 /** 441 * Get Ims Config 442 * 443 * @param ImsConfigItem 444 * @param slotId 445 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 446 */ 447 int32_t GetImsConfig(ImsConfigItem item, int32_t slotId); 448 449 /** 450 * Set Ims Feature Value 451 * 452 * @param FeatureType 453 * @param value 454 * @param slotId 455 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 456 */ 457 int32_t SetImsFeatureValue(FeatureType type, int32_t value, int32_t slotId); 458 459 /** 460 * Get Ims Feature Value 461 * 462 * @param FeatureType 463 * @param slotId 464 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 465 */ 466 int32_t GetImsFeatureValue(FeatureType type, int32_t slotId); 467 468 /** 469 * InviteToConference interface 470 * 471 * @param numberList 472 * @param slotId 473 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 474 */ 475 int32_t InviteToConference(const std::vector<std::string> &numberList, int32_t slotId); 476 477 /** 478 * SetMute 479 * 480 * @param mute 481 * @param slotId 482 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 483 */ 484 int32_t SetMute(int32_t mute, int32_t slotId); 485 486 /** 487 * CloseUnFinishedUssd 488 * 489 * @brief Close Unfinished Ussd function for the current account 490 * @param slotId[in], The slot id 491 * @return Returns 0 on success, others on failure. 492 */ 493 int CloseUnFinishedUssd(int32_t slotId); 494 495 /** 496 * Is Connect cellular call service Object 497 * 498 * @return result for Connect cellular call service 499 */ 500 bool IsConnect() const; 501 502 private: 503 int32_t ConnectService(); 504 int32_t RegisterCallBackFun(); 505 void DisconnectService(); 506 int32_t ReConnectService(); 507 void OnDeath(); 508 void Clean(); 509 void NotifyDeath(); 510 int32_t ClearAllCalls(); 511 512 private: 513 class SystemAbilityListener : public SystemAbilityStatusChangeStub { 514 public: 515 SystemAbilityListener() = default; 516 ~SystemAbilityListener() = default; 517 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 518 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 519 }; 520 521 private: 522 int32_t systemAbilityId_; 523 sptr<ICallStatusCallback> cellularCallCallbackPtr_; 524 sptr<CellularCallInterface> cellularCallInterfacePtr_; 525 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 526 bool connectState_; 527 Utils::RWLock rwClientLock_; 528 }; 529 } // namespace Telephony 530 } // namespace OHOS 531 532 #endif 533