1 /* 2 * Copyright (C) 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_base" 20 #include "__mutex_base" 21 #include "ability.h" 22 #include "ability_lifecycle.h" 23 #include "iosfwd" 24 #include "map" 25 #include "memory" 26 #include "rdb_opkey_helper.h" 27 #include "string" 28 #include "telephony_permission.h" 29 #include "vector" 30 31 namespace OHOS { 32 namespace NativeRdb { 33 class AbsRdbPredicates; 34 class AbsSharedResultSet; 35 class DataAbilityPredicates; 36 class ValuesBucket; 37 } 38 namespace Telephony { 39 enum class OpKeyUriType { 40 UNKNOW, OPKEY_INFO 41 }; 42 class OpKeyAbility : public AppExecFwk::Ability { 43 public: 44 virtual void OnStart(const AppExecFwk::Want &want) override; 45 virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override; 46 virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query( 47 const Uri &uri, const std::vector<std::string> &columns, 48 const NativeRdb::DataAbilityPredicates &predicates) override; 49 virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value, 50 const NativeRdb::DataAbilityPredicates &predicates) override; 51 virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override; 52 virtual std::string GetType(const Uri &uri) override; 53 virtual int OpenFile(const Uri &uri, const std::string &mode) override; 54 55 private: 56 /** 57 * Parse Uri Type 58 * 59 * @param uri Resource address 60 * @return return OpKeyUriType 61 */ 62 OpKeyUriType ParseUriType(Uri &uri); 63 64 /** 65 * Convert DataAbilityPredicates to AbsRdbPredicates 66 * 67 * @param predicates DataAbilityPredicates 68 * @param absRdbPredicates AbsRdbPredicates 69 */ 70 void ConvertPredicates( 71 const NativeRdb::DataAbilityPredicates &predicates, NativeRdb::AbsRdbPredicates *absRdbPredicates); 72 73 /** 74 * Check whether the initialization succeeds 75 * 76 * @return true : succeed ,false : failed 77 */ 78 bool IsInitOk(); 79 80 /** 81 * Init UriMap 82 */ 83 void InitUriMap(); 84 85 private: 86 RdbOpKeyHelper helper_; 87 std::mutex lock_; 88 std::map<std::string, OpKeyUriType> opKeyUriMap_; 89 bool initDatabaseDir_ = false; 90 bool initRdbStore_ = false; 91 }; 92 } // namespace Telephony 93 } // namespace OHOS 94 #endif // DATA_STORAGE_OPKEY_ABILITY_H