• 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 "rwlock.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 AnswerCall(int32_t callId, int32_t videoState);
53     int32_t RejectCall(int32_t callId, bool isSendSms, std::u16string content);
54     int32_t HangUpCall(int32_t callId);
55     int32_t GetCallState();
56     int32_t HoldCall(int32_t callId);
57     int32_t UnHoldCall(int32_t callId);
58     int32_t SwitchCall(int32_t callId);
59     int32_t CombineConference(int32_t callId);
60     int32_t SeparateConference(int32_t callId);
61     int32_t KickOutFromConference(int32_t callId);
62     int32_t GetMainCallId(int32_t &callId, int32_t &mainCallId);
63     int32_t GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList);
64     int32_t GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList);
65     int32_t GetCallWaiting(int32_t slotId);
66     int32_t SetCallWaiting(int32_t slotId, bool activate);
67     int32_t GetCallRestriction(int32_t slotId, CallRestrictionType type);
68     int32_t SetCallRestriction(int32_t slotId, CallRestrictionInfo &info);
69     int32_t SetCallRestrictionPassword(
70         int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword);
71     int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type);
72     int32_t SetCallTransferInfo(int32_t slotId, CallTransferInfo &info);
73     int32_t CanSetCallTransferTime(int32_t slotId, bool &result);
74     int32_t SetCallPreferenceMode(int32_t slotId, int32_t mode);
75     int32_t StartDtmf(int32_t callId, char str);
76     int32_t StopDtmf(int32_t callId);
77     int32_t PostDialProceed(int32_t callId, bool proceed);
78     int32_t IsRinging(bool &enabled);
79     bool HasCall();
80     int32_t IsNewCallAllowed(bool &enabled);
81     int32_t RegisterVoipCallManagerCallback();
82     int32_t UnRegisterVoipCallManagerCallback();
83     int32_t IsInEmergencyCall(bool &enabled);
84     int32_t IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled);
85     int32_t FormatPhoneNumber(std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber);
86     int32_t FormatPhoneNumberToE164(
87         std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber);
88     int32_t SetMuted(bool isMute);
89     int32_t MuteRinger();
90     int32_t SetAudioDevice(const AudioDevice &audioDevice);
91     int32_t ControlCamera(int32_t callId, std::u16string &cameraId);
92     int32_t SetPreviewWindow(int32_t callId, std::string &surfaceId);
93     int32_t SetDisplayWindow(int32_t callId, std::string &surfaceId);
94     int32_t SetCameraZoom(float zoomRatio);
95     int32_t SetPausePicture(int32_t callId, std::u16string &path);
96     int32_t SetDeviceDirection(int32_t callId, int32_t rotation);
97     int32_t GetImsConfig(int32_t slotId, ImsConfigItem item);
98     int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value);
99     int32_t GetImsFeatureValue(int32_t slotId, FeatureType type);
100     int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value);
101     int32_t UpdateImsCallMode(int32_t callId, ImsCallMode mode);
102     int32_t EnableImsSwitch(int32_t slotId);
103     int32_t DisableImsSwitch(int32_t slotId);
104     int32_t IsImsSwitchEnabled(int32_t slotId, bool &enabled);
105     int32_t SetVoNRState(int32_t slotId, int32_t state);
106     int32_t GetVoNRState(int32_t slotId, int32_t &state);
107     int32_t StartRtt(int32_t callId, std::u16string &msg);
108     int32_t StopRtt(int32_t callId);
109     int32_t JoinConference(int32_t callId, std::vector<std::u16string> &numberList);
110     int32_t ReportOttCallDetailsInfo(std::vector<OttCallDetailsInfo> &ottVec);
111     int32_t ReportOttCallEventInfo(OttCallEventInfo &eventInfo);
112     int32_t CloseUnFinishedUssd(int32_t slotId);
113     int32_t InputDialerSpecialCode(const std::string &specialCode);
114     int32_t RemoveMissedIncomingCallNotification();
115     int32_t SetVoIPCallState(int32_t state);
116     int32_t GetVoIPCallState(int32_t &state);
117     sptr<IRemoteObject> GetProxyObjectPtr(CallManagerProxyType proxyType);
118     void OnRemoteDied(const wptr<IRemoteObject> &remote);
119     int32_t ReportAudioDeviceInfo();
120     int32_t CancelCallUpgrade(int32_t callId);
121     int32_t RequestCameraCapabilities(int32_t callId);
122 
123 private:
124     int32_t ConnectService();
125     void DisconnectService();
126     int32_t ReConnectService();
127     int32_t ReRegisterCallBack();
128 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
129     void SetInitState(bool status);
130     bool IsServiceStart();
131     std::unique_ptr<CallManagerCallback> GetCallBack();
132 #endif
133 
134 private:
135     class CallManagerServiceDeathRecipient : public IRemoteObject::DeathRecipient {
136     public:
CallManagerServiceDeathRecipient(CallManagerProxy & proxy)137         explicit CallManagerServiceDeathRecipient(CallManagerProxy &proxy) : proxy_(proxy) {}
138         ~CallManagerServiceDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)139         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
140         {
141             proxy_.OnRemoteDied(remote);
142         }
143 
144     private:
145         CallManagerProxy &proxy_;
146     };
147 
148 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
149     class CallManagerProxySubcribed : public EventFwk::CommonEventSubscriber,
150         public std::enable_shared_from_this<CallManagerProxySubcribed> {
151     public:
152         explicit CallManagerProxySubcribed(const EventFwk::CommonEventSubscribeInfo &subscriberInfo);
153         ~CallManagerProxySubcribed() = default;
154         void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
155     };
156 #endif
157 
158 private:
159     int32_t systemAbilityId_;
160     Utils::RWLock rwClientLock_;
161     bool registerStatus_;
162     bool initStatus_;
163     sptr<ICallManagerService> callManagerServicePtr_ = nullptr;
164     sptr<CallAbilityCallback> callAbilityCallbackPtr_ = nullptr;
165     std::mutex mutex_;
166     sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr };
167 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
168     std::unique_ptr<CallManagerCallback> callBack_ = nullptr;
169 #endif
170 };
171 } // namespace Telephony
172 } // namespace OHOS
173 
174 #endif
175