• 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_MANAGER_PROXY_H
17 #define CALL_MANAGER_PROXY_H
18 
19 #include <string_ex.h>
20 #include <mutex>
21 
22 #include "if_system_ability_manager.h"
23 #include "refbase.h"
24 #include "singleton.h"
25 #include "surface_utils.h"
26 #include "ffrt.h"
27 #include "pac_map.h"
28 
29 #include "i_call_manager_service.h"
30 #include "i_call_ability_callback.h"
31 #include "timer.h"
32 
33 #include "call_manager_callback.h"
34 #include "call_ability_callback.h"
35 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
36 #include "common_event_manager.h"
37 #include "common_event_support.h"
38 #endif
39 
40 namespace OHOS {
41 namespace Telephony {
42 class CallManagerProxy : public std::enable_shared_from_this<CallManagerProxy> {
43     DECLARE_DELAYED_SINGLETON(CallManagerProxy)
44 
45 public:
46     void Init(int32_t systemAbilityId);
47     void UnInit();
48     int32_t RegisterCallBack(std::unique_ptr<CallManagerCallback> callback);
49     int32_t UnRegisterCallBack();
50     int32_t ObserverOnCallDetailsChange();
51     int32_t DialCall(std::u16string number, AppExecFwk::PacMap &extras);
52     int32_t MakeCall(std::string number);
53     int32_t AnswerCall(int32_t callId, int32_t videoState);
54     int32_t RejectCall(int32_t callId, bool isSendSms, std::u16string content);
55     int32_t HangUpCall(int32_t callId);
56     int32_t GetCallState();
57     int32_t HoldCall(int32_t callId);
58     int32_t UnHoldCall(int32_t callId);
59     int32_t SwitchCall(int32_t callId);
60     int32_t CombineConference(int32_t callId);
61     int32_t SeparateConference(int32_t callId);
62     int32_t KickOutFromConference(int32_t callId);
63     int32_t GetMainCallId(int32_t &callId, int32_t &mainCallId);
64     int32_t GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList);
65     int32_t GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList);
66     int32_t GetCallWaiting(int32_t slotId);
67     int32_t SetCallWaiting(int32_t slotId, bool activate);
68     int32_t GetCallRestriction(int32_t slotId, CallRestrictionType type);
69     int32_t SetCallRestriction(int32_t slotId, CallRestrictionInfo &info);
70     int32_t SetCallRestrictionPassword(
71         int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword);
72     int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type);
73     int32_t SetCallTransferInfo(int32_t slotId, CallTransferInfo &info);
74     int32_t CanSetCallTransferTime(int32_t slotId, bool &result);
75     int32_t SetCallPreferenceMode(int32_t slotId, int32_t mode);
76     int32_t StartDtmf(int32_t callId, char str);
77     int32_t StopDtmf(int32_t callId);
78     int32_t PostDialProceed(int32_t callId, bool proceed);
79     int32_t IsRinging(bool &enabled);
80     bool HasCall(const bool isInCludeVoipCall = true);
81     int32_t IsNewCallAllowed(bool &enabled);
82     int32_t RegisterVoipCallManagerCallback();
83     int32_t UnRegisterVoipCallManagerCallback();
84     int32_t IsInEmergencyCall(bool &enabled);
85     int32_t IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled);
86     int32_t FormatPhoneNumber(std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber);
87     int32_t FormatPhoneNumberToE164(
88         std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber);
89     int32_t SetMuted(bool isMute);
90     int32_t MuteRinger();
91     int32_t SetAudioDevice(const AudioDevice &audioDevice);
92     int32_t ControlCamera(int32_t callId, std::u16string &cameraId);
93     int32_t SetPreviewWindow(int32_t callId, std::string &surfaceId);
94     int32_t SetDisplayWindow(int32_t callId, std::string &surfaceId);
95     int32_t SetCameraZoom(float zoomRatio);
96     int32_t SetPausePicture(int32_t callId, std::u16string &path);
97     int32_t SetDeviceDirection(int32_t callId, int32_t rotation);
98     int32_t GetImsConfig(int32_t slotId, ImsConfigItem item);
99     int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value);
100     int32_t GetImsFeatureValue(int32_t slotId, FeatureType type);
101     int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value);
102     int32_t UpdateImsCallMode(int32_t callId, ImsCallMode mode);
103     int32_t EnableImsSwitch(int32_t slotId);
104     int32_t DisableImsSwitch(int32_t slotId);
105     int32_t IsImsSwitchEnabled(int32_t slotId, bool &enabled);
106     int32_t SetVoNRState(int32_t slotId, int32_t state);
107     int32_t GetVoNRState(int32_t slotId, int32_t &state);
108     int32_t StartRtt(int32_t callId, std::u16string &msg);
109     int32_t StopRtt(int32_t callId);
110     int32_t JoinConference(int32_t callId, std::vector<std::u16string> &numberList);
111     int32_t ReportOttCallDetailsInfo(std::vector<OttCallDetailsInfo> &ottVec);
112     int32_t ReportOttCallEventInfo(OttCallEventInfo &eventInfo);
113     int32_t CloseUnFinishedUssd(int32_t slotId);
114     int32_t InputDialerSpecialCode(const std::string &specialCode);
115     int32_t RemoveMissedIncomingCallNotification();
116     int32_t SetVoIPCallState(int32_t state);
117     int32_t GetVoIPCallState(int32_t &state);
118     int32_t SetVoIPCallInfo(int32_t callId, int32_t state, std::string phoneNumber);
119     int32_t GetVoIPCallInfo(int32_t &callId, int32_t &state, std::string &phoneNumber);
120     sptr<IRemoteObject> GetProxyObjectPtr(CallManagerProxyType proxyType);
121     void OnRemoteDied(const wptr<IRemoteObject> &remote);
122     int32_t ReportAudioDeviceInfo();
123     int32_t CancelCallUpgrade(int32_t callId);
124     int32_t RequestCameraCapabilities(int32_t callId);
125     int32_t SendCallUiEvent(int32_t callId, std::string &eventName);
126     sptr<ICallStatusCallback> RegisterBluetoothCallManagerCallbackPtr(std::string &macAddress);
127     int32_t SendUssdResponse(int32_t slotId, std::string &content);
128     int32_t SetCallPolicyInfo(bool isDialingTrustlist, const std::vector<std::string> &dialingList,
129         bool isIncomingTrustlist, const std::vector<std::string> &incomingList);
130 
131 private:
132     int32_t ConnectService();
133     void DisconnectService();
134     int32_t ReConnectService();
135     int32_t ReRegisterCallBack();
136 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
137     void SetInitState(bool status);
138     bool IsServiceStart();
139     std::unique_ptr<CallManagerCallback> GetCallBack();
140 #endif
141 
142 private:
143     class CallManagerServiceDeathRecipient : public IRemoteObject::DeathRecipient {
144     public:
CallManagerServiceDeathRecipient(CallManagerProxy & proxy)145         explicit CallManagerServiceDeathRecipient(CallManagerProxy &proxy) : proxy_(proxy) {}
146         ~CallManagerServiceDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)147         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
148         {
149             proxy_.OnRemoteDied(remote);
150         }
151 
152     private:
153         CallManagerProxy &proxy_;
154     };
155 
156 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
157     class CallManagerProxySubcribed : public EventFwk::CommonEventSubscriber,
158         public std::enable_shared_from_this<CallManagerProxySubcribed> {
159     public:
160         explicit CallManagerProxySubcribed(const EventFwk::CommonEventSubscribeInfo &subscriberInfo);
161         ~CallManagerProxySubcribed() = default;
162         void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
163     };
164 #endif
165 
166 private:
167     int32_t systemAbilityId_;
168     ffrt::shared_mutex clientLock_;
169     bool registerStatus_;
170     bool initStatus_;
171     sptr<ICallManagerService> callManagerServicePtr_ = nullptr;
172     sptr<CallAbilityCallback> callAbilityCallbackPtr_ = nullptr;
173     std::mutex mutex_;
174     sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr };
175 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
176     std::unique_ptr<CallManagerCallback> callBack_ = nullptr;
177 #endif
178 };
179 } // namespace Telephony
180 } // namespace OHOS
181 
182 #endif
183