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 OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_H 18 19 #include <mutex> 20 #include <vector> 21 22 #include "auto_startup_info.h" 23 #include "distributed_kv_data_manager.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace AbilityRuntime { 28 class AbilityAutoStartupDataManager : public DelayedSingleton<AbilityAutoStartupDataManager> { 29 public: 30 AbilityAutoStartupDataManager(); 31 32 virtual ~AbilityAutoStartupDataManager(); 33 34 int32_t InsertAutoStartupData(const AutoStartupInfo &info, bool isAutoStartup, bool isEdmForce); 35 36 int32_t UpdateAutoStartupData(const AutoStartupInfo &info, bool isAutoStartup, bool isEdmForce); 37 38 int32_t DeleteAutoStartupData(const AutoStartupInfo &info); 39 40 int32_t DeleteAutoStartupData(const std::string &bundleName); 41 42 AutoStartupStatus QueryAutoStartupData(const AutoStartupInfo &info); 43 44 int32_t QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList); 45 46 int32_t GetCurrentAppAutoStartupData(const std::string &bundleName, std::vector<AutoStartupInfo> &infoList); 47 48 private: 49 DistributedKv::Status GetKvStore(); 50 bool CheckKvStore(); 51 DistributedKv::Value ConvertAutoStartupStatusToValue( 52 bool isAutoStartup, bool isEdmForce, const std::string &abilityTypeName); 53 void ConvertAutoStartupStatusFromValue(const DistributedKv::Value &value, bool &isAutoStartup, bool &isEdmForce); 54 DistributedKv::Key ConvertAutoStartupDataToKey(const AutoStartupInfo &info); 55 AutoStartupInfo ConvertAutoStartupInfoFromKeyAndValue( 56 const DistributedKv::Key &key, const DistributedKv::Value &value); 57 bool IsEqual(const DistributedKv::Key &key, const AutoStartupInfo &info); 58 bool IsEqual(const DistributedKv::Key &key, const std::string &bundleName); 59 60 static const DistributedKv::AppId APP_ID; 61 static const DistributedKv::StoreId STORE_ID; 62 DistributedKv::DistributedKvDataManager dataManager_; 63 std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_; 64 mutable std::mutex kvStorePtrMutex_; 65 }; 66 } // namespace AbilityRuntime 67 } // namespace OHOS 68 #endif // OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_H