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 FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_DB 17 #define FOUNDATION_DEFAULT_APPLICATION_FRAMEWORK_DEFAULT_APP_DB 18 19 #include "default_app_db_interface.h" 20 #include "distributed_kv_data_manager.h" 21 #include "kvstore_death_recipient.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 class DefaultAppDb final : 26 public IDefaultAppDb, 27 public std::enable_shared_from_this<DefaultAppDb>, 28 public DistributedKv::KvStoreDeathRecipient { 29 public: 30 DefaultAppDb(); 31 ~DefaultAppDb(); 32 bool GetDefaultApplicationInfos(int32_t userId, std::map<std::string, Element>& infos) override; 33 bool GetDefaultApplicationInfo(int32_t userId, const std::string& type, Element& element) override; 34 bool SetDefaultApplicationInfos(int32_t userId, const std::map<std::string, Element>& infos) override; 35 bool SetDefaultApplicationInfo(int32_t userId, const std::string& type, const Element& element) override; 36 bool DeleteDefaultApplicationInfos(int32_t userId) override; 37 bool DeleteDefaultApplicationInfo(int32_t userId, const std::string& type) override; 38 virtual void OnRemoteDied() override; 39 void RegisterDeathListener() override; 40 void UnRegisterDeathListener() override; 41 private: 42 void Init(); 43 bool OpenKvDb(); 44 void LoadDefaultApplicationConfig(); 45 bool GetDataFromDb(int32_t userId, std::map<std::string, Element>& infos); 46 bool SaveDataToDb(int32_t userId, const std::map<std::string, Element>& infos); 47 bool DeleteDataFromDb(int32_t userId); 48 49 const DistributedKv::AppId appId_ { Constants::APP_ID }; 50 const DistributedKv::StoreId storeId_ { Constants::DEFAULT_APP_DATA_STORE_ID }; 51 DistributedKv::DistributedKvDataManager dataManager_; 52 std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_; 53 }; 54 } 55 } 56 #endif 57