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 CALL_MANAGER_SERVICE_H 17 #define CALL_MANAGER_SERVICE_H 18 19 #include <memory> 20 21 #include "bluetooth_call_manager.h" 22 #include "call_control_manager.h" 23 #include "call_manager_service_stub.h" 24 #include "call_state_report_proxy.h" 25 #include "i_call_status_callback.h" 26 #include "iremote_stub.h" 27 #include "iservice_registry.h" 28 #include "singleton.h" 29 #include "system_ability.h" 30 #include "system_ability_definition.h" 31 32 namespace OHOS { 33 namespace Telephony { 34 class CallManagerService : public SystemAbility, 35 public CallManagerServiceStub, 36 public std::enable_shared_from_this<CallManagerService> { 37 DECLARE_DELAYED_SINGLETON(CallManagerService) 38 DECLARE_SYSTEM_ABILITY(CallManagerService) 39 public: 40 bool Init(); 41 void UnInit(); 42 43 /** 44 * service OnStart 45 */ 46 void OnStart() override; 47 48 /** 49 * service OnStop 50 */ 51 void OnStop() override; 52 53 /** 54 * service dump 55 * @param fd 56 * @param args 57 * @return 58 */ 59 int32_t Dump(std::int32_t fd, const std::vector<std::u16string> &args) override; 60 61 /** 62 * Get bindTime_ 63 * @return string 64 */ 65 std::string GetBindTime(); 66 67 /** 68 * Get spendTime_ 69 * @return string 70 */ 71 std::string GetStartServiceSpent(); 72 73 /** 74 * Get serviceRunningState_ 75 * @return serviceRunningState_ 76 */ 77 int32_t GetServiceRunningState(); 78 79 /** 80 * RegisterCallBack 81 * 82 * @brief Register callback 83 * @param callback[in], callback function pointer 84 * @param bundleName[in], bundle name 85 * @return Returns 0 on success, others on failure. 86 */ 87 int32_t RegisterCallBack(const sptr<ICallAbilityCallback> &callback) override; 88 89 /** 90 * UnRegisterCallBack 91 * 92 * @brief unregister callback 93 * @param bundleName[in], bundle name 94 * @return Returns 0 on success, others on failure. 95 */ 96 int32_t UnRegisterCallBack() override; 97 98 /** 99 * ObserverOnCallDetailsChange 100 * 101 * @brief excute when observe OnCallDetailsChange 102 * @return Returns 0 on success, others on failure. 103 */ 104 int32_t ObserverOnCallDetailsChange() override; 105 106 /** 107 * DialCall 108 * 109 * @brief Make a phone call 110 * @param number[in], dial param. 111 * @param extras[in], extras date. 112 * @return Returns callId when the value is greater than zero, others on failure. 113 */ 114 int32_t DialCall(std::u16string number, AppExecFwk::PacMap &extras) override; 115 116 /** 117 * AnswerCall 118 * 119 * @brief Answer a phone call 120 * @param callId[in], call id 121 * @param videoState[in], 0: audio, 1: video 122 * @return Returns 0 on success, others on failure. 123 */ 124 int32_t AnswerCall(int32_t callId, int32_t videoState) override; 125 126 /** 127 * RejectCall 128 * 129 * @brief Reject a phone call 130 * @param callId[in], call id 131 * @param rejectWithMessage[in], Whether to enter the reason for rejection,true:yes false:no 132 * @param textMessage[in], The reason you reject the call 133 * @return Returns 0 on success, others on failure. 134 */ 135 int32_t RejectCall(int32_t callId, bool rejectWithMessage, std::u16string textMessage) override; 136 137 /** 138 * HangUpCall 139 * 140 * @brief Hang up the phone 141 * @param callId[in], call id 142 * @return Returns 0 on success, others on failure. 143 */ 144 int32_t HangUpCall(int32_t callId) override; 145 146 /** 147 * GetCallState 148 * 149 * @brief Obtain the call status of the device 150 * @return Returns call state. 151 */ 152 int32_t GetCallState() override; 153 154 /** 155 * HoldCall 156 * 157 * @brief Park a phone call 158 * @param callId[in], call id 159 * @return Returns 0 on success, others on failure. 160 */ 161 int32_t HoldCall(int32_t callId) override; 162 163 /** 164 * UnHoldCall 165 * 166 * @brief Activate a phone call 167 * @param callId[in], call id 168 * @return Returns 0 on success, others on failure. 169 */ 170 int32_t UnHoldCall(int32_t callId) override; 171 172 /** 173 * SwitchCall 174 * 175 * @brief Switch the phone 176 * @param callId[in], call id 177 * @return Returns 0 on success, others on failure. 178 */ 179 int32_t SwitchCall(int32_t callId) override; 180 181 /** 182 * HasCall 183 * 184 * @brief Is there Call 185 * @return Returns true on has call, others on there is no call. 186 */ 187 bool HasCall() override; 188 189 /** 190 * IsNewCallAllowed 191 * 192 * @brief Can I initiate a call 193 * @param enabled[out], true on can, others on there is not can 194 * @return Returns interface processing results. 195 */ 196 int32_t IsNewCallAllowed(bool &enabled) override; 197 198 /** 199 * SetMuted 200 * 201 * @brief Mute the Microphone 202 * @param isMute[in], mute state 203 * @return Returns 0 on success, others on failure. 204 */ 205 int32_t SetMuted(bool isMute) override; 206 207 /** 208 * MuteRinger 209 * 210 * @brief Call mute 211 * @return Returns 0 on success, others on failure. 212 */ 213 int32_t MuteRinger() override; 214 215 /** 216 * SetAudioDevice 217 * 218 * @brief Setting the Audio Channel 219 * @param audioDevice[in], contain audioDeviceType ande address 220 * @return Returns 0 on success, others on failure. 221 */ 222 int32_t SetAudioDevice(const AudioDevice &audioDevice) override; 223 224 /** 225 * IsRinging 226 * 227 * @brief Whether the ringing 228 * @param enabled[out], true on ringing, false on there is no ringing 229 * @return Returns interface processing results. 230 */ 231 int32_t IsRinging(bool &enabled) override; 232 233 /** 234 * IsInEmergencyCall 235 * 236 * @brief Is there an emergency call 237 * @param enabled[out], true on emergency call, false on no emergency call 238 * @return Returns interface processing results. 239 */ 240 int32_t IsInEmergencyCall(bool &enabled) override; 241 242 /** 243 * StartDtmf 244 * 245 * @brief Enable and send DTMF 246 * @param callId[in], call id 247 * @param str[in], Characters sent 248 * @return Returns 0 on success, others on failure. 249 */ 250 int32_t StartDtmf(int32_t callId, char str) override; 251 252 /** 253 * StopDtmf 254 * 255 * @brief Stop the DTMF 256 * @param callId[in], call id 257 * @return Returns 0 on success, others on failure. 258 */ 259 int32_t StopDtmf(int32_t callId) override; 260 261 int32_t PostDialProceed(int32_t callId, bool proceed) override; 262 263 /** 264 * GetCallWaiting 265 * 266 * @brief Gets whether the call waiting service of the current account is enabled 267 * @param slotId[in], The slot id 268 * @return Returns 0 on success, others on failure. 269 */ 270 int32_t GetCallWaiting(int32_t slotId) override; 271 272 /** 273 * SetCallWaiting 274 * 275 * @brief Set the call waiting function for the current account 276 * @param slotId[in], The slot id 277 * @param activate[in], Activation of switch 278 * @return Returns 0 on success, others on failure. 279 */ 280 int32_t SetCallWaiting(int32_t slotId, bool activate) override; 281 282 /** 283 * GetCallRestriction 284 * 285 * @brief Gets the call restriction information of the specified account 286 * @param slotId[in], The slot id 287 * @param type[in], Call Restriction type 288 * @return Returns 0 on success, others on failure. 289 */ 290 int32_t GetCallRestriction(int32_t slotId, CallRestrictionType type) override; 291 292 /** 293 * SetCallRestriction 294 * 295 * @brief Set the call restriction function for the current account 296 * @param slotId[in], The slot id 297 * @param info[in], Call restriction information 298 * @return Returns 0 on success, others on failure. 299 */ 300 int32_t SetCallRestriction(int32_t slotId, CallRestrictionInfo &info) override; 301 302 /** 303 * SetCallRestrictionPassword 304 * 305 * @brief Set the call restriction password function for the current account 306 * @param slotId[in], The slot id 307 * @param fac[in], Call restriction type 308 * @param oldPassword[in], Old password of call restriction type 309 * @param newPassword[in], New password of call restriction type 310 * @return Returns 0 on success, others on failure. 311 */ 312 int32_t SetCallRestrictionPassword( 313 int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword) override; 314 315 /** 316 * GetCallTransferInfo 317 * 318 * @brief Gets the call transfer information of the current account 319 * @param slotId[in], The slot id 320 * @param type[in], Call Transfer Type 321 * @return Returns 0 on success, others on failure. 322 */ 323 int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type) override; 324 325 /** 326 * SetCallTransferInfo 327 * 328 * @brief Set the call transfer function for the current account 329 * @param slotId[in], The slot id 330 * @param info[in], Call Transfer Information 331 * @return Returns 0 on success, others on failure. 332 */ 333 int32_t SetCallTransferInfo(int32_t slotId, CallTransferInfo &info) override; 334 335 /** 336 * CanSetCallTransferTime 337 * 338 * @brief confirm whether IMS support call transfer due to time. 339 * @param slotId[in], The slot id 340 * @param result[out], The result of support or not 341 * @return Returns 0 on success, others on failure. 342 */ 343 int32_t CanSetCallTransferTime(int32_t slotId, bool &result) override; 344 345 /** 346 * CombineConference 347 * 348 * @brief Merge calls to form a conference 349 * @param callId[in], call id 350 * @return Returns 0 on success, others on failure. 351 */ 352 int32_t CombineConference(int32_t mainCallId) override; 353 354 /** 355 * SeparateConference 356 * 357 * @brief Separates a specified call from a conference call 358 * @param callId[in], call id 359 * @return Returns 0 on success, others on failure. 360 */ 361 int32_t SeparateConference(int32_t callId) override; 362 363 /** 364 * KickOutFromConference 365 * 366 * @brief Hangup a specified call from a conference call 367 * @param callId[in], call id 368 * @return Returns 0 on success, others on failure. 369 */ 370 int32_t KickOutFromConference(int32_t callId) override; 371 372 /** 373 * ControlCamera 374 * 375 * @brief Open or close camera 376 * @param callId[in], call id 377 * @param cameraId[in], The camera id 378 * @return Returns 0 on success, others on failure. 379 */ 380 int32_t ControlCamera(int32_t callId, std::u16string &cameraId) override; 381 382 /** 383 * SetPreviewWindow 384 * 385 * @brief Set the location and size of the preview window for videos captured by the local camera. 386 * @param callId[in], call id 387 * @param surfaceId[in], Window information 388 * @param surface[in], Window information 389 * @return Returns 0 on success, others on failure. 390 */ 391 int32_t SetPreviewWindow(int32_t callId, std::string &surfaceId, sptr<Surface> surface) override; 392 393 /** 394 * SetDisplayWindow 395 * 396 * @brief Sets the location and size of the remote video window. 397 * @param callId[in], call id 398 * @param surfaceId[in], Window information 399 * @param surface[in], Window information 400 * @return Returns 0 on success, others on failure. 401 */ 402 int32_t SetDisplayWindow(int32_t callId, std::string &surfaceId, sptr<Surface> surface) override; 403 404 /** 405 * SetCameraZoom 406 * 407 * @brief Sets the local camera zoom scale 408 * @param zoomRatio[in], Camera scale 409 * @return Returns 0 on success, others on failure. 410 */ 411 int32_t SetCameraZoom(float zoomRatio) override; 412 413 /** 414 * SetPausePicture 415 * 416 * @brief APP sets the screen of the remote video freeze immediately. 417 * If the APP does not call this interface when making a video call, 418 * the last frame before the remote video freeze is displayed by default 419 * @param callId[in], call id 420 * @param path[in], Local Picture address 421 * @return Returns 0 on success, others on failure. 422 */ 423 int32_t SetPausePicture(int32_t callId, std::u16string &path) override; 424 425 /** 426 * SetDeviceDirection 427 * 428 * @brief Set the rotation Angle of the local device. The default value is 0 429 * @param callId[in], call id 430 * @param rotation[in], Rotation Angle 431 * @return Returns 0 on success, others on failure. 432 */ 433 int32_t SetDeviceDirection(int32_t callId, int32_t rotation) override; 434 435 /** 436 * IsEmergencyPhoneNumber 437 * 438 * @brief Is it an emergency call 439 * @param number[in], Phone number to be formatted 440 * @param slotId[in], The slot id 441 * @param enabled[out] result of is it an emergency call 442 * @return Returns 0 on success, others on failure. 443 */ 444 int32_t IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled) override; 445 446 /** 447 * FormatPhoneNumber 448 * 449 * @brief Formatting a phone number 450 * @param number[in], Phone number to be formatted 451 * @param countryCode[in], Country code of the phone number 452 * @param formatNumber[out] Formatting a phone number 453 * @return Returns 0 on success, others on failure. 454 */ 455 int32_t FormatPhoneNumber( 456 std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber) override; 457 458 /** 459 * FormatPhoneNumberToE164 460 * 461 * @brief Formatting a phone number 462 * @param number[in]. Phone number to be formatted 463 * @param countryCode[in], Country code of the phone number 464 * @param formatNumber[out] Formatting a phone number 465 * @return Returns 0 on success, others on failure. 466 */ 467 int32_t FormatPhoneNumberToE164( 468 std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber) override; 469 470 /** 471 * GetMainCallId 472 * 473 * @brief Obtain the ID of the primary call in a conference 474 * @param callId[in], Id of a call in a conference 475 * @return Returns main call id, -1 on not call id. 476 */ 477 int32_t GetMainCallId(int32_t callId, int32_t &mainCallId) override; 478 479 /** 480 * GetSubCallIdList 481 * 482 * @brief Obtain the list of neutron call ids 483 * @param callId[in], Id of a call in a conference 484 * @param callIdList[out], the list of neutron call ids 485 * @return Returns 0 on success, others on failure. 486 */ 487 int32_t GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList) override; 488 489 /** 490 * GetCallIdListForConference 491 * 492 * @brief Obtain the callId list of all calls in a conference 493 * @param callId[in], Id of a call in a conference 494 * @param callIdList[out], the callId list of all calls in a conference 495 * @return Returns 0 on success, others on failure. 496 */ 497 int32_t GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList) override; 498 499 /** 500 * SetCallPreferenceMode 501 * 502 * @brief Setting the Call Type 503 * @param slotId[in], The slot id 504 * @param mode[in], Preference Mode 505 * @return Returns 0 on success, others on failure. 506 */ 507 int32_t SetCallPreferenceMode(int32_t slotId, int32_t mode) override; 508 509 /** 510 * GetImsConfig 511 * 512 * @brief Obtain the IMS service configuration 513 * @param slotId[in], The slot id 514 * @param item[in] 515 * @return Returns 0 on success, others on failure. 516 */ 517 int32_t GetImsConfig(int32_t slotId, ImsConfigItem item) override; 518 519 /** 520 * SetImsConfig 521 * 522 * @brief Example Set the IMS service configuration 523 * @param slotId[in], The slot id 524 * @param item[in] 525 * @return Returns 0 on success, others on failure. 526 */ 527 int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value) override; 528 529 /** 530 * GetImsFeatureValue 531 * 532 * @brief Gets the value of the IMS function item of the specified network type 533 * @param slotId[in], The slot id 534 * @param info[in], FeatureType 535 * @return Returns 0 on success, others on failure. 536 */ 537 int32_t GetImsFeatureValue(int32_t slotId, FeatureType type) override; 538 539 /** 540 * SetImsFeatureValue 541 * 542 * @brief Set the value of the IMS function item of the specified network type 543 * @param slotId[in], The slot id 544 * @param info[in], FeatureType 545 * @param value[in] 546 * @return Returns 0 on success, others on failure. 547 */ 548 int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value) override; 549 550 /** 551 * UpdateImsCallMode 552 * 553 * @brief Setting the Call Mode 554 * @param callId[in], The call id 555 * @param mode[in], Calling patterns 556 * @return Returns 0 on success, others on failure. 557 */ 558 int32_t UpdateImsCallMode(int32_t callId, ImsCallMode mode) override; 559 560 /** 561 * EnableImsSwitch 562 * 563 * @brief Start VoLte 564 * @param slotId[in], The slot id 565 * @return Returns 0 on success, others on failure. 566 */ 567 int32_t EnableImsSwitch(int32_t slotId) override; 568 569 /** 570 * DisableImsSwitch 571 * 572 * @brief Stop VoLte 573 * @param slotId[in], The slot id 574 * @return Returns 0 on success, others on failure. 575 */ 576 int32_t DisableImsSwitch(int32_t slotId) override; 577 578 /** 579 * IsImsSwitchEnabled 580 * 581 * @brief Whether to enable VoLte 582 * @param slotId[in], The slot id 583 * @param enabled[out], The result of enable or not 584 * @return Returns 0 on success, others on failure. 585 */ 586 int32_t IsImsSwitchEnabled(int32_t slotId, bool &enabled) override; 587 588 /** 589 * SetVoNRState 590 * 591 * @brief Set VoNR State 592 * @param slotId[in], The slot id 593 * @param state[in], The state of VoNR 594 * @return Returns 0 on success, others on failure. 595 */ 596 int32_t SetVoNRState(int32_t slotId, int32_t state) override; 597 598 /** 599 * GetVoNRState 600 * 601 * @brief Get VoNR State 602 * @param slotId[in], The slot id 603 * @param state[out], The result of VoNR state ON or OFF 604 * @return Returns 0 on success, others on failure. 605 */ 606 int32_t GetVoNRState(int32_t slotId, int32_t &state) override; 607 608 /** 609 * StartRtt 610 * 611 * @brief Enable and send RTT information 612 * @param callId[in], The call id 613 * @param msg[in], RTT information 614 * @return Returns 0 on success, others on failure. 615 */ 616 int32_t StartRtt(int32_t callId, std::u16string &msg) override; 617 618 /** 619 * StopRtt 620 * 621 * @brief Close the RTT 622 * @param callId[in], The call id 623 * @return Returns 0 on success, others on failure. 624 */ 625 int32_t StopRtt(int32_t callId) override; 626 627 /** 628 * JoinConference 629 * 630 * @brief Bring someone into a meeting 631 * @param callId[in], The call id 632 * @param numberList[in], List of calls to join the conference 633 * @return Returns 0 on success, others on failure. 634 */ 635 int32_t JoinConference(int32_t callId, std::vector<std::u16string> &numberList) override; 636 637 /** 638 * ReportOttCallDetailsInfo 639 * 640 * @brief report ott call details info 641 * @param ottVec[in], ott call status detail info list 642 * @return Returns 0 on success, others on failure. 643 */ 644 int32_t ReportOttCallDetailsInfo(std::vector<OttCallDetailsInfo> &ottVec) override; 645 646 /** 647 * ReportOttCallEventInfo 648 * 649 * @brief report ott call details info 650 * @param ottVec[in], ott call status detail info list 651 * @return Returns 0 on success, others on failure. 652 */ 653 int32_t ReportOttCallEventInfo(OttCallEventInfo &eventInfo) override; 654 655 /** 656 * CloseUnFinishedUssd 657 * 658 * @brief Close Unfinished ussd function for the current account 659 * @param slotId[in], The slot id 660 * @return Returns 0 on success, others on failure. 661 */ 662 int32_t CloseUnFinishedUssd(int32_t slotId) override; 663 664 /** 665 * Remove missed incoming call notification. 666 * 667 * @return Returns 0 on success, others on failure. 668 */ 669 int32_t RemoveMissedIncomingCallNotification() override; 670 671 /** 672 * SetVoIPCallState 673 * 674 * @brief Set VoIP Call State 675 * @param state[in], The state of VoIP Call 676 * @return Returns 0 on success, others on failure. 677 */ 678 int32_t SetVoIPCallState(int32_t state) override; 679 680 /** 681 * GetVoIPCallState 682 * 683 * @brief Get VoIP Call State 684 * @param state[out], The result of VoIP Call 685 * @return Returns 0 on success, others on failure. 686 */ 687 int32_t GetVoIPCallState(int32_t &state) override; 688 689 /** 690 * Handle special code from dialer. 691 * 692 * @param specialCode[in], special code 693 * @return Returns 0 on success, others on failure. 694 */ 695 int32_t InputDialerSpecialCode(const std::string &specialCode) override; 696 697 /** 698 * GetProxyObjectPtr 699 * 700 * @brief get callManager proxy object ptr 701 * @param proxyType[in], proxy type 702 * @return Returns nullptr on failure, others on success. 703 */ 704 sptr<IRemoteObject> GetProxyObjectPtr(CallManagerProxyType proxyType) override; 705 706 /** 707 * ReportAudioDeviceInfo 708 * 709 * @brief report audio device info 710 * @return Returns 0 on success, others on failure. 711 */ 712 int32_t ReportAudioDeviceInfo() override; 713 714 /** 715 * CancelCallUpgrade 716 * 717 * @brief cancel upgrade to video call 718 * @param callId[in], The call id 719 * 720 * @return Returns 0 on success, others on failure. 721 */ 722 int32_t CancelCallUpgrade(int32_t callId) override; 723 724 /** 725 * RequestCameraCapabilities 726 * 727 * @brief request camera capabilities 728 * @param callId[in], The call id 729 * 730 * @return Returns 0 on success, others on failure. 731 */ 732 int32_t RequestCameraCapabilities(int32_t callId) override; 733 734 /** 735 * RegisterVoipCallManagerCallback 736 * 737 * @brief notify voip register callstatus callback 738 * @return Returns 0 on success, others on failure. 739 */ 740 int32_t RegisterVoipCallManagerCallback() override; 741 742 /** 743 * @brief notify voip unregister callstatus callback 744 * 745 * @return Returns 0 on success, others on failure. 746 */ 747 int32_t UnRegisterVoipCallManagerCallback() override; 748 749 private: 750 std::string GetBundleName(); 751 752 private: 753 enum ServiceRunningState { 754 STATE_STOPPED = 0, 755 STATE_RUNNING, 756 }; 757 758 ServiceRunningState state_ { ServiceRunningState::STATE_STOPPED }; 759 #ifndef TELEPHONY_VOIP_CALL_MANAGER_SYS_ABILITY_ID 760 #define TELEPHONY_VOIP_CALL_MANAGER_SYS_ABILITY_ID 65968 761 #endif 762 std::shared_ptr<CallControlManager> callControlManagerPtr_; 763 std::map<uint32_t, sptr<IRemoteObject>> proxyObjectPtrMap_; 764 std::vector<std::string> supportSpecialCode_ { "2846579" }; 765 sptr<ICallStatusCallback> voipCallCallbackPtr_; 766 std::mutex lock_; 767 const int32_t startTime_ = 1900; 768 const int32_t extraMonth_ = 1; 769 int64_t bindTime_ = 0L; 770 int32_t spendTime_ = 0; 771 }; 772 } // namespace Telephony 773 } // namespace OHOS 774 775 #endif // CALL_MANAGER_SERVICE_H 776