• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     FAILED_INVALID_PARAMETER = 1025,
111     SIM_NOT_EXIT = 1026,
112     SIM_PIN_NEED = 1027,
113     CALL_NOT_ALLOW = 1029,
114     SIM_INVALID = 1045,
115     FAILED_UNKNOWN = 1279,
116 };
117 
118 class ResourceUtils {
119 public:
120     static const std::string IS_NOTIFY_USER_RESTRICTIED_CHANGE;
121     static const std::string IS_CS_CAPABLE;
122     static const std::string IS_SWITCH_PHONE_REG_CHANGE;
123     static const std::string SPN_FORMATS;
124     static const std::string EMERGENCY_CALLS_ONLY;
125     static const std::string OUT_OF_SERIVCE;
126     static const std::string CMCC;
127     static const std::string CUCC;
128     static const std::string CTCC;
129     static const std::string CALL_FAILED_UNASSIGNED_NUMBER;
130     static const std::string CALL_FAILED_NO_ROUTE_TO_DESTINATION;
131     static const std::string CALL_FAILED_CHANNEL_UNACCEPTABLE;
132     static const std::string CALL_FAILED_OPERATOR_DETERMINED_BARRING;
133     static const std::string CALL_FAILED_NORMAL_CALL_CLEARING;
134     static const std::string CALL_FAILED_USER_BUSY;
135     static const std::string CALL_FAILED_NO_USER_RESPONDING;
136     static const std::string CALL_FAILED_USER_ALERTING_NO_ANSWER;
137     static const std::string CALL_FAILED_CALL_REJECTED;
138     static const std::string CALL_FAILED_NUMBER_CHANGED;
139     static const std::string CALL_FAILED_CALL_REJECTED_DESTINATION;
140     static const std::string CALL_FAILED_FAILED_PRE_EMPTION;
141     static const std::string CALL_FAILED_NON_SELECTED_USER_CLEARING;
142     static const std::string CALL_FAILED_DESTINATION_OUT_OF_ORDER;
143     static const std::string CALL_FAILED_INVALID_NUMBER_FORMAT;
144     static const std::string CALL_FAILED_FACILITY_REJECTED;
145     static const std::string CALL_FAILED_RESPONSE_TO_STATUS_ENQUIRY;
146     static const std::string CALL_FAILED_NORMAL_UNSPECIFIED;
147     static const std::string CALL_FAILED_NO_CIRCUIT_CHANNEL_AVAILABLE;
148     static const std::string CALL_FAILED_NETWORK_OUT_OF_ORDER;
149     static const std::string CALL_FAILED_TEMPORARY_FAILURE;
150     static const std::string CALL_FAILED_SWITCHING_EQUIPMENT_CONGESTION;
151     static const std::string CALL_FAILED_ACCESS_INFORMATION_DISCARDED;
152     static const std::string CALL_FAILED_REQUEST_CIRCUIT_CHANNEL_NOT_AVAILABLE;
153     static const std::string CALL_FAILED_RESOURCES_UNAVAILABLE_UNSPECIFIED;
154     static const std::string CALL_FAILED_QUALITY_OF_SERVICE_UNAVAILABLE;
155     static const std::string CALL_FAILED_REQUESTED_FACILITY_NOT_SUBSCRIBED;
156     static const std::string CALL_FAILED_INCOMING_CALLS_BARRED_WITHIN_THE_CUG;
157     static const std::string CALL_FAILED_BEARER_CAPABILITY_NOT_AUTHORIZED;
158     static const std::string CALL_FAILED_BEARER_CAPABILITY_NOT_PRESENTLY_AVAILABLE;
159     static const std::string CALL_FAILED_SERVICE_OR_OPTION_NOT_AVAILABLE_UNSPECIFIED;
160     static const std::string CALL_FAILED_BEARER_SERVICE_NOT_IMPLEMENTED;
161     static const std::string CALL_FAILED_ACM_EQUALTO_OR_GREATE_THAN_ACMMAX;
162     static const std::string CALL_FAILED_REQUESTED_FACILITY_NOT_IMPLEMENTED;
163     static const std::string CALL_FAILED_ONLY_RESTRICTED_DIGITAL_INFO_BEARER_CAPABILITY_IS_AVAILABLE;
164     static const std::string CALL_FAILED_SERVICE_OR_OPTION_NOT_IMPLEMENTED_UNSPECIFIED;
165     static const std::string CALL_FAILED_INVALID_TRANSACTION_IDENTIFIER_VALUE;
166     static const std::string CALL_FAILED_USER_NOT_MEMBER_OF_CUG;
167     static const std::string CALL_FAILED_INCOMPATIBLE_DESTINATION;
168     static const std::string CALL_FAILED_INVALID_TRANSIT_NETWORK_SELECTION;
169     static const std::string CALL_FAILED_SEMANTICALLY_INCORRECT_MESSAGE;
170     static const std::string CALL_FAILED_INVALID_MANDATORY_INFORMATION;
171     static const std::string CALL_FAILED_MESSAGE_TYPE_NON_EXISTENT_OR_NOT_IMPLEMENTED;
172     static const std::string CALL_FAILED_MESSAGE_TYPE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE;
173     static const std::string CALL_FAILED_INFORMATION_ELEMENT_NON_EXISTENT_OR_NOT_IMPLEMENTED;
174     static const std::string CALL_FAILED_CONDITIONAL_IE_ERROR;
175     static const std::string CALL_FAILED_MESSAGE_NOT_COMPATIBLE_WITH_PROTOCOL_STATE;
176     static const std::string CALL_FAILED_RECOVERY_ON_TIMER_EXPIRED;
177     static const std::string CALL_FAILED_PROTOCOL_ERROR_UNSPECIFIED;
178     static const std::string CALL_FAILED_INTERWORKING_UNSPECIFIED;
179     static const std::string CALL_FAILED_CALL_BARRED;
180     static const std::string CALL_FAILED_FDN_BLOCKED;
181     static const std::string CALL_FAILED_IMSI_UNKNOWN_IN_VLR;
182     static const std::string CALL_FAILED_IMEI_NOT_ACCEPTED;
183     static const std::string CALL_FAILED_DIAL_MODIFIED_TO_USSD;
184     static const std::string CALL_FAILED_DIAL_MODIFIED_TO_SS;
185     static const std::string CALL_FAILED_DIAL_MODIFIED_TO_DIAL;
186     static const std::string CALL_FAILED_RADIO_OFF;
187     static const std::string CALL_FAILED_OUT_OF_SERVICE;
188     static const std::string CALL_FAILED_NO_VALID_SIM;
189     static const std::string CALL_FAILED_RADIO_INTERNAL_ERROR;
190     static const std::string CALL_FAILED_NETWORK_RESP_TIMEOUT;
191     static const std::string CALL_FAILED_NETWORK_REJECT;
192     static const std::string CALL_FAILED_RADIO_ACCESS_FAILURE;
193     static const std::string CALL_FAILED_RADIO_LINK_FAILURE;
194     static const std::string CALL_FAILED_RADIO_LINK_LOST;
195     static const std::string CALL_FAILED_RADIO_UPLINK_FAILURE;
196     static const std::string CALL_FAILED_RADIO_SETUP_FAILURE;
197     static const std::string CALL_FAILED_RADIO_RELEASE_NORMAL;
198     static const std::string CALL_FAILED_RADIO_RELEASE_ABNORMAL;
199     static const std::string CALL_FAILED_ACCESS_CLASS_BLOCKED;
200     static const std::string CALL_FAILED_NETWORK_DETACH;
201     static const std::string CALL_FAILED_INVALID_PARAMETER;
202     static const std::string CALL_FAILED_SIM_NOT_EXIT;
203     static const std::string CALL_FAILED_SIM_PIN_NEED;
204     static const std::string CALL_FAILED_CALL_NOT_ALLOW;
205     static const std::string CALL_FAILED_SIM_INVALID;
206     static const std::string CALL_FAILED_UNKNOWN;
207 
208     static ResourceUtils &Get();
209     bool Init();
210     void ShowAllValue();
211     ~ResourceUtils() = default;
212 
213     template<typename T>
214     bool GetValueByName(std::string name, T &value);
215     bool GetCallFailedMessageName(int32_t reason, std::string &name);
216     bool GetStringValueByName(std::string name, std::string &value);
217 
218 private:
219     ResourceUtils();
220     void SaveAllValue();
221     bool GetStringByName(std::string name, std::string &value);
222     bool GetIntegerByName(std::string name, int &value);
223     bool GetBooleanByName(std::string name, bool &value);
224     bool GetStringArrayByName(std::string name, std::vector<std::string> &value);
225     bool GetIntArrayByName(std::string name, std::vector<int32_t> &value);
226     bool IsFileExist(const std::string &filePath);
227 
228 private:
229     std::unique_ptr<Global::Resource::ResourceManager> resourceManager_ = nullptr;
230     bool beSourceAdd_ = false;
231     std::map<std::string, std::any> mapResourceValues_;
232     std::mutex mutex_;
233 
234     enum class ResourceType {
235         ResourceTypeUnkown,
236         ResourceTypeString,
237         ResourceTypeInteger,
238         ResourceTypeBoolean,
239         ResourceTypeArrayString,
240         ResourceTypeArrayInteger
241     };
242 
243     static const std::map<std::string, ResourceType> mapResourceNameType_;
244     static const std::map<DisconnectedReasons, std::string> callFailedResourceName_;
245     static const std::string RESOURCE_HAP_BUNDLE_NAME;
246     static const std::string RESOURCE_INDEX_PATH;
247 };
248 
249 template<typename T>
GetValueByName(std::string name,T & value)250 bool ResourceUtils::GetValueByName(std::string name, T &value)
251 {
252     auto itor = mapResourceValues_.find(name);
253     if (itor == mapResourceValues_.end()) {
254         return false;
255     }
256     value = std::any_cast<T>(itor->second);
257     return true;
258 };
259 } // namespace Telephony
260 } // namespace OHOS
261 
262 #endif