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