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