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 Update Call Media Mode 222 * 223 * @param CellularCallInfo 224 * @param ImsCallMode 225 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 226 */ 227 int32_t UpdateImsCallMode(const CellularCallInfo &callInfo, ImsCallMode mode) override; 228 229 /** 230 * Register CallManager CallBack 231 * 232 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 233 */ 234 int32_t RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback) override; 235 236 /** 237 * UnRegister CallManager CallBack 238 * 239 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 240 */ 241 int32_t UnRegisterCallManagerCallBack() override; 242 243 /** 244 * StartDtmf 245 * 246 * @param Dtmf Code 247 * @param CellularCallInfo 248 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 249 */ 250 int32_t StartDtmf(char cDtmfCode, const CellularCallInfo &callInfo) override; 251 252 /** 253 * StopDtmf 254 * 255 * @param CellularCallInfo 256 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 257 */ 258 int32_t StopDtmf(const CellularCallInfo &callInfo) override; 259 260 int32_t PostDialProceed(const CellularCallInfo &callInfo, const bool proceed) override; 261 262 /** 263 * SendDtmf 264 * 265 * @param Dtmf Code 266 * @param CellularCallInfo 267 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 268 */ 269 int32_t SendDtmf(char cDtmfCode, const CellularCallInfo &callInfo) override; 270 271 /** 272 * Start Rtt 273 * 274 * @param slotId 275 * @param msg 276 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 277 */ 278 int32_t StartRtt(int32_t slotId, const std::string &msg) override; 279 280 /** 281 * Stop Rtt 282 * 283 * @param slotId 284 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 285 */ 286 int32_t StopRtt(int32_t slotId) override; 287 288 /** 289 * Set Call Transfer 290 * 291 * @param slotId 292 * @param CallTransferInfo 293 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 294 */ 295 int32_t SetCallTransferInfo(int32_t slotId, const CallTransferInfo &cfInfo) override; 296 297 /** 298 * confirm whether IMS can set call transfer time. 299 * 300 * @param slotId[in], The slot id 301 * @param result[out], The result of can set or not 302 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 303 */ 304 int32_t CanSetCallTransferTime(int32_t slotId, bool &result) override; 305 306 /** 307 * Get Call Transfer 308 * 309 * @param slotId 310 * @param CallTransferType 311 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 312 */ 313 int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type) override; 314 315 /** 316 * Set Call Waiting 317 * 318 * @param slotId 319 * @param activate 320 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 321 */ 322 int32_t SetCallWaiting(int32_t slotId, bool activate) override; 323 324 /** 325 * Inquire Call Waiting 326 * 327 * @param slotId 328 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 329 */ 330 int32_t GetCallWaiting(int32_t slotId) override; 331 332 /** 333 * Set Call Restriction 334 * 335 * @param slotId 336 * @param CallRestrictionInfo 337 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 338 */ 339 int32_t SetCallRestriction(int32_t slotId, const CallRestrictionInfo &crInfo) override; 340 341 /** 342 * Inquire Call Restriction 343 * 344 * @param slotId 345 * @param CallRestrictionType 346 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 347 */ 348 int32_t GetCallRestriction(int32_t slotId, CallRestrictionType facType) override; 349 350 /** 351 * @brief Set the call restriction password of the specified account 352 * 353 * @param slotId[in] the slot id 354 * @param facType[in] indicate the call restriction type, just like all incoming, all outgoing .etc 355 * @param oldPassword[in] indicate the call restriction old password 356 * @param newPassword[in] indicate the call restriction new password 357 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 358 */ 359 int32_t SetCallRestrictionPassword( 360 int32_t slotId, CallRestrictionType facType, const char *oldPassword, const char *newPassword) override; 361 362 /** 363 * Set Domain Preference Mode 364 * 365 * @param slotId 366 * @param mode 367 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 368 */ 369 int32_t SetDomainPreferenceMode(int32_t slotId, int32_t mode) override; 370 371 /** 372 * Get Domain Preference Mode 373 * 374 * @param slotId 375 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 376 */ 377 int32_t GetDomainPreferenceMode(int32_t slotId) override; 378 379 /** 380 * Set Ims Switch Status 381 * 382 * @param slotId 383 * @param active 384 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 385 */ 386 int32_t SetImsSwitchStatus(int32_t slotId, bool active) override; 387 388 /** 389 * Get Ims Switch Status 390 * 391 * @param slotId 392 * @param enabled 393 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 394 */ 395 int32_t GetImsSwitchStatus(int32_t slotId, bool &enabled) override; 396 397 /** 398 * Set Ims Config 399 * 400 * @param slotId 401 * @param ImsConfigItem 402 * @param value 403 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 404 */ 405 int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, const std::string &value) override; 406 407 /** 408 * Set VoNR Switch State 409 * 410 * @param slotId 411 * @param state 412 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 413 */ 414 virtual int32_t SetVoNRState(int32_t slotId, int32_t state) override; 415 416 /** 417 * Get VoNR Switch State 418 * 419 * @param slotId 420 * @param state 421 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 422 */ 423 virtual int32_t GetVoNRState(int32_t slotId, int32_t &state) override; 424 425 /** 426 * Set Ims Config 427 * 428 * @param slotId 429 * @param ImsConfigItem 430 * @param value 431 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 432 */ 433 int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, int32_t value) override; 434 435 /** 436 * Get Ims Config 437 * 438 * @param slotId 439 * @param ImsConfigItem 440 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 441 */ 442 int32_t GetImsConfig(int32_t slotId, ImsConfigItem item) override; 443 444 /** 445 * Set Ims Feature Value 446 * 447 * @param slotId 448 * @param FeatureType 449 * @param value 450 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 451 */ 452 int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value) override; 453 454 /** 455 * Get Ims Feature Value 456 * 457 * @param slotId 458 * @param FeatureType 459 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 460 */ 461 int32_t GetImsFeatureValue(int32_t slotId, FeatureType type) override; 462 463 /** 464 * CtrlCamera 465 * 466 * @param cameraId 467 * @param callingUid 468 * @param callingPid 469 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 470 */ 471 int32_t CtrlCamera(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid) override; 472 473 /** 474 * SetPreviewWindow 475 * 476 * @param x 477 * @param y 478 * @param z 479 * @param width 480 * @param height 481 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 482 */ 483 int32_t SetPreviewWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height) override; 484 485 /** 486 * SetDisplayWindow 487 * 488 * @param x 489 * @param y 490 * @param z 491 * @param width 492 * @param height 493 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 494 */ 495 int32_t SetDisplayWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height) override; 496 497 /** 498 * SetCameraZoom 499 * 500 * @param zoomRatio 501 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 502 */ 503 int32_t SetCameraZoom(float zoomRatio) override; 504 505 /** 506 * SetPauseImage 507 * 508 * @param path 509 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 510 */ 511 int32_t SetPauseImage(const std::u16string &path) override; 512 513 /** 514 * SetDeviceDirection 515 * 516 * @param rotation 517 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 518 */ 519 int32_t SetDeviceDirection(int32_t rotation) override; 520 521 /** 522 * SetMute 523 * 524 * @param mute 525 * @param slotId 526 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 527 */ 528 int32_t SetMute(int32_t slotId, int32_t mute) override; 529 530 /** 531 * GetMute 532 * 533 * @param slotId 534 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 535 */ 536 int32_t GetMute(int32_t slotId) override; 537 538 /** 539 * Close Unfinished ussd 540 * 541 * @param slotId 542 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 543 */ 544 int32_t CloseUnFinishedUssd(int32_t slotId) override; 545 546 int32_t ClearAllCalls(const std::vector<CellularCallInfo> &infos) override; 547 548 /** 549 * Is need choose IMS for execute 550 * 551 * @param slotId 552 * @return bool 553 */ 554 bool IsNeedIms(int32_t slotId) const; 555 556 /** 557 * Get CSControl 558 * 559 * @param slotId 560 * @return shared_ptr CSControl 561 */ 562 std::shared_ptr<CSControl> GetCsControl(int32_t slotId); 563 564 /** 565 * Get IMControl 566 * 567 * @param slotId 568 * @return shared_ptr CSControl 569 */ 570 std::shared_ptr<IMSControl> GetImsControl(int32_t slotId); 571 572 /** 573 * Set SetCsControl 574 * 575 * @param slotId 576 * @param shared_ptr CSControl 577 */ 578 void SetCsControl(int32_t slotId, const std::shared_ptr<CSControl> &csControl); 579 580 /** 581 * Set IMSControl 582 * 583 * @param slotId 584 * @param shared_ptr IMSControl 585 */ 586 void SetImsControl(int32_t slotId, const std::shared_ptr<IMSControl> &imsControl); 587 588 /** 589 * Get Handler 590 * 591 * @param slotId 592 * @return CellularCallHandler 593 */ 594 std::shared_ptr<CellularCallHandler> GetHandler(int32_t slotId); 595 596 void SetSrvccState(int32_t srvccState); 597 598 int32_t GetSrvccState(); 599 600 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE 601 /** 602 * Get call manager service 603 */ 604 void StartCallManagerService(); 605 #endif 606 607 private: 608 /** 609 * Init service 610 * 611 * @return whether init success 612 */ 613 bool Init(); 614 615 /** 616 * Register Handler 617 */ 618 void RegisterCoreServiceHandler(); 619 620 /** 621 * Create Handler 622 */ 623 void CreateHandler(); 624 625 /** 626 * Handler Reset UnRegister 627 */ 628 void HandlerResetUnRegister(); 629 630 /** 631 * SendEventRegisterHandler 632 */ 633 void SendEventRegisterHandler(); 634 635 /** 636 * Is Valid Slot Id 637 * 638 * @param slotId 639 * @return bool 640 */ 641 bool IsValidSlotId(int32_t slotId) const; 642 643 /** 644 * Check whether IMS should be used firstly for emergency call 645 */ 646 bool UseImsForEmergency(const CellularCallInfo &callInfo, bool isEcc); 647 648 /** 649 * Handle CallManager exception 650 */ 651 void HandleCallManagerException(); 652 653 void HangUpWithCellularCallRestart(const std::vector<CellularCallInfo> &infos); 654 655 int32_t SetControl(const CellularCallInfo &info); 656 657 private: 658 int64_t bindTime_ = 0L; 659 int64_t endTime_ = 0L; 660 int64_t spendTime_ = 0L; 661 ServiceRunningState state_; 662 std::shared_ptr<AppExecFwk::EventRunner> eventLoop_; 663 std::map<int32_t, std::shared_ptr<CellularCallHandler>> handlerMap_; 664 int32_t srvccState_ = SrvccState::SRVCC_NONE; 665 std::map<int32_t, std::shared_ptr<CSControl>> csControlMap_; 666 std::map<int32_t, std::shared_ptr<IMSControl>> imsControlMap_; 667 sptr<NetworkSearchCallBackBase> networkSearchCallBack_; 668 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 669 sptr<ISystemAbilityStatusChange> callManagerListener_ = nullptr; 670 std::mutex mutex_; 671 672 private: 673 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 674 public: 675 SystemAbilityStatusChangeListener() = default; 676 explicit SystemAbilityStatusChangeListener(std::shared_ptr<CellularCallHandler> &cellularCallHandler); 677 ~SystemAbilityStatusChangeListener() = default; 678 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 679 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 680 681 private: 682 std::shared_ptr<CellularCallHandler> cellularCallHandler_ = nullptr; 683 int32_t count_ = 0; 684 }; 685 }; 686 } // namespace Telephony 687 } // namespace OHOS 688 689 #endif // CELLULAR_CALL_SERVICE_H 690