Add new APIs for task-manager
[platform/core/appfw/librua.git] / src / rua_info.c
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define _GNU_SOURCE
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22
23 #include <glib.h>
24 #include <pkgmgr-info.h>
25 #include <aul.h>
26 #include <aul_comp_info.h>
27
28 #include "rua.h"
29 #include "rua_private.h"
30 #include "rua_info.h"
31 #include "rua_info_internal.h"
32
33 #define RUA_INFO_START 0
34
35 enum rua_info_e {
36         RUA_INFO_APP_ID = RUA_INFO_START,
37         RUA_INFO_APP_PATH,
38         RUA_INFO_ARGS,
39         RUA_INFO_LAUNCH_TIME,
40         RUA_INFO_INSTANCE_ID,
41         RUA_INFO_INSTANCE_NAME,
42         RUA_INFO_ICON,
43         RUA_INFO_URI,
44         RUA_INFO_IMAGE,
45         RUA_INFO_COMPONENT_ID,
46         RUA_INFO_APP_INFO,
47         RUA_INFO_COMP_INFO,
48         RUA_INFO_MAX,
49 };
50
51 struct rua_info_s {
52         char *value[RUA_INFO_MAX];
53 };
54
55 typedef int (*rua_info_add_cb)(struct rua_rec *rec,
56                 struct rua_info_s *info);
57 typedef void (*rua_info_remove_cb)(void *data);
58 typedef int (*rua_info_clone_cb)(struct rua_info_s *info,
59                 struct rua_info_s *clone);
60
61 typedef struct _rua_info_vft {
62         rua_info_add_cb ctor;
63         rua_info_remove_cb dtor;
64         rua_info_clone_cb clnr;
65 } rua_info_vft;
66
67 static int __rua_info_add_app_id(struct rua_rec *rec,
68                 struct rua_info_s *info)
69 {
70         info->value[RUA_INFO_APP_ID] = strdup(rec->pkg_name);
71         if (!info->value[RUA_INFO_APP_ID]) {
72                 _E("Out of memory");
73                 return RUA_ERROR_OUT_OF_MEMORY;
74         }
75
76         return RUA_ERROR_NONE;
77 }
78
79 static int __rua_info_add_app_path(struct rua_rec *rec,
80                 struct rua_info_s *info)
81 {
82         info->value[RUA_INFO_APP_PATH] = strdup(rec->app_path);
83         if (!info->value[RUA_INFO_APP_PATH]) {
84                 _E("Out of memory");
85                 return RUA_ERROR_OUT_OF_MEMORY;
86         }
87
88         return RUA_ERROR_NONE;
89 }
90
91 static int __rua_info_add_args(struct rua_rec *rec,
92                 struct rua_info_s *info)
93 {
94         info->value[RUA_INFO_ARGS] = strdup(rec->arg);
95         if (!info->value[RUA_INFO_ARGS]) {
96                 _E("Out of memory");
97                 return RUA_ERROR_OUT_OF_MEMORY;
98         }
99
100         return RUA_ERROR_NONE;
101 }
102
103 static int __rua_info_add_launch_time(struct rua_rec *rec,
104                 struct rua_info_s *info)
105 {
106         info->value[RUA_INFO_LAUNCH_TIME] = GINT_TO_POINTER(rec->launch_time);
107
108         return RUA_ERROR_NONE;
109 }
110
111 static int __rua_info_add_instance_id(struct rua_rec *rec,
112                 struct rua_info_s *info)
113 {
114         if (!rec->instance_id)
115                 return RUA_ERROR_NONE;
116
117         info->value[RUA_INFO_INSTANCE_ID] = strdup(rec->instance_id);
118         if (!info->value[RUA_INFO_INSTANCE_ID]) {
119                 _E("Out of memory");
120                 return RUA_ERROR_OUT_OF_MEMORY;
121         }
122
123         return RUA_ERROR_NONE;
124 }
125
126 static int __rua_info_add_instance_name(struct rua_rec *rec,
127                 struct rua_info_s *info)
128 {
129         if (!rec->instance_name)
130                 return RUA_ERROR_NONE;
131
132         info->value[RUA_INFO_INSTANCE_NAME] = strdup(rec->instance_name);
133         if (!info->value[RUA_INFO_INSTANCE_NAME]) {
134                 _E("Out of memory");
135                 return RUA_ERROR_OUT_OF_MEMORY;
136         }
137
138         return RUA_ERROR_NONE;
139 }
140
141 static int __rua_info_add_icon(struct rua_rec *rec, struct rua_info_s *info)
142 {
143         if (!rec->icon)
144                 return RUA_ERROR_NONE;
145
146         info->value[RUA_INFO_ICON] = strdup(rec->icon);
147         if (!info->value[RUA_INFO_ICON]) {
148                 _E("Out of memory");
149                 return RUA_ERROR_OUT_OF_MEMORY;
150         }
151
152         return RUA_ERROR_NONE;
153 }
154
155 static int __rua_info_add_uri(struct rua_rec *rec, struct rua_info_s *info)
156 {
157         if (!rec->uri)
158                 return RUA_ERROR_NONE;
159
160         info->value[RUA_INFO_URI] = strdup(rec->uri);
161         if (!info->value[RUA_INFO_URI]) {
162                 _E("Ouf of memory");
163                 return RUA_ERROR_OUT_OF_MEMORY;
164         }
165
166         return RUA_ERROR_NONE;
167 }
168
169 static int __rua_info_add_image(struct rua_rec *rec, struct rua_info_s *info)
170 {
171         if (!rec->image)
172                 return RUA_ERROR_NONE;
173
174         info->value[RUA_INFO_IMAGE] = strdup(rec->image);
175         if (!info->value[RUA_INFO_IMAGE]) {
176                 _E("Out of memory");
177                 return RUA_ERROR_OUT_OF_MEMORY;
178         }
179
180         return RUA_ERROR_NONE;
181 }
182
183 static int __rua_info_add_component_id(struct rua_rec *rec,
184                 struct rua_info_s *info)
185 {
186         if (!rec->comp_id)
187                 return RUA_ERROR_NONE;
188
189         info->value[RUA_INFO_COMPONENT_ID] = strdup(rec->comp_id);
190         if (!info->value[RUA_INFO_COMPONENT_ID]) {
191                 _E("Out of memory");
192                 return RUA_ERROR_OUT_OF_MEMORY;
193         }
194
195         return RUA_ERROR_NONE;
196 }
197
198 static int __rua_info_add_app_info(struct rua_rec *rec,
199                 struct rua_info_s *info)
200 {
201         pkgmgrinfo_appinfo_h app_info;
202         int ret;
203
204         ret = pkgmgrinfo_appinfo_get_appinfo(rec->pkg_name, &app_info);
205         if (ret != PMINFO_R_OK) {
206                 _E("Failed to get appinfo");
207                 return RUA_ERROR_IO_ERROR;
208         }
209
210         info->value[RUA_INFO_APP_INFO] = app_info;
211
212         return RUA_ERROR_NONE;
213 }
214
215 static int __rua_info_add_comp_info(struct rua_rec *rec,
216                 struct rua_info_s *info)
217 {
218         aul_comp_info_h comp_info;
219         int ret;
220
221         if (!rec->comp_id)
222                 return RUA_ERROR_NONE;
223
224         ret = aul_comp_info_create(rec->comp_id, &comp_info);
225         if (ret != AUL_R_OK) {
226                 _E("Failed to create comp info");
227                 return RUA_ERROR_IO_ERROR;
228         }
229
230         info->value[RUA_INFO_COMP_INFO] = comp_info;
231
232         return RUA_ERROR_NONE;
233 }
234
235 static void __rua_info_remove_app_info(void *data)
236 {
237         pkgmgrinfo_appinfo_h app_info;
238
239         app_info = (pkgmgrinfo_appinfo_h)data;
240         pkgmgrinfo_appinfo_destroy_appinfo(app_info);
241 }
242
243 static void __rua_info_remove_comp_info(void *data)
244 {
245         aul_comp_info_h comp_info;
246
247         comp_info = (aul_comp_info_h)data;
248         aul_comp_info_destroy(comp_info);
249 }
250
251 static int __rua_info_clone_app_id(struct rua_info_s *info,
252                 struct rua_info_s *clone)
253 {
254         clone->value[RUA_INFO_APP_ID] = strdup(info->value[RUA_INFO_APP_ID]);
255         if (!clone->value[RUA_INFO_APP_ID]) {
256                 _E("Out of memory");
257                 return RUA_ERROR_OUT_OF_MEMORY;
258         }
259
260         return RUA_ERROR_NONE;
261 }
262
263 static int __rua_info_clone_app_path(struct rua_info_s *info,
264                 struct rua_info_s *clone)
265 {
266         clone->value[RUA_INFO_APP_PATH] =
267                 strdup(info->value[RUA_INFO_APP_PATH]);
268         if (!clone->value[RUA_INFO_APP_PATH]) {
269                 _E("Out of memory");
270                 return RUA_ERROR_OUT_OF_MEMORY;
271         }
272
273         return RUA_ERROR_NONE;
274 }
275
276 static int __rua_info_clone_args(struct rua_info_s *info,
277                 struct rua_info_s *clone)
278 {
279         clone->value[RUA_INFO_ARGS] = strdup(info->value[RUA_INFO_ARGS]);
280         if (!clone->value[RUA_INFO_ARGS]) {
281                 _E("Out of memory");
282                 return RUA_ERROR_OUT_OF_MEMORY;
283         }
284
285         return RUA_ERROR_NONE;
286 }
287
288 static int __rua_info_clone_launch_time(struct rua_info_s *info,
289                 struct rua_info_s *clone)
290 {
291         clone->value[RUA_INFO_LAUNCH_TIME] = info->value[RUA_INFO_LAUNCH_TIME];
292
293         return RUA_ERROR_NONE;
294 }
295
296 static int __rua_info_clone_instance_id(struct rua_info_s *info,
297                 struct rua_info_s *clone)
298 {
299         if (!info->value[RUA_INFO_INSTANCE_ID])
300                 return RUA_ERROR_NONE;
301
302         clone->value[RUA_INFO_INSTANCE_ID] =
303                 strdup(info->value[RUA_INFO_INSTANCE_ID]);
304         if (!clone->value[RUA_INFO_INSTANCE_ID]) {
305                 _E("Out of memory");
306                 return RUA_ERROR_OUT_OF_MEMORY;
307         }
308
309         return RUA_ERROR_NONE;
310 }
311
312 static int __rua_info_clone_instance_name(struct rua_info_s *info,
313                 struct rua_info_s *clone)
314 {
315         if (!info->value[RUA_INFO_INSTANCE_NAME])
316                 return RUA_ERROR_NONE;
317
318         clone->value[RUA_INFO_INSTANCE_NAME] =
319                 strdup(info->value[RUA_INFO_INSTANCE_NAME]);
320         if (!clone->value[RUA_INFO_INSTANCE_NAME]) {
321                 _E("Out of memory");
322                 return RUA_ERROR_OUT_OF_MEMORY;
323         }
324
325         return RUA_ERROR_NONE;
326 }
327
328 static int __rua_info_clone_icon(struct rua_info_s *info,
329                 struct rua_info_s *clone)
330 {
331         if (!info->value[RUA_INFO_ICON])
332                 return RUA_ERROR_NONE;
333
334         clone->value[RUA_INFO_ICON] = strdup(info->value[RUA_INFO_ICON]);
335         if (!clone->value[RUA_INFO_ICON]) {
336                 _E("Out of memory");
337                 return RUA_ERROR_OUT_OF_MEMORY;
338         }
339
340         return RUA_ERROR_NONE;
341 }
342
343 static int __rua_info_clone_uri(struct rua_info_s *info,
344                 struct rua_info_s *clone)
345 {
346         if (!info->value[RUA_INFO_URI])
347                 return RUA_ERROR_NONE;
348
349         clone->value[RUA_INFO_URI] = strdup(info->value[RUA_INFO_URI]);
350         if (!clone->value[RUA_INFO_URI]) {
351                 _E("Out of memory");
352                 return RUA_ERROR_OUT_OF_MEMORY;
353         }
354
355         return RUA_ERROR_NONE;
356 }
357
358 static int __rua_info_clone_image(struct rua_info_s *info,
359                 struct rua_info_s *clone)
360 {
361         if (!info->value[RUA_INFO_IMAGE])
362                 return RUA_ERROR_NONE;
363
364         clone->value[RUA_INFO_IMAGE] = strdup(info->value[RUA_INFO_IMAGE]);
365         if (!clone->value[RUA_INFO_IMAGE]) {
366                 _E("Out of memory");
367                 return RUA_ERROR_OUT_OF_MEMORY;
368         }
369
370         return RUA_ERROR_NONE;
371 }
372
373 static int __rua_info_clone_component_id(struct rua_info_s *info,
374                 struct rua_info_s *clone)
375 {
376         if (!info->value[RUA_INFO_COMPONENT_ID])
377                 return RUA_ERROR_NONE;
378
379         clone->value[RUA_INFO_COMPONENT_ID] =
380                 strdup(info->value[RUA_INFO_COMPONENT_ID]);
381         if (!clone->value[RUA_INFO_COMPONENT_ID]) {
382                 _E("Out of memory");
383                 return RUA_ERROR_OUT_OF_MEMORY;
384         }
385
386         return RUA_ERROR_NONE;
387 }
388
389 static int __rua_info_clone_app_info(struct rua_info_s *info,
390                 struct rua_info_s *clone)
391 {
392         pkgmgrinfo_appinfo_h app_info;
393         int ret;
394
395         ret = pkgmgrinfo_appinfo_clone_appinfo(
396                         info->value[RUA_INFO_APP_INFO],
397                         &app_info);
398         if (ret != RUA_ERROR_NONE) {
399                 _E("Failed to clone app info");
400                 return RUA_ERROR_OUT_OF_MEMORY;
401         }
402
403         clone->value[RUA_INFO_APP_INFO] = app_info;
404
405         return RUA_ERROR_NONE;
406 }
407
408 static int __rua_info_clone_comp_info(struct rua_info_s *info,
409                 struct rua_info_s *clone)
410 {
411         aul_comp_info_h comp_info;
412         int ret;
413
414         if (!info->value[RUA_INFO_COMP_INFO])
415                 return RUA_ERROR_NONE;
416
417         ret = aul_comp_info_clone(info->value[RUA_INFO_COMP_INFO],
418                         &comp_info);
419         if (ret != RUA_ERROR_NONE) {
420                 _E("Failed to clone comp info");
421                 return RUA_ERROR_OUT_OF_MEMORY;
422         }
423
424         clone->value[RUA_INFO_COMP_INFO] = comp_info;
425
426         return RUA_ERROR_NONE;
427 }
428
429 static rua_info_vft __rua_table[] = {
430         [RUA_INFO_APP_ID] = {
431                 .ctor = __rua_info_add_app_id,
432                 .dtor = free,
433                 .clnr = __rua_info_clone_app_id
434         },
435         [RUA_INFO_APP_PATH] = {
436                 .ctor = __rua_info_add_app_path,
437                 .dtor = free,
438                 .clnr = __rua_info_clone_app_path
439         },
440         [RUA_INFO_ARGS] = {
441                 .ctor = __rua_info_add_args,
442                 .dtor = free,
443                 .clnr = __rua_info_clone_args
444         },
445         [RUA_INFO_LAUNCH_TIME] = {
446                 .ctor = __rua_info_add_launch_time,
447                 .dtor = NULL,
448                 .clnr = __rua_info_clone_launch_time
449         },
450         [RUA_INFO_INSTANCE_ID] = {
451                 .ctor = __rua_info_add_instance_id,
452                 .dtor = free,
453                 .clnr = __rua_info_clone_instance_id
454         },
455         [RUA_INFO_INSTANCE_NAME] = {
456                 .ctor = __rua_info_add_instance_name,
457                 .dtor = free,
458                 .clnr = __rua_info_clone_instance_name
459         },
460         [RUA_INFO_ICON] = {
461                 .ctor = __rua_info_add_icon,
462                 .dtor = free,
463                 .clnr = __rua_info_clone_icon
464         },
465         [RUA_INFO_URI] = {
466                 .ctor = __rua_info_add_uri,
467                 .dtor = free,
468                 .clnr = __rua_info_clone_uri
469         },
470         [RUA_INFO_IMAGE] = {
471                 .ctor = __rua_info_add_image,
472                 .dtor = free,
473                 .clnr = __rua_info_clone_image
474         },
475         [RUA_INFO_COMPONENT_ID] = {
476                 .ctor = __rua_info_add_component_id,
477                 .dtor = free,
478                 .clnr = __rua_info_clone_component_id
479         },
480         [RUA_INFO_APP_INFO] = {
481                 .ctor = __rua_info_add_app_info,
482                 .dtor = __rua_info_remove_app_info,
483                 .clnr = __rua_info_clone_app_info
484         },
485         [RUA_INFO_COMP_INFO] = {
486                 .ctor = __rua_info_add_comp_info,
487                 .dtor = __rua_info_remove_comp_info,
488                 .clnr = __rua_info_clone_comp_info
489         },
490 };
491
492 static void __destroy_rua_info(gpointer data)
493 {
494         struct rua_info_s *info = (struct rua_info_s *)data;
495         int i;
496
497         if (!info)
498                 return;
499
500         for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) {
501                 if (!__rua_table[i].dtor)
502                         continue;
503
504                 __rua_table[i].dtor(info->value[i]);
505         }
506
507         free(info);
508 }
509
510 static struct rua_info_s *__create_rua_info(struct rua_rec *rec)
511 {
512         struct rua_info_s *info;
513         int ret;
514         int i;
515
516         info = calloc(1, sizeof(struct rua_info_s));
517         if (!info) {
518                 _E("Out of memory");
519                 return NULL;
520         }
521
522         for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) {
523                 if (!__rua_table[i].ctor)
524                         continue;
525
526                 ret = __rua_table[i].ctor(rec, info);
527                 if (ret != RUA_ERROR_NONE) {
528                         __destroy_rua_info(info);
529                         return NULL;
530                 }
531         }
532
533         return info;
534 }
535
536 static struct rua_info_s *__clone_rua_info(struct rua_info_s *info)
537 {
538         struct rua_info_s *clone;
539         int ret;
540         int i;
541
542         clone = calloc(1, sizeof(struct rua_info_s));
543         if (!clone) {
544                 _E("Out of memory");
545                 return NULL;
546         }
547
548         for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) {
549                 if (!__rua_table[i].clnr)
550                         continue;
551
552                 ret = __rua_table[i].clnr(info, clone);
553                 if (ret != RUA_ERROR_NONE) {
554                         __destroy_rua_info(clone);
555                         return NULL;
556                 }
557         }
558
559         return clone;
560 }
561
562 int rua_info_foreach(rua_manager_rua_info_cb callback, void *user_data)
563 {
564         return rua_info_usr_foreach(getuid(), callback, user_data);
565 }
566
567 int rua_info_usr_foreach(uid_t uid, rua_manager_rua_info_cb callback,
568                 void *user_data)
569 {
570         struct rua_info_s *info;
571         struct rua_rec rec;
572         GList *list = NULL;
573         GList *iter;
574         char **table = NULL;
575         int nrows = 0;
576         int ncols = 0;
577         int row;
578         int ret;
579
580         if (!callback) {
581                 _E("Invalid parameter");
582                 return RUA_ERROR_INVALID_PARAMETER;
583         }
584
585         ret = rua_history_load_db_for_uid(&table, &nrows, &ncols, uid);
586         if (ret < 0) {
587                 _E("Failed to load rua history");
588                 return RUA_ERROR_IO_ERROR;
589         }
590
591         for (row = 0; row < nrows; ++row) {
592                 rua_history_get_rec(&rec, table, nrows, ncols, row);
593                 info = __create_rua_info(&rec);
594                 if (!info) {
595                         rua_history_unload_db(&table);
596                         g_list_free_full(list, __destroy_rua_info);
597                         return RUA_ERROR_OUT_OF_MEMORY;
598                 }
599
600                 list = g_list_append(list, info);
601         }
602
603         rua_history_unload_db(&table);
604
605         iter = list;
606         while (iter) {
607                 info = (struct rua_info_s *)iter->data;
608                 if (!callback(info, user_data))
609                         break;
610
611                 iter = g_list_next(iter);
612         }
613
614         g_list_free_full(list, __destroy_rua_info);
615
616         return RUA_ERROR_NONE;
617 }
618
619 API int rua_info_get_app_id(rua_info_h info, char **app_id)
620 {
621         if (!info || !app_id) {
622                 _E("Invalid parameter");
623                 return RUA_ERROR_INVALID_PARAMETER;
624         }
625
626         *app_id = strdup(info->value[RUA_INFO_APP_ID]);
627         if (*app_id == NULL) {
628                 _E("Out of memory");
629                 return RUA_ERROR_OUT_OF_MEMORY;
630         }
631
632         return RUA_ERROR_NONE;
633 }
634
635 API int rua_info_get_app_path(rua_info_h info, char **app_path)
636 {
637         if (!info || !app_path) {
638                 _E("Invalid parameter");
639                 return RUA_ERROR_INVALID_PARAMETER;
640         }
641
642         *app_path = strdup(info->value[RUA_INFO_APP_PATH]);
643         if (*app_path == NULL) {
644                 _E("Out of memory");
645                 return RUA_ERROR_OUT_OF_MEMORY;
646         }
647
648         return RUA_ERROR_NONE;
649 }
650
651 API int rua_info_get_args(rua_info_h info, char **args)
652 {
653         if (!info || !args) {
654                 _E("Invalid parameter");
655                 return RUA_ERROR_INVALID_PARAMETER;
656         }
657
658         *args = strdup(info->value[RUA_INFO_ARGS]);
659         if (*args == NULL) {
660                 _E("Out of memory");
661                 return RUA_ERROR_OUT_OF_MEMORY;
662         }
663
664         return RUA_ERROR_NONE;
665 }
666
667 API int rua_info_get_launch_time(rua_info_h info, time_t *launch_time)
668 {
669         if (!info || !launch_time) {
670                 _E("Invalid parameter");
671                 return RUA_ERROR_INVALID_PARAMETER;
672         }
673
674         *launch_time = GPOINTER_TO_INT(info->value[RUA_INFO_LAUNCH_TIME]);
675
676         return RUA_ERROR_NONE;
677 }
678
679 API int rua_info_get_instance_id(rua_info_h info, char **instance_id)
680 {
681         if (!info || !instance_id) {
682                 _E("Invalid parameter");
683                 return RUA_ERROR_INVALID_PARAMETER;
684         }
685
686         if (info->value[RUA_INFO_INSTANCE_ID]) {
687                 *instance_id = strdup(info->value[RUA_INFO_INSTANCE_ID]);
688                 if (*instance_id == NULL) {
689                         _E("Out of memory");
690                         return RUA_ERROR_OUT_OF_MEMORY;
691                 }
692         } else {
693                 *instance_id = NULL;
694         }
695
696         return RUA_ERROR_NONE;
697 }
698
699 API int rua_info_get_instance_name(rua_info_h info, char **instance_name)
700 {
701         if (!info || !instance_name) {
702                 _E("Invalid parameter");
703                 return RUA_ERROR_INVALID_PARAMETER;
704         }
705
706         if (info->value[RUA_INFO_INSTANCE_NAME]) {
707                 *instance_name = strdup(info->value[RUA_INFO_INSTANCE_NAME]);
708                 if (*instance_name == NULL) {
709                         _E("Out of memory");
710                         return RUA_ERROR_OUT_OF_MEMORY;
711                 }
712         } else {
713                 *instance_name = NULL;
714         }
715
716         return RUA_ERROR_NONE;
717 }
718
719 static char *__get_icon(rua_info_h info)
720 {
721         pkgmgrinfo_appinfo_h app_info;
722         aul_comp_info_h comp_info;
723         char *icon;
724         int ret;
725
726         if (info->value[RUA_INFO_COMP_INFO]) {
727                 comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO];
728                 ret = aul_comp_info_get_icon(comp_info, (const char **)&icon);
729                 if (ret != AUL_R_OK) {
730                         _E("Failed to get icon");
731                         return NULL;
732                 }
733         } else {
734                 app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO];
735                 ret = pkgmgrinfo_appinfo_get_icon(app_info, &icon);
736                 if (ret != PMINFO_R_OK) {
737                         _E("Failed to get icon");
738                         return NULL;
739                 }
740         }
741
742         if (icon && icon[0] != '\0')
743                 return strdup(icon);
744
745         return NULL;
746 }
747
748 API int rua_info_get_icon(rua_info_h info, char **icon)
749 {
750         if (!info || !icon) {
751                 _E("Invalid parameter");
752                 return RUA_ERROR_INVALID_PARAMETER;
753         }
754
755         if (info->value[RUA_INFO_ICON]) {
756                 *icon = strdup(info->value[RUA_INFO_ICON]);
757                 if (*icon == NULL) {
758                         _E("Out of memory");
759                         return RUA_ERROR_OUT_OF_MEMORY;
760                 }
761         } else {
762                 *icon = __get_icon(info);
763         }
764
765         return RUA_ERROR_NONE;
766 }
767
768 API int rua_info_get_uri(rua_info_h info, char **uri)
769 {
770         if (!info || !uri) {
771                 _E("Invalid parameter");
772                 return RUA_ERROR_INVALID_PARAMETER;
773         }
774
775         if (info->value[RUA_INFO_URI]) {
776                 *uri = info->value[RUA_INFO_URI];
777                 if (*uri == NULL) {
778                         _E("Out of memory");
779                         return RUA_ERROR_OUT_OF_MEMORY;
780                 }
781         } else {
782                 *uri = NULL;
783         }
784
785         return RUA_ERROR_NONE;
786 }
787
788 API int rua_info_get_image(rua_info_h info, char **image)
789 {
790         if (!info || !image) {
791                 _E("Invalid parameter");
792                 return RUA_ERROR_INVALID_PARAMETER;
793         }
794
795         if (info->value[RUA_INFO_IMAGE]) {
796                 *image = info->value[RUA_INFO_IMAGE];
797                 if (*image == NULL) {
798                         _E("Out of memory");
799                         return RUA_ERROR_OUT_OF_MEMORY;
800                 }
801         } else {
802                 *image = NULL;
803         }
804
805         return RUA_ERROR_NONE;
806 }
807
808 API int rua_info_get_component_id(rua_info_h info, char **component_id)
809 {
810         if (!info || !component_id) {
811                 _E("Invalid parameter");
812                 return RUA_ERROR_INVALID_PARAMETER;
813         }
814
815         if (info->value[RUA_INFO_COMPONENT_ID]) {
816                 *component_id = info->value[RUA_INFO_COMPONENT_ID];
817                 if (*component_id == NULL) {
818                         _E("Out of memory");
819                         return RUA_ERROR_OUT_OF_MEMORY;
820                 }
821         } else {
822                 *component_id = NULL;
823         }
824
825         return RUA_ERROR_NONE;
826 }
827
828
829 API int rua_info_is_managed_by_task_manager(rua_info_h info, bool *managed)
830 {
831         pkgmgrinfo_appinfo_h app_info;
832         aul_comp_info_h comp_info;
833         int ret;
834
835         if (!info || !managed) {
836                 _E("Invalid parameter");
837                 return RUA_ERROR_INVALID_PARAMETER;
838         }
839
840         if (info->value[RUA_INFO_COMP_INFO]) {
841                 comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO];
842                 ret = aul_comp_info_is_taskmanage(comp_info, managed);
843                 if (ret != AUL_R_OK) {
844                         _E("Failed to check taskmanage");
845                         return RUA_ERROR_INVALID_PARAMETER;
846                 }
847         } else {
848                 app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO];
849                 ret = pkgmgrinfo_appinfo_is_taskmanage(app_info, managed);
850                 if (ret != PMINFO_R_OK) {
851                         _E("Failed to check taskmanage");
852                         return RUA_ERROR_INVALID_PARAMETER;
853                 }
854         }
855
856         return RUA_ERROR_NONE;
857 }
858
859 static char *__get_label(rua_info_h info)
860 {
861         pkgmgrinfo_appinfo_h app_info;
862         aul_comp_info_h comp_info;
863         char *label;
864         int ret;
865
866         if (info->value[RUA_INFO_COMP_INFO]) {
867                 comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO];
868                 ret = aul_comp_info_get_label(comp_info, (const char **)&label);
869                 if (ret != AUL_R_OK) {
870                         _E("Failed to get label");
871                         return NULL;
872                 }
873         } else {
874                 app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO];
875                 ret = pkgmgrinfo_appinfo_get_label(app_info, &label);
876                 if (ret != PMINFO_R_OK) {
877                         _E("Failed to get label");
878                         return NULL;
879                 }
880         }
881
882         if (label && label[0] != '\0')
883                 return strdup(label);
884
885         return NULL;
886 }
887
888 API int rua_info_get_label(rua_info_h info, char **label)
889 {
890         if (!info || !label) {
891                 _E("Invalid parameter");
892                 return RUA_ERROR_INVALID_PARAMETER;
893         }
894
895         *label = __get_label(info);
896
897         return RUA_ERROR_NONE;
898 }
899
900 API int rua_info_destroy(rua_info_h info)
901 {
902         if (!info) {
903                 _E("Invalid parameter");
904                 return RUA_ERROR_INVALID_PARAMETER;
905         }
906
907         __destroy_rua_info(info);
908
909         return RUA_ERROR_NONE;
910 }
911
912 API int rua_info_clone(rua_info_h info, rua_info_h *clone)
913 {
914         if (!info || !clone) {
915                 _E("Invalid parameter");
916                 return RUA_ERROR_INVALID_PARAMETER;
917         }
918
919         *clone = __clone_rua_info(info);
920         if (*clone == NULL) {
921                 _E("Failed to clone rua info");
922                 return RUA_ERROR_OUT_OF_MEMORY;
923         }
924
925         return RUA_ERROR_NONE;
926 }