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 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(); 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 sptr<IRemoteObject> GetProxyObjectPtr(CallManagerProxyType proxyType); 119 void OnRemoteDied(const wptr<IRemoteObject> &remote); 120 int32_t ReportAudioDeviceInfo(); 121 int32_t CancelCallUpgrade(int32_t callId); 122 int32_t RequestCameraCapabilities(int32_t callId); 123 int32_t SendCallUiEvent(int32_t callId, std::string &eventName); 124 125 private: 126 int32_t ConnectService(); 127 void DisconnectService(); 128 int32_t ReConnectService(); 129 int32_t ReRegisterCallBack(); 130 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE 131 void SetInitState(bool status); 132 bool IsServiceStart(); 133 std::unique_ptr<CallManagerCallback> GetCallBack(); 134 #endif 135 136 private: 137 class CallManagerServiceDeathRecipient : public IRemoteObject::DeathRecipient { 138 public: CallManagerServiceDeathRecipient(CallManagerProxy & proxy)139 explicit CallManagerServiceDeathRecipient(CallManagerProxy &proxy) : proxy_(proxy) {} 140 ~CallManagerServiceDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)141 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 142 { 143 proxy_.OnRemoteDied(remote); 144 } 145 146 private: 147 CallManagerProxy &proxy_; 148 }; 149 150 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE 151 class CallManagerProxySubcribed : public EventFwk::CommonEventSubscriber, 152 public std::enable_shared_from_this<CallManagerProxySubcribed> { 153 public: 154 explicit CallManagerProxySubcribed(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); 155 ~CallManagerProxySubcribed() = default; 156 void OnReceiveEvent(const EventFwk::CommonEventData &data) override; 157 }; 158 #endif 159 160 private: 161 int32_t systemAbilityId_; 162 Utils::RWLock rwClientLock_; 163 bool registerStatus_; 164 bool initStatus_; 165 sptr<ICallManagerService> callManagerServicePtr_ = nullptr; 166 sptr<CallAbilityCallback> callAbilityCallbackPtr_ = nullptr; 167 std::mutex mutex_; 168 sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr }; 169 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE 170 std::unique_ptr<CallManagerCallback> callBack_ = nullptr; 171 #endif 172 }; 173 } // namespace Telephony 174 } // namespace OHOS 175 176 #endif 177