• 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      * Add system resource to hap resource vector.
48      *
49      * @param resourceManager the hap resource manager.
50      */
51     static bool AddSystemResource(ResourceManagerImpl *resourceManager);
52 
53 private:
54     static std::mutex mutex_;
55 
56     static ResourceManagerImpl *resourceManager_;
57 
58     static std::weak_ptr<ResourceManagerImpl> weakResourceManager_;
59 
60     static const std::string SYSTEM_RESOURCE_PATH;
61 
62     static const std::string SYSTEM_RESOURCE_PATH_COMPRESSED;
63 
64     static const std::string SYSTEM_RESOURCE_OVERLAY_PATH;
65 
66     static const std::string SYSTEM_RESOURCE_OVERLAY_PATH_COMPRESSED;
67 
68     static const std::string SYSTEM_RESOURCE_NO_SAND_BOX_PKG_PATH;
69 
70     static const std::string SYSTEM_RESOURCE_NO_SAND_BOX_HAP_PATH;
71 
72     static const std::string SYSTEM_RESOURCE_EXT_NO_SAND_BOX_HAP_PATH;
73 
74     static bool LoadSystemResource(ResourceManagerImpl *impl, bool isSandbox = true);
75 
76     static ResourceManagerImpl *CreateSystemResourceManager(bool isSandbox);
77 
78     static std::shared_ptr<ResourceManagerImpl> CreateSystemResourceManager();
79 };
80 } // namespace Resource
81 } // namespace Global
82 } // namespace OHOS
83 #endif