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 #ifndef OHOS_RESOURCE_MANAGER_SYSTEMRESOURCEMANAGER_H 16 #define OHOS_RESOURCE_MANAGER_SYSTEMRESOURCEMANAGER_H 17 18 #include <memory> 19 #include "resource_manager_impl.h" 20 21 namespace OHOS { 22 namespace Global { 23 namespace Resource { 24 class SystemResourceManager { 25 public: 26 SystemResourceManager(); 27 28 ~SystemResourceManager(); 29 30 /** 31 * Get system resource manager, the added system resource is sandbox path. This method should call 32 * after the sandbox mount. 33 * 34 * @return pointer of system resource manager 35 */ 36 static ResourceManagerImpl *GetSystemResourceManager(); 37 38 /** 39 * Get system resource manager, the added system resource is no sandbox path. This method should call 40 * before the sandbox mount, for example appspawn. 41 * 42 * @return pointer of system resource manager 43 */ 44 static ResourceManagerImpl *GetSystemResourceManagerNoSandBox(); 45 46 /** 47 * Release system resource manager. 48 */ 49 static void ReleaseSystemResourceManager(); 50 51 /** 52 * Add system resource to hap resource vector. 53 * 54 * @param resourceManager the hap resource manager. 55 */ 56 static bool AddSystemResource(ResourceManagerImpl *resourceManager); 57 58 /** 59 * create system resource manager 60 * 61 * @return the new system resource manager 62 */ 63 EXPORT_FUNC static std::shared_ptr<ResourceManagerImpl> CreateSysResourceManager(); 64 65 /** 66 * update system resource manager resconfig 67 * 68 * @param resConfig the current resconfig 69 * @param isThemeSystemResEnable if true means is theme system res enable 70 */ 71 static void UpdateSysResConfig(ResConfigImpl &resConfig, bool isThemeSystemResEnable); 72 73 #if defined(__ARKUI_CROSS__) || defined(__IDE_PREVIEW__) 74 /** 75 * add system resource for preview 76 * 77 * @param resMgr the system resource manager 78 */ 79 static void AddSystemResourceForPreview(ResourceManagerImpl* resMgr); 80 #endif 81 private: 82 static std::mutex mutex_; 83 84 static ResourceManagerImpl *resourceManager_; 85 86 static std::weak_ptr<ResourceManagerImpl> weakResourceManager_; 87 88 static const std::string SYSTEM_RESOURCE_PATH; 89 90 static const std::string SYSTEM_RESOURCE_PATH_COMPRESSED; 91 92 static const std::string SYSTEM_RESOURCE_OVERLAY_PATH; 93 94 static const std::string SYSTEM_RESOURCE_OVERLAY_PATH_COMPRESSED; 95 96 static const std::string SYSTEM_RESOURCE_NO_SAND_BOX_PKG_PATH; 97 98 static const std::string SYSTEM_RESOURCE_NO_SAND_BOX_HAP_PATH; 99 100 static const std::string SYSTEM_RESOURCE_EXT_NO_SAND_BOX_HAP_PATH; 101 102 static bool LoadSystemResource(ResourceManagerImpl *impl, bool isSandbox = true); 103 104 static ResourceManagerImpl *CreateSystemResourceManager(bool isSandbox); 105 106 static std::shared_ptr<ResourceManagerImpl> CreateSystemResourceManager(); 107 108 static void SaveResConfig(ResConfigImpl &resConfig, bool isThemeSystemResEnable); 109 110 static void UpdateResConfig(ResConfigImpl &resConfig, bool isThemeSystemResEnable); 111 112 static bool InitResourceManager(ResourceManagerImpl *impl); 113 114 static std::mutex sysResMgrMutex_; 115 116 static std::shared_ptr<ResourceManagerImpl> sysResMgr_; 117 118 static std::shared_ptr<ResConfigImpl> resConfig_; 119 120 static bool isUpdateAppConfig_; 121 122 static bool isThemeSystemResEnable_; 123 }; 124 } // namespace Resource 125 } // namespace Global 126 } // namespace OHOS 127 #endif