1 /* 2 * Copyright (c) 2021-2022 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 DATA_STORAGE_SMS_MMS_ABILITY_H 17 #define DATA_STORAGE_SMS_MMS_ABILITY_H 18 19 #include <functional> 20 21 #include "__mutex_base" 22 #include "ability.h" 23 #include "ability_lifecycle.h" 24 #include "abs_shared_result_set.h" 25 #include "datashare_ext_ability.h" 26 #include "datashare_ext_ability_context.h" 27 #include "datashare_predicates.h" 28 #include "datashare_values_bucket.h" 29 #include "iosfwd" 30 #include "map" 31 #include "memory" 32 #include "rdb_predicates.h" 33 #include "rdb_sms_mms_helper.h" 34 #include "string" 35 #include "vector" 36 #include "want.h" 37 38 namespace OHOS { 39 namespace NativeRdb { 40 class AbsRdbPredicates; 41 class ResultSet; 42 class DataAbilityPredicates; 43 class ValuesBucket; 44 } 45 namespace Telephony { 46 enum class MessageUriType { 47 UNKNOW, 48 SMS_MMS, 49 THIRTY, 50 MAX_GROUP, 51 UNREAD_TOTAL, 52 MMS_PROTOCOL, 53 SMS_SUBSECTION, 54 MMS_PART, 55 SESSION, 56 MMS_PDU, 57 }; 58 class SmsMmsAbility : public DataShare::DataShareExtAbility { 59 public: 60 SmsMmsAbility(); 61 virtual ~SmsMmsAbility() override; 62 static SmsMmsAbility* Create(); 63 void DoInit(); 64 sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override; 65 virtual void OnStart(const AppExecFwk::Want &want) override; 66 virtual int Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value) override; 67 virtual std::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri, 68 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, 69 DataShare::DatashareBusinessError &businessError) override; 70 virtual int Update(const Uri &uri, const DataShare::DataSharePredicates &predicates, 71 const DataShare::DataShareValuesBucket &value) override; 72 virtual int Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates) override; 73 virtual std::string GetType(const Uri &uri) override; 74 virtual int OpenFile(const Uri &uri, const std::string &mode) override; 75 virtual int BatchInsert(const Uri &uri, const std::vector<DataShare::DataShareValuesBucket> &values) override; 76 77 private: 78 /** 79 * Parse Uri Type 80 * 81 * @param uri Resource address 82 * @return return MessageUriType 83 */ 84 MessageUriType ParseUriType(Uri &uri); 85 86 /** 87 * Convert DataSharePredicates to RdbPredicates 88 * 89 * @param tableName table name of the predicates 90 * @param predicates DataSharePredicates 91 */ 92 OHOS::NativeRdb::RdbPredicates ConvertPredicates( 93 const std::string &tableName, const DataShare::DataSharePredicates &predicates); 94 95 /** 96 * Check whether the initialization succeeds 97 * 98 * @return true : succeed ,false : failed 99 */ 100 bool IsInitOk(); 101 102 NativeRdb::AbsRdbPredicates *CreateAbsRdbPredicates(MessageUriType messageUriType, int &result, Uri uri); 103 NativeRdb::AbsRdbPredicates *GetPredicates(MessageUriType messageUriType, const Uri &uri); 104 std::shared_ptr<DataShare::DataShareResultSet> GetResultSet(MessageUriType messageUriType, const Uri &uri); 105 106 private: 107 RdbSmsMmsHelper helper_; 108 std::mutex lock_; 109 bool initDatabaseDir = false; 110 bool initRdbStore = false; 111 }; 112 } // namespace Telephony 113 } // namespace OHOS 114 #endif // DATA_STORAGE_SMS_MMS_ABILITY_H 115