1 /* 2 * Copyright (C) 2021-2025 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_STATUS_MANAGER_H 17 #define CALL_STATUS_MANAGER_H 18 19 #include <map> 20 21 #include "refbase.h" 22 23 #include "common_type.h" 24 #include "call_status_policy.h" 25 #include "call_incoming_filter_manager.h" 26 #include "time_wait_helper.h" 27 #include "voip_call_manager_info.h" 28 29 /** 30 * Singleton 31 * @ClassName:CallStatusManager 32 * @Description:CallStatusManager is designed for watching call state changes, 33 * when call state changes, cellularcall will notify callstatusmanager to handle it. 34 * call state: idle,disconnected, disconnecting,dialing,alerting,active,holding,waiting 35 * incoming 36 */ 37 namespace OHOS { 38 namespace Telephony { 39 const int32_t SLOT_NUM = 2; 40 const std::string ANTIFRAUD_FEATURE = "const.telephony.antifraud.supported"; 41 constexpr int32_t DEVICE_PROVISION_UNDEF = -1; 42 constexpr int32_t DEVICE_PROVISION_INVALID = 0; 43 constexpr int32_t DEVICE_PROVISION_VALID = 1; 44 45 class OOBEStatusObserver : public AAFwk::DataAbilityObserverStub { 46 public: 47 OOBEStatusObserver() = default; 48 ~OOBEStatusObserver() = default; 49 void OnChange() override; 50 }; 51 52 class CallStatusManager : public CallStatusPolicy { 53 public: 54 CallStatusManager(); 55 ~CallStatusManager(); 56 int32_t Init(); 57 int32_t UnInit(); 58 int32_t HandleCallReportInfo(const CallDetailInfo &info); 59 void HandleDsdaInfo(int32_t slotId); 60 int32_t HandleCallsReportInfo(const CallDetailsInfo &info); 61 int32_t HandleDisconnectedCause(const DisconnectedDetails &details); 62 int32_t HandleEventResultReportInfo(const CellularCallEventInfo &info); 63 int32_t HandleOttEventReportInfo(const OttCallEventInfo &info); 64 int32_t HandleVoipCallReportInfo(const CallDetailInfo &info); 65 void CallFilterCompleteResult(const CallDetailInfo &info); 66 int32_t HandleVoipEventReportInfo(const VoipCallEventInfo &info); 67 void HandleCeliaCall(sptr<CallBase> &call); 68 void TriggerAntiFraud(int32_t antiFraudState); 69 int32_t GetAntiFraudSlotId(); 70 int32_t GetAntiFraudIndex(); 71 static int32_t GetDevProvisioned(); 72 static void RegisterObserver(); 73 static void UpdateDevProvisioned(); 74 75 private: 76 void InitCallBaseEvent(); 77 int32_t IncomingHandle(const CallDetailInfo &info); 78 int32_t IncomingVoipCallHandle(const CallDetailInfo &info); 79 int32_t OutgoingVoipCallHandle(const CallDetailInfo &info); 80 int32_t AnsweredVoipCallHandle(const CallDetailInfo &info); 81 int32_t DisconnectingVoipCallHandle(const CallDetailInfo &info); 82 int32_t DialingHandle(const CallDetailInfo &info); 83 int32_t ActiveHandle(const CallDetailInfo &info); 84 int32_t ActiveVoipCallHandle(const CallDetailInfo &info); 85 int32_t HoldingHandle(const CallDetailInfo &info); 86 int32_t WaitingHandle(const CallDetailInfo &info); 87 int32_t AlertHandle(const CallDetailInfo &info); 88 int32_t DisconnectingHandle(const CallDetailInfo &info); 89 int32_t DisconnectedVoipCallHandle(const CallDetailInfo &info); 90 int32_t DisconnectedHandle(const CallDetailInfo &info); 91 void HandleHoldCallOrAutoAnswerCall(const sptr<CallBase> call, 92 std::vector<std::u16string> callIdList, CallRunningState previousState, TelCallState priorState); 93 void IsCanUnHold(int32_t activeCallNum, int32_t waitingCallNum, int32_t size, bool &canUnHold); 94 void AutoAnswer(int32_t activeCallNum, int32_t waitingCallNum); 95 void AutoHandleForDsda( 96 bool canSwitchCallState, TelCallState priorState, int32_t activeCallNum, int32_t slotId, bool continueAnswer); 97 void AutoAnswerForVoiceCall(sptr<CallBase> ringCall, int32_t slotId, bool continueAnswer); 98 void AutoAnswerForVideoCall(int32_t activeCallNum); 99 void AutoUnHoldForDsda(bool canSwitchCallState, TelCallState priorState, int32_t activeCallNum, int32_t slotId); 100 sptr<CallBase> CreateNewCall(const CallDetailInfo &info, CallDirection dir); 101 sptr<CallBase> CreateNewCallByCallType( 102 DialParaInfo ¶Info, const CallDetailInfo &info, CallDirection dir, AppExecFwk::PacMap &extras); 103 sptr<CallBase> CreateNewCallByCallTypeEx( 104 DialParaInfo ¶Info, const CallDetailInfo &info, CallDirection dir, AppExecFwk::PacMap &extras); 105 sptr<CallBase> RefreshCallIfNecessary(const sptr<CallBase> &call, const CallDetailInfo &info); 106 void SetOriginalCallTypeForActiveState(sptr<CallBase> &call); 107 void SetOriginalCallTypeForDisconnectState(sptr<CallBase> &call); 108 void PackParaInfo( 109 DialParaInfo ¶Info, const CallDetailInfo &info, CallDirection dir, AppExecFwk::PacMap &extras); 110 int32_t UpdateCallState(sptr<CallBase> &call, TelCallState nextState); 111 int32_t ToSpeakerPhone(sptr<CallBase> &call); 112 int32_t TurnOffMute(sptr<CallBase> &call); 113 int32_t IncomingFilterPolicy(const CallDetailInfo &info); 114 void QueryCallerInfo(ContactInfo &contactInfo, std::string phoneNum); 115 void SetAntiFraudSlotId(int32_t slotId); 116 void SetAntiFraudIndex(int32_t index); 117 void SetupAntiFraudService(const sptr<CallBase> &call, const CallDetailInfo &info); 118 void StopAntiFraudDetect(sptr<CallBase> &call, const CallDetailInfo &info); 119 void UpdateAntiFraudState(sptr<CallBase> &call, int32_t antiFraudState); 120 bool IsContactPhoneNum(const std::string &phoneNum); 121 void HandleVideoCallInAdvsecMode(const sptr<CallBase> &call, const CallDetailInfo &info); 122 bool IsTrustedNumber(MarkType markType, std::string phoneNumber); 123 int32_t UpdateDialingCallInfo(const CallDetailInfo &info); 124 void SetContactInfo(sptr<CallBase> &call, std::string phoneNum); 125 bool SetBluetoothCallContactInfo(sptr<CallBase> &call, ContactInfo &contactInfo, std::string phoneNum); 126 int32_t HandleRejectCall(sptr<CallBase> &call, bool isBlock); 127 bool ShouldRejectIncomingCall(); 128 bool ShouldBlockIncomingCall(const sptr<CallBase> &call, const CallDetailInfo &info); 129 bool IsRingOnceCall(const sptr<CallBase> &call, const CallDetailInfo &info); 130 int32_t HandleRingOnceCall(sptr<CallBase> &call); 131 void CarrierAndVoipConflictProcess(int32_t callId); 132 void SetVideoCallState(sptr<CallBase> &call, TelCallState nextState); 133 bool IsFocusModeOpen(); 134 bool IsRejectCall(sptr<CallBase> &call, const CallDetailInfo &info, bool &block); 135 void CreateAndSaveNewCall(const CallDetailInfo &info, CallDirection direction); 136 int32_t UpdateCallStateAndHandleDsdsMode(const CallDetailInfo &info, sptr<CallBase> &call); 137 bool IsDcCallConneceted(); 138 void HandleDialWhenHolding(int32_t callId, sptr<CallBase> &call); 139 void SetConferenceCall(std::vector<sptr<CallBase>>); 140 std::vector<sptr<CallBase>> GetConferenceCallList(int32_t slotId); 141 void UpdateCallDetailsInfo(const CallDetailsInfo &info); 142 bool IsDistributeCallSourceStatus(); 143 void HandleBluetoothCallReportInfo(const CallDetailInfo &info); 144 void SetBtCallDialByPhone(const sptr<CallBase> &call, bool isBtCallDialByPhone); 145 void BtCallDialingHandle(sptr<CallBase> &call, const CallDetailInfo &info); 146 void SetDistributedDeviceDialing(sptr<CallBase> call, bool isDistributedDeviceDialing); 147 void BtCallDialingHandleFirst(sptr<CallBase> call, const CallDetailInfo &infol); 148 int32_t HandleCallReportInfoEx(const CallDetailInfo &info); 149 void ClearPendingState(sptr<CallBase> &call); 150 void RefreshCallDisconnectReason(const sptr<CallBase> &call, int32_t reason, const std::string &message); 151 #ifdef NOT_SUPPORT_MULTICALL 152 void AutoAnswerSecondCall(); 153 #endif 154 bool IsFromTheSameNumberAtTheSameTime(const sptr<CallBase> &newCall); 155 void ModifyEsimType(); 156 int32_t RefreshOldCall(const CallDetailInfo &info, bool &isExistedOldCall); 157 bool IsCallMotionRecognitionEnable(const std::string &key); 158 void StartInComingCallMotionRecognition(); 159 void StartOutGoingCallMotionRecognition(); 160 void StopCallMotionRecognition(TelCallState nextState); 161 bool UpdateDialingHandle(const CallDetailInfo &info, bool &isDistributedDeviceDialing); 162 bool RefreshDialingStateByOtherState(sptr<CallBase> &call, const CallDetailInfo &info); 163 164 private: 165 CallDetailInfo callReportInfo_; 166 CallDetailsInfo callDetailsInfo_[SLOT_NUM]; 167 CallDetailsInfo tmpCallDetailsInfo_[SLOT_NUM]; 168 void HandleConnectingCallReportInfo(const CallDetailInfo &info); 169 sptr<CallIncomingFilterManager> CallIncomingFilterManagerPtr_; 170 std::map<RequestResultEventId, CallAbilityEventId> mEventIdTransferMap_; 171 std::map<OttCallEventId, CallAbilityEventId> mOttEventIdTransferMap_; 172 VideoStateType priorVideoState_[SLOT_NUM] = {VideoStateType::TYPE_VOICE}; 173 const std::string DETAIL_INFO = "detail_info"; 174 const std::string FORMAT_PHONE_NUMBER = "format_phone_number"; 175 const std::string CONTENT_TYPE = "content_type"; 176 const std::string PHONE = "phone"; 177 const std::string TYPE_ID = "type_id"; 178 const std::string IS_DELETED = "is_deleted"; 179 const int32_t CALL_NUMBER = 2; 180 std::unique_ptr<TimeWaitHelper> timeWaitHelper_ {nullptr}; 181 std::chrono::system_clock::time_point detectStartTime = std::chrono::system_clock::from_time_t(0); 182 int32_t antiFraudSlotId_ = -1; 183 int32_t antiFraudIndex_ = -1; 184 ffrt::mutex mutex_; 185 static sptr<OOBEStatusObserver> oobeStatusObserver_; 186 static int32_t deviceProvisioned_; 187 }; 188 } // namespace Telephony 189 } // namespace OHOS 190 191 #endif // CALL_STATUS_MANAGER_H 192