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 RESOURCE_UTILS_H 17 #define RESOURCE_UTILS_H 18 19 #include <any> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 #include <vector> 24 25 #include "resource_manager.h" 26 27 namespace OHOS { 28 namespace Telephony { 29 /* 30 * 3GPP TS 24.008 31 * V17.4.0 10.5.4.11 Cause 32 * The purpose of the cause information element is to describe the reason for generating 33 * certain messages, to provide diagnostic information in the event of procedural 34 * errors and to indicate the location of the cause originator. 35 */ 36 enum DisconnectedReasons { 37 UNASSIGNED_NUMBER = 1, 38 NO_ROUTE_TO_DESTINATION = 3, 39 CHANNEL_UNACCEPTABLE = 6, 40 OPERATOR_DETERMINED_BARRING = 8, 41 CALL_COMPLETED_ELSEWHERE = 13, 42 NORMAL_CALL_CLEARING = 16, 43 FAILED_USER_BUSY = 17, 44 NO_USER_RESPONDING = 18, 45 USER_ALERTING_NO_ANSWER = 19, 46 CALL_REJECTED = 21, 47 NUMBER_CHANGED = 22, 48 CALL_REJECTED_DUE_TO_FEATURE_AT_THE_DESTINATION = 24, 49 FAILED_PRE_EMPTION = 25, 50 NON_SELECTED_USER_CLEARING = 26, 51 DESTINATION_OUT_OF_ORDER = 27, 52 INVALID_NUMBER_FORMAT = 28, 53 FACILITY_REJECTED = 29, 54 RESPONSE_TO_STATUS_ENQUIRY = 30, 55 NORMAL_UNSPECIFIED = 31, 56 NO_CIRCUIT_CHANNEL_AVAILABLE = 34, 57 NETWORK_OUT_OF_ORDER = 38, 58 TEMPORARY_FAILURE = 41, 59 SWITCHING_EQUIPMENT_CONGESTION = 42, 60 ACCESS_INFORMATION_DISCARDED = 43, 61 REQUEST_CIRCUIT_CHANNEL_NOT_AVAILABLE = 44, 62 RESOURCES_UNAVAILABLE_UNSPECIFIED = 47, 63 QUALITY_OF_SERVICE_UNAVAILABLE = 49, 64 REQUESTED_FACILITY_NOT_SUBSCRIBED = 50, 65 INCOMING_CALLS_BARRED_WITHIN_THE_CUG = 55, 66 BEARER_CAPABILITY_NOT_AUTHORIZED = 57, 67 BEARER_CAPABILITY_NOT_PRESENTLY_AVAILABLE = 58, 68 SERVICE_OR_OPTION_NOT_AVAILABLE_UNSPECIFIED = 63, 69 BEARER_SERVICE_NOT_IMPLEMENTED = 65, 70 ACM_EQUALTO_OR_GREATE_THAN_ACMMAX = 68, 71 REQUESTED_FACILITY_NOT_IMPLEMENTED = 69, 72 ONLY_RESTRICTED_DIGITAL_INFO_BEARER_CAPABILITY_IS_AVAILABLE = 70, 73 SERVICE_OR_OPTION_NOT_IMPLEMENTED_UNSPECIFIED = 79, 74 INVALID_TRANSACTION_IDENTIFIER_VALUE = 81, 75 USER_NOT_MEMBER_OF_CUG = 87, 76 INCOMPATIBLE_DESTINATION = 88, 77 INVALID_TRANSIT_NETWORK_SELECTION = 91, 78 SEMANTICALLY_INCORRECT_MESSAGE = 95, 79 INVALID_MANDATORY_INFORMATION = 96, 80 MESSAGE_TYPE_NON_EXISTENT_OR_NOT_IMPLEMENTED = 97, 81 MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE = 98, 82 INFORMATION_ELEMENT_NON_EXISTENT_OR_NOT_IMPLEMENTED = 99, 83 CONDITIONAL_IE_ERROR = 100, 84 MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE = 101, 85 RECOVERY_ON_TIMER_EXPIRED = 102, 86 PROTOCOL_ERROR_UNSPECIFIED = 111, 87 INTERWORKING_UNSPECIFIED = 127, 88 CALL_BARRED = 240, 89 FDN_BLOCKED = 241, 90 IMSI_UNKNOWN_IN_VLR = 242, 91 IMEI_NOT_ACCEPTED = 243, 92 DIAL_MODIFIED_TO_USSD = 244, // STK Call Control 93 DIAL_MODIFIED_TO_SS = 245, 94 DIAL_MODIFIED_TO_DIAL = 246, 95 RADIO_OFF = 247, // Radio is OFF 96 OUT_OF_SERVICE = 248, // No cellular coverage 97 NO_VALID_SIM = 249, // No valid SIM is present 98 RADIO_INTERNAL_ERROR = 250, // Internal error at Modem 99 NETWORK_RESP_TIMEOUT = 251, // No response from network 100 NETWORK_REJECT = 252, // Explicit network reject 101 RADIO_ACCESS_FAILURE = 253, // RRC connection failure. Eg.RACH 102 RADIO_LINK_FAILURE = 254, // Radio Link Failure 103 RADIO_LINK_LOST = 255, // Radio link lost due to poor coverage 104 RADIO_UPLINK_FAILURE = 256, // Radio uplink failure 105 RADIO_SETUP_FAILURE = 257, // RRC connection setup failure 106 RADIO_RELEASE_NORMAL = 258, // RRC connection release, normal 107 RADIO_RELEASE_ABNORMAL = 259, // RRC connection release, abnormal 108 ACCESS_CLASS_BLOCKED = 260, // Access class barring 109 NETWORK_DETACH = 261, // Explicit network detach 110 IMEISV_NOT_ACCEPTED = 262, // ImeiSv not accepted 111 FAILED_INVALID_PARAMETER = 1025, 112 SIM_NOT_EXIT = 1026, 113 SIM_PIN_NEED = 1027, 114 CALL_NOT_ALLOW = 1029, 115 SIM_INVALID = 1045, 116 FAILED_UNKNOWN = 1279, 117 }; 118 119 class ResourceUtils { 120 public: 121 static const std::string IS_NOTIFY_USER_RESTRICTIED_CHANGE; 122 static const std::string IS_CS_CAPABLE; 123 static const std::string IS_SWITCH_PHONE_REG_CHANGE; 124 static const std::string SPN_FORMATS; 125 static const std::string EMERGENCY_CALLS_ONLY; 126 static const std::string OUT_OF_SERIVCE; 127 static const std::string CMCC; 128 static const std::string CUCC; 129 static const std::string CTCC; 130 static const std::string CALL_FAILED_UNASSIGNED_NUMBER; 131 static const std::string CALL_FAILED_NO_ROUTE_TO_DESTINATION; 132 static const std::string CALL_FAILED_CHANNEL_UNACCEPTABLE; 133 static const std::string CALL_FAILED_OPERATOR_DETERMINED_BARRING; 134 static const std::string CALL_FAILED_NORMAL_CALL_CLEARING; 135 static const std::string CALL_FAILED_USER_BUSY; 136 static const std::string CALL_FAILED_NO_USER_RESPONDING; 137 static const std::string CALL_FAILED_USER_ALERTING_NO_ANSWER; 138 static const std::string CALL_FAILED_CALL_REJECTED; 139 static const std::string CALL_FAILED_NUMBER_CHANGED; 140 static const std::string CALL_FAILED_CALL_REJECTED_DESTINATION; 141 static const std::string CALL_FAILED_FAILED_PRE_EMPTION; 142 static const std::string CALL_FAILED_NON_SELECTED_USER_CLEARING; 143 static const std::string CALL_FAILED_DESTINATION_OUT_OF_ORDER; 144 static const std::string CALL_FAILED_INVALID_NUMBER_FORMAT; 145 static const std::string CALL_FAILED_FACILITY_REJECTED; 146 static const std::string CALL_FAILED_RESPONSE_TO_STATUS_ENQUIRY; 147 static const std::string CALL_FAILED_NORMAL_UNSPECIFIED; 148 static const std::string CALL_FAILED_NO_CIRCUIT_CHANNEL_AVAILABLE; 149 static const std::string CALL_FAILED_NETWORK_OUT_OF_ORDER; 150 static const std::string CALL_FAILED_TEMPORARY_FAILURE; 151 static const std::string CALL_FAILED_SWITCHING_EQUIPMENT_CONGESTION; 152 static const std::string CALL_FAILED_ACCESS_INFORMATION_DISCARDED; 153 static const std::string CALL_FAILED_REQUEST_CIRCUIT_CHANNEL_NOT_AVAILABLE; 154 static const std::string CALL_FAILED_RESOURCES_UNAVAILABLE_UNSPECIFIED; 155 static const std::string CALL_FAILED_QUALITY_OF_SERVICE_UNAVAILABLE; 156 static const std::string CALL_FAILED_REQUESTED_FACILITY_NOT_SUBSCRIBED; 157 static const std::string CALL_FAILED_INCOMING_CALLS_BARRED_WITHIN_THE_CUG; 158 static const std::string CALL_FAILED_BEARER_CAPABILITY_NOT_AUTHORIZED; 159 static const std::string CALL_FAILED_BEARER_CAPABILITY_NOT_PRESENTLY_AVAILABLE; 160 static const std::string CALL_FAILED_SERVICE_OR_OPTION_NOT_AVAILABLE_UNSPECIFIED; 161 static const std::string CALL_FAILED_BEARER_SERVICE_NOT_IMPLEMENTED; 162 static const std::string CALL_FAILED_ACM_EQUALTO_OR_GREATE_THAN_ACMMAX; 163 static const std::string CALL_FAILED_REQUESTED_FACILITY_NOT_IMPLEMENTED; 164 static const std::string CALL_FAILED_ONLY_RESTRICTED_DIGITAL_INFO_BEARER_CAPABILITY_IS_AVAILABLE; 165 static const std::string CALL_FAILED_SERVICE_OR_OPTION_NOT_IMPLEMENTED_UNSPECIFIED; 166 static const std::string CALL_FAILED_INVALID_TRANSACTION_IDENTIFIER_VALUE; 167 static const std::string CALL_FAILED_USER_NOT_MEMBER_OF_CUG; 168 static const std::string CALL_FAILED_INCOMPATIBLE_DESTINATION; 169 static const std::string CALL_FAILED_INVALID_TRANSIT_NETWORK_SELECTION; 170 static const std::string CALL_FAILED_SEMANTICALLY_INCORRECT_MESSAGE; 171 static const std::string CALL_FAILED_INVALID_MANDATORY_INFORMATION; 172 static const std::string CALL_FAILED_MESSAGE_TYPE_NON_EXISTENT_OR_NOT_IMPLEMENTED; 173 static const std::string CALL_FAILED_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE; 174 static const std::string CALL_FAILED_INFORMATION_ELEMENT_NON_EXISTENT_OR_NOT_IMPLEMENTED; 175 static const std::string CALL_FAILED_CONDITIONAL_IE_ERROR; 176 static const std::string CALL_FAILED_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE; 177 static const std::string CALL_FAILED_RECOVERY_ON_TIMER_EXPIRED; 178 static const std::string CALL_FAILED_PROTOCOL_ERROR_UNSPECIFIED; 179 static const std::string CALL_FAILED_INTERWORKING_UNSPECIFIED; 180 static const std::string CALL_FAILED_CALL_BARRED; 181 static const std::string CALL_FAILED_FDN_BLOCKED; 182 static const std::string CALL_FAILED_IMSI_UNKNOWN_IN_VLR; 183 static const std::string CALL_FAILED_IMEI_NOT_ACCEPTED; 184 static const std::string CALL_FAILED_IMEISV_NOT_ACCEPTED; 185 static const std::string CALL_FAILED_DIAL_MODIFIED_TO_USSD; 186 static const std::string CALL_FAILED_DIAL_MODIFIED_TO_SS; 187 static const std::string CALL_FAILED_DIAL_MODIFIED_TO_DIAL; 188 static const std::string CALL_FAILED_RADIO_OFF; 189 static const std::string CALL_FAILED_OUT_OF_SERVICE; 190 static const std::string CALL_FAILED_NO_VALID_SIM; 191 static const std::string CALL_FAILED_RADIO_INTERNAL_ERROR; 192 static const std::string CALL_FAILED_NETWORK_RESP_TIMEOUT; 193 static const std::string CALL_FAILED_NETWORK_REJECT; 194 static const std::string CALL_FAILED_RADIO_ACCESS_FAILURE; 195 static const std::string CALL_FAILED_RADIO_LINK_FAILURE; 196 static const std::string CALL_FAILED_RADIO_LINK_LOST; 197 static const std::string CALL_FAILED_RADIO_UPLINK_FAILURE; 198 static const std::string CALL_FAILED_RADIO_SETUP_FAILURE; 199 static const std::string CALL_FAILED_RADIO_RELEASE_NORMAL; 200 static const std::string CALL_FAILED_RADIO_RELEASE_ABNORMAL; 201 static const std::string CALL_FAILED_ACCESS_CLASS_BLOCKED; 202 static const std::string CALL_FAILED_NETWORK_DETACH; 203 static const std::string CALL_FAILED_INVALID_PARAMETER; 204 static const std::string CALL_FAILED_SIM_NOT_EXIT; 205 static const std::string CALL_FAILED_SIM_PIN_NEED; 206 static const std::string CALL_FAILED_CALL_NOT_ALLOW; 207 static const std::string CALL_FAILED_SIM_INVALID; 208 static const std::string CALL_FAILED_UNKNOWN; 209 210 static ResourceUtils &Get(); 211 bool Init(); 212 void ShowAllValue(); 213 ~ResourceUtils() = default; 214 215 bool GetCallFailedMessageName(int32_t reason, std::string &name); 216 bool GetStringValueByName(const std::string &name, std::string &value); 217 bool GetStringArrayValueByName(const std::string &name, std::vector<std::string> &value); 218 bool GetBooleanValueByName(const std::string &name, bool &value); 219 bool GetIntegerValueByName(const std::string &name, int32_t &value); 220 bool GetIntArrayValueByName(const std::string &name, std::vector<int32_t> &value); 221 222 private: 223 ResourceUtils(); 224 void SaveAllValue(); 225 bool GetStringByName(std::string name, std::string &value); 226 bool GetIntegerByName(std::string name, int &value); 227 bool GetBooleanByName(std::string name, bool &value); 228 bool GetStringArrayByName(std::string name, std::vector<std::string> &value); 229 bool GetIntArrayByName(std::string name, std::vector<int32_t> &value); 230 bool IsFileExist(const std::string &filePath); 231 232 private: 233 std::unique_ptr<Global::Resource::ResourceManager> resourceManager_ = nullptr; 234 bool beSourceAdd_ = false; 235 std::map<std::string, std::any> mapResourceValues_; 236 std::mutex mutex_; 237 238 enum class ResourceType { 239 ResourceTypeUnkown, 240 ResourceTypeString, 241 ResourceTypeInteger, 242 ResourceTypeBoolean, 243 ResourceTypeArrayString, 244 ResourceTypeArrayInteger 245 }; 246 247 static const std::map<std::string, ResourceType> mapResourceNameType_; 248 static const std::map<int32_t, std::string> callFailedResourceName_; 249 static const std::string RESOURCE_HAP_BUNDLE_NAME; 250 static const std::string RESOURCE_INDEX_PATH; 251 }; 252 } // namespace Telephony 253 } // namespace OHOS 254 255 #endif