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 "
103 " LEFT OUTER JOIN package_app_app_metadata"
104 " ON package_app_info.app_id=package_app_app_metadata.app_id ";
107 char *query_localized;
112 query = _get_filtered_query(query_raw, filter);
115 query_localized = sqlite3_mprintf(query, locale);
117 if (query_localized == NULL)
120 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query_localized,
121 strlen(query_localized), &stmt, NULL);
122 sqlite3_free(query_localized);
123 if (ret != SQLITE_OK) {
124 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
128 while (sqlite3_step(stmt) == SQLITE_ROW) {
129 _save_column_str(stmt, 0, (const char **)&appid);
130 list = g_slist_append(list, appid);
133 sqlite3_finalize(stmt);
138 static int _appinfo_get_label(const char *appid, const char *locale,
141 static const char query_raw[] =
142 "SELECT app_label, app_locale "
143 "FROM package_app_localized_info "
144 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
151 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
153 LOGE("out of memory");
154 return PMINFO_R_ERROR;
157 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
160 if (ret != SQLITE_OK) {
161 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
162 return PMINFO_R_ERROR;
165 while (sqlite3_step(stmt) == SQLITE_ROW) {
166 info = calloc(1, sizeof(label_x));
168 LOGE("out of memory");
169 sqlite3_finalize(stmt);
171 LISTHEAD(*label, info);
174 return PMINFO_R_ERROR;
177 _save_column_str(stmt, idx++, &info->text);
178 _save_column_str(stmt, idx++, &info->lang);
179 LISTADD(*label, info);
183 LISTHEAD(*label, info);
187 sqlite3_finalize(stmt);
192 static int _appinfo_get_icon(const char *appid, const char *locale,
195 static const char query_raw[] =
196 "SELECT app_icon, app_locale "
197 "FROM package_app_localized_info "
198 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
205 query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
207 LOGE("out of memory");
208 return PMINFO_R_ERROR;
211 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
214 if (ret != SQLITE_OK) {
215 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
216 return PMINFO_R_ERROR;
219 while (sqlite3_step(stmt) == SQLITE_ROW) {
220 info = calloc(1, sizeof(icon_x));
222 LOGE("out of memory");
223 sqlite3_finalize(stmt);
225 LISTHEAD(*icon, info);
228 return PMINFO_R_ERROR;
231 _save_column_str(stmt, idx++, &info->text);
232 _save_column_str(stmt, idx++, &info->lang);
233 LISTADD(*icon, info);
237 LISTHEAD(*icon, info);
241 sqlite3_finalize(stmt);
246 static int _appinfo_get_category(const char *appid, category_x **category)
248 static const char query_raw[] =
249 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
255 query = sqlite3_mprintf(query_raw, appid);
257 LOGE("out of memory");
258 return PMINFO_R_ERROR;
261 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
264 if (ret != SQLITE_OK) {
265 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
266 return PMINFO_R_ERROR;
269 while (sqlite3_step(stmt) == SQLITE_ROW) {
270 info = calloc(1, sizeof(category_x));
272 LOGE("out of memory");
273 sqlite3_finalize(stmt);
275 LISTHEAD(*category, info);
278 return PMINFO_R_ERROR;
280 _save_column_str(stmt, 0, &info->name);
281 LISTADD(*category, info);
285 LISTHEAD(*category, info);
289 sqlite3_finalize(stmt);
294 static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
301 if (appcontrol_str == NULL)
304 dup = strdup(appcontrol_str);
306 ac = calloc(1, sizeof(appcontrol_x));
308 _LOGE("out of memory");
311 token = strtok_r(dup, "|", &ptr);
312 if (token && strcmp(token, "NULL"))
313 ac->operation = strdup(token);
314 token = strtok_r(NULL, "|", &ptr);
315 if (token && strcmp(token, "NULL"))
316 ac->uri = strdup(token);
317 token = strtok_r(NULL, "|", &ptr);
318 if (token && strcmp(token, "NULL"))
319 ac->mime = strdup(token);
320 LISTADD(*appcontrol, ac);
321 } while ((token = strtok_r(NULL, ";", &ptr)));
324 LISTHEAD(*appcontrol, ac);
330 static int _appinfo_get_app_control(const char *appid,
331 appcontrol_x **appcontrol)
333 static const char query_raw[] =
334 "SELECT app_control FROM package_app_app_control "
339 appcontrol_x *info = NULL;
342 query = sqlite3_mprintf(query_raw, appid);
344 LOGE("out of memory");
345 return PMINFO_R_ERROR;
348 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
351 if (ret != SQLITE_OK) {
352 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
353 return PMINFO_R_ERROR;
356 while (sqlite3_step(stmt) == SQLITE_ROW) {
358 _save_column_str(stmt, 0, (const char **)&str);
360 __parse_appcontrol(&info, str);
366 sqlite3_finalize(stmt);
371 static int _appinfo_get_data_control(const char *appid,
372 datacontrol_x **datacontrol)
374 static const char query_raw[] =
375 "SELECT providerid, access, type "
376 "FROM package_app_data_control WHERE app_id=%Q";
383 query = sqlite3_mprintf(query_raw, appid);
385 LOGE("out of memory");
386 return PMINFO_R_ERROR;
389 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
392 if (ret != SQLITE_OK) {
393 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
394 return PMINFO_R_ERROR;
397 while (sqlite3_step(stmt) == SQLITE_ROW) {
398 info = calloc(1, sizeof(datacontrol_x));
400 LOGE("out of memory");
401 sqlite3_finalize(stmt);
403 LISTHEAD(*datacontrol, info);
406 return PMINFO_R_ERROR;
409 _save_column_str(stmt, idx++, &info->providerid);
410 _save_column_str(stmt, idx++, &info->access);
411 _save_column_str(stmt, idx++, &info->type);
412 LISTADD(*datacontrol, info);
416 LISTHEAD(*datacontrol, info);
420 sqlite3_finalize(stmt);
425 static int _appinfo_get_metadata(const char *appid, metadata_x **metadata)
427 static const char query_raw[] =
428 "SELECT md_key, md_value "
429 "FROM package_app_app_metadata WHERE app_id=%Q";
436 query = sqlite3_mprintf(query_raw, appid);
438 LOGE("out of memory");
439 return PMINFO_R_ERROR;
442 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
445 if (ret != SQLITE_OK) {
446 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
447 return PMINFO_R_ERROR;
450 while (sqlite3_step(stmt) == SQLITE_ROW) {
451 info = calloc(1, sizeof(metadata_x));
453 LOGE("out of memory");
454 sqlite3_finalize(stmt);
456 LISTHEAD(*metadata, info);
459 return PMINFO_R_ERROR;
462 _save_column_str(stmt, idx++, &info->key);
463 _save_column_str(stmt, idx++, &info->value);
464 LISTADD(*metadata, info);
468 LISTHEAD(*metadata, info);
472 sqlite3_finalize(stmt);
478 static int _appinfo_get_app(const char *appid, const char *locale,
479 pkgmgr_appinfo_x **appinfo)
481 static const char query_raw[] =
482 "SELECT app_id, app_component, app_exec, app_nodisplay, "
483 "app_type, app_onboot, app_multiple, app_autorestart, "
484 "app_taskmanage, app_enabled, app_hwacceleration, "
485 "app_screenreader, app_mainapp, app_recentimage, "
486 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
487 "app_landscapeimg, app_guestmodevisibility, "
488 "app_permissiontype, app_preload, app_submode, "
489 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
490 "component_type, package "
491 "FROM package_app_info WHERE app_id=%Q";
496 pkgmgr_appinfo_x *info;
499 query = sqlite3_mprintf(query_raw, appid);
501 LOGE("out of memory");
502 return PMINFO_R_ERROR;
505 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
508 if (ret != SQLITE_OK) {
509 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
510 return PMINFO_R_ERROR;
513 ret = sqlite3_step(stmt);
514 if (ret == SQLITE_DONE) {
515 LOGE("cannot find app");
516 sqlite3_finalize(stmt);
517 return PMINFO_R_ENOENT;
518 } else if (ret != SQLITE_ROW) {
519 LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
520 sqlite3_finalize(stmt);
521 return PMINFO_R_ERROR;
524 app = calloc(1, sizeof(application_x));
526 LOGE("out of memory");
527 sqlite3_finalize(stmt);
528 return PMINFO_R_ERROR;
531 _save_column_str(stmt, idx++, &app->appid);
532 _save_column_str(stmt, idx++, &app->component);
533 _save_column_str(stmt, idx++, &app->exec);
534 _save_column_str(stmt, idx++, &app->nodisplay);
535 _save_column_str(stmt, idx++, &app->type);
536 _save_column_str(stmt, idx++, &app->onboot);
537 _save_column_str(stmt, idx++, &app->multiple);
538 _save_column_str(stmt, idx++, &app->autorestart);
539 _save_column_str(stmt, idx++, &app->taskmanage);
540 _save_column_str(stmt, idx++, &app->enabled);
541 _save_column_str(stmt, idx++, &app->hwacceleration);
542 _save_column_str(stmt, idx++, &app->screenreader);
543 _save_column_str(stmt, idx++, &app->mainapp);
544 _save_column_str(stmt, idx++, &app->recentimage);
545 _save_column_str(stmt, idx++, &app->launchcondition);
546 _save_column_str(stmt, idx++, &app->indicatordisplay);
547 _save_column_str(stmt, idx++, &app->portraitimg);
548 _save_column_str(stmt, idx++, &app->landscapeimg);
549 _save_column_str(stmt, idx++, &app->guestmode_visibility);
550 _save_column_str(stmt, idx++, &app->permission_type);
551 _save_column_str(stmt, idx++, &app->preload);
552 _save_column_str(stmt, idx++, &app->submode);
553 _save_column_str(stmt, idx++, &app->submode_mainid);
554 _save_column_str(stmt, idx++, &app->launch_mode);
555 _save_column_str(stmt, idx++, &app->ui_gadget);
556 _save_column_str(stmt, idx++, &app->component_type);
557 _save_column_str(stmt, idx++, &app->package);
559 if (_appinfo_get_label(app->appid, locale, &app->label)) {
560 pkgmgrinfo_basic_free_application(app);
561 sqlite3_finalize(stmt);
562 return PMINFO_R_ERROR;
565 if (_appinfo_get_icon(app->appid, locale, &app->icon)) {
566 pkgmgrinfo_basic_free_application(app);
567 sqlite3_finalize(stmt);
568 return PMINFO_R_ERROR;
571 if (_appinfo_get_category(app->appid, &app->category)) {
572 pkgmgrinfo_basic_free_application(app);
573 sqlite3_finalize(stmt);
574 return PMINFO_R_ERROR;
577 if (_appinfo_get_app_control(app->appid, &app->appcontrol)) {
578 pkgmgrinfo_basic_free_application(app);
579 sqlite3_finalize(stmt);
580 return PMINFO_R_ERROR;
583 if (_appinfo_get_data_control(app->appid, &app->datacontrol)) {
584 pkgmgrinfo_basic_free_application(app);
585 sqlite3_finalize(stmt);
586 return PMINFO_R_ERROR;
589 if (_appinfo_get_metadata(app->appid, &app->metadata)) {
590 pkgmgrinfo_basic_free_application(app);
591 sqlite3_finalize(stmt);
592 return PMINFO_R_ERROR;
595 info = calloc(1, sizeof(pkgmgr_appinfo_x));
597 LOGE("out of memory");
598 pkgmgrinfo_basic_free_application(app);
599 sqlite3_finalize(stmt);
600 return PMINFO_R_ERROR;
603 info->package = strdup(app->package);
604 info->app_info = app;
605 info->locale = strdup(locale);
608 sqlite3_finalize(stmt);
613 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
614 pkgmgrinfo_appinfo_h *handle)
616 pkgmgr_appinfo_x *appinfo = NULL;
619 if (appid == NULL || handle == NULL) {
620 LOGE("invalid parameter");
621 return PMINFO_R_EINVAL;
624 if (__open_manifest_db(uid, true) < 0)
625 return PMINFO_R_ERROR;
627 locale = _get_system_locale();
628 if (locale == NULL) {
629 __close_manifest_db();
630 return PMINFO_R_ERROR;
633 if (_appinfo_get_app(appid, locale, &appinfo)) {
635 __close_manifest_db();
636 return PMINFO_R_ERROR;
642 __close_manifest_db();
647 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
649 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
652 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
653 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
656 pkgmgr_appinfo_x *info;
663 if (__open_manifest_db(uid, true) < 0)
664 return PMINFO_R_ERROR;
666 locale = _get_system_locale();
667 if (locale == NULL) {
668 __close_manifest_db();
669 return PMINFO_R_ERROR;
672 list = _appinfo_get_filtered_list(locale, filter);
675 __close_manifest_db();
679 for (tmp = list; tmp; tmp = tmp->next) {
680 appid = (char *)tmp->data;
682 if (_appinfo_get_app(appid, locale, &info)) {
686 if (app_list_cb(info, user_data) < 0)
688 pkgmgrinfo_appinfo_destroy_appinfo(info);
695 __close_manifest_db();
700 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
701 pkgmgrinfo_app_component component,
702 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
705 pkgmgrinfo_appinfo_filter_h filter;
707 const char *comp_str = NULL;
709 if (handle == NULL || app_func == NULL) {
710 LOGE("invalied parameter");
711 return PMINFO_R_EINVAL;
714 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
715 LOGE("invalid parameter");
716 return PMINFO_R_EINVAL;
719 if (pkgmgrinfo_appinfo_filter_create(&filter))
720 return PMINFO_R_ERROR;
722 if (pkgmgrinfo_appinfo_filter_add_string(filter,
723 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
724 pkgmgrinfo_appinfo_filter_destroy(filter);
725 return PMINFO_R_ERROR;
731 comp_str = PMINFO_APPINFO_UI_APP;
734 comp_str = PMINFO_APPINFO_SVC_APP;
741 if (pkgmgrinfo_appinfo_filter_add_string(filter,
742 PMINFO_APPINFO_PROP_APP_COMPONENT,
744 pkgmgrinfo_appinfo_filter_destroy(filter);
745 return PMINFO_R_ERROR;
749 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
752 pkgmgrinfo_appinfo_filter_destroy(filter);
757 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
758 pkgmgrinfo_app_list_cb app_func, void *user_data)
760 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
763 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
765 if (app_func == NULL) {
766 LOGE("invalid parameter");
767 return PMINFO_R_EINVAL;
770 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
774 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
776 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
779 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
781 if (app_func == NULL) {
782 LOGE("invalid parameter");
783 return PMINFO_R_EINVAL;
786 return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
790 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
792 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
795 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
797 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
799 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
800 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
802 if (info->app_info == NULL || info->app_info->appid == NULL)
803 return PMINFO_R_ERROR;
804 *appid = (char *)info->app_info->appid;
809 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
811 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
813 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
814 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
816 if (info->package == NULL)
817 return PMINFO_R_ERROR;
819 *pkg_name = (char *)info->package;
824 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
826 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
828 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
829 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
831 if (info->package == NULL)
832 return PMINFO_R_ERROR;
834 *pkgid = (char *)info->package;
839 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
841 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
843 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
844 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
846 if (info->app_info == NULL || info->app_info->exec == NULL)
847 return PMINFO_R_ERROR;
848 *exec = (char *)info->app_info->exec;
854 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
859 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
861 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
862 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
864 locale = info->locale;
865 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
867 start = info->app_info->icon;
868 for (ptr = start; ptr != NULL; ptr = ptr->next) {
869 if (ptr->lang == NULL)
872 if (strcmp(ptr->lang, locale) == 0) {
873 *icon = (char *)ptr->text;
874 if (strcasecmp(*icon, "(null)") == 0) {
875 locale = DEFAULT_LOCALE;
880 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
881 *icon = (char *)ptr->text;
886 return PMINFO_R_ERROR;
890 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
895 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
897 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
898 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
900 locale = info->locale;
901 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
903 start = info->app_info->label;
904 for (ptr = start; ptr != NULL; ptr = ptr->next) {
905 if (ptr->lang == NULL)
908 if (strcmp(ptr->lang, locale) == 0) {
909 *label = (char *)ptr->text;
910 if (strcasecmp(*label, "(null)") == 0) {
911 locale = DEFAULT_LOCALE;
916 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
917 *label = (char *)ptr->text;
922 return PMINFO_R_ERROR;
925 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
929 sqlite3_stmt *stmt = NULL;
932 const char *manifest_db;
934 manifest_db = getUserPkgParserDBPathUID(uid);
935 if (manifest_db == NULL) {
936 _LOGE("Failed to get manifest db path");
940 if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
941 _LOGE("DB open fail\n");
945 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
947 _LOGE("Out of memory");
951 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
952 _LOGE("prepare_v2 fail\n");
956 if (sqlite3_step(stmt) == SQLITE_ROW) {
957 val = (char *)sqlite3_column_text(stmt, 0);
959 result = strdup(val);
963 sqlite3_finalize(stmt);
970 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
974 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
976 val = _get_localed_label(appid, locale, uid);
978 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
981 return PMINFO_R_ERROR;
988 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
990 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
993 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
995 if ( strcasecmp(comp, "uiapp") == 0)
996 return PMINFO_UI_APP;
997 else if ( strcasecmp(comp, "svcapp") == 0)
998 return PMINFO_SVC_APP;
1003 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1005 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1008 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1009 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1011 if (info->app_info == NULL)
1012 return PMINFO_R_ERROR;
1014 comp = __appcomponent_convert(info->app_info->component);
1016 return PMINFO_R_ERROR;
1023 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1025 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1027 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1028 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1030 if (info->app_info == NULL || info->app_info->type == NULL)
1031 return PMINFO_R_ERROR;
1032 *app_type = (char *)info->app_info->type;
1037 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1038 int *operation_count, char ***operation)
1040 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1041 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1042 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1043 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1044 *operation_count = data->operation_count;
1045 *operation = data->operation;
1049 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1050 int *uri_count, char ***uri)
1052 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1053 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1054 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1055 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1056 *uri_count = data->uri_count;
1061 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1062 int *mime_count, char ***mime)
1064 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1065 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1066 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1067 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1068 *mime_count = data->mime_count;
1073 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1074 int *subapp_count, char ***subapp)
1076 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1077 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1078 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1079 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1080 *subapp_count = data->subapp_count;
1081 *subapp = data->subapp;
1085 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1089 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1091 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1092 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1094 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1095 if (ptr->section == NULL)
1098 val = (char *)ptr->section;
1099 if (val && strcmp(val, "setting") == 0) {
1100 *icon = (char *)ptr->text;
1105 return PMINFO_R_ERROR;
1109 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1113 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1115 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1116 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1118 for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
1119 if (ptr->section == NULL)
1122 val = (char *)ptr->section;
1123 if (val && strcmp(val, "notification") == 0){
1124 *icon = (char *)ptr->text;
1129 return PMINFO_R_ERROR;
1132 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1135 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1137 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1138 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1140 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1141 return PMINFO_R_ERROR;
1143 val = (char *)info->app_info->recentimage;
1144 if (strcasecmp(val, "capture") == 0)
1145 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1146 else if (strcasecmp(val, "icon") == 0)
1147 *type = PMINFO_RECENTIMAGE_USE_ICON;
1149 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1154 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1158 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1161 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1163 for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
1164 if (ptr->section == NULL)
1167 val = (char *)ptr->section;
1168 if (val && strcmp(val, "preview") == 0) {
1169 *preview_img = (char *)ptr->text;
1174 return PMINFO_R_ERROR;
1177 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1180 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1182 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1183 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1185 val = info->app_info->permission_type;
1187 return PMINFO_R_ERROR;
1189 if (strcmp(val, "signature") == 0)
1190 *permission = PMINFO_PERMISSION_SIGNATURE;
1191 else if (strcmp(val, "privilege") == 0)
1192 *permission = PMINFO_PERMISSION_PRIVILEGE;
1194 *permission = PMINFO_PERMISSION_NORMAL;
1199 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1201 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1204 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1206 if (info->app_info == NULL || info->app_info->component_type == NULL)
1207 return PMINFO_R_ERROR;
1209 *component_type = (char *)info->app_info->component_type;
1214 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1217 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1220 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1222 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1223 return PMINFO_R_ERROR;
1225 val = (char *)info->app_info->hwacceleration;
1226 if (strcasecmp(val, "not-use-GL") == 0)
1227 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1228 else if (strcasecmp(val, "use-GL") == 0)
1229 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1231 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1236 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1239 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1241 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1242 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1244 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1245 return PMINFO_R_ERROR;
1247 val = (char *)info->app_info->screenreader;
1248 if (strcasecmp(val, "screenreader-off") == 0)
1249 *screenreader = PMINFO_SCREENREADER_OFF;
1250 else if (strcasecmp(val, "screenreader-on") == 0)
1251 *screenreader = PMINFO_SCREENREADER_ON;
1253 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1258 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1260 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1262 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1263 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1264 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1266 if (info->app_info == NULL || info->app_info->portraitimg ||
1267 info->app_info->landscapeimg == NULL)
1268 return PMINFO_R_ERROR;
1270 *portrait_img = (char *)info->app_info->portraitimg;
1271 *landscape_img = (char *)info->app_info->landscapeimg;
1276 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1278 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1280 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1281 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1283 if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1284 return PMINFO_R_ERROR;
1286 *submode_mainid = (char *)info->app_info->submode_mainid;
1291 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1293 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1296 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1298 if (info->app_info->launch_mode == NULL)
1299 return PMINFO_R_ERROR;
1301 *mode = (char *)(info->app_info->launch_mode);
1306 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1308 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1309 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1310 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1311 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1313 int ret = PMINFO_R_OK;
1315 sqlite3_stmt *stmt = NULL;
1318 ret = __open_manifest_db(uid, true);
1319 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1321 /*Start constructing query*/
1322 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1325 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1326 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1329 ret = sqlite3_step(stmt);
1330 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1332 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1333 *access = strdup((char *)sqlite3_column_text(stmt, 2));
1338 sqlite3_free(query);
1339 sqlite3_finalize(stmt);
1340 __close_manifest_db();
1344 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1346 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1349 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1351 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1352 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1354 int ret = PMINFO_R_OK;
1356 sqlite3_stmt *stmt = NULL;
1359 ret = __open_manifest_db(uid, true);
1360 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1362 /*Start constructing query*/
1363 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1366 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1367 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1370 ret = sqlite3_step(stmt);
1371 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1373 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1378 sqlite3_free(query);
1379 sqlite3_finalize(stmt);
1380 __close_manifest_db();
1384 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1386 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1389 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1390 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1392 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1393 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1395 permission_x *ptr = NULL;
1396 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1398 if (info->app_info == NULL)
1399 return PMINFO_R_ERROR;
1401 for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
1403 ret = permission_func(ptr->value, user_data);
1411 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1412 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1414 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1415 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1417 category_x *ptr = NULL;
1418 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1420 if (info->app_info == NULL)
1421 return PMINFO_R_ERROR;
1423 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1425 ret = category_func(ptr->name, user_data);
1433 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1434 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1436 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1437 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1439 metadata_x *ptr = NULL;
1440 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1442 if (info->app_info == NULL)
1443 return PMINFO_R_ERROR;
1445 for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
1447 ret = metadata_func(ptr->key, ptr->value, user_data);
1455 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1456 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1458 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1459 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1461 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1462 appcontrol_x *appcontrol;
1464 if (info->uiapp_info == NULL)
1465 return PMINFO_R_ERROR;
1467 for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
1468 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1476 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1478 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1479 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1480 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1482 if (info->app_info == NULL)
1483 return PMINFO_R_ERROR;
1485 *nodisplay = _get_bool_value(info->app_info->nodisplay);
1489 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1491 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1492 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1493 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1495 if (info->app_info == NULL)
1496 return PMINFO_R_ERROR;
1498 *multiple = _get_bool_value(info->app_info->multiple);
1502 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1504 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1505 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1506 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1508 if (info->app_info == NULL)
1509 return PMINFO_R_ERROR;
1511 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1515 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
1517 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1518 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1519 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1521 if (info->app_info == NULL)
1522 return PMINFO_R_ERROR;
1524 *taskmanage = _get_bool_value(info->app_info->taskmanage);
1528 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
1530 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1531 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1532 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1534 if (info->app_info == NULL)
1535 return PMINFO_R_ERROR;
1537 *enabled = _get_bool_value(info->app_info->enabled);
1542 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
1544 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1545 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1546 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1548 if (info->app_info == NULL)
1549 return PMINFO_R_ERROR;
1551 *onboot = _get_bool_value(info->app_info->onboot);
1555 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
1557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1558 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1559 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1561 if (info->app_info == NULL)
1562 return PMINFO_R_ERROR;
1564 *autorestart = _get_bool_value(info->app_info->autorestart);
1568 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
1570 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1571 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1572 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1574 if (info->app_info == NULL)
1575 return PMINFO_R_ERROR;
1577 *mainapp = _get_bool_value(info->app_info->mainapp);
1581 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1583 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1584 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1585 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1587 if (info->app_info == NULL)
1588 return PMINFO_R_ERROR;
1590 *preload = _get_bool_value(info->app_info->preload);
1594 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1596 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1597 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1598 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1600 if (info->app_info == NULL)
1601 return PMINFO_R_ERROR;
1603 *submode = _get_bool_value(info->app_info->submode);
1607 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1610 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1611 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1613 category_x *ptr = NULL;
1614 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1616 if (info->app_info == NULL)
1617 return PMINFO_R_ERROR;
1620 for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
1622 if (strcasecmp(ptr->name, category) == 0) {
1632 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1635 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1637 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1638 _LOGE("invalid parameter");
1639 return PMINFO_R_EINVAL;
1642 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1647 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1649 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1650 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1651 __cleanup_appinfo(info);
1655 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1657 return (pkgmgrinfo_pkginfo_filter_create(handle));
1660 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1662 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1665 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1667 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1668 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1669 if (node1->prop == node2->prop)
1671 else if (node1->prop > node2->prop)
1677 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1678 const char *property, const int value)
1680 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1681 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1682 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1684 GSList *link = NULL;
1686 prop = _pminfo_appinfo_convert_to_prop_int(property);
1687 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1688 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1689 _LOGE("Invalid Integer Property\n");
1690 return PMINFO_R_EINVAL;
1692 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1693 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1695 _LOGE("Out of Memory!!!\n");
1696 return PMINFO_R_ERROR;
1698 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1699 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1701 _LOGE("Out of Memory\n");
1704 return PMINFO_R_ERROR;
1708 /*If API is called multiple times for same property, we should override the previous values.
1709 Last value set will be used for filtering.*/
1710 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1712 filter->list = g_slist_delete_link(filter->list, link);
1713 filter->list = g_slist_append(filter->list, (gpointer)node);
1718 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1719 const char *property, const bool value)
1721 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1722 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1724 GSList *link = NULL;
1726 prop = _pminfo_appinfo_convert_to_prop_bool(property);
1727 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1728 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1729 _LOGE("Invalid Boolean Property\n");
1730 return PMINFO_R_EINVAL;
1732 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1733 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1735 _LOGE("Out of Memory!!!\n");
1736 return PMINFO_R_ERROR;
1739 val = strndup("('true','True')", 15);
1741 val = strndup("('false','False')", 17);
1743 _LOGE("Out of Memory\n");
1746 return PMINFO_R_ERROR;
1750 /*If API is called multiple times for same property, we should override the previous values.
1751 Last value set will be used for filtering.*/
1752 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1754 filter->list = g_slist_delete_link(filter->list, link);
1755 filter->list = g_slist_append(filter->list, (gpointer)node);
1760 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1761 const char *property, const char *value)
1763 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1764 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1765 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1767 pkgmgrinfo_node_x *ptr = NULL;
1768 char prev[PKG_STRING_LEN_MAX] = {'\0'};
1769 char temp[PKG_STRING_LEN_MAX] = {'\0'};
1770 GSList *link = NULL;
1772 prop = _pminfo_appinfo_convert_to_prop_str(property);
1773 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1774 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1775 _LOGE("Invalid String Property\n");
1776 return PMINFO_R_EINVAL;
1778 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1779 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1781 _LOGE("Out of Memory!!!\n");
1782 return PMINFO_R_ERROR;
1786 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1787 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1788 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1790 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1792 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1794 filter->list = g_slist_delete_link(filter->list, link);
1795 filter->list = g_slist_append(filter->list, (gpointer)node);
1797 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1798 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1799 case E_PMINFO_APPINFO_PROP_APP_URI:
1800 case E_PMINFO_APPINFO_PROP_APP_MIME:
1801 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1803 _LOGE("Out of Memory\n");
1806 return PMINFO_R_ERROR;
1808 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1810 ptr = (pkgmgrinfo_node_x *)link->data;
1811 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1812 _LOGE("Previous value is %s\n", prev);
1813 filter->list = g_slist_delete_link(filter->list, link);
1814 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1815 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1816 _LOGE("New value is %s\n", val);
1818 filter->list = g_slist_append(filter->list, (gpointer)node);
1819 memset(temp, '\0', PKG_STRING_LEN_MAX);
1821 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1822 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1823 _LOGE("First value is %s\n", val);
1825 filter->list = g_slist_append(filter->list, (gpointer)node);
1826 memset(temp, '\0', PKG_STRING_LEN_MAX);
1830 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1831 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1833 filter->list = g_slist_delete_link(filter->list, link);
1834 filter->list = g_slist_append(filter->list, (gpointer)node);
1840 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
1842 int *p = (int*)data;
1843 *p = atoi(coltxt[0]);
1844 _LOGE("count value is %d\n", *p);
1848 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1850 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1851 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1852 char *locale = NULL;
1853 char *condition = NULL;
1854 char *error_message = NULL;
1855 char query[MAX_QUERY_LEN] = {'\0'};
1856 char where[MAX_QUERY_LEN] = {'\0'};
1860 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1861 /*Get current locale*/
1862 locale = _get_system_locale();
1863 if (locale == NULL) {
1864 _LOGE("manifest locale is NULL\n");
1865 return PMINFO_R_ERROR;
1868 ret = __open_manifest_db(uid, true);
1870 _LOGE("Fail to open manifest DB\n");
1872 return PMINFO_R_ERROR;
1875 /*Start constructing query*/
1876 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
1878 /*Get where clause*/
1879 for (list = filter->list; list; list = g_slist_next(list)) {
1880 __get_filter_condition(list->data, &condition);
1882 strncat(where, condition, sizeof(where) - strlen(where) -1);
1883 where[sizeof(where) - 1] = '\0';
1887 if (g_slist_next(list)) {
1888 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1889 where[sizeof(where) - 1] = '\0';
1892 if (strlen(where) > 0) {
1893 strncat(query, where, sizeof(query) - strlen(query) - 1);
1894 query[sizeof(query) - 1] = '\0';
1899 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
1900 _LOGE("Don't execute query = %s error message = %s\n", query,
1902 sqlite3_free(error_message);
1903 ret = PMINFO_R_ERROR;
1913 __close_manifest_db();
1917 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1919 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1922 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1923 pkgmgrinfo_appinfo_filter_h handle,
1924 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1926 if (handle == NULL || app_cb == NULL) {
1927 LOGE("invalid parameter");
1928 return PMINFO_R_EINVAL;
1931 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1935 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1936 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1938 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1941 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1943 return (pkgmgrinfo_pkginfo_filter_create(handle));
1946 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
1948 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1951 API int pkgmgrinfo_appinfo_metadata_filter_add(
1952 pkgmgrinfo_appinfo_metadata_filter_h handle,
1953 const char *key, const char *value)
1957 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
1958 PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
1959 if (ret != PMINFO_R_OK)
1962 /* value can be NULL.
1963 * In that case all apps with specified key should be displayed
1966 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
1967 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
1968 if (ret != PMINFO_R_OK)
1975 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
1976 pkgmgrinfo_appinfo_metadata_filter_h handle,
1977 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1979 if (handle == NULL || app_cb == NULL) {
1980 LOGE("invalid parameter");
1981 return PMINFO_R_EINVAL;
1984 return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1988 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
1989 pkgmgrinfo_appinfo_metadata_filter_h handle,
1990 pkgmgrinfo_app_list_cb app_cb, void *user_data)
1992 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
1993 user_data, GLOBAL_USER);
1996 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
1999 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2001 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2002 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2004 val = info->uiapp_info->guestmode_visibility;
2005 *status = _get_bool_value(val);