1 2 /* 3 * Copyright (C) 2023 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef TELEPHONY_SATELLITE_CALL_CLIENT_H 18 #define TELEPHONY_SATELLITE_CALL_CLIENT_H 19 20 #include "event_runner.h" 21 #include "i_satellite_service.h" 22 #include "iremote_stub.h" 23 #include "rwlock.h" 24 #include "satellite_call_interface.h" 25 #include "singleton.h" 26 #include "system_ability_status_change_stub.h" 27 28 namespace OHOS { 29 namespace Telephony { 30 class SatelliteCallClient { 31 DECLARE_DELAYED_SINGLETON(SatelliteCallClient); 32 33 public: 34 /** 35 * @brief Get SatelliteCall Remote Object ptr 36 * 37 * @return sptr<SatelliteCallInterface> 38 */ 39 sptr<SatelliteCallInterface> GetSatelliteCallProxy(); 40 41 /** 42 * @brief Get the remote object ptr, initiate a listener and subscribe the system ability 43 */ 44 void Init(); 45 46 /** 47 * @brief Clear the listener and the remote ptr when destroy the SatelliteCallClient Object 48 */ 49 void UnInit(); 50 51 /** 52 * @brief Register SatelliteCallCallback Handler, put the handler and slot id into {handlerMap_} 53 * 54 * @param slotId Indicates the card slot index number, 55 * @param handler Indicates the event handler ptr 56 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 57 */ 58 int32_t RegisterSatelliteCallCallbackHandler( 59 int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler); 60 61 /** 62 * @brief Get the event handler ptr from {handlerMap_} 63 * 64 * @param slotId Indicates the card slot index number, 65 * @return AppExecFwk::EventHandler 66 */ 67 std::shared_ptr<AppExecFwk::EventHandler> GetHandler(int32_t slotId); 68 69 /****************** call basic ******************/ 70 /** 71 * @brief Satellite dial the call interface 72 * 73 * @param SatelliteCallInfo Indicates the call detail information, contains phone number, slot id, 74 * video state, call index 75 * @param CLIRMode Indicates the CLIR mode, like default, transfer, inhibition 76 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 77 */ 78 int32_t Dial(const SatelliteCallInfo &callInfo, CLIRMode mode); 79 80 /** 81 * @brief Satellite HangUp the call interface 82 * 83 * @param slotId Indicates the call slot id, 84 * @param index Indicates the call id, 85 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 86 */ 87 int32_t HangUp(int32_t slotId, int32_t index); 88 89 /** 90 * @brief Satellite Reject the call interface 91 * 92 * @param slotId Indicates the call slot id, 93 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 94 */ 95 int32_t Reject(int32_t slotId); 96 97 /** 98 * @brief Satellite Answer the call interface 99 * 100 * @param slotId Indicates the call slot id, 101 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 102 */ 103 int32_t Answer(int32_t slotId); 104 105 /** 106 * @brief Get Satellite Calls Data Request 107 * 108 * @param slotId Indicates the card slot index number, 109 * @param lastCallsDataFlag The Satellite call data id, is a number in milliseconds 110 * @return Returns TELEPHONY_SUCCESS on success, others on failure. 111 */ 112 int32_t GetSatelliteCallsDataRequest(int32_t slotId, int64_t lastCallsDataFlag); 113 114 /** 115 * @brief Get Satellite status 116 * 117 * @param slotId Indicates the card slot index number, 118 * @return Returns true on satellite enable, others on false. 119 */ 120 bool IsSatelliteEnabled(int32_t slotId); 121 122 private: 123 /** 124 * Is Connect ImsCall Remote Object 125 * 126 * @return bool 127 */ 128 bool IsConnect(); 129 int32_t RegisterSatelliteCallCallback(); 130 int32_t ReConnectService(); 131 void Clean(); 132 133 class SatelliteServiceDeathRecipient : public IRemoteObject::DeathRecipient { 134 public: SatelliteServiceDeathRecipient(SatelliteCallClient & client)135 explicit SatelliteServiceDeathRecipient(SatelliteCallClient &client) : client_(client) {} 136 ~SatelliteServiceDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)137 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 138 { 139 client_.OnRemoteDied(remote); 140 } 141 142 private: 143 SatelliteCallClient &client_; 144 }; 145 146 void RemoveDeathRecipient(const wptr<IRemoteObject> &remote); 147 148 void OnRemoteDied(const wptr<IRemoteObject> &remote); 149 150 private: 151 sptr<ISatelliteService> satelliteServiceProxy_ = nullptr; 152 sptr<SatelliteCallInterface> satelliteCallProxy_ = nullptr; 153 sptr<SatelliteCallCallbackInterface> satelliteCallCallback_ = nullptr; 154 sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr }; 155 std::map<int32_t, std::shared_ptr<AppExecFwk::EventHandler>> handlerMap_; 156 Utils::RWLock rwClientLock_; 157 std::mutex mutexProxy_; 158 std::mutex mutexMap_; 159 }; 160 } // namespace Telephony 161 } // namespace OHOS 162 163 #endif // TELEPHONY_SATELLITE_CALL_CLIENT_H