13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
19 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
20 "ON package_app_info.app_id=package_app_localized_info.app_id " \
21 "and package_app_localized_info.app_locale='%s' " \
22 "LEFT OUTER JOIN package_app_app_svc " \
23 "ON package_app_info.app_id=package_app_app_svc.app_id " \
24 "LEFT OUTER JOIN package_app_app_category " \
25 "ON package_app_info.app_id=package_app_app_category.app_id where "
27 static bool _get_bool_value(const char *str)
31 else if (!strcasecmp(str, "true"))
37 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
39 pkgmgr_appinfo_x *info = data;
40 pkgmgr_appinfo_x *tmp;
42 while (info != NULL) {
45 free((void *)info->package);
47 free((void *)info->locale);
49 pkgmgrinfo_basic_free_application(info->app_info);
56 static char *_get_filtered_query(const char *query_raw,
57 pkgmgrinfo_filter_x *filter)
59 char buf[MAX_QUERY_LEN] = { 0, };
68 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
70 for (list = head; list; list = list->next) {
71 /* TODO: revise condition getter function */
72 __get_filter_condition(list->data, &condition);
73 if (condition == NULL)
75 if (buf[strlen(query_raw)] == '\0') {
76 len += strlen(" WHERE ");
77 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
79 len += strlen(" AND ");
80 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
82 len += strlen(condition);
83 strncat(buf, condition, sizeof(buf) - len - 1);
91 static gint __list_strcmp(gconstpointer a, gconstpointer b)
93 return strcmp((char *)a, (char *)b);
96 static gint _appinfo_get_list(sqlite3 *db, const char *locale,
97 pkgmgrinfo_filter_x *filter, GList **list)
99 static const char query_raw[] =
100 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
101 " LEFT OUTER JOIN package_app_localized_info"
102 " ON package_app_info.app_id=package_app_localized_info.app_id"
103 " AND package_app_localized_info.app_locale=%Q"
104 " LEFT OUTER JOIN package_app_app_category"
105 " ON package_app_info.app_id=package_app_app_category.app_id"
106 " LEFT OUTER JOIN package_app_app_svc"
107 " ON package_app_info.app_id=package_app_app_svc.app_id "
108 " LEFT OUTER JOIN package_app_app_metadata"
109 " ON package_app_info.app_id=package_app_app_metadata.app_id ";
112 char *query_localized;
116 query = _get_filtered_query(query_raw, filter);
118 return PMINFO_R_ERROR;
119 query_localized = sqlite3_mprintf(query, locale);
121 if (query_localized == NULL)
122 return PMINFO_R_ERROR;
124 ret = sqlite3_prepare_v2(db, query_localized,
125 strlen(query_localized), &stmt, NULL);
126 sqlite3_free(query_localized);
127 if (ret != SQLITE_OK) {
128 LOGE("prepare failed: %s", sqlite3_errmsg(db));
129 return PMINFO_R_ERROR;
132 while (sqlite3_step(stmt) == SQLITE_ROW) {
133 _save_column_str(stmt, 0, (const char **)&appid);
135 *list = g_list_insert_sorted(*list, appid,
139 sqlite3_finalize(stmt);
144 static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
153 locale = _get_system_locale();
155 return PMINFO_R_ERROR;
157 dbpath = getUserPkgParserDBPathUID(uid);
158 if (dbpath == NULL) {
160 return PMINFO_R_ERROR;
163 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
164 if (ret != SQLITE_OK) {
165 _LOGE("failed to open db: %d", ret);
167 return PMINFO_R_ERROR;
170 if (_appinfo_get_list(db, locale, filter, list)) {
172 sqlite3_close_v2(db);
173 return PMINFO_R_ERROR;
175 sqlite3_close_v2(db);
177 if (uid == GLOBAL_USER) {
182 /* search again from global */
183 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
184 if (dbpath == NULL) {
186 return PMINFO_R_ERROR;
189 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
190 if (ret != SQLITE_OK) {
191 _LOGE("failed to open db: %d", ret);
193 return PMINFO_R_ERROR;
196 if (_appinfo_get_list(db, locale, filter, list)) {
198 sqlite3_close_v2(db);
199 return PMINFO_R_ERROR;
201 sqlite3_close_v2(db);
203 /* remove duplicate element:
204 * since the list is sorted, we can remove duplicates in linear time
206 for (tmp = *list; tmp; tmp = tmp->next) {
207 if (tmp->prev == NULL || tmp->data == NULL)
209 if (strcmp((const char *)tmp->prev->data,
210 (const char *)tmp->data) == 0)
211 *list = g_list_delete_link(*list, tmp);
218 static int _appinfo_get_label(sqlite3 *db, const char *appid,
219 const char *locale, label_x **label)
221 static const char query_raw[] =
222 "SELECT app_label, app_locale "
223 "FROM package_app_localized_info "
224 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
231 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
233 LOGE("out of memory");
234 return PMINFO_R_ERROR;
237 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
239 if (ret != SQLITE_OK) {
240 LOGE("prepare failed: %s", sqlite3_errmsg(db));
241 return PMINFO_R_ERROR;
244 while (sqlite3_step(stmt) == SQLITE_ROW) {
245 info = calloc(1, sizeof(label_x));
247 LOGE("out of memory");
248 sqlite3_finalize(stmt);
250 LISTHEAD(*label, info);
253 return PMINFO_R_ERROR;
256 _save_column_str(stmt, idx++, &info->text);
257 _save_column_str(stmt, idx++, &info->lang);
258 LISTADD(*label, info);
262 LISTHEAD(*label, info);
266 sqlite3_finalize(stmt);
271 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
274 static const char query_raw[] =
275 "SELECT app_icon, app_locale "
276 "FROM package_app_localized_info "
277 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
284 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
286 LOGE("out of memory");
287 return PMINFO_R_ERROR;
290 ret = sqlite3_prepare_v2(db, query, strlen(query),
293 if (ret != SQLITE_OK) {
294 LOGE("prepare failed: %s", sqlite3_errmsg(db));
295 return PMINFO_R_ERROR;
298 while (sqlite3_step(stmt) == SQLITE_ROW) {
299 info = calloc(1, sizeof(icon_x));
301 LOGE("out of memory");
302 sqlite3_finalize(stmt);
304 LISTHEAD(*icon, info);
307 return PMINFO_R_ERROR;
310 _save_column_str(stmt, idx++, &info->text);
311 _save_column_str(stmt, idx++, &info->lang);
312 LISTADD(*icon, info);
316 LISTHEAD(*icon, info);
320 sqlite3_finalize(stmt);
325 static int _appinfo_get_category(sqlite3 *db, const char *appid,
326 category_x **category)
328 static const char query_raw[] =
329 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
335 query = sqlite3_mprintf(query_raw, appid);
337 LOGE("out of memory");
338 return PMINFO_R_ERROR;
341 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
343 if (ret != SQLITE_OK) {
344 LOGE("prepare failed: %s", sqlite3_errmsg(db));
345 return PMINFO_R_ERROR;
348 while (sqlite3_step(stmt) == SQLITE_ROW) {
349 info = calloc(1, sizeof(category_x));
351 LOGE("out of memory");
352 sqlite3_finalize(stmt);
354 LISTHEAD(*category, info);
357 return PMINFO_R_ERROR;
359 _save_column_str(stmt, 0, &info->name);
360 LISTADD(*category, info);
364 LISTHEAD(*category, info);
368 sqlite3_finalize(stmt);
373 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
380 if (appcontrol_str == NULL)
383 dup = strdup(appcontrol_str);
385 ac = calloc(1, sizeof(appcontrol_x));
387 _LOGE("out of memory");
390 token = strtok_r(dup, "|", &ptr);
391 if (token && strcmp(token, "NULL"))
392 ac->operation = strdup(token);
393 token = strtok_r(NULL, "|", &ptr);
394 if (token && strcmp(token, "NULL"))
395 ac->uri = strdup(token);
396 token = strtok_r(NULL, "|", &ptr);
397 if (token && strcmp(token, "NULL"))
398 ac->mime = strdup(token);
399 LISTADD(*appcontrol, ac);
400 } while ((token = strtok_r(NULL, ";", &ptr)));
403 LISTHEAD(*appcontrol, ac);
409 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
410 appcontrol_x **appcontrol)
412 static const char query_raw[] =
413 "SELECT app_control FROM package_app_app_control "
418 appcontrol_x *info = NULL;
421 query = sqlite3_mprintf(query_raw, appid);
423 LOGE("out of memory");
424 return PMINFO_R_ERROR;
427 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
429 if (ret != SQLITE_OK) {
430 LOGE("prepare failed: %s", sqlite3_errmsg(db));
431 return PMINFO_R_ERROR;
434 while (sqlite3_step(stmt) == SQLITE_ROW) {
436 _save_column_str(stmt, 0, (const char **)&str);
438 __parse_appcontrol(&info, str);
444 sqlite3_finalize(stmt);
449 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
450 datacontrol_x **datacontrol)
452 static const char query_raw[] =
453 "SELECT providerid, access, type "
454 "FROM package_app_data_control 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(datacontrol_x));
477 LOGE("out of memory");
478 sqlite3_finalize(stmt);
480 LISTHEAD(*datacontrol, info);
483 return PMINFO_R_ERROR;
486 _save_column_str(stmt, idx++, &info->providerid);
487 _save_column_str(stmt, idx++, &info->access);
488 _save_column_str(stmt, idx++, &info->type);
489 LISTADD(*datacontrol, info);
493 LISTHEAD(*datacontrol, info);
497 sqlite3_finalize(stmt);
502 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
503 metadata_x **metadata)
505 static const char query_raw[] =
506 "SELECT md_key, md_value "
507 "FROM package_app_app_metadata 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 while (sqlite3_step(stmt) == SQLITE_ROW) {
528 info = calloc(1, sizeof(metadata_x));
530 LOGE("out of memory");
531 sqlite3_finalize(stmt);
533 LISTHEAD(*metadata, info);
536 return PMINFO_R_ERROR;
539 _save_column_str(stmt, idx++, &info->key);
540 _save_column_str(stmt, idx++, &info->value);
541 LISTADD(*metadata, info);
545 LISTHEAD(*metadata, info);
549 sqlite3_finalize(stmt);
555 static int _appinfo_get_application(sqlite3 *db, const char *appid,
556 const char *locale, application_x **application)
558 static const char query_raw[] =
559 "SELECT app_id, app_component, app_exec, app_nodisplay, "
560 "app_type, app_onboot, app_multiple, app_autorestart, "
561 "app_taskmanage, app_enabled, app_hwacceleration, "
562 "app_screenreader, app_mainapp, app_recentimage, "
563 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
564 "app_landscapeimg, app_guestmodevisibility, "
565 "app_permissiontype, app_preload, app_submode, "
566 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
567 "app_support_disable, "
568 "component_type, package "
569 "FROM package_app_info WHERE app_id=%Q";
576 query = sqlite3_mprintf(query_raw, appid);
578 LOGE("out of memory");
579 return PMINFO_R_ERROR;
582 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
584 if (ret != SQLITE_OK) {
585 LOGE("prepare failed: %s", sqlite3_errmsg(db));
586 return PMINFO_R_ERROR;
589 ret = sqlite3_step(stmt);
590 if (ret == SQLITE_DONE) {
591 sqlite3_finalize(stmt);
592 return PMINFO_R_ENOENT;
593 } else if (ret != SQLITE_ROW) {
594 LOGE("step failed: %s", sqlite3_errmsg(db));
595 sqlite3_finalize(stmt);
596 return PMINFO_R_ERROR;
599 info = calloc(1, sizeof(application_x));
601 LOGE("out of memory");
602 sqlite3_finalize(stmt);
603 return PMINFO_R_ERROR;
606 _save_column_str(stmt, idx++, &info->appid);
607 _save_column_str(stmt, idx++, &info->component);
608 _save_column_str(stmt, idx++, &info->exec);
609 _save_column_str(stmt, idx++, &info->nodisplay);
610 _save_column_str(stmt, idx++, &info->type);
611 _save_column_str(stmt, idx++, &info->onboot);
612 _save_column_str(stmt, idx++, &info->multiple);
613 _save_column_str(stmt, idx++, &info->autorestart);
614 _save_column_str(stmt, idx++, &info->taskmanage);
615 _save_column_str(stmt, idx++, &info->enabled);
616 _save_column_str(stmt, idx++, &info->hwacceleration);
617 _save_column_str(stmt, idx++, &info->screenreader);
618 _save_column_str(stmt, idx++, &info->mainapp);
619 _save_column_str(stmt, idx++, &info->recentimage);
620 _save_column_str(stmt, idx++, &info->launchcondition);
621 _save_column_str(stmt, idx++, &info->indicatordisplay);
622 _save_column_str(stmt, idx++, &info->portraitimg);
623 _save_column_str(stmt, idx++, &info->landscapeimg);
624 _save_column_str(stmt, idx++, &info->guestmode_visibility);
625 _save_column_str(stmt, idx++, &info->permission_type);
626 _save_column_str(stmt, idx++, &info->preload);
627 _save_column_str(stmt, idx++, &info->submode);
628 _save_column_str(stmt, idx++, &info->submode_mainid);
629 _save_column_str(stmt, idx++, &info->launch_mode);
630 _save_column_str(stmt, idx++, &info->ui_gadget);
631 _save_column_str(stmt, idx++, &info->support_disable);
632 _save_column_str(stmt, idx++, &info->component_type);
633 _save_column_str(stmt, idx++, &info->package);
635 if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
636 pkgmgrinfo_basic_free_application(info);
637 sqlite3_finalize(stmt);
638 return PMINFO_R_ERROR;
641 if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
642 pkgmgrinfo_basic_free_application(info);
643 sqlite3_finalize(stmt);
644 return PMINFO_R_ERROR;
647 if (_appinfo_get_category(db, info->appid, &info->category)) {
648 pkgmgrinfo_basic_free_application(info);
649 sqlite3_finalize(stmt);
650 return PMINFO_R_ERROR;
653 if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
654 pkgmgrinfo_basic_free_application(info);
655 sqlite3_finalize(stmt);
656 return PMINFO_R_ERROR;
659 if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
660 pkgmgrinfo_basic_free_application(info);
661 sqlite3_finalize(stmt);
662 return PMINFO_R_ERROR;
665 if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
666 pkgmgrinfo_basic_free_application(info);
667 sqlite3_finalize(stmt);
668 return PMINFO_R_ERROR;
673 sqlite3_finalize(stmt);
678 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
679 pkgmgr_appinfo_x **appinfo)
685 pkgmgr_appinfo_x *info;
687 dbpath = getUserPkgParserDBPathUID(uid);
689 return PMINFO_R_ERROR;
691 locale = _get_system_locale();
693 return PMINFO_R_ERROR;
695 ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
696 if (ret != SQLITE_OK) {
697 _LOGE("failed to open db: %d", ret);
699 return PMINFO_R_ERROR;
702 info = calloc(1, sizeof(pkgmgr_appinfo_x));
704 _LOGE("out of memory");
706 sqlite3_close_v2(db);
707 return PMINFO_R_ERROR;
710 ret = _appinfo_get_application(db, appid, locale, &info->app_info);
711 if (ret == PMINFO_R_OK) {
712 info->locale = strdup(locale);
713 info->package = strdup(info->app_info->package);
719 sqlite3_close_v2(db);
724 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
725 pkgmgrinfo_appinfo_h *handle)
729 if (appid == NULL || handle == NULL) {
730 LOGE("invalid parameter");
731 return PMINFO_R_EINVAL;
734 ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
735 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
736 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
737 (pkgmgr_appinfo_x **)handle);
739 if (ret != PMINFO_R_OK)
740 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
745 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
747 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
750 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
751 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
755 pkgmgr_appinfo_x *info;
761 ret = _appinfo_get_filtered_list(filter, uid, &list);
762 if (ret != PMINFO_R_OK)
763 return PMINFO_R_ERROR;
765 for (tmp = list; tmp; tmp = tmp->next) {
766 appid = (char *)tmp->data;
768 ret = _appinfo_get_appinfo(appid, uid, &info);
769 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
770 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
772 if (ret != PMINFO_R_OK) {
776 if (app_list_cb(info, user_data) < 0)
778 pkgmgrinfo_appinfo_destroy_appinfo(info);
788 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
789 pkgmgrinfo_app_component component,
790 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
793 pkgmgrinfo_appinfo_filter_h filter;
795 const char *comp_str = NULL;
797 if (handle == NULL || app_func == NULL) {
798 LOGE("invalied parameter");
799 return PMINFO_R_EINVAL;
802 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
803 LOGE("invalid parameter");
804 return PMINFO_R_EINVAL;
807 if (pkgmgrinfo_appinfo_filter_create(&filter))
808 return PMINFO_R_ERROR;
810 if (pkgmgrinfo_appinfo_filter_add_string(filter,
811 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
812 pkgmgrinfo_appinfo_filter_destroy(filter);
813 return PMINFO_R_ERROR;
819 comp_str = PMINFO_APPINFO_UI_APP;
822 comp_str = PMINFO_APPINFO_SVC_APP;
829 if (pkgmgrinfo_appinfo_filter_add_string(filter,
830 PMINFO_APPINFO_PROP_APP_COMPONENT,
832 pkgmgrinfo_appinfo_filter_destroy(filter);
833 return PMINFO_R_ERROR;
837 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
840 pkgmgrinfo_appinfo_filter_destroy(filter);
845 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
846 pkgmgrinfo_app_list_cb app_func, void *user_data)
848 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
851 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
853 if (app_func == NULL) {
854 LOGE("invalid parameter");
855 return PMINFO_R_EINVAL;
858 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
862 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
864 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
867 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
869 if (app_func == NULL) {
870 LOGE("invalid parameter");
871 return PMINFO_R_EINVAL;
874 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
878 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
880 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
883 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
885 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
887 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
888 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
890 if (info->app_info == NULL || info->app_info->appid == NULL)
891 return PMINFO_R_ERROR;
892 *appid = (char *)info->app_info->appid;
897 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
899 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
901 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
902 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
904 if (info->package == NULL)
905 return PMINFO_R_ERROR;
907 *pkg_name = (char *)info->package;
912 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
914 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
916 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
917 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
919 if (info->package == NULL)
920 return PMINFO_R_ERROR;
922 *pkgid = (char *)info->package;
927 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
929 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
931 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
932 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
934 if (info->app_info == NULL || info->app_info->exec == NULL)
935 return PMINFO_R_ERROR;
936 *exec = (char *)info->app_info->exec;
942 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
947 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
949 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
950 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
952 locale = info->locale;
953 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
955 start = info->app_info->icon;
956 for (ptr = start; ptr != NULL; ptr = ptr->next) {
957 if (ptr->lang == NULL)
960 if (strcmp(ptr->lang, locale) == 0) {
961 *icon = (char *)ptr->text;
962 if (strcasecmp(*icon, "(null)") == 0) {
963 locale = DEFAULT_LOCALE;
968 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
969 *icon = (char *)ptr->text;
974 return PMINFO_R_ERROR;
978 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
983 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
985 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
986 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
988 locale = info->locale;
989 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
991 start = info->app_info->label;
992 for (ptr = start; ptr != NULL; ptr = ptr->next) {
993 if (ptr->lang == NULL)
996 if (strcmp(ptr->lang, locale) == 0) {
997 *label = (char *)ptr->text;
998 if (strcasecmp(*label, "(null)") == 0) {
999 locale = DEFAULT_LOCALE;
1004 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1005 *label = (char *)ptr->text;
1010 return PMINFO_R_ERROR;
1013 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1015 char *result = NULL;
1017 sqlite3_stmt *stmt = NULL;
1020 const char *manifest_db;
1022 manifest_db = getUserPkgParserDBPathUID(uid);
1023 if (manifest_db == NULL) {
1024 _LOGE("Failed to get manifest db path");
1028 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1029 _LOGE("DB open fail\n");
1033 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1034 if (query == NULL) {
1035 _LOGE("Out of memory");
1039 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1040 _LOGE("prepare_v2 fail\n");
1044 if (sqlite3_step(stmt) == SQLITE_ROW) {
1045 val = (char *)sqlite3_column_text(stmt, 0);
1047 result = strdup(val);
1051 sqlite3_finalize(stmt);
1052 sqlite3_free(query);
1058 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1062 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1064 val = _get_localed_label(appid, locale, uid);
1066 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1069 return PMINFO_R_ERROR;
1076 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1078 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1081 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1083 if ( strcasecmp(comp, "uiapp") == 0)
1084 return PMINFO_UI_APP;
1085 else if ( strcasecmp(comp, "svcapp") == 0)
1086 return PMINFO_SVC_APP;
1091 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1093 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1096 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1097 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1099 if (info->app_info == NULL)
1100 return PMINFO_R_ERROR;
1102 comp = __appcomponent_convert(info->app_info->component);
1104 return PMINFO_R_ERROR;
1111 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1113 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1115 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1116 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1118 if (info->app_info == NULL || info->app_info->type == NULL)
1119 return PMINFO_R_ERROR;
1120 *app_type = (char *)info->app_info->type;
1125 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1126 int *operation_count, char ***operation)
1128 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1129 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1130 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1131 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1132 *operation_count = data->operation_count;
1133 *operation = data->operation;
1137 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1138 int *uri_count, char ***uri)
1140 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1141 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1142 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1143 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1144 *uri_count = data->uri_count;
1149 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1150 int *mime_count, char ***mime)
1152 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1153 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1154 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1155 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1156 *mime_count = data->mime_count;
1161 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1162 int *subapp_count, char ***subapp)
1164 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1165 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1166 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1167 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1168 *subapp_count = data->subapp_count;
1169 *subapp = data->subapp;
1173 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1177 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1179 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1180 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1182 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1183 if (ptr->section == NULL)
1186 val = (char *)ptr->section;
1187 if (val && strcmp(val, "setting") == 0) {
1188 *icon = (char *)ptr->text;
1193 return PMINFO_R_ERROR;
1197 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1201 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1204 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1206 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1207 if (ptr->section == NULL)
1210 val = (char *)ptr->section;
1211 if (val && strcmp(val, "notification") == 0){
1212 *icon = (char *)ptr->text;
1217 return PMINFO_R_ERROR;
1220 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1223 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1225 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1226 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1228 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1229 return PMINFO_R_ERROR;
1231 val = (char *)info->app_info->recentimage;
1232 if (strcasecmp(val, "capture") == 0)
1233 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1234 else if (strcasecmp(val, "icon") == 0)
1235 *type = PMINFO_RECENTIMAGE_USE_ICON;
1237 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1242 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1246 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1248 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1249 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1251 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1252 if (ptr->section == NULL)
1255 val = (char *)ptr->section;
1256 if (val && strcmp(val, "preview") == 0) {
1257 *preview_img = (char *)ptr->text;
1262 return PMINFO_R_ERROR;
1265 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1268 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1270 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1271 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1273 val = info->app_info->permission_type;
1275 return PMINFO_R_ERROR;
1277 if (strcmp(val, "signature") == 0)
1278 *permission = PMINFO_PERMISSION_SIGNATURE;
1279 else if (strcmp(val, "privilege") == 0)
1280 *permission = PMINFO_PERMISSION_PRIVILEGE;
1282 *permission = PMINFO_PERMISSION_NORMAL;
1287 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1289 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1291 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1292 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1294 if (info->app_info == NULL || info->app_info->component_type == NULL)
1295 return PMINFO_R_ERROR;
1297 *component_type = (char *)info->app_info->component_type;
1302 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1305 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1307 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1308 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1310 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1311 return PMINFO_R_ERROR;
1313 val = (char *)info->app_info->hwacceleration;
1314 if (strcasecmp(val, "not-use-GL") == 0)
1315 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1316 else if (strcasecmp(val, "use-GL") == 0)
1317 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1319 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1324 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1327 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1329 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1330 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1332 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1333 return PMINFO_R_ERROR;
1335 val = (char *)info->app_info->screenreader;
1336 if (strcasecmp(val, "screenreader-off") == 0)
1337 *screenreader = PMINFO_SCREENREADER_OFF;
1338 else if (strcasecmp(val, "screenreader-on") == 0)
1339 *screenreader = PMINFO_SCREENREADER_ON;
1341 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1346 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1348 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1350 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1351 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1352 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1354 if (info->app_info == NULL || info->app_info->portraitimg ||
1355 info->app_info->landscapeimg == NULL)
1356 return PMINFO_R_ERROR;
1358 *portrait_img = (char *)info->app_info->portraitimg;
1359 *landscape_img = (char *)info->app_info->landscapeimg;
1364 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1366 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1368 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1369 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1371 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1372 return PMINFO_R_ERROR;
1374 *submode_mainid = (char *)info->app_info->submode_mainid;
1379 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1381 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1383 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1384 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1386 if (info->app_info->launch_mode == NULL)
1387 return PMINFO_R_ERROR;
1389 *mode = (char *)(info->app_info->launch_mode);
1394 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1396 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1397 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1398 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1399 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1401 int ret = PMINFO_R_OK;
1403 sqlite3_stmt *stmt = NULL;
1406 ret = __open_manifest_db(uid, true);
1407 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1409 /*Start constructing query*/
1410 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1413 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1414 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1417 ret = sqlite3_step(stmt);
1418 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1420 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1421 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1426 sqlite3_free(query);
1427 sqlite3_finalize(stmt);
1428 __close_manifest_db();
1432 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1434 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1437 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1439 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1440 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1442 int ret = PMINFO_R_OK;
1444 sqlite3_stmt *stmt = NULL;
1447 ret = __open_manifest_db(uid, true);
1448 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1450 /*Start constructing query*/
1451 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1454 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1455 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1458 ret = sqlite3_step(stmt);
1459 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1461 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1466 sqlite3_free(query);
1467 sqlite3_finalize(stmt);
1468 __close_manifest_db();
1472 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1474 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1477 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1478 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1480 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1481 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1483 permission_x *ptr = NULL;
1484 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1486 if (info->app_info == NULL)
1487 return PMINFO_R_ERROR;
1489 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1491 ret = permission_func(ptr->value, user_data);
1499 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1500 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1502 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1503 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1505 category_x *ptr = NULL;
1506 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1508 if (info->app_info == NULL)
1509 return PMINFO_R_ERROR;
1511 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1513 ret = category_func(ptr->name, user_data);
1521 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1522 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1524 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1525 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1527 metadata_x *ptr = NULL;
1528 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1530 if (info->app_info == NULL)
1531 return PMINFO_R_ERROR;
1533 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1535 ret = metadata_func(ptr->key, ptr->value, user_data);
1543 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1544 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1546 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1547 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1549 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1550 appcontrol_x *appcontrol;
1552 if (info->uiapp_info == NULL)
1553 return PMINFO_R_ERROR;
1555 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1556 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1564 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1566 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1567 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1568 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1570 if (info->app_info == NULL)
1571 return PMINFO_R_ERROR;
1573 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1577 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1579 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1580 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1581 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1583 if (info->app_info == NULL)
1584 return PMINFO_R_ERROR;
1586 *multiple = _get_bool_value(info->app_info->multiple);
1590 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1592 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1593 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1594 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1596 if (info->app_info == NULL)
1597 return PMINFO_R_ERROR;
1599 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1603 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1605 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1606 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1607 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1609 if (info->app_info == NULL)
1610 return PMINFO_R_ERROR;
1612 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1616 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1618 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1619 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1620 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1622 if (info->app_info == NULL)
1623 return PMINFO_R_ERROR;
1625 *enabled = _get_bool_value(info->app_info->enabled);
1630 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1632 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1633 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1634 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1636 if (info->app_info == NULL)
1637 return PMINFO_R_ERROR;
1639 *onboot = _get_bool_value(info->app_info->onboot);
1643 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1645 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1646 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1647 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1649 if (info->app_info == NULL)
1650 return PMINFO_R_ERROR;
1652 *autorestart = _get_bool_value(info->app_info->autorestart);
1656 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1658 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1659 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1660 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1662 if (info->app_info == NULL)
1663 return PMINFO_R_ERROR;
1665 *mainapp = _get_bool_value(info->app_info->mainapp);
1669 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1671 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1672 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1673 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1675 if (info->app_info == NULL)
1676 return PMINFO_R_ERROR;
1678 *preload = _get_bool_value(info->app_info->preload);
1682 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1684 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1685 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1686 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1688 if (info->app_info == NULL)
1689 return PMINFO_R_ERROR;
1691 *submode = _get_bool_value(info->app_info->submode);
1695 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1697 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1698 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1699 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1701 category_x *ptr = NULL;
1702 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1704 if (info->app_info == NULL)
1705 return PMINFO_R_ERROR;
1708 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1710 if (strcasecmp(ptr->name, category) == 0) {
1720 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1723 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1725 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1726 _LOGE("invalid parameter");
1727 return PMINFO_R_EINVAL;
1730 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1735 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1736 bool *support_disable)
1738 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1740 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1741 _LOGE("invalid parameter");
1742 return PMINFO_R_EINVAL;
1745 *support_disable = _get_bool_value(info->app_info->support_disable);
1750 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1752 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1753 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1754 __cleanup_appinfo(info);
1758 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1760 return (pkgmgrinfo_pkginfo_filter_create(handle));
1763 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1765 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1768 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1770 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1771 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1772 if (node1->prop == node2->prop)
1774 else if (node1->prop > node2->prop)
1780 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1781 const char *property, const int value)
1783 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1784 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1785 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1787 GSList *link = NULL;
1789 prop = _pminfo_appinfo_convert_to_prop_int(property);
1790 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1791 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1792 _LOGE("Invalid Integer Property\n");
1793 return PMINFO_R_EINVAL;
1795 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1796 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1798 _LOGE("Out of Memory!!!\n");
1799 return PMINFO_R_ERROR;
1801 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1802 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1804 _LOGE("Out of Memory\n");
1807 return PMINFO_R_ERROR;
1811 /*If API is called multiple times for same property, we should override the previous values.
1812 Last value set will be used for filtering.*/
1813 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1815 filter->list = g_slist_delete_link(filter->list, link);
1816 filter->list = g_slist_append(filter->list, (gpointer)node);
1821 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1822 const char *property, const bool value)
1824 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1825 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1827 GSList *link = NULL;
1829 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1830 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1831 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1832 _LOGE("Invalid Boolean Property\n");
1833 return PMINFO_R_EINVAL;
1835 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1836 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1838 _LOGE("Out of Memory!!!\n");
1839 return PMINFO_R_ERROR;
1842 val = strndup("('true','True')", 15);
1844 val = strndup("('false','False')", 17);
1846 _LOGE("Out of Memory\n");
1849 return PMINFO_R_ERROR;
1853 /*If API is called multiple times for same property, we should override the previous values.
1854 Last value set will be used for filtering.*/
1855 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1857 filter->list = g_slist_delete_link(filter->list, link);
1858 filter->list = g_slist_append(filter->list, (gpointer)node);
1863 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1864 const char *property, const char *value)
1866 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1867 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1868 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1870 pkgmgrinfo_node_x *ptr = NULL;
1871 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1872 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1873 GSList *link = NULL;
1875 prop = _pminfo_appinfo_convert_to_prop_str(property);
1876 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1877 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1878 _LOGE("Invalid String Property\n");
1879 return PMINFO_R_EINVAL;
1881 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1882 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1884 _LOGE("Out of Memory!!!\n");
1885 return PMINFO_R_ERROR;
1889 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1890 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1891 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1893 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1895 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1897 filter->list = g_slist_delete_link(filter->list, link);
1898 filter->list = g_slist_append(filter->list, (gpointer)node);
1900 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1901 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1902 case E_PMINFO_APPINFO_PROP_APP_URI:
1903 case E_PMINFO_APPINFO_PROP_APP_MIME:
1904 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1906 _LOGE("Out of Memory\n");
1909 return PMINFO_R_ERROR;
1911 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1913 ptr = (pkgmgrinfo_node_x *)link->data;
1914 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1915 _LOGE("Previous value is %s\n", prev);
1916 filter->list = g_slist_delete_link(filter->list, link);
1917 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1918 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1919 _LOGE("New value is %s\n", val);
1921 filter->list = g_slist_append(filter->list, (gpointer)node);
1922 memset(temp, '\0', PKG_STRING_LEN_MAX);
1924 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1925 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1926 _LOGE("First value is %s\n", val);
1928 filter->list = g_slist_append(filter->list, (gpointer)node);
1929 memset(temp, '\0', PKG_STRING_LEN_MAX);
1933 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1934 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1936 filter->list = g_slist_delete_link(filter->list, link);
1937 filter->list = g_slist_append(filter->list, (gpointer)node);
1943 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
1945 int *p = (int*)data;
1946 *p = atoi(coltxt[0]);
1947 _LOGE("count value is %d\n", *p);
1951 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1953 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1954 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1955 char *locale = NULL;
1956 char *condition = NULL;
1957 char *error_message = NULL;
1958 char query[MAX_QUERY_LEN] = {'\0'};
1959 char where[MAX_QUERY_LEN] = {'\0'};
1963 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1964 /*Get current locale*/
1965 locale = _get_system_locale();
1966 if (locale == NULL) {
1967 _LOGE("manifest locale is NULL\n");
1968 return PMINFO_R_ERROR;
1971 ret = __open_manifest_db(uid, true);
1973 _LOGE("Fail to open manifest DB\n");
1975 return PMINFO_R_ERROR;
1978 /*Start constructing query*/
1979 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
1981 /*Get where clause*/
1982 for (list = filter->list; list; list = g_slist_next(list)) {
1983 __get_filter_condition(list->data, &condition);
1985 strncat(where, condition, sizeof(where) - strlen(where) -1);
1986 where[sizeof(where) - 1] = '\0';
1990 if (g_slist_next(list)) {
1991 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1992 where[sizeof(where) - 1] = '\0';
1995 if (strlen(where) > 0) {
1996 strncat(query, where, sizeof(query) - strlen(query) - 1);
1997 query[sizeof(query) - 1] = '\0';
2002 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
2003 _LOGE("Don't execute query = %s error message = %s\n", query,
2005 sqlite3_free(error_message);
2006 ret = PMINFO_R_ERROR;
2016 __close_manifest_db();
2020 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2022 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
2025 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2026 pkgmgrinfo_appinfo_filter_h handle,
2027 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2029 if (handle == NULL || app_cb == NULL) {
2030 LOGE("invalid parameter");
2031 return PMINFO_R_EINVAL;
2034 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2038 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2039 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2041 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
2044 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2046 return (pkgmgrinfo_pkginfo_filter_create(handle));
2049 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2051 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2054 API int pkgmgrinfo_appinfo_metadata_filter_add(
2055 pkgmgrinfo_appinfo_metadata_filter_h handle,
2056 const char *key, const char *value)
2060 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2061 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2062 if (ret != PMINFO_R_OK)
2065 /* value can be NULL.
2066 * In that case all apps with specified key should be displayed
2069 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2070 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2071 if (ret != PMINFO_R_OK)
2078 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2079 pkgmgrinfo_appinfo_metadata_filter_h handle,
2080 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2082 if (handle == NULL || app_cb == NULL) {
2083 LOGE("invalid parameter");
2084 return PMINFO_R_EINVAL;
2087 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2091 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2092 pkgmgrinfo_appinfo_metadata_filter_h handle,
2093 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2095 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2096 user_data, GLOBAL_USER);
2099 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2102 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2104 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2105 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2107 val = info->uiapp_info->guestmode_visibility;
2108 *status = _get_bool_value(val);