1 /* 2 * Copyright (c) 2025 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_ROSEN_WINDOW_SCENE_STARTING_WINDOW_RDB_MANAGER_H 17 #define OHOS_ROSEN_WINDOW_SCENE_STARTING_WINDOW_RDB_MANAGER_H 18 19 #include <atomic> 20 #include <mutex> 21 #include <utility> 22 23 #include "rdb_helper.h" 24 25 #include "interfaces/include/ws_common.h" 26 #include "wms_rdb_open_callback.h" 27 28 namespace OHOS::AppExecFwk { 29 class IBundleMgr; 30 struct AbilityInfo; 31 struct BundleInfo; 32 class LauncherService; 33 } // namespace OHOS::AppExecFwk 34 35 namespace OHOS::Global::Resource { 36 class ResourceManager; 37 } // namespace OHOS::Global::Resource 38 39 namespace OHOS { 40 namespace Rosen { 41 struct StartingWindowRdbItemKey { 42 std::string bundleName; 43 std::string moduleName; 44 std::string abilityName; 45 bool darkMode; 46 }; 47 48 class StartingWindowRdbManager final { 49 public: 50 StartingWindowRdbManager(const WmsRdbConfig& rdbConfig); 51 ~StartingWindowRdbManager(); 52 53 bool Init(); 54 bool InsertData(const StartingWindowRdbItemKey& key, const StartingWindowInfo& value); 55 bool BatchInsert(int64_t& outInsertNum, 56 const std::vector<std::pair<StartingWindowRdbItemKey, StartingWindowInfo>>& inputValues); 57 bool DeleteDataByBundleName(const std::string& bundleName); 58 bool DeleteAllData(); 59 bool QueryData(const StartingWindowRdbItemKey& key, StartingWindowInfo& value); 60 std::string GetStartWindowValFromProfile(const AppExecFwk::AbilityInfo& abilityInfo, 61 const std::shared_ptr<Global::Resource::ResourceManager>& resourceMgr, 62 const std::string& key, const std::string& defaultVal); 63 void ClearRdbStore(); 64 65 private: 66 std::shared_ptr<NativeRdb::RdbStore> GetRdbStore(); 67 68 std::mutex rdbMutex_; 69 std::shared_ptr<NativeRdb::RdbStore> rdbStore_; 70 WmsRdbConfig wmsRdbConfig_; 71 }; 72 } // namespace Rosen 73 } // namespace OHOS 74 #endif // OHOS_ROSEN_WINDOW_SCENE_STARTING_WINDOW_RDB_MANAGER_H