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 GSList *_appinfo_get_filtered_list(const char *locale,
92 pkgmgrinfo_filter_x *filter)
94 static const char query_raw[] =
95 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
96 " LEFT OUTER JOIN package_app_localized_info"
97 " ON package_app_info.app_id=package_app_localized_info.app_id"
98 " AND package_app_localized_info.app_locale=%Q"
99 " LEFT OUTER JOIN package_app_app_category"
100 " ON package_app_info.app_id=package_app_app_category.app_id"
101 " LEFT OUTER JOIN package_app_app_svc"
102 " ON package_app_info.app_id=package_app_app_svc.app_id ";
105 char *query_localized;
110 query = _get_filtered_query(query_raw, filter);
113 query_localized = sqlite3_mprintf(query, locale);
115 if (query_localized == NULL)
118 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query_localized,
119 strlen(query_localized), &stmt, NULL);
120 sqlite3_free(query_localized);
121 if (ret != SQLITE_OK) {
122 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
126 while (sqlite3_step(stmt) == SQLITE_ROW) {
127 _save_column_str(stmt, 0, (const char **)&appid);
128 list = g_slist_append(list, appid);
131 sqlite3_finalize(stmt);
136 static int _appinfo_get_label(const char *appid, const char *locale,
139 static const char query_raw[] =
140 "SELECT app_label, app_locale "
141 "FROM package_app_localized_info "
142 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
149 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
151 LOGE("out of memory");
152 return PMINFO_R_ERROR;
155 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
158 if (ret != SQLITE_OK) {
159 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
160 return PMINFO_R_ERROR;
163 while (sqlite3_step(stmt) == SQLITE_ROW) {
164 info = calloc(1, sizeof(label_x));
166 LOGE("out of memory");
167 sqlite3_finalize(stmt);
169 LISTHEAD(*label, info);
172 return PMINFO_R_ERROR;
175 _save_column_str(stmt, idx++, &info->text);
176 _save_column_str(stmt, idx++, &info->lang);
177 LISTADD(*label, info);
181 LISTHEAD(*label, info);
185 sqlite3_finalize(stmt);
190 static int _appinfo_get_icon(const char *appid, const char *locale,
193 static const char query_raw[] =
194 "SELECT app_icon, app_locale "
195 "FROM package_app_localized_info "
196 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
203 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
205 LOGE("out of memory");
206 return PMINFO_R_ERROR;
209 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
212 if (ret != SQLITE_OK) {
213 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
214 return PMINFO_R_ERROR;
217 while (sqlite3_step(stmt) == SQLITE_ROW) {
218 info = calloc(1, sizeof(icon_x));
220 LOGE("out of memory");
221 sqlite3_finalize(stmt);
223 LISTHEAD(*icon, info);
226 return PMINFO_R_ERROR;
229 _save_column_str(stmt, idx++, &info->text);
230 _save_column_str(stmt, idx++, &info->lang);
231 LISTADD(*icon, info);
235 LISTHEAD(*icon, info);
239 sqlite3_finalize(stmt);
244 static int _appinfo_get_category(const char *appid, category_x **category)
246 static const char query_raw[] =
247 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
253 query = sqlite3_mprintf(query_raw, appid);
255 LOGE("out of memory");
256 return PMINFO_R_ERROR;
259 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
262 if (ret != SQLITE_OK) {
263 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
264 return PMINFO_R_ERROR;
267 while (sqlite3_step(stmt) == SQLITE_ROW) {
268 info = calloc(1, sizeof(category_x));
270 LOGE("out of memory");
271 sqlite3_finalize(stmt);
273 LISTHEAD(*category, info);
276 return PMINFO_R_ERROR;
278 _save_column_str(stmt, 0, &info->name);
279 LISTADD(*category, info);
283 LISTHEAD(*category, info);
287 sqlite3_finalize(stmt);
292 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
299 if (appcontrol_str == NULL)
302 dup = strdup(appcontrol_str);
304 ac = calloc(1, sizeof(appcontrol_x));
306 _LOGE("out of memory");
309 token = strtok_r(dup, "|", &ptr);
310 if (token && strcmp(token, "NULL"))
311 ac->operation = strdup(token);
312 token = strtok_r(NULL, "|", &ptr);
313 if (token && strcmp(token, "NULL"))
314 ac->uri = strdup(token);
315 token = strtok_r(NULL, "|", &ptr);
316 if (token && strcmp(token, "NULL"))
317 ac->mime = strdup(token);
318 LISTADD(*appcontrol, ac);
319 } while ((token = strtok_r(NULL, ";", &ptr)));
322 LISTHEAD(*appcontrol, ac);
328 static int _appinfo_get_app_control(const char *appid,
329 appcontrol_x **appcontrol)
331 static const char query_raw[] =
332 "SELECT app_control FROM package_app_app_control "
337 appcontrol_x *info = NULL;
340 query = sqlite3_mprintf(query_raw, appid);
342 LOGE("out of memory");
343 return PMINFO_R_ERROR;
346 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
349 if (ret != SQLITE_OK) {
350 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
351 return PMINFO_R_ERROR;
354 while (sqlite3_step(stmt) == SQLITE_ROW) {
356 _save_column_str(stmt, 0, (const char **)&str);
358 __parse_appcontrol(&info, str);
364 sqlite3_finalize(stmt);
369 static int _appinfo_get_data_control(const char *appid,
370 datacontrol_x **datacontrol)
372 static const char query_raw[] =
373 "SELECT providerid, access, type "
374 "FROM package_app_data_control WHERE app_id=%Q";
381 query = sqlite3_mprintf(query_raw, appid);
383 LOGE("out of memory");
384 return PMINFO_R_ERROR;
387 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
390 if (ret != SQLITE_OK) {
391 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
392 return PMINFO_R_ERROR;
395 while (sqlite3_step(stmt) == SQLITE_ROW) {
396 info = calloc(1, sizeof(datacontrol_x));
398 LOGE("out of memory");
399 sqlite3_finalize(stmt);
401 LISTHEAD(*datacontrol, info);
404 return PMINFO_R_ERROR;
407 _save_column_str(stmt, idx++, &info->providerid);
408 _save_column_str(stmt, idx++, &info->access);
409 _save_column_str(stmt, idx++, &info->type);
410 LISTADD(*datacontrol, info);
414 LISTHEAD(*datacontrol, info);
418 sqlite3_finalize(stmt);
423 static int _appinfo_get_metadata(const char *appid, metadata_x **metadata)
425 static const char query_raw[] =
426 "SELECT md_key, md_value "
427 "FROM package_app_app_metadata WHERE app_id=%Q";
434 query = sqlite3_mprintf(query_raw, appid);
436 LOGE("out of memory");
437 return PMINFO_R_ERROR;
440 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
443 if (ret != SQLITE_OK) {
444 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
445 return PMINFO_R_ERROR;
448 while (sqlite3_step(stmt) == SQLITE_ROW) {
449 info = calloc(1, sizeof(metadata_x));
451 LOGE("out of memory");
452 sqlite3_finalize(stmt);
454 LISTHEAD(*metadata, info);
457 return PMINFO_R_ERROR;
460 _save_column_str(stmt, idx++, &info->key);
461 _save_column_str(stmt, idx++, &info->value);
462 LISTADD(*metadata, info);
466 LISTHEAD(*metadata, info);
470 sqlite3_finalize(stmt);
476 static int _appinfo_get_app(const char *appid, const char *locale,
477 pkgmgr_appinfo_x **appinfo)
479 static const char query_raw[] =
480 "SELECT app_id, app_component, app_exec, app_nodisplay, "
481 "app_type, app_onboot, app_multiple, app_autorestart, "
482 "app_taskmanage, app_enabled, app_hwacceleration, "
483 "app_screenreader, app_mainapp, app_recentimage, "
484 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
485 "app_landscapeimg, app_guestmodevisibility, "
486 "app_permissiontype, app_preload, app_submode, "
487 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
488 "component_type, package "
489 "FROM package_app_info WHERE app_id=%Q";
494 pkgmgr_appinfo_x *info;
497 query = sqlite3_mprintf(query_raw, appid);
499 LOGE("out of memory");
500 return PMINFO_R_ERROR;
503 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
506 if (ret != SQLITE_OK) {
507 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
508 return PMINFO_R_ERROR;
511 ret = sqlite3_step(stmt);
512 if (ret == SQLITE_DONE) {
513 LOGE("cannot find app");
514 sqlite3_finalize(stmt);
515 return PMINFO_R_ENOENT;
516 } else if (ret != SQLITE_ROW) {
517 LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
518 sqlite3_finalize(stmt);
519 return PMINFO_R_ERROR;
522 app = calloc(1, sizeof(application_x));
524 LOGE("out of memory");
525 sqlite3_finalize(stmt);
526 return PMINFO_R_ERROR;
529 _save_column_str(stmt, idx++, &app->appid);
530 _save_column_str(stmt, idx++, &app->component);
531 _save_column_str(stmt, idx++, &app->exec);
532 _save_column_str(stmt, idx++, &app->nodisplay);
533 _save_column_str(stmt, idx++, &app->type);
534 _save_column_str(stmt, idx++, &app->onboot);
535 _save_column_str(stmt, idx++, &app->multiple);
536 _save_column_str(stmt, idx++, &app->autorestart);
537 _save_column_str(stmt, idx++, &app->taskmanage);
538 _save_column_str(stmt, idx++, &app->enabled);
539 _save_column_str(stmt, idx++, &app->hwacceleration);
540 _save_column_str(stmt, idx++, &app->screenreader);
541 _save_column_str(stmt, idx++, &app->mainapp);
542 _save_column_str(stmt, idx++, &app->recentimage);
543 _save_column_str(stmt, idx++, &app->launchcondition);
544 _save_column_str(stmt, idx++, &app->indicatordisplay);
545 _save_column_str(stmt, idx++, &app->portraitimg);
546 _save_column_str(stmt, idx++, &app->landscapeimg);
547 _save_column_str(stmt, idx++, &app->guestmode_visibility);
548 _save_column_str(stmt, idx++, &app->permission_type);
549 _save_column_str(stmt, idx++, &app->preload);
550 _save_column_str(stmt, idx++, &app->submode);
551 _save_column_str(stmt, idx++, &app->submode_mainid);
552 _save_column_str(stmt, idx++, &app->launch_mode);
553 _save_column_str(stmt, idx++, &app->ui_gadget);
554 _save_column_str(stmt, idx++, &app->component_type);
555 _save_column_str(stmt, idx++, &app->package);
557 if (_appinfo_get_label(app->appid, locale, &app->label)) {
558 pkgmgrinfo_basic_free_application(app);
559 sqlite3_finalize(stmt);
560 return PMINFO_R_ERROR;
563 if (_appinfo_get_icon(app->appid, locale, &app->icon)) {
564 pkgmgrinfo_basic_free_application(app);
565 sqlite3_finalize(stmt);
566 return PMINFO_R_ERROR;
569 if (_appinfo_get_category(app->appid, &app->category)) {
570 pkgmgrinfo_basic_free_application(app);
571 sqlite3_finalize(stmt);
572 return PMINFO_R_ERROR;
575 if (_appinfo_get_app_control(app->appid, &app->appcontrol)) {
576 pkgmgrinfo_basic_free_application(app);
577 sqlite3_finalize(stmt);
578 return PMINFO_R_ERROR;
581 if (_appinfo_get_data_control(app->appid, &app->datacontrol)) {
582 pkgmgrinfo_basic_free_application(app);
583 sqlite3_finalize(stmt);
584 return PMINFO_R_ERROR;
587 if (_appinfo_get_metadata(app->appid, &app->metadata)) {
588 pkgmgrinfo_basic_free_application(app);
589 sqlite3_finalize(stmt);
590 return PMINFO_R_ERROR;
593 info = calloc(1, sizeof(pkgmgr_appinfo_x));
595 LOGE("out of memory");
596 pkgmgrinfo_basic_free_application(app);
597 sqlite3_finalize(stmt);
598 return PMINFO_R_ERROR;
601 info->package = strdup(app->package);
602 info->app_info = app;
603 info->locale = strdup(locale);
606 sqlite3_finalize(stmt);
611 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
612 pkgmgrinfo_appinfo_h *handle)
614 pkgmgr_appinfo_x *appinfo = NULL;
617 if (appid == NULL || handle == NULL) {
618 LOGE("invalid parameter");
619 return PMINFO_R_EINVAL;
622 if (__open_manifest_db(uid, true) < 0)
623 return PMINFO_R_ERROR;
625 locale = _get_system_locale();
626 if (locale == NULL) {
627 __close_manifest_db();
628 return PMINFO_R_ERROR;
631 if (_appinfo_get_app(appid, locale, &appinfo)) {
633 __close_manifest_db();
634 return PMINFO_R_ERROR;
640 __close_manifest_db();
645 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
647 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
650 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
651 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
654 pkgmgr_appinfo_x *info;
661 if (__open_manifest_db(uid, true) < 0)
662 return PMINFO_R_ERROR;
664 locale = _get_system_locale();
665 if (locale == NULL) {
666 __close_manifest_db();
667 return PMINFO_R_ERROR;
670 list = _appinfo_get_filtered_list(locale, filter);
673 __close_manifest_db();
677 for (tmp = list; tmp; tmp = tmp->next) {
678 appid = (char *)tmp->data;
680 if (_appinfo_get_app(appid, locale, &info)) {
684 if (app_list_cb(info, user_data) < 0)
686 pkgmgrinfo_appinfo_destroy_appinfo(info);
693 __close_manifest_db();
698 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
699 pkgmgrinfo_app_component component,
700 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
703 pkgmgrinfo_appinfo_filter_h filter;
705 const char *comp_str = NULL;
707 if (handle == NULL || app_func == NULL) {
708 LOGE("invalied parameter");
709 return PMINFO_R_EINVAL;
712 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
713 LOGE("invalid parameter");
714 return PMINFO_R_EINVAL;
717 if (pkgmgrinfo_appinfo_filter_create(&filter))
718 return PMINFO_R_ERROR;
720 if (pkgmgrinfo_appinfo_filter_add_string(filter,
721 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
722 pkgmgrinfo_appinfo_filter_destroy(filter);
723 return PMINFO_R_ERROR;
729 comp_str = PMINFO_APPINFO_UI_APP;
732 comp_str = PMINFO_APPINFO_SVC_APP;
739 if (pkgmgrinfo_appinfo_filter_add_string(filter,
740 PMINFO_APPINFO_PROP_APP_COMPONENT,
742 pkgmgrinfo_appinfo_filter_destroy(filter);
743 return PMINFO_R_ERROR;
747 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
750 pkgmgrinfo_appinfo_filter_destroy(filter);
755 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
756 pkgmgrinfo_app_list_cb app_func, void *user_data)
758 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
761 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
763 if (app_func == NULL) {
764 LOGE("invalid parameter");
765 return PMINFO_R_EINVAL;
768 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
772 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
774 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
777 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
779 if (app_func == NULL) {
780 LOGE("invalid parameter");
781 return PMINFO_R_EINVAL;
784 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
788 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
790 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
793 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
795 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
797 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
798 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
800 if (info->app_info == NULL || info->app_info->appid == NULL)
801 return PMINFO_R_ERROR;
802 *appid = (char *)info->app_info->appid;
807 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
809 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
811 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
812 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
814 if (info->package == NULL)
815 return PMINFO_R_ERROR;
817 *pkg_name = (char *)info->package;
822 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
824 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
826 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
827 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
829 if (info->package == NULL)
830 return PMINFO_R_ERROR;
832 *pkgid = (char *)info->package;
837 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
839 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
841 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
842 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
844 if (info->app_info == NULL || info->app_info->exec == NULL)
845 return PMINFO_R_ERROR;
846 *exec = (char *)info->app_info->exec;
852 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
857 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
859 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
860 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
862 locale = info->locale;
863 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
865 start = info->app_info->icon;
866 for (ptr = start; ptr != NULL; ptr = ptr->next) {
867 if (ptr->lang == NULL)
870 if (strcmp(ptr->lang, locale) == 0) {
871 *icon = (char *)ptr->text;
872 if (strcasecmp(*icon, "(null)") == 0) {
873 locale = DEFAULT_LOCALE;
878 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
879 *icon = (char *)ptr->text;
884 return PMINFO_R_ERROR;
888 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
893 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
895 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
896 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
898 locale = info->locale;
899 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
901 start = info->app_info->label;
902 for (ptr = start; ptr != NULL; ptr = ptr->next) {
903 if (ptr->lang == NULL)
906 if (strcmp(ptr->lang, locale) == 0) {
907 *label = (char *)ptr->text;
908 if (strcasecmp(*label, "(null)") == 0) {
909 locale = DEFAULT_LOCALE;
914 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
915 *label = (char *)ptr->text;
920 return PMINFO_R_ERROR;
923 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
927 sqlite3_stmt *stmt = NULL;
930 const char *manifest_db;
932 manifest_db = getUserPkgParserDBPathUID(uid);
933 if (manifest_db == NULL) {
934 _LOGE("Failed to get manifest db path");
938 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
939 _LOGE("DB open fail\n");
943 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
945 _LOGE("Out of memory");
949 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
950 _LOGE("prepare_v2 fail\n");
954 if (sqlite3_step(stmt) == SQLITE_ROW) {
955 val = (char *)sqlite3_column_text(stmt, 0);
957 result = strdup(val);
961 sqlite3_finalize(stmt);
968 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
972 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
974 val = _get_localed_label(appid, locale, uid);
976 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
979 return PMINFO_R_ERROR;
986 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
988 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
991 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
993 if ( strcasecmp(comp, "uiapp") == 0)
994 return PMINFO_UI_APP;
995 else if ( strcasecmp(comp, "svcapp") == 0)
996 return PMINFO_SVC_APP;
1001 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1003 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1006 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1007 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1009 if (info->app_info == NULL)
1010 return PMINFO_R_ERROR;
1012 comp = __appcomponent_convert(info->app_info->component);
1014 return PMINFO_R_ERROR;
1021 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1023 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1025 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1026 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1028 if (info->app_info == NULL || info->app_info->type == NULL)
1029 return PMINFO_R_ERROR;
1030 *app_type = (char *)info->app_info->type;
1035 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1036 int *operation_count, char ***operation)
1038 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1039 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1040 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1041 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1042 *operation_count = data->operation_count;
1043 *operation = data->operation;
1047 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1048 int *uri_count, char ***uri)
1050 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1051 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1052 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1053 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1054 *uri_count = data->uri_count;
1059 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1060 int *mime_count, char ***mime)
1062 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1063 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1064 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1065 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1066 *mime_count = data->mime_count;
1071 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1072 int *subapp_count, char ***subapp)
1074 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1075 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1076 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1077 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1078 *subapp_count = data->subapp_count;
1079 *subapp = data->subapp;
1083 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1087 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1089 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1090 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1092 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1093 if (ptr->section == NULL)
1096 val = (char *)ptr->section;
1097 if (val && strcmp(val, "setting") == 0) {
1098 *icon = (char *)ptr->text;
1103 return PMINFO_R_ERROR;
1107 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1111 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1113 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1114 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1116 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1117 if (ptr->section == NULL)
1120 val = (char *)ptr->section;
1121 if (val && strcmp(val, "notification") == 0){
1122 *icon = (char *)ptr->text;
1127 return PMINFO_R_ERROR;
1130 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1133 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1135 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1136 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1138 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1139 return PMINFO_R_ERROR;
1141 val = (char *)info->app_info->recentimage;
1142 if (strcasecmp(val, "capture") == 0)
1143 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1144 else if (strcasecmp(val, "icon") == 0)
1145 *type = PMINFO_RECENTIMAGE_USE_ICON;
1147 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1152 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1156 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1158 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1159 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1161 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1162 if (ptr->section == NULL)
1165 val = (char *)ptr->section;
1166 if (val && strcmp(val, "preview") == 0) {
1167 *preview_img = (char *)ptr->text;
1172 return PMINFO_R_ERROR;
1175 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1178 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1180 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1181 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1183 val = info->app_info->permission_type;
1185 return PMINFO_R_ERROR;
1187 if (strcmp(val, "signature") == 0)
1188 *permission = PMINFO_PERMISSION_SIGNATURE;
1189 else if (strcmp(val, "privilege") == 0)
1190 *permission = PMINFO_PERMISSION_PRIVILEGE;
1192 *permission = PMINFO_PERMISSION_NORMAL;
1197 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1199 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1201 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1202 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1204 if (info->app_info == NULL || info->app_info->component_type == NULL)
1205 return PMINFO_R_ERROR;
1207 *component_type = (char *)info->app_info->component_type;
1212 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1215 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1217 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1218 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1220 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1221 return PMINFO_R_ERROR;
1223 val = (char *)info->app_info->hwacceleration;
1224 if (strcasecmp(val, "not-use-GL") == 0)
1225 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1226 else if (strcasecmp(val, "use-GL") == 0)
1227 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1229 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1234 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1237 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1239 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1240 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1242 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1243 return PMINFO_R_ERROR;
1245 val = (char *)info->app_info->screenreader;
1246 if (strcasecmp(val, "screenreader-off") == 0)
1247 *screenreader = PMINFO_SCREENREADER_OFF;
1248 else if (strcasecmp(val, "screenreader-on") == 0)
1249 *screenreader = PMINFO_SCREENREADER_ON;
1251 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1256 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1258 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1260 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1261 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1262 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1264 if (info->app_info == NULL || info->app_info->portraitimg ||
1265 info->app_info->landscapeimg == NULL)
1266 return PMINFO_R_ERROR;
1268 *portrait_img = (char *)info->app_info->portraitimg;
1269 *landscape_img = (char *)info->app_info->landscapeimg;
1274 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1276 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1278 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1279 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1281 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1282 return PMINFO_R_ERROR;
1284 *submode_mainid = (char *)info->app_info->submode_mainid;
1289 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1291 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1293 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1294 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1296 if (info->app_info->launch_mode == NULL)
1297 return PMINFO_R_ERROR;
1299 *mode = (char *)(info->app_info->launch_mode);
1304 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1306 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1307 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1308 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1309 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1311 int ret = PMINFO_R_OK;
1313 sqlite3_stmt *stmt = NULL;
1316 ret = __open_manifest_db(uid, true);
1317 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1319 /*Start constructing query*/
1320 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1323 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1324 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1327 ret = sqlite3_step(stmt);
1328 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1330 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1331 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1336 sqlite3_free(query);
1337 sqlite3_finalize(stmt);
1338 __close_manifest_db();
1342 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1344 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1347 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1349 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1350 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1352 int ret = PMINFO_R_OK;
1354 sqlite3_stmt *stmt = NULL;
1357 ret = __open_manifest_db(uid, true);
1358 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1360 /*Start constructing query*/
1361 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1364 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1365 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1368 ret = sqlite3_step(stmt);
1369 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1371 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1376 sqlite3_free(query);
1377 sqlite3_finalize(stmt);
1378 __close_manifest_db();
1382 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1384 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1387 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1388 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1390 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1391 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1393 permission_x *ptr = NULL;
1394 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1396 if (info->app_info == NULL)
1397 return PMINFO_R_ERROR;
1399 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1401 ret = permission_func(ptr->value, user_data);
1409 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1410 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1412 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1413 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1415 category_x *ptr = NULL;
1416 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1418 if (info->app_info == NULL)
1419 return PMINFO_R_ERROR;
1421 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1423 ret = category_func(ptr->name, user_data);
1431 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1432 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1434 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1435 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1437 metadata_x *ptr = NULL;
1438 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1440 if (info->app_info == NULL)
1441 return PMINFO_R_ERROR;
1443 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1445 ret = metadata_func(ptr->key, ptr->value, user_data);
1453 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1454 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1456 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1457 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1459 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1460 appcontrol_x *appcontrol;
1462 if (info->uiapp_info == NULL)
1463 return PMINFO_R_ERROR;
1465 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1466 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1474 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1476 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1477 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1478 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1480 if (info->app_info == NULL)
1481 return PMINFO_R_ERROR;
1483 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1487 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1489 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1490 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1491 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1493 if (info->app_info == NULL)
1494 return PMINFO_R_ERROR;
1496 *multiple = _get_bool_value(info->app_info->multiple);
1500 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1502 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1503 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1504 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1506 if (info->app_info == NULL)
1507 return PMINFO_R_ERROR;
1509 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1513 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1515 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1516 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1517 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1519 if (info->app_info == NULL)
1520 return PMINFO_R_ERROR;
1522 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1526 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1528 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1529 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1530 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1532 if (info->app_info == NULL)
1533 return PMINFO_R_ERROR;
1535 *enabled = _get_bool_value(info->app_info->enabled);
1540 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1543 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1544 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1546 if (info->app_info == NULL)
1547 return PMINFO_R_ERROR;
1549 *onboot = _get_bool_value(info->app_info->onboot);
1553 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1555 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1556 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1557 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1559 if (info->app_info == NULL)
1560 return PMINFO_R_ERROR;
1562 *autorestart = _get_bool_value(info->app_info->autorestart);
1566 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1568 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1569 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1570 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1572 if (info->app_info == NULL)
1573 return PMINFO_R_ERROR;
1575 *mainapp = _get_bool_value(info->app_info->mainapp);
1579 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1581 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1582 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1583 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1585 if (info->app_info == NULL)
1586 return PMINFO_R_ERROR;
1588 *preload = _get_bool_value(info->app_info->preload);
1592 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1594 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1595 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1596 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1598 if (info->app_info == NULL)
1599 return PMINFO_R_ERROR;
1601 *submode = _get_bool_value(info->app_info->submode);
1605 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1607 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1608 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1609 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1611 category_x *ptr = NULL;
1612 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1614 if (info->app_info == NULL)
1615 return PMINFO_R_ERROR;
1618 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1620 if (strcasecmp(ptr->name, category) == 0) {
1630 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1633 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1635 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1636 _LOGE("invalid parameter");
1637 return PMINFO_R_EINVAL;
1640 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1645 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1647 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1648 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1649 __cleanup_appinfo(info);
1653 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1655 return (pkgmgrinfo_pkginfo_filter_create(handle));
1658 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1660 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1663 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1665 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1666 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1667 if (node1->prop == node2->prop)
1669 else if (node1->prop > node2->prop)
1675 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1676 const char *property, const int value)
1678 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1679 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1680 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1682 GSList *link = NULL;
1684 prop = _pminfo_appinfo_convert_to_prop_int(property);
1685 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1686 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1687 _LOGE("Invalid Integer Property\n");
1688 return PMINFO_R_EINVAL;
1690 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1691 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1693 _LOGE("Out of Memory!!!\n");
1694 return PMINFO_R_ERROR;
1696 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1697 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1699 _LOGE("Out of Memory\n");
1702 return PMINFO_R_ERROR;
1706 /*If API is called multiple times for same property, we should override the previous values.
1707 Last value set will be used for filtering.*/
1708 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1710 filter->list = g_slist_delete_link(filter->list, link);
1711 filter->list = g_slist_append(filter->list, (gpointer)node);
1716 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1717 const char *property, const bool value)
1719 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1720 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1722 GSList *link = NULL;
1724 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1725 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1726 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1727 _LOGE("Invalid Boolean Property\n");
1728 return PMINFO_R_EINVAL;
1730 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1731 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1733 _LOGE("Out of Memory!!!\n");
1734 return PMINFO_R_ERROR;
1737 val = strndup("('true','True')", 15);
1739 val = strndup("('false','False')", 17);
1741 _LOGE("Out of Memory\n");
1744 return PMINFO_R_ERROR;
1748 /*If API is called multiple times for same property, we should override the previous values.
1749 Last value set will be used for filtering.*/
1750 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1752 filter->list = g_slist_delete_link(filter->list, link);
1753 filter->list = g_slist_append(filter->list, (gpointer)node);
1758 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1759 const char *property, const char *value)
1761 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1762 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1763 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1765 pkgmgrinfo_node_x *ptr = NULL;
1766 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1767 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1768 GSList *link = NULL;
1770 prop = _pminfo_appinfo_convert_to_prop_str(property);
1771 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1772 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1773 _LOGE("Invalid String Property\n");
1774 return PMINFO_R_EINVAL;
1776 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1777 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1779 _LOGE("Out of Memory!!!\n");
1780 return PMINFO_R_ERROR;
1784 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1785 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1786 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1788 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1790 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1792 filter->list = g_slist_delete_link(filter->list, link);
1793 filter->list = g_slist_append(filter->list, (gpointer)node);
1795 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1796 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1797 case E_PMINFO_APPINFO_PROP_APP_URI:
1798 case E_PMINFO_APPINFO_PROP_APP_MIME:
1799 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1801 _LOGE("Out of Memory\n");
1804 return PMINFO_R_ERROR;
1806 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1808 ptr = (pkgmgrinfo_node_x *)link->data;
1809 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1810 _LOGE("Previous value is %s\n", prev);
1811 filter->list = g_slist_delete_link(filter->list, link);
1812 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1813 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1814 _LOGE("New value is %s\n", val);
1816 filter->list = g_slist_append(filter->list, (gpointer)node);
1817 memset(temp, '\0', PKG_STRING_LEN_MAX);
1819 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1820 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1821 _LOGE("First value is %s\n", val);
1823 filter->list = g_slist_append(filter->list, (gpointer)node);
1824 memset(temp, '\0', PKG_STRING_LEN_MAX);
1828 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1829 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1831 filter->list = g_slist_delete_link(filter->list, link);
1832 filter->list = g_slist_append(filter->list, (gpointer)node);
1838 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
1840 int *p = (int*)data;
1841 *p = atoi(coltxt[0]);
1842 _LOGE("count value is %d\n", *p);
1846 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1848 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1849 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1850 char *locale = NULL;
1851 char *condition = NULL;
1852 char *error_message = NULL;
1853 char query[MAX_QUERY_LEN] = {'\0'};
1854 char where[MAX_QUERY_LEN] = {'\0'};
1858 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1859 /*Get current locale*/
1860 locale = _get_system_locale();
1861 if (locale == NULL) {
1862 _LOGE("manifest locale is NULL\n");
1863 return PMINFO_R_ERROR;
1866 ret = __open_manifest_db(uid, true);
1868 _LOGE("Fail to open manifest DB\n");
1870 return PMINFO_R_ERROR;
1873 /*Start constructing query*/
1874 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
1876 /*Get where clause*/
1877 for (list = filter->list; list; list = g_slist_next(list)) {
1878 __get_filter_condition(list->data, &condition);
1880 strncat(where, condition, sizeof(where) - strlen(where) -1);
1881 where[sizeof(where) - 1] = '\0';
1885 if (g_slist_next(list)) {
1886 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1887 where[sizeof(where) - 1] = '\0';
1890 if (strlen(where) > 0) {
1891 strncat(query, where, sizeof(query) - strlen(query) - 1);
1892 query[sizeof(query) - 1] = '\0';
1897 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
1898 _LOGE("Don't execute query = %s error message = %s\n", query,
1900 sqlite3_free(error_message);
1901 ret = PMINFO_R_ERROR;
1911 __close_manifest_db();
1915 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1917 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1920 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1921 pkgmgrinfo_appinfo_filter_h handle,
1922 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1924 if (handle == NULL || app_cb == NULL) {
1925 LOGE("invalid parameter");
1926 return PMINFO_R_EINVAL;
1929 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1933 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1934 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1936 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1939 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1941 return (pkgmgrinfo_pkginfo_filter_create(handle));
1944 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
1946 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1949 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
1950 const char *key, const char *value)
1952 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
1953 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
1954 /*value can be NULL. In that case all apps with specified key should be displayed*/
1958 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1959 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1960 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
1962 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1966 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1969 /*If API is called multiple times, we should OR all conditions.*/
1970 filter->list = g_slist_append(filter->list, (gpointer)node);
1971 /*All memory will be freed in destroy API*/
1989 static void __get_metadata_filter_condition(gpointer data, char **condition)
1991 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
1992 char key[MAX_QUERY_LEN] = {'\0'};
1993 char value[MAX_QUERY_LEN] = {'\0'};
1995 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
1998 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
2003 *condition = strdup(key);
2007 static char *_get_metadata_filtered_query(const char *query_raw,
2008 pkgmgrinfo_filter_x *filter)
2010 char buf[MAX_QUERY_LEN] = { 0, };
2014 GSList *head = NULL;
2017 head = filter->list;
2019 strncat(buf, query_raw, MAX_QUERY_LEN - 1);
2021 for (list = head; list; list = list->next) {
2022 /* TODO: revise condition getter function */
2023 __get_metadata_filter_condition(list->data, &condition);
2024 if (condition == NULL)
2026 if (buf[strlen(query_raw)] == '\0') {
2027 len += strlen(" WHERE ");
2028 strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
2030 len += strlen(" AND ");
2031 strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
2033 len += strlen(condition);
2034 strncat(buf, condition, sizeof(buf) - len - 1);
2042 static GSList *_appinfo_get_metadata_filtered_list(pkgmgrinfo_filter_x *filter)
2044 static const char query_raw[] =
2045 "SELECT app_id FROM package_app_app_metadata";
2049 GSList *list = NULL;
2052 query = _get_metadata_filtered_query(query_raw, filter);
2053 if (query == NULL) {
2054 LOGE("out of memory");
2058 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
2061 if (ret != SQLITE_OK) {
2062 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
2066 while (sqlite3_step(stmt) == SQLITE_ROW) {
2067 _save_column_str(stmt, 0, (const char **)&appid);
2068 list = g_slist_append(list, appid);
2071 sqlite3_finalize(stmt);
2076 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2077 pkgmgrinfo_appinfo_metadata_filter_h handle,
2078 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2083 pkgmgrinfo_appinfo_h info;
2086 if (handle == NULL || app_cb == NULL) {
2087 LOGE("invalid parameter");
2088 return PMINFO_R_EINVAL;
2091 if (__open_manifest_db(uid, true) < 0)
2092 return PMINFO_R_ERROR;
2094 list = _appinfo_get_metadata_filtered_list(handle);
2097 __close_manifest_db();
2101 for (tmp = list; tmp; tmp = tmp->next) {
2102 appid = (char *)tmp->data;
2104 if (pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid,
2109 if (app_cb(info, user_data) < 0)
2111 pkgmgrinfo_appinfo_destroy_appinfo(info);
2117 __close_manifest_db();
2122 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
2123 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2125 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
2128 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2131 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2133 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2134 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2136 val = info->uiapp_info->guestmode_visibility;
2137 *status = _get_bool_value(val);