• 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 #include "promptActionUtils.h"
17 
18 #include "core/pipeline/pipeline_base.h"
19 
20 std::unordered_map<int, uint32_t> colorMap = {
21     {PromptActionColor::PROMPT_ACTION_COLOR_WHITE, 0xffffff | 0xFF000000},
22     {PromptActionColor::PROMPT_ACTION_COLOR_BLACK, 0x000000 | 0xFF000000},
23     {PromptActionColor::PROMPT_ACTION_COLOR_BLUE, 0x0000ff | 0xFF000000},
24     {PromptActionColor::PROMPT_ACTION_COLOR_BROWN, 0xa52a2a | 0xFF000000},
25     {PromptActionColor::PROMPT_ACTION_COLOR_GRAY, 0x808080 | 0xFF000000},
26     {PromptActionColor::PROMPT_ACTION_COLOR_GREEN, 0x008000 | 0xFF000000},
27     {PromptActionColor::PROMPT_ACTION_COLOR_GREY, 0x808080 | 0xFF000000},
28     {PromptActionColor::PROMPT_ACTION_COLOR_ORANGE, 0xffa500 | 0xFF000000},
29     {PromptActionColor::PROMPT_ACTION_COLOR_PINK, 0xffc0cb | 0xFF000000},
30     {PromptActionColor::PROMPT_ACTION_COLOR_RED, 0xff0000 | 0xFF000000},
31     {PromptActionColor::PROMPT_ACTION_COLOR_YELLOW, 0xffff00 | 0xFF000000},
32     {PromptActionColor::PROMPT_ACTION_COLOR_TRANSPARENT, 0x00000000},
33 };
34 
ANIUtils_ANIStringToStdString(ani_env * env,ani_string ani_str)35 std::string ANIUtils_ANIStringToStdString(ani_env *env, ani_string ani_str)
36 {
37     ani_size strSize;
38     env->String_GetUTF8Size(ani_str, &strSize);
39 
40     std::vector<char> buffer(strSize + 1);
41     char* utf8Buffer = buffer.data();
42 
43     ani_size bytesWritten = 0;
44     env->String_GetUTF8(ani_str, utf8Buffer, strSize + 1, &bytesWritten);
45 
46     utf8Buffer[bytesWritten] = '\0';
47     std::string content = std::string(utf8Buffer);
48     return content;
49 }
PreFixEmptyBundleName(ani_env * env,ani_object value)50 void PreFixEmptyBundleName(ani_env *env, ani_object value)
51 {
52     ani_ref bundleName_ref;
53     if (ANI_OK != env->Object_GetPropertyByName_Ref(value, "bundleName", &bundleName_ref)) {
54         return;
55     }
56     auto bundleName = ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(bundleName_ref));
57     if (bundleName.empty()) {
58         auto container = OHOS::Ace::Container::CurrentSafely();
59         CHECK_NULL_VOID(container);
60         bundleName = container->GetBundleName();
61         ani_string ani_bundleName{};
62         bundleName = "app";
63         env->String_NewUTF8(bundleName.c_str(), bundleName.size(), &ani_bundleName);
64         if (ANI_OK != env->Object_SetPropertyByName_Ref(value, "bundleName", static_cast<ani_ref>(ani_bundleName))) {
65             return;
66         }
67     }
68 }
processResourceType(ani_env * env,ani_object value,ani_ref params_ref,size_t length,std::string resName)69 void processResourceType(ani_env *env, ani_object value, ani_ref params_ref, size_t length, std::string resName)
70 {
71     std::vector<std::string> strings;
72     for (int i = 0; i < int(length); i++) {
73         ani_ref stringEntryRef;
74         if (ANI_OK != env->Object_CallMethodByName_Ref(static_cast<ani_object>(params_ref),
75             "$_get", "I:Lstd/core/Object;", &stringEntryRef, (ani_int)i)) {
76             break;
77         }
78         auto stringContent = ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(stringEntryRef));
79         strings.emplace_back(stringContent);
80     }
81     ani_class stringCls = nullptr;
82     if (ANI_OK != env->FindClass("Lstd/core/String;", &stringCls)) {
83         return;
84     }
85     ani_ref undefinedRef = nullptr;
86     if (ANI_OK !=env->GetUndefined(&undefinedRef)) {
87         return;
88     }
89     int32_t index = 0;
90     ani_string ani_first_str;
91     if (ANI_OK == env->String_NewUTF8(resName.c_str(), resName.size(), &ani_first_str)) {
92         if (ANI_OK != env->Object_CallMethodByName_Void(static_cast<ani_object>(params_ref),
93             "$_set", "ILstd/core/Object;:V", index, ani_first_str)) {
94             return;
95         }
96     }
97     index++;
98     for (auto string : strings) {
99         ani_string ani_str;
100         if (ANI_OK != env->String_NewUTF8(string.c_str(), string.size(), &ani_str)) {
101             break;
102         }
103         if (ANI_OK != env->Object_CallMethodByName_Void(static_cast<ani_object>(params_ref),
104             "$_set", "ILstd/core/Object;:V", index, ani_str)) {
105             break;
106         }
107         index++;
108     }
109 }
ModifyResourceParam(ani_env * env,ani_object value,const ResourceType & resType,const std::string & resName)110 void ModifyResourceParam(ani_env *env, ani_object value, const ResourceType& resType, const std::string& resName)
111 {
112     // raw input : {"id":"app.xxx.xxx","params":[],"moduleName":"xxx","bundleName":"xxx"}
113     // modified output : {"id":-1, "params":["app.xxx.xxx"],"type":xxxx,"moduleName":"xxx","bundleName":"xxx"}
114     ani_ref params_ref;
115     if (ANI_OK != env->Object_GetPropertyByName_Ref(value, "params", &params_ref)) {
116         return;
117     }
118     if (GetIsUndefinedObject(env, params_ref)) {
119         return;
120     }
121     if (!GetIsArrayObject(env, params_ref)) {
122         return;
123     }
124     ani_double length;
125     if (ANI_OK != env->Object_GetPropertyByName_Double(static_cast<ani_object>(params_ref), "length", &length)) {
126         return;
127     }
128     if (resType == ResourceType::PLURAL || resType == ResourceType::STRING) {
129         processResourceType(env, value, params_ref, static_cast<size_t>(length), resName);
130     } else {
131         ani_string ani_res{};
132         env->String_NewUTF8(resName.c_str(), resName.size(), &ani_res);
133         if (ANI_OK != env->Object_SetPropertyByName_Ref(value, "params", static_cast<ani_ref>(ani_res))) {
134             return;
135         }
136     }
137 }
CompleteResourceParamV1(ani_env * env,ani_object value)138 void CompleteResourceParamV1(ani_env *env, ani_object value)
139 {
140     ani_ref id_ref;
141     if (ANI_OK != env->Object_GetPropertyByName_Ref(value, "id", &id_ref)) {
142         return;
143     }
144     std::string resName;
145     std::string moduleName;
146     ResourceType resType;
147     if (!ParseDollarResource(env, static_cast<ani_object>(id_ref), resType, resName, moduleName)) {
148         return;
149     }
150     ModifyResourceParam(env, value, resType, resName);
151     ani_int ani_id = static_cast<ani_int>(UNKNOWN_RESOURCE_ID);
152     if (ANI_OK != env->Object_SetPropertyByName_Int(value, "id", static_cast<ani_int>(ani_id))) {
153         return;
154     }
155     int32_t aniType = static_cast<int32_t>(resType);
156     if (ANI_OK != env->Object_SetPropertyByName_Int(value, "type", static_cast<ani_int>(aniType))) {
157         return;
158     }
159     ani_ref bundleName_ref;
160     if (ANI_OK != env->Object_GetPropertyByName_Ref(value, "bundleName", &bundleName_ref)) {
161         std::string bundleNameStr = "";
162         ani_string defaut_bundleName{};
163         env->String_NewUTF8(bundleNameStr.c_str(), bundleNameStr.size(), &defaut_bundleName);
164         if (ANI_OK != env->Object_SetPropertyByName_Ref(value, "bundleName",
165             static_cast<ani_ref>(defaut_bundleName))) {
166             return;
167         }
168         return;
169     }
170     ani_ref moduleName_ref;
171     if (ANI_OK != env->Object_GetPropertyByName_Ref(value, "moduleName", &moduleName_ref)) {
172         std::string moduleNameStr = "";
173         ani_string defaut_moduleName{};
174         env->String_NewUTF8(moduleNameStr.c_str(), moduleNameStr.size(), &defaut_moduleName);
175         if (ANI_OK != env->Object_SetPropertyByName_Ref(value, "moduleName",
176             static_cast<ani_ref>(defaut_moduleName))) {
177             return;
178         }
179         return;
180     }
181 }
CompleteResourceParamV2(ani_env * env,ani_object value)182 void CompleteResourceParamV2(ani_env *env, ani_object value)
183 {
184     ani_ref params_ref;
185     if (ANI_OK != env->Object_GetPropertyByName_Ref(value, "params", &params_ref)) {
186         return;
187     }
188     if (GetIsUndefinedObject(env, params_ref)) {
189         return;
190     }
191     ani_double length;
192     if (ANI_OK != env->Object_GetPropertyByName_Double(static_cast<ani_object>(params_ref), "length", &length)) {
193         return;
194     }
195     std::string resName;
196     std::string moduleName;
197     ResourceType resType;
198     if (!ParseDollarResource(env, static_cast<ani_object>(params_ref), resType, resName, moduleName)) {
199         return;
200     }
201     int32_t aniType = static_cast<int32_t>(resType);
202 
203     if (ANI_OK != env->Object_SetPropertyByName_Int(value, "type", static_cast<ani_int>(aniType))) {
204         return;
205     }
206     if (!moduleName.empty()) {
207         ani_string ani_moduleName{};
208         env->String_NewUTF8(moduleName.c_str(), moduleName.size(), &ani_moduleName);
209         if (ANI_OK != env->Object_SetPropertyByName_Ref(value, "moduleName", static_cast<ani_ref>(ani_moduleName))) {
210             return;
211         }
212     }
213 }
ParseDollarResource(ani_env * env,ani_object params_ref,ResourceType & resType,std::string & resName,std::string & moduleName)214 bool ParseDollarResource(
215     ani_env *env, ani_object params_ref, ResourceType& resType, std::string& resName, std::string& moduleName)
216 {
217     if (!GetIsStringObject(env, params_ref)) {
218         return false;
219     }
220     auto resPath = ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(params_ref));
221 
222     std::vector<std::string> tokens;
223     OHOS::Ace::StringUtils::StringSplitter(resPath, '.', tokens);
224     // $r format like app.xxx.xxx, has 3 paragraph
225     if (static_cast<int32_t>(tokens.size()) != 3) {
226         return false;
227     }
228     std::string maybeModuleName = tokens[0];
229     // [*] or app/hsp at least has 3 chars
230     if (maybeModuleName.size() < 3) {
231         return false;
232     }
233     char begin = *maybeModuleName.begin();
234     char end = maybeModuleName.at(maybeModuleName.size() - 1);
235     bool headCheckPass = false;
236     if (begin == '[' && end == ']') {
237         moduleName = maybeModuleName.substr(NUMBER_ONE, maybeModuleName.size() - NUMBER_TWO);
238         headCheckPass = true;
239     }
240     if (std::find(RESOURCE_HEADS.begin(), RESOURCE_HEADS.end(), tokens[0]) == RESOURCE_HEADS.end() && !headCheckPass) {
241         return false;
242     }
243     if (!ConvertResourceType(tokens[1], resType)) {
244         return false;
245     }
246     resName = resPath;
247     return true;
248 }
ConvertResourceType(const std::string & typeName,ResourceType & resType)249 bool ConvertResourceType(const std::string& typeName, ResourceType& resType)
250 {
251     static const std::unordered_map<std::string, ResourceType> resTypeMap {
252         { "color", ResourceType::COLOR },
253         { "media", ResourceType::MEDIA },
254         { "float", ResourceType::FLOAT },
255         { "string", ResourceType::STRING },
256         { "plural", ResourceType::PLURAL },
257         { "pattern", ResourceType::PATTERN },
258         { "boolean", ResourceType::BOOLEAN },
259         { "integer", ResourceType::INTEGER },
260         { "strarray", ResourceType::STRARRAY },
261         { "intarray", ResourceType::INTARRAY },
262     };
263     auto it = resTypeMap.find(typeName);
264     if (it == resTypeMap.end()) {
265         return false;
266     }
267     resType = it->second;
268     return true;
269 }
CheckResourceStruct(ani_env * env,ani_object value)270 ResourceStruct CheckResourceStruct(ani_env *env, ani_object value)
271 {
272     ani_double id;
273     if (ANI_OK != env->Object_GetPropertyByName_Double(value, "id", &id)) {
274         ani_ref id_ref;
275         if (ANI_OK != env->Object_GetPropertyByName_Ref(value, "id", &id_ref)) {
276             return ResourceStruct::CONSTANT;
277         }
278         return ResourceStruct::DYNAMIC_V1;
279     } else {
280         if (static_cast<int32_t>(id) == UNKNOWN_RESOURCE_ID) {
281             return ResourceStruct::DYNAMIC_V2;
282         }
283     }
284     return ResourceStruct::CONSTANT;
285 }
CompleteResourceParam(ani_env * env,ani_object value)286 void CompleteResourceParam(ani_env *env, ani_object value)
287 {
288     PreFixEmptyBundleName(env, value);
289     ResourceStruct resourceStruct = CheckResourceStruct(env, value);
290     switch (resourceStruct) {
291         case ResourceStruct::CONSTANT:
292             return;
293         case ResourceStruct::DYNAMIC_V1:
294             CompleteResourceParamV1(env, value);
295             return;
296         case ResourceStruct::DYNAMIC_V2:
297             CompleteResourceParamV2(env, value);
298             return;
299         default:
300             return;
301     }
302 }
ParseResourceParamId(ani_env * env,ani_object objects,ResourceInfo & info)303 bool ParseResourceParamId(ani_env *env, ani_object objects, ResourceInfo& info)
304 {
305     ani_double id_ref;
306     if (ANI_OK != env->Object_GetPropertyByName_Double(objects, "id", &id_ref)) {
307         return false;
308     }
309     info.resId = static_cast<int32_t>(id_ref);
310     return true;
311 }
ParseResourceParamBundleName(ani_env * env,ani_object objects,ResourceInfo & info)312 bool ParseResourceParamBundleName(ani_env *env, ani_object objects, ResourceInfo& info)
313 {
314     ani_ref bundleName_ref;
315     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "bundleName", &bundleName_ref)) {
316         return false;
317     }
318     auto bundleName_str = ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(bundleName_ref));
319     info.bundleName = bundleName_str;
320     return true;
321 }
ParseResourceParamModuleName(ani_env * env,ani_object objects,ResourceInfo & info)322 bool ParseResourceParamModuleName(ani_env *env, ani_object objects, ResourceInfo& info)
323 {
324     ani_ref moduleName_ref;
325     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "moduleName", &moduleName_ref)) {
326         return false;
327     }
328     auto moduleName_str = ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(moduleName_ref));
329     info.moduleName = moduleName_str;
330     return true;
331 }
ParseResourceParamType(ani_env * env,ani_object objects,ResourceInfo & info)332 bool ParseResourceParamType(ani_env *env, ani_object objects, ResourceInfo& info)
333 {
334     ani_ref type_ref;
335     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "type", &type_ref)) {
336         return false;
337     }
338     if (GetIsUndefinedObject(env, type_ref)) {
339         return false;
340     }
341     ani_double type;
342     if (ANI_OK !=env->Object_CallMethodByName_Double(
343         static_cast<ani_object>(type_ref), "doubleValue", nullptr, &type)) {
344         return false;
345     }
346     info.type = static_cast<int32_t>(type);
347     return true;
348 }
ParseResourceParamName(ani_env * env,ani_object objects,ResourceInfo & info)349 bool ParseResourceParamName(ani_env *env, ani_object objects, ResourceInfo& info)
350 {
351     ani_ref params_ref;
352     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "params", &params_ref)) {
353         return false;
354     }
355     if (GetIsUndefinedObject(env, params_ref)) {
356         return false;
357     }
358     ani_double length;
359     if (ANI_OK != env->Object_GetPropertyByName_Double(static_cast<ani_object>(params_ref), "length", &length)) {
360         return false;
361     }
362     std::vector<std::string> strings;
363     for (int i = 0; i < int(length); i++) {
364         ani_ref stringEntryRef;
365         if (ANI_OK != env->Object_CallMethodByName_Ref(static_cast<ani_object>(params_ref),
366             "$_get", "I:Lstd/core/Object;", &stringEntryRef, (ani_int)i)) {
367             return false;
368         }
369         strings.emplace_back(ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(stringEntryRef)));
370     }
371     info.params = strings;
372     for (const auto &s : strings) {
373         std::cout << "ParseResourceParamName Array String Content:" << s.c_str() << std::endl;
374     }
375     return true;
376 }
ParseResourceParam(ani_env * env,ani_object objects,ResourceInfo & info)377 bool ParseResourceParam(ani_env *env, ani_object objects, ResourceInfo& info)
378 {
379     CompleteResourceParam(env, objects);
380 
381     ParseResourceParamId(env, objects, info);
382     ParseResourceParamBundleName(env, objects, info);
383     ParseResourceParamModuleName(env, objects, info);
384     ParseResourceParamType(env, objects, info);
385     ParseResourceParamName(env, objects, info);
386     return true;
387 }
GetThemeConstants(const std::optional<std::string> & bundleName,const std::optional<std::string> & moduleName)388 OHOS::Ace::RefPtr<OHOS::Ace::ThemeConstants> GetThemeConstants(
389     const std::optional<std::string>& bundleName, const std::optional<std::string>& moduleName)
390 {
391     auto container = OHOS::Ace::Container::Current();
392     if (!container) {
393         return nullptr;
394     }
395     auto pipelineContext = container->GetPipelineContext();
396     if (!pipelineContext) {
397         return nullptr;
398     }
399     auto themeManager = pipelineContext->GetThemeManager();
400     if (!themeManager) {
401         LOGE("themeManager is null!");
402         return nullptr;
403     }
404     if (bundleName.has_value() && moduleName.has_value()) {
405         return themeManager->GetThemeConstants(bundleName.value_or(""), moduleName.value_or(""));
406     }
407     return themeManager->GetThemeConstants();
408 }
CreateResourceWrapper(const ResourceInfo & info)409 OHOS::Ace::RefPtr<OHOS::Ace::ResourceWrapper> CreateResourceWrapper(const ResourceInfo& info)
410 {
411     auto bundleName = info.bundleName;
412     auto moduleName = info.moduleName;
413 
414     OHOS::Ace::RefPtr<OHOS::Ace::ResourceAdapter> resourceAdapter = nullptr;
415     OHOS::Ace::RefPtr<OHOS::Ace::ThemeConstants> themeConstants = nullptr;
416     if (OHOS::Ace::SystemProperties::GetResourceDecoupling()) {
417         if (bundleName.has_value() && moduleName.has_value()) {
418             auto resourceObject = OHOS::Ace::AceType::MakeRefPtr<OHOS::Ace::ResourceObject>(
419                             bundleName.value_or(""), moduleName.value_or(""), OHOS::Ace::Container::CurrentIdSafely());
420             resourceAdapter = OHOS::Ace::ResourceManager::GetInstance().GetOrCreateResourceAdapter(resourceObject);
421         } else {
422             resourceAdapter = OHOS::Ace::ResourceManager::GetInstance().GetResourceAdapter(
423                 OHOS::Ace::Container::CurrentIdSafely());
424         }
425         if (!resourceAdapter) {
426             return nullptr;
427         }
428     } else {
429         themeConstants = GetThemeConstants(info.bundleName, info.moduleName);
430         if (!themeConstants) {
431             return nullptr;
432         }
433     }
434     auto resourceWrapper = OHOS::Ace::AceType::MakeRefPtr<OHOS::Ace::ResourceWrapper>(themeConstants, resourceAdapter);
435     return resourceWrapper;
436 }
ReplaceHolder(std::string & originStr,const std::vector<std::string> & params,uint32_t containCount)437 void ReplaceHolder(std::string& originStr, const std::vector<std::string>& params, uint32_t containCount)
438 {
439     auto size = static_cast<uint32_t>(params.size());
440     if (containCount == size) {
441         return;
442     }
443     std::string::const_iterator start = originStr.begin();
444     std::string::const_iterator end = originStr.end();
445     std::smatch matches;
446     bool shortHolderType = false;
447     bool firstMatch = true;
448     uint32_t searchTime = 0;
449     while (std::regex_search(start, end, matches, RESOURCE_APP_STRING_PLACEHOLDER)) {
450         std::string pos = matches[2];
451         std::string type = matches[4];
452         if (firstMatch) {
453             firstMatch = false;
454             shortHolderType = pos.length() == 0;
455         } else {
456             if (static_cast<uint32_t>(shortHolderType) ^ (static_cast<uint32_t>(pos.length() == 0))) {
457                 LOGE("wrong place holder,stop parse string");
458                 return;
459             }
460         }
461 
462         std::string replaceContentStr;
463         std::string::size_type index = 0;
464         if (shortHolderType) {
465             index = static_cast<std::string::size_type>(searchTime + containCount);
466         } else {
467             int32_t indexTmp = OHOS::Ace::StringUtils::StringToInt(pos) + static_cast<int32_t>(containCount) - 1;
468             if (indexTmp >= 0) {
469                 index = static_cast<std::string::size_type>(indexTmp);
470             } else {
471                 LOGE("indexTmp err:%{public}d", indexTmp);
472             }
473         }
474         if (static_cast<uint32_t>(index) < size) {
475             replaceContentStr = params[index];
476         } else {
477             LOGE("index = %{public}d size = %{public}d", static_cast<uint32_t>(index), size);
478         }
479         originStr.replace(matches[0].first - originStr.begin(), matches[0].length(), replaceContentStr);
480         start = originStr.begin() + matches.prefix().length() + replaceContentStr.length();
481         end = originStr.end();
482         searchTime++;
483     }
484 }
DimensionToString(OHOS::Ace::Dimension dimension)485 std::string DimensionToString(OHOS::Ace::Dimension dimension)
486 {
487     static const int32_t unitsNum = 6;
488     static const int32_t percentIndex = 3;
489     static const int32_t percentUnit = 100;
490     static std::array<std::string, unitsNum> units = { "px", "vp", "fp", "%", "lpx", "auto" };
491     auto unit = dimension.Unit();
492     auto value = dimension.Value();
493     if (unit == OHOS::Ace::DimensionUnit::NONE) {
494         return OHOS::Ace::StringUtils::DoubleToString(value).append("none");
495     }
496     if (units[static_cast<int>(unit)] == units[percentIndex]) {
497         return OHOS::Ace::StringUtils::DoubleToString(value * percentUnit).append(units[static_cast<int>(unit)]);
498     }
499     return OHOS::Ace::StringUtils::DoubleToString(value).append(units[static_cast<int>(unit)]);
500 }
ParseString(const ResourceInfo & info,std::string & result)501 bool ParseString(const ResourceInfo& info, std::string& result)
502 {
503     auto resourceWrapper = CreateResourceWrapper(info);
504     if (info.type == static_cast<int>(ResourceType::PLURAL)) {
505         std::string pluralResults;
506         if (info.resId == UNKNOWN_RESOURCE_ID) {
507             auto count = OHOS::Ace::StringUtils::StringToInt(info.params[1]);
508             pluralResults = resourceWrapper->GetPluralStringByName(info.params[0], count);
509             ReplaceHolder(pluralResults, info.params, 2); // plural holder in index 2
510         } else {
511             auto count = OHOS::Ace::StringUtils::StringToInt(info.params[0]);
512             pluralResults = resourceWrapper->GetPluralString(info.resId, count);
513             ReplaceHolder(pluralResults, info.params, 1);
514         }
515         result = pluralResults;
516         return true;
517     } else if (info.type == static_cast<int>(ResourceType::RAWFILE)) {
518         auto fileName = info.params[0];
519         result = resourceWrapper->GetRawfile(fileName);
520         return true;
521     } else if (info.type == static_cast<int>(ResourceType::FLOAT)) {
522         if (info.resId == UNKNOWN_RESOURCE_ID) {
523             result = DimensionToString(resourceWrapper->GetDimensionByName(info.params[0]));
524         } else {
525             result = DimensionToString(resourceWrapper->GetDimension(info.resId));
526         }
527         return true;
528     } else if (info.type == static_cast<int>(ResourceType::STRING)) {
529         std::string originStr;
530         if (info.resId == UNKNOWN_RESOURCE_ID) {
531             originStr = resourceWrapper->GetStringByName(info.params[0]);
532             ReplaceHolder(originStr, info.params, 1);
533         } else {
534             originStr = resourceWrapper->GetString(info.resId);
535             ReplaceHolder(originStr, info.params, 0);
536         }
537         result = originStr;
538         return true;
539     } else if (info.type == static_cast<int>(ResourceType::COLOR)) {
540         result = resourceWrapper->GetColor(info.resId).ColorToString();
541         return true;
542     } else if (info.type == static_cast<int>(ResourceType::INTEGER)) {
543         result = std::to_string(resourceWrapper->GetInt(info.resId));
544         return true;
545     }
546     return false;
547 }
ParseAniColor(ani_env * env,ani_ref resourceColor_ref,OHOS::Ace::Color & resourceColor)548 bool ParseAniColor(ani_env *env, ani_ref resourceColor_ref, OHOS::Ace::Color& resourceColor)
549 {
550     if (GetIsStringObject(env, resourceColor_ref)) {
551         auto stringContent = ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(resourceColor_ref));
552         resourceColor = OHOS::Ace::Color::FromString(stringContent);
553         return true;
554     }
555     if (GetIsColorEnum(env, resourceColor_ref)) {
556         ani_int Color_int;
557         if (ANI_OK != env->EnumItem_GetValue_Int(static_cast<ani_enum_item>(resourceColor_ref), &Color_int)) {
558             return false;
559         }
560         OHOS::Ace::Color resourceColorValue;
561         ParseColorMapToColor(static_cast<PromptActionColor>(Color_int), resourceColorValue);
562         resourceColor = resourceColorValue;
563         return true;
564     }
565     if (GetIsNumberObject(env, resourceColor_ref)) {
566         ani_double resourceColorValue;
567         if (ANI_OK !=env->Object_CallMethodByName_Double(
568             static_cast<ani_object>(resourceColor_ref), "doubleValue", nullptr, &resourceColorValue)) {
569             return false;
570         }
571         resourceColor = static_cast<OHOS::Ace::Color>(resourceColorValue);
572         return true;
573     }
574     if (GetIsResourceObject(env, resourceColor_ref)) {
575         bool ret = ParseResourceColor(env, resourceColor_ref, resourceColor);
576         return ret;
577     }
578     return false;
579 }
ParseResourceColor(ani_env * env,ani_ref resourceColor_ref,OHOS::Ace::Color & resourceColor)580 bool ParseResourceColor(ani_env *env, ani_ref resourceColor_ref, OHOS::Ace::Color& resourceColor)
581 {
582     ResourceInfo resourceInfo;
583     std::string resourceColorStr;
584     if (!ParseResourceParam(env, static_cast<ani_object>(resourceColor_ref), resourceInfo)) {
585         return false;
586     }
587     if (!ParseString(resourceInfo, resourceColorStr)) {
588         return false;
589     }
590     if (resourceColorStr.size() == 0) {
591         return false;
592     }
593     resourceColor = OHOS::Ace::Color::FromString(resourceColorStr);
594     return true;
595 }
ParseColorMapToColor(PromptActionColor colorenum,OHOS::Ace::Color & Color)596 bool ParseColorMapToColor(PromptActionColor colorenum, OHOS::Ace::Color& Color)
597 {
598     OHOS::Ace::Color colorProp;
599     auto it = colorMap.find(colorenum);
600     if (it != colorMap.end()) {
601         colorProp = OHOS::Ace::Color(it->second);
602         Color = colorProp;
603         return true;
604     }
605     return false;
606 }
ParseLengthToDimension(ani_env * env,ani_ref source_ref,OHOS::Ace::DimensionUnit defaultUnit,OHOS::Ace::CalcDimension & result)607 bool ParseLengthToDimension(ani_env *env, ani_ref source_ref, OHOS::Ace::DimensionUnit defaultUnit,
608                             OHOS::Ace::CalcDimension& result)
609 {
610     if (GetIsStringObject(env, source_ref)) {
611         auto stringContent = ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(source_ref));
612         result = OHOS::Ace::StringUtils::StringToCalcDimension(stringContent, false, defaultUnit);
613         std::cout <<"ParseLengthToDimension string:" << stringContent.c_str() << std::endl;
614         return true;
615     }
616     if (GetIsNumberObject(env, source_ref)) {
617         ani_double numberValue;
618         if (ANI_OK !=env->Object_CallMethodByName_Double(
619             static_cast<ani_object>(source_ref), "doubleValue", nullptr, &numberValue)) {
620             return false;
621         }
622         result.SetUnit(defaultUnit);
623         result.SetValue(static_cast<double>(numberValue));
624         std::cout <<"ParseLengthToDimension dx/dy:" << static_cast<double>(numberValue) << std::endl;
625         return true;
626     }
627     if (GetIsResourceObject(env, source_ref)) {
628         ResourceInfo recv;
629         std::string parameterStr;
630         if (!ParseResourceParam(env, static_cast<ani_object>(source_ref), recv)) {
631             return false;
632         }
633         if (!ParseString(recv, parameterStr)) {
634             return false;
635         }
636         result = OHOS::Ace::StringUtils::StringToDimensionWithUnit(parameterStr, defaultUnit);
637         std::cout <<"ParseLengthToDimension resource" << std::endl;
638         return true;
639     }
640     return true;
641 }
GetShadowFromTheme(OHOS::Ace::ShadowStyle shadowStyle,OHOS::Ace::Shadow & shadow)642 bool GetShadowFromTheme(OHOS::Ace::ShadowStyle shadowStyle, OHOS::Ace::Shadow& shadow)
643 {
644     auto container = OHOS::Ace::Container::CurrentSafelyWithCheck();
645     CHECK_NULL_RETURN(container, false);
646     auto colorMode = container->GetColorMode();
647     if (shadowStyle == OHOS::Ace::ShadowStyle::None) {
648         return true;
649     }
650     auto pipelineContext = container->GetPipelineContext();
651     CHECK_NULL_RETURN(pipelineContext, false);
652     auto shadowTheme = pipelineContext->GetTheme<OHOS::Ace::ShadowTheme>();
653     if (!shadowTheme) {
654         return false;
655     }
656     shadow = shadowTheme->GetShadow(shadowStyle, colorMode);
657     return true;
658 }
GetToastObjectShadow(ani_env * env,ani_object objects,OHOS::Ace::Shadow & shadowProps)659 bool GetToastObjectShadow(ani_env *env, ani_object objects, OHOS::Ace::Shadow& shadowProps)
660 {
661     double radiusValue = 0.0;
662     ParseShadowOptionsRadius(env, objects, radiusValue);
663     shadowProps.SetBlurRadius(radiusValue);
664     int32_t shadowType = static_cast<int32_t>(OHOS::Ace::ShadowType::COLOR);
665     if (ParseShadowOptionsType(env, objects, shadowType)) {
666         std::cerr << "ParseShadowOptionsType shadowType:" << shadowType << std::endl;
667         shadowProps.SetShadowType(static_cast<OHOS::Ace::ShadowType>(shadowType));
668     }
669     ParseShadowOptionsColor(env, objects, shadowProps);
670     double offsetX = 0.0;
671     if (ParseShadowOptionsOffsetX(env, objects, offsetX)) {
672         std::cerr << "ParseShadowOptionsOffsetX offsetX:" << offsetX << std::endl;
673         shadowProps.SetOffsetX(offsetX);
674     }
675     double offsetY = 0.0;
676     if (ParseShadowOptionsOffsetY(env, objects, offsetY)) {
677         std::cerr << "ParseShadowOptionsOffsetY offsetY:" << offsetY << std::endl;
678         shadowProps.SetOffsetY(offsetY);
679     }
680     bool isFilled = false;
681     if (ParseShadowOptionsFill(env, objects, isFilled)) {
682         std::cerr << "ParseShadowOptionsFill isFilled:" << isFilled << std::endl;
683         shadowProps.SetIsFilled(isFilled);
684     }
685     return true;
686 }
ParseShadowOptionsFill(ani_env * env,ani_object objects,bool & isFilled)687 bool ParseShadowOptionsFill(ani_env *env, ani_object objects, bool& isFilled)
688 {
689     ani_ref fill_ref;
690     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "fill", &fill_ref)) {
691         return false;
692     }
693     if (GetIsUndefinedObject(env, fill_ref)) {
694         return false;
695     }
696     ani_boolean fillValue;
697     if (ANI_OK != env->Object_CallMethodByName_Boolean(
698         static_cast<ani_object>(fill_ref), "unboxed", nullptr, &fillValue)) {
699         return false;
700     }
701     isFilled = static_cast<bool>(fillValue);
702     return true;
703 }
ParseShadowOptionsOffsetX(ani_env * env,ani_object objects,double & offset)704 bool ParseShadowOptionsOffsetX(ani_env *env, ani_object objects, double& offset)
705 {
706     ani_ref offset_ref;
707     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "offsetX", &offset_ref)) {
708         return false;
709     }
710     if (GetIsUndefinedObject(env, offset_ref)) {
711         return false;
712     }
713     double offsetX = 0.0;
714     if (ParseShadowOptionsOffset(env, offset_ref, offsetX)) {
715         offset = offsetX;
716         return true;
717     }
718     return false;
719 }
ParseShadowOptionsOffsetY(ani_env * env,ani_object objects,double & offset)720 bool ParseShadowOptionsOffsetY(ani_env *env, ani_object objects, double& offset)
721 {
722     ani_ref offset_ref;
723     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "offsetY", &offset_ref)) {
724         return false;
725     }
726     if (GetIsUndefinedObject(env, offset_ref)) {
727         return false;
728     }
729     double offsetY = 0.0;
730     if (ParseShadowOptionsOffset(env, offset_ref, offsetY)) {
731         offset = offsetY;
732         return true;
733     }
734     return false;
735 }
ParseShadowOptionsOffset(ani_env * env,ani_ref offset_ref,double & offset)736 bool ParseShadowOptionsOffset(ani_env *env, ani_ref offset_ref, double& offset)
737 {
738     if (GetIsNumberObject(env, offset_ref)) {
739         ani_double offsetValue;
740         if (ANI_OK !=env->Object_CallMethodByName_Double(
741             static_cast<ani_object>(offset_ref), "doubleValue", nullptr, &offsetValue)) {
742             return false;
743         }
744         offset = static_cast<double>(offsetValue);
745         return true;
746     }
747     if (GetIsResourceObject(env, offset_ref)) {
748         ResourceInfo resourceInfo;
749         bool isRtl = OHOS::Ace::AceApplicationInfo::GetInstance().IsRightToLeft();
750         if (!ParseResourceParam(env, static_cast<ani_object>(offset_ref), resourceInfo)) {
751             return false;
752         }
753         OHOS::Ace::CalcDimension offsetDimension;
754         auto resourceWrapper = CreateResourceWrapper(resourceInfo);
755         auto offsetValue = resourceWrapper->GetDimension(resourceInfo.resId);
756         double value = isRtl ? offsetValue.Value() * (-1) : offsetValue.Value();
757         offset = value;
758         return true;
759     }
760     return false;
761 }
ParseShadowColorStrategy(ani_env * env,ani_ref resourceColor_ref,OHOS::Ace::ShadowColorStrategy & strategy)762 bool ParseShadowColorStrategy(ani_env *env, ani_ref resourceColor_ref, OHOS::Ace::ShadowColorStrategy& strategy)
763 {
764     ani_string stringValue;
765     if (ANI_OK != env->EnumItem_GetValue_String(static_cast<ani_enum_item>(resourceColor_ref), &stringValue)) {
766         return false;
767     }
768     auto colorStr = ANIUtils_ANIStringToStdString(env, static_cast<ani_string>(stringValue));
769     if (!colorStr.empty()) {
770         if (colorStr == "average") {
771             strategy = OHOS::Ace::ShadowColorStrategy::AVERAGE;
772             return true;
773         } else if (colorStr == "primary") {
774             strategy = OHOS::Ace::ShadowColorStrategy::PRIMARY;
775             return true;
776         }
777     }
778     return false;
779 }
ParseShadowOptionsColor(ani_env * env,ani_object objects,OHOS::Ace::Shadow & shadowProps)780 bool ParseShadowOptionsColor(ani_env *env, ani_object objects, OHOS::Ace::Shadow& shadowProps)
781 {
782     ani_ref color_ref;
783     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "color", &color_ref)) {
784         return false;
785     }
786     if (GetIsUndefinedObject(env, color_ref)) {
787         return false;
788     }
789     OHOS::Ace::Color color;
790     OHOS::Ace::ShadowColorStrategy shadowColorStrategy;
791     if (GetIsColoringStrategyEnum(env, color_ref)) {
792         if (ParseShadowColorStrategy(env, color_ref, shadowColorStrategy)) {
793             std::cout << "ParseShadowOptionsColor Strategy :" << (int32_t)shadowColorStrategy << std::endl;
794             shadowProps.SetShadowColorStrategy(shadowColorStrategy);
795         }
796     } else {
797         if (ParseAniColor(env, color_ref, color)) {
798             std::cout << "ParseShadowOptionsColor Color :" << color.ToString().c_str() << std::endl;
799             shadowProps.SetColor(color);
800         }
801     }
802     return true;
803 }
ParseShadowOptionsType(ani_env * env,ani_object objects,int32_t & shadowType)804 bool ParseShadowOptionsType(ani_env *env, ani_object objects, int32_t& shadowType)
805 {
806     ani_ref type_ref;
807     if (ANI_OK != env->Object_GetPropertyByName_Ref(objects, "type", &type_ref)) {
808         return false;
809     }
810     if (GetIsUndefinedObject(env, type_ref)) {
811         return false;
812     }
813     if (!GetIsShadowTypeEnum(env, type_ref)) {
814         return false;
815     }
816     ani_int type_int;
817     if (ANI_OK != env->EnumItem_GetValue_Int(static_cast<ani_enum_item>(type_ref), &type_int)) {
818         return false;
819     }
820     shadowType = static_cast<int32_t>(type_int);
821     if (shadowType != static_cast<int32_t>(OHOS::Ace::ShadowType::BLUR)) {
822         shadowType = static_cast<int32_t>(OHOS::Ace::ShadowType::COLOR);
823     }
824     shadowType = std::clamp(shadowType, static_cast<int32_t>(OHOS::Ace::ShadowType::COLOR),
825                     static_cast<int32_t>(OHOS::Ace::ShadowType::BLUR));
826     return true;
827 }
ParseShadowOptionsRadius(ani_env * env,ani_object object,double & result)828 bool ParseShadowOptionsRadius(ani_env *env, ani_object object, double& result)
829 {
830     ani_ref radius_ref;
831     if (ANI_OK != env->Object_GetPropertyByName_Ref(object, "radius", &radius_ref)) {
832         return false;
833     }
834     double radiusValue = 0.0;
835     if (GetIsNumberObject(env, radius_ref)) {
836         ParseRadiusNumberToDouble(env, static_cast<ani_object>(radius_ref), radiusValue);
837         result = radiusValue;
838         return true;
839     }
840     if (GetIsResourceObject(env, radius_ref)) {
841         ParseRadiusResourceToDouble(env, static_cast<ani_object>(radius_ref), radiusValue);
842         result = radiusValue;
843         return true;
844     }
845     return false;
846 }
ParseRadiusNumberToDouble(ani_env * env,ani_object resource_object,double & result)847 bool ParseRadiusNumberToDouble(ani_env *env, ani_object resource_object, double& result)
848 {
849     double radiusValue = 0.0;
850     ani_double radiu_ani;
851     if (ANI_OK !=env->Object_CallMethodByName_Double(resource_object, "doubleValue", nullptr, &radiu_ani)) {
852         return false;
853     }
854     radiusValue = static_cast<double>(radiu_ani);
855     if (OHOS::Ace::LessNotEqual(radiusValue, 0.0)) {
856         radiusValue = 0.0;
857     }
858     result = radiusValue;
859     return true;
860 }
ParseRadiusResourceToDouble(ani_env * env,ani_object resource_object,double & result)861 bool ParseRadiusResourceToDouble(ani_env *env, ani_object resource_object, double& result)
862 {
863     double radiusValue = 0.0;
864     ResourceInfo resourceInfo;
865     if (!ParseResourceParam(env, resource_object, resourceInfo)) {
866         return false;
867     }
868     OHOS::Ace::CalcDimension radius;
869     if (ParseResource(resourceInfo, radius)) {
870         radiusValue = OHOS::Ace::LessNotEqual(radius.Value(), 0.0) ? 0.0 : radius.Value();
871     }
872     result = radiusValue;
873     return true;
874 }
ParseResource(const ResourceInfo resource,OHOS::Ace::CalcDimension & result)875 bool ParseResource(const ResourceInfo resource, OHOS::Ace::CalcDimension& result)
876 {
877     auto resourceWrapper = CreateResourceWrapper(resource);
878     CHECK_NULL_RETURN(resourceWrapper, false);
879     if (resource.type == static_cast<uint32_t>(ResourceType::STRING)) {
880         auto value = resourceWrapper->GetString(resource.resId);
881         return OHOS::Ace::StringUtils::StringToCalcDimensionNG(value, result, false);
882     }
883     if (resource.type == static_cast<uint32_t>(ResourceType::INTEGER)) {
884         auto value = std::to_string(resourceWrapper->GetInt(resource.resId));
885         OHOS::Ace::StringUtils::StringToDimensionWithUnitNG(value, result);
886         return true;
887     }
888     if (resource.type == static_cast<uint32_t>(ResourceType::FLOAT)) {
889         result = resourceWrapper->GetDimension(resource.resId);
890         return true;
891     }
892     return false;
893 }
GetIsResourceObject(ani_env * env,ani_ref object_ref)894 bool GetIsResourceObject(ani_env *env, ani_ref object_ref)
895 {
896     ani_class resourceClass;
897     if (ANI_OK != env->FindClass("L@ohos/promptAction/promptAction/Resource;", &resourceClass)) {
898         return false;
899     }
900     ani_boolean isResource = false;
901     if (ANI_OK != env->Object_InstanceOf(static_cast<ani_object>(object_ref), resourceClass, &isResource)) {
902         return false;
903     }
904     return (bool)isResource;
905 }
GetIsStringObject(ani_env * env,ani_ref object_ref)906 bool GetIsStringObject(ani_env *env, ani_ref object_ref)
907 {
908     ani_class stringClass;
909     if (ANI_OK != env->FindClass("Lstd/core/String;", &stringClass)) {
910         return false;
911     }
912     ani_boolean isString;
913     if (ANI_OK != env->Object_InstanceOf(static_cast<ani_object>(object_ref), stringClass, &isString)) {
914         return false;
915     }
916     return (bool)isString;
917 }
GetIsNumberObject(ani_env * env,ani_ref object_ref)918 bool GetIsNumberObject(ani_env *env, ani_ref object_ref)
919 {
920     ani_class numberClass;
921     if (ANI_OK != env->FindClass("Lstd/core/Numeric;", &numberClass)) {
922         return false;
923     }
924     ani_boolean isNumber;
925     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), numberClass, &isNumber)) {
926         return false;
927     }
928     return (bool)isNumber;
929 }
GetIsArrayObject(ani_env * env,ani_ref object_ref)930 bool GetIsArrayObject(ani_env *env, ani_ref object_ref)
931 {
932     ani_class arrayClass;
933     if (ANI_OK != env->FindClass("Lescompat/Array;", &arrayClass)) {
934         return false;
935     }
936     ani_boolean isArray;
937     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), arrayClass, &isArray)) {
938         return false;
939     }
940     return (bool)isArray;
941 }
GetIsShadowOptionsObject(ani_env * env,ani_ref object_ref)942 bool GetIsShadowOptionsObject(ani_env *env, ani_ref object_ref)
943 {
944     ani_class ShadowOptionsClass;
945     if (ANI_OK != env->FindClass("L@ohos/promptAction/promptAction/ShadowOptions;", &ShadowOptionsClass)) {
946         return false;
947     }
948     ani_boolean isShadowOptions;
949     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), ShadowOptionsClass, &isShadowOptions)) {
950         return false;
951     }
952     return (bool)isShadowOptions;
953 }
GetIsShowToastOptionsObject(ani_env * env,ani_object object)954 bool GetIsShowToastOptionsObject(ani_env *env, ani_object object)
955 {
956     ani_class optionsClass;
957     if (ANI_OK != env->FindClass("L@ohos/promptAction/promptAction/ShowToastOptions;", &optionsClass)) {
958         return false;
959     }
960     ani_boolean isOptions;
961     if (env->Object_InstanceOf(object, optionsClass, &isOptions)) {
962         return false;
963     }
964     return (bool)isOptions;
965 }
GetIsBlurStyleEnum(ani_env * env,ani_ref object_ref)966 bool GetIsBlurStyleEnum(ani_env *env, ani_ref object_ref)
967 {
968     ani_enum enumType;
969     if (ANI_OK != env->FindEnum("L@ohos/promptAction/promptAction/#BlurStyle;", &enumType)) {
970         return false;
971     }
972     ani_boolean isEnum;
973     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), enumType, &isEnum)) {
974         return false;
975     }
976     return (bool)isEnum;
977 }
GetIsToastShowModeEnum(ani_env * env,ani_ref object_ref)978 bool GetIsToastShowModeEnum(ani_env *env, ani_ref object_ref)
979 {
980     ani_enum enumType;
981     if (ANI_OK != env->FindEnum("L@ohos/promptAction/promptAction/#ToastShowMode;", &enumType)) {
982         return false;
983     }
984     ani_boolean isEnum;
985     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), enumType, &isEnum)) {
986         return false;
987     }
988     return (bool)isEnum;
989 }
GetIsShadowStyleEnum(ani_env * env,ani_ref object_ref)990 bool GetIsShadowStyleEnum(ani_env *env, ani_ref object_ref)
991 {
992     ani_enum enumType;
993     if (ANI_OK != env->FindEnum("L@ohos/promptAction/promptAction/#ShadowStyle;", &enumType)) {
994         return false;
995     }
996     ani_boolean isEnum;
997     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), enumType, &isEnum)) {
998         return false;
999     }
1000     return (bool)isEnum;
1001 }
GetIsAlignmentEnum(ani_env * env,ani_ref object_ref)1002 bool GetIsAlignmentEnum(ani_env *env, ani_ref object_ref)
1003 {
1004     ani_enum enumType;
1005     if (ANI_OK != env->FindEnum("L@ohos/promptAction/promptAction/#Alignment;", &enumType)) {
1006         return false;
1007     }
1008     ani_boolean isEnum;
1009     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), enumType, &isEnum)) {
1010         return false;
1011     }
1012     return (bool)isEnum;
1013 }
GetIsShadowTypeEnum(ani_env * env,ani_ref object_ref)1014 bool GetIsShadowTypeEnum(ani_env *env, ani_ref object_ref)
1015 {
1016     ani_enum enumType;
1017     if (ANI_OK != env->FindEnum("L@ohos/promptAction/promptAction/#ShadowType;", &enumType)) {
1018         return false;
1019     }
1020     ani_boolean isEnum;
1021     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), enumType, &isEnum)) {
1022         return false;
1023     }
1024     return (bool)isEnum;
1025 }
GetIsColoringStrategyEnum(ani_env * env,ani_ref object_ref)1026 bool GetIsColoringStrategyEnum(ani_env *env, ani_ref object_ref)
1027 {
1028     ani_enum coloringStrategyEnum;
1029     if (ANI_OK != env->FindEnum("L@ohos/promptAction/promptAction/#ColoringStrategy;", &coloringStrategyEnum)) {
1030         return false;
1031     }
1032     ani_boolean isEnum;
1033     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), coloringStrategyEnum, &isEnum)) {
1034         return false;
1035     }
1036     return (bool)isEnum;
1037 }
GetIsColorEnum(ani_env * env,ani_ref object_ref)1038 bool GetIsColorEnum(ani_env *env, ani_ref object_ref)
1039 {
1040     ani_enum colorEnum;
1041     if (ANI_OK != env->FindEnum("L@ohos/promptAction/promptAction/#Color;", &colorEnum)) {
1042         return false;
1043     }
1044     ani_boolean isEnum;
1045     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), colorEnum, &isEnum)) {
1046         return false;
1047     }
1048     return (bool)isEnum;
1049 }
GetIsHoverModeAreaEnum(ani_env * env,ani_ref object_ref)1050 bool GetIsHoverModeAreaEnum(ani_env *env, ani_ref object_ref)
1051 {
1052     ani_enum areaEnum;
1053     if (ANI_OK != env->FindEnum("L@ohos/promptAction/promptAction/#HoverModeAreaType;", &areaEnum)) {
1054         return false;
1055     }
1056     ani_boolean isEnum;
1057     if (env->Object_InstanceOf(static_cast<ani_object>(object_ref), areaEnum, &isEnum)) {
1058         return false;
1059     }
1060     return (bool)isEnum;
1061 }
GetIsUndefinedObject(ani_env * env,ani_ref object_ref)1062 bool GetIsUndefinedObject(ani_env *env, ani_ref object_ref)
1063 {
1064     ani_boolean isUndefined;
1065     if (ANI_OK != env->Reference_IsUndefined(object_ref, &isUndefined)) {
1066         return false;
1067     }
1068     return (bool)isUndefined;
1069 }