13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 static bool _get_bool_value(const char *str)
20 if (str && !strcmp(str, "true"))
26 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
28 pkgmgr_appinfo_x *info = data;
32 free((void *)info->package);
34 free((void *)info->locale);
36 pkgmgrinfo_basic_free_application(info->app_info);
42 static const char join_localized_info[] =
43 " LEFT OUTER JOIN package_app_localized_info"
44 " ON ai.app_id=package_app_localized_info.app_id"
45 " AND package_app_localized_info.app_locale=?";
46 static const char join_category[] =
47 " LEFT OUTER JOIN package_app_app_category"
48 " ON ai.app_id=package_app_app_category.app_id";
49 static const char join_app_control[] =
50 " LEFT OUTER JOIN package_app_app_control"
51 " ON ai.app_id=package_app_app_control.app_id";
52 static const char join_metadata[] =
53 " LEFT OUTER JOIN package_app_app_metadata"
54 " ON ai.app_id=package_app_app_metadata.app_id ";
56 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
57 const char *locale, uid_t uid, char **query, GList **bind_params)
60 char *condition = NULL;
61 char buf[MAX_QUERY_LEN] = { '\0' };
62 char tmp_query[MAX_QUERY_LEN] = { '\0' };
67 strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1);
69 for (list = filter->list; list; list = list->next) {
70 joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
71 if (condition == NULL)
74 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
76 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
81 if (filter->list_metadata)
82 strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1);
83 for (list = filter->list_metadata; list; list = list->next) {
84 joined |= __get_metadata_filter_condition(list->data,
85 &condition, bind_params);
86 if (condition == NULL)
88 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
92 strncat(buf, " OR ", sizeof(buf) - strlen(buf) - 1);
94 if (filter->list_metadata)
95 strncat(buf, "1=0)", sizeof(buf) - strlen(buf) - 1);
97 if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
98 strncat(tmp_query, join_localized_info, sizeof(tmp_query) - strlen(tmp_query) - 1);
99 *bind_params = g_list_append(*bind_params, strdup(locale));
101 if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY)
102 strncat(tmp_query, join_category, sizeof(tmp_query) - strlen(tmp_query) - 1);
103 if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL)
104 strncat(tmp_query, join_app_control, sizeof(tmp_query) - strlen(tmp_query) - 1);
105 if (joined & E_PMINFO_APPINFO_JOIN_METADATA)
106 strncat(tmp_query, join_metadata, sizeof(tmp_query) - strlen(tmp_query) - 1);
108 strncat(tmp_query, buf, sizeof(tmp_query) - strlen(tmp_query) - 1);
110 *query = strdup(tmp_query);
112 return PMINFO_R_ERROR;
117 static int _appinfo_get_category(sqlite3 *db, const char *appid,
120 static const char query_raw[] =
121 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
127 query = sqlite3_mprintf(query_raw, appid);
129 LOGE("out of memory");
130 return PMINFO_R_ERROR;
133 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
135 if (ret != SQLITE_OK) {
136 LOGE("prepare failed: %s", sqlite3_errmsg(db));
137 return PMINFO_R_ERROR;
140 while (sqlite3_step(stmt) == SQLITE_ROW) {
142 _save_column_str(stmt, 0, &val);
144 *category = g_list_append(*category, (gpointer)val);
147 sqlite3_finalize(stmt);
152 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
159 if (appcontrol_str == NULL)
162 dup = strdup(appcontrol_str);
164 ac = calloc(1, sizeof(appcontrol_x));
166 _LOGE("out of memory");
169 token = strtok_r(dup, "|", &ptr);
170 if (token && strcmp(token, "NULL"))
171 ac->operation = strdup(token);
172 token = strtok_r(NULL, "|", &ptr);
173 if (token && strcmp(token, "NULL"))
174 ac->uri = strdup(token);
175 token = strtok_r(NULL, "|", &ptr);
176 if (token && strcmp(token, "NULL"))
177 ac->mime = strdup(token);
178 *appcontrol = g_list_append(*appcontrol, ac);
179 } while ((token = strtok_r(NULL, ";", &ptr)));
184 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
187 static const char query_raw[] =
188 "SELECT app_control FROM package_app_app_control "
195 query = sqlite3_mprintf(query_raw, appid);
197 LOGE("out of memory");
198 return PMINFO_R_ERROR;
201 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
203 if (ret != SQLITE_OK) {
204 LOGE("prepare failed: %s", sqlite3_errmsg(db));
205 return PMINFO_R_ERROR;
208 while (sqlite3_step(stmt) == SQLITE_ROW) {
210 _save_column_str(stmt, 0, &str);
212 __parse_appcontrol(appcontrol, str);
216 sqlite3_finalize(stmt);
221 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
224 static const char query_raw[] =
225 "SELECT md_key, md_value "
226 "FROM package_app_app_metadata WHERE app_id=%Q";
233 query = sqlite3_mprintf(query_raw, appid);
235 LOGE("out of memory");
236 return PMINFO_R_ERROR;
239 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
241 if (ret != SQLITE_OK) {
242 LOGE("prepare failed: %s", sqlite3_errmsg(db));
243 return PMINFO_R_ERROR;
246 while (sqlite3_step(stmt) == SQLITE_ROW) {
247 info = calloc(1, sizeof(metadata_x));
249 LOGE("out of memory");
250 sqlite3_finalize(stmt);
251 return PMINFO_R_ERROR;
254 _save_column_str(stmt, idx++, &info->key);
255 _save_column_str(stmt, idx++, &info->value);
256 *metadata = g_list_append(*metadata, info);
259 sqlite3_finalize(stmt);
265 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
266 GList **splashscreens)
268 static const char query_raw[] =
269 "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
270 "FROM package_app_splash_screen WHERE app_id=%Q";
275 splashscreen_x *info;
277 query = sqlite3_mprintf(query_raw, appid);
279 LOGE("out of memory");
280 return PMINFO_R_ERROR;
283 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
285 if (ret != SQLITE_OK) {
286 LOGE("prepare failed: %s", sqlite3_errmsg(db));
287 return PMINFO_R_ERROR;
290 while (sqlite3_step(stmt) == SQLITE_ROW) {
291 info = calloc(1, sizeof(splashscreen_x));
293 LOGE("out of memory");
294 sqlite3_finalize(stmt);
295 return PMINFO_R_ERROR;
298 _save_column_str(stmt, idx++, &info->src);
299 _save_column_str(stmt, idx++, &info->type);
300 _save_column_str(stmt, idx++, &info->orientation);
301 _save_column_str(stmt, idx++, &info->indicatordisplay);
302 _save_column_str(stmt, idx++, &info->operation);
303 _save_column_str(stmt, idx++, &info->color_depth);
304 *splashscreens = g_list_append(*splashscreens, info);
307 sqlite3_finalize(stmt);
312 static GList *__get_background_category(const char *value)
314 GList *category_list = NULL;
315 int convert_value = 0;
316 if (!value || strlen(value) == 0)
319 convert_value = atoi(value);
320 if (convert_value < 0)
323 if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
324 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
326 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
328 if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
329 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
331 if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
332 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
334 if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
335 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
337 if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
338 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
340 if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
341 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
343 if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
344 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
346 if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
347 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
349 return category_list;
353 static void __free_applications(gpointer data)
355 pkgmgrinfo_basic_free_application((application_x *)data);
358 static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
360 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
361 pkgmgrinfo_appinfo_disable_type *value =
362 (pkgmgrinfo_appinfo_disable_type *)data2;
364 if (value == E_APPINFO_DISABLE_TYPE_PKG)
365 return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
368 return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
372 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
373 pkgmgrinfo_appinfo_disable_type type)
380 link = g_slist_find_custom(filter->list, &type, __disable_chk_func);
387 static int __bind_params(sqlite3_stmt *stmt, GList *params)
389 GList *tmp_list = NULL;
393 if (stmt == NULL || params == NULL)
394 return PMINFO_R_EINVAL;
398 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
399 if (ret != SQLITE_OK)
400 return PMINFO_R_ERROR;
401 tmp_list = tmp_list->next;
407 static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter)
409 GSList *tmp_list = NULL;
410 pkgmgrinfo_node_x *tmp_node = NULL;
413 if (tmp_filter == NULL)
416 property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
417 for (tmp_list = tmp_filter->list; tmp_list != NULL;
418 tmp_list = g_slist_next(tmp_list)) {
419 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
420 if (property == tmp_node->prop) {
421 if (strcmp(tmp_node->value, "true") == 0)
431 static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
432 const char *locale, pkgmgrinfo_filter_x *filter, int flag,
433 GHashTable *applications)
435 static const char query_raw[] =
436 "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
437 "ai.app_external_path";
438 static const char query_basic[] =
439 ", ai.app_component, ai.app_exec, "
440 "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
441 "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
442 "ai.app_hwacceleration, ai.app_screenreader, "
443 "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, "
444 "ai.app_indicatordisplay, ai.app_portraitimg, "
445 "ai.app_landscapeimg, ai.app_guestmodevisibility, "
446 "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
447 "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
448 "ai.app_support_disable, ai.app_process_pool, "
449 "ai.app_background_category, ai.app_package_type, "
450 "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
451 "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
452 "ai.app_zip_mount_file, ai.component_type, ai.package, "
453 "ai.app_package_system, ai.app_removable, "
454 "ai.app_package_installed_time, ai.app_support_mode, "
455 "ai.app_support_ambient, ai.app_setup_appid";
456 static const char query_uid_info[] =
457 ", ui.is_disabled, ui.is_splash_screen_enabled";
458 static const char query_label[] =
460 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
461 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
462 static const char query_icon[] =
464 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
465 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
466 static const char query_from_clause[] = " FROM package_app_info as ai";
467 static const char query_uid_info_clause[] =
468 " LEFT OUTER JOIN package_app_info_for_uid AS ui "
469 "ON (ai.app_id=ui.app_id AND ui.uid=?)";
470 int ret = PMINFO_R_ERROR;
473 char *bg_category_str = NULL;
474 char *constraint = NULL;
475 char *tmp_record = NULL;
476 char query[MAX_QUERY_LEN] = { '\0' };
477 char buf[BUFSIZE] = { '\0' };
478 application_x *info = NULL;
479 GList *bind_params = NULL;
481 sqlite3_stmt *stmt = NULL;
482 bool is_check_storage = true;
483 const uid_t global_user_uid = GLOBAL_USER;
485 dbpath = getUserPkgParserDBPathUID(db_uid);
487 return PMINFO_R_ERROR;
489 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
490 if (ret != SQLITE_OK) {
491 _LOGE("failed to open db(%s): %d", dbpath, ret);
493 return PMINFO_R_ERROR;
497 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
499 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
500 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
501 strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1);
503 if (flag & PMINFO_APPINFO_GET_LABEL) {
504 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
505 bind_params = g_list_append(bind_params, strdup(locale));
507 if (flag & PMINFO_APPINFO_GET_ICON) {
508 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
509 bind_params = g_list_append(bind_params, strdup(locale));
512 snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
513 bind_params = g_list_append(bind_params, strdup(buf));
515 is_check_storage = __check_app_storage_status(filter);
517 ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
518 if (ret != PMINFO_R_OK) {
519 LOGE("Failed to get WHERE clause");
522 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
524 strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1);
527 strncat(query, constraint, sizeof(query) - strlen(query) - 1);
529 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
530 if (ret != SQLITE_OK) {
531 LOGE("prepare failed: %s", sqlite3_errmsg(db));
532 ret = PMINFO_R_ERROR;
536 if (g_list_length(bind_params) != 0) {
537 ret = __bind_params(stmt, bind_params);
538 if (ret != SQLITE_OK) {
539 LOGE("Failed to bind parameters");
544 while (sqlite3_step(stmt) == SQLITE_ROW) {
545 info = calloc(1, sizeof(application_x));
547 LOGE("out of memory");
548 ret = PMINFO_R_ERROR;
552 _save_column_str(stmt, idx++, &info->appid);
553 _save_column_str(stmt, idx++, &info->installed_storage);
554 _save_column_str(stmt, idx++ , &info->external_path);
556 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
557 _save_column_str(stmt, idx++, &info->component);
558 _save_column_str(stmt, idx++, &info->exec);
559 _save_column_str(stmt, idx++, &info->nodisplay);
560 _save_column_str(stmt, idx++, &info->type);
561 _save_column_str(stmt, idx++, &info->onboot);
562 _save_column_str(stmt, idx++, &info->multiple);
563 _save_column_str(stmt, idx++, &info->autorestart);
564 _save_column_str(stmt, idx++, &info->taskmanage);
565 _save_column_str(stmt, idx++, &info->hwacceleration);
566 _save_column_str(stmt, idx++, &info->screenreader);
567 _save_column_str(stmt, idx++, &info->mainapp);
568 _save_column_str(stmt, idx++, &info->recentimage);
569 _save_column_str(stmt, idx++, &info->launchcondition);
570 _save_column_str(stmt, idx++, &info->indicatordisplay);
571 _save_column_str(stmt, idx++, &info->portraitimg);
572 _save_column_str(stmt, idx++, &info->landscapeimg);
573 _save_column_str(stmt, idx++, &info->guestmode_visibility);
574 _save_column_str(stmt, idx++, &info->permission_type);
575 _save_column_str(stmt, idx++, &info->preload);
576 _save_column_str(stmt, idx++, &info->submode);
577 _save_column_str(stmt, idx++, &info->submode_mainid);
578 _save_column_str(stmt, idx++, &info->launch_mode);
579 _save_column_str(stmt, idx++, &info->ui_gadget);
580 _save_column_str(stmt, idx++, &info->support_disable);
581 _save_column_str(stmt, idx++, &info->process_pool);
582 _save_column_str(stmt, idx++, &bg_category_str);
583 _save_column_str(stmt, idx++, &info->package_type);
584 _save_column_str(stmt, idx++, &info->root_path);
585 _save_column_str(stmt, idx++, &info->api_version);
586 _save_column_str(stmt, idx++, &info->effective_appid);
587 _save_column_str(stmt, idx++, &info->is_disabled);
588 _save_column_str(stmt, idx++, &info->splash_screen_display);
589 _save_column_str(stmt, idx++, &info->tep_name);
590 _save_column_str(stmt, idx++, &info->zip_mount_file);
591 _save_column_str(stmt, idx++, &info->component_type);
592 _save_column_str(stmt, idx++, &info->package);
593 _save_column_str(stmt, idx++, &info->package_system);
594 _save_column_str(stmt, idx++, &info->removable);
595 _save_column_str(stmt, idx++, &info->package_installed_time);
596 _save_column_str(stmt, idx++, &info->support_mode);
597 _save_column_str(stmt, idx++, &info->support_ambient);
598 _save_column_str(stmt, idx++, &info->setup_appid);
599 info->background_category = __get_background_category(
601 free(bg_category_str);
604 info->for_all_users =
605 strdup((db_uid != global_user_uid) ? "false" : "true");
607 if (db_uid != global_user_uid) {
611 _save_column_str(stmt, idx++, &tmp_record);
612 if (tmp_record != NULL) {
613 if (strcasecmp(info->is_disabled, "false") == 0 &&
614 strcasecmp(tmp_record, "false") == 0) {
615 free(info->is_disabled);
616 info->is_disabled = tmp_record;
620 _save_column_str(stmt, idx++, &tmp_record);
621 if (tmp_record != NULL) {
622 if (strcasecmp(info->splash_screen_display, "false") == 0 &&
623 strcasecmp(tmp_record, "false") == 0) {
624 free(info->splash_screen_display);
625 info->splash_screen_display = tmp_record;
630 if (flag & PMINFO_APPINFO_GET_LABEL) {
632 _save_column_str(stmt, idx++, &tmp_record);
633 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
634 ret = PMINFO_R_ERROR;
639 if (flag & PMINFO_APPINFO_GET_ICON) {
641 _save_column_str(stmt, idx++, &tmp_record);
642 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
643 ret = PMINFO_R_ERROR;
648 if (flag & PMINFO_APPINFO_GET_CATEGORY) {
649 if (_appinfo_get_category(db, info->appid,
651 ret = PMINFO_R_ERROR;
656 if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
657 if (_appinfo_get_app_control(db, info->appid,
658 &info->appcontrol)) {
659 ret = PMINFO_R_ERROR;
664 if (flag & PMINFO_APPINFO_GET_METADATA) {
665 if (_appinfo_get_metadata(db, info->appid,
667 ret = PMINFO_R_ERROR;
672 if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
673 if (_appinfo_get_splashscreens(db, info->appid,
674 &info->splashscreens)) {
675 ret = PMINFO_R_ERROR;
680 if (is_check_storage &&
681 __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
682 ret = PMINFO_R_ERROR;
683 pkgmgrinfo_basic_free_application(info);
688 g_hash_table_insert(applications, (gpointer)info->appid,
698 if (ret != PMINFO_R_OK && info != NULL)
699 pkgmgrinfo_basic_free_application(info);
701 g_list_free_full(bind_params, free);
702 sqlite3_close_v2(db);
703 sqlite3_finalize(stmt);
708 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
709 pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
714 pkgmgr_appinfo_x *info;
716 if (appid == NULL || filter == NULL || handle == NULL) {
717 LOGE("invalid parameter");
718 return PMINFO_R_EINVAL;
721 locale = _get_system_locale();
723 return PMINFO_R_ERROR;
725 list = g_hash_table_new(g_str_hash, g_str_equal);
728 return PMINFO_R_ERROR;
731 ret = _appinfo_get_applications(uid, uid, locale, filter,
732 PMINFO_APPINFO_GET_ALL, list);
733 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
734 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
735 PMINFO_APPINFO_GET_ALL, list);
737 if (!g_hash_table_size(list)) {
738 _LOGD("appinfo for [%s] is not existed for user [%d]",
740 g_hash_table_destroy(list);
742 return PMINFO_R_ENOENT;
745 info = calloc(1, sizeof(pkgmgr_appinfo_x));
747 _LOGE("out of memory");
748 g_hash_table_destroy(list);
750 return PMINFO_R_ERROR;
753 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
754 info->locale = locale;
755 info->package = strdup(info->app_info->package);
757 /* just free list only */
758 g_hash_table_destroy(list);
765 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
766 pkgmgrinfo_appinfo_h *handle)
769 pkgmgrinfo_appinfo_filter_h filter;
771 if (appid == NULL || handle == NULL) {
772 LOGE("invalid parameter");
773 return PMINFO_R_EINVAL;
776 ret = pkgmgrinfo_appinfo_filter_create(&filter);
777 if (ret != PMINFO_R_OK)
780 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
781 PMINFO_APPINFO_PROP_APP_ID, appid);
782 if (ret != PMINFO_R_OK) {
783 pkgmgrinfo_appinfo_filter_destroy(filter);
784 return PMINFO_R_ERROR;
787 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
788 PMINFO_APPINFO_PROP_APP_DISABLE, true);
789 if (ret != PMINFO_R_OK) {
790 pkgmgrinfo_appinfo_filter_destroy(filter);
791 return PMINFO_R_ERROR;
794 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
795 pkgmgrinfo_appinfo_filter_destroy(filter);
800 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
802 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
805 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
806 pkgmgrinfo_appinfo_h *handle)
809 pkgmgrinfo_appinfo_filter_h filter;
811 if (appid == NULL || handle == NULL) {
812 LOGE("invalid parameter");
813 return PMINFO_R_EINVAL;
816 ret = pkgmgrinfo_appinfo_filter_create(&filter);
817 if (ret != PMINFO_R_OK)
820 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
821 PMINFO_APPINFO_PROP_APP_ID, appid);
822 if (ret != PMINFO_R_OK) {
823 pkgmgrinfo_appinfo_filter_destroy(filter);
824 return PMINFO_R_ERROR;
827 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
828 PMINFO_APPINFO_PROP_APP_DISABLE, false);
829 if (ret != PMINFO_R_OK) {
830 pkgmgrinfo_appinfo_filter_destroy(filter);
831 return PMINFO_R_ERROR;
834 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
835 PMINFO_APPINFO_PROP_PKG_DISABLE, false);
836 if (ret != PMINFO_R_OK) {
837 pkgmgrinfo_appinfo_filter_destroy(filter);
838 return PMINFO_R_ERROR;
841 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
842 pkgmgrinfo_appinfo_filter_destroy(filter);
846 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
848 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
851 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
852 pkgmgrinfo_appinfo_h *handle)
855 pkgmgrinfo_appinfo_filter_h filter;
857 if (appid == NULL || handle == NULL) {
858 LOGE("invalid parameter");
859 return PMINFO_R_EINVAL;
862 ret = pkgmgrinfo_appinfo_filter_create(&filter);
863 if (ret != PMINFO_R_OK)
866 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
867 PMINFO_APPINFO_PROP_APP_ID, appid);
868 if (ret != PMINFO_R_OK) {
869 pkgmgrinfo_appinfo_filter_destroy(filter);
870 return PMINFO_R_ERROR;
873 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
874 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
875 if (ret != PMINFO_R_OK) {
876 pkgmgrinfo_appinfo_filter_destroy(filter);
877 return PMINFO_R_ERROR;
880 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
881 pkgmgrinfo_appinfo_filter_destroy(filter);
886 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
888 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
891 static gpointer __copy_str(gconstpointer src, gpointer data)
893 const char *tmp = (const char *)src;
896 buffer = strdup(tmp);
897 if (buffer == NULL) {
898 LOGE("memory alloc failed");
906 static gpointer __copy_label(gconstpointer src, gpointer data)
908 label_x *tmp = (label_x *)src;
911 label = calloc(1, sizeof(label_x));
913 LOGE("memory alloc failed");
919 label->name = strdup(tmp->name);
921 label->text = strdup(tmp->text);
923 label->lang = strdup(tmp->lang);
928 static gpointer __copy_icon(gconstpointer src, gpointer data)
930 icon_x *tmp = (icon_x *)src;
933 icon = calloc(1, sizeof(icon_x));
935 LOGE("memory alloc failed");
941 icon->text = strdup(tmp->text);
943 icon->lang = strdup(tmp->lang);
945 icon->section = strdup(tmp->section);
947 icon->size = strdup(tmp->size);
949 icon->resolution = strdup(tmp->resolution);
954 static gpointer __copy_metadata(gconstpointer src, gpointer data)
956 metadata_x *tmp = (metadata_x *)src;
957 metadata_x *metadata;
959 metadata = calloc(1, sizeof(metadata_x));
960 if (metadata == NULL) {
961 LOGE("memory alloc failed");
967 metadata->key = strdup(tmp->key);
969 metadata->value = strdup(tmp->value);
974 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
976 datacontrol_x *tmp = (datacontrol_x *)src;
977 datacontrol_x *datacontrol;
979 datacontrol = calloc(1, sizeof(datacontrol_x));
980 if (datacontrol == NULL) {
981 LOGE("memory alloc failed");
987 datacontrol->providerid = strdup(tmp->providerid);
989 datacontrol->access = strdup(tmp->access);
991 datacontrol->type = strdup(tmp->type);
993 datacontrol->trusted = strdup(tmp->trusted);
998 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1000 appcontrol_x *tmp = (appcontrol_x *)src;
1001 appcontrol_x *appcontrol;
1003 appcontrol = calloc(1, sizeof(appcontrol_x));
1004 if (appcontrol == NULL) {
1005 LOGE("memory alloc failed");
1011 appcontrol->operation = strdup(tmp->operation);
1013 appcontrol->uri = strdup(tmp->uri);
1015 appcontrol->mime = strdup(tmp->mime);
1020 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1022 splashscreen_x *tmp = (splashscreen_x *)src;
1023 splashscreen_x *splashscreen;
1025 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1026 if (splashscreen == NULL) {
1027 LOGE("memory alloc failed");
1033 splashscreen->src = strdup(tmp->src);
1035 splashscreen->type = strdup(tmp->type);
1036 if (tmp->orientation)
1037 splashscreen->orientation = strdup(tmp->orientation);
1038 if (tmp->indicatordisplay)
1039 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1041 splashscreen->operation = strdup(tmp->operation);
1042 if (tmp->color_depth)
1043 splashscreen->color_depth = strdup(tmp->color_depth);
1045 return splashscreen;
1048 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1050 application_x *app_info;
1053 app_info = calloc(1, sizeof(application_x));
1054 if (app_info == NULL) {
1055 LOGE("memory alloc failed");
1056 return PMINFO_R_ERROR;
1059 if (data->appid != NULL)
1060 app_info->appid = strdup(data->appid);
1061 if (data->exec != NULL)
1062 app_info->exec = strdup(data->exec);
1063 if (data->nodisplay != NULL)
1064 app_info->nodisplay = strdup(data->nodisplay);
1065 if (data->multiple != NULL)
1066 app_info->multiple = strdup(data->multiple);
1067 if (data->taskmanage != NULL)
1068 app_info->taskmanage = strdup(data->taskmanage);
1069 if (data->type != NULL)
1070 app_info->type = strdup(data->type);
1071 if (data->categories != NULL)
1072 app_info->categories = strdup(data->categories);
1073 if (data->hwacceleration != NULL)
1074 app_info->hwacceleration = strdup(data->hwacceleration);
1075 if (data->screenreader != NULL)
1076 app_info->screenreader = strdup(data->screenreader);
1077 if (data->mainapp != NULL)
1078 app_info->mainapp = strdup(data->mainapp);
1079 if (data->package != NULL)
1080 app_info->package = strdup(data->package);
1081 if (data->recentimage != NULL)
1082 app_info->recentimage = strdup(data->recentimage);
1083 if (data->launchcondition != NULL)
1084 app_info->launchcondition = strdup(data->launchcondition);
1085 if (data->indicatordisplay != NULL)
1086 app_info->indicatordisplay = strdup(data->indicatordisplay);
1087 if (data->portraitimg != NULL)
1088 app_info->portraitimg = strdup(data->portraitimg);
1089 if (data->landscapeimg != NULL)
1090 app_info->landscapeimg = strdup(data->landscapeimg);
1091 if (data->guestmode_visibility != NULL)
1092 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1093 if (data->component != NULL)
1094 app_info->component = strdup(data->component);
1095 if (data->permission_type != NULL)
1096 app_info->permission_type = strdup(data->permission_type);
1097 if (data->component_type != NULL)
1098 app_info->component_type = strdup(data->component_type);
1099 if (data->preload != NULL)
1100 app_info->preload = strdup(data->preload);
1101 if (data->submode != NULL)
1102 app_info->submode = strdup(data->submode);
1103 if (data->submode_mainid != NULL)
1104 app_info->submode_mainid = strdup(data->submode_mainid);
1105 if (data->process_pool != NULL)
1106 app_info->process_pool = strdup(data->process_pool);
1107 if (data->installed_storage != NULL)
1108 app_info->installed_storage = strdup(data->installed_storage);
1109 if (data->autorestart != NULL)
1110 app_info->autorestart = strdup(data->autorestart);
1111 if (data->onboot != NULL)
1112 app_info->onboot = strdup(data->onboot);
1113 if (data->support_disable != NULL)
1114 app_info->support_disable = strdup(data->support_disable);
1115 if (data->ui_gadget != NULL)
1116 app_info->ui_gadget = strdup(data->ui_gadget);
1117 if (data->launch_mode != NULL)
1118 app_info->launch_mode = strdup(data->launch_mode);
1119 if (data->package_type != NULL)
1120 app_info->package_type = strdup(data->package_type);
1121 if (data->effective_appid != NULL)
1122 app_info->effective_appid = strdup(data->effective_appid);
1123 if (data->splash_screen_display != NULL)
1124 app_info->splash_screen_display = strdup(data->splash_screen_display);
1128 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1130 LOGE("memory alloc failed");
1131 pkgmgrinfo_basic_free_application(app_info);
1132 return PMINFO_R_ERROR;
1136 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1138 LOGE("memory alloc failed");
1139 pkgmgrinfo_basic_free_application(app_info);
1140 return PMINFO_R_ERROR;
1144 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1146 LOGE("memory alloc failed");
1147 pkgmgrinfo_basic_free_application(app_info);
1148 return PMINFO_R_ERROR;
1152 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1154 LOGE("memory alloc failed");
1155 pkgmgrinfo_basic_free_application(app_info);
1156 return PMINFO_R_ERROR;
1160 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1162 LOGE("memory alloc failed");
1163 pkgmgrinfo_basic_free_application(app_info);
1164 return PMINFO_R_ERROR;
1168 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1170 LOGE("memory alloc failed");
1171 pkgmgrinfo_basic_free_application(app_info);
1172 return PMINFO_R_ERROR;
1176 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1178 LOGE("memory alloc failed");
1179 pkgmgrinfo_basic_free_application(app_info);
1180 return PMINFO_R_ERROR;
1184 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1186 LOGE("memory alloc failed");
1187 pkgmgrinfo_basic_free_application(app_info);
1188 return PMINFO_R_ERROR;
1191 *application = app_info;
1196 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1197 pkgmgrinfo_appinfo_h *clone)
1199 pkgmgr_appinfo_x *info;
1200 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1203 return PMINFO_R_EINVAL;
1205 info = calloc(1, sizeof(pkgmgr_appinfo_x));
1207 LOGE("memory alloc failed");
1208 return PMINFO_R_ERROR;
1211 if (temp->package != NULL)
1212 info->package = strdup(temp->package);
1213 if (temp->locale != NULL)
1214 info->locale = strdup(temp->locale);
1216 info->app_component = temp->app_component;
1218 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1219 LOGE("appinfo copy failed");
1221 free((void *)info->package);
1225 return PMINFO_R_ERROR;
1233 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1234 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1240 pkgmgr_appinfo_x info;
1242 GHashTableIter iter;
1245 locale = _get_system_locale();
1247 return PMINFO_R_ERROR;
1249 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1250 __free_applications);
1253 return PMINFO_R_ERROR;
1256 ret = _appinfo_get_applications(uid, uid, locale, filter,
1257 flag | PMINFO_APPINFO_GET_BASICINFO, list);
1258 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1259 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1260 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1262 if (ret != PMINFO_R_OK) {
1263 g_hash_table_destroy(list);
1268 g_hash_table_iter_init(&iter, list);
1269 while (g_hash_table_iter_next(&iter, NULL, &value)) {
1270 app = (application_x *)value;
1271 info.app_info = app;
1272 info.locale = locale;
1273 info.package = app->package;
1274 if (app_list_cb(&info, user_data) < 0)
1277 g_hash_table_destroy(list);
1283 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1285 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1286 pkgmgrinfo_app_component component,
1287 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1290 pkgmgrinfo_appinfo_filter_h filter;
1292 const char *comp_str = NULL;
1294 if (handle == NULL || app_func == NULL) {
1295 LOGE("invalid parameter");
1296 return PMINFO_R_EINVAL;
1299 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1300 LOGE("invalid parameter");
1301 return PMINFO_R_EINVAL;
1304 if (pkgmgrinfo_appinfo_filter_create(&filter))
1305 return PMINFO_R_ERROR;
1307 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1308 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1309 pkgmgrinfo_appinfo_filter_destroy(filter);
1310 return PMINFO_R_ERROR;
1313 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1314 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1315 pkgmgrinfo_appinfo_filter_destroy(filter);
1316 return PMINFO_R_ERROR;
1319 comp_str = __appcomponent_str(component);
1322 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1323 PMINFO_APPINFO_PROP_APP_COMPONENT,
1325 pkgmgrinfo_appinfo_filter_destroy(filter);
1326 return PMINFO_R_ERROR;
1330 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1331 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1333 pkgmgrinfo_appinfo_filter_destroy(filter);
1338 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1339 pkgmgrinfo_app_component component,
1340 pkgmgrinfo_app_list_cb app_func, void *user_data)
1342 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1345 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1346 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1350 pkgmgrinfo_appinfo_filter_h filter;
1352 if (app_func == NULL) {
1353 LOGE("invalid parameter");
1354 return PMINFO_R_EINVAL;
1357 if (pkgmgrinfo_appinfo_filter_create(&filter))
1358 return PMINFO_R_ERROR;
1360 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1361 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1362 pkgmgrinfo_appinfo_filter_destroy(filter);
1363 return PMINFO_R_ERROR;
1366 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1367 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1368 pkgmgrinfo_appinfo_filter_destroy(filter);
1369 return PMINFO_R_ERROR;
1372 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1373 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1374 pkgmgrinfo_appinfo_filter_destroy(filter);
1375 return PMINFO_R_ERROR;
1378 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1381 pkgmgrinfo_appinfo_filter_destroy(filter);
1386 API int pkgmgrinfo_appinfo_get_installed_list_full(
1387 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1389 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1390 _getuid(), flag, user_data);
1393 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1394 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1397 pkgmgrinfo_appinfo_filter_h filter;
1399 if (app_func == NULL) {
1400 LOGE("invalid parameter");
1401 return PMINFO_R_EINVAL;
1404 /* create an empty filter */
1405 ret = pkgmgrinfo_appinfo_filter_create(&filter);
1406 if (ret != PMINFO_R_OK)
1409 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1410 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1411 pkgmgrinfo_appinfo_filter_destroy(filter);
1412 return PMINFO_R_ERROR;
1415 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1416 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1417 pkgmgrinfo_appinfo_filter_destroy(filter);
1418 return PMINFO_R_ERROR;
1421 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1422 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1424 pkgmgrinfo_appinfo_filter_destroy(filter);
1429 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1432 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1436 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1438 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1440 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1441 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1443 if (info->app_info == NULL || info->app_info->appid == NULL)
1444 return PMINFO_R_ERROR;
1445 *appid = (char *)info->app_info->appid;
1450 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1452 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1454 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1455 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1457 if (info->package == NULL)
1458 return PMINFO_R_ERROR;
1460 *pkg_name = (char *)info->package;
1465 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1467 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1469 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1470 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1472 if (info->package == NULL)
1473 return PMINFO_R_ERROR;
1475 *pkgid = (char *)info->package;
1480 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1483 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1484 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1486 *pkgtype = (char *)info->app_info->package_type;
1491 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1493 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1495 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1496 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1498 if (info->app_info == NULL || info->app_info->exec == NULL)
1499 return PMINFO_R_ERROR;
1500 *exec = (char *)info->app_info->exec;
1506 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1509 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1512 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1514 if (info->app_info == NULL)
1515 return PMINFO_R_ERROR;
1517 if (info->app_info->icon == NULL) {
1522 ptr = (icon_x *)info->app_info->icon->data;
1524 return PMINFO_R_ERROR;
1526 if (ptr->text == NULL)
1527 return PMINFO_R_ERROR;
1535 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1538 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1544 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1546 if (info->app_info == NULL)
1547 return PMINFO_R_ERROR;
1549 locale = info->locale;
1551 locale = DEFAULT_LOCALE;
1553 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1554 ptr = (label_x *)tmp->data;
1555 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
1566 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1567 ptr = (label_x *)tmp->data;
1568 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
1574 *label = lbl ? lbl : "";
1579 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1581 char *result = NULL;
1583 sqlite3_stmt *stmt = NULL;
1588 parser_db = getUserPkgParserDBPathUID(uid);
1589 if (parser_db == NULL) {
1590 _LOGE("Failed to get parser db path");
1594 if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1595 _LOGE("DB open fail\n");
1601 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1602 if (query == NULL) {
1603 _LOGE("Out of memory");
1607 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1608 _LOGE("prepare_v2 fail\n");
1612 if (sqlite3_step(stmt) == SQLITE_ROW) {
1613 val = (char *)sqlite3_column_text(stmt, 0);
1615 result = strdup(val);
1619 sqlite3_finalize(stmt);
1620 sqlite3_free(query);
1626 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1630 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1632 val = _get_localed_label(appid, locale, uid);
1634 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1637 val = _get_localed_label(appid, locale, GLOBAL_USER);
1639 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1643 return PMINFO_R_ERROR;
1650 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1652 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1655 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1657 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1658 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1659 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1661 GList *list_md = NULL;
1662 metadata_x *metadata = NULL;
1663 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1665 list_md = info->app_info->metadata;
1667 for (; list_md; list_md = list_md->next) {
1668 metadata = (metadata_x *)list_md->data;
1669 if (metadata && metadata->key) {
1670 if (strcasecmp(metadata->key, metadata_key) == 0) {
1671 if (metadata->value == NULL)
1672 *metadata_value = "";
1674 *metadata_value = (char *)metadata->value;
1680 return PMINFO_R_EINVAL;
1683 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1685 if (strcasecmp(comp, "uiapp") == 0)
1686 return PMINFO_UI_APP;
1687 else if (strcasecmp(comp, "svcapp") == 0)
1688 return PMINFO_SVC_APP;
1689 else if (strcasecmp(comp, "widgetapp") == 0)
1690 return PMINFO_WIDGET_APP;
1691 else if (strcasecmp(comp, "watchapp") == 0)
1692 return PMINFO_WATCH_APP;
1697 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1702 case PMINFO_SVC_APP:
1704 case PMINFO_WIDGET_APP:
1706 case PMINFO_WATCH_APP:
1713 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1715 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1718 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1719 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1721 if (info->app_info == NULL)
1722 return PMINFO_R_ERROR;
1724 comp = __appcomponent_convert(info->app_info->component);
1726 return PMINFO_R_ERROR;
1733 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1735 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1737 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1738 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1740 if (info->app_info == NULL || info->app_info->type == NULL)
1741 return PMINFO_R_ERROR;
1742 *app_type = (char *)info->app_info->type;
1747 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1748 int *operation_count, char ***operation)
1750 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1751 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1752 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1753 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1754 *operation_count = data->operation_count;
1755 *operation = data->operation;
1759 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1760 int *uri_count, char ***uri)
1762 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1763 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1764 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1765 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1766 *uri_count = data->uri_count;
1771 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1772 int *mime_count, char ***mime)
1774 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1775 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1776 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1777 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1778 *mime_count = data->mime_count;
1783 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1784 int *subapp_count, char ***subapp)
1786 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1787 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1788 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1789 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1790 *subapp_count = data->subapp_count;
1791 *subapp = data->subapp;
1795 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1800 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1802 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1803 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1805 if (info->app_info == NULL)
1806 return PMINFO_R_ERROR;
1808 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1809 ptr = (icon_x *)tmp->data;
1810 if (ptr == NULL || ptr->section == NULL)
1813 val = (char *)ptr->section;
1814 if (val && strcmp(val, "notification") == 0) {
1815 *icon = (char *)ptr->text;
1820 return PMINFO_R_ERROR;
1823 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1826 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1828 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1829 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1831 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1832 return PMINFO_R_ERROR;
1834 val = (char *)info->app_info->recentimage;
1835 if (strcasecmp(val, "capture") == 0)
1836 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1837 else if (strcasecmp(val, "icon") == 0)
1838 *type = PMINFO_RECENTIMAGE_USE_ICON;
1840 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1845 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1850 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1853 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1855 if (info->app_info == NULL)
1856 return PMINFO_R_ERROR;
1858 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1859 ptr = (image_x *)tmp->data;
1860 if (ptr == NULL || ptr->section == NULL)
1863 val = (char *)ptr->section;
1864 if (val && strcmp(val, "preview") == 0) {
1865 *preview_img = (char *)ptr->text;
1870 return PMINFO_R_ERROR;
1873 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1876 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1878 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1879 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1881 val = info->app_info->permission_type;
1883 return PMINFO_R_ERROR;
1885 if (strcmp(val, "signature") == 0)
1886 *permission = PMINFO_PERMISSION_SIGNATURE;
1887 else if (strcmp(val, "privilege") == 0)
1888 *permission = PMINFO_PERMISSION_PRIVILEGE;
1890 *permission = PMINFO_PERMISSION_NORMAL;
1895 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1897 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1899 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1900 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1902 if (info->app_info == NULL || info->app_info->component_type == NULL)
1903 return PMINFO_R_ERROR;
1905 *component_type = (char *)info->app_info->component_type;
1910 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1913 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1915 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1916 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1918 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1919 return PMINFO_R_ERROR;
1921 val = (char *)info->app_info->hwacceleration;
1922 if (strcasecmp(val, "off") == 0)
1923 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1924 else if (strcasecmp(val, "on") == 0)
1925 *hwacceleration = PMINFO_HWACCELERATION_ON;
1927 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1932 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1935 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1937 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1938 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1940 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1941 return PMINFO_R_ERROR;
1943 val = (char *)info->app_info->screenreader;
1944 if (strcasecmp(val, "screenreader-off") == 0)
1945 *screenreader = PMINFO_SCREENREADER_OFF;
1946 else if (strcasecmp(val, "screenreader-on") == 0)
1947 *screenreader = PMINFO_SCREENREADER_ON;
1949 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1954 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1956 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1958 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1959 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1960 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1962 if (info->app_info == NULL)
1963 return PMINFO_R_ERROR;
1965 if (info->app_info->portraitimg == NULL)
1968 *portrait_img = (char *)info->app_info->portraitimg;
1970 if (info->app_info->landscapeimg == NULL)
1971 *landscape_img = "";
1973 *landscape_img = (char *)info->app_info->landscapeimg;
1978 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1980 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1982 if (handle == NULL || effectimage_type == NULL) {
1983 LOGE("invalid parameter");
1984 return PMINFO_R_EINVAL;
1987 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1988 return PMINFO_R_ERROR;
1990 *effectimage_type = (char *)info->app_info->effectimage_type;
1995 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1997 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1999 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2000 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2002 if (info->app_info == NULL)
2003 return PMINFO_R_ERROR;
2005 if (info->app_info->submode_mainid == NULL)
2006 *submode_mainid = "";
2008 *submode_mainid = (char *)info->app_info->submode_mainid;
2013 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2015 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2016 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2018 if (info->app_info && info->app_info->installed_storage) {
2019 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2020 *storage = PMINFO_INTERNAL_STORAGE;
2021 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2022 *storage = PMINFO_EXTERNAL_STORAGE;
2024 return PMINFO_R_ERROR;
2026 return PMINFO_R_ERROR;
2032 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2034 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2036 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2037 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2039 if (info->app_info->launch_mode == NULL)
2040 return PMINFO_R_ERROR;
2042 *mode = (char *)(info->app_info->launch_mode);
2047 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2049 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2051 if (handle == NULL || alias_appid == NULL) {
2052 LOGE("invalid parameter");
2053 return PMINFO_R_EINVAL;
2056 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2057 return PMINFO_R_ERROR;
2059 *alias_appid = (char *)info->app_info->alias_appid;
2064 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2066 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2068 if (handle == NULL || effective_appid == NULL) {
2069 LOGE("invalid parameter");
2070 return PMINFO_R_EINVAL;
2073 if (info->app_info == NULL)
2074 return PMINFO_R_ERROR;
2076 if (info->app_info->effective_appid == NULL)
2077 *effective_appid = "";
2079 *effective_appid = (char *)info->app_info->effective_appid;
2084 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2086 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2088 if (handle == NULL || tep_name == NULL) {
2089 LOGE("invalid parameter");
2090 return PMINFO_R_EINVAL;
2093 if (info->app_info == NULL)
2094 return PMINFO_R_ERROR;
2096 if (info->app_info->tep_name == NULL)
2099 *tep_name = (char *)info->app_info->tep_name;
2104 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2106 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2108 if (handle == NULL || zip_mount_file == NULL) {
2109 LOGE("invalid parameter");
2110 return PMINFO_R_EINVAL;
2113 if (info->app_info == NULL)
2114 return PMINFO_R_ERROR;
2116 if (info->app_info->zip_mount_file == NULL)
2117 *zip_mount_file = "";
2119 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2124 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2126 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2128 if (handle == NULL || root_path == NULL) {
2129 LOGE("invalid parameter");
2130 return PMINFO_R_EINVAL;
2133 if (info->app_info == NULL || info->app_info->root_path == NULL)
2134 return PMINFO_R_ERROR;
2136 *root_path = (char *)info->app_info->root_path;
2141 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2143 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2145 if (handle == NULL || api_version == NULL) {
2146 LOGE("invalid parameter");
2147 return PMINFO_R_EINVAL;
2150 if (info->app_info == NULL || info->app_info->api_version == NULL)
2151 return PMINFO_R_ERROR;
2153 *api_version = (char *)info->app_info->api_version;
2158 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2160 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2162 if (handle == NULL || installed_time == NULL) {
2163 LOGE("invalid parameter");
2164 return PMINFO_R_EINVAL;
2167 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2168 return PMINFO_R_ERROR;
2170 *installed_time = atoi(info->app_info->package_installed_time);
2175 static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
2176 const char *type, char **appid, char **access)
2178 static const char query[] =
2179 "SELECT app_id, access FROM package_app_data_control "
2180 "WHERE providerid=? AND type=?";
2184 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2185 if (ret != SQLITE_OK) {
2186 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2187 return PMINFO_R_ERROR;
2190 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2191 if (ret != SQLITE_OK) {
2192 LOGE("bind failed: %s", sqlite3_errmsg(db));
2193 sqlite3_finalize(stmt);
2194 return PMINFO_R_ERROR;
2197 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2198 if (ret != SQLITE_OK) {
2199 LOGE("bind failed: %s", sqlite3_errmsg(db));
2200 sqlite3_finalize(stmt);
2201 return PMINFO_R_ERROR;
2204 ret = sqlite3_step(stmt);
2205 if (ret != SQLITE_ROW) {
2206 sqlite3_finalize(stmt);
2207 if (ret == SQLITE_DONE) {
2208 return PMINFO_R_ENOENT;
2210 LOGE("step error: %s", sqlite3_errmsg(db));
2211 return PMINFO_R_ERROR;
2215 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2216 if (*appid == NULL) {
2217 LOGE("out of memory");
2218 sqlite3_finalize(stmt);
2219 return PMINFO_R_ERROR;
2221 *access = strdup((char *)sqlite3_column_text(stmt, 1));
2222 if (*access == NULL) {
2223 LOGE("out of memory");
2225 sqlite3_finalize(stmt);
2226 return PMINFO_R_ERROR;
2229 sqlite3_finalize(stmt);
2234 static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
2235 const char *providerid, const char *type,
2236 char **appid, char **access)
2242 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2244 return PMINFO_R_ERROR;
2246 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2248 if (ret != SQLITE_OK) {
2249 LOGE("open db failed: %s", sqlite3_errmsg(db));
2250 return PMINFO_R_ERROR;
2253 ret = _appinfo_get_datacontrol_info(db, providerid, type, appid,
2255 sqlite3_close_v2(db);
2260 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2261 const char *type, uid_t uid, char **appid, char **access)
2265 if (providerid == NULL || type == NULL || appid == NULL ||
2267 LOGE("invalid parameter");
2268 return PMINFO_R_EINVAL;
2271 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
2272 type, appid, access);
2273 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2274 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
2275 type, appid, access);
2277 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2278 * implementation, return PMINFO_R_ERROR. This should be
2281 if (ret == PMINFO_R_ENOENT) {
2282 LOGE("no datacontrol info of %s", providerid);
2283 ret = PMINFO_R_ERROR;
2289 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2290 const char *type, char **appid, char **access)
2292 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2293 type, _getuid(), appid, access);
2296 static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
2299 static const char query[] =
2300 "SELECT app_id FROM package_app_data_control "
2301 "WHERE providerid=?";
2305 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2306 if (ret != SQLITE_OK) {
2307 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2308 return PMINFO_R_ERROR;
2311 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2312 if (ret != SQLITE_OK) {
2313 LOGE("bind failed: %s", sqlite3_errmsg(db));
2314 sqlite3_finalize(stmt);
2315 return PMINFO_R_ERROR;
2318 ret = sqlite3_step(stmt);
2319 if (ret != SQLITE_ROW) {
2320 sqlite3_finalize(stmt);
2321 if (ret == SQLITE_DONE) {
2322 return PMINFO_R_ENOENT;
2324 LOGE("step error: %s", sqlite3_errmsg(db));
2325 return PMINFO_R_ERROR;
2329 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2331 sqlite3_finalize(stmt);
2333 if (*appid == NULL) {
2334 LOGE("out of memory");
2335 return PMINFO_R_ERROR;
2341 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
2342 const char *providerid, char **appid)
2348 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2350 return PMINFO_R_ERROR;
2352 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2354 if (ret != SQLITE_OK) {
2355 LOGE("open db failed: %s", sqlite3_errmsg(db));
2356 return PMINFO_R_ERROR;
2359 ret = _appinfo_get_datacontrol_appid(db, providerid, appid);
2360 sqlite3_close_v2(db);
2365 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
2366 uid_t uid, char **appid)
2370 if (providerid == NULL || appid == NULL) {
2371 LOGE("invalid parameter");
2372 return PMINFO_R_EINVAL;
2375 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
2377 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2378 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
2381 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2382 * implementation, return PMINFO_R_ERROR. This should be
2385 if (ret == PMINFO_R_ENOENT) {
2386 LOGE("no datacontrol appid of %s", providerid);
2387 ret = PMINFO_R_ERROR;
2393 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2395 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2398 static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
2399 const char *providerid, const char *type, char **appid,
2402 static const char query[] =
2403 "SELECT app_id, trusted FROM package_app_data_control "
2404 "WHERE providerid=? AND type=?";
2408 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2409 if (ret != SQLITE_OK) {
2410 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2411 return PMINFO_R_ERROR;
2414 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2415 if (ret != SQLITE_OK) {
2416 LOGE("bind failed: %s", sqlite3_errmsg(db));
2417 sqlite3_finalize(stmt);
2418 return PMINFO_R_ERROR;
2421 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2422 if (ret != SQLITE_OK) {
2423 LOGE("bind failed: %s", sqlite3_errmsg(db));
2424 sqlite3_finalize(stmt);
2425 return PMINFO_R_ERROR;
2428 ret = sqlite3_step(stmt);
2429 if (ret != SQLITE_ROW) {
2430 sqlite3_finalize(stmt);
2431 if (ret == SQLITE_DONE) {
2432 return PMINFO_R_ENOENT;
2434 LOGE("step error: %s", sqlite3_errmsg(db));
2435 return PMINFO_R_ERROR;
2439 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2440 *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2442 sqlite3_finalize(stmt);
2444 if (*appid == NULL) {
2445 LOGE("out of memory");
2446 return PMINFO_R_ERROR;
2452 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
2453 const char *providerid, const char *type, char **appid,
2460 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2462 return PMINFO_R_ERROR;
2464 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2466 if (ret != SQLITE_OK) {
2467 LOGE("open db failed: %s", sqlite3_errmsg(db));
2468 return PMINFO_R_ERROR;
2471 ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid,
2473 sqlite3_close_v2(db);
2478 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
2479 const char *providerid, const char *type, uid_t uid,
2480 char **appid, bool *is_trusted)
2484 if (providerid == NULL || type == NULL || appid == NULL ||
2485 is_trusted == NULL) {
2486 LOGE("invalid parameter");
2487 return PMINFO_R_EINVAL;
2490 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
2491 providerid, type, appid, is_trusted);
2492 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2493 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
2494 providerid, type, appid, is_trusted);
2496 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2497 * implementation, return PMINFO_R_ERROR. This should be
2500 if (ret == PMINFO_R_ENOENT) {
2501 LOGE("no datacontrol trusted info of %s", providerid);
2502 ret = PMINFO_R_ERROR;
2508 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2509 const char *type, char **appid, bool *is_trusted)
2511 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2512 type, _getuid(), appid, is_trusted);
2515 static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
2516 const char *providerid, const char *type,
2517 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2519 static const char query[] =
2520 "SELECT privilege FROM package_app_data_control_privilege "
2521 "WHERE providerid=? AND type=?";
2526 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2527 if (ret != SQLITE_OK) {
2528 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2529 return PMINFO_R_ERROR;
2532 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2533 if (ret != SQLITE_OK) {
2534 LOGE("bind failed: %s", sqlite3_errmsg(db));
2535 sqlite3_finalize(stmt);
2536 return PMINFO_R_ERROR;
2539 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2540 if (ret != SQLITE_OK) {
2541 LOGE("bind failed: %s", sqlite3_errmsg(db));
2542 sqlite3_finalize(stmt);
2543 return PMINFO_R_ERROR;
2546 while (sqlite3_step(stmt) == SQLITE_ROW) {
2548 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2554 sqlite3_finalize(stmt);
2556 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2559 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
2560 const char *providerid, const char *type,
2561 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2567 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2569 return PMINFO_R_ERROR;
2571 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2573 if (ret != SQLITE_OK) {
2574 LOGE("open db failed: %s", sqlite3_errmsg(db));
2575 return PMINFO_R_ERROR;
2578 ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
2579 callback, user_data);
2580 sqlite3_close_v2(db);
2585 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2586 const char *providerid, const char *type,
2587 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2588 void *user_data, uid_t uid)
2592 if (providerid == NULL || type == NULL || privilege_func == NULL) {
2593 LOGE("invalid parameter");
2594 return PMINFO_R_EINVAL;
2597 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
2598 providerid, type, privilege_func, user_data);
2599 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2600 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
2601 providerid, type, privilege_func, user_data);
2603 if (ret == PMINFO_R_ENOENT)
2609 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
2610 const char *providerid, const char *type,
2611 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2614 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2615 providerid, type, privilege_func, user_data, _getuid());
2618 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
2620 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2621 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2623 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2624 if (info->app_info->support_mode)
2625 *support_mode = atoi(info->app_info->support_mode);
2632 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2633 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2635 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2636 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2638 const char *category;
2640 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2642 if (info->app_info == NULL)
2643 return PMINFO_R_ERROR;
2645 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2646 category = (const char *)tmp->data;
2648 ret = category_func(category, user_data);
2656 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2657 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2659 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2660 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2664 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2666 if (info->app_info == NULL)
2667 return PMINFO_R_ERROR;
2669 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2670 ptr = (metadata_x *)tmp->data;
2674 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2682 static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
2683 const char *appid, const char *app_control,
2684 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2686 static const char query[] =
2687 "SELECT privilege FROM package_app_app_control_privilege "
2688 "WHERE app_id=? AND app_control=?";
2693 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2694 if (ret != SQLITE_OK) {
2695 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2696 return PMINFO_R_ERROR;
2699 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_STATIC);
2700 if (ret != SQLITE_OK) {
2701 LOGE("bind failed: %s", sqlite3_errmsg(db));
2702 sqlite3_finalize(stmt);
2703 return PMINFO_R_ERROR;
2706 ret = sqlite3_bind_text(stmt, 2, app_control, -1, SQLITE_STATIC);
2707 if (ret != SQLITE_OK) {
2708 LOGE("bind failed: %s", sqlite3_errmsg(db));
2709 sqlite3_finalize(stmt);
2710 return PMINFO_R_ERROR;
2713 while (sqlite3_step(stmt) == SQLITE_ROW) {
2715 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2721 sqlite3_finalize(stmt);
2723 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2726 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
2727 const char *appid, const char *app_control,
2728 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2734 dbpath = getUserPkgParserDBPathUID(uid);
2736 return PMINFO_R_ERROR;
2738 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2740 if (ret != SQLITE_OK) {
2741 LOGE("open db failed: %s", sqlite3_errmsg(db));
2742 return PMINFO_R_ERROR;
2745 ret = _appinfo_foreach_appcontrol_privileges(db, appid, app_control,
2746 callback, user_data);
2747 sqlite3_close_v2(db);
2752 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
2753 const char *operation, const char *uri, const char *mime,
2754 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2755 void *user_data, uid_t uid)
2758 char app_control[BUFSIZE];
2760 if (appid == NULL || operation == NULL || privilege_func == NULL) {
2761 LOGE("invalid parameter");
2762 return PMINFO_R_EINVAL;
2765 snprintf(app_control, sizeof(app_control), "%s|%s|%s", operation,
2766 uri ? uri : "NULL", mime ? mime : "NULL");
2768 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
2769 appid, app_control, privilege_func, user_data);
2770 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2771 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
2772 appid, app_control, privilege_func, user_data);
2774 if (ret == PMINFO_R_ENOENT)
2780 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
2781 const char *operation, const char *uri, const char *mime,
2782 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2785 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
2786 operation, uri, mime, privilege_func, user_data,
2790 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2791 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2793 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2794 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2796 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2797 appcontrol_x *appcontrol;
2800 if (info->app_info == NULL)
2801 return PMINFO_R_ERROR;
2803 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2804 appcontrol = (appcontrol_x *)tmp->data;
2805 if (appcontrol == NULL)
2807 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2815 API int pkgmgrinfo_appinfo_foreach_background_category(
2816 pkgmgrinfo_appinfo_h handle,
2817 pkgmgrinfo_app_background_category_list_cb category_func,
2820 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2824 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2825 LOGE("invalid parameter");
2826 return PMINFO_R_EINVAL;
2829 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2830 category = (char *)tmp->data;
2831 if (category == NULL)
2834 if (category_func(category, user_data) < 0)
2841 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2842 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2845 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2846 splashscreen_x *splashscreen;
2850 if (info == NULL || info->app_info == NULL
2851 || splash_screen_func == NULL) {
2852 LOGE("invalid parameter");
2853 return PMINFO_R_EINVAL;
2856 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2857 splashscreen = (splashscreen_x *)tmp->data;
2858 if (splashscreen == NULL)
2860 ret = splash_screen_func(splashscreen->src,
2862 splashscreen->orientation,
2863 splashscreen->indicatordisplay,
2864 splashscreen->operation,
2865 splashscreen->color_depth,
2874 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2876 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2877 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2878 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2880 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2881 return PMINFO_R_ERROR;
2883 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2888 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2890 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2891 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2892 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2894 if (info->app_info == NULL || info->app_info->multiple == NULL)
2895 return PMINFO_R_ERROR;
2897 *multiple = _get_bool_value(info->app_info->multiple);
2902 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2904 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2905 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2906 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2908 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2909 return PMINFO_R_ERROR;
2911 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2916 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2918 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2919 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2920 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2922 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2923 return PMINFO_R_ERROR;
2925 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2930 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2932 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2933 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2934 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2936 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2937 return PMINFO_R_ERROR;
2939 *enabled = !_get_bool_value(info->app_info->is_disabled);
2944 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2946 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2947 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2948 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2950 if (info->app_info == NULL || info->app_info->onboot == NULL)
2951 return PMINFO_R_ERROR;
2953 *onboot = _get_bool_value(info->app_info->onboot);
2958 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
2960 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2961 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2962 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2964 if (info->app_info == NULL || info->app_info->autorestart == NULL)
2965 return PMINFO_R_ERROR;
2967 *autorestart = _get_bool_value(info->app_info->autorestart);
2972 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
2974 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2975 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2976 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2978 if (info->app_info == NULL || info->app_info->mainapp == NULL)
2979 return PMINFO_R_ERROR;
2981 *mainapp = _get_bool_value(info->app_info->mainapp);
2986 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2988 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2989 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2990 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2992 if (info->app_info == NULL || info->app_info->preload == NULL)
2993 return PMINFO_R_ERROR;
2995 *preload = _get_bool_value(info->app_info->preload);
3000 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
3002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3003 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3004 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3006 if (info->app_info == NULL || info->app_info->submode == NULL)
3007 return PMINFO_R_ERROR;
3009 *submode = _get_bool_value(info->app_info->submode);
3014 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
3016 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3018 if (handle == NULL || process_pool == NULL) {
3019 LOGE("invalid parameter");
3020 return PMINFO_R_EINVAL;
3023 if (info->app_info == NULL)
3024 return PMINFO_R_ERROR;
3026 *process_pool = _get_bool_value(info->app_info->process_pool);
3031 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
3033 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3034 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
3035 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
3039 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3041 if (info->app_info == NULL)
3042 return PMINFO_R_ERROR;
3045 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
3046 val = (const char *)tmp->data;
3049 if (strcasecmp(val, category) == 0) {
3058 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
3061 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3063 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
3064 _LOGE("invalid parameter");
3065 return PMINFO_R_EINVAL;
3067 if (info->app_info->ui_gadget == NULL)
3068 info->app_info->ui_gadget = strdup("false");
3070 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
3075 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
3076 bool *support_disable)
3078 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3080 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
3081 _LOGE("invalid parameter");
3082 return PMINFO_R_EINVAL;
3085 *support_disable = _get_bool_value(info->app_info->support_disable);
3090 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
3093 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3095 if (info == NULL || info->app_info == NULL || removable == NULL) {
3096 _LOGE("invalid parameter");
3097 return PMINFO_R_EINVAL;
3100 *removable = _get_bool_value(info->app_info->removable);
3105 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
3107 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3109 if (info == NULL || info->app_info == NULL || system == NULL) {
3110 _LOGE("invalid parameter");
3111 return PMINFO_R_EINVAL;
3114 *system = _get_bool_value(info->app_info->package_system);
3119 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
3121 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3122 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3123 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3125 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
3126 return PMINFO_R_ERROR;
3128 *disabled = _get_bool_value(info->app_info->is_disabled);
3133 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
3135 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3137 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3138 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3140 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
3141 return PMINFO_R_ERROR;
3143 *global = _get_bool_value(info->app_info->for_all_users);
3148 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
3150 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3152 if (info == NULL || splash_screen_display == NULL) {
3153 _LOGE("Invalid parameter");
3154 return PMINFO_R_EINVAL;
3157 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
3158 return PMINFO_R_ERROR;
3160 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
3165 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
3167 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3169 if (info == NULL || setup_appid == NULL) {
3170 _LOGE("Invalid parameter");
3171 return PMINFO_R_EINVAL;
3174 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
3175 return PMINFO_R_ERROR;
3177 *setup_appid = info->app_info->setup_appid;
3181 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
3182 bool *support_ambient)
3184 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3186 if (info == NULL || support_ambient == NULL) {
3187 _LOGE("Invalid parameter");
3188 return PMINFO_R_EINVAL;
3191 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
3192 return PMINFO_R_ERROR;
3194 *support_ambient = _get_bool_value(info->app_info->support_ambient);
3199 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
3201 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3202 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3203 __cleanup_appinfo(info);
3207 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
3209 return (pkgmgrinfo_pkginfo_filter_create(handle));
3212 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
3214 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3217 static gint __compare_func(gconstpointer data1, gconstpointer data2)
3219 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
3220 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
3221 if (node1->prop == node2->prop)
3223 else if (node1->prop > node2->prop)
3229 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
3230 const char *property, const int value)
3232 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3233 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3234 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3236 GSList *link = NULL;
3238 prop = _pminfo_appinfo_convert_to_prop_int(property);
3239 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
3240 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
3241 _LOGE("Invalid Integer Property\n");
3242 return PMINFO_R_EINVAL;
3244 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3245 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3247 _LOGE("Out of Memory!!!\n");
3248 return PMINFO_R_ERROR;
3250 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3251 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3253 _LOGE("Out of Memory\n");
3256 return PMINFO_R_ERROR;
3260 /*If API is called multiple times for same property, we should override the previous values.
3261 Last value set will be used for filtering.*/
3262 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3264 filter->list = g_slist_delete_link(filter->list, link);
3265 filter->list = g_slist_append(filter->list, (gpointer)node);
3270 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
3271 const char *property, const bool value)
3273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3274 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3276 GSList *link = NULL;
3278 prop = _pminfo_appinfo_convert_to_prop_bool(property);
3279 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
3280 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
3281 _LOGE("Invalid Boolean Property\n");
3282 return PMINFO_R_EINVAL;
3284 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3285 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3287 _LOGE("Out of Memory!!!\n");
3288 return PMINFO_R_ERROR;
3291 val = strndup("true", 4);
3293 val = strndup("false", 5);
3295 _LOGE("Out of Memory\n");
3298 return PMINFO_R_ERROR;
3302 /*If API is called multiple times for same property, we should override the previous values.
3303 Last value set will be used for filtering.*/
3304 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3306 filter->list = g_slist_delete_link(filter->list, link);
3307 filter->list = g_slist_append(filter->list, (gpointer)node);
3312 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
3313 const char *property, const char *value)
3315 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3316 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3317 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3319 pkgmgrinfo_node_x *ptr = NULL;
3320 char prev[PKG_STRING_LEN_MAX] = {'\0'};
3321 char temp[PKG_STRING_LEN_MAX] = {'\0'};
3322 GSList *link = NULL;
3324 prop = _pminfo_appinfo_convert_to_prop_str(property);
3325 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
3326 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
3327 _LOGE("Invalid String Property\n");
3328 return PMINFO_R_EINVAL;
3330 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3331 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3333 _LOGE("Out of Memory!!!\n");
3334 return PMINFO_R_ERROR;
3338 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
3339 node->value = strdup(value);
3340 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3342 filter->list = g_slist_delete_link(filter->list, link);
3343 filter->list = g_slist_append(filter->list, (gpointer)node);
3345 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
3346 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
3348 _LOGE("Out of Memory\n");
3351 return PMINFO_R_ERROR;
3353 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3355 ptr = (pkgmgrinfo_node_x *)link->data;
3356 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
3357 _LOGI("Previous value is %s\n", prev);
3358 filter->list = g_slist_delete_link(filter->list, link);
3359 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
3360 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3361 _LOGI("New value is %s\n", val);
3363 filter->list = g_slist_append(filter->list, (gpointer)node);
3364 memset(temp, '\0', PKG_STRING_LEN_MAX);
3366 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3367 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3368 _LOGI("First value is %s\n", val);
3370 filter->list = g_slist_append(filter->list, (gpointer)node);
3371 memset(temp, '\0', PKG_STRING_LEN_MAX);
3375 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3376 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3378 filter->list = g_slist_delete_link(filter->list, link);
3379 filter->list = g_slist_append(filter->list, (gpointer)node);
3385 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3391 if (handle == NULL || count == NULL) {
3392 _LOGE("invalid parameter");
3393 return PMINFO_R_EINVAL;
3396 locale = _get_system_locale();
3398 return PMINFO_R_ERROR;
3400 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3401 __free_applications);
3404 return PMINFO_R_ERROR;
3407 if (__check_disable_filter_exist(
3408 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3409 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3410 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
3411 g_hash_table_destroy(list);
3413 return PMINFO_R_ERROR;
3417 if (__check_disable_filter_exist(
3418 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3419 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3420 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
3421 g_hash_table_destroy(list);
3423 return PMINFO_R_ERROR;
3427 ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3428 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3429 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3432 if (ret != PMINFO_R_OK) {
3433 g_hash_table_destroy(list);
3435 return PMINFO_R_ERROR;
3438 *count = g_hash_table_size(list);
3439 g_hash_table_destroy(list);
3445 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3447 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3450 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3451 pkgmgrinfo_appinfo_filter_h handle,
3452 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3454 if (handle == NULL || app_cb == NULL) {
3455 LOGE("invalid parameter");
3456 return PMINFO_R_EINVAL;
3459 if (__check_disable_filter_exist(
3460 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3461 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3462 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3463 return PMINFO_R_ERROR;
3466 if (__check_disable_filter_exist(
3467 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3468 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3469 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3470 return PMINFO_R_ERROR;
3473 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3477 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3478 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3480 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3483 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3485 return (pkgmgrinfo_pkginfo_filter_create(handle));
3488 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3490 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3493 API int pkgmgrinfo_appinfo_metadata_filter_add(
3494 pkgmgrinfo_appinfo_metadata_filter_h handle,
3495 const char *key, const char *value)
3497 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3498 pkgmgrinfo_metadata_node_x *node;
3500 /* value can be NULL.
3501 * In that case all apps with specified key should be displayed
3504 LOGE("invalid parameter");
3505 return PMINFO_R_EINVAL;
3508 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3510 LOGE("out of memory");
3511 return PMINFO_R_ERROR;
3514 node->key = strdup(key);
3515 if (value && strlen(value))
3516 node->value = strdup(value);
3518 filter->list_metadata = g_slist_append(filter->list_metadata,
3524 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3525 pkgmgrinfo_appinfo_metadata_filter_h handle,
3526 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3528 if (handle == NULL || app_cb == NULL) {
3529 LOGE("invalid parameter");
3530 return PMINFO_R_EINVAL;
3533 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3534 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3535 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3536 return PMINFO_R_ERROR;
3538 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3539 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3540 return PMINFO_R_ERROR;
3542 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3546 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3547 pkgmgrinfo_appinfo_metadata_filter_h handle,
3548 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3550 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3551 user_data, _getuid());
3554 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3557 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3559 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3560 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3562 val = info->app_info->guestmode_visibility;
3563 *status = _get_bool_value(val);