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_svc"
98 " ON package_app_info.app_id=package_app_app_svc.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);
210 static int _appinfo_get_label(sqlite3 *db, const char *appid,
211 const char *locale, label_x **label)
213 static const char query_raw[] =
214 "SELECT app_label, app_locale "
215 "FROM package_app_localized_info "
216 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
223 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
225 LOGE("out of memory");
226 return PMINFO_R_ERROR;
229 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
231 if (ret != SQLITE_OK) {
232 LOGE("prepare failed: %s", sqlite3_errmsg(db));
233 return PMINFO_R_ERROR;
236 while (sqlite3_step(stmt) == SQLITE_ROW) {
237 info = calloc(1, sizeof(label_x));
239 LOGE("out of memory");
240 sqlite3_finalize(stmt);
242 LISTHEAD(*label, info);
245 return PMINFO_R_ERROR;
248 _save_column_str(stmt, idx++, &info->text);
249 _save_column_str(stmt, idx++, &info->lang);
250 LISTADD(*label, info);
254 LISTHEAD(*label, info);
258 sqlite3_finalize(stmt);
263 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
266 static const char query_raw[] =
267 "SELECT app_icon, app_locale "
268 "FROM package_app_localized_info "
269 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
276 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
278 LOGE("out of memory");
279 return PMINFO_R_ERROR;
282 ret = sqlite3_prepare_v2(db, query, strlen(query),
285 if (ret != SQLITE_OK) {
286 LOGE("prepare failed: %s", sqlite3_errmsg(db));
287 return PMINFO_R_ERROR;
290 while (sqlite3_step(stmt) == SQLITE_ROW) {
291 info = calloc(1, sizeof(icon_x));
293 LOGE("out of memory");
294 sqlite3_finalize(stmt);
296 LISTHEAD(*icon, info);
299 return PMINFO_R_ERROR;
302 _save_column_str(stmt, idx++, &info->text);
303 _save_column_str(stmt, idx++, &info->lang);
304 LISTADD(*icon, info);
308 LISTHEAD(*icon, info);
312 sqlite3_finalize(stmt);
317 static int _appinfo_get_category(sqlite3 *db, const char *appid,
318 category_x **category)
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) {
341 info = calloc(1, sizeof(category_x));
343 LOGE("out of memory");
344 sqlite3_finalize(stmt);
346 LISTHEAD(*category, info);
349 return PMINFO_R_ERROR;
351 _save_column_str(stmt, 0, &info->name);
352 LISTADD(*category, info);
356 LISTHEAD(*category, info);
360 sqlite3_finalize(stmt);
365 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
372 if (appcontrol_str == NULL)
375 dup = strdup(appcontrol_str);
377 ac = calloc(1, sizeof(appcontrol_x));
379 _LOGE("out of memory");
382 token = strtok_r(dup, "|", &ptr);
383 if (token && strcmp(token, "NULL"))
384 ac->operation = strdup(token);
385 token = strtok_r(NULL, "|", &ptr);
386 if (token && strcmp(token, "NULL"))
387 ac->uri = strdup(token);
388 token = strtok_r(NULL, "|", &ptr);
389 if (token && strcmp(token, "NULL"))
390 ac->mime = strdup(token);
391 LISTADD(*appcontrol, ac);
392 } while ((token = strtok_r(NULL, ";", &ptr)));
395 LISTHEAD(*appcontrol, ac);
401 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
402 appcontrol_x **appcontrol)
404 static const char query_raw[] =
405 "SELECT app_control FROM package_app_app_control "
410 appcontrol_x *info = NULL;
413 query = sqlite3_mprintf(query_raw, appid);
415 LOGE("out of memory");
416 return PMINFO_R_ERROR;
419 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
421 if (ret != SQLITE_OK) {
422 LOGE("prepare failed: %s", sqlite3_errmsg(db));
423 return PMINFO_R_ERROR;
426 while (sqlite3_step(stmt) == SQLITE_ROW) {
428 _save_column_str(stmt, 0, (const char **)&str);
430 __parse_appcontrol(&info, str);
436 sqlite3_finalize(stmt);
441 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
442 datacontrol_x **datacontrol)
444 static const char query_raw[] =
445 "SELECT providerid, access, type "
446 "FROM package_app_data_control WHERE app_id=%Q";
453 query = sqlite3_mprintf(query_raw, appid);
455 LOGE("out of memory");
456 return PMINFO_R_ERROR;
459 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
461 if (ret != SQLITE_OK) {
462 LOGE("prepare failed: %s", sqlite3_errmsg(db));
463 return PMINFO_R_ERROR;
466 while (sqlite3_step(stmt) == SQLITE_ROW) {
467 info = calloc(1, sizeof(datacontrol_x));
469 LOGE("out of memory");
470 sqlite3_finalize(stmt);
472 LISTHEAD(*datacontrol, info);
475 return PMINFO_R_ERROR;
478 _save_column_str(stmt, idx++, &info->providerid);
479 _save_column_str(stmt, idx++, &info->access);
480 _save_column_str(stmt, idx++, &info->type);
481 LISTADD(*datacontrol, info);
485 LISTHEAD(*datacontrol, info);
489 sqlite3_finalize(stmt);
494 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
495 metadata_x **metadata)
497 static const char query_raw[] =
498 "SELECT md_key, md_value "
499 "FROM package_app_app_metadata WHERE app_id=%Q";
506 query = sqlite3_mprintf(query_raw, appid);
508 LOGE("out of memory");
509 return PMINFO_R_ERROR;
512 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
514 if (ret != SQLITE_OK) {
515 LOGE("prepare failed: %s", sqlite3_errmsg(db));
516 return PMINFO_R_ERROR;
519 while (sqlite3_step(stmt) == SQLITE_ROW) {
520 info = calloc(1, sizeof(metadata_x));
522 LOGE("out of memory");
523 sqlite3_finalize(stmt);
525 LISTHEAD(*metadata, info);
528 return PMINFO_R_ERROR;
531 _save_column_str(stmt, idx++, &info->key);
532 _save_column_str(stmt, idx++, &info->value);
533 LISTADD(*metadata, info);
537 LISTHEAD(*metadata, info);
541 sqlite3_finalize(stmt);
547 static int _appinfo_get_application(sqlite3 *db, const char *appid,
548 const char *locale, application_x **application)
550 static const char query_raw[] =
551 "SELECT app_id, app_component, app_exec, app_nodisplay, "
552 "app_type, app_onboot, app_multiple, app_autorestart, "
553 "app_taskmanage, app_enabled, app_hwacceleration, "
554 "app_screenreader, app_mainapp, app_recentimage, "
555 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
556 "app_landscapeimg, app_guestmodevisibility, "
557 "app_permissiontype, app_preload, app_submode, "
558 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
559 "app_support_disable, "
560 "component_type, package "
561 "FROM package_app_info WHERE app_id=%Q";
568 query = sqlite3_mprintf(query_raw, appid);
570 LOGE("out of memory");
571 return PMINFO_R_ERROR;
574 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);
627 if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
628 pkgmgrinfo_basic_free_application(info);
629 sqlite3_finalize(stmt);
630 return PMINFO_R_ERROR;
633 if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
634 pkgmgrinfo_basic_free_application(info);
635 sqlite3_finalize(stmt);
636 return PMINFO_R_ERROR;
639 if (_appinfo_get_category(db, info->appid, &info->category)) {
640 pkgmgrinfo_basic_free_application(info);
641 sqlite3_finalize(stmt);
642 return PMINFO_R_ERROR;
645 if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
646 pkgmgrinfo_basic_free_application(info);
647 sqlite3_finalize(stmt);
648 return PMINFO_R_ERROR;
651 if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
652 pkgmgrinfo_basic_free_application(info);
653 sqlite3_finalize(stmt);
654 return PMINFO_R_ERROR;
657 if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
658 pkgmgrinfo_basic_free_application(info);
659 sqlite3_finalize(stmt);
660 return PMINFO_R_ERROR;
665 sqlite3_finalize(stmt);
670 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
671 pkgmgr_appinfo_x **appinfo)
677 pkgmgr_appinfo_x *info;
679 dbpath = getUserPkgParserDBPathUID(uid);
681 return PMINFO_R_ERROR;
683 locale = _get_system_locale();
685 return PMINFO_R_ERROR;
687 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
688 if (ret != SQLITE_OK) {
689 _LOGE("failed to open db: %d", ret);
691 return PMINFO_R_ERROR;
694 info = calloc(1, sizeof(pkgmgr_appinfo_x));
696 _LOGE("out of memory");
698 sqlite3_close_v2(db);
699 return PMINFO_R_ERROR;
702 ret = _appinfo_get_application(db, appid, locale, &info->app_info);
703 if (ret == PMINFO_R_OK) {
704 info->locale = strdup(locale);
705 info->package = strdup(info->app_info->package);
711 sqlite3_close_v2(db);
716 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
717 pkgmgrinfo_appinfo_h *handle)
721 if (appid == NULL || handle == NULL) {
722 LOGE("invalid parameter");
723 return PMINFO_R_EINVAL;
726 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
727 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
728 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
729 (pkgmgr_appinfo_x **)handle);
731 if (ret != PMINFO_R_OK)
732 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
737 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
739 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
742 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
743 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
747 pkgmgr_appinfo_x *info;
753 ret = _appinfo_get_filtered_list(filter, uid, &list);
754 if (ret != PMINFO_R_OK)
755 return PMINFO_R_ERROR;
757 for (tmp = list; tmp; tmp = tmp->next) {
758 appid = (char *)tmp->data;
760 ret = _appinfo_get_appinfo(appid, uid, &info);
761 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
762 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
764 if (ret != PMINFO_R_OK) {
768 if (app_list_cb(info, user_data) < 0)
770 pkgmgrinfo_appinfo_destroy_appinfo(info);
780 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
781 pkgmgrinfo_app_component component,
782 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
785 pkgmgrinfo_appinfo_filter_h filter;
787 const char *comp_str = NULL;
789 if (handle == NULL || app_func == NULL) {
790 LOGE("invalied parameter");
791 return PMINFO_R_EINVAL;
794 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
795 LOGE("invalid parameter");
796 return PMINFO_R_EINVAL;
799 if (pkgmgrinfo_appinfo_filter_create(&filter))
800 return PMINFO_R_ERROR;
802 if (pkgmgrinfo_appinfo_filter_add_string(filter,
803 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
804 pkgmgrinfo_appinfo_filter_destroy(filter);
805 return PMINFO_R_ERROR;
811 comp_str = PMINFO_APPINFO_UI_APP;
814 comp_str = PMINFO_APPINFO_SVC_APP;
821 if (pkgmgrinfo_appinfo_filter_add_string(filter,
822 PMINFO_APPINFO_PROP_APP_COMPONENT,
824 pkgmgrinfo_appinfo_filter_destroy(filter);
825 return PMINFO_R_ERROR;
829 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
832 pkgmgrinfo_appinfo_filter_destroy(filter);
837 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
838 pkgmgrinfo_app_list_cb app_func, void *user_data)
840 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
843 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
845 if (app_func == NULL) {
846 LOGE("invalid parameter");
847 return PMINFO_R_EINVAL;
850 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
854 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
856 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
859 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
861 if (app_func == NULL) {
862 LOGE("invalid parameter");
863 return PMINFO_R_EINVAL;
866 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
870 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
872 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
875 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
877 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
879 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
880 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
882 if (info->app_info == NULL || info->app_info->appid == NULL)
883 return PMINFO_R_ERROR;
884 *appid = (char *)info->app_info->appid;
889 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
891 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
894 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
896 if (info->package == NULL)
897 return PMINFO_R_ERROR;
899 *pkg_name = (char *)info->package;
904 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
906 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
908 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
909 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
911 if (info->package == NULL)
912 return PMINFO_R_ERROR;
914 *pkgid = (char *)info->package;
919 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
921 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
923 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
924 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
926 if (info->app_info == NULL || info->app_info->exec == NULL)
927 return PMINFO_R_ERROR;
928 *exec = (char *)info->app_info->exec;
934 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
939 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
941 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
942 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
944 locale = info->locale;
945 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
947 start = info->app_info->icon;
948 for (ptr = start; ptr != NULL; ptr = ptr->next) {
949 if (ptr->lang == NULL)
952 if (strcmp(ptr->lang, locale) == 0) {
953 *icon = (char *)ptr->text;
954 if (strcasecmp(*icon, "(null)") == 0) {
955 locale = DEFAULT_LOCALE;
960 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
961 *icon = (char *)ptr->text;
966 return PMINFO_R_ERROR;
970 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
975 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
977 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
978 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
980 locale = info->locale;
981 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
983 start = info->app_info->label;
984 for (ptr = start; ptr != NULL; ptr = ptr->next) {
985 if (ptr->lang == NULL)
988 if (strcmp(ptr->lang, locale) == 0) {
989 *label = (char *)ptr->text;
990 if (strcasecmp(*label, "(null)") == 0) {
991 locale = DEFAULT_LOCALE;
996 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
997 *label = (char *)ptr->text;
1002 return PMINFO_R_ERROR;
1005 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1007 char *result = NULL;
1009 sqlite3_stmt *stmt = NULL;
1012 const char *manifest_db;
1014 manifest_db = getUserPkgParserDBPathUID(uid);
1015 if (manifest_db == NULL) {
1016 _LOGE("Failed to get manifest db path");
1020 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1021 _LOGE("DB open fail\n");
1025 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1026 if (query == NULL) {
1027 _LOGE("Out of memory");
1031 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1032 _LOGE("prepare_v2 fail\n");
1036 if (sqlite3_step(stmt) == SQLITE_ROW) {
1037 val = (char *)sqlite3_column_text(stmt, 0);
1039 result = strdup(val);
1043 sqlite3_finalize(stmt);
1044 sqlite3_free(query);
1050 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1054 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1056 val = _get_localed_label(appid, locale, uid);
1058 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1061 return PMINFO_R_ERROR;
1068 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1070 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1073 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1075 if ( strcasecmp(comp, "uiapp") == 0)
1076 return PMINFO_UI_APP;
1077 else if ( strcasecmp(comp, "svcapp") == 0)
1078 return PMINFO_SVC_APP;
1083 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1085 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1088 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1089 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1091 if (info->app_info == NULL)
1092 return PMINFO_R_ERROR;
1094 comp = __appcomponent_convert(info->app_info->component);
1096 return PMINFO_R_ERROR;
1103 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1105 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1108 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1110 if (info->app_info == NULL || info->app_info->type == NULL)
1111 return PMINFO_R_ERROR;
1112 *app_type = (char *)info->app_info->type;
1117 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1118 int *operation_count, char ***operation)
1120 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1121 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1122 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1123 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1124 *operation_count = data->operation_count;
1125 *operation = data->operation;
1129 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1130 int *uri_count, char ***uri)
1132 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1133 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1134 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1135 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1136 *uri_count = data->uri_count;
1141 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1142 int *mime_count, char ***mime)
1144 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1145 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1146 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1147 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1148 *mime_count = data->mime_count;
1153 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1154 int *subapp_count, char ***subapp)
1156 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1157 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1158 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1159 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1160 *subapp_count = data->subapp_count;
1161 *subapp = data->subapp;
1165 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1169 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1171 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1172 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1174 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1175 if (ptr->section == NULL)
1178 val = (char *)ptr->section;
1179 if (val && strcmp(val, "setting") == 0) {
1180 *icon = (char *)ptr->text;
1185 return PMINFO_R_ERROR;
1189 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1193 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1195 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1196 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1198 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1199 if (ptr->section == NULL)
1202 val = (char *)ptr->section;
1203 if (val && strcmp(val, "notification") == 0){
1204 *icon = (char *)ptr->text;
1209 return PMINFO_R_ERROR;
1212 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1215 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1217 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1218 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1220 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1221 return PMINFO_R_ERROR;
1223 val = (char *)info->app_info->recentimage;
1224 if (strcasecmp(val, "capture") == 0)
1225 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1226 else if (strcasecmp(val, "icon") == 0)
1227 *type = PMINFO_RECENTIMAGE_USE_ICON;
1229 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1234 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1238 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1240 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1241 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1243 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1244 if (ptr->section == NULL)
1247 val = (char *)ptr->section;
1248 if (val && strcmp(val, "preview") == 0) {
1249 *preview_img = (char *)ptr->text;
1254 return PMINFO_R_ERROR;
1257 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1260 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1262 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1263 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1265 val = info->app_info->permission_type;
1267 return PMINFO_R_ERROR;
1269 if (strcmp(val, "signature") == 0)
1270 *permission = PMINFO_PERMISSION_SIGNATURE;
1271 else if (strcmp(val, "privilege") == 0)
1272 *permission = PMINFO_PERMISSION_PRIVILEGE;
1274 *permission = PMINFO_PERMISSION_NORMAL;
1279 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1281 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1283 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1284 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1286 if (info->app_info == NULL || info->app_info->component_type == NULL)
1287 return PMINFO_R_ERROR;
1289 *component_type = (char *)info->app_info->component_type;
1294 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1297 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1299 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1300 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1302 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1303 return PMINFO_R_ERROR;
1305 val = (char *)info->app_info->hwacceleration;
1306 if (strcasecmp(val, "not-use-GL") == 0)
1307 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1308 else if (strcasecmp(val, "use-GL") == 0)
1309 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1311 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1316 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1319 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1322 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1324 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1325 return PMINFO_R_ERROR;
1327 val = (char *)info->app_info->screenreader;
1328 if (strcasecmp(val, "screenreader-off") == 0)
1329 *screenreader = PMINFO_SCREENREADER_OFF;
1330 else if (strcasecmp(val, "screenreader-on") == 0)
1331 *screenreader = PMINFO_SCREENREADER_ON;
1333 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1338 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1340 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1342 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1343 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1344 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1346 if (info->app_info == NULL || info->app_info->portraitimg ||
1347 info->app_info->landscapeimg == NULL)
1348 return PMINFO_R_ERROR;
1350 *portrait_img = (char *)info->app_info->portraitimg;
1351 *landscape_img = (char *)info->app_info->landscapeimg;
1356 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1358 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1361 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1363 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1364 return PMINFO_R_ERROR;
1366 *submode_mainid = (char *)info->app_info->submode_mainid;
1371 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1373 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1375 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1376 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1378 if (info->app_info->launch_mode == NULL)
1379 return PMINFO_R_ERROR;
1381 *mode = (char *)(info->app_info->launch_mode);
1386 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1388 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1389 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1390 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1391 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1393 int ret = PMINFO_R_OK;
1395 sqlite3_stmt *stmt = NULL;
1398 ret = __open_manifest_db(uid, true);
1399 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1401 /*Start constructing query*/
1402 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1405 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1406 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1409 ret = sqlite3_step(stmt);
1410 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1412 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1413 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1418 sqlite3_free(query);
1419 sqlite3_finalize(stmt);
1420 __close_manifest_db();
1424 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1426 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1429 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1431 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1432 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1434 int ret = PMINFO_R_OK;
1436 sqlite3_stmt *stmt = NULL;
1439 ret = __open_manifest_db(uid, true);
1440 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1442 /*Start constructing query*/
1443 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1446 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1447 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1450 ret = sqlite3_step(stmt);
1451 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1453 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1458 sqlite3_free(query);
1459 sqlite3_finalize(stmt);
1460 __close_manifest_db();
1464 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1466 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1469 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1470 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1472 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1473 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1475 permission_x *ptr = NULL;
1476 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1478 if (info->app_info == NULL)
1479 return PMINFO_R_ERROR;
1481 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1483 ret = permission_func(ptr->value, user_data);
1491 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1492 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1495 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1497 category_x *ptr = NULL;
1498 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1500 if (info->app_info == NULL)
1501 return PMINFO_R_ERROR;
1503 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1505 ret = category_func(ptr->name, user_data);
1513 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1514 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1516 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1517 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1519 metadata_x *ptr = NULL;
1520 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1522 if (info->app_info == NULL)
1523 return PMINFO_R_ERROR;
1525 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1527 ret = metadata_func(ptr->key, ptr->value, user_data);
1535 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1536 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1538 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1539 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1541 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1542 appcontrol_x *appcontrol;
1544 if (info->uiapp_info == NULL)
1545 return PMINFO_R_ERROR;
1547 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1548 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1556 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1558 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1559 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1560 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1562 if (info->app_info == NULL)
1563 return PMINFO_R_ERROR;
1565 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1569 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1571 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1572 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1573 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1575 if (info->app_info == NULL)
1576 return PMINFO_R_ERROR;
1578 *multiple = _get_bool_value(info->app_info->multiple);
1582 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1584 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1585 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1586 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1588 if (info->app_info == NULL)
1589 return PMINFO_R_ERROR;
1591 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1595 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1597 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1598 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1599 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1601 if (info->app_info == NULL)
1602 return PMINFO_R_ERROR;
1604 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1608 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1610 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1611 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1612 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1614 if (info->app_info == NULL)
1615 return PMINFO_R_ERROR;
1617 *enabled = _get_bool_value(info->app_info->enabled);
1622 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1624 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1625 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1626 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1628 if (info->app_info == NULL)
1629 return PMINFO_R_ERROR;
1631 *onboot = _get_bool_value(info->app_info->onboot);
1635 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1637 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1638 retvm_if(autorestart == 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)
1642 return PMINFO_R_ERROR;
1644 *autorestart = _get_bool_value(info->app_info->autorestart);
1648 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1650 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1651 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1652 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1654 if (info->app_info == NULL)
1655 return PMINFO_R_ERROR;
1657 *mainapp = _get_bool_value(info->app_info->mainapp);
1661 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1663 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1664 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1665 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1667 if (info->app_info == NULL)
1668 return PMINFO_R_ERROR;
1670 *preload = _get_bool_value(info->app_info->preload);
1674 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1676 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1677 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1678 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1680 if (info->app_info == NULL)
1681 return PMINFO_R_ERROR;
1683 *submode = _get_bool_value(info->app_info->submode);
1687 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1689 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1690 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1691 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1693 category_x *ptr = NULL;
1694 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1696 if (info->app_info == NULL)
1697 return PMINFO_R_ERROR;
1700 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1702 if (strcasecmp(ptr->name, category) == 0) {
1712 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1715 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1717 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1718 _LOGE("invalid parameter");
1719 return PMINFO_R_EINVAL;
1722 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1727 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1728 bool *support_disable)
1730 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1732 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1733 _LOGE("invalid parameter");
1734 return PMINFO_R_EINVAL;
1737 *support_disable = _get_bool_value(info->app_info->support_disable);
1742 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1744 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1745 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1746 __cleanup_appinfo(info);
1750 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1752 return (pkgmgrinfo_pkginfo_filter_create(handle));
1755 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1757 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1760 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1762 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1763 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1764 if (node1->prop == node2->prop)
1766 else if (node1->prop > node2->prop)
1772 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1773 const char *property, const int value)
1775 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1776 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1777 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1779 GSList *link = NULL;
1781 prop = _pminfo_appinfo_convert_to_prop_int(property);
1782 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1783 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1784 _LOGE("Invalid Integer Property\n");
1785 return PMINFO_R_EINVAL;
1787 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1788 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1790 _LOGE("Out of Memory!!!\n");
1791 return PMINFO_R_ERROR;
1793 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1794 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1796 _LOGE("Out of Memory\n");
1799 return PMINFO_R_ERROR;
1803 /*If API is called multiple times for same property, we should override the previous values.
1804 Last value set will be used for filtering.*/
1805 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1807 filter->list = g_slist_delete_link(filter->list, link);
1808 filter->list = g_slist_append(filter->list, (gpointer)node);
1813 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1814 const char *property, const bool value)
1816 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1817 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1819 GSList *link = NULL;
1821 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1822 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1823 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1824 _LOGE("Invalid Boolean Property\n");
1825 return PMINFO_R_EINVAL;
1827 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1828 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1830 _LOGE("Out of Memory!!!\n");
1831 return PMINFO_R_ERROR;
1834 val = strndup("('true','True')", 15);
1836 val = strndup("('false','False')", 17);
1838 _LOGE("Out of Memory\n");
1841 return PMINFO_R_ERROR;
1845 /*If API is called multiple times for same property, we should override the previous values.
1846 Last value set will be used for filtering.*/
1847 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1849 filter->list = g_slist_delete_link(filter->list, link);
1850 filter->list = g_slist_append(filter->list, (gpointer)node);
1855 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1856 const char *property, const char *value)
1858 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1859 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1860 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1862 pkgmgrinfo_node_x *ptr = NULL;
1863 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1864 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1865 GSList *link = NULL;
1867 prop = _pminfo_appinfo_convert_to_prop_str(property);
1868 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1869 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1870 _LOGE("Invalid String Property\n");
1871 return PMINFO_R_EINVAL;
1873 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1874 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1876 _LOGE("Out of Memory!!!\n");
1877 return PMINFO_R_ERROR;
1881 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1882 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1883 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1885 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1887 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1889 filter->list = g_slist_delete_link(filter->list, link);
1890 filter->list = g_slist_append(filter->list, (gpointer)node);
1892 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1893 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1894 case E_PMINFO_APPINFO_PROP_APP_URI:
1895 case E_PMINFO_APPINFO_PROP_APP_MIME:
1896 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1898 _LOGE("Out of Memory\n");
1901 return PMINFO_R_ERROR;
1903 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1905 ptr = (pkgmgrinfo_node_x *)link->data;
1906 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1907 _LOGE("Previous value is %s\n", prev);
1908 filter->list = g_slist_delete_link(filter->list, link);
1909 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1910 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1911 _LOGE("New value is %s\n", val);
1913 filter->list = g_slist_append(filter->list, (gpointer)node);
1914 memset(temp, '\0', PKG_STRING_LEN_MAX);
1916 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1917 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1918 _LOGE("First value is %s\n", val);
1920 filter->list = g_slist_append(filter->list, (gpointer)node);
1921 memset(temp, '\0', PKG_STRING_LEN_MAX);
1925 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1926 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1928 filter->list = g_slist_delete_link(filter->list, link);
1929 filter->list = g_slist_append(filter->list, (gpointer)node);
1935 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1940 if (handle == NULL || count == NULL) {
1941 _LOGE("invalid parameter");
1942 return PMINFO_R_EINVAL;
1945 ret = _appinfo_get_filtered_list(handle, uid, &list);
1946 if (ret != PMINFO_R_OK)
1947 return PMINFO_R_ERROR;
1949 *count = g_list_length(list);
1951 g_list_free_full(list, free);
1956 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1958 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1961 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1962 pkgmgrinfo_appinfo_filter_h handle,
1963 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1965 if (handle == NULL || app_cb == NULL) {
1966 LOGE("invalid parameter");
1967 return PMINFO_R_EINVAL;
1970 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1974 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1975 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1977 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1980 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1982 return (pkgmgrinfo_pkginfo_filter_create(handle));
1985 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
1987 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1990 API int pkgmgrinfo_appinfo_metadata_filter_add(
1991 pkgmgrinfo_appinfo_metadata_filter_h handle,
1992 const char *key, const char *value)
1996 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
1997 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
1998 if (ret != PMINFO_R_OK)
2001 /* value can be NULL.
2002 * In that case all apps with specified key should be displayed
2005 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2006 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2007 if (ret != PMINFO_R_OK)
2014 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2015 pkgmgrinfo_appinfo_metadata_filter_h handle,
2016 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2018 if (handle == NULL || app_cb == NULL) {
2019 LOGE("invalid parameter");
2020 return PMINFO_R_EINVAL;
2023 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2027 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2028 pkgmgrinfo_appinfo_metadata_filter_h handle,
2029 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2031 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2032 user_data, GLOBAL_USER);
2035 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2038 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2040 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2041 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2043 val = info->uiapp_info->guestmode_visibility;
2044 *status = _get_bool_value(val);