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 int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
259 static const char query_raw[] =
260 "SELECT app_icon, app_locale "
261 "FROM package_app_localized_info "
262 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
269 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
271 LOGE("out of memory");
272 return PMINFO_R_ERROR;
275 ret = sqlite3_prepare_v2(db, query, strlen(query),
278 if (ret != SQLITE_OK) {
279 LOGE("prepare failed: %s", sqlite3_errmsg(db));
280 return PMINFO_R_ERROR;
283 while (sqlite3_step(stmt) == SQLITE_ROW) {
284 info = calloc(1, sizeof(icon_x));
286 LOGE("out of memory");
287 sqlite3_finalize(stmt);
288 return PMINFO_R_ERROR;
291 _save_column_str(stmt, idx++, &info->text);
292 _save_column_str(stmt, idx++, &info->lang);
293 *icon = g_list_append(*icon, info);
296 sqlite3_finalize(stmt);
301 static int _appinfo_get_category(sqlite3 *db, const char *appid,
304 static const char query_raw[] =
305 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
311 query = sqlite3_mprintf(query_raw, appid);
313 LOGE("out of memory");
314 return PMINFO_R_ERROR;
317 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
319 if (ret != SQLITE_OK) {
320 LOGE("prepare failed: %s", sqlite3_errmsg(db));
321 return PMINFO_R_ERROR;
324 while (sqlite3_step(stmt) == SQLITE_ROW) {
326 _save_column_str(stmt, 0, &val);
328 *category = g_list_append(*category, (gpointer)val);
331 sqlite3_finalize(stmt);
336 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
343 if (appcontrol_str == NULL)
346 dup = strdup(appcontrol_str);
348 ac = calloc(1, sizeof(appcontrol_x));
350 _LOGE("out of memory");
353 token = strtok_r(dup, "|", &ptr);
354 if (token && strcmp(token, "NULL"))
355 ac->operation = strdup(token);
356 token = strtok_r(NULL, "|", &ptr);
357 if (token && strcmp(token, "NULL"))
358 ac->uri = strdup(token);
359 token = strtok_r(NULL, "|", &ptr);
360 if (token && strcmp(token, "NULL"))
361 ac->mime = strdup(token);
362 *appcontrol = g_list_append(*appcontrol, ac);
363 } while ((token = strtok_r(NULL, ";", &ptr)));
368 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
371 static const char query_raw[] =
372 "SELECT app_control FROM package_app_app_control "
379 query = sqlite3_mprintf(query_raw, appid);
381 LOGE("out of memory");
382 return PMINFO_R_ERROR;
385 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
387 if (ret != SQLITE_OK) {
388 LOGE("prepare failed: %s", sqlite3_errmsg(db));
389 return PMINFO_R_ERROR;
392 while (sqlite3_step(stmt) == SQLITE_ROW) {
394 _save_column_str(stmt, 0, (const char **)&str);
396 __parse_appcontrol(appcontrol, str);
400 sqlite3_finalize(stmt);
405 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
408 static const char query_raw[] =
409 "SELECT providerid, access, type "
410 "FROM package_app_data_control WHERE app_id=%Q";
417 query = sqlite3_mprintf(query_raw, appid);
419 LOGE("out of memory");
420 return PMINFO_R_ERROR;
423 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
425 if (ret != SQLITE_OK) {
426 LOGE("prepare failed: %s", sqlite3_errmsg(db));
427 return PMINFO_R_ERROR;
430 while (sqlite3_step(stmt) == SQLITE_ROW) {
431 info = calloc(1, sizeof(datacontrol_x));
433 LOGE("out of memory");
434 sqlite3_finalize(stmt);
435 return PMINFO_R_ERROR;
438 _save_column_str(stmt, idx++, &info->providerid);
439 _save_column_str(stmt, idx++, &info->access);
440 _save_column_str(stmt, idx++, &info->type);
441 *datacontrol = g_list_append(*datacontrol, info);
444 sqlite3_finalize(stmt);
449 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
452 static const char query_raw[] =
453 "SELECT md_key, md_value "
454 "FROM package_app_app_metadata WHERE app_id=%Q";
461 query = sqlite3_mprintf(query_raw, appid);
463 LOGE("out of memory");
464 return PMINFO_R_ERROR;
467 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
469 if (ret != SQLITE_OK) {
470 LOGE("prepare failed: %s", sqlite3_errmsg(db));
471 return PMINFO_R_ERROR;
474 while (sqlite3_step(stmt) == SQLITE_ROW) {
475 info = calloc(1, sizeof(metadata_x));
477 LOGE("out of memory");
478 sqlite3_finalize(stmt);
479 return PMINFO_R_ERROR;
482 _save_column_str(stmt, idx++, &info->key);
483 _save_column_str(stmt, idx++, &info->value);
484 *metadata = g_list_append(*metadata, info);
487 sqlite3_finalize(stmt);
493 static int _appinfo_get_application(sqlite3 *db, const char *appid,
494 const char *locale, application_x **application)
496 static const char query_raw[] =
497 "SELECT app_id, app_component, app_exec, app_nodisplay, "
498 "app_type, app_onboot, app_multiple, app_autorestart, "
499 "app_taskmanage, app_enabled, app_hwacceleration, "
500 "app_screenreader, app_mainapp, app_recentimage, "
501 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
502 "app_landscapeimg, app_guestmodevisibility, "
503 "app_permissiontype, app_preload, app_submode, "
504 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
505 "app_support_disable, "
506 "component_type, package, app_process_pool, app_installed_storage "
507 "FROM package_app_info WHERE app_id=%Q";
514 query = sqlite3_mprintf(query_raw, appid);
516 LOGE("out of memory");
517 return PMINFO_R_ERROR;
520 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
522 if (ret != SQLITE_OK) {
523 LOGE("prepare failed: %s", sqlite3_errmsg(db));
524 return PMINFO_R_ERROR;
527 ret = sqlite3_step(stmt);
528 if (ret == SQLITE_DONE) {
529 sqlite3_finalize(stmt);
530 return PMINFO_R_ENOENT;
531 } else if (ret != SQLITE_ROW) {
532 LOGE("step failed: %s", sqlite3_errmsg(db));
533 sqlite3_finalize(stmt);
534 return PMINFO_R_ERROR;
537 info = calloc(1, sizeof(application_x));
539 LOGE("out of memory");
540 sqlite3_finalize(stmt);
541 return PMINFO_R_ERROR;
544 _save_column_str(stmt, idx++, &info->appid);
545 _save_column_str(stmt, idx++, &info->component);
546 _save_column_str(stmt, idx++, &info->exec);
547 _save_column_str(stmt, idx++, &info->nodisplay);
548 _save_column_str(stmt, idx++, &info->type);
549 _save_column_str(stmt, idx++, &info->onboot);
550 _save_column_str(stmt, idx++, &info->multiple);
551 _save_column_str(stmt, idx++, &info->autorestart);
552 _save_column_str(stmt, idx++, &info->taskmanage);
553 _save_column_str(stmt, idx++, &info->enabled);
554 _save_column_str(stmt, idx++, &info->hwacceleration);
555 _save_column_str(stmt, idx++, &info->screenreader);
556 _save_column_str(stmt, idx++, &info->mainapp);
557 _save_column_str(stmt, idx++, &info->recentimage);
558 _save_column_str(stmt, idx++, &info->launchcondition);
559 _save_column_str(stmt, idx++, &info->indicatordisplay);
560 _save_column_str(stmt, idx++, &info->portraitimg);
561 _save_column_str(stmt, idx++, &info->landscapeimg);
562 _save_column_str(stmt, idx++, &info->guestmode_visibility);
563 _save_column_str(stmt, idx++, &info->permission_type);
564 _save_column_str(stmt, idx++, &info->preload);
565 _save_column_str(stmt, idx++, &info->submode);
566 _save_column_str(stmt, idx++, &info->submode_mainid);
567 _save_column_str(stmt, idx++, &info->launch_mode);
568 _save_column_str(stmt, idx++, &info->ui_gadget);
569 _save_column_str(stmt, idx++, &info->support_disable);
570 _save_column_str(stmt, idx++, &info->component_type);
571 _save_column_str(stmt, idx++, &info->package);
572 _save_column_str(stmt, idx++, &info->process_pool);
573 _save_column_str(stmt, idx++, &info->installed_storage);
575 if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
576 pkgmgrinfo_basic_free_application(info);
577 sqlite3_finalize(stmt);
578 return PMINFO_R_ERROR;
581 if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
582 pkgmgrinfo_basic_free_application(info);
583 sqlite3_finalize(stmt);
584 return PMINFO_R_ERROR;
587 if (_appinfo_get_category(db, info->appid, &info->category)) {
588 pkgmgrinfo_basic_free_application(info);
589 sqlite3_finalize(stmt);
590 return PMINFO_R_ERROR;
593 if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
594 pkgmgrinfo_basic_free_application(info);
595 sqlite3_finalize(stmt);
596 return PMINFO_R_ERROR;
599 if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
600 pkgmgrinfo_basic_free_application(info);
601 sqlite3_finalize(stmt);
602 return PMINFO_R_ERROR;
605 if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
606 pkgmgrinfo_basic_free_application(info);
607 sqlite3_finalize(stmt);
608 return PMINFO_R_ERROR;
613 sqlite3_finalize(stmt);
618 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
619 pkgmgr_appinfo_x **appinfo)
625 pkgmgr_appinfo_x *info;
627 dbpath = getUserPkgParserDBPathUID(uid);
629 return PMINFO_R_ERROR;
631 locale = _get_system_locale();
633 return PMINFO_R_ERROR;
635 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
636 if (ret != SQLITE_OK) {
637 _LOGE("failed to open db: %d", ret);
639 return PMINFO_R_ERROR;
642 info = calloc(1, sizeof(pkgmgr_appinfo_x));
644 _LOGE("out of memory");
646 sqlite3_close_v2(db);
647 return PMINFO_R_ERROR;
650 ret = _appinfo_get_application(db, appid, locale, &info->app_info);
651 if (ret != PMINFO_R_OK) {
654 sqlite3_close_v2(db);
658 info->locale = locale;
659 info->package = strdup(info->app_info->package);
663 sqlite3_close_v2(db);
668 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
669 pkgmgrinfo_appinfo_h *handle)
673 if (appid == NULL || handle == NULL) {
674 LOGE("invalid parameter");
675 return PMINFO_R_EINVAL;
678 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
679 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
680 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
681 (pkgmgr_appinfo_x **)handle);
683 if (ret != PMINFO_R_OK)
684 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
689 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
691 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
694 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
695 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
699 pkgmgr_appinfo_x *info;
705 ret = _appinfo_get_filtered_list(filter, uid, &list);
706 if (ret != PMINFO_R_OK)
707 return PMINFO_R_ERROR;
709 for (tmp = list; tmp; tmp = tmp->next) {
710 appid = (char *)tmp->data;
712 ret = _appinfo_get_appinfo(appid, uid, &info);
713 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
714 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
716 if (ret != PMINFO_R_OK) {
720 if (app_list_cb(info, user_data) < 0)
722 pkgmgrinfo_appinfo_destroy_appinfo(info);
732 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
733 pkgmgrinfo_app_component component,
734 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
737 pkgmgrinfo_appinfo_filter_h filter;
739 const char *comp_str = NULL;
741 if (handle == NULL || app_func == NULL) {
742 LOGE("invalied parameter");
743 return PMINFO_R_EINVAL;
746 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
747 LOGE("invalid parameter");
748 return PMINFO_R_EINVAL;
751 if (pkgmgrinfo_appinfo_filter_create(&filter))
752 return PMINFO_R_ERROR;
754 if (pkgmgrinfo_appinfo_filter_add_string(filter,
755 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
756 pkgmgrinfo_appinfo_filter_destroy(filter);
757 return PMINFO_R_ERROR;
763 comp_str = PMINFO_APPINFO_UI_APP;
766 comp_str = PMINFO_APPINFO_SVC_APP;
773 if (pkgmgrinfo_appinfo_filter_add_string(filter,
774 PMINFO_APPINFO_PROP_APP_COMPONENT,
776 pkgmgrinfo_appinfo_filter_destroy(filter);
777 return PMINFO_R_ERROR;
781 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
784 pkgmgrinfo_appinfo_filter_destroy(filter);
789 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
790 pkgmgrinfo_app_list_cb app_func, void *user_data)
792 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
795 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
797 if (app_func == NULL) {
798 LOGE("invalid parameter");
799 return PMINFO_R_EINVAL;
802 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
806 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
808 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
811 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
813 if (app_func == NULL) {
814 LOGE("invalid parameter");
815 return PMINFO_R_EINVAL;
818 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
822 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
824 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
827 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
829 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
831 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
832 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
834 if (info->app_info == NULL || info->app_info->appid == NULL)
835 return PMINFO_R_ERROR;
836 *appid = (char *)info->app_info->appid;
841 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
843 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
845 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
846 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
848 if (info->package == NULL)
849 return PMINFO_R_ERROR;
851 *pkg_name = (char *)info->package;
856 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
858 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
860 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
861 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
863 if (info->package == NULL)
864 return PMINFO_R_ERROR;
866 *pkgid = (char *)info->package;
871 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
873 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
875 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
876 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
878 if (info->app_info == NULL || info->app_info->exec == NULL)
879 return PMINFO_R_ERROR;
880 *exec = (char *)info->app_info->exec;
886 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
891 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
894 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
896 locale = info->locale;
897 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
899 if (info->app_info == NULL)
900 return PMINFO_R_ERROR;
902 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
903 ptr = (icon_x *)tmp->data;
904 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
905 strcmp(ptr->lang, locale))
907 *icon = (char *)ptr->text;
911 locale = DEFAULT_LOCALE;
912 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
913 ptr = (icon_x *)tmp->data;
914 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
915 strcmp(ptr->lang, locale))
917 *icon = (char *)ptr->text;
921 return PMINFO_R_ERROR;
925 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
930 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
932 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
933 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
935 locale = info->locale;
936 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
938 if (info->app_info == NULL)
939 return PMINFO_R_ERROR;
941 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
942 ptr = (label_x *)tmp->data;
943 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
944 strcmp(ptr->lang, locale))
946 *label = (char *)ptr->text;
950 locale = DEFAULT_LOCALE;
951 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
952 ptr = (label_x *)tmp->data;
953 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
954 strcmp(ptr->lang, locale))
956 *label = (char *)ptr->text;
960 return PMINFO_R_ERROR;
963 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
967 sqlite3_stmt *stmt = NULL;
970 const char *manifest_db;
972 manifest_db = getUserPkgParserDBPathUID(uid);
973 if (manifest_db == NULL) {
974 _LOGE("Failed to get manifest db path");
978 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
979 _LOGE("DB open fail\n");
983 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
985 _LOGE("Out of memory");
989 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
990 _LOGE("prepare_v2 fail\n");
994 if (sqlite3_step(stmt) == SQLITE_ROW) {
995 val = (char *)sqlite3_column_text(stmt, 0);
997 result = strdup(val);
1001 sqlite3_finalize(stmt);
1002 sqlite3_free(query);
1008 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1012 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1014 val = _get_localed_label(appid, locale, uid);
1016 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1019 return PMINFO_R_ERROR;
1026 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1028 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1031 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1033 if ( strcasecmp(comp, "uiapp") == 0)
1034 return PMINFO_UI_APP;
1035 else if ( strcasecmp(comp, "svcapp") == 0)
1036 return PMINFO_SVC_APP;
1041 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1043 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1046 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1047 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1049 if (info->app_info == NULL)
1050 return PMINFO_R_ERROR;
1052 comp = __appcomponent_convert(info->app_info->component);
1054 return PMINFO_R_ERROR;
1061 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1063 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1065 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1066 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1068 if (info->app_info == NULL || info->app_info->type == NULL)
1069 return PMINFO_R_ERROR;
1070 *app_type = (char *)info->app_info->type;
1075 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1076 int *operation_count, char ***operation)
1078 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1079 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1080 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1081 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1082 *operation_count = data->operation_count;
1083 *operation = data->operation;
1087 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1088 int *uri_count, char ***uri)
1090 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1091 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1092 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1093 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1094 *uri_count = data->uri_count;
1099 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1100 int *mime_count, char ***mime)
1102 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1103 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1104 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1105 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1106 *mime_count = data->mime_count;
1111 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1112 int *subapp_count, char ***subapp)
1114 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1115 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1116 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1117 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1118 *subapp_count = data->subapp_count;
1119 *subapp = data->subapp;
1123 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1128 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1130 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1131 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1133 if (info->app_info == NULL)
1134 return PMINFO_R_ERROR;
1136 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1137 ptr = (icon_x *)tmp->data;
1138 if (ptr == NULL || ptr->section == NULL)
1141 val = (char *)ptr->section;
1142 if (val && strcmp(val, "setting") == 0) {
1143 *icon = (char *)ptr->text;
1148 return PMINFO_R_ERROR;
1152 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1157 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1159 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1160 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1162 if (info->app_info == NULL)
1163 return PMINFO_R_ERROR;
1165 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1166 ptr = (icon_x *)tmp->data;
1167 if (ptr == NULL || ptr->section == NULL)
1170 val = (char *)ptr->section;
1171 if (val && strcmp(val, "notification") == 0){
1172 *icon = (char *)ptr->text;
1177 return PMINFO_R_ERROR;
1180 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1183 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1185 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1186 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1188 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1189 return PMINFO_R_ERROR;
1191 val = (char *)info->app_info->recentimage;
1192 if (strcasecmp(val, "capture") == 0)
1193 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1194 else if (strcasecmp(val, "icon") == 0)
1195 *type = PMINFO_RECENTIMAGE_USE_ICON;
1197 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1202 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1207 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1209 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1210 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1212 if (info->app_info == NULL)
1213 return PMINFO_R_ERROR;
1215 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1216 ptr = (image_x *)tmp->data;
1217 if (ptr == NULL || ptr->section == NULL)
1220 val = (char *)ptr->section;
1221 if (val && strcmp(val, "preview") == 0) {
1222 *preview_img = (char *)ptr->text;
1227 return PMINFO_R_ERROR;
1230 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1233 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1235 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1236 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1238 val = info->app_info->permission_type;
1240 return PMINFO_R_ERROR;
1242 if (strcmp(val, "signature") == 0)
1243 *permission = PMINFO_PERMISSION_SIGNATURE;
1244 else if (strcmp(val, "privilege") == 0)
1245 *permission = PMINFO_PERMISSION_PRIVILEGE;
1247 *permission = PMINFO_PERMISSION_NORMAL;
1252 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1254 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1256 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1257 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1259 if (info->app_info == NULL || info->app_info->component_type == NULL)
1260 return PMINFO_R_ERROR;
1262 *component_type = (char *)info->app_info->component_type;
1267 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1270 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1272 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1273 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1275 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1276 return PMINFO_R_ERROR;
1278 val = (char *)info->app_info->hwacceleration;
1279 if (strcasecmp(val, "not-use-GL") == 0)
1280 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1281 else if (strcasecmp(val, "use-GL") == 0)
1282 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1284 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1289 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1292 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1294 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1295 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1297 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1298 return PMINFO_R_ERROR;
1300 val = (char *)info->app_info->screenreader;
1301 if (strcasecmp(val, "screenreader-off") == 0)
1302 *screenreader = PMINFO_SCREENREADER_OFF;
1303 else if (strcasecmp(val, "screenreader-on") == 0)
1304 *screenreader = PMINFO_SCREENREADER_ON;
1306 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1311 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1313 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1315 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1316 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1317 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1319 if (info->app_info == NULL || info->app_info->portraitimg ||
1320 info->app_info->landscapeimg == NULL)
1321 return PMINFO_R_ERROR;
1323 *portrait_img = (char *)info->app_info->portraitimg;
1324 *landscape_img = (char *)info->app_info->landscapeimg;
1329 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1331 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1333 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1334 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1336 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1337 return PMINFO_R_ERROR;
1339 *submode_mainid = (char *)info->app_info->submode_mainid;
1344 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
1346 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1347 retvm_if(process_pool == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1349 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1350 val = (char *)info->app_info->process_pool;
1352 if (strcasecmp(val, "true") == 0)
1354 else if (strcasecmp(val, "false") == 0)
1362 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
1364 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1365 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1367 if (info->app_info && info->app_info->installed_storage){
1368 if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
1369 *storage = PMINFO_INTERNAL_STORAGE;
1370 else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
1371 *storage = PMINFO_EXTERNAL_STORAGE;
1373 return PMINFO_R_ERROR;
1375 return PMINFO_R_ERROR;
1380 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1382 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1384 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1385 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1387 if (info->app_info->launch_mode == NULL)
1388 return PMINFO_R_ERROR;
1390 *mode = (char *)(info->app_info->launch_mode);
1395 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1397 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1398 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1399 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1400 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1402 int ret = PMINFO_R_OK;
1404 sqlite3_stmt *stmt = NULL;
1407 ret = __open_manifest_db(uid, true);
1408 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1410 /*Start constructing query*/
1411 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1414 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1415 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1418 ret = sqlite3_step(stmt);
1419 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1421 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1422 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1427 sqlite3_free(query);
1428 sqlite3_finalize(stmt);
1429 __close_manifest_db();
1433 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1435 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1438 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1440 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1441 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1443 int ret = PMINFO_R_OK;
1445 sqlite3_stmt *stmt = NULL;
1448 ret = __open_manifest_db(uid, true);
1449 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1451 /*Start constructing query*/
1452 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1455 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1456 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1459 ret = sqlite3_step(stmt);
1460 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1462 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1467 sqlite3_free(query);
1468 sqlite3_finalize(stmt);
1469 __close_manifest_db();
1473 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1475 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1478 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1479 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1481 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1482 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1486 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1488 if (info->app_info == NULL)
1489 return PMINFO_R_ERROR;
1491 for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
1492 ptr = (permission_x *)tmp->data;
1496 ret = permission_func(ptr->value, user_data);
1504 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1505 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1507 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1508 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1510 const char *category;
1512 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1514 if (info->app_info == NULL)
1515 return PMINFO_R_ERROR;
1517 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1518 category = (const char *)tmp->data;
1520 ret = category_func(category, user_data);
1528 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1529 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1531 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1532 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1536 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1538 if (info->app_info == NULL)
1539 return PMINFO_R_ERROR;
1541 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1542 ptr = (metadata_x *)tmp->data;
1546 ret = metadata_func(ptr->key, ptr->value, user_data);
1554 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1555 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1558 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1560 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1561 appcontrol_x *appcontrol;
1564 if (info->app_info == NULL)
1565 return PMINFO_R_ERROR;
1567 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1568 appcontrol = (appcontrol_x *)tmp->data;
1569 if (appcontrol == NULL)
1571 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1579 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1581 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1582 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1583 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1585 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1586 return PMINFO_R_ERROR;
1588 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1593 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1595 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1596 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1597 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1599 if (info->app_info == NULL || info->app_info->multiple == NULL)
1600 return PMINFO_R_ERROR;
1602 *multiple = _get_bool_value(info->app_info->multiple);
1607 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1610 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1611 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1613 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1614 return PMINFO_R_ERROR;
1616 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1621 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1623 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1624 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1625 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1627 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1628 return PMINFO_R_ERROR;
1630 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1635 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1637 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1638 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1639 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1641 if (info->app_info == NULL || info->app_info->enabled == NULL)
1642 return PMINFO_R_ERROR;
1644 *enabled = _get_bool_value(info->app_info->enabled);
1649 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1651 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1652 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1653 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1655 if (info->app_info == NULL || info->app_info->onboot == NULL)
1656 return PMINFO_R_ERROR;
1658 *onboot = _get_bool_value(info->app_info->onboot);
1663 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1665 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1666 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1667 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1669 if (info->app_info == NULL || info->app_info->autorestart == NULL)
1670 return PMINFO_R_ERROR;
1672 *autorestart = _get_bool_value(info->app_info->autorestart);
1677 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1679 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1680 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1681 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1683 if (info->app_info == NULL || info->app_info->mainapp == NULL)
1684 return PMINFO_R_ERROR;
1686 *mainapp = _get_bool_value(info->app_info->mainapp);
1691 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1693 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1694 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1695 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1697 if (info->app_info == NULL || info->app_info->preload == NULL)
1698 return PMINFO_R_ERROR;
1700 *preload = _get_bool_value(info->app_info->preload);
1705 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1707 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1708 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1709 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1711 if (info->app_info == NULL || info->app_info->submode == NULL)
1712 return PMINFO_R_ERROR;
1714 *submode = _get_bool_value(info->app_info->submode);
1719 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1721 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1722 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1723 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1727 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1729 if (info->app_info == NULL)
1730 return PMINFO_R_ERROR;
1733 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1734 val = (const char *)tmp->data;
1737 if (strcasecmp(val, category) == 0) {
1746 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1749 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1751 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1752 _LOGE("invalid parameter");
1753 return PMINFO_R_EINVAL;
1756 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1761 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1762 bool *support_disable)
1764 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1766 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1767 _LOGE("invalid parameter");
1768 return PMINFO_R_EINVAL;
1771 *support_disable = _get_bool_value(info->app_info->support_disable);
1776 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1778 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1779 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1780 __cleanup_appinfo(info);
1784 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1786 return (pkgmgrinfo_pkginfo_filter_create(handle));
1789 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1791 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1794 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1796 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1797 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1798 if (node1->prop == node2->prop)
1800 else if (node1->prop > node2->prop)
1806 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1807 const char *property, const int value)
1809 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1810 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1811 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1813 GSList *link = NULL;
1815 prop = _pminfo_appinfo_convert_to_prop_int(property);
1816 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1817 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1818 _LOGE("Invalid Integer Property\n");
1819 return PMINFO_R_EINVAL;
1821 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1822 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1824 _LOGE("Out of Memory!!!\n");
1825 return PMINFO_R_ERROR;
1827 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1828 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1830 _LOGE("Out of Memory\n");
1833 return PMINFO_R_ERROR;
1837 /*If API is called multiple times for same property, we should override the previous values.
1838 Last value set will be used for filtering.*/
1839 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1841 filter->list = g_slist_delete_link(filter->list, link);
1842 filter->list = g_slist_append(filter->list, (gpointer)node);
1847 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1848 const char *property, const bool value)
1850 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1851 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1853 GSList *link = NULL;
1855 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1856 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1857 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1858 _LOGE("Invalid Boolean Property\n");
1859 return PMINFO_R_EINVAL;
1861 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1862 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1864 _LOGE("Out of Memory!!!\n");
1865 return PMINFO_R_ERROR;
1868 val = strndup("('true','True')", 15);
1870 val = strndup("('false','False')", 17);
1872 _LOGE("Out of Memory\n");
1875 return PMINFO_R_ERROR;
1879 /*If API is called multiple times for same property, we should override the previous values.
1880 Last value set will be used for filtering.*/
1881 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1883 filter->list = g_slist_delete_link(filter->list, link);
1884 filter->list = g_slist_append(filter->list, (gpointer)node);
1889 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1890 const char *property, const char *value)
1892 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1893 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1894 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1896 pkgmgrinfo_node_x *ptr = NULL;
1897 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1898 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1899 GSList *link = NULL;
1901 prop = _pminfo_appinfo_convert_to_prop_str(property);
1902 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1903 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1904 _LOGE("Invalid String Property\n");
1905 return PMINFO_R_EINVAL;
1907 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1908 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1910 _LOGE("Out of Memory!!!\n");
1911 return PMINFO_R_ERROR;
1915 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1916 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1917 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1919 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1921 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1923 filter->list = g_slist_delete_link(filter->list, link);
1924 filter->list = g_slist_append(filter->list, (gpointer)node);
1926 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1927 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1928 case E_PMINFO_APPINFO_PROP_APP_URI:
1929 case E_PMINFO_APPINFO_PROP_APP_MIME:
1930 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1932 _LOGE("Out of Memory\n");
1935 return PMINFO_R_ERROR;
1937 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1939 ptr = (pkgmgrinfo_node_x *)link->data;
1940 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1941 _LOGE("Previous value is %s\n", prev);
1942 filter->list = g_slist_delete_link(filter->list, link);
1943 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1944 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1945 _LOGE("New value is %s\n", val);
1947 filter->list = g_slist_append(filter->list, (gpointer)node);
1948 memset(temp, '\0', PKG_STRING_LEN_MAX);
1950 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1951 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1952 _LOGE("First value is %s\n", val);
1954 filter->list = g_slist_append(filter->list, (gpointer)node);
1955 memset(temp, '\0', PKG_STRING_LEN_MAX);
1959 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1960 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1962 filter->list = g_slist_delete_link(filter->list, link);
1963 filter->list = g_slist_append(filter->list, (gpointer)node);
1969 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1974 if (handle == NULL || count == NULL) {
1975 _LOGE("invalid parameter");
1976 return PMINFO_R_EINVAL;
1979 ret = _appinfo_get_filtered_list(handle, uid, &list);
1980 if (ret != PMINFO_R_OK)
1981 return PMINFO_R_ERROR;
1983 *count = g_list_length(list);
1985 g_list_free_full(list, free);
1990 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1992 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1995 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1996 pkgmgrinfo_appinfo_filter_h handle,
1997 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1999 if (handle == NULL || app_cb == NULL) {
2000 LOGE("invalid parameter");
2001 return PMINFO_R_EINVAL;
2004 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2008 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2009 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2011 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2014 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2016 return (pkgmgrinfo_pkginfo_filter_create(handle));
2019 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2021 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2024 API int pkgmgrinfo_appinfo_metadata_filter_add(
2025 pkgmgrinfo_appinfo_metadata_filter_h handle,
2026 const char *key, const char *value)
2030 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2031 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2032 if (ret != PMINFO_R_OK)
2035 /* value can be NULL.
2036 * In that case all apps with specified key should be displayed
2039 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2040 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2041 if (ret != PMINFO_R_OK)
2048 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2049 pkgmgrinfo_appinfo_metadata_filter_h handle,
2050 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2052 if (handle == NULL || app_cb == NULL) {
2053 LOGE("invalid parameter");
2054 return PMINFO_R_EINVAL;
2057 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2061 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2062 pkgmgrinfo_appinfo_metadata_filter_h handle,
2063 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2065 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2066 user_data, GLOBAL_USER);
2069 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2072 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2074 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2075 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2077 val = info->app_info->guestmode_visibility;
2078 *status = _get_bool_value(val);