• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "ohresmgr.h"
17 
18 #include <securec.h>
19 #include "drawable_descriptor/drawable_descriptor.h"
20 #include "hilog_wrapper.h"
21 #include "resource_manager_impl.h"
22 #include "rstate.h"
23 #include "utils/utils.h"
24 
25 using namespace OHOS::Global::Resource;
26 using namespace OHOS::Ace::Napi;
27 
28 struct NativeResourceManager {
29     std::shared_ptr<ResourceManager> resManager = nullptr;
30 };
31 
copyStringArray(char *** resultValue,uint32_t * resultLen,vector<string> tempResultValue,string apiName)32 ResourceManager_ErrorCode copyStringArray(char ***resultValue, uint32_t *resultLen,
33     vector<string> tempResultValue, string apiName)
34 {
35     size_t len = tempResultValue.size();
36     *resultValue = new char* [tempResultValue.size()];
37     if (*resultValue == nullptr) {
38         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "%{public}s malloc error", apiName.c_str());
39         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
40     }
41     for (size_t i = 0; i < len; i++) {
42         size_t strLen = tempResultValue[i].size();
43         (*resultValue)[i] = new char[strLen + 1];
44         if ((*resultValue)[i] == nullptr) {
45             RESMGR_HILOGE(RESMGR_NATIVE_TAG, "%{public}s malloc error", apiName.c_str());
46             OH_ResourceManager_ReleaseStringArray(resultValue, len);
47             return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
48         }
49         if (strncpy_s((*resultValue)[i], strLen + 1, tempResultValue[i].c_str(), strLen) != 0) {
50             RESMGR_HILOGE(RESMGR_NATIVE_TAG, "%{public}s strncpy_s error", apiName.c_str());
51             OH_ResourceManager_ReleaseStringArray(resultValue, len);
52             return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
53         }
54     }
55     *resultLen = static_cast<uint32_t>(len);
56     return ResourceManager_ErrorCode::SUCCESS;
57 }
58 
copyLocalInfo(const icu::Locale * localeInfo,ResourceManager_Configuration * configuration)59 ResourceManager_ErrorCode copyLocalInfo(const icu::Locale *localeInfo, ResourceManager_Configuration *configuration)
60 {
61     std::string locale;
62     if (localeInfo == nullptr) {
63         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
64             "failed get configuration localeInfo errorCode = %{public}d",
65             ResourceManager_ErrorCode::ERROR_CODE_SYSTEM_RES_MANAGER_GET_FAILED);
66         return ResourceManager_ErrorCode::ERROR_CODE_SYSTEM_RES_MANAGER_GET_FAILED;
67     }
68     const char *lang = localeInfo->getLanguage();
69     if (lang == nullptr) {
70         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
71             "failed get configuration language errorCode = %{public}d",
72             ResourceManager_ErrorCode::ERROR_CODE_SYSTEM_RES_MANAGER_GET_FAILED);
73         return ResourceManager_ErrorCode::ERROR_CODE_SYSTEM_RES_MANAGER_GET_FAILED;
74     }
75     locale = lang;
76     const char *script = localeInfo->getScript();
77     if (script != nullptr) {
78         locale += std::string("_") + script;
79     }
80     const char *region = localeInfo->getCountry();
81     if (region != nullptr) {
82         locale += std::string("_") + region;
83     }
84     configuration->locale = (char*)malloc(locale.size() + 1);
85     if (configuration->locale == nullptr) {
86         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetConfiguration malloc error");
87         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
88     }
89     if (strncpy_s(configuration->locale, locale.size() + 1, locale.c_str(), locale.size()) != 0) {
90         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetConfiguration locale strncpy_s error");
91         free(configuration->locale);
92         configuration->locale = nullptr;
93         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
94     }
95     return ResourceManager_ErrorCode::SUCCESS;
96 }
97 
copyString(char ** resultValue,string tempResultValue,string apiName)98 ResourceManager_ErrorCode copyString(char **resultValue, string tempResultValue, string apiName)
99 {
100     size_t len = tempResultValue.size();
101     *resultValue = (char*)malloc(tempResultValue.size() + 1);
102     if (*resultValue == nullptr) {
103         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "%{public}s malloc error", apiName.c_str());
104         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
105     }
106     if (strncpy_s(*resultValue, len + 1, tempResultValue.c_str(), len) != 0) {
107         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "%{public}s strncpy_s error", apiName.c_str());
108         free(*resultValue);
109         *resultValue = nullptr;
110         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
111     }
112     return ResourceManager_ErrorCode::SUCCESS;
113 }
114 
OH_ResourceManager_GetMediaBase64(const NativeResourceManager * mgr,uint32_t resId,char ** resultValue,uint64_t * resultLen,uint32_t density)115 ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64(const NativeResourceManager *mgr, uint32_t resId,
116     char **resultValue, uint64_t *resultLen, uint32_t density)
117 {
118     return OH_ResourceManager_GetMediaBase64Data(mgr, resId, resultValue, resultLen, density);
119 }
120 
OH_ResourceManager_GetMediaBase64Data(const NativeResourceManager * mgr,uint32_t resId,char ** resultValue,uint64_t * resultLen,uint32_t density)121 ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64Data(const NativeResourceManager *mgr, uint32_t resId,
122     char **resultValue, uint64_t *resultLen, uint32_t density)
123 {
124     if (mgr == nullptr || resultValue == nullptr || resultLen == nullptr || mgr->resManager == nullptr) {
125         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
126     }
127     std::string tempResultValue;
128     RState state = mgr->resManager->GetMediaBase64DataById(resId, tempResultValue, density);
129     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
130     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
131         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
132             "failed get media base64 id = %{public}d, errorCode = %{public}d", resId, errorCode);
133         return errorCode;
134     }
135     *resultValue = (char*)malloc(tempResultValue.size() + 1);
136     if (*resultValue == nullptr) {
137         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetMediaBase64 malloc error");
138         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
139     }
140     if (strncpy_s(*resultValue, tempResultValue.size() + 1, tempResultValue.c_str(), tempResultValue.size()) != 0) {
141         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetMediaBase64 strncpy_s error");
142         free(*resultValue);
143         *resultValue = nullptr;
144         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
145     }
146     *resultLen = static_cast<uint64_t>(tempResultValue.size());
147     return errorCode;
148 }
149 
OH_ResourceManager_GetMediaBase64ByName(const NativeResourceManager * mgr,const char * resName,char ** resultValue,uint64_t * resultLen,uint32_t density)150 ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64ByName(const NativeResourceManager *mgr,
151     const char *resName, char **resultValue, uint64_t *resultLen, uint32_t density)
152 {
153     return OH_ResourceManager_GetMediaBase64DataByName(mgr, resName, resultValue, resultLen, density);
154 }
155 
OH_ResourceManager_GetMediaBase64DataByName(const NativeResourceManager * mgr,const char * resName,char ** resultValue,uint64_t * resultLen,uint32_t density)156 ResourceManager_ErrorCode OH_ResourceManager_GetMediaBase64DataByName(const NativeResourceManager *mgr,
157     const char *resName, char **resultValue, uint64_t *resultLen, uint32_t density)
158 {
159     if (mgr == nullptr || resultValue == nullptr || resultLen == nullptr || mgr->resManager == nullptr) {
160         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
161     }
162 
163     std::string tempResultValue;
164     RState state = mgr->resManager->GetMediaBase64DataByName(resName, tempResultValue, density);
165     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
166     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
167         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
168             "failed get media base64 name = %{public}s, errorCode = %{public}d", resName, errorCode);
169         return errorCode;
170     }
171     *resultValue = (char*)malloc(tempResultValue.size() + 1);
172     if (*resultValue == nullptr) {
173         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetMediaBase64Byname malloc error");
174         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
175     }
176     if (strncpy_s(*resultValue, tempResultValue.size() + 1, tempResultValue.c_str(), tempResultValue.size()) != 0) {
177         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetMediaBase64Byname strncpy_s error");
178         free(*resultValue);
179         *resultValue = nullptr;
180         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
181     }
182     *resultLen = static_cast<uint64_t>(tempResultValue.size());
183     return errorCode;
184 }
185 
OH_ResourceManager_GetMedia(const NativeResourceManager * mgr,uint32_t resId,uint8_t ** resultValue,uint64_t * resultLen,uint32_t density)186 ResourceManager_ErrorCode OH_ResourceManager_GetMedia(const NativeResourceManager *mgr, uint32_t resId,
187     uint8_t **resultValue, uint64_t *resultLen, uint32_t density)
188 {
189     return OH_ResourceManager_GetMediaData(mgr, resId, resultValue, resultLen, density);
190 }
191 
OH_ResourceManager_GetMediaData(const NativeResourceManager * mgr,uint32_t resId,uint8_t ** resultValue,uint64_t * resultLen,uint32_t density)192 ResourceManager_ErrorCode OH_ResourceManager_GetMediaData(const NativeResourceManager *mgr, uint32_t resId,
193     uint8_t **resultValue, uint64_t *resultLen, uint32_t density)
194 {
195     if (mgr == nullptr || resultValue == nullptr || resultLen == nullptr || mgr->resManager == nullptr) {
196         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
197     }
198 
199     std::unique_ptr<uint8_t[]> tempResultValue;
200     size_t len;
201     RState state = mgr->resManager->GetMediaDataById(resId, len, tempResultValue, density);
202     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
203     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
204         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
205             "failed get media resource id = %{public}d, errorCode = %{public}d", resId, errorCode);
206         return errorCode;
207     }
208     uint8_t *temPtr = tempResultValue.get();
209     *resultValue = static_cast<uint8_t*>(malloc(len));
210     if (*resultValue == nullptr) {
211         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetMedia malloc error");
212         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
213     }
214     std::copy(temPtr, temPtr + len, *resultValue);
215     *resultLen = static_cast<uint64_t>(len);
216     return errorCode;
217 }
218 
OH_ResourceManager_GetMediaByName(const NativeResourceManager * mgr,const char * resName,uint8_t ** resultValue,uint64_t * resultLen,uint32_t density)219 ResourceManager_ErrorCode OH_ResourceManager_GetMediaByName(const NativeResourceManager *mgr, const char *resName,
220     uint8_t **resultValue, uint64_t *resultLen, uint32_t density)
221 {
222     return OH_ResourceManager_GetMediaDataByName(mgr, resName, resultValue, resultLen, density);
223 }
224 
OH_ResourceManager_GetMediaDataByName(const NativeResourceManager * mgr,const char * resName,uint8_t ** resultValue,uint64_t * resultLen,uint32_t density)225 ResourceManager_ErrorCode OH_ResourceManager_GetMediaDataByName(const NativeResourceManager *mgr, const char *resName,
226     uint8_t **resultValue, uint64_t *resultLen, uint32_t density)
227 {
228     if (mgr == nullptr || resultValue == nullptr || resultLen == nullptr || mgr->resManager == nullptr) {
229         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
230     }
231 
232     std::unique_ptr<uint8_t[]> tempResultValue;
233     size_t len;
234     RState state = mgr->resManager->GetMediaDataByName(resName, len, tempResultValue, density);
235     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
236     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
237         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
238             "failed get media resource name = %{public}s, errorCode = %{public}d", resName, errorCode);
239         return errorCode;
240     }
241     uint8_t *temPtr = tempResultValue.get();
242     *resultValue = static_cast<uint8_t*>(malloc(len));
243     if (*resultValue == nullptr) {
244         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "GetMediaByName malloc error");
245         return ResourceManager_ErrorCode::ERROR_CODE_OUT_OF_MEMORY;
246     }
247     std::copy(temPtr, temPtr + len, *resultValue);
248     *resultLen = static_cast<uint64_t>(len);
249     return errorCode;
250 }
251 
OH_ResourceManager_GetDrawableDescriptor(const NativeResourceManager * mgr,uint32_t resId,ArkUI_DrawableDescriptor ** drawableDescriptor,uint32_t density,uint32_t type)252 ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptor(const NativeResourceManager *mgr,
253     uint32_t resId, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type)
254 {
255     return OH_ResourceManager_GetDrawableDescriptorData(mgr, resId, drawableDescriptor, density, type);
256 }
257 
ProcessThemeIcon(const std::shared_ptr<ResourceManager> & resourceMgr,ArkUI_DrawableDescriptor ** drawableDescriptor,std::pair<std::unique_ptr<uint8_t[]>,size_t> & foregroundInfo,std::pair<std::unique_ptr<uint8_t[]>,size_t> & backgroundInfo,std::string & themeMask)258 ResourceManager_ErrorCode ProcessThemeIcon(const std::shared_ptr<ResourceManager>& resourceMgr,
259     ArkUI_DrawableDescriptor **drawableDescriptor,
260     std::pair<std::unique_ptr<uint8_t[]>, size_t> &foregroundInfo,
261     std::pair<std::unique_ptr<uint8_t[]>, size_t> &backgroundInfo, std::string &themeMask)
262 {
263     if (backgroundInfo.first == nullptr &&
264         Utils::GetSystemParameter("const.global.support_single_icon_theme") == "true") {
265         auto descriptor = std::make_unique<DrawableDescriptor>(std::move(foregroundInfo.first), foregroundInfo.second);
266         *drawableDescriptor = OH_ArkUI_CreateFromNapiDrawable(descriptor.get());
267         return (*drawableDescriptor != nullptr) ? ResourceManager_ErrorCode::SUCCESS :
268             ResourceManager_ErrorCode::ERROR_CODE_RES_NOT_FOUND_BY_ID;
269     }
270 
271     DrawableDescriptor::DrawableType drawableType;
272     auto descriptor = DrawableDescriptorFactory::Create(foregroundInfo, backgroundInfo,
273         themeMask, drawableType, resourceMgr);
274     *drawableDescriptor = OH_ArkUI_CreateFromNapiDrawable(descriptor.get());
275     return (*drawableDescriptor != nullptr) ? ResourceManager_ErrorCode::SUCCESS :
276         ResourceManager_ErrorCode::ERROR_CODE_RES_NOT_FOUND_BY_ID;
277 }
278 
OH_ResourceManager_GetDrawableDescriptorData(const NativeResourceManager * mgr,uint32_t resId,ArkUI_DrawableDescriptor ** drawableDescriptor,uint32_t density,uint32_t type)279 ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorData(const NativeResourceManager *mgr,
280     uint32_t resId, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type)
281 {
282     if (mgr == nullptr || drawableDescriptor == nullptr || mgr->resManager == nullptr) {
283         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
284     }
285     RState state = RState::SUCCESS;
286     DrawableDescriptor::DrawableType drawableType;
287     if (type == 1) {
288         std::string themeMask = mgr->resManager->GetThemeMask();
289         std::pair<std::unique_ptr<uint8_t[]>, size_t> foregroundInfo;
290         std::pair<std::unique_ptr<uint8_t[]>, size_t> backgroundInfo;
291         state = mgr->resManager->GetThemeIcons(resId, foregroundInfo, backgroundInfo, density);
292         if (state == RState::SUCCESS) {
293             return ProcessThemeIcon(mgr->resManager, drawableDescriptor, foregroundInfo, backgroundInfo, themeMask);
294         }
295     }
296     auto descriptor = DrawableDescriptorFactory::Create(resId, mgr->resManager, state, drawableType, density);
297     if (state != RState::SUCCESS) {
298         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "Failed to Create drawableDescriptor");
299         return static_cast<ResourceManager_ErrorCode>(state);
300     }
301     *drawableDescriptor = OH_ArkUI_CreateFromNapiDrawable(descriptor.get());
302     return (*drawableDescriptor != nullptr) ? ResourceManager_ErrorCode::SUCCESS :
303         ResourceManager_ErrorCode::ERROR_CODE_RES_NOT_FOUND_BY_ID;
304 }
305 
OH_ResourceManager_GetDrawableDescriptorByName(const NativeResourceManager * mgr,const char * resName,ArkUI_DrawableDescriptor ** drawableDescriptor,uint32_t density,uint32_t type)306 ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorByName(const NativeResourceManager *mgr,
307     const char *resName, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type)
308 {
309     return OH_ResourceManager_GetDrawableDescriptorDataByName(mgr, resName, drawableDescriptor, density, type);
310 }
311 
OH_ResourceManager_GetDrawableDescriptorDataByName(const NativeResourceManager * mgr,const char * resName,ArkUI_DrawableDescriptor ** drawableDescriptor,uint32_t density,uint32_t type)312 ResourceManager_ErrorCode OH_ResourceManager_GetDrawableDescriptorDataByName(const NativeResourceManager *mgr,
313     const char *resName, ArkUI_DrawableDescriptor **drawableDescriptor, uint32_t density, uint32_t type)
314 {
315     if (mgr == nullptr || drawableDescriptor == nullptr || mgr->resManager == nullptr) {
316         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
317     }
318     RState state = RState::SUCCESS;
319     DrawableDescriptor::DrawableType drawableType;
320     if (type == 1) {
321         std::string themeMask = mgr->resManager->GetThemeMask();
322         std::pair<std::unique_ptr<uint8_t[]>, size_t> foregroundInfo;
323         std::pair<std::unique_ptr<uint8_t[]>, size_t> backgroundInfo;
324         state = mgr->resManager->GetThemeIcons(0, foregroundInfo, backgroundInfo, density);
325         if (state == RState::SUCCESS) {
326             return ProcessThemeIcon(mgr->resManager, drawableDescriptor, foregroundInfo, backgroundInfo, themeMask);
327         }
328     }
329     if (type == 2) { // 2 means get the dynamic icon from theme
330         std::pair<std::unique_ptr<uint8_t[]>, size_t> iconInfo;
331         state = mgr->resManager->GetDynamicIcon(resName, iconInfo, density);
332         if (state == RState::SUCCESS) {
333             auto descriptor = std::make_unique<DrawableDescriptor>(std::move(iconInfo.first), iconInfo.second);
334             *drawableDescriptor = OH_ArkUI_CreateFromNapiDrawable(descriptor.get());
335             return (*drawableDescriptor != nullptr) ? ResourceManager_ErrorCode::SUCCESS :
336                 ResourceManager_ErrorCode::ERROR_CODE_RES_NOT_FOUND_BY_ID;
337         }
338     }
339 
340     auto descriptor = DrawableDescriptorFactory::Create(resName, mgr->resManager, state, drawableType, density);
341     if (state != RState::SUCCESS) {
342         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "Failed to Create drawableDescriptor");
343         return static_cast<ResourceManager_ErrorCode>(state);
344     }
345     *drawableDescriptor = OH_ArkUI_CreateFromNapiDrawable(descriptor.get());
346     return (*drawableDescriptor != nullptr) ? ResourceManager_ErrorCode::SUCCESS :
347         ResourceManager_ErrorCode::ERROR_CODE_RES_NOT_FOUND_BY_ID;
348 }
349 
OH_ResourceManager_GetSymbol(const NativeResourceManager * mgr,uint32_t resId,uint32_t * resultValue)350 ResourceManager_ErrorCode OH_ResourceManager_GetSymbol(const NativeResourceManager *mgr, uint32_t resId,
351     uint32_t *resultValue)
352 {
353     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
354         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
355     }
356     uint32_t tempResultValue;
357     RState state = mgr->resManager->GetSymbolById(resId, tempResultValue);
358     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
359     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
360         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
361             "failed get symbol resource id = %{public}d, errorCode = %{public}d", resId, errorCode);
362         return errorCode;
363     }
364     *resultValue = tempResultValue;
365     return errorCode;
366 }
367 
OH_ResourceManager_GetSymbolByName(const NativeResourceManager * mgr,const char * resName,uint32_t * resultValue)368 ResourceManager_ErrorCode OH_ResourceManager_GetSymbolByName(const NativeResourceManager *mgr, const char *resName,
369     uint32_t *resultValue)
370 {
371     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
372         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
373     }
374     uint32_t tempResultValue;
375     RState state = mgr->resManager->GetSymbolByName(resName, tempResultValue);
376     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
377     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
378         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
379             "failed get symbol resource name = %{public}s, errorCode = %{public}d", resName, errorCode);
380         return errorCode;
381     }
382     *resultValue = tempResultValue;
383     return errorCode;
384 }
385 
OH_ResourceManager_GetLocales(const NativeResourceManager * mgr,char *** resultValue,uint32_t * resultLen,bool includeSystem)386 ResourceManager_ErrorCode OH_ResourceManager_GetLocales(const NativeResourceManager *mgr, char ***resultValue,
387     uint32_t *resultLen, bool includeSystem)
388 {
389     return OH_ResourceManager_GetLocalesData(mgr, resultValue, resultLen, includeSystem);
390 }
391 
OH_ResourceManager_GetLocalesData(const NativeResourceManager * mgr,char *** resultValue,uint32_t * resultLen,bool includeSystem)392 ResourceManager_ErrorCode OH_ResourceManager_GetLocalesData(const NativeResourceManager *mgr, char ***resultValue,
393     uint32_t *resultLen, bool includeSystem)
394 {
395     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
396         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
397     }
398     std::vector<std::string> tempResultValue;
399     mgr->resManager->GetLocales(tempResultValue, includeSystem);
400     return copyStringArray(resultValue, resultLen, tempResultValue, "GetLocales");
401 }
402 
GetConfiguration(const NativeResourceManager * mgr,ResourceManager_Configuration * configuration,bool getScreenDensityDpi)403 ResourceManager_ErrorCode GetConfiguration(const NativeResourceManager *mgr,
404     ResourceManager_Configuration *configuration, bool getScreenDensityDpi)
405 {
406     if (mgr == nullptr || configuration == nullptr || mgr->resManager == nullptr) {
407         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
408     }
409     ResConfigImpl resConfig;
410     mgr->resManager->GetResConfig(resConfig);
411 
412     const icu::Locale *localeInfo = resConfig.GetLocaleInfo();
413     ResourceManager_ErrorCode errCode = copyLocalInfo(localeInfo, configuration);
414     if (errCode != ResourceManager_ErrorCode::SUCCESS) {
415         return errCode;
416     }
417     {
418         configuration->direction = static_cast<::ResourceManager_Direction>(resConfig.GetDirection());
419         configuration->deviceType = static_cast<::ResourceManager_DeviceType>(resConfig.GetDeviceType());
420         if (getScreenDensityDpi) {
421             configuration->screenDensity = static_cast<::ScreenDensity>(resConfig.GetScreenDensityDpi());
422         } else {
423             configuration->screenDensity = static_cast<::ScreenDensity>(resConfig.GetScreenDensity());
424         }
425         configuration->colorMode = static_cast<::ResourceManager_ColorMode>(resConfig.GetColorMode());
426         configuration->mcc = resConfig.GetMcc();
427         configuration->mnc = resConfig.GetMnc();
428     }
429     return ResourceManager_ErrorCode::SUCCESS;
430 }
431 
OH_ResourceManager_GetConfiguration(const NativeResourceManager * mgr,ResourceManager_Configuration * configuration)432 ResourceManager_ErrorCode OH_ResourceManager_GetConfiguration(const NativeResourceManager *mgr,
433     ResourceManager_Configuration *configuration)
434 {
435     return GetConfiguration(mgr, configuration, false);
436 }
437 
OH_ResourceManager_GetResourceConfiguration(const NativeResourceManager * mgr,ResourceManager_Configuration * configuration)438 ResourceManager_ErrorCode OH_ResourceManager_GetResourceConfiguration(const NativeResourceManager *mgr,
439     ResourceManager_Configuration *configuration)
440 {
441     return GetConfiguration(mgr, configuration, true);
442 }
443 
OH_ResourceManager_GetStringArray(const NativeResourceManager * mgr,uint32_t resId,char *** resultValue,uint32_t * resultValueLen)444 ResourceManager_ErrorCode OH_ResourceManager_GetStringArray(const NativeResourceManager *mgr,
445     uint32_t resId, char ***resultValue, uint32_t *resultValueLen)
446 {
447     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
448         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
449     }
450     std::vector<std::string> tempResultValue;
451     RState state = mgr->resManager->GetStringArrayById(resId, tempResultValue);
452     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
453     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
454         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
455             "failed get string array id = %{public}d, errorCode = %{public}d", resId, errorCode);
456         return errorCode;
457     }
458     return copyStringArray(resultValue, resultValueLen, tempResultValue, "GetStringArray");
459 }
460 
OH_ResourceManager_GetStringArrayByName(const NativeResourceManager * mgr,const char * resName,char *** resultValue,uint32_t * resultLen)461 ResourceManager_ErrorCode OH_ResourceManager_GetStringArrayByName(const NativeResourceManager *mgr,
462     const char *resName, char ***resultValue, uint32_t *resultLen)
463 {
464     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
465         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
466     }
467     std::vector<std::string> tempResultValue;
468     RState state = mgr->resManager->GetStringArrayByName(resName, tempResultValue);
469     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
470     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
471         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
472             "failed get string array resName = %{public}s, errorCode = %{public}d", resName, errorCode);
473         return errorCode;
474     }
475     return copyStringArray(resultValue, resultLen, tempResultValue, "GetStringArrayByName");
476 }
477 
OH_ResourceManager_GetPluralStringByName(const NativeResourceManager * mgr,const char * resName,uint32_t num,char ** resultValue)478 ResourceManager_ErrorCode OH_ResourceManager_GetPluralStringByName(const NativeResourceManager *mgr,
479     const char *resName, uint32_t num, char **resultValue)
480 {
481     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
482         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
483     }
484     std::string tempResultValue;
485     RState state = mgr->resManager->GetPluralStringByNameFormat(tempResultValue, resName, num, num);
486     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
487     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
488         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
489             "failed get plural string name = %{public}s, errorCode = %{public}d", resName, errorCode);
490         return errorCode;
491     }
492     return copyString(resultValue, tempResultValue, "GetPluralStringByName");
493 }
494 
OH_ResourceManager_GetPluralString(const NativeResourceManager * mgr,uint32_t resId,uint32_t num,char ** resultValue)495 ResourceManager_ErrorCode OH_ResourceManager_GetPluralString(const NativeResourceManager *mgr,
496     uint32_t resId, uint32_t num, char **resultValue)
497 {
498     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
499         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
500     }
501     std::string tempResultValue;
502     RState state = mgr->resManager->GetPluralStringByIdFormat(tempResultValue, resId, num, num);
503     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
504     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
505         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
506             "failed get plural string id = %{public}d, errorCode = %{public}d", resId, errorCode);
507         return errorCode;
508     }
509     return copyString(resultValue, tempResultValue, "GetPluralString");
510 }
511 
OH_ResourceManager_GetColor(const NativeResourceManager * mgr,uint32_t resId,uint32_t * resultValue)512 ResourceManager_ErrorCode OH_ResourceManager_GetColor(const NativeResourceManager *mgr, uint32_t resId,
513     uint32_t *resultValue)
514 {
515     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
516         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
517     }
518     uint32_t tempResultValue;
519     RState state = mgr->resManager->GetColorById(resId, tempResultValue);
520     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
521     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
522         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "failed get color id = %{public}d, errorCode = %{public}d", resId, errorCode);
523         return errorCode;
524     }
525     *resultValue = tempResultValue;
526     return errorCode;
527 }
528 
OH_ResourceManager_GetColorByName(const NativeResourceManager * mgr,const char * resName,uint32_t * resultValue)529 ResourceManager_ErrorCode OH_ResourceManager_GetColorByName(const NativeResourceManager *mgr, const char *resName,
530     uint32_t *resultValue)
531 {
532     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
533         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
534     }
535     uint32_t tempResultValue;
536     RState state = mgr->resManager->GetColorByName(resName, tempResultValue);
537     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
538     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
539         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
540             "failed get color name = %{public}s, errorCode = %{public}d", resName, errorCode);
541         return errorCode;
542     }
543     *resultValue = tempResultValue;
544     return errorCode;
545 }
546 
OH_ResourceManager_GetInt(const NativeResourceManager * mgr,uint32_t resId,int * resultValue)547 ResourceManager_ErrorCode OH_ResourceManager_GetInt(const NativeResourceManager *mgr, uint32_t resId,
548     int *resultValue)
549 {
550     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
551         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
552     }
553     int tempResultValue;
554     RState state = mgr->resManager->GetIntegerById(resId, tempResultValue);
555     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
556     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
557         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
558             "failed get integer id = %{public}d, errorCode = %{public}d", resId, errorCode);
559         return errorCode;
560     }
561     *resultValue = tempResultValue;
562     return errorCode;
563 }
564 
OH_ResourceManager_GetIntByName(const NativeResourceManager * mgr,const char * resName,int * resultValue)565 ResourceManager_ErrorCode OH_ResourceManager_GetIntByName(const NativeResourceManager *mgr, const char *resName,
566     int *resultValue)
567 {
568     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
569         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
570     }
571     int tempResultValue;
572     RState state = mgr->resManager->GetIntegerByName(resName, tempResultValue);
573     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
574     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
575         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
576             "failed get integer name = %{public}s, errorCode = %{public}d", resName, errorCode);
577         return errorCode;
578     }
579     *resultValue = tempResultValue;
580     return errorCode;
581 }
582 
OH_ResourceManager_GetFloat(const NativeResourceManager * mgr,uint32_t resId,float * resultValue)583 ResourceManager_ErrorCode OH_ResourceManager_GetFloat(const NativeResourceManager *mgr, uint32_t resId,
584     float *resultValue)
585 {
586     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
587         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
588     }
589     float tempResultValue;
590     RState state = mgr->resManager->GetFloatById(resId, tempResultValue);
591     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
592     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
593         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "failed get float id = %{public}d, errorCode = %{public}d", resId, errorCode);
594         return errorCode;
595     }
596     *resultValue = tempResultValue;
597     return errorCode;
598 }
599 
OH_ResourceManager_GetFloatByName(const NativeResourceManager * mgr,const char * resName,float * resultValue)600 ResourceManager_ErrorCode OH_ResourceManager_GetFloatByName(const NativeResourceManager *mgr, const char *resName,
601     float *resultValue)
602 {
603     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
604         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
605     }
606     float tempResultValue;
607     RState state = mgr->resManager->GetFloatByName(resName, tempResultValue);
608     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
609     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
610         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
611             "failed get float name = %{public}s, errorCode = %{public}d", resName, errorCode);
612         return errorCode;
613     }
614     *resultValue = tempResultValue;
615     return errorCode;
616 }
617 
OH_ResourceManager_GetBool(const NativeResourceManager * mgr,uint32_t resId,bool * resultValue)618 ResourceManager_ErrorCode OH_ResourceManager_GetBool(const NativeResourceManager *mgr, uint32_t resId,
619     bool *resultValue)
620 {
621     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
622         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
623     }
624     bool tempResultValue;
625     RState state = mgr->resManager->GetBooleanById(resId, tempResultValue);
626     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
627     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
628         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "failed get bool id = %{public}d, errorCode = %{public}d", resId, errorCode);
629         return errorCode;
630     }
631     *resultValue = tempResultValue;
632     return errorCode;
633 }
634 
OH_ResourceManager_GetBoolByName(const NativeResourceManager * mgr,const char * resName,bool * resultValue)635 ResourceManager_ErrorCode OH_ResourceManager_GetBoolByName(const NativeResourceManager *mgr, const char *resName,
636     bool *resultValue)
637 {
638     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
639         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
640     }
641     bool tempResultValue;
642     RState state = mgr->resManager->GetBooleanByName(resName, tempResultValue);
643     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
644     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
645         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
646             "failed get bool name = %{public}s, errorCode = %{public}d", resName, errorCode);
647         return errorCode;
648     }
649     *resultValue = tempResultValue;
650     return errorCode;
651 }
652 
OH_ResourceManager_AddResource(const NativeResourceManager * mgr,const char * path)653 ResourceManager_ErrorCode OH_ResourceManager_AddResource(const NativeResourceManager *mgr, const char *path)
654 {
655     if (mgr == nullptr || path == nullptr || mgr->resManager == nullptr) {
656         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
657     }
658     if (!mgr->resManager->AddAppOverlay(path)) {
659         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "Failed to add overlay path");
660         return ResourceManager_ErrorCode::ERROR_CODE_OVERLAY_RES_PATH_INVALID;
661     }
662     return ResourceManager_ErrorCode::SUCCESS;
663 }
664 
OH_ResourceManager_RemoveResource(const NativeResourceManager * mgr,const char * path)665 ResourceManager_ErrorCode OH_ResourceManager_RemoveResource(const NativeResourceManager *mgr, const char *path)
666 {
667     if (mgr == nullptr || path == nullptr || mgr->resManager == nullptr) {
668         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
669     }
670     if (!mgr->resManager->RemoveAppOverlay(path)) {
671         RESMGR_HILOGE(RESMGR_NATIVE_TAG, "Failed to remove overlay path");
672         return ResourceManager_ErrorCode::ERROR_CODE_OVERLAY_RES_PATH_INVALID;
673     }
674     return ResourceManager_ErrorCode::SUCCESS;
675 }
676 
OH_ResourceManager_ReleaseConfiguration(ResourceManager_Configuration * configuration)677 ResourceManager_ErrorCode OH_ResourceManager_ReleaseConfiguration(ResourceManager_Configuration *configuration)
678 {
679     if (configuration == nullptr) {
680         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
681     }
682     if (configuration->locale != nullptr) {
683         free(configuration->locale);
684         configuration->locale = nullptr;
685     }
686     return ResourceManager_ErrorCode::SUCCESS;
687 }
688 
OH_ResourceManager_ReleaseStringArray(char *** resValue,uint32_t len)689 ResourceManager_ErrorCode OH_ResourceManager_ReleaseStringArray(char ***resValue, uint32_t len)
690 {
691     if (resValue == nullptr || *resValue == nullptr) {
692         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
693     }
694     for (uint32_t i = 0; i < len; i++) {
695         if ((*resValue)[i] != nullptr) {
696             delete [] (*resValue)[i];
697             (*resValue)[i] = nullptr;
698         }
699     }
700     delete [] *resValue;
701     *resValue = nullptr;
702     return ResourceManager_ErrorCode::SUCCESS;
703 }
704 
OH_ResourceManager_GetString(const NativeResourceManager * mgr,uint32_t resId,char ** resultValue,...)705 ResourceManager_ErrorCode OH_ResourceManager_GetString(const NativeResourceManager *mgr, uint32_t resId,
706     char **resultValue, ...)
707 {
708     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
709         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
710     }
711     string tempResultValue;
712 
713     va_list args;
714     va_start(args, resultValue);
715     RState state = mgr->resManager->GetStringFormatById(tempResultValue, resId, args);
716     va_end(args);
717     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
718     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
719         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
720             "failed get string id = %{public}d, errorCode = %{public}d", resId, errorCode);
721         return errorCode;
722     }
723     return copyString(resultValue, tempResultValue, "GetString");
724 }
725 
OH_ResourceManager_GetStringByName(const NativeResourceManager * mgr,const char * resName,char ** resultValue,...)726 ResourceManager_ErrorCode OH_ResourceManager_GetStringByName(const NativeResourceManager *mgr, const char *resName,
727     char **resultValue, ...)
728 {
729     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
730         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
731     }
732     string tempResultValue;
733 
734     va_list args;
735     va_start(args, resultValue);
736     RState state = mgr->resManager->GetStringFormatByName(tempResultValue, resName, args);
737     va_end(args);
738     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
739     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
740         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
741             "failed get string name = %{public}s, errorCode = %{public}d", resName, errorCode);
742         return errorCode;
743     }
744     return copyString(resultValue, tempResultValue, "GetStringByName");
745 }
746 
OH_ResourceManager_GetIntPluralString(const NativeResourceManager * mgr,uint32_t resId,uint32_t num,char ** resultValue,...)747 ResourceManager_ErrorCode OH_ResourceManager_GetIntPluralString(const NativeResourceManager *mgr,
748     uint32_t resId, uint32_t num, char **resultValue, ...)
749 {
750     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
751         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
752     }
753     std::string tempResultValue;
754 
755     va_list args;
756     va_start(args, resultValue);
757     ResourceManager::Quantity quantity = { true, num, 0.0 };
758     RState state = mgr->resManager->GetFormatPluralStringById(tempResultValue, resId, quantity, args);
759     va_end(args);
760     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
761     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
762         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
763             "failed get plural string id = %{public}d, errorCode = %{public}d", resId, errorCode);
764         return errorCode;
765     }
766     return copyString(resultValue, tempResultValue, "GetIntPluralString");
767 }
768 
OH_ResourceManager_GetDoublePluralString(const NativeResourceManager * mgr,uint32_t resId,double num,char ** resultValue,...)769 ResourceManager_ErrorCode OH_ResourceManager_GetDoublePluralString(const NativeResourceManager *mgr,
770     uint32_t resId, double num, char **resultValue, ...)
771 {
772     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
773         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
774     }
775     std::string tempResultValue;
776 
777     va_list args;
778     va_start(args, resultValue);
779     ResourceManager::Quantity quantity = { false, 0, num };
780     RState state = mgr->resManager->GetFormatPluralStringById(tempResultValue, resId, quantity, args);
781     va_end(args);
782     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
783     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
784         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
785             "failed get plural string id = %{public}d, errorCode = %{public}d", resId, errorCode);
786         return errorCode;
787     }
788     return copyString(resultValue, tempResultValue, "GetDoublePluralString");
789 }
790 
OH_ResourceManager_GetIntPluralStringByName(const NativeResourceManager * mgr,const char * resName,uint32_t num,char ** resultValue,...)791 ResourceManager_ErrorCode OH_ResourceManager_GetIntPluralStringByName(const NativeResourceManager *mgr,
792     const char *resName, uint32_t num, char **resultValue, ...)
793 {
794     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
795         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
796     }
797     std::string tempResultValue;
798 
799     va_list args;
800     va_start(args, resultValue);
801     ResourceManager::Quantity quantity = { true, num, 0.0 };
802     RState state = mgr->resManager->GetFormatPluralStringByName(tempResultValue, resName, quantity, args);
803     va_end(args);
804     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
805     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
806         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
807             "failed get plural string name = %{public}s, errorCode = %{public}d", resName, errorCode);
808         return errorCode;
809     }
810     return copyString(resultValue, tempResultValue, "GetIntPluralStringByName");
811 }
812 
OH_ResourceManager_GetDoublePluralStringByName(const NativeResourceManager * mgr,const char * resName,double num,char ** resultValue,...)813 ResourceManager_ErrorCode OH_ResourceManager_GetDoublePluralStringByName(const NativeResourceManager *mgr,
814     const char *resName, double num, char **resultValue, ...)
815 {
816     if (mgr == nullptr || resultValue == nullptr || mgr->resManager == nullptr) {
817         return ResourceManager_ErrorCode::ERROR_CODE_INVALID_INPUT_PARAMETER;
818     }
819     std::string tempResultValue;
820 
821     va_list args;
822     va_start(args, resultValue);
823     ResourceManager::Quantity quantity = { false, 0, num };
824     RState state = mgr->resManager->GetFormatPluralStringByName(tempResultValue, resName, quantity, args);
825     va_end(args);
826     ResourceManager_ErrorCode errorCode = static_cast<ResourceManager_ErrorCode>(state);
827     if (errorCode != ResourceManager_ErrorCode::SUCCESS) {
828         RESMGR_HILOGE(RESMGR_NATIVE_TAG,
829             "failed get plural string name = %{public}s, errorCode = %{public}d", resName, errorCode);
830         return errorCode;
831     }
832     return copyString(resultValue, tempResultValue, "GetDoublePluralStringByName");
833 }