1 /* 2 * Copyright (C) 2021 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 TELEPHONY_STATE_REGISTRY_CLIENT_H 17 #define TELEPHONY_STATE_REGISTRY_CLIENT_H 18 19 #include <cstdint> 20 #include <iremote_object.h> 21 #include <singleton.h> 22 23 #include "i_telephony_state_notify.h" 24 25 namespace OHOS { 26 namespace Telephony { 27 class TelephonyStateRegistryClient : public DelayedRefSingleton<TelephonyStateRegistryClient> { 28 DECLARE_DELAYED_REF_SINGLETON(TelephonyStateRegistryClient); 29 30 public: 31 /** 32 * @brief Update cellular data connect state 33 * 34 * @param slotId sim slot id 35 * @param dataState cellular data link state 36 * @param networkState network state 37 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 38 */ 39 int32_t UpdateCellularDataConnectState(int32_t slotId, int32_t dataState, int32_t networkState); 40 /** 41 * @brief Update call state 42 * 43 * @param slotId sim slot id 44 * @param callStatus call status 45 * @param number call number 46 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 47 */ 48 int32_t UpdateCallState(int32_t slotId, int32_t callStatus, const std::u16string &number); 49 /** 50 * @brief Update call state for slotId 51 * 52 * @param slotId sim slot id 53 * @param callId call id 54 * @param callStatus call status 55 * @param number incoming number 56 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 57 */ 58 int32_t UpdateCallStateForSlotId( 59 int32_t slotId, int32_t callId, int32_t callStatus, const std::u16string &number); 60 /** 61 * @brief Update signal information 62 * 63 * @param slotId sim slot id 64 * @param vec networkType search signal information 65 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 66 */ 67 int32_t UpdateSignalInfo(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec); 68 /** 69 * @brief Update cell information 70 * 71 * @param slotId sim slot id 72 * @param vec cell info 73 * @return int32_t TELEPHONY_NO_ERROR on success, others on failure. 74 */ 75 int32_t UpdateCellInfo(int32_t slotId, const std::vector<sptr<CellInformation>> &vec); 76 /** 77 * @brief Update network state 78 * 79 * @param slotId sim slot id 80 * @param networkStatus network status 81 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 82 */ 83 int32_t UpdateNetworkState(int32_t slotId, const sptr<NetworkState> &networkState); 84 /** 85 * @brief Update sim state 86 * 87 * @param slotId sim slot id 88 * @param CardType sim card type 89 * @param state sim state 90 * @param reason Indicates the reason of update sim state 91 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 92 */ 93 int32_t UpdateSimState(int32_t slotId, CardType type, SimState state, LockReason reason); 94 /** 95 * @brief Update cellular data flow 96 * 97 * @param slotId sim slot id 98 * @param dataFlowType cellular data flow state 99 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 100 */ 101 int32_t UpdateCellularDataFlow(int32_t slotId, int32_t flowType); 102 /** 103 * @brief Update call forward unconditionally indicator 104 * 105 * @param slotId sim slot id 106 * @param cfuResult set the result of call forwarding 107 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 108 */ 109 int32_t UpdateCfuIndicator(int32_t slotId, bool cfuResult); 110 /** 111 * @brief Update voice mail message indicator 112 * 113 * @param slotId sim slot id 114 * @param voiceMailMsgResult voice mail message indicator 115 * @return int32_t TELEPHONY_SUCCESS on success, others on failure. 116 */ 117 int32_t UpdateVoiceMailMsgIndicator(int32_t slotId, bool voiceMailMsgResult); 118 int32_t UpdateIccAccount(); 119 sptr<ITelephonyStateNotify> GetProxy(); 120 121 private: 122 class StateRegistryDeathRecipient : public IRemoteObject::DeathRecipient { 123 public: StateRegistryDeathRecipient(TelephonyStateRegistryClient & client)124 explicit StateRegistryDeathRecipient(TelephonyStateRegistryClient &client) : client_(client) {} 125 ~StateRegistryDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)126 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 127 { 128 client_.OnRemoteDied(remote); 129 } 130 131 private: 132 TelephonyStateRegistryClient &client_; 133 }; 134 135 void OnRemoteDied(const wptr<IRemoteObject> &remote); 136 137 private: 138 std::mutex mutexProxy_; 139 sptr<ITelephonyStateNotify> proxy_ {nullptr}; 140 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 141 }; 142 } // namespace Telephony 143 } // namespace OHOS 144 #endif // TELEPHONY_STATE_REGISTRY_CLIENT_H 145