• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 private:
59     static std::mutex mutex_;
60 
61     static ResourceManagerImpl *resourceManager_;
62 
63     static std::weak_ptr<ResourceManagerImpl> weakResourceManager_;
64 
65     static const std::string SYSTEM_RESOURCE_PATH;
66 
67     static const std::string SYSTEM_RESOURCE_PATH_COMPRESSED;
68 
69     static const std::string SYSTEM_RESOURCE_OVERLAY_PATH;
70 
71     static const std::string SYSTEM_RESOURCE_OVERLAY_PATH_COMPRESSED;
72 
73     static const std::string SYSTEM_RESOURCE_NO_SAND_BOX_PKG_PATH;
74 
75     static const std::string SYSTEM_RESOURCE_NO_SAND_BOX_HAP_PATH;
76 
77     static const std::string SYSTEM_RESOURCE_EXT_NO_SAND_BOX_HAP_PATH;
78 
79     static bool LoadSystemResource(ResourceManagerImpl *impl, bool isSandbox = true);
80 
81     static ResourceManagerImpl *CreateSystemResourceManager(bool isSandbox);
82     static std::shared_ptr<ResourceManagerImpl> CreateSystemResourceManager();
83 };
84 } // namespace Resource
85 } // namespace Global
86 } // namespace OHOS
87 #endif