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 SMS_PERSIST_HELPER_H
17 #define SMS_PERSIST_HELPER_H
18 
19 #include "datashare_helper.h"
20 #include "datashare_predicates.h"
21 #include "phonenumbers/phonenumberutil.h"
22 #include "singleton.h"
23 #include "sms_mms_data.h"
24 #include "sms_receive_indexer.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class SmsPersistHelper {
29     DECLARE_DELAYED_SINGLETON(SmsPersistHelper)
30 public:
31     bool Insert(DataShare::DataShareValuesBucket &values, uint16_t &dataBaseId);
32     bool Insert(std::string tableUri, DataShare::DataShareValuesBucket &values);
33     bool Query(DataShare::DataSharePredicates &predicates, std::vector<SmsReceiveIndexer> &indexers);
34     bool Delete(DataShare::DataSharePredicates &predicates);
35     bool Update(DataShare::DataSharePredicates &predicates, DataShare::DataShareValuesBucket &values);
36     bool QueryBlockPhoneNumber(const std::string &phoneNum);
37     bool QueryParamBoolean(const std::string key, bool defValue);
38     bool QueryMaxGroupId(DataShare::DataSharePredicates &predicates, uint16_t &maxGroupId);
39     bool QuerySession(DataShare::DataSharePredicates &predicates, uint16_t &sessionId, uint16_t &messageCount);
40     bool UpdateContact(const std::string &address);
41 
42     inline static const std::string SMS_CAPABLE_KEY = "sms_config_capable";
43     inline static const std::string SMS_ENCODING_KEY = "sms_config_force_7bit_encoding";
44     inline static const std::string SMS_CAPABLE_PARAM_KEY = "const.telephony.sms.capable";
45     inline static const std::string SMS_ENCODING_PARAM_KEY = "persist.sys.sms.config.7bitforce";
46 
47 private:
48     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(const std::string &uri);
49     void ResultSetConvertToIndexer(
50         SmsReceiveIndexer &info, const std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
51     void ConvertIntToIndexer(
52         SmsReceiveIndexer &info, const std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
53     void ConvertStringToIndexer(
54         SmsReceiveIndexer &info, const std::shared_ptr<DataShare::DataShareResultSet> &resultSet);
55     int32_t FormatSmsNumber(const std::string &num, std::string countryCode,
56         const i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat formatInfo, std::string &formatNum);
57     void TrimSpace(std::string &num);
58     bool QueryContactedCount(const std::string &address, int32_t &rawCountId, int32_t &contactedCount);
59     bool QueryRawContactId(const std::string &address, int32_t &rawCountId);
60     void CbnFormat(std::string &numTemp, const i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat formatInfo,
61         std::string &formatNum);
62 };
63 } // namespace Telephony
64 } // namespace OHOS
65 #endif
66