• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "pac_map.h"
25 #include "singleton.h"
26 #include "call_broadcast_subscriber.h"
27 #include "call_setting_manager.h"
28 #include "call_policy.h"
29 #include "call_state_listener.h"
30 #include "call_request_handler.h"
31 #include "missed_call_notification.h"
32 #include "incoming_call_wake_up.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 public:
46     bool Init();
47     int32_t DialCall(std::u16string &number, AppExecFwk::PacMap &extras);
48     int32_t AnswerCall(int32_t callId, int32_t videoState);
49     int32_t RejectCall(int32_t callId, bool rejectWithMessage, std::u16string textMessage);
50     int32_t HangUpCall(int32_t callId);
51     int32_t GetCallState();
52     int32_t HoldCall(int32_t callId);
53     int32_t UnHoldCall(int32_t callId);
54     int32_t SwitchCall(int32_t callId);
55     bool HasCall();
56     int32_t IsNewCallAllowed(bool &enabled);
57     int32_t IsRinging(bool &enabled);
58     int32_t HasEmergency(bool &enabled);
59     bool NotifyNewCallCreated(sptr<CallBase> &callObjectPtr);
60     bool NotifyCallDestroyed(const DisconnectedDetails &details);
61     bool NotifyCallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState);
62     bool NotifyIncomingCallAnswered(sptr<CallBase> &callObjectPtr);
63     bool NotifyIncomingCallRejected(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content);
64     bool NotifyCallEventUpdated(CallEventInfo &info);
65     int32_t StartDtmf(int32_t callId, char str);
66     int32_t StopDtmf(int32_t callId);
67     int32_t GetCallWaiting(int32_t slotId);
68     int32_t SetCallWaiting(int32_t slotId, bool activate);
69     int32_t GetCallRestriction(int32_t slotId, CallRestrictionType type);
70     int32_t SetCallRestriction(int32_t slotId, CallRestrictionInfo &info);
71     int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type);
72     int32_t SetCallTransferInfo(int32_t slotId, CallTransferInfo &info);
73     int32_t SetCallPreferenceMode(int32_t slotId, int32_t mode);
74     // merge calls
75     int32_t CombineConference(int32_t mainCallId);
76     int32_t SeparateConference(int32_t callId);
77     int32_t GetMainCallId(int32_t callId, int32_t &mainCallId);
78     int32_t GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList);
79     int32_t GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList);
80     int32_t GetImsConfig(int32_t slotId, ImsConfigItem item);
81     int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value);
82     int32_t GetImsFeatureValue(int32_t slotId, FeatureType type);
83     int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value);
84     int32_t EnableImsSwitch(int32_t slotId);
85     int32_t DisableImsSwitch(int32_t slotId);
86     int32_t IsImsSwitchEnabled(int32_t slotId, bool &enabled);
87     int32_t UpdateImsCallMode(int32_t callId, ImsCallMode mode);
88     int32_t StartRtt(int32_t callId, std::u16string &msg);
89     int32_t StopRtt(int32_t callId);
90     // invite calls to participate conference
91     int32_t JoinConference(int32_t callId, std::vector<std::u16string> &numberList);
92     int32_t SetMuted(bool isMute);
93     int32_t MuteRinger();
94     int32_t SetAudioDevice(AudioDevice deviceType, const std::string &bluetoothAddress);
95     int32_t ControlCamera(std::u16string cameraId, int32_t callingUid, int32_t callingPid);
96     int32_t SetPreviewWindow(VideoWindow &window);
97     int32_t SetDisplayWindow(VideoWindow &window);
98     int32_t SetCameraZoom(float zoomRatio);
99     int32_t SetPausePicture(std::u16string path);
100     int32_t SetDeviceDirection(int32_t rotation);
101     int32_t IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled);
102     int32_t FormatPhoneNumber(std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber);
103     int32_t FormatPhoneNumberToE164(
104         std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber);
105     void GetDialParaInfo(DialParaInfo &info);
106     void GetDialParaInfo(DialParaInfo &info, AppExecFwk::PacMap &extras);
107 
108 private:
109     void CallStateObserve();
110     int32_t NumberLegalityCheck(std::string &number);
111     int32_t BroadcastSubscriber();
112 
113 private:
114     class SystemAbilityListener : public SystemAbilityStatusChangeStub {
115     public:
116         explicit SystemAbilityListener(std::shared_ptr<CallBroadcastSubscriber> subscriberPtr);
117         ~SystemAbilityListener() = default;
118         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
119         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
120 
121     private:
122         std::shared_ptr<CallBroadcastSubscriber> subscriberPtr_;
123     };
124 
125 private:
126     std::unique_ptr<CallStateListener> callStateListenerPtr_;
127     std::unique_ptr<CallRequestHandlerService> callRequestHandlerServicePtr_;
128     // notify when incoming calls are ignored, not rejected or answered
129     std::shared_ptr<IncomingCallWakeup> incomingCallWakeup_;
130     std::shared_ptr<MissedCallNotification> missedCallNotification_;
131     std::unique_ptr<CallSettingManager> callSettingManagerPtr_;
132     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
133     DialParaInfo dialSrcInfo_;
134     AppExecFwk::PacMap extras_;
135     std::mutex mutex_;
136 };
137 } // namespace Telephony
138 } // namespace OHOS
139 #endif // CALL_CONTROL_MANAGER_H
140