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