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