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_OPKEY_ABILITY_H 17 #define DATA_STORAGE_OPKEY_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_values_bucket.h" 28 #include "iosfwd" 29 #include "map" 30 #include "memory" 31 #include "rdb_opkey_helper.h" 32 #include "rdb_predicates.h" 33 #include "string" 34 #include "vector" 35 #include "want.h" 36 37 namespace OHOS { 38 namespace NativeRdb { 39 class AbsRdbPredicates; 40 class ResultSet; 41 class DataAbilityPredicates; 42 class ValuesBucket; 43 } 44 namespace Telephony { 45 enum class OpKeyUriType { 46 UNKNOW, OPKEY_INFO 47 }; 48 class OpKeyAbility : public DataShare::DataShareExtAbility { 49 public: 50 OpKeyAbility(); 51 virtual ~OpKeyAbility() override; 52 static OpKeyAbility* Create(); 53 void DoInit(); 54 sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override; 55 virtual void OnStart(const AppExecFwk::Want &want) override; 56 virtual int Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value) override; 57 virtual std::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri, 58 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, 59 DataShare::DatashareBusinessError &businessError) override; 60 virtual int Update(const Uri &uri, const DataShare::DataSharePredicates &predicates, 61 const DataShare::DataShareValuesBucket &value) override; 62 virtual int Delete(const Uri &uri, const DataShare::DataSharePredicates &predicates) override; 63 virtual std::string GetType(const Uri &uri) override; 64 virtual int OpenFile(const Uri &uri, const std::string &mode) override; 65 66 private: 67 /** 68 * Parse Uri Type 69 * 70 * @param uri Resource address 71 * @return return OpKeyUriType 72 */ 73 OpKeyUriType ParseUriType(Uri &uri); 74 75 /** 76 * Convert DataSharePredicates to RdbPredicates 77 * 78 * @param tableName table name of the predicates 79 * @param predicates DataSharePredicates 80 */ 81 OHOS::NativeRdb::RdbPredicates ConvertPredicates( 82 const std::string &tableName, const DataShare::DataSharePredicates &predicates); 83 84 /** 85 * Check whether the initialization succeeds 86 * 87 * @return true : succeed ,false : failed 88 */ 89 bool IsInitOk(); 90 91 private: 92 RdbOpKeyHelper helper_; 93 std::mutex lock_; 94 bool initDatabaseDir_ = false; 95 bool initRdbStore_ = false; 96 }; 97 } // namespace Telephony 98 } // namespace OHOS 99 #endif // DATA_STORAGE_OPKEY_ABILITY_H 100