• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RESOURCEMANAGER_H
17 #define RESOURCEMANAGER_H
18 
19 #include <ani.h>
20 #include <array>
21 #include <iostream>
22 
23 #include "application_context.h"
24 #include "resource_manager.h"
25 
26 namespace OHOS {
27 namespace Global {
28 namespace Resource {
29 class ResMgrAddon {
30 public:
31     ResMgrAddon(const std::string& bundleName, const std::shared_ptr<ResourceManager>& resMgr,
32         const std::shared_ptr<OHOS::AbilityRuntime::Context>& context, bool isSystem = false);
33     ResMgrAddon(const std::shared_ptr<ResourceManager>& resMgr, bool isSystem = false);
34     ani_object CreateOverrideAddon(ani_env* env, const std::shared_ptr<ResourceManager>& resMgr);
35 
36     static ani_object CreateResMgr(ani_env* env, const std::string& bundleName,
37         const std::shared_ptr<ResourceManager>& resMgr, std::shared_ptr<AbilityRuntime::Context> context);
38 
39     static ani_object GetSysResourceManager(ani_env* env);
40 
41     static ani_string GetStringSyncById(ani_env* env, ani_object object, ani_double resId);
42 
43     static ani_string GetFormatStringSyncById(ani_env *env, ani_object object, ani_double resId, ani_object args);
44 
45     static ani_string GetStringByNameSync(ani_env* env, ani_object object, ani_string resName);
46 
47     static ani_string GetFormatStringByNameSync(ani_env *env, ani_object object, ani_string resName, ani_object args);
48 
49     static ani_boolean GetBooleanById(ani_env* env, ani_object object, ani_double resId);
50 
51     static ani_boolean GetBooleanByName(ani_env* env, ani_object object, ani_string resName);
52 
53     static ani_double GetNumberById(ani_env* env, ani_object object, ani_double resId);
54 
55     static ani_double GetNumberByName(ani_env* env, ani_object object, ani_string resName);
56 
57     static ani_double GetColorSyncById(ani_env* env, ani_object object, ani_double resId);
58 
59     static ani_string GetIntPluralStringValueSyncById(ani_env* env, ani_object object,
60         ani_double resId, ani_double num, ani_object args);
61 
62     static ani_string GetIntPluralStringByNameSync(ani_env* env, ani_object object,
63         ani_string resName, ani_double num, ani_object args);
64 
65     static ani_string GetDoublePluralStringValueSyncById(ani_env* env, ani_object object,
66         ani_double resId, ani_double num, ani_object args);
67 
68     static ani_string GetDoublePluralStringByNameSync(ani_env* env, ani_object object,
69         ani_string resName, ani_double num, ani_object args);
70 
71     static ani_double GetColorByNameSync(ani_env* env, ani_object object, ani_string resName);
72 
73     static void AddResource(ani_env* env, ani_object object, ani_string path);
74 
75     static void RemoveResource(ani_env* env, ani_object object, ani_string path);
76 
77     static ani_object GetRawFdSync(ani_env* env, ani_object object, ani_string path);
78 
79     static void CloseRawFdSync(ani_env* env, ani_object object, ani_string path);
80 
81     static ani_boolean IsRawDir(ani_env* env, ani_object object, ani_string path);
82 
83     static ani_object GetRawFileListSync(ani_env* env, ani_object object, ani_string path);
84 
85     static ani_object GetRawFileContentSync(ani_env* env, ani_object object, ani_string path);
86 
87     static ani_object GetMediaContentSyncById(ani_env* env, ani_object object,
88         ani_double resId, ani_object density);
89 
90     static ani_string GetMediaContentBase64SyncById(ani_env* env, ani_object object,
91         ani_double resId, ani_object density);
92 
93     static ani_object GetStringArrayValueSyncById(ani_env* env, ani_object object, ani_double resId);
94 
95     static ani_object GetStringArrayByNameSync(ani_env* env, ani_object object, ani_string resName);
96 
97     static ani_object GetMediaByNameSync(ani_env* env, ani_object object, ani_string resName, ani_object density);
98 
99     static ani_string GetMediaBase64ByNameSync(ani_env* env, ani_object object, ani_string resName, ani_object density);
100 
101     static ani_object GetConfigurationSync(ani_env* env, ani_object object);
102 
103     static ani_object GetDeviceCapabilitySync(ani_env* env, ani_object object);
104 
105     static ani_object GetLocales(ani_env* env, ani_object object, ani_object includeSystem);
106 
107     static ani_double GetSymbolById(ani_env* env, ani_object object, ani_double resId);
108 
109     static ani_double GetSymbolByName(ani_env* env, ani_object object, ani_string resName);
110 
111     static ani_object GetOverrideResourceManager(ani_env* env, ani_object object, ani_object configuration);
112 
113     static ani_object GetOverrideConfiguration(ani_env* env, ani_object object);
114 
115     static void UpdateOverrideConfiguration(ani_env* env, ani_object object, ani_object configuration);
116 
117     static ani_status BindContext(ani_env* env);
118 
GetResMgr()119     inline std::shared_ptr<ResourceManager> GetResMgr()
120     {
121         return resMgr_;
122     }
123 
GetContext()124     inline std::shared_ptr<AbilityRuntime::Context> GetContext()
125     {
126         return context_;
127     }
128 
IsSystem()129     inline bool IsSystem()
130     {
131         return isSystem_;
132     }
133 
isOverrideAddon()134     bool isOverrideAddon()
135     {
136         return isOverrideAddon_;
137     }
138 
139 private:
140     static ani_object WrapResourceManager(ani_env* env, std::shared_ptr<ResMgrAddon> &addon);
141 
142     std::string bundleName_;
143     std::shared_ptr<ResourceManager> resMgr_;
144     std::shared_ptr<AbilityRuntime::Context> context_;
145     bool isSystem_ = false;
146     bool isOverrideAddon_ = false;
147 };
148 } // namespace Resource
149 } // namespace Global
150 } // namespace OHOS
151 #endif
152