13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 static bool _get_bool_value(const char *str)
22 else if (!strcasecmp(str, "true"))
28 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
30 pkgmgr_appinfo_x *info = data;
34 free((void *)info->package);
36 free((void *)info->locale);
38 pkgmgrinfo_basic_free_application(info->app_info);
44 static char *_get_filtered_query(const char *query_raw,
45 pkgmgrinfo_filter_x *filter)
47 char buf[MAX_QUERY_LEN] = { 0, };
56 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
58 for (list = head; list; list = list->next) {
59 /* TODO: revise condition getter function */
60 __get_filter_condition(list->data, &condition);
61 if (condition == NULL)
63 if (buf[strlen(query_raw)] == '\0') {
64 len += strlen(" WHERE ");
65 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
67 len += strlen(" AND ");
68 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
70 len += strlen(condition);
71 strncat(buf, condition, sizeof(buf) - len - 1);
79 static gint __list_strcmp(gconstpointer a, gconstpointer b)
81 return strcmp((char *)a, (char *)b);
84 static gint _appinfo_get_list(sqlite3 *db, const char *locale,
85 pkgmgrinfo_filter_x *filter, GList **list)
87 static const char query_raw[] =
88 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
89 " LEFT OUTER JOIN package_app_localized_info"
90 " ON package_app_info.app_id=package_app_localized_info.app_id"
91 " AND package_app_localized_info.app_locale=%Q"
92 " LEFT OUTER JOIN package_app_app_category"
93 " ON package_app_info.app_id=package_app_app_category.app_id"
94 " LEFT OUTER JOIN package_app_app_control"
95 " ON package_app_info.app_id=package_app_app_control.app_id"
96 " LEFT OUTER JOIN package_app_app_metadata"
97 " ON package_app_info.app_id=package_app_app_metadata.app_id ";
100 char *query_localized;
104 query = _get_filtered_query(query_raw, filter);
106 return PMINFO_R_ERROR;
107 query_localized = sqlite3_mprintf(query, locale);
109 if (query_localized == NULL)
110 return PMINFO_R_ERROR;
112 ret = sqlite3_prepare_v2(db, query_localized,
113 strlen(query_localized), &stmt, NULL);
114 sqlite3_free(query_localized);
115 if (ret != SQLITE_OK) {
116 LOGE("prepare failed: %s", sqlite3_errmsg(db));
117 return PMINFO_R_ERROR;
120 while (sqlite3_step(stmt) == SQLITE_ROW) {
121 _save_column_str(stmt, 0, (const char **)&appid);
123 *list = g_list_insert_sorted(*list, appid,
127 sqlite3_finalize(stmt);
132 static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
142 locale = _get_system_locale();
144 return PMINFO_R_ERROR;
146 dbpath = getUserPkgParserDBPathUID(uid);
147 if (dbpath == NULL) {
149 return PMINFO_R_ERROR;
152 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
153 if (ret != SQLITE_OK) {
154 _LOGE("failed to open db: %d", ret);
156 return PMINFO_R_ERROR;
159 if (_appinfo_get_list(db, locale, filter, list)) {
161 sqlite3_close_v2(db);
162 return PMINFO_R_ERROR;
164 sqlite3_close_v2(db);
166 if (uid == GLOBAL_USER) {
171 /* search again from global */
172 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
173 if (dbpath == NULL) {
175 return PMINFO_R_ERROR;
178 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
179 if (ret != SQLITE_OK) {
180 _LOGE("failed to open db: %d", ret);
182 return PMINFO_R_ERROR;
185 if (_appinfo_get_list(db, locale, filter, list)) {
187 sqlite3_close_v2(db);
188 return PMINFO_R_ERROR;
190 sqlite3_close_v2(db);
192 /* remove duplicate element:
193 * since the list is sorted, we can remove duplicates in linear time
195 for (tmp = *list, tmp2 = g_list_next(tmp); tmp;
196 tmp = tmp2, tmp2 = g_list_next(tmp)) {
197 if (tmp->prev == NULL || tmp->data == NULL)
199 if (strcmp((const char *)tmp->prev->data,
200 (const char *)tmp->data) == 0)
201 *list = g_list_delete_link(*list, tmp);
209 static int _appinfo_get_label(sqlite3 *db, const char *appid,
210 const char *locale, GList **label)
212 static const char query_raw[] =
213 "SELECT app_label, app_locale "
214 "FROM package_app_localized_info "
215 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
222 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
224 LOGE("out of memory");
225 return PMINFO_R_ERROR;
228 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
230 if (ret != SQLITE_OK) {
231 LOGE("prepare failed: %s", sqlite3_errmsg(db));
232 return PMINFO_R_ERROR;
235 while (sqlite3_step(stmt) == SQLITE_ROW) {
236 info = calloc(1, sizeof(label_x));
238 LOGE("out of memory");
239 sqlite3_finalize(stmt);
240 return PMINFO_R_ERROR;
243 _save_column_str(stmt, idx++, &info->text);
244 _save_column_str(stmt, idx++, &info->lang);
245 *label = g_list_append(*label, info);
248 sqlite3_finalize(stmt);
253 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
256 static const char query_raw[] =
257 "SELECT app_icon, app_locale "
258 "FROM package_app_localized_info "
259 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
266 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
268 LOGE("out of memory");
269 return PMINFO_R_ERROR;
272 ret = sqlite3_prepare_v2(db, query, strlen(query),
275 if (ret != SQLITE_OK) {
276 LOGE("prepare failed: %s", sqlite3_errmsg(db));
277 return PMINFO_R_ERROR;
280 while (sqlite3_step(stmt) == SQLITE_ROW) {
281 info = calloc(1, sizeof(icon_x));
283 LOGE("out of memory");
284 sqlite3_finalize(stmt);
285 return PMINFO_R_ERROR;
288 _save_column_str(stmt, idx++, &info->text);
289 _save_column_str(stmt, idx++, &info->lang);
290 *icon = g_list_append(*icon, info);
293 sqlite3_finalize(stmt);
298 static int _appinfo_get_category(sqlite3 *db, const char *appid,
301 static const char query_raw[] =
302 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
308 query = sqlite3_mprintf(query_raw, appid);
310 LOGE("out of memory");
311 return PMINFO_R_ERROR;
314 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
316 if (ret != SQLITE_OK) {
317 LOGE("prepare failed: %s", sqlite3_errmsg(db));
318 return PMINFO_R_ERROR;
321 while (sqlite3_step(stmt) == SQLITE_ROW) {
323 _save_column_str(stmt, 0, &val);
325 *category = g_list_append(*category, (gpointer)val);
328 sqlite3_finalize(stmt);
333 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
340 if (appcontrol_str == NULL)
343 dup = strdup(appcontrol_str);
345 ac = calloc(1, sizeof(appcontrol_x));
347 _LOGE("out of memory");
350 token = strtok_r(dup, "|", &ptr);
351 if (token && strcmp(token, "NULL"))
352 ac->operation = strdup(token);
353 token = strtok_r(NULL, "|", &ptr);
354 if (token && strcmp(token, "NULL"))
355 ac->uri = strdup(token);
356 token = strtok_r(NULL, "|", &ptr);
357 if (token && strcmp(token, "NULL"))
358 ac->mime = strdup(token);
359 *appcontrol = g_list_append(*appcontrol, ac);
360 } while ((token = strtok_r(NULL, ";", &ptr)));
365 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
368 static const char query_raw[] =
369 "SELECT app_control FROM package_app_app_control "
376 query = sqlite3_mprintf(query_raw, appid);
378 LOGE("out of memory");
379 return PMINFO_R_ERROR;
382 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
384 if (ret != SQLITE_OK) {
385 LOGE("prepare failed: %s", sqlite3_errmsg(db));
386 return PMINFO_R_ERROR;
389 while (sqlite3_step(stmt) == SQLITE_ROW) {
391 _save_column_str(stmt, 0, (const char **)&str);
393 __parse_appcontrol(appcontrol, str);
397 sqlite3_finalize(stmt);
402 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
405 static const char query_raw[] =
406 "SELECT providerid, access, type "
407 "FROM package_app_data_control WHERE app_id=%Q";
414 query = sqlite3_mprintf(query_raw, appid);
416 LOGE("out of memory");
417 return PMINFO_R_ERROR;
420 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
422 if (ret != SQLITE_OK) {
423 LOGE("prepare failed: %s", sqlite3_errmsg(db));
424 return PMINFO_R_ERROR;
427 while (sqlite3_step(stmt) == SQLITE_ROW) {
428 info = calloc(1, sizeof(datacontrol_x));
430 LOGE("out of memory");
431 sqlite3_finalize(stmt);
432 return PMINFO_R_ERROR;
435 _save_column_str(stmt, idx++, &info->providerid);
436 _save_column_str(stmt, idx++, &info->access);
437 _save_column_str(stmt, idx++, &info->type);
438 *datacontrol = g_list_append(*datacontrol, info);
441 sqlite3_finalize(stmt);
446 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
449 static const char query_raw[] =
450 "SELECT md_key, md_value "
451 "FROM package_app_app_metadata WHERE app_id=%Q";
458 query = sqlite3_mprintf(query_raw, appid);
460 LOGE("out of memory");
461 return PMINFO_R_ERROR;
464 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
466 if (ret != SQLITE_OK) {
467 LOGE("prepare failed: %s", sqlite3_errmsg(db));
468 return PMINFO_R_ERROR;
471 while (sqlite3_step(stmt) == SQLITE_ROW) {
472 info = calloc(1, sizeof(metadata_x));
474 LOGE("out of memory");
475 sqlite3_finalize(stmt);
476 return PMINFO_R_ERROR;
479 _save_column_str(stmt, idx++, &info->key);
480 _save_column_str(stmt, idx++, &info->value);
481 *metadata = g_list_append(*metadata, info);
484 sqlite3_finalize(stmt);
490 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
491 GList **splashscreens)
493 static const char query_raw[] =
494 "SELECT src, type, orientation, indicatordisplay "
495 "FROM package_app_splash_screen WHERE app_id=%Q";
500 splashscreen_x *info;
502 query = sqlite3_mprintf(query_raw, appid);
504 LOGE("out of memory");
505 return PMINFO_R_ERROR;
508 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
510 if (ret != SQLITE_OK) {
511 LOGE("prepare failed: %s", sqlite3_errmsg(db));
512 return PMINFO_R_ERROR;
515 while (sqlite3_step(stmt) == SQLITE_ROW) {
516 info = calloc(1, sizeof(splashscreen_x));
518 LOGE("out of memory");
519 sqlite3_finalize(stmt);
520 return PMINFO_R_ERROR;
523 _save_column_str(stmt, idx++, &info->src);
524 _save_column_str(stmt, idx++, &info->type);
525 _save_column_str(stmt, idx++, &info->orientation);
526 _save_column_str(stmt, idx++, &info->indicatordisplay);
527 *splashscreens = g_list_append(*splashscreens, info);
530 sqlite3_finalize(stmt);
535 static GList *__get_background_category(char *value)
537 GList *category_list = NULL;
538 int convert_value = 0;
539 if (!value || strlen(value) == 0)
542 convert_value = atoi(value);
543 if (convert_value < 0)
546 if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
547 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
549 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
551 if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
552 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
554 if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
555 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
557 if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
558 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
560 if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
561 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
563 if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
564 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
566 if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
567 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
569 if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
570 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
572 return category_list;
576 static int _appinfo_get_application(sqlite3 *db, const char *appid,
577 const char *locale, application_x **application, bool is_disabled)
579 static const char query_raw[] =
580 "SELECT app_id, app_component, app_exec, app_nodisplay, "
581 "app_type, app_onboot, app_multiple, app_autorestart, "
582 "app_taskmanage, app_enabled, app_hwacceleration, "
583 "app_screenreader, app_mainapp, app_recentimage, "
584 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
585 "app_landscapeimg, app_guestmodevisibility, "
586 "app_permissiontype, app_preload, app_submode, "
587 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
588 "app_support_disable, "
589 "component_type, package, app_process_pool, app_installed_storage, "
590 "app_background_category, app_package_type "
591 "FROM package_app_info WHERE app_id='%s' "
592 "AND (app_disable='%s' "
594 "(SELECT app_id from package_app_disable_for_user WHERE uid='%d'))";
596 char query[MAX_QUERY_LEN] = { '\0' };
600 char *bg_category_str = NULL;
601 snprintf(query, MAX_QUERY_LEN - 1, query_raw,
603 is_disabled ? "true" : "false",
604 is_disabled ? "OR" : "AND",
605 is_disabled ? "" : "NOT",
608 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
609 if (ret != SQLITE_OK) {
610 LOGE("prepare failed: %s", sqlite3_errmsg(db));
611 return PMINFO_R_ERROR;
614 ret = sqlite3_step(stmt);
615 if (ret == SQLITE_DONE) {
616 sqlite3_finalize(stmt);
617 return PMINFO_R_ENOENT;
618 } else if (ret != SQLITE_ROW) {
619 LOGE("step failed: %s", sqlite3_errmsg(db));
620 sqlite3_finalize(stmt);
621 return PMINFO_R_ERROR;
624 info = calloc(1, sizeof(application_x));
626 LOGE("out of memory");
627 sqlite3_finalize(stmt);
628 return PMINFO_R_ERROR;
631 _save_column_str(stmt, idx++, &info->appid);
632 _save_column_str(stmt, idx++, &info->component);
633 _save_column_str(stmt, idx++, &info->exec);
634 _save_column_str(stmt, idx++, &info->nodisplay);
635 _save_column_str(stmt, idx++, &info->type);
636 _save_column_str(stmt, idx++, &info->onboot);
637 _save_column_str(stmt, idx++, &info->multiple);
638 _save_column_str(stmt, idx++, &info->autorestart);
639 _save_column_str(stmt, idx++, &info->taskmanage);
640 _save_column_str(stmt, idx++, &info->enabled);
641 _save_column_str(stmt, idx++, &info->hwacceleration);
642 _save_column_str(stmt, idx++, &info->screenreader);
643 _save_column_str(stmt, idx++, &info->mainapp);
644 _save_column_str(stmt, idx++, &info->recentimage);
645 _save_column_str(stmt, idx++, &info->launchcondition);
646 _save_column_str(stmt, idx++, &info->indicatordisplay);
647 _save_column_str(stmt, idx++, &info->portraitimg);
648 _save_column_str(stmt, idx++, &info->landscapeimg);
649 _save_column_str(stmt, idx++, &info->guestmode_visibility);
650 _save_column_str(stmt, idx++, &info->permission_type);
651 _save_column_str(stmt, idx++, &info->preload);
652 _save_column_str(stmt, idx++, &info->submode);
653 _save_column_str(stmt, idx++, &info->submode_mainid);
654 _save_column_str(stmt, idx++, &info->launch_mode);
655 _save_column_str(stmt, idx++, &info->ui_gadget);
656 _save_column_str(stmt, idx++, &info->support_disable);
657 _save_column_str(stmt, idx++, &info->component_type);
658 _save_column_str(stmt, idx++, &info->package);
659 _save_column_str(stmt, idx++, &info->process_pool);
660 _save_column_str(stmt, idx++, &info->installed_storage);
661 _save_column_str(stmt, idx++, &bg_category_str);
662 _save_column_str(stmt, idx++, &info->package_type);
664 info->background_category = __get_background_category(bg_category_str);
666 if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
667 pkgmgrinfo_basic_free_application(info);
668 sqlite3_finalize(stmt);
669 return PMINFO_R_ERROR;
672 if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
673 pkgmgrinfo_basic_free_application(info);
674 sqlite3_finalize(stmt);
675 return PMINFO_R_ERROR;
678 if (_appinfo_get_category(db, info->appid, &info->category)) {
679 pkgmgrinfo_basic_free_application(info);
680 sqlite3_finalize(stmt);
681 return PMINFO_R_ERROR;
684 if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
685 pkgmgrinfo_basic_free_application(info);
686 sqlite3_finalize(stmt);
687 return PMINFO_R_ERROR;
690 if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
691 pkgmgrinfo_basic_free_application(info);
692 sqlite3_finalize(stmt);
693 return PMINFO_R_ERROR;
696 if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
697 pkgmgrinfo_basic_free_application(info);
698 sqlite3_finalize(stmt);
699 return PMINFO_R_ERROR;
702 if (_appinfo_get_splashscreens(db, info->appid, &info->splashscreens)) {
703 pkgmgrinfo_basic_free_application(info);
704 sqlite3_finalize(stmt);
705 return PMINFO_R_ERROR;
710 sqlite3_finalize(stmt);
715 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
716 pkgmgr_appinfo_x **appinfo, bool is_disabled)
722 pkgmgr_appinfo_x *info;
724 dbpath = getUserPkgParserDBPathUID(uid);
726 return PMINFO_R_ERROR;
728 locale = _get_system_locale();
730 return PMINFO_R_ERROR;
732 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
733 if (ret != SQLITE_OK) {
734 _LOGE("failed to open db: %d", ret);
736 return PMINFO_R_ERROR;
739 info = calloc(1, sizeof(pkgmgr_appinfo_x));
741 _LOGE("out of memory");
743 sqlite3_close_v2(db);
744 return PMINFO_R_ERROR;
747 ret = _appinfo_get_application(db, appid, locale, &info->app_info, is_disabled);
748 if (ret != PMINFO_R_OK) {
751 sqlite3_close_v2(db);
755 info->locale = locale;
756 info->package = strdup(info->app_info->package);
760 sqlite3_close_v2(db);
765 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
766 pkgmgrinfo_appinfo_h *handle)
770 if (appid == NULL || handle == NULL) {
771 LOGE("invalid parameter");
772 return PMINFO_R_EINVAL;
775 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle, true);
776 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
777 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
778 (pkgmgr_appinfo_x **)handle, true);
780 if (ret != PMINFO_R_OK)
781 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
786 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
788 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, GLOBAL_USER, handle);
791 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
792 pkgmgrinfo_appinfo_h *handle)
796 if (appid == NULL || handle == NULL) {
797 LOGE("invalid parameter");
798 return PMINFO_R_EINVAL;
801 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle, false);
802 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
803 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
804 (pkgmgr_appinfo_x **)handle, false);
806 if (ret != PMINFO_R_OK)
807 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
812 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
814 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
817 static gpointer __copy_str(gconstpointer src, gpointer data)
819 const char *tmp = (const char *)src;
822 buffer = strdup(tmp);
823 if (buffer == NULL) {
824 LOGE("memory alloc failed");
832 static gpointer __copy_label(gconstpointer src, gpointer data)
834 label_x *tmp = (label_x *)src;
837 label = calloc(1, sizeof(label_x));
839 LOGE("memory alloc failed");
845 label->name = strdup(tmp->name);
847 label->text = strdup(tmp->text);
849 label->lang = strdup(tmp->lang);
854 static gpointer __copy_icon(gconstpointer src, gpointer data)
856 icon_x *tmp = (icon_x *)src;
859 icon = calloc(1, sizeof(icon_x));
861 LOGE("memory alloc failed");
867 icon->text = strdup(tmp->text);
869 icon->lang = strdup(tmp->lang);
871 icon->section = strdup(tmp->section);
873 icon->size = strdup(tmp->size);
875 icon->resolution = strdup(tmp->resolution);
880 static gpointer __copy_metadata(gconstpointer src, gpointer data)
882 metadata_x *tmp = (metadata_x *)src;
883 metadata_x *metadata;
885 metadata = calloc(1, sizeof(metadata_x));
886 if (metadata == NULL) {
887 LOGE("memory alloc failed");
893 metadata->key = strdup(tmp->key);
895 metadata->value = strdup(tmp->value);
900 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
902 datacontrol_x *tmp = (datacontrol_x *)src;
903 datacontrol_x *datacontrol;
905 datacontrol = calloc(1, sizeof(datacontrol_x));
906 if (datacontrol == NULL) {
907 LOGE("memory alloc failed");
913 datacontrol->providerid = strdup(tmp->providerid);
915 datacontrol->access = strdup(tmp->access);
917 datacontrol->type = strdup(tmp->type);
922 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
924 appcontrol_x *tmp = (appcontrol_x *)src;
925 appcontrol_x *appcontrol;
927 appcontrol = calloc(1, sizeof(appcontrol_x));
928 if (appcontrol ==NULL) {
929 LOGE("memory alloc failed");
935 appcontrol->operation = strdup(tmp->operation);
937 appcontrol->uri = strdup(tmp->uri);
939 appcontrol->mime = strdup(tmp->mime);
944 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
946 splashscreen_x *tmp = (splashscreen_x *)src;
947 splashscreen_x *splashscreen;
949 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
950 if (splashscreen == NULL) {
951 LOGE("memory alloc failed");
957 splashscreen->src = strdup(tmp->src);
959 splashscreen->type = strdup(tmp->type);
960 if (tmp->orientation)
961 splashscreen->orientation = strdup(tmp->orientation);
962 if (tmp->indicatordisplay)
963 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
968 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
970 application_x *app_info;
973 app_info = calloc(1, sizeof(application_x));
974 if (app_info == NULL) {
975 LOGE("memory alloc failed");
976 return PMINFO_R_ERROR;
979 if (data->appid != NULL)
980 app_info->appid = strdup(data->appid);
981 if (data->exec != NULL)
982 app_info->exec = strdup(data->exec);
983 if (data->nodisplay != NULL)
984 app_info->nodisplay = strdup(data->nodisplay);
985 if (data->multiple != NULL)
986 app_info->multiple = strdup(data->multiple);
987 if (data->taskmanage != NULL)
988 app_info->taskmanage = strdup(data->taskmanage);
989 if (data->enabled != NULL)
990 app_info->enabled = strdup(data->enabled);
991 if (data->type != NULL)
992 app_info->type = strdup(data->type);
993 if (data->categories != NULL)
994 app_info->categories = strdup(data->categories);
995 if (data->hwacceleration != NULL)
996 app_info->hwacceleration = strdup(data->hwacceleration);
997 if (data->screenreader != NULL)
998 app_info->screenreader = strdup(data->screenreader);
999 if (data->mainapp != NULL)
1000 app_info->mainapp = strdup(data->mainapp);
1001 if (data->package != NULL)
1002 app_info->package = strdup(data->package);
1003 if (data->recentimage != NULL)
1004 app_info->recentimage = strdup(data->recentimage);
1005 if (data->launchcondition != NULL)
1006 app_info->launchcondition = strdup(data->launchcondition);
1007 if (data->indicatordisplay != NULL)
1008 app_info->indicatordisplay = strdup(data->indicatordisplay);
1009 if (data->portraitimg != NULL)
1010 app_info->portraitimg = strdup(data->portraitimg);
1011 if (data->landscapeimg != NULL)
1012 app_info->landscapeimg = strdup(data->landscapeimg);
1013 if (data->guestmode_visibility != NULL)
1014 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1015 if (data->component != NULL)
1016 app_info->component = strdup(data->component);
1017 if (data->permission_type != NULL)
1018 app_info->permission_type = strdup(data->permission_type);
1019 if (data->component_type != NULL)
1020 app_info->component_type = strdup(data->component_type);
1021 if (data->preload != NULL)
1022 app_info->preload = strdup(data->preload);
1023 if (data->submode != NULL)
1024 app_info->submode = strdup(data->submode);
1025 if (data->submode_mainid != NULL)
1026 app_info->submode_mainid = strdup(data->submode_mainid);
1027 if (data->process_pool != NULL)
1028 app_info->process_pool = strdup(data->process_pool);
1029 if (data->installed_storage != NULL)
1030 app_info->installed_storage = strdup(data->installed_storage);
1031 if (data->autorestart != NULL)
1032 app_info->autorestart = strdup(data->autorestart);
1033 if (data->onboot != NULL)
1034 app_info->onboot = strdup(data->onboot);
1035 if (data->support_disable != NULL)
1036 app_info->support_disable = strdup(data->support_disable);
1037 if (data->ui_gadget != NULL)
1038 app_info->ui_gadget = strdup(data->ui_gadget);
1039 if (data->launch_mode != NULL)
1040 app_info->launch_mode = strdup(data->launch_mode);
1041 if (data->package_type != NULL)
1042 app_info->package_type = strdup(data->package_type);
1046 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1048 LOGE("memory alloc failed");
1049 pkgmgrinfo_basic_free_application(app_info);
1050 return PMINFO_R_ERROR;
1054 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1056 LOGE("memory alloc failed");
1057 pkgmgrinfo_basic_free_application(app_info);
1058 return PMINFO_R_ERROR;
1062 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1064 LOGE("memory alloc failed");
1065 pkgmgrinfo_basic_free_application(app_info);
1066 return PMINFO_R_ERROR;
1070 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1072 LOGE("memory alloc failed");
1073 pkgmgrinfo_basic_free_application(app_info);
1074 return PMINFO_R_ERROR;
1078 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1080 LOGE("memory alloc failed");
1081 pkgmgrinfo_basic_free_application(app_info);
1082 return PMINFO_R_ERROR;
1086 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1088 LOGE("memory alloc failed");
1089 pkgmgrinfo_basic_free_application(app_info);
1090 return PMINFO_R_ERROR;
1094 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1096 LOGE("memory alloc failed");
1097 pkgmgrinfo_basic_free_application(app_info);
1098 return PMINFO_R_ERROR;
1102 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1104 LOGE("memory alloc failed");
1105 pkgmgrinfo_basic_free_application(app_info);
1106 return PMINFO_R_ERROR;
1109 *application = app_info;
1114 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1115 pkgmgrinfo_appinfo_h *clone)
1117 pkgmgr_appinfo_x *info;
1118 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1121 return PMINFO_R_EINVAL;
1123 info = calloc(1, sizeof(pkgmgr_appinfo_x));
1125 LOGE("memory alloc failed");
1126 return PMINFO_R_ERROR;
1129 if (temp->package != NULL)
1130 info->package = strdup(temp->package);
1131 if (temp->locale != NULL)
1132 info->locale = strdup(temp->locale);
1134 info->app_component = temp->app_component;
1136 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1137 LOGE("appinfo copy failed");
1139 free((void *)info->package);
1143 return PMINFO_R_ERROR;
1151 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1152 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
1156 pkgmgr_appinfo_x *info;
1162 ret = _appinfo_get_filtered_list(filter, uid, &list);
1163 if (ret != PMINFO_R_OK)
1164 return PMINFO_R_ERROR;
1166 for (tmp = list; tmp; tmp = tmp->next) {
1167 appid = (char *)tmp->data;
1169 ret = _appinfo_get_appinfo(appid, uid, &info, false);
1170 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1171 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
1173 if (ret != PMINFO_R_OK) {
1177 if (app_list_cb(info, user_data) < 0)
1179 pkgmgrinfo_appinfo_destroy_appinfo(info);
1189 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1190 pkgmgrinfo_app_component component,
1191 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1194 pkgmgrinfo_appinfo_filter_h filter;
1196 const char *comp_str = NULL;
1198 if (handle == NULL || app_func == NULL) {
1199 LOGE("invalid parameter");
1200 return PMINFO_R_EINVAL;
1203 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1204 LOGE("invalid parameter");
1205 return PMINFO_R_EINVAL;
1208 if (pkgmgrinfo_appinfo_filter_create(&filter))
1209 return PMINFO_R_ERROR;
1211 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1212 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1213 pkgmgrinfo_appinfo_filter_destroy(filter);
1214 return PMINFO_R_ERROR;
1217 if (uid == GLOBAL_USER) {
1218 if (pkgmgrinfo_appinfo_filter_add_int(filter,
1219 PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) {
1220 pkgmgrinfo_appinfo_filter_destroy(filter);
1221 return PMINFO_R_ERROR;
1225 switch (component) {
1227 comp_str = PMINFO_APPINFO_UI_APP;
1229 case PMINFO_SVC_APP:
1230 comp_str = PMINFO_APPINFO_SVC_APP;
1237 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1238 PMINFO_APPINFO_PROP_APP_COMPONENT,
1240 pkgmgrinfo_appinfo_filter_destroy(filter);
1241 return PMINFO_R_ERROR;
1245 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
1248 pkgmgrinfo_appinfo_filter_destroy(filter);
1253 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
1254 pkgmgrinfo_app_list_cb app_func, void *user_data)
1256 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
1259 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1261 if (app_func == NULL) {
1262 LOGE("invalid parameter");
1263 return PMINFO_R_EINVAL;
1266 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1270 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1272 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
1275 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1277 if (app_func == NULL) {
1278 LOGE("invalid parameter");
1279 return PMINFO_R_EINVAL;
1282 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1286 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1288 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
1291 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1293 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1296 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1298 if (info->app_info == NULL || info->app_info->appid == NULL)
1299 return PMINFO_R_ERROR;
1300 *appid = (char *)info->app_info->appid;
1305 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1307 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1309 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1310 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1312 if (info->package == NULL)
1313 return PMINFO_R_ERROR;
1315 *pkg_name = (char *)info->package;
1320 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1322 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1324 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1325 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1327 if (info->package == NULL)
1328 return PMINFO_R_ERROR;
1330 *pkgid = (char *)info->package;
1335 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1337 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1338 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1339 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1341 *pkgtype = (char *)info->app_info->package_type;
1346 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1348 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1350 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1351 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1353 if (info->app_info == NULL || info->app_info->exec == NULL)
1354 return PMINFO_R_ERROR;
1355 *exec = (char *)info->app_info->exec;
1361 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1366 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1368 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1369 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1371 locale = info->locale;
1372 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1374 if (info->app_info == NULL)
1375 return PMINFO_R_ERROR;
1377 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1378 ptr = (icon_x *)tmp->data;
1379 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1380 !strcasecmp(ptr->text, "") ||
1381 strcmp(ptr->lang, locale))
1383 *icon = (char *)ptr->text;
1387 locale = DEFAULT_LOCALE;
1388 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1389 ptr = (icon_x *)tmp->data;
1390 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1391 strcmp(ptr->lang, locale))
1393 *icon = (char *)ptr->text;
1397 return PMINFO_R_ERROR;
1401 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1406 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1408 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1409 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1411 locale = info->locale;
1412 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1414 if (info->app_info == NULL)
1415 return PMINFO_R_ERROR;
1417 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1418 ptr = (label_x *)tmp->data;
1419 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1420 strcmp(ptr->lang, locale))
1422 *label = (char *)ptr->text;
1426 locale = DEFAULT_LOCALE;
1427 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1428 ptr = (label_x *)tmp->data;
1429 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1430 strcmp(ptr->lang, locale))
1432 *label = (char *)ptr->text;
1436 return PMINFO_R_ERROR;
1439 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1441 char *result = NULL;
1443 sqlite3_stmt *stmt = NULL;
1446 const char *manifest_db;
1448 manifest_db = getUserPkgParserDBPathUID(uid);
1449 if (manifest_db == NULL) {
1450 _LOGE("Failed to get manifest db path");
1454 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1455 _LOGE("DB open fail\n");
1459 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1460 if (query == NULL) {
1461 _LOGE("Out of memory");
1465 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1466 _LOGE("prepare_v2 fail\n");
1470 if (sqlite3_step(stmt) == SQLITE_ROW) {
1471 val = (char *)sqlite3_column_text(stmt, 0);
1473 result = strdup(val);
1477 sqlite3_finalize(stmt);
1478 sqlite3_free(query);
1484 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1488 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1490 val = _get_localed_label(appid, locale, uid);
1492 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1495 return PMINFO_R_ERROR;
1502 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1504 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1507 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1509 if ( strcasecmp(comp, "uiapp") == 0)
1510 return PMINFO_UI_APP;
1511 else if ( strcasecmp(comp, "svcapp") == 0)
1512 return PMINFO_SVC_APP;
1517 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1519 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1522 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1523 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1525 if (info->app_info == NULL)
1526 return PMINFO_R_ERROR;
1528 comp = __appcomponent_convert(info->app_info->component);
1530 return PMINFO_R_ERROR;
1537 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1539 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1541 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1542 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1544 if (info->app_info == NULL || info->app_info->type == NULL)
1545 return PMINFO_R_ERROR;
1546 *app_type = (char *)info->app_info->type;
1551 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1552 int *operation_count, char ***operation)
1554 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1555 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1556 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1557 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1558 *operation_count = data->operation_count;
1559 *operation = data->operation;
1563 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1564 int *uri_count, char ***uri)
1566 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1567 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1568 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1569 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1570 *uri_count = data->uri_count;
1575 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1576 int *mime_count, char ***mime)
1578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1579 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1580 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1581 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1582 *mime_count = data->mime_count;
1587 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1588 int *subapp_count, char ***subapp)
1590 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1591 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1592 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1593 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1594 *subapp_count = data->subapp_count;
1595 *subapp = data->subapp;
1599 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1604 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1607 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1609 if (info->app_info == NULL)
1610 return PMINFO_R_ERROR;
1612 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1613 ptr = (icon_x *)tmp->data;
1614 if (ptr == NULL || ptr->section == NULL)
1617 val = (char *)ptr->section;
1618 if (val && strcmp(val, "setting") == 0) {
1619 *icon = (char *)ptr->text;
1624 return PMINFO_R_ERROR;
1628 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1633 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1635 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1636 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1638 if (info->app_info == NULL)
1639 return PMINFO_R_ERROR;
1641 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1642 ptr = (icon_x *)tmp->data;
1643 if (ptr == NULL || ptr->section == NULL)
1646 val = (char *)ptr->section;
1647 if (val && strcmp(val, "notification") == 0){
1648 *icon = (char *)ptr->text;
1653 return PMINFO_R_ERROR;
1656 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1659 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1661 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1662 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1664 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1665 return PMINFO_R_ERROR;
1667 val = (char *)info->app_info->recentimage;
1668 if (strcasecmp(val, "capture") == 0)
1669 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1670 else if (strcasecmp(val, "icon") == 0)
1671 *type = PMINFO_RECENTIMAGE_USE_ICON;
1673 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1678 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1683 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1685 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1686 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1688 if (info->app_info == NULL)
1689 return PMINFO_R_ERROR;
1691 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1692 ptr = (image_x *)tmp->data;
1693 if (ptr == NULL || ptr->section == NULL)
1696 val = (char *)ptr->section;
1697 if (val && strcmp(val, "preview") == 0) {
1698 *preview_img = (char *)ptr->text;
1703 return PMINFO_R_ERROR;
1706 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1709 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1711 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1712 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1714 val = info->app_info->permission_type;
1716 return PMINFO_R_ERROR;
1718 if (strcmp(val, "signature") == 0)
1719 *permission = PMINFO_PERMISSION_SIGNATURE;
1720 else if (strcmp(val, "privilege") == 0)
1721 *permission = PMINFO_PERMISSION_PRIVILEGE;
1723 *permission = PMINFO_PERMISSION_NORMAL;
1728 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1730 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1732 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1733 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1735 if (info->app_info == NULL || info->app_info->component_type == NULL)
1736 return PMINFO_R_ERROR;
1738 *component_type = (char *)info->app_info->component_type;
1743 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1746 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1748 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1749 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1751 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1752 return PMINFO_R_ERROR;
1754 val = (char *)info->app_info->hwacceleration;
1755 if (strcasecmp(val, "not-use-GL") == 0)
1756 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1757 else if (strcasecmp(val, "use-GL") == 0)
1758 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1760 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1765 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1768 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1770 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1771 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1773 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1774 return PMINFO_R_ERROR;
1776 val = (char *)info->app_info->screenreader;
1777 if (strcasecmp(val, "screenreader-off") == 0)
1778 *screenreader = PMINFO_SCREENREADER_OFF;
1779 else if (strcasecmp(val, "screenreader-on") == 0)
1780 *screenreader = PMINFO_SCREENREADER_ON;
1782 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1787 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1789 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1791 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1792 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1793 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1795 if (info->app_info == NULL || (info->app_info->portraitimg == NULL
1796 && info->app_info->landscapeimg == NULL))
1797 return PMINFO_R_ERROR;
1799 *portrait_img = (char *)info->app_info->portraitimg;
1800 *landscape_img = (char *)info->app_info->landscapeimg;
1805 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1807 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1809 if (handle == NULL || effectimage_type == NULL) {
1810 LOGE("invalid parameter");
1811 return PMINFO_R_EINVAL;
1814 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1815 return PMINFO_R_ERROR;
1817 *effectimage_type = (char *)info->app_info->effectimage_type;
1822 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1824 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1826 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1827 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1829 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1830 return PMINFO_R_ERROR;
1832 *submode_mainid = (char *)info->app_info->submode_mainid;
1837 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1839 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1840 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1842 if (info->app_info && info->app_info->installed_storage){
1843 if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
1844 *storage = PMINFO_INTERNAL_STORAGE;
1845 else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
1846 *storage = PMINFO_EXTERNAL_STORAGE;
1848 return PMINFO_R_ERROR;
1850 return PMINFO_R_ERROR;
1855 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1857 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1859 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1860 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1862 if (info->app_info->launch_mode == NULL)
1863 return PMINFO_R_ERROR;
1865 *mode = (char *)(info->app_info->launch_mode);
1870 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
1872 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1874 if (handle == NULL || alias_appid == NULL) {
1875 LOGE("invalid parameter");
1876 return PMINFO_R_EINVAL;
1879 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
1880 return PMINFO_R_ERROR;
1882 *alias_appid = (char *)info->app_info->alias_appid;
1887 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
1889 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1891 if (handle == NULL || effective_appid == NULL) {
1892 LOGE("invalid parameter");
1893 return PMINFO_R_EINVAL;
1896 if (info->app_info == NULL || info->app_info->effective_appid == NULL)
1897 return PMINFO_R_ERROR;
1899 *effective_appid = (char *)info->app_info->effective_appid;
1904 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1906 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1907 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1908 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1909 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1911 int ret = PMINFO_R_OK;
1913 sqlite3_stmt *stmt = NULL;
1916 ret = __open_manifest_db(uid, true);
1917 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1919 /*Start constructing query*/
1920 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1923 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1924 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1927 ret = sqlite3_step(stmt);
1928 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1930 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1931 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1936 sqlite3_free(query);
1937 sqlite3_finalize(stmt);
1938 __close_manifest_db();
1942 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1944 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1947 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1949 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1950 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1952 int ret = PMINFO_R_OK;
1954 sqlite3_stmt *stmt = NULL;
1957 ret = __open_manifest_db(uid, true);
1958 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1960 /*Start constructing query*/
1961 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1964 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1965 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1968 ret = sqlite3_step(stmt);
1969 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1971 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1976 sqlite3_free(query);
1977 sqlite3_finalize(stmt);
1978 __close_manifest_db();
1982 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1984 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1987 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1988 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1990 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1991 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1995 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1997 if (info->app_info == NULL)
1998 return PMINFO_R_ERROR;
2000 for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
2001 ptr = (permission_x *)tmp->data;
2005 ret = permission_func(ptr->value, user_data);
2013 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2014 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2016 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2017 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2019 const char *category;
2021 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2023 if (info->app_info == NULL)
2024 return PMINFO_R_ERROR;
2026 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2027 category = (const char *)tmp->data;
2029 ret = category_func(category, user_data);
2037 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2038 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2040 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2041 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2045 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2047 if (info->app_info == NULL)
2048 return PMINFO_R_ERROR;
2050 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2051 ptr = (metadata_x *)tmp->data;
2055 ret = metadata_func(ptr->key, ptr->value, user_data);
2063 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2064 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2066 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2067 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2069 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2070 appcontrol_x *appcontrol;
2073 if (info->app_info == NULL)
2074 return PMINFO_R_ERROR;
2076 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2077 appcontrol = (appcontrol_x *)tmp->data;
2078 if (appcontrol == NULL)
2080 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2088 API int pkgmgrinfo_appinfo_foreach_background_category(
2089 pkgmgrinfo_appinfo_h handle,
2090 pkgmgrinfo_app_background_category_list_cb category_func,
2093 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2097 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2098 LOGE("invalid parameter");
2099 return PMINFO_R_EINVAL;
2102 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2103 category = (char *)tmp->data;
2104 if (category == NULL)
2107 if (category_func(category, user_data) < 0)
2114 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2115 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2118 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2119 splashscreen_x *splashscreen;
2123 if (info == NULL || info->app_info == NULL
2124 || splash_screen_func == NULL) {
2125 LOGE("invalid parameter");
2126 return PMINFO_R_EINVAL;
2129 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2130 splashscreen = (splashscreen_x *)tmp->data;
2131 if (splashscreen == NULL)
2133 ret = splash_screen_func(splashscreen->src,
2135 splashscreen->orientation,
2136 splashscreen->indicatordisplay,
2145 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2147 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2148 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2149 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2151 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2152 return PMINFO_R_ERROR;
2154 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2159 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2161 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2162 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2163 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2165 if (info->app_info == NULL || info->app_info->multiple == NULL)
2166 return PMINFO_R_ERROR;
2168 *multiple = _get_bool_value(info->app_info->multiple);
2173 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2175 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2176 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2177 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2179 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2180 return PMINFO_R_ERROR;
2182 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2187 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2189 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2190 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2191 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2193 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2194 return PMINFO_R_ERROR;
2196 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2201 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2204 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2205 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2207 if (info->app_info == NULL || info->app_info->enabled == NULL)
2208 return PMINFO_R_ERROR;
2210 *enabled = _get_bool_value(info->app_info->enabled);
2215 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2217 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2218 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2219 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2221 if (info->app_info == NULL || info->app_info->onboot == NULL)
2222 return PMINFO_R_ERROR;
2224 *onboot = _get_bool_value(info->app_info->onboot);
2229 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
2231 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2232 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2233 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2235 if (info->app_info == NULL || info->app_info->autorestart == NULL)
2236 return PMINFO_R_ERROR;
2238 *autorestart = _get_bool_value(info->app_info->autorestart);
2243 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
2245 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2246 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2247 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2249 if (info->app_info == NULL || info->app_info->mainapp == NULL)
2250 return PMINFO_R_ERROR;
2252 *mainapp = _get_bool_value(info->app_info->mainapp);
2257 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2260 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2261 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2263 if (info->app_info == NULL || info->app_info->preload == NULL)
2264 return PMINFO_R_ERROR;
2266 *preload = _get_bool_value(info->app_info->preload);
2271 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2274 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2275 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2277 if (info->app_info == NULL || info->app_info->submode == NULL)
2278 return PMINFO_R_ERROR;
2280 *submode = _get_bool_value(info->app_info->submode);
2285 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2287 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2289 if (handle == NULL || process_pool == NULL) {
2290 LOGE("invalid parameter");
2291 return PMINFO_R_EINVAL;
2294 if (info->app_info == NULL)
2295 return PMINFO_R_ERROR;
2297 *process_pool = _get_bool_value(info->app_info->process_pool);
2302 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2304 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2305 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2306 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2310 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2312 if (info->app_info == NULL)
2313 return PMINFO_R_ERROR;
2316 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2317 val = (const char *)tmp->data;
2320 if (strcasecmp(val, category) == 0) {
2329 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2332 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2334 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2335 _LOGE("invalid parameter");
2336 return PMINFO_R_EINVAL;
2339 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2344 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2345 bool *support_disable)
2347 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2349 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2350 _LOGE("invalid parameter");
2351 return PMINFO_R_EINVAL;
2354 *support_disable = _get_bool_value(info->app_info->support_disable);
2359 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2361 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2362 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2363 __cleanup_appinfo(info);
2367 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2369 return (pkgmgrinfo_pkginfo_filter_create(handle));
2372 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2374 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2377 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2379 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
2380 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
2381 if (node1->prop == node2->prop)
2383 else if (node1->prop > node2->prop)
2389 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2390 const char *property, const int value)
2392 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2393 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2394 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2396 GSList *link = NULL;
2398 prop = _pminfo_appinfo_convert_to_prop_int(property);
2399 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2400 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2401 _LOGE("Invalid Integer Property\n");
2402 return PMINFO_R_EINVAL;
2404 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2405 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2407 _LOGE("Out of Memory!!!\n");
2408 return PMINFO_R_ERROR;
2410 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2411 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2413 _LOGE("Out of Memory\n");
2416 return PMINFO_R_ERROR;
2420 /*If API is called multiple times for same property, we should override the previous values.
2421 Last value set will be used for filtering.*/
2422 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2424 filter->list = g_slist_delete_link(filter->list, link);
2425 filter->list = g_slist_append(filter->list, (gpointer)node);
2430 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2431 const char *property, const bool value)
2433 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2434 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2436 GSList *link = NULL;
2438 prop = _pminfo_appinfo_convert_to_prop_bool(property);
2439 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2440 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2441 _LOGE("Invalid Boolean Property\n");
2442 return PMINFO_R_EINVAL;
2444 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2445 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2447 _LOGE("Out of Memory!!!\n");
2448 return PMINFO_R_ERROR;
2451 val = strndup("('true','True')", 15);
2453 val = strndup("('false','False')", 17);
2455 _LOGE("Out of Memory\n");
2458 return PMINFO_R_ERROR;
2462 /*If API is called multiple times for same property, we should override the previous values.
2463 Last value set will be used for filtering.*/
2464 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2466 filter->list = g_slist_delete_link(filter->list, link);
2467 filter->list = g_slist_append(filter->list, (gpointer)node);
2472 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2473 const char *property, const char *value)
2475 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2476 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2477 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2479 pkgmgrinfo_node_x *ptr = NULL;
2480 char prev[PKG_STRING_LEN_MAX] = {'\0'};
2481 char temp[PKG_STRING_LEN_MAX] = {'\0'};
2482 GSList *link = NULL;
2484 prop = _pminfo_appinfo_convert_to_prop_str(property);
2485 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2486 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2487 _LOGE("Invalid String Property\n");
2488 return PMINFO_R_EINVAL;
2490 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2491 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2493 _LOGE("Out of Memory!!!\n");
2494 return PMINFO_R_ERROR;
2498 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2499 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
2500 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
2502 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
2504 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2506 filter->list = g_slist_delete_link(filter->list, link);
2507 filter->list = g_slist_append(filter->list, (gpointer)node);
2509 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2510 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
2511 case E_PMINFO_APPINFO_PROP_APP_URI:
2512 case E_PMINFO_APPINFO_PROP_APP_MIME:
2513 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2515 _LOGE("Out of Memory\n");
2518 return PMINFO_R_ERROR;
2520 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2522 ptr = (pkgmgrinfo_node_x *)link->data;
2523 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2524 _LOGE("Previous value is %s\n", prev);
2525 filter->list = g_slist_delete_link(filter->list, link);
2526 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
2527 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2528 _LOGE("New value is %s\n", val);
2530 filter->list = g_slist_append(filter->list, (gpointer)node);
2531 memset(temp, '\0', PKG_STRING_LEN_MAX);
2533 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
2534 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2535 _LOGE("First value is %s\n", val);
2537 filter->list = g_slist_append(filter->list, (gpointer)node);
2538 memset(temp, '\0', PKG_STRING_LEN_MAX);
2542 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2543 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2545 filter->list = g_slist_delete_link(filter->list, link);
2546 filter->list = g_slist_append(filter->list, (gpointer)node);
2552 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2557 if (handle == NULL || count == NULL) {
2558 _LOGE("invalid parameter");
2559 return PMINFO_R_EINVAL;
2562 ret = _appinfo_get_filtered_list(handle, uid, &list);
2563 if (ret != PMINFO_R_OK)
2564 return PMINFO_R_ERROR;
2566 *count = g_list_length(list);
2568 g_list_free_full(list, free);
2573 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2575 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
2578 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2579 pkgmgrinfo_appinfo_filter_h handle,
2580 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2582 if (handle == NULL || app_cb == NULL) {
2583 LOGE("invalid parameter");
2584 return PMINFO_R_EINVAL;
2587 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2591 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2592 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2594 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2597 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2599 return (pkgmgrinfo_pkginfo_filter_create(handle));
2602 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2604 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2607 API int pkgmgrinfo_appinfo_metadata_filter_add(
2608 pkgmgrinfo_appinfo_metadata_filter_h handle,
2609 const char *key, const char *value)
2613 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2614 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2615 if (ret != PMINFO_R_OK)
2618 /* value can be NULL.
2619 * In that case all apps with specified key should be displayed
2622 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2623 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2624 if (ret != PMINFO_R_OK)
2631 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2632 pkgmgrinfo_appinfo_metadata_filter_h handle,
2633 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2635 if (handle == NULL || app_cb == NULL) {
2636 LOGE("invalid parameter");
2637 return PMINFO_R_EINVAL;
2640 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2644 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2645 pkgmgrinfo_appinfo_metadata_filter_h handle,
2646 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2648 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2649 user_data, GLOBAL_USER);
2652 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2655 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2657 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2658 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2660 val = info->app_info->guestmode_visibility;
2661 *status = _get_bool_value(val);