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