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 FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_ICON_RDB_H 17 #define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_ICON_RDB_H 18 19 #include <unordered_map> 20 #include <shared_mutex> 21 #include <vector> 22 23 #include "bundle_resource_info.h" 24 #include "launcher_ability_resource_info.h" 25 #include "rdb_data_manager.h" 26 #include "resource_info.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 class BundleResourceIconRdb : public std::enable_shared_from_this<BundleResourceIconRdb> { 31 public: 32 BundleResourceIconRdb(); 33 ~BundleResourceIconRdb(); 34 // add resource info to resource rdb 35 bool AddResourceIconInfo(const int32_t userId, const IconResourceType type, 36 const ResourceInfo &resourceInfo); 37 38 bool AddResourceIconInfos(const int32_t userId, const IconResourceType type, 39 const std::vector<ResourceInfo> &resourceInfos); 40 41 bool DeleteResourceIconInfo(const std::string &bundleName, const int32_t userId, 42 const int32_t appIndex = 0, const IconResourceType type = IconResourceType::UNKNOWN); 43 44 bool DeleteResourceIconInfos(const std::string &bundleName, const int32_t userId, 45 const IconResourceType type = IconResourceType::UNKNOWN); 46 47 bool DeleteResourceIconInfos(const std::string &bundleName, 48 const IconResourceType type = IconResourceType::UNKNOWN); 49 50 bool GetAllResourceIconName(const int32_t userId, std::set<std::string> &resourceNames, 51 const IconResourceType type = IconResourceType::UNKNOWN); 52 53 bool GetResourceIconInfos(const std::string &bundleName, const int32_t userId, 54 const int32_t appIndex, const uint32_t resourceFlag, 55 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos, 56 const IconResourceType type = IconResourceType::UNKNOWN); 57 58 bool GetAllResourceIconInfo(const int32_t userId, const uint32_t resourceFlag, 59 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos); 60 61 void SetIsOnlineTheme(const int32_t userId, bool isOnlineTheme); 62 63 bool GetIsOnlineTheme(const int32_t userId); 64 65 private: 66 void ParseNameToResourceName(const std::string &name, std::string &resourceName); 67 68 bool ConvertToLauncherAbilityResourceInfo( 69 const std::shared_ptr<NativeRdb::ResultSet> &absSharedResultSet, const uint32_t resourceFlag, 70 LauncherAbilityResourceInfo &launcherAbilityResourceInfo, IconResourceType &iconType); 71 72 void ParseKey(const std::string &key, 73 LauncherAbilityResourceInfo &launcherAbilityResourceInfo); 74 75 void InnerProcessResourceIconInfos(const LauncherAbilityResourceInfo &resourceInfo, 76 const IconResourceType type, const int32_t userId, 77 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos); 78 79 std::shared_ptr<RdbDataManager> rdbDataManager_; 80 mutable ffrt::shared_mutex isOnlineThemeMutex_; 81 std::unordered_map<int32_t, bool> isOnlineThemeMap_; 82 83 #define CHECK_RDB_RESULT_RETURN_IF_FAIL(errcode, errmsg) \ 84 do { \ 85 if ((errcode) != NativeRdb::E_OK) { \ 86 APP_LOGE(errmsg, errcode); \ 87 return false; \ 88 } \ 89 } while (0) 90 }; 91 } // AppExecFwk 92 } // OHOS 93 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_ICON_RDB_H 94