1 /* 2 * Copyright (c) 2024 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_OBSERVER_UTILS_H 17 #define TELEPHONY_OBSERVER_UTILS_H 18 19 #include <cstdint> 20 #include <codecvt> 21 #include <locale> 22 #include <memory> 23 #include <string> 24 #include <vector> 25 26 #include "cell_information.h" 27 #include "network_state.h" 28 #include "refbase.h" 29 #include "signal_information.h" 30 #include "sim_state_type.h" 31 #include "telephony_log_wrapper.h" 32 #include "telephony_observer_broker.h" 33 34 namespace OHOS { 35 namespace Telephony { 36 37 char* MallocCString(const std::string& origin); 38 std::string ToUtf8(std::u16string str16); 39 40 enum CJErrorCode { 41 /** 42 * The input parameter value is out of range. 43 */ 44 CJ_ERROR_TELEPHONY_ARGUMENT_ERROR = 8300001, 45 46 /** 47 * Operation failed. Cannot connect to service. 48 */ 49 CJ_ERROR_TELEPHONY_SERVICE_ERROR = 8300002, 50 51 /** 52 * System internal error. 53 */ 54 CJ_ERROR_TELEPHONY_SYSTEM_ERROR = 8300003, 55 56 /** 57 * Do not have sim card. 58 */ 59 CJ_ERROR_TELEPHONY_NO_SIM_CARD = 8300004, 60 61 /** 62 * Airplane mode is on. 63 */ 64 CJ_ERROR_TELEPHONY_AIRPLANE_MODE_ON = 8300005, 65 66 /** 67 * Network not in service. 68 */ 69 CJ_ERROR_TELEPHONY_NETWORK_NOT_IN_SERVICE = 8300006, 70 71 /** 72 * Unknown error code. 73 */ 74 CJ_ERROR_TELEPHONY_UNKNOW_ERROR = 8300999, 75 76 /** 77 * SIM card is not activated. 78 */ 79 CJ_ERROR_SIM_CARD_IS_NOT_ACTIVE = 8301001, 80 81 /** 82 * SIM card operation error. 83 */ 84 CJ_ERROR_SIM_CARD_OPERATION_ERROR = 8301002, 85 86 /** 87 * Operator config error. 88 */ 89 CJ_ERROR_OPERATOR_CONFIG_ERROR = 8301003, 90 91 /** 92 * Permission verification failed, usually the result returned by VerifyAccessToken. 93 */ 94 CJ_ERROR_TELEPHONY_PERMISSION_DENIED = 201, 95 96 /** 97 * Permission verification failed, application which is not a system application uses system API. 98 */ 99 CJ_ERROR_ILLEGAL_USE_OF_SYSTEM_API = 202, 100 }; 101 102 enum class CallState : int32_t { 103 /** 104 * Indicates an invalid state, which is used when the call state fails to be 105 * obtained. 106 */ 107 CALL_STATE_UNKNOWN = -1, 108 109 /** 110 * Indicates that there is no ongoing call. 111 */ 112 CALL_STATE_IDLE = 0, 113 114 /** 115 * Indicates that an incoming call is ringing or waiting. 116 */ 117 CALL_STATE_RINGING = 1, 118 119 /** 120 * Indicates that a least one call is in the dialing, active, or hold state, 121 * and there is no new incoming call ringing or waiting. 122 */ 123 CALL_STATE_OFFHOOK = 2, 124 125 /** 126 * Indicates that an incoming call is answered. 127 */ 128 CALL_STATE_ANSWERED = 3 129 }; 130 131 enum class TelephonyUpdateEventType { 132 NONE_EVENT_TYPE = 0, 133 EVENT_NETWORK_STATE_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE, 134 EVENT_CALL_STATE_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE, 135 EVENT_CELL_INFO_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO, 136 EVENT_SIGNAL_STRENGTHS_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS, 137 EVENT_SIM_STATE_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE, 138 EVENT_DATA_CONNECTION_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE, 139 EVENT_CELLULAR_DATA_FLOW_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW, 140 EVENT_CFU_INDICATOR_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR, 141 EVENT_VOICE_MAIL_MSG_INDICATOR_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR, 142 EVENT_ICC_ACCOUNT_CHANGE = TelephonyObserverBroker::OBSERVER_MASK_ICC_ACCOUNT, 143 }; 144 145 enum class TelephonyCallbackEventId : uint32_t { 146 EVENT_REMOVE_ONCE = 0, 147 EVENT_ON_CALL_STATE_UPDATE = 1, 148 EVENT_ON_SIGNAL_INFO_UPDATE = 2, 149 EVENT_ON_NETWORK_STATE_UPDATE = 3, 150 EVENT_ON_SIM_STATE_UPDATE = 4, 151 EVENT_ON_CELL_INFOMATION_UPDATE = 5, 152 EVENT_ON_CELLULAR_DATA_CONNECTION_UPDATE = 6, 153 EVENT_ON_CELLULAR_DATA_FLOW_UPDATE = 7, 154 EVENT_ON_CFU_INDICATOR_UPDATE = 8, 155 EVENT_ON_VOICE_MAIL_MSG_INDICATOR_UPDATE = 9, 156 EVENT_ON_ICC_ACCOUNT_UPDATE = 10, 157 }; 158 159 struct EventListener { 160 TelephonyUpdateEventType eventType = TelephonyUpdateEventType::NONE_EVENT_TYPE; 161 int32_t slotId = 0; 162 int64_t funcId; 163 std::function<void(void*)> callbackRef; 164 std::shared_ptr<bool> isDeleting = nullptr; 165 }; 166 167 struct ObserverOptions { 168 int32_t slotId = 0; 169 }; 170 171 struct UpdateInfo { 172 int32_t slotId_ = 0; UpdateInfoOHOS::Telephony::CallState::UpdateInfo173 explicit UpdateInfo(int32_t slotId) : slotId_(slotId) {} 174 }; 175 176 struct CallStateUpdateInfo : public UpdateInfo { 177 int32_t callState_ = 0; 178 std::u16string phoneNumber_ = u""; CallStateUpdateInfoOHOS::Telephony::CallState::CallStateUpdateInfo179 CallStateUpdateInfo(int32_t slotId, int32_t callStateParam, std::u16string phoneNumberParam) 180 : UpdateInfo(slotId), callState_(callStateParam), phoneNumber_(phoneNumberParam) {} 181 }; 182 183 struct SignalUpdateInfo : public UpdateInfo { 184 std::vector<sptr<SignalInformation>> signalInfoList_ {}; SignalUpdateInfoOHOS::Telephony::CallState::SignalUpdateInfo185 SignalUpdateInfo(int32_t slotId, std::vector<sptr<SignalInformation>> infoList) 186 : UpdateInfo(slotId), signalInfoList_(infoList) {} 187 }; 188 189 struct NetworkStateUpdateInfo : public UpdateInfo { 190 sptr<NetworkState> networkState_ = nullptr; NetworkStateUpdateInfoOHOS::Telephony::CallState::NetworkStateUpdateInfo191 NetworkStateUpdateInfo(int32_t slotId, sptr<NetworkState> state) : UpdateInfo(slotId), networkState_(state) {} 192 }; 193 194 struct SimStateUpdateInfo : public UpdateInfo { 195 CardType type_; 196 SimState state_; 197 LockReason reason_; SimStateUpdateInfoOHOS::Telephony::CallState::SimStateUpdateInfo198 SimStateUpdateInfo(int32_t slotId, CardType type, SimState simState, LockReason theReason) 199 : UpdateInfo(slotId), type_(type), state_(simState), reason_(theReason) {} 200 }; 201 202 struct CellInfomationUpdate : public UpdateInfo { 203 std::vector<sptr<CellInformation>> cellInfoVec_ {}; CellInfomationUpdateOHOS::Telephony::CallState::CellInfomationUpdate204 CellInfomationUpdate(int32_t slotId, const std::vector<sptr<CellInformation>> &cellInfo) 205 : UpdateInfo(slotId), cellInfoVec_(cellInfo) {} 206 }; 207 208 struct CellularDataConnectState : public UpdateInfo { 209 int32_t dataState_ = 0; 210 int32_t networkType_ = 0; CellularDataConnectStateOHOS::Telephony::CallState::CellularDataConnectState211 CellularDataConnectState(int32_t slotId, int32_t dataState, int32_t networkType) 212 : UpdateInfo(slotId), dataState_(dataState), networkType_(networkType) {} 213 }; 214 215 struct CellularDataFlowUpdate : public UpdateInfo { 216 int32_t flowType_ = 0; CellularDataFlowUpdateOHOS::Telephony::CallState::CellularDataFlowUpdate217 CellularDataFlowUpdate(int32_t slotId, int32_t flowType) : UpdateInfo(slotId), flowType_(flowType) {} 218 }; 219 220 struct CfuIndicatorUpdate : public UpdateInfo { 221 bool cfuResult_ = false; CfuIndicatorUpdateOHOS::Telephony::CallState::CfuIndicatorUpdate222 CfuIndicatorUpdate(int32_t slotId, bool cfuResult) : UpdateInfo(slotId), cfuResult_(cfuResult) {} 223 }; 224 225 struct VoiceMailMsgIndicatorUpdate : public UpdateInfo { 226 bool voiceMailMsgResult_ = false; VoiceMailMsgIndicatorUpdateOHOS::Telephony::CallState::VoiceMailMsgIndicatorUpdate227 VoiceMailMsgIndicatorUpdate(int32_t slotId, bool voiceMailMsgResult) 228 : UpdateInfo(slotId), voiceMailMsgResult_(voiceMailMsgResult) {} 229 }; 230 231 // @C 232 struct CNetworkState { 233 char* longOperatorName; 234 char* shortOperatorName; 235 char* plmnNumeric; 236 bool isRoaming; 237 int32_t regState; 238 int32_t cfgTech; 239 int32_t nsaState; 240 bool isCaActive; 241 bool isEmergency; 242 }; 243 244 struct CSignalInformation { 245 int32_t signalType; 246 int32_t signalLevel; 247 int32_t dBm; 248 }; 249 250 struct CCallStateInfo { 251 int32_t state; 252 char* number; 253 }; 254 255 struct CDataConnectionStateInfo { 256 int32_t state; 257 int32_t network; 258 }; 259 260 struct CSimStateData { 261 int32_t cardType; 262 int32_t state; 263 int32_t reason; 264 }; 265 266 struct CArraySignalInformation { 267 CSignalInformation* head; 268 int64_t size; 269 }; 270 } 271 } 272 273 #endif