• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "emergency_utils.h"
17 
18 #include "shortnumberinfo.h"
19 
20 #include "cellular_call_config.h"
21 #include "mmi_code_utils.h"
22 #include "module_service_utils.h"
23 
24 namespace OHOS {
25 namespace Telephony {
IsEmergencyCall(int32_t slotId,const std::string & phoneNum)26 bool EmergencyUtils::IsEmergencyCall(int32_t slotId, const std::string &phoneNum)
27 {
28     if (phoneNum.empty()) {
29         TELEPHONY_LOGI("IsEmergencyCall return, phoneNum is empty.");
30         return false;
31     }
32 
33     if (phoneNum.find('@') != std::string::npos || phoneNum.find("%40") != std::string::npos) {
34         TELEPHONY_LOGI("IsEmergencyCall return, phoneNum is not emergency.");
35         return false;
36     }
37 
38     if (phoneNum.front() == '+') {
39         TELEPHONY_LOGI("IsEmergencyCall return, phoneNum is not emergency.");
40         return false;
41     }
42 
43     return IsEmergencyCallProcessing(slotId, phoneNum);
44 }
45 
IsEmergencyCallProcessing(int32_t slotId,const std::string & formatString)46 bool EmergencyUtils::IsEmergencyCallProcessing(int32_t slotId, const std::string &formatString)
47 {
48     TELEPHONY_LOGI("IsEmergencyCallProcessing entry.");
49     std::vector<std::string> emergencyNumList = {
50         "110", "120", "119", "122", "12395", "114", "112", "000", "911", "08", "118", "999",
51     };
52     if (std::find(emergencyNumList.begin(), emergencyNumList.end(), formatString) != emergencyNumList.end()) {
53         TELEPHONY_LOGI("IsEmergencyCallProcessing, Complies with local configuration data.");
54         return true;
55     }
56     CellularCallConfig config;
57     ModuleServiceUtils dependDataObtain;
58     std::string countryIsoCode = dependDataObtain.GetNetworkCountryCode(slotId);
59     std::vector<EmergencyInfo> eccCallList = config.GetEccCallList(slotId);
60     for (auto it = eccCallList.begin(); it != eccCallList.end(); it++) {
61         if (countryIsoCode == it->mcc && formatString == it->eccNum) {
62             TELEPHONY_LOGI("IsEmergencyCallProcessing, Complies with sim data.");
63             return true;
64         }
65     }
66     if (!countryIsoCode.empty()) {
67         TELEPHONY_LOGI("IsEmergencyCallProcessing countryIsoCode is not empty");
68         i18n::phonenumbers::ShortNumberInfo shortNumberInfo;
69         transform(countryIsoCode.begin(), countryIsoCode.end(), countryIsoCode.begin(), ::toupper);
70         return shortNumberInfo.IsEmergencyNumber(formatString, countryIsoCode);
71     }
72     TELEPHONY_LOGI("IsEmergencyCallProcessing, not an emergency number.");
73     return false;
74 }
75 } // namespace Telephony
76 } // namespace OHOS
77