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