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 #include "sts_convert_other.h"
16
17 #include "sts_common.h"
18 #include "pixel_map_taihe_ani.h"
19
20 namespace OHOS {
21 namespace NotificationSts {
UnwrapWantAgent(ani_env * env,ani_object agent)22 std::shared_ptr<WantAgent> UnwrapWantAgent(ani_env *env, ani_object agent)
23 {
24 ANS_LOGD("UnwrapWantAgent called");
25 if (env == nullptr || agent == nullptr) {
26 ANS_LOGE("UnwrapWantAgent failed, has nullPtr");
27 return nullptr;
28 }
29 ani_status status = ANI_ERROR;
30 ani_long nativeObj {};
31 if ((status = env->Object_GetFieldByName_Long(agent, "nativeObj", &nativeObj)) != ANI_OK) {
32 ANS_LOGI("UnwrapWantAgent Object_GetField_Long fetch failed, status = %{public}d", status);
33 return nullptr;
34 }
35 WantAgent* wantAgent = reinterpret_cast<WantAgent*>(nativeObj);
36 if (wantAgent == nullptr) {
37 ANS_LOGI("UnwrapWantAgent wantAgent nullptr");
38 return nullptr;
39 }
40 std::shared_ptr<WantAgent> wantAgentSp = std::make_shared<WantAgent>(*wantAgent);
41 deletePoint(wantAgent);
42 ANS_LOGD("UnwrapWantAgent end");
43 return wantAgentSp;
44 }
45
UnwrapResource(ani_env * env,ani_object obj,ResourceManager::Resource & resource)46 ani_status UnwrapResource(ani_env *env, ani_object obj, ResourceManager::Resource &resource)
47 {
48 ANS_LOGD("UnwrapResource called");
49 if (env == nullptr || obj == nullptr) {
50 ANS_LOGE("UnwrapResource failed, has nullptr");
51 return ANI_ERROR;
52 }
53 ani_status status = ANI_ERROR;
54 std::string tempStr = "";
55 ani_boolean isUndefined = ANI_TRUE;
56 if ((status = GetPropertyString(env, obj, "bundleName", isUndefined, tempStr)) != ANI_OK
57 || isUndefined == ANI_TRUE) {
58 return ANI_INVALID_ARGS;
59 }
60 std::string bundleName = GetResizeStr(tempStr, STR_MAX_SIZE);
61 resource.bundleName = bundleName;
62
63 if ((status = GetPropertyString(env, obj, "moduleName", isUndefined, tempStr)) != ANI_OK
64 || isUndefined == ANI_TRUE) {
65 return ANI_INVALID_ARGS;
66 }
67 std::string moduleName = GetResizeStr(tempStr, STR_MAX_SIZE);
68 resource.moduleName = moduleName;
69
70 ani_double idAni = 0.0;
71 if ((status = GetPropertyDouble(env, obj, "id", isUndefined, idAni)) != ANI_OK
72 || isUndefined == ANI_TRUE) {
73 return ANI_INVALID_ARGS;
74 }
75 resource.id = static_cast<int32_t>(idAni);
76 ANS_LOGD("UnwrapResource end");
77 return status;
78 }
79
CreateAniPixelMap(ani_env * env,std::shared_ptr<PixelMap> pixelMap)80 ani_object CreateAniPixelMap(ani_env* env, std::shared_ptr<PixelMap> pixelMap)
81 {
82 ANS_LOGD("CreateAniPixelMap call");
83 if (env == nullptr || pixelMap == nullptr) {
84 ANS_LOGE("CreateAniPixelMap failed, has nullPtr");
85 return nullptr;
86 }
87 return PixelMapTaiheAni::CreateEtsPixelMap(env, pixelMap);
88 }
89
GetPixelMapFromAni(ani_env * env,ani_object obj)90 std::shared_ptr<PixelMap> GetPixelMapFromAni(ani_env* env, ani_object obj)
91 {
92 ANS_LOGD("GetPixelMapFromAni call");
93 if (env == nullptr || obj == nullptr) {
94 ANS_LOGE("GetPixelMapFromAni failed, has nullPtr");
95 return nullptr;
96 }
97 return PixelMapTaiheAni::GetNativePixelMap(env, obj);
98 }
99
GetPixelMapArrayByRef(ani_env * env,ani_ref param,std::vector<std::shared_ptr<PixelMap>> & pixelMaps)100 ani_status GetPixelMapArrayByRef(ani_env *env, ani_ref param, std::vector<std::shared_ptr<PixelMap>> &pixelMaps)
101 {
102 ANS_LOGD("GetPixelMapArrayByRef call");
103 if (env == nullptr || param == nullptr) {
104 ANS_LOGE("GetPixelMapArrayByRef failed, has nullPtr");
105 return ANI_ERROR;
106 }
107 ani_status status = ANI_ERROR;
108 ani_double length;
109 status = env->Object_GetPropertyByName_Double(static_cast<ani_object>(param), "length", &length);
110 if (status != ANI_OK) {
111 ANS_LOGE("GetPixelMapArrayByRef: status : %{public}d", status);
112 return status;
113 }
114
115 for (int i = 0; i < static_cast<int>(length); i++) {
116 ani_ref pixelMapRef;
117 status = env->Object_CallMethodByName_Ref(static_cast<ani_object>(param),
118 "$_get", "I:Lstd/core/Object;", &pixelMapRef, (ani_int)i);
119 if (status != ANI_OK) {
120 ANS_LOGE("GetPixelMapArrayByRef:status : %{public}d, index: %{public}d", status, i);
121 pixelMaps.clear();
122 return status;
123 }
124 std::shared_ptr<PixelMap> pixelMap = GetPixelMapFromAni(env, static_cast<ani_object>(pixelMapRef));
125 if (pixelMap == nullptr) {
126 ANS_LOGE("GetPixelMapArrayByRef: GetPixelMapFromAni failed.");
127 pixelMaps.clear();
128 return ANI_INVALID_ARGS;
129 }
130 pixelMaps.push_back(pixelMap);
131 }
132 ANS_LOGD("GetPixelMapArrayByRef end");
133 return status;
134 }
135
GetPixelMapArray(ani_env * env,ani_object param,const char * name,std::vector<std::shared_ptr<PixelMap>> & pixelMaps)136 ani_status GetPixelMapArray(ani_env *env,
137 ani_object param, const char *name, std::vector<std::shared_ptr<PixelMap>> &pixelMaps)
138 {
139 ANS_LOGD("GetPixelMapArray call");
140 if (env == nullptr || param == nullptr || name == nullptr) {
141 ANS_LOGE("GetPixelMapArray failed, has nullPtr");
142 return ANI_ERROR;
143 }
144 ani_ref arrayObj = nullptr;
145 ani_boolean isUndefined = ANI_TRUE;
146 ani_status status = ANI_ERROR;
147 if ((status = GetPropertyRef(env, param, name, isUndefined, arrayObj)) != ANI_OK || isUndefined == ANI_TRUE) {
148 return ANI_INVALID_ARGS;
149 }
150
151 if ((status = GetPixelMapArrayByRef(env, arrayObj, pixelMaps)) != ANI_OK) {
152 pixelMaps.clear();
153 return status;
154 }
155 ANS_LOGD("GetPixelMapArray end");
156 return status;
157 }
158
GetResourceArray(ani_env * env,ani_object param,const char * name,std::vector<ResourceManager::Resource> & res)159 ani_status GetResourceArray(ani_env *env,
160 ani_object param, const char *name, std::vector<ResourceManager::Resource> &res)
161 {
162 ANS_LOGD("GetResourceArray call");
163 if (env == nullptr || param == nullptr || name == nullptr) {
164 ANS_LOGE("GetResourceArray failed, has nullPtr");
165 return ANI_ERROR;
166 }
167 ani_ref arrayObj = nullptr;
168 ani_boolean isUndefined = true;
169 ani_status status;
170 ani_double length;
171 if ((status = GetPropertyRef(env, param, name, isUndefined, arrayObj)) != ANI_OK || isUndefined == ANI_TRUE) {
172 ANS_LOGE("GetResourceArray failed, status : %{public}d", status);
173 return ANI_INVALID_ARGS;
174 }
175 status = env->Object_GetPropertyByName_Double(static_cast<ani_object>(arrayObj), "length", &length);
176 if (status != ANI_OK) {
177 ANS_LOGE("GetResourceArray : status : %{public}d", status);
178 return status;
179 }
180 for (int i = 0; i < static_cast<int>(length); i++) {
181 ani_ref iconRef;
182 status = env->Object_CallMethodByName_Ref(static_cast<ani_object>(arrayObj),
183 "$_get", "I:Lstd/core/Object;", &iconRef, (ani_int)i);
184 if (status != ANI_OK) {
185 res.clear();
186 ANS_LOGE("GetResourceArray: status = %{public}d, index = %{public}d", status, i);
187 return status;
188 }
189 ResourceManager::Resource resource;
190 if (ANI_OK != UnwrapResource(env, static_cast<ani_object>(iconRef), resource)) {
191 ANS_LOGE("GetResourceArray : status = %{public}d, index= %{public}d", status, i);
192 res.clear();
193 return status;
194 }
195 res.push_back(resource);
196 }
197 ANS_LOGD("GetResourceArray end");
198 return status;
199 }
200
GetKeyString(ani_env * env,ani_object obj,int index,ani_string & str)201 ani_status GetKeyString(ani_env *env, ani_object obj, int index, ani_string &str)
202 {
203 ANS_LOGD("GetKeyString call");
204 if (env == nullptr || obj == nullptr) {
205 ANS_LOGE("GetKeyString failed, has nullPtr");
206 return ANI_ERROR;
207 }
208 ani_status status = ANI_ERROR;
209 ani_ref stringEntryRef;
210 status = env->Object_CallMethodByName_Ref(obj,
211 "$_get", "I:Lstd/core/Object;", &stringEntryRef, (ani_int)index);
212 if (status != ANI_OK) {
213 ANS_LOGE("status : %{public}d, index: %{public}d", status, index);
214 return status;
215 }
216 str = static_cast<ani_string>(stringEntryRef);
217 ANS_LOGD("GetKeyString end");
218 return status;
219 }
220
GetPixelMapByKeys(ani_env * env,ani_object obj,std::vector<ani_string> keys,std::map<std::string,std::vector<std::shared_ptr<Media::PixelMap>>> & pictureMap)221 ani_status GetPixelMapByKeys(ani_env *env, ani_object obj, std::vector<ani_string> keys,
222 std::map<std::string, std::vector<std::shared_ptr<Media::PixelMap>>> &pictureMap)
223 {
224 ANS_LOGD("GetPixelMapByKeys call");
225 if (env == nullptr || obj == nullptr) {
226 ANS_LOGE("GetPixelMapByKeys failed, has nullPtr");
227 return ANI_ERROR;
228 }
229 ani_status status = ANI_ERROR;
230 for (auto anikey : keys) {
231 ani_ref picturesArrayRef;
232 if (ANI_OK != (status = env->Object_CallMethodByName_Ref(obj, "$_get", nullptr, &picturesArrayRef, anikey))) {
233 ANS_LOGE("GetPixelMapByKeys : Object_CallMethodByName_Ref failed");
234 deleteVectorWithArraySpPoints(pictureMap);
235 return status;
236 }
237 std::vector<std::shared_ptr<PixelMap>> pixelMaps = {};
238 if ((status = GetPixelMapArrayByRef(env, picturesArrayRef, pixelMaps)) != ANI_OK) {
239 ANS_LOGE("GetPixelMapByKeys : GetPixelMapArrayByRef failed");
240 deleteVectorWithSpPoints(pixelMaps);
241 deleteVectorWithArraySpPoints(pictureMap);
242 return status;
243 }
244 std::string str = "";
245 if ((status = GetStringByAniString(env, anikey, str)) != ANI_OK) {
246 ANS_LOGE("GetPixelMapByKeys : GetStringByAniString failed");
247 deleteVectorWithSpPoints(pixelMaps);
248 deleteVectorWithArraySpPoints(pictureMap);
249 return status;
250 }
251 pictureMap[str] = pixelMaps;
252 }
253 ANS_LOGD("GetPixelMapByKeys end");
254 return status;
255 }
256
GetPixelMapByRef(ani_env * env,ani_object obj,ani_ref keysStrArrayRef,std::map<std::string,std::vector<std::shared_ptr<Media::PixelMap>>> & pictureMap)257 ani_status GetPixelMapByRef(
258 ani_env *env, ani_object obj, ani_ref keysStrArrayRef,
259 std::map<std::string, std::vector<std::shared_ptr<Media::PixelMap>>> &pictureMap)
260 {
261 ANS_LOGD("GetPixelMapByRef call");
262 if (env == nullptr || obj == nullptr || keysStrArrayRef == nullptr) {
263 ANS_LOGE("GetPixelMapByRef failed, has nullPtr");
264 return ANI_ERROR;
265 }
266 ani_status status = ANI_ERROR;
267 ani_double length;
268 if (ANI_OK !=
269 (status = env->Object_GetPropertyByName_Double(static_cast<ani_object>(keysStrArrayRef), "length", &length))) {
270 ANS_LOGE("GetPixelMapByRef : Object_GetPropertyByName_Double status = %{public}d", status);
271 return status;
272 }
273 ani_string strAni = {};
274 std::vector<ani_string> keys = {};
275 for (int i = 0; i < static_cast<int>(length); i++) {
276 if ((status = GetKeyString(env, static_cast<ani_object>(keysStrArrayRef), i, strAni)) != ANI_OK) {
277 ANS_LOGE("GetPixelMapByRef : GetKeyString status = %{public}d", status);
278 keys.clear();
279 return status;
280 }
281 keys.push_back(strAni);
282 }
283 status = GetPixelMapByKeys(env, obj, keys, pictureMap);
284 ANS_LOGD("GetPixelMapByRef end");
285 return status;
286 }
287
GetMapOfPictureInfo(ani_env * env,ani_object obj,std::map<std::string,std::vector<std::shared_ptr<Media::PixelMap>>> & pictureMap)288 ani_status GetMapOfPictureInfo(ani_env *env, ani_object obj,
289 std::map<std::string, std::vector<std::shared_ptr<Media::PixelMap>>> &pictureMap)
290 {
291 ANS_LOGD("GetMapOfPictureInfo call");
292 if (env == nullptr || obj == nullptr) {
293 ANS_LOGE("GetMapOfPictureInfo failed, has nullPtr");
294 return ANI_ERROR;
295 }
296 ani_status status = ANI_ERROR;
297 ani_class cls = nullptr;
298 if (ANI_OK != (status = env->FindClass("Lnotification/notificationContent/RecordTools;", &cls))) {
299 ANS_LOGE("GetMapOfPictureInfo : FindClass status = %{public}d", status);
300 return status;
301 }
302 if (cls == nullptr) {
303 ANS_LOGE("GetMapOfPictureInfo : cls is nullptr");
304 return ANI_INVALID_TYPE;
305 }
306 ani_static_method keysMethod = nullptr;
307 if (ANI_OK != (status = env->Class_FindStaticMethod(cls, "GetKeys", nullptr, &keysMethod))) {
308 ANS_LOGE("GetMapOfPictureInfo : Class_FindStaticMethod status = %{public}d", status);
309 return status;
310 }
311 ani_ref keysStrArrayRef = nullptr;
312 if (ANI_OK != (status = env->Class_CallStaticMethod_Ref(cls, keysMethod, &keysStrArrayRef, obj))) {
313 ANS_LOGE("GetMapOfPictureInfo : Class_CallStaticMethod_Ref status = %{public}d", status);
314 return status;
315 }
316 if (IsUndefine(env, static_cast<ani_object>(keysStrArrayRef))) {
317 ANS_LOGE("GetMapOfPictureInfo : keysStrArrayRef IsUndefined");
318 return ANI_INVALID_ARGS;
319 }
320 if (ANI_OK != (status = GetPixelMapByRef(env, obj, keysStrArrayRef, pictureMap))) {
321 deleteVectorWithArraySpPoints(pictureMap);
322 ANS_LOGE("GetMapOfPictureInfo : GetPixelMapByRef status = %{public}d", status);
323 }
324 ANS_LOGD("GetMapOfPictureInfo end");
325 return status;
326 }
327
GetAniResource(ani_env * env,const std::shared_ptr<ResourceManager::Resource> resource)328 ani_object GetAniResource(ani_env *env, const std::shared_ptr<ResourceManager::Resource> resource)
329 {
330 ANS_LOGD("GetAniResource call");
331 if (env == nullptr || resource == nullptr) {
332 ANS_LOGE("GetAniResource failed, has nullPtr");
333 return nullptr;
334 }
335 ani_status status = ANI_ERROR;
336 ani_class resourceCls = nullptr;
337 ani_object resourceObject = nullptr;
338 if (!CreateClassObjByClassName(env,
339 "Lglobal/resourceInner/ResourceInner;", resourceCls, resourceObject)) {
340 ANS_LOGE("GetAniResource : CreateClassObjByClassName failed");
341 return nullptr;
342 }
343 ani_string stringValue = nullptr;
344 if (ANI_OK != (status = GetAniStringByString(env, resource->bundleName, stringValue))
345 || !CallSetter(env, resourceCls, resourceObject, "bundleName", stringValue)) {
346 ANS_LOGE("GetAniResource : set bundleName failed, status = %{public}d", status);
347 return nullptr;
348 }
349 if (ANI_OK != (status = GetAniStringByString(env, resource->moduleName, stringValue))
350 || !CallSetter(env, resourceCls, resourceObject, "moduleName", stringValue)) {
351 ANS_LOGE("GetAniResource : set moduleName failed, status = %{public}d", status);
352 return nullptr;
353 }
354 if (!CallSetter(env, resourceCls, resourceObject, "id", resource->id)) {
355 ANS_LOGE("GetAniResource : set moduleName failed, status = %{public}d", status);
356 }
357 ANS_LOGD("GetAniResource end");
358 return resourceObject;
359 }
360
GetAniArrayPixelMap(ani_env * env,const std::vector<std::shared_ptr<Media::PixelMap>> pixelMaps)361 ani_object GetAniArrayPixelMap(ani_env *env, const std::vector<std::shared_ptr<Media::PixelMap>> pixelMaps)
362 {
363 ANS_LOGD("GetAniArrayPixelMap call");
364 if (env == nullptr) {
365 ANS_LOGE("GetAniArrayPixelMap failed, env is nullPtr");
366 return nullptr;
367 }
368 ani_size length = pixelMaps.size();
369 ani_object arrayObj = newArrayClass(env, length);
370 if (arrayObj == nullptr) {
371 ANS_LOGE("GetAniArrayPixelMap : arrayObj is nullptr");
372 return nullptr;
373 }
374 ani_size i = 0;
375 for (auto pixelMap : pixelMaps) {
376 ani_object pixelMapObject = CreateAniPixelMap(env, pixelMap);
377 if (pixelMapObject == nullptr) {
378 ANS_LOGE("GetAniArrayPixelMap : pixelMapObject is nullptr");
379 return nullptr;
380 }
381 ani_status status = env->Object_CallMethodByName_Void(arrayObj, "$_set", "ILstd/core/Object;:V",
382 i, pixelMapObject);
383 if (status != ANI_OK) {
384 ANS_LOGE("GetAniArrayPixelMap : Object_CallMethodByName_Void failed %{public}d", status);
385 return nullptr;
386 }
387 i++;
388 }
389 ANS_LOGD("GetAniArrayPixelMap end");
390 return arrayObj;
391 }
392
GetAniArrayResource(ani_env * env,const std::vector<std::shared_ptr<ResourceManager::Resource>> resources)393 ani_object GetAniArrayResource(ani_env *env,
394 const std::vector<std::shared_ptr<ResourceManager::Resource>> resources)
395 {
396 ANS_LOGD("GetAniArrayResource call");
397 if (env == nullptr) {
398 ANS_LOGE("GetAniArrayResource failed, env is nullPtr");
399 return nullptr;
400 }
401 ani_size length = resources.size();
402 ani_object arrayObj = newArrayClass(env, length);
403 if (arrayObj == nullptr) {
404 ANS_LOGE("GetAniArrayResource : arrayObj is nullPtr");
405 return nullptr;
406 }
407 ani_size i = 0;
408 for (auto resource : resources) {
409 ani_object resourceObject = GetAniResource(env, resource);
410 if (resourceObject == nullptr) {
411 ANS_LOGE("GetAniArrayResource : resourceObject is nullPtr");
412 return nullptr;
413 }
414 ani_status status = env->Object_CallMethodByName_Void(arrayObj, "$_set", "ILstd/core/Object;:V",
415 i, resourceObject);
416 if (status != ANI_OK) {
417 ANS_LOGE("GetAniArrayResource : Object_CallMethodByName_Void failed %{public}d", status);
418 return nullptr;
419 }
420 i++;
421 }
422 ANS_LOGD("GetAniArrayResource end");
423 return arrayObj;
424 }
425
GetAniPictrueInfo(ani_env * env,std::map<std::string,std::vector<std::shared_ptr<Media::PixelMap>>> pictureMap,ani_object & pictureInfoObj)426 bool GetAniPictrueInfo(ani_env *env, std::map<std::string, std::vector<std::shared_ptr<Media::PixelMap>>> pictureMap,
427 ani_object &pictureInfoObj)
428 {
429 ANS_LOGD("GetAniPictrueInfo call");
430 if (env == nullptr) {
431 ANS_LOGE("GetAniPictrueInfo failed, env is nullPtr");
432 return false;
433 }
434 pictureInfoObj = newRecordClass(env);
435 if (pictureInfoObj == nullptr) {
436 ANS_LOGE("GetAniPictrueInfo failed, pictureInfoObj is nullPtr");
437 return false;
438 }
439 for (const auto& [key, value] : pictureMap) {
440 ani_string aniKey;
441 if (GetAniStringByString(env, key, aniKey) != ANI_OK || aniKey == nullptr) {
442 ANS_LOGE("GetAniPictrueInfo : GetAniStringByString failed");
443 return false;
444 }
445 ani_object aniPictrueArray = GetAniArrayPixelMap(env, value);
446 if (aniPictrueArray == nullptr) {
447 ANS_LOGE("GetAniPictrueInfo : GetAniArrayPixelMap failed");
448 return false;
449 }
450 if (ANI_OK != env->Object_CallMethodByName_Void(pictureInfoObj,
451 "$_set", "Lstd/core/Object;Lstd/core/Object;:V", aniKey, aniPictrueArray)) {
452 ANS_LOGE("GetAniPictrueInfo : Object_CallMethodByName_Void failed");
453 return false;
454 }
455 }
456 ANS_LOGD("GetAniPictrueInfo end");
457 return true;
458 }
459
WarpWantAgent(ani_env * env,std::shared_ptr<WantAgent> wantAgent)460 ani_object WarpWantAgent(ani_env *env, std::shared_ptr<WantAgent> wantAgent)
461 {
462 ANS_LOGD("WarpWantAgent call");
463 if (wantAgent == nullptr) {
464 ANS_LOGE("WarpWantAgent failed, wantAgent is nullptr");
465 return nullptr;
466 }
467 ani_object wantAgentObj = AppExecFwk::WrapWantAgent(env, wantAgent.get());
468 if (wantAgentObj == nullptr) {
469 ANS_LOGE("WarpWantAgent : wantAgentObj is nullptr");
470 }
471 ANS_LOGD("WarpWantAgent end");
472 return wantAgentObj;
473 }
474
GetAniWantAgentArray(ani_env * env,std::vector<std::shared_ptr<WantAgent>> wantAgents)475 ani_object GetAniWantAgentArray(ani_env *env, std::vector<std::shared_ptr<WantAgent>> wantAgents)
476 {
477 ANS_LOGD("GetAniWantAgentArray call");
478 if (env == nullptr || wantAgents.empty()) {
479 ANS_LOGE("GetAniWantAgentArray failed, env is nullptr or wantAgents is empty");
480 return nullptr;
481 }
482 ani_status status = ANI_ERROR;
483 ani_class arrayCls = nullptr;
484 if (ANI_OK != (status = env->FindClass("Lescompat/Array;", &arrayCls))) {
485 ANS_LOGE("GetAniWantAgentArray : FindClass status = %{public}d", status);
486 return nullptr;
487 }
488 ani_method arrayCtor;
489 if (ANI_OK != (status = env->Class_FindMethod(arrayCls, "<ctor>", "I:V", &arrayCtor))) {
490 ANS_LOGE("GetAniWantAgentArray : Class_FindMethod status = %{public}d", status);
491 return nullptr;
492 }
493 ani_object arrayObj;
494 if (ANI_OK != (status = env->Object_New(arrayCls, arrayCtor, &arrayObj, wantAgents.size()))) {
495 ANS_LOGE("GetAniWantAgentArray : Object_New status = %{public}d", status);
496 return nullptr;
497 }
498 ani_size index = 0;
499 for (auto &wantAgent : wantAgents) {
500 ani_object item = WarpWantAgent(env, wantAgent);
501 if (item == nullptr
502 || ANI_OK != env->Object_CallMethodByName_Void(arrayObj, "$_set", "ILstd/core/Object;:V", index, item)) {
503 ANS_LOGE("GetAniWantAgentArray : set WantAgent failed");
504 return nullptr;
505 }
506 index ++;
507 }
508 ANS_LOGD("GetAniWantAgentArray end");
509 return arrayObj;
510 }
511 } // namespace NotificationSts
512 } // OHOS