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 "app_state_observer.h" 25 #include "call_broadcast_subscriber.h" 26 #include "call_policy.h" 27 #include "call_request_handler.h" 28 #include "call_setting_manager.h" 29 #include "call_state_listener.h" 30 #include "incoming_call_wake_up.h" 31 #include "missed_call_notification.h" 32 #include "pac_map.h" 33 #include "singleton.h" 34 #include "system_ability_status_change_stub.h" 35 #include "ffrt.h" 36 37 /** 38 * Singleton 39 * @ClassName:CallControlManager 40 * @Description:CallControlManager is designed for performing dial/answer/reject etc ops 41 * on kinds of calls(ims,cs,ott). usually as an entrance for downflowed [app->ril] telephony business 42 */ 43 namespace OHOS { 44 namespace Telephony { 45 constexpr const char *KEY_CONST_TELEPHONY_READ_SET_VOIP_CALL_INFO = 46 "const.telephony.read_set_voip_call_info"; 47 class CallControlManager : public CallPolicy { 48 DECLARE_DELAYED_SINGLETON(CallControlManager) 49 50 public: 51 bool Init(); 52 void UnInit(); 53 int32_t DialCall(std::u16string &number, AppExecFwk::PacMap &extras); 54 int32_t AnswerCall(int32_t callId, int32_t videoState); 55 int32_t HandlerAnswerCall(int32_t callId, int32_t videoState); 56 int32_t RejectCall(int32_t callId, bool rejectWithMessage, std::u16string textMessage); 57 int32_t HangUpCall(int32_t callId); 58 int32_t GetCallState(); 59 int32_t HoldCall(int32_t callId); 60 int32_t UnHoldCall(int32_t callId); 61 int32_t SwitchCall(int32_t callId); 62 bool HasCall(); 63 bool HasVoipCall(); 64 int32_t GetMeetimeCallState(); 65 int32_t IsNewCallAllowed(bool &enabled); 66 int32_t IsRinging(bool &enabled); 67 int32_t HasEmergency(bool &enabled); 68 bool NotifyNewCallCreated(sptr<CallBase> &callObjectPtr); 69 bool NotifyCallDestroyed(const DisconnectedDetails &details); 70 bool NotifyCallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState); 71 bool NotifyVoipCallStateUpdated(CallAttributeInfo info, TelCallState priorState, TelCallState nextState); 72 bool NotifyIncomingCallAnswered(sptr<CallBase> &callObjectPtr); 73 bool NotifyIncomingCallRejected(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content); 74 bool NotifyCallEventUpdated(CallEventInfo &info); 75 int32_t StartDtmf(int32_t callId, char str); 76 int32_t StopDtmf(int32_t callId); 77 int32_t PostDialProceed(int32_t callId, bool proceed); 78 int32_t GetCallWaiting(int32_t slotId); 79 int32_t SetCallWaiting(int32_t slotId, bool activate); 80 int32_t GetCallRestriction(int32_t slotId, CallRestrictionType type); 81 int32_t SetCallRestriction(int32_t slotId, CallRestrictionInfo &info); 82 int32_t SetCallRestrictionPassword( 83 int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword); 84 int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type); 85 int32_t SetCallTransferInfo(int32_t slotId, CallTransferInfo &info); 86 int32_t CanSetCallTransferTime(int32_t slotId, bool &result); 87 int32_t SetCallPreferenceMode(int32_t slotId, int32_t mode); 88 // merge calls 89 int32_t CombineConference(int32_t mainCallId); 90 int32_t SeparateConference(int32_t callId); 91 int32_t KickOutFromConference(int32_t callId); 92 int32_t GetMainCallId(int32_t callId, int32_t &mainCallId); 93 int32_t GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList); 94 int32_t GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList); 95 int32_t GetImsConfig(int32_t slotId, ImsConfigItem item); 96 int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value); 97 int32_t GetImsFeatureValue(int32_t slotId, FeatureType type); 98 int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value); 99 int32_t EnableImsSwitch(int32_t slotId); 100 int32_t DisableImsSwitch(int32_t slotId); 101 int32_t IsImsSwitchEnabled(int32_t slotId, bool &enabled); 102 int32_t SetVoNRState(int32_t slotId, int32_t state); 103 int32_t GetVoNRState(int32_t slotId, int32_t &state); 104 int32_t UpdateImsCallMode(int32_t callId, ImsCallMode mode); 105 int32_t StartRtt(int32_t callId, std::u16string &msg); 106 int32_t StopRtt(int32_t callId); 107 // invite calls to participate conference 108 int32_t JoinConference(int32_t callId, std::vector<std::u16string> &numberList); 109 int32_t SetMuted(bool isMute); 110 int32_t MuteRinger(); 111 int32_t SetAudioDevice(const AudioDevice &audioDevice); 112 int32_t ControlCamera(std::u16string cameraId, int32_t callingUid, int32_t callingPid); 113 int32_t SetPreviewWindow(VideoWindow &window); 114 int32_t SetDisplayWindow(VideoWindow &window); 115 int32_t SetCameraZoom(float zoomRatio); 116 int32_t SetPausePicture(std::u16string path); 117 int32_t SetDeviceDirection(int32_t rotation); 118 int32_t IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled); 119 int32_t FormatPhoneNumber(std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber); 120 int32_t FormatPhoneNumberToE164( 121 std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber); 122 int32_t CloseUnFinishedUssd(int32_t slotId); 123 void GetDialParaInfo(DialParaInfo &info); 124 void GetDialParaInfo(DialParaInfo &info, AppExecFwk::PacMap &extras); 125 void ConnectCallUiService(bool shouldConnect); 126 bool ShouldDisconnectService(); 127 int32_t RemoveMissedIncomingCallNotification(); 128 int32_t SetVoIPCallState(int32_t state); 129 int32_t GetVoIPCallState(int32_t &state); 130 int32_t SetVoIPCallInfo(int32_t callId, int32_t state, std::string phoneNumber); 131 int32_t GetVoIPCallInfo(int32_t &callId, int32_t &state, std::string &phoneNumber); 132 int32_t AddCallLogAndNotification(sptr<CallBase> &callObjectPtr); 133 int32_t AddBlockLogAndNotification(sptr<CallBase> &callObjectPtr); 134 int32_t HangUpVoipCall(); 135 int32_t CarrierAndVoipConflictProcess(int32_t callId, TelCallState callState); 136 void AcquireIncomingLock(); 137 void ReleaseIncomingLock(); 138 void DisconnectAllCalls(); 139 #ifdef NOT_SUPPORT_MULTICALL 140 bool HangUpFirstCallBtAndESIM(int32_t secondCallId); 141 bool HangUpFirstCallBtCall(int32_t secondCallId); 142 bool HangUpFirstCallESIMCall(int32_t secondCallId); 143 bool HangUpFirstCall(int32_t secondCallId); 144 void HangUpFirstCallBySecondCallID(int32_t secondCallId, bool secondAutoAnswer = false); 145 #endif 146 private: 147 void CallStateObserve(); 148 int32_t NumberLegalityCheck(std::string &number); 149 int32_t SubscriberSaStateChange(); 150 void ReportPhoneUEInSuperPrivacy(const std::string &eventName); 151 void PackageDialInformation(AppExecFwk::PacMap &extras, std::string accountNumber, bool isEcc); 152 static void handler(); 153 bool cancel(ffrt::task_handle &handle); 154 int32_t CanDial(std::u16string &number, AppExecFwk::PacMap &extras, bool isEcc); 155 void AnswerHandlerForSatelliteOrVideoCall(sptr<CallBase> &call, int32_t videoState); 156 bool CurrentIsSuperPrivacyMode(int32_t callId, int32_t videoState); 157 void AppStateObserver(); 158 void SetCallTypeExtras(AppExecFwk::PacMap &extras); 159 void HandleVoipConnected(int32_t &numActive, int32_t callId); 160 void HandleVoipIncoming(int32_t &numActive, int32_t callId, const std::string phoneNumber); 161 int32_t HandleVoipDisconnected(int32_t &numActive, int32_t numHeld, int32_t callId, 162 int32_t state, const std::string phoneNumber); 163 void HandleVoipAlerting(int32_t callId, const std::string phoneNumber); 164 bool IsSupportSetVoipInfo(); 165 void SetVoipCallInfoInner(const int32_t callId, const int32_t state, 166 const std::string phoneNumber); 167 void sendEventToVoip(CallAbilityEventId eventId); 168 private: 169 class SystemAbilityListener : public SystemAbilityStatusChangeStub { 170 public: 171 explicit SystemAbilityListener(); 172 ~SystemAbilityListener() = default; 173 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 174 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 175 176 private: 177 int32_t CommonBroadcastSubscriber(); 178 int32_t ContactsBroadcastSubscriber(); 179 int32_t SatcommBroadcastSubscriber(); 180 int32_t SuperPrivacyModeBroadcastSubscriber(); 181 int32_t HSDRBroadcastSubscriber(); 182 int32_t HfpBroadcastSubscriber(); 183 184 private: 185 std::vector<std::shared_ptr<CallBroadcastSubscriber>> subscriberPtrList_; 186 }; 187 188 private: 189 std::unique_ptr<CallStateListener> callStateListenerPtr_; 190 std::unique_ptr<CallRequestHandler> CallRequestHandlerPtr_; 191 // notify when incoming calls are ignored, not rejected or answered 192 std::shared_ptr<IncomingCallWakeup> incomingCallWakeup_; 193 std::shared_ptr<MissedCallNotification> missedCallNotification_; 194 std::unique_ptr<CallSettingManager> callSettingManagerPtr_; 195 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 196 DialParaInfo dialSrcInfo_; 197 AppExecFwk::PacMap extras_; 198 std::mutex mutex_; 199 CallStateToApp VoIPCallState_ = CallStateToApp::CALL_STATE_IDLE; 200 bool shouldDisconnect = true; 201 static bool alarmSeted; 202 struct AnsweredCallQueue { 203 bool hasCall = false; 204 int32_t callId = 0; 205 int32_t videoState = 0; 206 } AnsweredCallQueue_; 207 208 struct VoipCallInfo { 209 int32_t callId = 10000; 210 int32_t state = 0; 211 std::string phoneNumber = ""; 212 } VoipCallInfo_; 213 214 ffrt::task_handle disconnectHandle = nullptr; 215 sptr<ApplicationStateObserver> appStateObserver = nullptr; 216 sptr<AppExecFwk::IAppMgr> appMgrProxy = nullptr; 217 218 std::mutex voipMutex_; 219 }; 220 } // namespace Telephony 221 } // namespace OHOS 222 #endif // CALL_CONTROL_MANAGER_H 223