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;
31 pkgmgr_appinfo_x *tmp;
33 while (info != NULL) {
36 free((void *)info->package);
38 free((void *)info->locale);
40 pkgmgrinfo_basic_free_application(info->app_info);
47 static char *_get_filtered_query(const char *query_raw,
48 pkgmgrinfo_filter_x *filter)
50 char buf[MAX_QUERY_LEN] = { 0, };
59 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
61 for (list = head; list; list = list->next) {
62 /* TODO: revise condition getter function */
63 __get_filter_condition(list->data, &condition);
64 if (condition == NULL)
66 if (buf[strlen(query_raw)] == '\0') {
67 len += strlen(" WHERE ");
68 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
70 len += strlen(" AND ");
71 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
73 len += strlen(condition);
74 strncat(buf, condition, sizeof(buf) - len - 1);
82 static gint __list_strcmp(gconstpointer a, gconstpointer b)
84 return strcmp((char *)a, (char *)b);
87 static gint _appinfo_get_list(sqlite3 *db, const char *locale,
88 pkgmgrinfo_filter_x *filter, GList **list)
90 static const char query_raw[] =
91 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
92 " LEFT OUTER JOIN package_app_localized_info"
93 " ON package_app_info.app_id=package_app_localized_info.app_id"
94 " AND package_app_localized_info.app_locale=%Q"
95 " LEFT OUTER JOIN package_app_app_category"
96 " ON package_app_info.app_id=package_app_app_category.app_id"
97 " LEFT OUTER JOIN package_app_app_control"
98 " ON package_app_info.app_id=package_app_app_control.app_id"
99 " LEFT OUTER JOIN package_app_app_metadata"
100 " ON package_app_info.app_id=package_app_app_metadata.app_id ";
103 char *query_localized;
107 query = _get_filtered_query(query_raw, filter);
109 return PMINFO_R_ERROR;
110 query_localized = sqlite3_mprintf(query, locale);
112 if (query_localized == NULL)
113 return PMINFO_R_ERROR;
115 ret = sqlite3_prepare_v2(db, query_localized,
116 strlen(query_localized), &stmt, NULL);
117 sqlite3_free(query_localized);
118 if (ret != SQLITE_OK) {
119 LOGE("prepare failed: %s", sqlite3_errmsg(db));
120 return PMINFO_R_ERROR;
123 while (sqlite3_step(stmt) == SQLITE_ROW) {
124 _save_column_str(stmt, 0, (const char **)&appid);
126 *list = g_list_insert_sorted(*list, appid,
130 sqlite3_finalize(stmt);
135 static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
145 locale = _get_system_locale();
147 return PMINFO_R_ERROR;
149 dbpath = getUserPkgParserDBPathUID(uid);
150 if (dbpath == NULL) {
152 return PMINFO_R_ERROR;
155 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
156 if (ret != SQLITE_OK) {
157 _LOGE("failed to open db: %d", ret);
159 return PMINFO_R_ERROR;
162 if (_appinfo_get_list(db, locale, filter, list)) {
164 sqlite3_close_v2(db);
165 return PMINFO_R_ERROR;
167 sqlite3_close_v2(db);
169 if (uid == GLOBAL_USER) {
174 /* search again from global */
175 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
176 if (dbpath == NULL) {
178 return PMINFO_R_ERROR;
181 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
182 if (ret != SQLITE_OK) {
183 _LOGE("failed to open db: %d", ret);
185 return PMINFO_R_ERROR;
188 if (_appinfo_get_list(db, locale, filter, list)) {
190 sqlite3_close_v2(db);
191 return PMINFO_R_ERROR;
193 sqlite3_close_v2(db);
195 /* remove duplicate element:
196 * since the list is sorted, we can remove duplicates in linear time
198 for (tmp = *list, tmp2 = g_list_next(tmp); tmp;
199 tmp = tmp2, tmp2 = g_list_next(tmp)) {
200 if (tmp->prev == NULL || tmp->data == NULL)
202 if (strcmp((const char *)tmp->prev->data,
203 (const char *)tmp->data) == 0)
204 *list = g_list_delete_link(*list, tmp);
212 static int _appinfo_get_label(sqlite3 *db, const char *appid,
213 const char *locale, GList **label)
215 static const char query_raw[] =
216 "SELECT app_label, app_locale "
217 "FROM package_app_localized_info "
218 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
225 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
227 LOGE("out of memory");
228 return PMINFO_R_ERROR;
231 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
233 if (ret != SQLITE_OK) {
234 LOGE("prepare failed: %s", sqlite3_errmsg(db));
235 return PMINFO_R_ERROR;
238 while (sqlite3_step(stmt) == SQLITE_ROW) {
239 info = calloc(1, sizeof(label_x));
241 LOGE("out of memory");
242 sqlite3_finalize(stmt);
243 return PMINFO_R_ERROR;
246 _save_column_str(stmt, idx++, &info->text);
247 _save_column_str(stmt, idx++, &info->lang);
248 *label = g_list_append(*label, info);
251 sqlite3_finalize(stmt);
256 static void _appinfo_modify_icon(const char *appid, const char **icon)
258 char buf[PKG_VALUE_STRING_LEN_MAX];
261 if (*icon == NULL || (*icon)[0] == '/' || !strcasecmp(*icon, "(null)"))
265 snprintf(buf, sizeof(buf), "%s%s.png", getIconPath(getuid()), appid);
270 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
273 static const char query_raw[] =
274 "SELECT app_icon, app_locale "
275 "FROM package_app_localized_info "
276 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
283 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
285 LOGE("out of memory");
286 return PMINFO_R_ERROR;
289 ret = sqlite3_prepare_v2(db, query, strlen(query),
292 if (ret != SQLITE_OK) {
293 LOGE("prepare failed: %s", sqlite3_errmsg(db));
294 return PMINFO_R_ERROR;
297 while (sqlite3_step(stmt) == SQLITE_ROW) {
298 info = calloc(1, sizeof(icon_x));
300 LOGE("out of memory");
301 sqlite3_finalize(stmt);
302 return PMINFO_R_ERROR;
305 _save_column_str(stmt, idx++, &info->text);
306 /* FIXME: this is a workaround. this must be removed later */
307 _appinfo_modify_icon(appid, &info->text);
308 _save_column_str(stmt, idx++, &info->lang);
309 *icon = g_list_append(*icon, info);
312 sqlite3_finalize(stmt);
317 static int _appinfo_get_category(sqlite3 *db, const char *appid,
320 static const char query_raw[] =
321 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
327 query = sqlite3_mprintf(query_raw, appid);
329 LOGE("out of memory");
330 return PMINFO_R_ERROR;
333 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
335 if (ret != SQLITE_OK) {
336 LOGE("prepare failed: %s", sqlite3_errmsg(db));
337 return PMINFO_R_ERROR;
340 while (sqlite3_step(stmt) == SQLITE_ROW) {
342 _save_column_str(stmt, 0, &val);
344 *category = g_list_append(*category, (gpointer)val);
347 sqlite3_finalize(stmt);
352 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
359 if (appcontrol_str == NULL)
362 dup = strdup(appcontrol_str);
364 ac = calloc(1, sizeof(appcontrol_x));
366 _LOGE("out of memory");
369 token = strtok_r(dup, "|", &ptr);
370 if (token && strcmp(token, "NULL"))
371 ac->operation = strdup(token);
372 token = strtok_r(NULL, "|", &ptr);
373 if (token && strcmp(token, "NULL"))
374 ac->uri = strdup(token);
375 token = strtok_r(NULL, "|", &ptr);
376 if (token && strcmp(token, "NULL"))
377 ac->mime = strdup(token);
378 *appcontrol = g_list_append(*appcontrol, ac);
379 } while ((token = strtok_r(NULL, ";", &ptr)));
384 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
387 static const char query_raw[] =
388 "SELECT app_control FROM package_app_app_control "
395 query = sqlite3_mprintf(query_raw, appid);
397 LOGE("out of memory");
398 return PMINFO_R_ERROR;
401 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
403 if (ret != SQLITE_OK) {
404 LOGE("prepare failed: %s", sqlite3_errmsg(db));
405 return PMINFO_R_ERROR;
408 while (sqlite3_step(stmt) == SQLITE_ROW) {
410 _save_column_str(stmt, 0, (const char **)&str);
412 __parse_appcontrol(appcontrol, str);
416 sqlite3_finalize(stmt);
421 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
424 static const char query_raw[] =
425 "SELECT providerid, access, type "
426 "FROM package_app_data_control WHERE app_id=%Q";
433 query = sqlite3_mprintf(query_raw, appid);
435 LOGE("out of memory");
436 return PMINFO_R_ERROR;
439 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
441 if (ret != SQLITE_OK) {
442 LOGE("prepare failed: %s", sqlite3_errmsg(db));
443 return PMINFO_R_ERROR;
446 while (sqlite3_step(stmt) == SQLITE_ROW) {
447 info = calloc(1, sizeof(datacontrol_x));
449 LOGE("out of memory");
450 sqlite3_finalize(stmt);
451 return PMINFO_R_ERROR;
454 _save_column_str(stmt, idx++, &info->providerid);
455 _save_column_str(stmt, idx++, &info->access);
456 _save_column_str(stmt, idx++, &info->type);
457 *datacontrol = g_list_append(*datacontrol, info);
460 sqlite3_finalize(stmt);
465 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
468 static const char query_raw[] =
469 "SELECT md_key, md_value "
470 "FROM package_app_app_metadata WHERE app_id=%Q";
477 query = sqlite3_mprintf(query_raw, appid);
479 LOGE("out of memory");
480 return PMINFO_R_ERROR;
483 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
485 if (ret != SQLITE_OK) {
486 LOGE("prepare failed: %s", sqlite3_errmsg(db));
487 return PMINFO_R_ERROR;
490 while (sqlite3_step(stmt) == SQLITE_ROW) {
491 info = calloc(1, sizeof(metadata_x));
493 LOGE("out of memory");
494 sqlite3_finalize(stmt);
495 return PMINFO_R_ERROR;
498 _save_column_str(stmt, idx++, &info->key);
499 _save_column_str(stmt, idx++, &info->value);
500 *metadata = g_list_append(*metadata, info);
503 sqlite3_finalize(stmt);
509 static GList *__get_background_category(char *value)
511 GList *category_list = NULL;
512 int convert_value = 0;
513 if (!value || strlen(value) == 0)
516 convert_value = atoi(value);
517 if (convert_value < 0)
520 if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
521 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
523 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
525 if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
526 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
528 if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
529 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
531 if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
532 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
534 if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
535 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
537 if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
538 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
540 if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
541 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
543 if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
544 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
546 return category_list;
550 static int _appinfo_get_application(sqlite3 *db, const char *appid,
551 const char *locale, application_x **application)
553 static const char query_raw[] =
554 "SELECT app_id, app_component, app_exec, app_nodisplay, "
555 "app_type, app_onboot, app_multiple, app_autorestart, "
556 "app_taskmanage, app_enabled, app_hwacceleration, "
557 "app_screenreader, app_mainapp, app_recentimage, "
558 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
559 "app_landscapeimg, app_guestmodevisibility, "
560 "app_permissiontype, app_preload, app_submode, "
561 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
562 "app_support_disable, "
563 "component_type, package, app_process_pool, app_installed_storage, "
564 "app_background_category, app_package_type "
565 "FROM package_app_info WHERE app_id='%s' AND app_disable='false' "
567 "(SELECT app_id from package_app_disable_for_user WHERE uid='%d')";
569 char query[MAX_QUERY_LEN] = { '\0' };
573 char *bg_category_str = NULL;
574 snprintf(query, MAX_QUERY_LEN - 1, query_raw, appid, (int)getuid());
575 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
576 if (ret != SQLITE_OK) {
577 LOGE("prepare failed: %s", sqlite3_errmsg(db));
578 return PMINFO_R_ERROR;
581 ret = sqlite3_step(stmt);
582 if (ret == SQLITE_DONE) {
583 sqlite3_finalize(stmt);
584 return PMINFO_R_ENOENT;
585 } else if (ret != SQLITE_ROW) {
586 LOGE("step failed: %s", sqlite3_errmsg(db));
587 sqlite3_finalize(stmt);
588 return PMINFO_R_ERROR;
591 info = calloc(1, sizeof(application_x));
593 LOGE("out of memory");
594 sqlite3_finalize(stmt);
595 return PMINFO_R_ERROR;
598 _save_column_str(stmt, idx++, &info->appid);
599 _save_column_str(stmt, idx++, &info->component);
600 _save_column_str(stmt, idx++, &info->exec);
601 _save_column_str(stmt, idx++, &info->nodisplay);
602 _save_column_str(stmt, idx++, &info->type);
603 _save_column_str(stmt, idx++, &info->onboot);
604 _save_column_str(stmt, idx++, &info->multiple);
605 _save_column_str(stmt, idx++, &info->autorestart);
606 _save_column_str(stmt, idx++, &info->taskmanage);
607 _save_column_str(stmt, idx++, &info->enabled);
608 _save_column_str(stmt, idx++, &info->hwacceleration);
609 _save_column_str(stmt, idx++, &info->screenreader);
610 _save_column_str(stmt, idx++, &info->mainapp);
611 _save_column_str(stmt, idx++, &info->recentimage);
612 _save_column_str(stmt, idx++, &info->launchcondition);
613 _save_column_str(stmt, idx++, &info->indicatordisplay);
614 _save_column_str(stmt, idx++, &info->portraitimg);
615 _save_column_str(stmt, idx++, &info->landscapeimg);
616 _save_column_str(stmt, idx++, &info->guestmode_visibility);
617 _save_column_str(stmt, idx++, &info->permission_type);
618 _save_column_str(stmt, idx++, &info->preload);
619 _save_column_str(stmt, idx++, &info->submode);
620 _save_column_str(stmt, idx++, &info->submode_mainid);
621 _save_column_str(stmt, idx++, &info->launch_mode);
622 _save_column_str(stmt, idx++, &info->ui_gadget);
623 _save_column_str(stmt, idx++, &info->support_disable);
624 _save_column_str(stmt, idx++, &info->component_type);
625 _save_column_str(stmt, idx++, &info->package);
626 _save_column_str(stmt, idx++, &info->process_pool);
627 _save_column_str(stmt, idx++, &info->installed_storage);
628 _save_column_str(stmt, idx++, &bg_category_str);
629 _save_column_str(stmt, idx++, &info->package_type);
631 info->background_category = __get_background_category(bg_category_str);
633 if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
634 pkgmgrinfo_basic_free_application(info);
635 sqlite3_finalize(stmt);
636 return PMINFO_R_ERROR;
639 if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
640 pkgmgrinfo_basic_free_application(info);
641 sqlite3_finalize(stmt);
642 return PMINFO_R_ERROR;
645 if (_appinfo_get_category(db, info->appid, &info->category)) {
646 pkgmgrinfo_basic_free_application(info);
647 sqlite3_finalize(stmt);
648 return PMINFO_R_ERROR;
651 if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
652 pkgmgrinfo_basic_free_application(info);
653 sqlite3_finalize(stmt);
654 return PMINFO_R_ERROR;
657 if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
658 pkgmgrinfo_basic_free_application(info);
659 sqlite3_finalize(stmt);
660 return PMINFO_R_ERROR;
663 if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
664 pkgmgrinfo_basic_free_application(info);
665 sqlite3_finalize(stmt);
666 return PMINFO_R_ERROR;
671 sqlite3_finalize(stmt);
676 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
677 pkgmgr_appinfo_x **appinfo)
683 pkgmgr_appinfo_x *info;
685 dbpath = getUserPkgParserDBPathUID(uid);
687 return PMINFO_R_ERROR;
689 locale = _get_system_locale();
691 return PMINFO_R_ERROR;
693 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
694 if (ret != SQLITE_OK) {
695 _LOGE("failed to open db: %d", ret);
697 return PMINFO_R_ERROR;
700 info = calloc(1, sizeof(pkgmgr_appinfo_x));
702 _LOGE("out of memory");
704 sqlite3_close_v2(db);
705 return PMINFO_R_ERROR;
708 ret = _appinfo_get_application(db, appid, locale, &info->app_info);
709 if (ret != PMINFO_R_OK) {
712 sqlite3_close_v2(db);
716 info->locale = locale;
717 info->package = strdup(info->app_info->package);
721 sqlite3_close_v2(db);
726 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
728 application_x *app_info;
730 app_info = calloc(1, sizeof(application_x));
731 if (app_info == NULL) {
732 LOGE("memory alloc failed");
733 return PMINFO_R_ERROR;
736 if (data->appid != NULL)
737 app_info->appid = strdup(data->appid);
738 if (data->exec != NULL)
739 app_info->exec = strdup(data->exec);
740 if (data->nodisplay != NULL)
741 app_info->nodisplay = strdup(data->nodisplay);
742 if (data->multiple != NULL)
743 app_info->multiple = strdup(data->multiple);
744 if (data->taskmanage != NULL)
745 app_info->taskmanage = strdup(data->taskmanage);
746 if (data->enabled != NULL)
747 app_info->enabled = strdup(data->enabled);
748 if (data->type != NULL)
749 app_info->type = strdup(data->type);
750 if (data->categories != NULL)
751 app_info->categories = strdup(data->categories);
752 if (data->extraid != NULL)
753 app_info->extraid = strdup(data->extraid);
754 if (data->hwacceleration != NULL)
755 app_info->hwacceleration = strdup(data->hwacceleration);
756 if (data->screenreader != NULL)
757 app_info->screenreader = strdup(data->screenreader);
758 if (data->mainapp != NULL)
759 app_info->mainapp = strdup(data->mainapp);
760 if (data->package != NULL)
761 app_info->package = strdup(data->package);
762 if (data->recentimage != NULL)
763 app_info->recentimage = strdup(data->recentimage);
764 if (data->launchcondition != NULL)
765 app_info->launchcondition = strdup(data->launchcondition);
766 if (data->indicatordisplay != NULL)
767 app_info->indicatordisplay = strdup(data->indicatordisplay);
768 if (data->portraitimg != NULL)
769 app_info->portraitimg = strdup(data->portraitimg);
770 if (data->landscapeimg != NULL)
771 app_info->landscapeimg = strdup(data->landscapeimg);
772 if (data->effectimage_type != NULL)
773 app_info->effectimage_type = strdup(data->effectimage_type);
774 if (data->guestmode_visibility != NULL)
775 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
776 if (data->component != NULL)
777 app_info->component = strdup(data->component);
778 if (data->permission_type != NULL)
779 app_info->permission_type = strdup(data->permission_type);
780 if (data->component_type != NULL)
781 app_info->component_type = strdup(data->component_type);
782 if (data->preload != NULL)
783 app_info->preload = strdup(data->preload);
784 if (data->submode != NULL)
785 app_info->submode = strdup(data->submode);
786 if (data->submode_mainid != NULL)
787 app_info->submode_mainid = strdup(data->submode_mainid);
788 if (data->process_pool != NULL)
789 app_info->process_pool = strdup(data->process_pool);
790 if (data->installed_storage != NULL)
791 app_info->installed_storage = strdup(data->installed_storage);
792 if (data->autorestart != NULL)
793 app_info->autorestart = strdup(data->autorestart);
794 if (data->onboot != NULL)
795 app_info->onboot = strdup(data->onboot);
796 if (data->support_disable != NULL)
797 app_info->support_disable = strdup(data->support_disable);
798 if (data->ui_gadget != NULL)
799 app_info->ui_gadget = strdup(data->ui_gadget);
800 if (data->launch_mode != NULL)
801 app_info->launch_mode = strdup(data->launch_mode);
802 if (data->ambient_support != NULL)
803 app_info->ambient_support = strdup(data->ambient_support);
804 if (data->alias_appid != NULL)
805 app_info->alias_appid = strdup(data->alias_appid);
806 if (data->effective_appid != NULL)
807 app_info->effective_appid = strdup(data->effective_appid);
809 app_info->label = g_list_copy(data->label);
810 app_info->icon = g_list_copy(data->icon);
811 app_info->image = g_list_copy(data->image);
812 app_info->category = g_list_copy(data->category);
813 app_info->metadata = g_list_copy(data->metadata);
814 app_info->permission = g_list_copy(data->permission);
815 app_info->launchconditions = g_list_copy(data->launchconditions);
816 app_info->notification = g_list_copy(data->notification);
817 app_info->datashare = g_list_copy(data->datashare);
818 app_info->datacontrol = g_list_copy(data->datacontrol);
819 app_info->background_category = g_list_copy(data->background_category);
820 app_info->appcontrol = g_list_copy(data->appcontrol);
822 *application = app_info;
827 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
828 pkgmgrinfo_appinfo_h *handle)
832 if (appid == NULL || handle == NULL) {
833 LOGE("invalid parameter");
834 return PMINFO_R_EINVAL;
837 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
838 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
839 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
840 (pkgmgr_appinfo_x **)handle);
842 if (ret != PMINFO_R_OK)
843 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
848 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
850 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
853 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
854 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
858 pkgmgr_appinfo_x *info;
864 ret = _appinfo_get_filtered_list(filter, uid, &list);
865 if (ret != PMINFO_R_OK)
866 return PMINFO_R_ERROR;
868 for (tmp = list; tmp; tmp = tmp->next) {
869 appid = (char *)tmp->data;
871 ret = _appinfo_get_appinfo(appid, uid, &info);
872 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
873 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
875 if (ret != PMINFO_R_OK) {
879 if (app_list_cb(info, user_data) < 0)
881 pkgmgrinfo_appinfo_destroy_appinfo(info);
891 API int pkgmgrinfo_appinfo_get_clone(pkgmgrinfo_appinfo_h *clone,
892 pkgmgrinfo_appinfo_h handle)
894 pkgmgr_appinfo_x *info;
895 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
898 return PMINFO_R_EINVAL;
900 info = calloc(1, sizeof(pkgmgr_appinfo_x));
902 LOGE("memory alloc failed");
903 return PMINFO_R_ERROR;
906 if (temp->package != NULL)
907 info->package = strdup(temp->package);
908 if (temp->locale != NULL)
909 info->locale = strdup(temp->locale);
911 info->app_component = temp->app_component;
913 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
914 LOGE("appinfo copy failed");
920 return PMINFO_R_ERROR;
928 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
929 pkgmgrinfo_app_component component,
930 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
933 pkgmgrinfo_appinfo_filter_h filter;
935 const char *comp_str = NULL;
937 if (handle == NULL || app_func == NULL) {
938 LOGE("invalid parameter");
939 return PMINFO_R_EINVAL;
942 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
943 LOGE("invalid parameter");
944 return PMINFO_R_EINVAL;
947 if (pkgmgrinfo_appinfo_filter_create(&filter))
948 return PMINFO_R_ERROR;
950 if (pkgmgrinfo_appinfo_filter_add_string(filter,
951 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
952 pkgmgrinfo_appinfo_filter_destroy(filter);
953 return PMINFO_R_ERROR;
956 if (uid == GLOBAL_USER) {
957 if (pkgmgrinfo_appinfo_filter_add_int(filter,
958 PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) {
959 pkgmgrinfo_appinfo_filter_destroy(filter);
960 return PMINFO_R_ERROR;
966 comp_str = PMINFO_APPINFO_UI_APP;
969 comp_str = PMINFO_APPINFO_SVC_APP;
976 if (pkgmgrinfo_appinfo_filter_add_string(filter,
977 PMINFO_APPINFO_PROP_APP_COMPONENT,
979 pkgmgrinfo_appinfo_filter_destroy(filter);
980 return PMINFO_R_ERROR;
984 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
987 pkgmgrinfo_appinfo_filter_destroy(filter);
992 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
993 pkgmgrinfo_app_list_cb app_func, void *user_data)
995 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
998 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1000 if (app_func == NULL) {
1001 LOGE("invalid parameter");
1002 return PMINFO_R_EINVAL;
1005 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1009 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1011 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
1014 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1016 if (app_func == NULL) {
1017 LOGE("invalid parameter");
1018 return PMINFO_R_EINVAL;
1021 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1025 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1027 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
1030 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1032 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1034 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1035 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1037 if (info->app_info == NULL || info->app_info->appid == NULL)
1038 return PMINFO_R_ERROR;
1039 *appid = (char *)info->app_info->appid;
1044 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1046 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1048 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1049 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1051 if (info->package == NULL)
1052 return PMINFO_R_ERROR;
1054 *pkg_name = (char *)info->package;
1059 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1061 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1063 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1064 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1066 if (info->package == NULL)
1067 return PMINFO_R_ERROR;
1069 *pkgid = (char *)info->package;
1074 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1076 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1077 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1078 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1080 *pkgtype = (char *)info->app_info->package_type;
1085 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1087 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1089 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1090 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1092 if (info->app_info == NULL || info->app_info->exec == NULL)
1093 return PMINFO_R_ERROR;
1094 *exec = (char *)info->app_info->exec;
1100 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1105 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1108 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1110 locale = info->locale;
1111 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1113 if (info->app_info == NULL)
1114 return PMINFO_R_ERROR;
1116 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1117 ptr = (icon_x *)tmp->data;
1118 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1119 !strcasecmp(ptr->text, "(null)") ||
1120 strcmp(ptr->lang, locale))
1122 *icon = (char *)ptr->text;
1126 locale = DEFAULT_LOCALE;
1127 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1128 ptr = (icon_x *)tmp->data;
1129 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1130 strcmp(ptr->lang, locale))
1132 *icon = (char *)ptr->text;
1136 return PMINFO_R_ERROR;
1140 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1145 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1147 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1148 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1150 locale = info->locale;
1151 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1153 if (info->app_info == NULL)
1154 return PMINFO_R_ERROR;
1156 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1157 ptr = (label_x *)tmp->data;
1158 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1159 strcmp(ptr->lang, locale))
1161 *label = (char *)ptr->text;
1165 locale = DEFAULT_LOCALE;
1166 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1167 ptr = (label_x *)tmp->data;
1168 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1169 strcmp(ptr->lang, locale))
1171 *label = (char *)ptr->text;
1175 return PMINFO_R_ERROR;
1178 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1180 char *result = NULL;
1182 sqlite3_stmt *stmt = NULL;
1185 const char *manifest_db;
1187 manifest_db = getUserPkgParserDBPathUID(uid);
1188 if (manifest_db == NULL) {
1189 _LOGE("Failed to get manifest db path");
1193 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1194 _LOGE("DB open fail\n");
1198 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1199 if (query == NULL) {
1200 _LOGE("Out of memory");
1204 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1205 _LOGE("prepare_v2 fail\n");
1209 if (sqlite3_step(stmt) == SQLITE_ROW) {
1210 val = (char *)sqlite3_column_text(stmt, 0);
1212 result = strdup(val);
1216 sqlite3_finalize(stmt);
1217 sqlite3_free(query);
1223 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1227 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1229 val = _get_localed_label(appid, locale, uid);
1231 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1234 return PMINFO_R_ERROR;
1241 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1243 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1246 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1248 if ( strcasecmp(comp, "uiapp") == 0)
1249 return PMINFO_UI_APP;
1250 else if ( strcasecmp(comp, "svcapp") == 0)
1251 return PMINFO_SVC_APP;
1256 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1258 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1261 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1262 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1264 if (info->app_info == NULL)
1265 return PMINFO_R_ERROR;
1267 comp = __appcomponent_convert(info->app_info->component);
1269 return PMINFO_R_ERROR;
1276 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1278 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1280 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1281 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1283 if (info->app_info == NULL || info->app_info->type == NULL)
1284 return PMINFO_R_ERROR;
1285 *app_type = (char *)info->app_info->type;
1290 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1291 int *operation_count, char ***operation)
1293 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1294 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1295 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1296 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1297 *operation_count = data->operation_count;
1298 *operation = data->operation;
1302 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1303 int *uri_count, char ***uri)
1305 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1306 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1307 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1308 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1309 *uri_count = data->uri_count;
1314 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1315 int *mime_count, char ***mime)
1317 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1318 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1319 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1320 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1321 *mime_count = data->mime_count;
1326 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1327 int *subapp_count, char ***subapp)
1329 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1330 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1331 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1332 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1333 *subapp_count = data->subapp_count;
1334 *subapp = data->subapp;
1338 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1343 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1345 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1346 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1348 if (info->app_info == NULL)
1349 return PMINFO_R_ERROR;
1351 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1352 ptr = (icon_x *)tmp->data;
1353 if (ptr == NULL || ptr->section == NULL)
1356 val = (char *)ptr->section;
1357 if (val && strcmp(val, "setting") == 0) {
1358 *icon = (char *)ptr->text;
1363 return PMINFO_R_ERROR;
1367 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1372 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1374 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1375 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1377 if (info->app_info == NULL)
1378 return PMINFO_R_ERROR;
1380 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1381 ptr = (icon_x *)tmp->data;
1382 if (ptr == NULL || ptr->section == NULL)
1385 val = (char *)ptr->section;
1386 if (val && strcmp(val, "notification") == 0){
1387 *icon = (char *)ptr->text;
1392 return PMINFO_R_ERROR;
1395 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1398 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1400 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1401 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1403 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1404 return PMINFO_R_ERROR;
1406 val = (char *)info->app_info->recentimage;
1407 if (strcasecmp(val, "capture") == 0)
1408 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1409 else if (strcasecmp(val, "icon") == 0)
1410 *type = PMINFO_RECENTIMAGE_USE_ICON;
1412 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1417 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1422 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1424 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1425 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1427 if (info->app_info == NULL)
1428 return PMINFO_R_ERROR;
1430 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1431 ptr = (image_x *)tmp->data;
1432 if (ptr == NULL || ptr->section == NULL)
1435 val = (char *)ptr->section;
1436 if (val && strcmp(val, "preview") == 0) {
1437 *preview_img = (char *)ptr->text;
1442 return PMINFO_R_ERROR;
1445 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1448 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1450 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1451 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1453 val = info->app_info->permission_type;
1455 return PMINFO_R_ERROR;
1457 if (strcmp(val, "signature") == 0)
1458 *permission = PMINFO_PERMISSION_SIGNATURE;
1459 else if (strcmp(val, "privilege") == 0)
1460 *permission = PMINFO_PERMISSION_PRIVILEGE;
1462 *permission = PMINFO_PERMISSION_NORMAL;
1467 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1469 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1471 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1472 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1474 if (info->app_info == NULL || info->app_info->component_type == NULL)
1475 return PMINFO_R_ERROR;
1477 *component_type = (char *)info->app_info->component_type;
1482 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1485 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1487 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1488 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1490 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1491 return PMINFO_R_ERROR;
1493 val = (char *)info->app_info->hwacceleration;
1494 if (strcasecmp(val, "not-use-GL") == 0)
1495 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1496 else if (strcasecmp(val, "use-GL") == 0)
1497 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1499 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1504 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1507 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1509 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1510 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1512 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1513 return PMINFO_R_ERROR;
1515 val = (char *)info->app_info->screenreader;
1516 if (strcasecmp(val, "screenreader-off") == 0)
1517 *screenreader = PMINFO_SCREENREADER_OFF;
1518 else if (strcasecmp(val, "screenreader-on") == 0)
1519 *screenreader = PMINFO_SCREENREADER_ON;
1521 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1526 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1528 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1530 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1531 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1532 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1534 if (info->app_info == NULL || info->app_info->portraitimg ||
1535 info->app_info->landscapeimg == NULL)
1536 return PMINFO_R_ERROR;
1538 *portrait_img = (char *)info->app_info->portraitimg;
1539 *landscape_img = (char *)info->app_info->landscapeimg;
1544 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1546 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1548 if (handle == NULL || effectimage_type == NULL) {
1549 LOGE("invalid parameter");
1550 return PMINFO_R_EINVAL;
1553 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1554 return PMINFO_R_ERROR;
1556 *effectimage_type = (char *)info->app_info->effectimage_type;
1561 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1563 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1565 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1566 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1568 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1569 return PMINFO_R_ERROR;
1571 *submode_mainid = (char *)info->app_info->submode_mainid;
1576 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1579 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1581 if (info->app_info && info->app_info->installed_storage){
1582 if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
1583 *storage = PMINFO_INTERNAL_STORAGE;
1584 else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
1585 *storage = PMINFO_EXTERNAL_STORAGE;
1587 return PMINFO_R_ERROR;
1589 return PMINFO_R_ERROR;
1594 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1596 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1598 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1599 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1601 if (info->app_info->launch_mode == NULL)
1602 return PMINFO_R_ERROR;
1604 *mode = (char *)(info->app_info->launch_mode);
1609 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
1611 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1613 if (handle == NULL || alias_appid == NULL) {
1614 LOGE("invalid parameter");
1615 return PMINFO_R_EINVAL;
1618 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
1619 return PMINFO_R_ERROR;
1621 *alias_appid = (char *)info->app_info->alias_appid;
1626 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
1628 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1630 if (handle == NULL || effective_appid == NULL) {
1631 LOGE("invalid parameter");
1632 return PMINFO_R_EINVAL;
1635 if (info->app_info == NULL || info->app_info->effective_appid == NULL)
1636 return PMINFO_R_ERROR;
1638 *effective_appid = (char *)info->app_info->effective_appid;
1643 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1645 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1646 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1647 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1648 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1650 int ret = PMINFO_R_OK;
1652 sqlite3_stmt *stmt = NULL;
1655 ret = __open_manifest_db(uid, true);
1656 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1658 /*Start constructing query*/
1659 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1662 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1663 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1666 ret = sqlite3_step(stmt);
1667 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1669 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1670 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1675 sqlite3_free(query);
1676 sqlite3_finalize(stmt);
1677 __close_manifest_db();
1681 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1683 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1686 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1688 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1689 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1691 int ret = PMINFO_R_OK;
1693 sqlite3_stmt *stmt = NULL;
1696 ret = __open_manifest_db(uid, true);
1697 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1699 /*Start constructing query*/
1700 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1703 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1704 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1707 ret = sqlite3_step(stmt);
1708 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1710 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1715 sqlite3_free(query);
1716 sqlite3_finalize(stmt);
1717 __close_manifest_db();
1721 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1723 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1726 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1727 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1729 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1730 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1734 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1736 if (info->app_info == NULL)
1737 return PMINFO_R_ERROR;
1739 for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
1740 ptr = (permission_x *)tmp->data;
1744 ret = permission_func(ptr->value, user_data);
1752 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1753 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1755 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1756 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1758 const char *category;
1760 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1762 if (info->app_info == NULL)
1763 return PMINFO_R_ERROR;
1765 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1766 category = (const char *)tmp->data;
1768 ret = category_func(category, user_data);
1776 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1777 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1779 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1780 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1784 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1786 if (info->app_info == NULL)
1787 return PMINFO_R_ERROR;
1789 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1790 ptr = (metadata_x *)tmp->data;
1794 ret = metadata_func(ptr->key, ptr->value, user_data);
1802 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1803 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1805 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1806 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1808 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1809 appcontrol_x *appcontrol;
1812 if (info->app_info == NULL)
1813 return PMINFO_R_ERROR;
1815 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1816 appcontrol = (appcontrol_x *)tmp->data;
1817 if (appcontrol == NULL)
1819 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1827 API int pkgmgrinfo_appinfo_foreach_background_category(
1828 pkgmgrinfo_appinfo_h handle,
1829 pkgmgrinfo_app_background_category_list_cb category_func,
1832 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1836 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
1837 LOGE("invalid parameter");
1838 return PMINFO_R_EINVAL;
1841 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
1842 category = (char *)tmp->data;
1843 if (category == NULL)
1846 if (category_func(category, user_data) < 0)
1853 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1855 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1856 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1857 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1859 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1860 return PMINFO_R_ERROR;
1862 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1867 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1869 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1870 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1871 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1873 if (info->app_info == NULL || info->app_info->multiple == NULL)
1874 return PMINFO_R_ERROR;
1876 *multiple = _get_bool_value(info->app_info->multiple);
1881 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1883 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1884 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1885 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1887 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1888 return PMINFO_R_ERROR;
1890 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1895 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1897 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1898 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1899 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1901 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1902 return PMINFO_R_ERROR;
1904 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1909 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1911 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1912 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1913 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1915 if (info->app_info == NULL || info->app_info->enabled == NULL)
1916 return PMINFO_R_ERROR;
1918 *enabled = _get_bool_value(info->app_info->enabled);
1923 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1926 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1927 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1929 if (info->app_info == NULL || info->app_info->onboot == NULL)
1930 return PMINFO_R_ERROR;
1932 *onboot = _get_bool_value(info->app_info->onboot);
1937 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1939 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1940 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1941 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1943 if (info->app_info == NULL || info->app_info->autorestart == NULL)
1944 return PMINFO_R_ERROR;
1946 *autorestart = _get_bool_value(info->app_info->autorestart);
1951 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1953 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1954 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1955 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1957 if (info->app_info == NULL || info->app_info->mainapp == NULL)
1958 return PMINFO_R_ERROR;
1960 *mainapp = _get_bool_value(info->app_info->mainapp);
1965 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1967 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1968 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1969 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1971 if (info->app_info == NULL || info->app_info->preload == NULL)
1972 return PMINFO_R_ERROR;
1974 *preload = _get_bool_value(info->app_info->preload);
1979 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1981 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1982 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1983 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1985 if (info->app_info == NULL || info->app_info->submode == NULL)
1986 return PMINFO_R_ERROR;
1988 *submode = _get_bool_value(info->app_info->submode);
1993 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
1995 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1997 if (handle == NULL || process_pool == NULL) {
1998 LOGE("invalid parameter");
1999 return PMINFO_R_EINVAL;
2002 if (info->app_info == NULL)
2003 return PMINFO_R_ERROR;
2005 *process_pool = _get_bool_value(info->app_info->process_pool);
2010 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2012 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2013 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2014 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2018 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2020 if (info->app_info == NULL)
2021 return PMINFO_R_ERROR;
2024 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2025 val = (const char *)tmp->data;
2028 if (strcasecmp(val, category) == 0) {
2037 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2040 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2042 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2043 _LOGE("invalid parameter");
2044 return PMINFO_R_EINVAL;
2047 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2052 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2053 bool *support_disable)
2055 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2057 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2058 _LOGE("invalid parameter");
2059 return PMINFO_R_EINVAL;
2062 *support_disable = _get_bool_value(info->app_info->support_disable);
2067 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2069 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2070 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2071 __cleanup_appinfo(info);
2075 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2077 return (pkgmgrinfo_pkginfo_filter_create(handle));
2080 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2082 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2085 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2087 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
2088 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
2089 if (node1->prop == node2->prop)
2091 else if (node1->prop > node2->prop)
2097 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2098 const char *property, const int value)
2100 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2101 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2102 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2104 GSList *link = NULL;
2106 prop = _pminfo_appinfo_convert_to_prop_int(property);
2107 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2108 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2109 _LOGE("Invalid Integer Property\n");
2110 return PMINFO_R_EINVAL;
2112 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2113 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2115 _LOGE("Out of Memory!!!\n");
2116 return PMINFO_R_ERROR;
2118 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2119 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2121 _LOGE("Out of Memory\n");
2124 return PMINFO_R_ERROR;
2128 /*If API is called multiple times for same property, we should override the previous values.
2129 Last value set will be used for filtering.*/
2130 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2132 filter->list = g_slist_delete_link(filter->list, link);
2133 filter->list = g_slist_append(filter->list, (gpointer)node);
2138 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2139 const char *property, const bool value)
2141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2142 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2144 GSList *link = NULL;
2146 prop = _pminfo_appinfo_convert_to_prop_bool(property);
2147 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2148 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2149 _LOGE("Invalid Boolean Property\n");
2150 return PMINFO_R_EINVAL;
2152 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2153 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2155 _LOGE("Out of Memory!!!\n");
2156 return PMINFO_R_ERROR;
2159 val = strndup("('true','True')", 15);
2161 val = strndup("('false','False')", 17);
2163 _LOGE("Out of Memory\n");
2166 return PMINFO_R_ERROR;
2170 /*If API is called multiple times for same property, we should override the previous values.
2171 Last value set will be used for filtering.*/
2172 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2174 filter->list = g_slist_delete_link(filter->list, link);
2175 filter->list = g_slist_append(filter->list, (gpointer)node);
2180 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2181 const char *property, const char *value)
2183 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2184 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2185 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2187 pkgmgrinfo_node_x *ptr = NULL;
2188 char prev[PKG_STRING_LEN_MAX] = {'\0'};
2189 char temp[PKG_STRING_LEN_MAX] = {'\0'};
2190 GSList *link = NULL;
2192 prop = _pminfo_appinfo_convert_to_prop_str(property);
2193 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2194 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2195 _LOGE("Invalid String Property\n");
2196 return PMINFO_R_EINVAL;
2198 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2199 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2201 _LOGE("Out of Memory!!!\n");
2202 return PMINFO_R_ERROR;
2206 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2207 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
2208 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
2210 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
2212 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2214 filter->list = g_slist_delete_link(filter->list, link);
2215 filter->list = g_slist_append(filter->list, (gpointer)node);
2217 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2218 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
2219 case E_PMINFO_APPINFO_PROP_APP_URI:
2220 case E_PMINFO_APPINFO_PROP_APP_MIME:
2221 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2223 _LOGE("Out of Memory\n");
2226 return PMINFO_R_ERROR;
2228 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2230 ptr = (pkgmgrinfo_node_x *)link->data;
2231 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2232 _LOGE("Previous value is %s\n", prev);
2233 filter->list = g_slist_delete_link(filter->list, link);
2234 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
2235 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2236 _LOGE("New value is %s\n", val);
2238 filter->list = g_slist_append(filter->list, (gpointer)node);
2239 memset(temp, '\0', PKG_STRING_LEN_MAX);
2241 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
2242 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2243 _LOGE("First value is %s\n", val);
2245 filter->list = g_slist_append(filter->list, (gpointer)node);
2246 memset(temp, '\0', PKG_STRING_LEN_MAX);
2250 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2251 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2253 filter->list = g_slist_delete_link(filter->list, link);
2254 filter->list = g_slist_append(filter->list, (gpointer)node);
2260 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2265 if (handle == NULL || count == NULL) {
2266 _LOGE("invalid parameter");
2267 return PMINFO_R_EINVAL;
2270 ret = _appinfo_get_filtered_list(handle, uid, &list);
2271 if (ret != PMINFO_R_OK)
2272 return PMINFO_R_ERROR;
2274 *count = g_list_length(list);
2276 g_list_free_full(list, free);
2281 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2283 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
2286 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2287 pkgmgrinfo_appinfo_filter_h handle,
2288 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2290 if (handle == NULL || app_cb == NULL) {
2291 LOGE("invalid parameter");
2292 return PMINFO_R_EINVAL;
2295 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2299 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2300 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2302 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2305 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2307 return (pkgmgrinfo_pkginfo_filter_create(handle));
2310 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2312 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2315 API int pkgmgrinfo_appinfo_metadata_filter_add(
2316 pkgmgrinfo_appinfo_metadata_filter_h handle,
2317 const char *key, const char *value)
2321 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2322 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2323 if (ret != PMINFO_R_OK)
2326 /* value can be NULL.
2327 * In that case all apps with specified key should be displayed
2330 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2331 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2332 if (ret != PMINFO_R_OK)
2339 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2340 pkgmgrinfo_appinfo_metadata_filter_h handle,
2341 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2343 if (handle == NULL || app_cb == NULL) {
2344 LOGE("invalid parameter");
2345 return PMINFO_R_EINVAL;
2348 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2352 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2353 pkgmgrinfo_appinfo_metadata_filter_h handle,
2354 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2356 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2357 user_data, GLOBAL_USER);
2360 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2363 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2365 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2366 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2368 val = info->app_info->guestmode_visibility;
2369 *status = _get_bool_value(val);