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_CONTROL_MANAGER_H 17 #define CALL_CONTROL_MANAGER_H 18 19 #include <cstring> 20 #include <list> 21 #include <memory> 22 #include <mutex> 23 24 #include "call_broadcast_subscriber.h" 25 #include "call_policy.h" 26 #include "call_request_handler.h" 27 #include "call_setting_manager.h" 28 #include "call_state_listener.h" 29 #include "incoming_call_wake_up.h" 30 #include "missed_call_notification.h" 31 #include "pac_map.h" 32 #include "singleton.h" 33 #include "system_ability_status_change_stub.h" 34 35 /** 36 * Singleton 37 * @ClassName:CallControlManager 38 * @Description:CallControlManager is designed for performing dial/answer/reject etc ops 39 * on kinds of calls(ims,cs,ott). usually as an entrance for downflowed [app->ril] telephony business 40 */ 41 namespace OHOS { 42 namespace Telephony { 43 class CallControlManager : public CallPolicy { 44 DECLARE_DELAYED_SINGLETON(CallControlManager) 45 46 public: 47 bool Init(); 48 int32_t DialCall(std::u16string &number, AppExecFwk::PacMap &extras); 49 int32_t AnswerCall(int32_t callId, int32_t videoState); 50 int32_t RejectCall(int32_t callId, bool rejectWithMessage, std::u16string textMessage); 51 int32_t HangUpCall(int32_t callId); 52 int32_t GetCallState(); 53 int32_t HoldCall(int32_t callId); 54 int32_t UnHoldCall(int32_t callId); 55 int32_t SwitchCall(int32_t callId); 56 bool HasCall(); 57 int32_t IsNewCallAllowed(bool &enabled); 58 int32_t IsRinging(bool &enabled); 59 int32_t HasEmergency(bool &enabled); 60 bool NotifyNewCallCreated(sptr<CallBase> &callObjectPtr); 61 bool NotifyCallDestroyed(const DisconnectedDetails &details); 62 bool NotifyCallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState); 63 bool NotifyIncomingCallAnswered(sptr<CallBase> &callObjectPtr); 64 bool NotifyIncomingCallRejected(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content); 65 bool NotifyCallEventUpdated(CallEventInfo &info); 66 int32_t StartDtmf(int32_t callId, char str); 67 int32_t StopDtmf(int32_t callId); 68 int32_t PostDialProceed(int32_t callId, bool proceed); 69 int32_t GetCallWaiting(int32_t slotId); 70 int32_t SetCallWaiting(int32_t slotId, bool activate); 71 int32_t GetCallRestriction(int32_t slotId, CallRestrictionType type); 72 int32_t SetCallRestriction(int32_t slotId, CallRestrictionInfo &info); 73 int32_t SetCallRestrictionPassword( 74 int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword); 75 int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type); 76 int32_t SetCallTransferInfo(int32_t slotId, CallTransferInfo &info); 77 int32_t CanSetCallTransferTime(int32_t slotId, bool &result); 78 int32_t SetCallPreferenceMode(int32_t slotId, int32_t mode); 79 // merge calls 80 int32_t CombineConference(int32_t mainCallId); 81 int32_t SeparateConference(int32_t callId); 82 int32_t KickOutFromConference(int32_t callId); 83 int32_t GetMainCallId(int32_t callId, int32_t &mainCallId); 84 int32_t GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList); 85 int32_t GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList); 86 int32_t GetImsConfig(int32_t slotId, ImsConfigItem item); 87 int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value); 88 int32_t GetImsFeatureValue(int32_t slotId, FeatureType type); 89 int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value); 90 int32_t EnableImsSwitch(int32_t slotId); 91 int32_t DisableImsSwitch(int32_t slotId); 92 int32_t IsImsSwitchEnabled(int32_t slotId, bool &enabled); 93 int32_t SetVoNRState(int32_t slotId, int32_t state); 94 int32_t GetVoNRState(int32_t slotId, int32_t &state); 95 int32_t UpdateImsCallMode(int32_t callId, ImsCallMode mode); 96 int32_t StartRtt(int32_t callId, std::u16string &msg); 97 int32_t StopRtt(int32_t callId); 98 // invite calls to participate conference 99 int32_t JoinConference(int32_t callId, std::vector<std::u16string> &numberList); 100 int32_t SetMuted(bool isMute); 101 int32_t MuteRinger(); 102 int32_t SetAudioDevice(const AudioDevice &audioDevice); 103 int32_t ControlCamera(std::u16string cameraId, int32_t callingUid, int32_t callingPid); 104 int32_t SetPreviewWindow(VideoWindow &window); 105 int32_t SetDisplayWindow(VideoWindow &window); 106 int32_t SetCameraZoom(float zoomRatio); 107 int32_t SetPausePicture(std::u16string path); 108 int32_t SetDeviceDirection(int32_t rotation); 109 int32_t IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled); 110 int32_t FormatPhoneNumber(std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber); 111 int32_t FormatPhoneNumberToE164( 112 std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber); 113 int32_t CloseUnFinishedUssd(int32_t slotId); 114 void GetDialParaInfo(DialParaInfo &info); 115 void GetDialParaInfo(DialParaInfo &info, AppExecFwk::PacMap &extras); 116 int32_t RemoveMissedIncomingCallNotification(); 117 int32_t SetVoIPCallState(int32_t state); 118 int32_t GetVoIPCallState(int32_t &state); 119 int32_t HangUpVoipCall(); 120 121 private: 122 void CallStateObserve(); 123 int32_t NumberLegalityCheck(std::string &number); 124 int32_t BroadcastSubscriber(); 125 void PackageDialInformation(AppExecFwk::PacMap &extras, std::string accountNumber, bool isEcc); 126 127 private: 128 class SystemAbilityListener : public SystemAbilityStatusChangeStub { 129 public: 130 explicit SystemAbilityListener(std::shared_ptr<CallBroadcastSubscriber> subscriberPtr); 131 ~SystemAbilityListener() = default; 132 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 133 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 134 135 private: 136 std::shared_ptr<CallBroadcastSubscriber> subscriberPtr_; 137 }; 138 139 private: 140 std::unique_ptr<CallStateListener> callStateListenerPtr_; 141 std::unique_ptr<CallRequestHandler> CallRequestHandlerPtr_; 142 // notify when incoming calls are ignored, not rejected or answered 143 std::shared_ptr<IncomingCallWakeup> incomingCallWakeup_; 144 std::shared_ptr<MissedCallNotification> missedCallNotification_; 145 std::unique_ptr<CallSettingManager> callSettingManagerPtr_; 146 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 147 DialParaInfo dialSrcInfo_; 148 AppExecFwk::PacMap extras_; 149 std::mutex mutex_; 150 CallStateToApp VoIPCallState_ = CallStateToApp::CALL_STATE_IDLE; 151 struct AnsweredCallQueue { 152 bool hasCall = false; 153 int32_t callId = 0; 154 int32_t videoState = 0; 155 } AnsweredCallQueue_; 156 }; 157 } // namespace Telephony 158 } // namespace OHOS 159 #endif // CALL_CONTROL_MANAGER_H 160