Release version 0.5.10
[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         if (!data)
248                 return;
249
250         comp_info = (aul_comp_info_h)data;
251         aul_comp_info_destroy(comp_info);
252 }
253
254 static int __rua_info_clone_app_id(struct rua_info_s *info,
255                 struct rua_info_s *clone)
256 {
257         clone->value[RUA_INFO_APP_ID] = strdup(info->value[RUA_INFO_APP_ID]);
258         if (!clone->value[RUA_INFO_APP_ID]) {
259                 _E("Out of memory");
260                 return RUA_ERROR_OUT_OF_MEMORY;
261         }
262
263         return RUA_ERROR_NONE;
264 }
265
266 static int __rua_info_clone_app_path(struct rua_info_s *info,
267                 struct rua_info_s *clone)
268 {
269         clone->value[RUA_INFO_APP_PATH] =
270                 strdup(info->value[RUA_INFO_APP_PATH]);
271         if (!clone->value[RUA_INFO_APP_PATH]) {
272                 _E("Out of memory");
273                 return RUA_ERROR_OUT_OF_MEMORY;
274         }
275
276         return RUA_ERROR_NONE;
277 }
278
279 static int __rua_info_clone_args(struct rua_info_s *info,
280                 struct rua_info_s *clone)
281 {
282         clone->value[RUA_INFO_ARGS] = strdup(info->value[RUA_INFO_ARGS]);
283         if (!clone->value[RUA_INFO_ARGS]) {
284                 _E("Out of memory");
285                 return RUA_ERROR_OUT_OF_MEMORY;
286         }
287
288         return RUA_ERROR_NONE;
289 }
290
291 static int __rua_info_clone_launch_time(struct rua_info_s *info,
292                 struct rua_info_s *clone)
293 {
294         clone->value[RUA_INFO_LAUNCH_TIME] = info->value[RUA_INFO_LAUNCH_TIME];
295
296         return RUA_ERROR_NONE;
297 }
298
299 static int __rua_info_clone_instance_id(struct rua_info_s *info,
300                 struct rua_info_s *clone)
301 {
302         if (!info->value[RUA_INFO_INSTANCE_ID])
303                 return RUA_ERROR_NONE;
304
305         clone->value[RUA_INFO_INSTANCE_ID] =
306                 strdup(info->value[RUA_INFO_INSTANCE_ID]);
307         if (!clone->value[RUA_INFO_INSTANCE_ID]) {
308                 _E("Out of memory");
309                 return RUA_ERROR_OUT_OF_MEMORY;
310         }
311
312         return RUA_ERROR_NONE;
313 }
314
315 static int __rua_info_clone_instance_name(struct rua_info_s *info,
316                 struct rua_info_s *clone)
317 {
318         if (!info->value[RUA_INFO_INSTANCE_NAME])
319                 return RUA_ERROR_NONE;
320
321         clone->value[RUA_INFO_INSTANCE_NAME] =
322                 strdup(info->value[RUA_INFO_INSTANCE_NAME]);
323         if (!clone->value[RUA_INFO_INSTANCE_NAME]) {
324                 _E("Out of memory");
325                 return RUA_ERROR_OUT_OF_MEMORY;
326         }
327
328         return RUA_ERROR_NONE;
329 }
330
331 static int __rua_info_clone_icon(struct rua_info_s *info,
332                 struct rua_info_s *clone)
333 {
334         if (!info->value[RUA_INFO_ICON])
335                 return RUA_ERROR_NONE;
336
337         clone->value[RUA_INFO_ICON] = strdup(info->value[RUA_INFO_ICON]);
338         if (!clone->value[RUA_INFO_ICON]) {
339                 _E("Out of memory");
340                 return RUA_ERROR_OUT_OF_MEMORY;
341         }
342
343         return RUA_ERROR_NONE;
344 }
345
346 static int __rua_info_clone_uri(struct rua_info_s *info,
347                 struct rua_info_s *clone)
348 {
349         if (!info->value[RUA_INFO_URI])
350                 return RUA_ERROR_NONE;
351
352         clone->value[RUA_INFO_URI] = strdup(info->value[RUA_INFO_URI]);
353         if (!clone->value[RUA_INFO_URI]) {
354                 _E("Out of memory");
355                 return RUA_ERROR_OUT_OF_MEMORY;
356         }
357
358         return RUA_ERROR_NONE;
359 }
360
361 static int __rua_info_clone_image(struct rua_info_s *info,
362                 struct rua_info_s *clone)
363 {
364         if (!info->value[RUA_INFO_IMAGE])
365                 return RUA_ERROR_NONE;
366
367         clone->value[RUA_INFO_IMAGE] = strdup(info->value[RUA_INFO_IMAGE]);
368         if (!clone->value[RUA_INFO_IMAGE]) {
369                 _E("Out of memory");
370                 return RUA_ERROR_OUT_OF_MEMORY;
371         }
372
373         return RUA_ERROR_NONE;
374 }
375
376 static int __rua_info_clone_component_id(struct rua_info_s *info,
377                 struct rua_info_s *clone)
378 {
379         if (!info->value[RUA_INFO_COMPONENT_ID])
380                 return RUA_ERROR_NONE;
381
382         clone->value[RUA_INFO_COMPONENT_ID] =
383                 strdup(info->value[RUA_INFO_COMPONENT_ID]);
384         if (!clone->value[RUA_INFO_COMPONENT_ID]) {
385                 _E("Out of memory");
386                 return RUA_ERROR_OUT_OF_MEMORY;
387         }
388
389         return RUA_ERROR_NONE;
390 }
391
392 static int __rua_info_clone_app_info(struct rua_info_s *info,
393                 struct rua_info_s *clone)
394 {
395         pkgmgrinfo_appinfo_h app_info;
396         int ret;
397
398         ret = pkgmgrinfo_appinfo_clone_appinfo(
399                         info->value[RUA_INFO_APP_INFO],
400                         &app_info);
401         if (ret != RUA_ERROR_NONE) {
402                 _E("Failed to clone app info");
403                 return RUA_ERROR_OUT_OF_MEMORY;
404         }
405
406         clone->value[RUA_INFO_APP_INFO] = app_info;
407
408         return RUA_ERROR_NONE;
409 }
410
411 static int __rua_info_clone_comp_info(struct rua_info_s *info,
412                 struct rua_info_s *clone)
413 {
414         aul_comp_info_h comp_info;
415         int ret;
416
417         if (!info->value[RUA_INFO_COMP_INFO])
418                 return RUA_ERROR_NONE;
419
420         ret = aul_comp_info_clone(info->value[RUA_INFO_COMP_INFO],
421                         &comp_info);
422         if (ret != RUA_ERROR_NONE) {
423                 _E("Failed to clone comp info");
424                 return RUA_ERROR_OUT_OF_MEMORY;
425         }
426
427         clone->value[RUA_INFO_COMP_INFO] = comp_info;
428
429         return RUA_ERROR_NONE;
430 }
431
432 static rua_info_vft __rua_table[] = {
433         [RUA_INFO_APP_ID] = {
434                 .ctor = __rua_info_add_app_id,
435                 .dtor = free,
436                 .clnr = __rua_info_clone_app_id
437         },
438         [RUA_INFO_APP_PATH] = {
439                 .ctor = __rua_info_add_app_path,
440                 .dtor = free,
441                 .clnr = __rua_info_clone_app_path
442         },
443         [RUA_INFO_ARGS] = {
444                 .ctor = __rua_info_add_args,
445                 .dtor = free,
446                 .clnr = __rua_info_clone_args
447         },
448         [RUA_INFO_LAUNCH_TIME] = {
449                 .ctor = __rua_info_add_launch_time,
450                 .dtor = NULL,
451                 .clnr = __rua_info_clone_launch_time
452         },
453         [RUA_INFO_INSTANCE_ID] = {
454                 .ctor = __rua_info_add_instance_id,
455                 .dtor = free,
456                 .clnr = __rua_info_clone_instance_id
457         },
458         [RUA_INFO_INSTANCE_NAME] = {
459                 .ctor = __rua_info_add_instance_name,
460                 .dtor = free,
461                 .clnr = __rua_info_clone_instance_name
462         },
463         [RUA_INFO_ICON] = {
464                 .ctor = __rua_info_add_icon,
465                 .dtor = free,
466                 .clnr = __rua_info_clone_icon
467         },
468         [RUA_INFO_URI] = {
469                 .ctor = __rua_info_add_uri,
470                 .dtor = free,
471                 .clnr = __rua_info_clone_uri
472         },
473         [RUA_INFO_IMAGE] = {
474                 .ctor = __rua_info_add_image,
475                 .dtor = free,
476                 .clnr = __rua_info_clone_image
477         },
478         [RUA_INFO_COMPONENT_ID] = {
479                 .ctor = __rua_info_add_component_id,
480                 .dtor = free,
481                 .clnr = __rua_info_clone_component_id
482         },
483         [RUA_INFO_APP_INFO] = {
484                 .ctor = __rua_info_add_app_info,
485                 .dtor = __rua_info_remove_app_info,
486                 .clnr = __rua_info_clone_app_info
487         },
488         [RUA_INFO_COMP_INFO] = {
489                 .ctor = __rua_info_add_comp_info,
490                 .dtor = __rua_info_remove_comp_info,
491                 .clnr = __rua_info_clone_comp_info
492         },
493 };
494
495 static void __destroy_rua_info(gpointer data)
496 {
497         struct rua_info_s *info = (struct rua_info_s *)data;
498         int i;
499
500         if (!info)
501                 return;
502
503         for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) {
504                 if (!__rua_table[i].dtor)
505                         continue;
506
507                 __rua_table[i].dtor(info->value[i]);
508         }
509
510         free(info);
511 }
512
513 static struct rua_info_s *__create_rua_info(struct rua_rec *rec)
514 {
515         struct rua_info_s *info;
516         int ret;
517         int i;
518
519         info = calloc(1, sizeof(struct rua_info_s));
520         if (!info) {
521                 _E("Out of memory");
522                 return NULL;
523         }
524
525         for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) {
526                 if (!__rua_table[i].ctor)
527                         continue;
528
529                 ret = __rua_table[i].ctor(rec, info);
530                 if (ret != RUA_ERROR_NONE) {
531                         __destroy_rua_info(info);
532                         return NULL;
533                 }
534         }
535
536         return info;
537 }
538
539 static struct rua_info_s *__clone_rua_info(struct rua_info_s *info)
540 {
541         struct rua_info_s *clone;
542         int ret;
543         int i;
544
545         clone = calloc(1, sizeof(struct rua_info_s));
546         if (!clone) {
547                 _E("Out of memory");
548                 return NULL;
549         }
550
551         for (i = RUA_INFO_START; i < RUA_INFO_MAX; ++i) {
552                 if (!__rua_table[i].clnr)
553                         continue;
554
555                 ret = __rua_table[i].clnr(info, clone);
556                 if (ret != RUA_ERROR_NONE) {
557                         __destroy_rua_info(clone);
558                         return NULL;
559                 }
560         }
561
562         return clone;
563 }
564
565 int rua_info_foreach(rua_manager_rua_info_cb callback, void *user_data)
566 {
567         return rua_info_usr_foreach(getuid(), callback, user_data);
568 }
569
570 int rua_info_usr_foreach(uid_t uid, rua_manager_rua_info_cb callback,
571                 void *user_data)
572 {
573         struct rua_info_s *info;
574         struct rua_rec rec;
575         GList *list = NULL;
576         GList *iter;
577         char **table = NULL;
578         int nrows = 0;
579         int ncols = 0;
580         int row;
581         int ret;
582
583         if (!callback) {
584                 _E("Invalid parameter");
585                 return RUA_ERROR_INVALID_PARAMETER;
586         }
587
588         ret = rua_history_load_db_for_uid(&table, &nrows, &ncols, uid);
589         if (ret < 0) {
590                 _E("Failed to load rua history");
591                 return RUA_ERROR_IO_ERROR;
592         }
593
594         for (row = 0; row < nrows; ++row) {
595                 rua_history_get_rec(&rec, table, nrows, ncols, row);
596                 info = __create_rua_info(&rec);
597                 if (info)
598                         list = g_list_append(list, info);
599         }
600
601         rua_history_unload_db(&table);
602
603         iter = list;
604         while (iter) {
605                 info = (struct rua_info_s *)iter->data;
606                 if (!callback(info, user_data))
607                         break;
608
609                 iter = g_list_next(iter);
610         }
611
612         g_list_free_full(list, __destroy_rua_info);
613
614         return RUA_ERROR_NONE;
615 }
616
617 API int rua_info_get_app_id(rua_info_h info, char **app_id)
618 {
619         if (!info || !app_id) {
620                 _E("Invalid parameter");
621                 return RUA_ERROR_INVALID_PARAMETER;
622         }
623
624         *app_id = strdup(info->value[RUA_INFO_APP_ID]);
625         if (*app_id == NULL) {
626                 _E("Out of memory");
627                 return RUA_ERROR_OUT_OF_MEMORY;
628         }
629
630         return RUA_ERROR_NONE;
631 }
632
633 API int rua_info_get_app_path(rua_info_h info, char **app_path)
634 {
635         if (!info || !app_path) {
636                 _E("Invalid parameter");
637                 return RUA_ERROR_INVALID_PARAMETER;
638         }
639
640         *app_path = strdup(info->value[RUA_INFO_APP_PATH]);
641         if (*app_path == NULL) {
642                 _E("Out of memory");
643                 return RUA_ERROR_OUT_OF_MEMORY;
644         }
645
646         return RUA_ERROR_NONE;
647 }
648
649 API int rua_info_get_args(rua_info_h info, char **args)
650 {
651         if (!info || !args) {
652                 _E("Invalid parameter");
653                 return RUA_ERROR_INVALID_PARAMETER;
654         }
655
656         *args = strdup(info->value[RUA_INFO_ARGS]);
657         if (*args == NULL) {
658                 _E("Out of memory");
659                 return RUA_ERROR_OUT_OF_MEMORY;
660         }
661
662         return RUA_ERROR_NONE;
663 }
664
665 API int rua_info_get_launch_time(rua_info_h info, time_t *launch_time)
666 {
667         if (!info || !launch_time) {
668                 _E("Invalid parameter");
669                 return RUA_ERROR_INVALID_PARAMETER;
670         }
671
672         *launch_time = GPOINTER_TO_INT(info->value[RUA_INFO_LAUNCH_TIME]);
673
674         return RUA_ERROR_NONE;
675 }
676
677 API int rua_info_get_instance_id(rua_info_h info, char **instance_id)
678 {
679         if (!info || !instance_id) {
680                 _E("Invalid parameter");
681                 return RUA_ERROR_INVALID_PARAMETER;
682         }
683
684         if (info->value[RUA_INFO_INSTANCE_ID]) {
685                 *instance_id = strdup(info->value[RUA_INFO_INSTANCE_ID]);
686                 if (*instance_id == NULL) {
687                         _E("Out of memory");
688                         return RUA_ERROR_OUT_OF_MEMORY;
689                 }
690         } else {
691                 *instance_id = NULL;
692         }
693
694         return RUA_ERROR_NONE;
695 }
696
697 API int rua_info_get_instance_name(rua_info_h info, char **instance_name)
698 {
699         if (!info || !instance_name) {
700                 _E("Invalid parameter");
701                 return RUA_ERROR_INVALID_PARAMETER;
702         }
703
704         if (info->value[RUA_INFO_INSTANCE_NAME]) {
705                 *instance_name = strdup(info->value[RUA_INFO_INSTANCE_NAME]);
706                 if (*instance_name == NULL) {
707                         _E("Out of memory");
708                         return RUA_ERROR_OUT_OF_MEMORY;
709                 }
710         } else {
711                 *instance_name = NULL;
712         }
713
714         return RUA_ERROR_NONE;
715 }
716
717 static char *__get_icon(rua_info_h info)
718 {
719         pkgmgrinfo_appinfo_h app_info;
720         aul_comp_info_h comp_info;
721         char *icon;
722         int ret;
723
724         if (info->value[RUA_INFO_COMP_INFO]) {
725                 comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO];
726                 ret = aul_comp_info_get_icon(comp_info, (const char **)&icon);
727                 if (ret != AUL_R_OK) {
728                         _E("Failed to get icon");
729                         return NULL;
730                 }
731         } else {
732                 app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO];
733                 ret = pkgmgrinfo_appinfo_get_icon(app_info, &icon);
734                 if (ret != PMINFO_R_OK) {
735                         _E("Failed to get icon");
736                         return NULL;
737                 }
738         }
739
740         if (icon && icon[0] != '\0')
741                 return strdup(icon);
742
743         return NULL;
744 }
745
746 API int rua_info_get_icon(rua_info_h info, char **icon)
747 {
748         if (!info || !icon) {
749                 _E("Invalid parameter");
750                 return RUA_ERROR_INVALID_PARAMETER;
751         }
752
753         if (info->value[RUA_INFO_ICON]) {
754                 *icon = strdup(info->value[RUA_INFO_ICON]);
755                 if (*icon == NULL) {
756                         _E("Out of memory");
757                         return RUA_ERROR_OUT_OF_MEMORY;
758                 }
759         } else {
760                 *icon = __get_icon(info);
761         }
762
763         return RUA_ERROR_NONE;
764 }
765
766 API int rua_info_get_uri(rua_info_h info, char **uri)
767 {
768         if (!info || !uri) {
769                 _E("Invalid parameter");
770                 return RUA_ERROR_INVALID_PARAMETER;
771         }
772
773         if (info->value[RUA_INFO_URI]) {
774                 *uri = strdup(info->value[RUA_INFO_URI]);
775                 if (*uri == NULL) {
776                         _E("Out of memory");
777                         return RUA_ERROR_OUT_OF_MEMORY;
778                 }
779         } else {
780                 *uri = NULL;
781         }
782
783         return RUA_ERROR_NONE;
784 }
785
786 API int rua_info_get_image(rua_info_h info, char **image)
787 {
788         if (!info || !image) {
789                 _E("Invalid parameter");
790                 return RUA_ERROR_INVALID_PARAMETER;
791         }
792
793         if (info->value[RUA_INFO_IMAGE]) {
794                 *image = strdup(info->value[RUA_INFO_IMAGE]);
795                 if (*image == NULL) {
796                         _E("Out of memory");
797                         return RUA_ERROR_OUT_OF_MEMORY;
798                 }
799         } else {
800                 *image = NULL;
801         }
802
803         return RUA_ERROR_NONE;
804 }
805
806 API int rua_info_get_component_id(rua_info_h info, char **component_id)
807 {
808         if (!info || !component_id) {
809                 _E("Invalid parameter");
810                 return RUA_ERROR_INVALID_PARAMETER;
811         }
812
813         if (info->value[RUA_INFO_COMPONENT_ID]) {
814                 *component_id = strdup(info->value[RUA_INFO_COMPONENT_ID]);
815                 if (*component_id == NULL) {
816                         _E("Out of memory");
817                         return RUA_ERROR_OUT_OF_MEMORY;
818                 }
819         } else {
820                 *component_id = NULL;
821         }
822
823         return RUA_ERROR_NONE;
824 }
825
826
827 API int rua_info_is_managed_by_task_manager(rua_info_h info, bool *managed)
828 {
829         pkgmgrinfo_appinfo_h app_info;
830         aul_comp_info_h comp_info;
831         int ret;
832
833         if (!info || !managed) {
834                 _E("Invalid parameter");
835                 return RUA_ERROR_INVALID_PARAMETER;
836         }
837
838         if (info->value[RUA_INFO_COMP_INFO]) {
839                 comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO];
840                 ret = aul_comp_info_is_taskmanage(comp_info, managed);
841                 if (ret != AUL_R_OK) {
842                         _E("Failed to check taskmanage");
843                         return RUA_ERROR_INVALID_PARAMETER;
844                 }
845         } else {
846                 app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO];
847                 ret = pkgmgrinfo_appinfo_is_taskmanage(app_info, managed);
848                 if (ret != PMINFO_R_OK) {
849                         _E("Failed to check taskmanage");
850                         return RUA_ERROR_INVALID_PARAMETER;
851                 }
852         }
853
854         return RUA_ERROR_NONE;
855 }
856
857 static char *__get_label(rua_info_h info)
858 {
859         pkgmgrinfo_appinfo_h app_info;
860         aul_comp_info_h comp_info;
861         char *label;
862         int ret;
863
864         if (info->value[RUA_INFO_COMP_INFO]) {
865                 comp_info = (aul_comp_info_h)info->value[RUA_INFO_COMP_INFO];
866                 ret = aul_comp_info_get_label(comp_info, (const char **)&label);
867                 if (ret != AUL_R_OK) {
868                         _E("Failed to get label");
869                         return NULL;
870                 }
871         } else {
872                 app_info = (pkgmgrinfo_appinfo_h)info->value[RUA_INFO_APP_INFO];
873                 ret = pkgmgrinfo_appinfo_get_label(app_info, &label);
874                 if (ret != PMINFO_R_OK) {
875                         _E("Failed to get label");
876                         return NULL;
877                 }
878         }
879
880         if (label && label[0] != '\0')
881                 return strdup(label);
882
883         return NULL;
884 }
885
886 API int rua_info_get_label(rua_info_h info, char **label)
887 {
888         if (!info || !label) {
889                 _E("Invalid parameter");
890                 return RUA_ERROR_INVALID_PARAMETER;
891         }
892
893         *label = __get_label(info);
894
895         return RUA_ERROR_NONE;
896 }
897
898 API int rua_info_destroy(rua_info_h info)
899 {
900         if (!info) {
901                 _E("Invalid parameter");
902                 return RUA_ERROR_INVALID_PARAMETER;
903         }
904
905         __destroy_rua_info(info);
906
907         return RUA_ERROR_NONE;
908 }
909
910 API int rua_info_clone(rua_info_h info, rua_info_h *clone)
911 {
912         if (!info || !clone) {
913                 _E("Invalid parameter");
914                 return RUA_ERROR_INVALID_PARAMETER;
915         }
916
917         *clone = __clone_rua_info(info);
918         if (*clone == NULL) {
919                 _E("Failed to clone rua info");
920                 return RUA_ERROR_OUT_OF_MEMORY;
921         }
922
923         return RUA_ERROR_NONE;
924 }