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 CALL_NUMBER_UTILS_H
17 #define CALL_NUMBER_UTILS_H
18 
19 #include "pac_map.h"
20 #include "singleton.h"
21 #include "phonenumberutil.h"
22 
23 #include "common_type.h"
24 #include "call_base.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class CallNumberUtils {
29     DECLARE_DELAYED_SINGLETON(CallNumberUtils)
30 public:
31     int32_t FormatPhoneNumber(
32         const std::string &phoneNumber, const std::string &countryCode, std::string &formatNumber);
33     int32_t FormatPhoneNumberToE164(
34         const std::string phoneNumber, const std::string countryCode, std::string &formatNumber);
35     int32_t FormatPhoneNumberToNational(
36         const std::string phoneNumber, const std::string countryCode, std::string &formatNumber);
37     int32_t FormatPhoneNumberToInternational(
38         const std::string phoneNumber, const std::string countryCode, std::string &formatNumber);
39     int32_t FormatNumberBase(const std::string phoneNumber, std::string countryCode,
40         const i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat formatInfo, std::string &formatNumber);
41     int32_t FormatPhoneNumberAsYouType(
42         const std::string &phoneNumber, const std::string &countryCode, std::string &formatNumber);
43     int32_t CheckNumberIsEmergency(const std::string &phoneNumber, const int32_t slotId, bool &enabled);
44     bool IsValidSlotId(int32_t slotId) const;
45     bool IsMMICode(const std::string &number);
46     bool RegexMatchMmi(const std::string &number);
47     std::string RemoveSeparatorsPhoneNumber(const std::string &phoneString);
48     std::string RemovePostDialPhoneNumber(const std::string &phoneString);
49     bool HasBCPhoneNumber(const std::string &phoneNumber);
50     bool SelectAccountId(int32_t slotId, AppExecFwk::PacMap &extras);
51     int32_t QueryNumberLocationInfo(std::string &numberLocation, std::string accountNumber);
52     void NumberLocationUpdate(const sptr<CallBase> &callObjectPtr);
53     int32_t QueryYellowPageAndMarkInfo(NumberMarkInfo &numberMarkInfo, std::string accountNumber);
54     void YellowPageAndMarkUpdate(const sptr<CallBase> &callObjectPtr);
55 private:
56     void ProcessSpace(std::string &number);
57 
58 private:
59     static const int16_t HAS_A_SLOT = 1;
60     static const int16_t HAS_TWO_SLOT = 2;
61 };
62 } // namespace Telephony
63 } // namespace OHOS
64 
65 #endif // CALL_NUMBER_UTILS_H