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_SERVICE_H 17 #define CELLULAR_CALL_SERVICE_H 18 19 #include <memory> 20 #include <mutex> 21 22 #include "cellular_call_config.h" 23 #include "cellular_call_handler.h" 24 #include "cellular_call_stub.h" 25 #include "cellular_call_supplement.h" 26 #include "event_runner.h" 27 #include "iremote_broker.h" 28 #include "singleton.h" 29 #include "system_ability.h" 30 #include "system_ability_status_change_stub.h" 31 32 namespace OHOS { 33 namespace Telephony { 34 enum class ServiceRunningState { STATE_STOPPED, STATE_RUNNING }; 35 36 class CellularCallService : public SystemAbility, 37 public CellularCallStub, 38 public std::enable_shared_from_this<CellularCallService> { 39 DECLARE_DELAYED_SINGLETON(CellularCallService) 40 DECLEAR_SYSTEM_ABILITY(CellularCallService) 41 42 public: 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 * 56 * @param fd 57 * @param args 58 * @return 59 */ 60 int32_t Dump(std::int32_t fd, const std::vector<std::u16string> &args) override; 61 62 /** 63 * Get serviceRunningState_ 64 * @return serviceRunningState_ 65 */ 66 int32_t GetServiceRunningState(); 67 68 /** 69 * RegisterHandler 70 */ 71 void RegisterHandler(); 72 73 /** 74 * Get bindTime_ 75 * 76 * @return int64_t 77 */ 78 std::string GetBindTime(); 79 80 /** 81 * Get EndTime 82 * 83 * @return int64_t 84 */ 85 std::string GetEndTime(); 86 87 /** 88 * Get SpendTime 89 * 90 * @return int64_t 91 */ 92 std::string GetSpendTime(); 93 94 /** 95 * Dial 96 * 97 * @param CellularCallInfo, dial param. 98 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 99 */ 100 int32_t Dial(const CellularCallInfo &callInfo) override; 101 102 /** 103 * HangUp 104 * 105 * @param CellularCallInfo, HangUp param. 106 * @param CallSupplementType 107 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 108 */ 109 int32_t HangUp(const CellularCallInfo &callInfo, CallSupplementType type) override; 110 111 /** 112 * Reject 113 * 114 * @param CellularCallInfo, Reject param. 115 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 116 */ 117 int32_t Reject(const CellularCallInfo &callInfo) override; 118 119 /** 120 * Answer 121 * 122 * @param CellularCallInfo, Answer param. 123 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 124 */ 125 int32_t Answer(const CellularCallInfo &callInfo) override; 126 127 /** 128 * HoldCall 129 * 130 * @param CellularCallInfo, Hold param. 131 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 132 */ 133 int32_t HoldCall(const CellularCallInfo &callInfo) override; 134 135 /** 136 * UnHoldCall 137 * 138 * @param CellularCallInfo, UnHold param. 139 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 140 */ 141 int32_t UnHoldCall(const CellularCallInfo &callInfo) override; 142 143 /** 144 * SwitchCall 145 * 146 * @param CellularCallInfo, SwitchCall param. 147 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 148 */ 149 int32_t SwitchCall(const CellularCallInfo &callInfo) override; 150 151 /** 152 * IsEmergencyPhoneNumber 153 * 154 * @param slotId 155 * @param phone number 156 * @param enabled Is Urgent Call 157 * @return TELEPHONY_SUCCESS on success, others on failure. 158 */ 159 int32_t IsEmergencyPhoneNumber(int32_t slotId, const std::string &phoneNum, bool &enabled) override; 160 161 /** 162 * SetEmergencyCallList 163 * 164 * @param slotId 165 * @param eccVec 166 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 167 */ 168 int32_t SetEmergencyCallList(int32_t slotId, std::vector<EmergencyCall> &eccVec) override; 169 170 /** 171 * Merge into multiple calls 172 * 173 * @param CellularCallInfo 174 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 175 */ 176 int32_t CombineConference(const CellularCallInfo &callInfo) override; 177 178 /** 179 * SeparateConference 180 * 181 * @param CellularCallInfo 182 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 183 */ 184 int32_t SeparateConference(const CellularCallInfo &callInfo) override; 185 186 /** 187 * InviteToConference 188 * 189 * @param slotId 190 * @param numberList 191 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 192 */ 193 int32_t InviteToConference(int32_t slotId, const std::vector<std::string> &numberList) override; 194 195 /** 196 * KickOutFromConference 197 * 198 * @param CellularCallInfo 199 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 200 */ 201 int32_t KickOutFromConference(const CellularCallInfo &callInfo) override; 202 203 /** 204 * Hang Up All Connection 205 * 206 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 207 */ 208 int32_t HangUpAllConnection() override; 209 210 /** 211 * Hang Up All Connection 212 * 213 * @param slotId 214 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 215 */ 216 int32_t HangUpAllConnection(int32_t slotId) override; 217 218 int32_t SetReadyToCall(int32_t slotId, int32_t callType, bool isReadyToCall) override; 219 220 /** 221 * IMS Send Update Call Media Mode Request 222 * 223 * @param CellularCallInfo 224 * @param ImsCallMode 225 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 226 */ 227 int32_t SendUpdateCallMediaModeRequest(const CellularCallInfo &callInfo, ImsCallMode mode) override; 228 229 /** 230 * IMS Send Update Call Media Mode Response 231 * 232 * @param CellularCallInfo 233 * @param ImsCallMode 234 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 235 */ 236 int32_t SendUpdateCallMediaModeResponse(const CellularCallInfo &callInfo, ImsCallMode mode) override; 237 238 /** 239 * Cancel Call Upgrade 240 * 241 * @param slotId the slot id 242 * @param callIndex the call index number. 243 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 244 */ 245 int32_t CancelCallUpgrade(int32_t slotId, int32_t callIndex) override; 246 247 /** 248 * Request Camera Capabilities 249 * 250 * @param slotId the slot id 251 * @param callIndex the call index number. 252 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 253 */ 254 int32_t RequestCameraCapabilities(int32_t slotId, int32_t callIndex) override; 255 256 /** 257 * Register CallManager CallBack 258 * 259 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 260 */ 261 int32_t RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback) override; 262 263 /** 264 * UnRegister CallManager CallBack 265 * 266 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 267 */ 268 int32_t UnRegisterCallManagerCallBack() override; 269 270 /** 271 * StartDtmf 272 * 273 * @param Dtmf Code 274 * @param CellularCallInfo 275 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 276 */ 277 int32_t StartDtmf(char cDtmfCode, const CellularCallInfo &callInfo) override; 278 279 /** 280 * StopDtmf 281 * 282 * @param CellularCallInfo 283 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 284 */ 285 int32_t StopDtmf(const CellularCallInfo &callInfo) override; 286 287 int32_t PostDialProceed(const CellularCallInfo &callInfo, const bool proceed) override; 288 289 /** 290 * SendDtmf 291 * 292 * @param Dtmf Code 293 * @param CellularCallInfo 294 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 295 */ 296 int32_t SendDtmf(char cDtmfCode, const CellularCallInfo &callInfo) override; 297 298 /** 299 * Start Rtt 300 * 301 * @param slotId 302 * @param msg 303 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 304 */ 305 int32_t StartRtt(int32_t slotId, const std::string &msg) override; 306 307 /** 308 * Stop Rtt 309 * 310 * @param slotId 311 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 312 */ 313 int32_t StopRtt(int32_t slotId) override; 314 315 /** 316 * Set Call Transfer 317 * 318 * @param slotId 319 * @param CallTransferInfo 320 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 321 */ 322 int32_t SetCallTransferInfo(int32_t slotId, const CallTransferInfo &cfInfo) override; 323 324 /** 325 * confirm whether IMS can set call transfer time. 326 * 327 * @param slotId[in], The slot id 328 * @param result[out], The result of can set or not 329 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 330 */ 331 int32_t CanSetCallTransferTime(int32_t slotId, bool &result) override; 332 333 /** 334 * Get Call Transfer 335 * 336 * @param slotId 337 * @param CallTransferType 338 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 339 */ 340 int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type) override; 341 342 /** 343 * Set Call Waiting 344 * 345 * @param slotId 346 * @param activate 347 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 348 */ 349 int32_t SetCallWaiting(int32_t slotId, bool activate) override; 350 351 /** 352 * Inquire Call Waiting 353 * 354 * @param slotId 355 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 356 */ 357 int32_t GetCallWaiting(int32_t slotId) override; 358 359 /** 360 * Set Call Restriction 361 * 362 * @param slotId 363 * @param CallRestrictionInfo 364 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 365 */ 366 int32_t SetCallRestriction(int32_t slotId, const CallRestrictionInfo &crInfo) override; 367 368 /** 369 * Inquire Call Restriction 370 * 371 * @param slotId 372 * @param CallRestrictionType 373 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 374 */ 375 int32_t GetCallRestriction(int32_t slotId, CallRestrictionType facType) override; 376 377 /** 378 * @brief Set the call restriction password of the specified account 379 * 380 * @param slotId[in] the slot id 381 * @param facType[in] indicate the call restriction type, just like all incoming, all outgoing .etc 382 * @param oldPassword[in] indicate the call restriction old password 383 * @param newPassword[in] indicate the call restriction new password 384 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 385 */ 386 int32_t SetCallRestrictionPassword( 387 int32_t slotId, CallRestrictionType facType, const char *oldPassword, const char *newPassword) override; 388 389 /** 390 * Set Domain Preference Mode 391 * 392 * @param slotId 393 * @param mode 394 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 395 */ 396 int32_t SetDomainPreferenceMode(int32_t slotId, int32_t mode) override; 397 398 /** 399 * Get Domain Preference Mode 400 * 401 * @param slotId 402 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 403 */ 404 int32_t GetDomainPreferenceMode(int32_t slotId) override; 405 406 /** 407 * Set Ims Switch Status 408 * 409 * @param slotId 410 * @param active 411 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 412 */ 413 int32_t SetImsSwitchStatus(int32_t slotId, bool active) override; 414 415 /** 416 * Get Ims Switch Status 417 * 418 * @param slotId 419 * @param enabled 420 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 421 */ 422 int32_t GetImsSwitchStatus(int32_t slotId, bool &enabled) override; 423 424 /** 425 * Set Ims Config 426 * 427 * @param slotId 428 * @param ImsConfigItem 429 * @param value 430 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 431 */ 432 int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, const std::string &value) override; 433 434 /** 435 * Set VoNR Switch State 436 * 437 * @param slotId 438 * @param state 439 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 440 */ 441 virtual int32_t SetVoNRState(int32_t slotId, int32_t state) override; 442 443 /** 444 * Get VoNR Switch State 445 * 446 * @param slotId 447 * @param state 448 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 449 */ 450 virtual int32_t GetVoNRState(int32_t slotId, int32_t &state) override; 451 452 /** 453 * Set Ims Config 454 * 455 * @param slotId 456 * @param ImsConfigItem 457 * @param value 458 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 459 */ 460 int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, int32_t value) override; 461 462 /** 463 * Get Ims Config 464 * 465 * @param slotId 466 * @param ImsConfigItem 467 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 468 */ 469 int32_t GetImsConfig(int32_t slotId, ImsConfigItem item) override; 470 471 /** 472 * Set Ims Feature Value 473 * 474 * @param slotId 475 * @param FeatureType 476 * @param value 477 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 478 */ 479 int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value) override; 480 481 /** 482 * Get Ims Feature Value 483 * 484 * @param slotId 485 * @param FeatureType 486 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 487 */ 488 int32_t GetImsFeatureValue(int32_t slotId, FeatureType type) override; 489 490 /** 491 * ControlCamera 492 * 493 * @param slotId[in], The slot id 494 * @param index Indicates the call index number. 495 * @param cameraId 496 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 497 */ 498 int32_t ControlCamera(int32_t slotId, int32_t index, const std::string &cameraId) override; 499 500 /** 501 * SetPreviewWindow 502 * 503 * @param slotId[in], The slot id 504 * @param index Indicates the call index number. 505 * @param surfaceID Surface id of window object 506 * @param surface The surface object of window 507 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 508 */ 509 int32_t SetPreviewWindow( 510 int32_t slotId, int32_t index, const std::string &surfaceId, sptr<Surface> surface) override; 511 512 /** 513 * SetDisplayWindow 514 * 515 * @param slotId[in], The slot id 516 * @param index Indicates the call index number. 517 * @param surfaceID Surface id of window object 518 * @param surface The surface object of window 519 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 520 */ 521 int32_t SetDisplayWindow( 522 int32_t slotId, int32_t index, const std::string &surfaceId, sptr<Surface> surface) override; 523 524 /** 525 * SetCameraZoom 526 * 527 * @param zoomRatio 528 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 529 */ 530 int32_t SetCameraZoom(float zoomRatio) override; 531 532 /** 533 * SetPausePicture 534 * 535 * @param slotId[in], The slot id 536 * @param index Indicates the call index number. 537 * @param path 538 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 539 */ 540 int32_t SetPausePicture(int32_t slotId, int32_t index, const std::string &path) override; 541 542 /** 543 * SetDeviceDirection 544 * 545 * @param slotId[in], The slot id 546 * @param index Indicates the call index number. 547 * @param rotation 548 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 549 */ 550 int32_t SetDeviceDirection(int32_t slotId, int32_t index, int32_t rotation) override; 551 552 /** 553 * SetMute 554 * 555 * @param mute 556 * @param slotId 557 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 558 */ 559 int32_t SetMute(int32_t slotId, int32_t mute) override; 560 561 /** 562 * GetMute 563 * 564 * @param slotId 565 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 566 */ 567 int32_t GetMute(int32_t slotId) override; 568 569 /** 570 * Close Unfinished ussd 571 * 572 * @param slotId 573 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 574 */ 575 int32_t CloseUnFinishedUssd(int32_t slotId) override; 576 577 int32_t ClearAllCalls(const std::vector<CellularCallInfo> &infos) override; 578 579 /** 580 * Is need choose IMS for execute 581 * 582 * @param slotId 583 * @return bool 584 */ 585 bool IsNeedIms(int32_t slotId) const; 586 587 /** 588 * Get CSControl 589 * 590 * @param slotId 591 * @return shared_ptr CSControl 592 */ 593 std::shared_ptr<CSControl> GetCsControl(int32_t slotId); 594 595 /** 596 * Get IMControl 597 * 598 * @param slotId 599 * @return shared_ptr CSControl 600 */ 601 std::shared_ptr<IMSControl> GetImsControl(int32_t slotId); 602 603 /** 604 * Get SatelliteControl 605 * 606 * @param slotId 607 * @return shared_ptr SatelliteControl 608 */ 609 std::shared_ptr<SatelliteControl> GetSatelliteControl(int32_t slotId); 610 611 /** 612 * Set SetCsControl 613 * 614 * @param slotId 615 * @param shared_ptr CSControl 616 */ 617 void SetCsControl(int32_t slotId, const std::shared_ptr<CSControl> &csControl); 618 619 /** 620 * Set IMSControl 621 * 622 * @param slotId 623 * @param shared_ptr IMSControl 624 */ 625 void SetImsControl(int32_t slotId, const std::shared_ptr<IMSControl> &imsControl); 626 627 /** 628 * Set SatelliteControl 629 * 630 * @param slotId 631 * @param shared_ptr SatelliteControl 632 */ 633 void SetSatelliteControl(int32_t slotId, const std::shared_ptr<SatelliteControl> &satelliteControl); 634 635 /** 636 * Get Handler 637 * 638 * @param slotId 639 * @return CellularCallHandler 640 */ 641 std::shared_ptr<CellularCallHandler> GetHandler(int32_t slotId); 642 643 void SetSrvccState(int32_t srvccState); 644 645 int32_t GetSrvccState(); 646 647 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE 648 /** 649 * Get call manager service 650 */ 651 void StartCallManagerService(); 652 #endif 653 654 private: 655 /** 656 * Init service 657 * 658 * @return whether init success 659 */ 660 bool Init(); 661 662 /** 663 * Register Handler 664 */ 665 void RegisterCoreServiceHandler(); 666 667 /** 668 * Create Handler 669 */ 670 void CreateHandler(); 671 672 /** 673 * Handler Reset UnRegister 674 */ 675 void HandlerResetUnRegister(); 676 677 /** 678 * SendEventRegisterHandler 679 */ 680 void SendEventRegisterHandler(); 681 682 /** 683 * Is Valid Slot Id 684 * 685 * @param slotId 686 * @return bool 687 */ 688 bool IsValidSlotId(int32_t slotId) const; 689 690 /** 691 * Check whether IMS should be used firstly for emergency call 692 */ 693 bool UseImsForEmergency(const CellularCallInfo &callInfo, bool isEcc); 694 695 /** 696 * Handle CallManager exception 697 */ 698 void HandleCallManagerException(); 699 700 void HangUpWithCellularCallRestart(const std::vector<CellularCallInfo> &infos); 701 702 int32_t SetControl(const CellularCallInfo &info); 703 704 int32_t DialNormalCall(const CellularCallInfo &callInfo, bool isEcc); 705 706 void HandleCellularControlException(const CellularCallInfo &callInfo); 707 708 CallReportInfo EncapsulationCallReportInfo(const CellularCallInfo &callInfo); 709 710 private: 711 enum class SatelliteState { 712 SATELLITE_OFF, 713 SATELLITE_ON, 714 }; 715 716 int64_t bindTime_ = 0L; 717 int64_t endTime_ = 0L; 718 int64_t spendTime_ = 0L; 719 ServiceRunningState state_; 720 std::mutex handlerMapMutex_; 721 std::map<int32_t, std::shared_ptr<CellularCallHandler>> handlerMap_; 722 int32_t srvccState_ = SrvccState::SRVCC_NONE; 723 std::map<int32_t, std::shared_ptr<CSControl>> csControlMap_; 724 std::map<int32_t, std::shared_ptr<IMSControl>> imsControlMap_; 725 std::map<int32_t, std::shared_ptr<SatelliteControl>> satelliteControlMap_; 726 sptr<NetworkSearchCallBackBase> networkSearchCallBack_; 727 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 728 sptr<ISystemAbilityStatusChange> callManagerListener_ = nullptr; 729 std::mutex mutex_; 730 731 private: 732 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 733 public: 734 SystemAbilityStatusChangeListener() = default; 735 explicit SystemAbilityStatusChangeListener(std::shared_ptr<CellularCallHandler> &cellularCallHandler); 736 ~SystemAbilityStatusChangeListener() = default; 737 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 738 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 739 740 private: 741 std::shared_ptr<CellularCallHandler> cellularCallHandler_ = nullptr; 742 int32_t count_ = 0; 743 }; 744 }; 745 } // namespace Telephony 746 } // namespace OHOS 747 748 #endif // CELLULAR_CALL_SERVICE_H 749