1 /* 2 * Copyright (c) 2023 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_GLOBAL_PARAMS_ABILITY_H 17 #define DATA_STORAGE_GLOBAL_PARAMS_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_global_params_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 GlobalParamsUriType { 46 UNKNOW, 47 ECC_LIST, 48 NUMBER_MATCHS 49 }; 50 51 class GlobalParamsAbility : public DataShare::DataShareExtAbility { 52 public: 53 GlobalParamsAbility(); 54 virtual ~GlobalParamsAbility() override; 55 static GlobalParamsAbility* Create(); 56 void DoInit(); 57 sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override; 58 virtual void OnStart(const AppExecFwk::Want &want) override; 59 virtual int Insert(const Uri &uri, const DataShare::DataShareValuesBucket &value) 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::shared_ptr<DataShare::DataShareResultSet> Query(const Uri &uri, 64 const DataShare::DataSharePredicates &predicates, std::vector<std::string> &columns, 65 DataShare::DatashareBusinessError &businessError) override; 66 virtual std::string GetType(const Uri &uri) override; 67 virtual int OpenFile(const Uri &uri, const std::string &mode) override; 68 69 private: 70 /** 71 * Parse Uri Type 72 * 73 * @param uri Resource address 74 * @return return GlobalParamsUriType 75 */ 76 GlobalParamsUriType ParseUriType(Uri &uri); 77 78 /** 79 * Convert DataSharePredicates to RdbPredicates 80 * 81 * @param tableName table name of the predicates 82 * @param predicates DataSharePredicates 83 */ 84 OHOS::NativeRdb::RdbPredicates ConvertPredicates( 85 const std::string &tableName, const DataShare::DataSharePredicates &predicates); 86 87 /** 88 * Check whether the initialization succeeds 89 * 90 * @return true : succeed ,false : failed 91 */ 92 bool IsInitOk(); 93 94 private: 95 RdbGlobalParamsHelper helper_; 96 std::mutex lock_; 97 bool initDatabaseDir_ = false; 98 bool initRdbStore_ = false; 99 }; 100 } // namespace Telephony 101 } // namespace OHOS 102 #endif // DATA_STORAGE_GLOBAL_PARAMS_ABILITY_H