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 _LOGE("out of memory");
169 ac = calloc(1, sizeof(appcontrol_x));
171 _LOGE("out of memory");
174 token = strtok_r(dup, "|", &ptr);
175 if (token && strcmp(token, "NULL"))
176 ac->operation = strdup(token);
177 token = strtok_r(NULL, "|", &ptr);
178 if (token && strcmp(token, "NULL"))
179 ac->uri = strdup(token);
180 token = strtok_r(NULL, "|", &ptr);
181 if (token && strcmp(token, "NULL"))
182 ac->mime = strdup(token);
183 *appcontrol = g_list_append(*appcontrol, ac);
184 } while ((token = strtok_r(NULL, ";", &ptr)));
189 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
192 static const char query_raw[] =
193 "SELECT app_control FROM package_app_app_control "
200 query = sqlite3_mprintf(query_raw, appid);
202 LOGE("out of memory");
203 return PMINFO_R_ERROR;
206 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
208 if (ret != SQLITE_OK) {
209 LOGE("prepare failed: %s", sqlite3_errmsg(db));
210 return PMINFO_R_ERROR;
213 while (sqlite3_step(stmt) == SQLITE_ROW) {
215 _save_column_str(stmt, 0, &str);
217 __parse_appcontrol(appcontrol, str);
221 sqlite3_finalize(stmt);
226 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
229 static const char query_raw[] =
230 "SELECT md_key, md_value "
231 "FROM package_app_app_metadata WHERE app_id=%Q";
238 query = sqlite3_mprintf(query_raw, appid);
240 LOGE("out of memory");
241 return PMINFO_R_ERROR;
244 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
246 if (ret != SQLITE_OK) {
247 LOGE("prepare failed: %s", sqlite3_errmsg(db));
248 return PMINFO_R_ERROR;
251 while (sqlite3_step(stmt) == SQLITE_ROW) {
252 info = calloc(1, sizeof(metadata_x));
254 LOGE("out of memory");
255 sqlite3_finalize(stmt);
256 return PMINFO_R_ERROR;
259 _save_column_str(stmt, idx++, &info->key);
260 _save_column_str(stmt, idx++, &info->value);
261 *metadata = g_list_append(*metadata, info);
264 sqlite3_finalize(stmt);
270 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
271 GList **splashscreens)
273 static const char query_raw[] =
274 "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
275 "FROM package_app_splash_screen WHERE app_id=%Q";
280 splashscreen_x *info;
282 query = sqlite3_mprintf(query_raw, appid);
284 LOGE("out of memory");
285 return PMINFO_R_ERROR;
288 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
290 if (ret != SQLITE_OK) {
291 LOGE("prepare failed: %s", sqlite3_errmsg(db));
292 return PMINFO_R_ERROR;
295 while (sqlite3_step(stmt) == SQLITE_ROW) {
296 info = calloc(1, sizeof(splashscreen_x));
298 LOGE("out of memory");
299 sqlite3_finalize(stmt);
300 return PMINFO_R_ERROR;
303 _save_column_str(stmt, idx++, &info->src);
304 _save_column_str(stmt, idx++, &info->type);
305 _save_column_str(stmt, idx++, &info->orientation);
306 _save_column_str(stmt, idx++, &info->indicatordisplay);
307 _save_column_str(stmt, idx++, &info->operation);
308 _save_column_str(stmt, idx++, &info->color_depth);
309 *splashscreens = g_list_append(*splashscreens, info);
312 sqlite3_finalize(stmt);
317 static GList *__get_background_category(const char *value)
319 GList *category_list = NULL;
320 int convert_value = 0;
321 if (!value || strlen(value) == 0)
324 convert_value = atoi(value);
325 if (convert_value < 0)
328 if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
329 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
331 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
333 if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
334 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
336 if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
337 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
339 if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
340 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
342 if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
343 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
345 if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
346 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
348 if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
349 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
351 if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
352 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
354 return category_list;
358 static void __free_applications(gpointer data)
360 pkgmgrinfo_basic_free_application((application_x *)data);
363 static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
365 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
366 pkgmgrinfo_appinfo_disable_type value = GPOINTER_TO_INT(data2);
368 if (value == E_APPINFO_DISABLE_TYPE_PKG)
369 return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
372 return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
376 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
377 pkgmgrinfo_appinfo_disable_type type)
384 link = g_slist_find_custom(filter->list, GINT_TO_POINTER(type), __disable_chk_func);
391 static int __bind_params(sqlite3_stmt *stmt, GList *params)
393 GList *tmp_list = NULL;
397 if (stmt == NULL || params == NULL)
398 return PMINFO_R_EINVAL;
402 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
403 if (ret != SQLITE_OK)
404 return PMINFO_R_ERROR;
405 tmp_list = tmp_list->next;
411 static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter)
413 GSList *tmp_list = NULL;
414 pkgmgrinfo_node_x *tmp_node = NULL;
417 if (tmp_filter == NULL)
420 property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
421 for (tmp_list = tmp_filter->list; tmp_list != NULL;
422 tmp_list = g_slist_next(tmp_list)) {
423 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
424 if (property == tmp_node->prop) {
425 if (strcmp(tmp_node->value, "true") == 0)
435 static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
436 const char *locale, pkgmgrinfo_filter_x *filter, int flag,
437 GHashTable *applications)
439 static const char query_raw[] =
440 "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
441 "ai.app_external_path";
442 static const char query_basic[] =
443 ", ai.app_component, ai.app_exec, "
444 "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
445 "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
446 "ai.app_hwacceleration, ai.app_screenreader, "
447 "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, "
448 "ai.app_indicatordisplay, ai.app_portraitimg, "
449 "ai.app_landscapeimg, ai.app_guestmodevisibility, "
450 "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
451 "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
452 "ai.app_support_disable, ai.app_process_pool, "
453 "ai.app_background_category, ai.app_package_type, "
454 "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
455 "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
456 "ai.app_zip_mount_file, ai.component_type, ai.package, "
457 "ai.app_package_system, ai.app_removable, "
458 "ai.app_package_installed_time, ai.app_support_mode, "
459 "ai.app_support_ambient, ai.app_setup_appid";
460 static const char query_uid_info[] =
461 ", ui.is_disabled, ui.is_splash_screen_enabled";
462 static const char query_label[] =
464 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
465 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
466 static const char query_icon[] =
468 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
469 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
470 static const char query_from_clause[] = " FROM package_app_info as ai";
471 static const char query_uid_info_clause[] =
472 " LEFT OUTER JOIN package_app_info_for_uid AS ui "
473 "ON (ai.app_id=ui.app_id AND ui.uid=?)";
474 int ret = PMINFO_R_ERROR;
477 char *bg_category_str = NULL;
478 char *constraint = NULL;
479 char *tmp_record = NULL;
480 char query[MAX_QUERY_LEN] = { '\0' };
481 char buf[BUFSIZE] = { '\0' };
482 application_x *info = NULL;
483 GList *bind_params = NULL;
485 sqlite3_stmt *stmt = NULL;
486 bool is_check_storage = true;
487 const uid_t global_user_uid = GLOBAL_USER;
489 dbpath = getUserPkgParserDBPathUID(db_uid);
491 return PMINFO_R_ERROR;
493 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
494 if (ret != SQLITE_OK) {
495 _LOGE("failed to open db(%s): %d", dbpath, ret);
497 return PMINFO_R_ERROR;
501 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
503 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
504 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
505 strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1);
507 if (flag & PMINFO_APPINFO_GET_LABEL) {
508 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
509 bind_params = g_list_append(bind_params, strdup(locale));
511 if (flag & PMINFO_APPINFO_GET_ICON) {
512 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
513 bind_params = g_list_append(bind_params, strdup(locale));
516 snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
517 bind_params = g_list_append(bind_params, strdup(buf));
519 is_check_storage = __check_app_storage_status(filter);
521 ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
522 if (ret != PMINFO_R_OK) {
523 LOGE("Failed to get WHERE clause");
526 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
528 strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1);
531 strncat(query, constraint, sizeof(query) - strlen(query) - 1);
533 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
534 if (ret != SQLITE_OK) {
535 LOGE("prepare failed: %s", sqlite3_errmsg(db));
536 ret = PMINFO_R_ERROR;
540 if (g_list_length(bind_params) != 0) {
541 ret = __bind_params(stmt, bind_params);
542 if (ret != SQLITE_OK) {
543 LOGE("Failed to bind parameters");
548 while (sqlite3_step(stmt) == SQLITE_ROW) {
549 info = calloc(1, sizeof(application_x));
551 LOGE("out of memory");
552 ret = PMINFO_R_ERROR;
556 _save_column_str(stmt, idx++, &info->appid);
557 _save_column_str(stmt, idx++, &info->installed_storage);
558 _save_column_str(stmt, idx++ , &info->external_path);
560 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
561 _save_column_str(stmt, idx++, &info->component);
562 _save_column_str(stmt, idx++, &info->exec);
563 _save_column_str(stmt, idx++, &info->nodisplay);
564 _save_column_str(stmt, idx++, &info->type);
565 _save_column_str(stmt, idx++, &info->onboot);
566 _save_column_str(stmt, idx++, &info->multiple);
567 _save_column_str(stmt, idx++, &info->autorestart);
568 _save_column_str(stmt, idx++, &info->taskmanage);
569 _save_column_str(stmt, idx++, &info->hwacceleration);
570 _save_column_str(stmt, idx++, &info->screenreader);
571 _save_column_str(stmt, idx++, &info->mainapp);
572 _save_column_str(stmt, idx++, &info->recentimage);
573 _save_column_str(stmt, idx++, &info->launchcondition);
574 _save_column_str(stmt, idx++, &info->indicatordisplay);
575 _save_column_str(stmt, idx++, &info->portraitimg);
576 _save_column_str(stmt, idx++, &info->landscapeimg);
577 _save_column_str(stmt, idx++, &info->guestmode_visibility);
578 _save_column_str(stmt, idx++, &info->permission_type);
579 _save_column_str(stmt, idx++, &info->preload);
580 _save_column_str(stmt, idx++, &info->submode);
581 _save_column_str(stmt, idx++, &info->submode_mainid);
582 _save_column_str(stmt, idx++, &info->launch_mode);
583 _save_column_str(stmt, idx++, &info->ui_gadget);
584 _save_column_str(stmt, idx++, &info->support_disable);
585 _save_column_str(stmt, idx++, &info->process_pool);
586 _save_column_str(stmt, idx++, &bg_category_str);
587 _save_column_str(stmt, idx++, &info->package_type);
588 _save_column_str(stmt, idx++, &info->root_path);
589 _save_column_str(stmt, idx++, &info->api_version);
590 _save_column_str(stmt, idx++, &info->effective_appid);
591 _save_column_str(stmt, idx++, &info->is_disabled);
592 _save_column_str(stmt, idx++, &info->splash_screen_display);
593 _save_column_str(stmt, idx++, &info->tep_name);
594 _save_column_str(stmt, idx++, &info->zip_mount_file);
595 _save_column_str(stmt, idx++, &info->component_type);
596 _save_column_str(stmt, idx++, &info->package);
597 _save_column_str(stmt, idx++, &info->package_system);
598 _save_column_str(stmt, idx++, &info->removable);
599 _save_column_str(stmt, idx++, &info->package_installed_time);
600 _save_column_str(stmt, idx++, &info->support_mode);
601 _save_column_str(stmt, idx++, &info->support_ambient);
602 _save_column_str(stmt, idx++, &info->setup_appid);
603 info->background_category = __get_background_category(
605 free(bg_category_str);
608 info->for_all_users =
609 strdup((db_uid != global_user_uid) ? "false" : "true");
611 if (db_uid != global_user_uid) {
615 _save_column_str(stmt, idx++, &tmp_record);
616 if (tmp_record != NULL) {
617 if (strcasecmp(info->is_disabled, "false") == 0 &&
618 strcasecmp(tmp_record, "false") == 0) {
619 free(info->is_disabled);
620 info->is_disabled = tmp_record;
626 _save_column_str(stmt, idx++, &tmp_record);
627 if (tmp_record != NULL) {
628 if (strcasecmp(info->splash_screen_display, "false") == 0 &&
629 strcasecmp(tmp_record, "false") == 0) {
630 free(info->splash_screen_display);
631 info->splash_screen_display = tmp_record;
638 if (flag & PMINFO_APPINFO_GET_LABEL) {
640 _save_column_str(stmt, idx++, &tmp_record);
641 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
642 ret = PMINFO_R_ERROR;
647 if (flag & PMINFO_APPINFO_GET_ICON) {
649 _save_column_str(stmt, idx++, &tmp_record);
650 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
651 ret = PMINFO_R_ERROR;
656 if (flag & PMINFO_APPINFO_GET_CATEGORY) {
657 if (_appinfo_get_category(db, info->appid,
659 ret = PMINFO_R_ERROR;
664 if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
665 if (_appinfo_get_app_control(db, info->appid,
666 &info->appcontrol)) {
667 ret = PMINFO_R_ERROR;
672 if (flag & PMINFO_APPINFO_GET_METADATA) {
673 if (_appinfo_get_metadata(db, info->appid,
675 ret = PMINFO_R_ERROR;
680 if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
681 if (_appinfo_get_splashscreens(db, info->appid,
682 &info->splashscreens)) {
683 ret = PMINFO_R_ERROR;
688 if (is_check_storage &&
689 __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
690 ret = PMINFO_R_ERROR;
691 pkgmgrinfo_basic_free_application(info);
696 g_hash_table_insert(applications, (gpointer)info->appid,
706 if (ret != PMINFO_R_OK && info != NULL)
707 pkgmgrinfo_basic_free_application(info);
709 g_list_free_full(bind_params, free);
710 sqlite3_close_v2(db);
711 sqlite3_finalize(stmt);
716 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
717 pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
722 pkgmgr_appinfo_x *info;
724 if (appid == NULL || filter == NULL || handle == NULL) {
725 LOGE("invalid parameter");
726 return PMINFO_R_EINVAL;
729 locale = _get_system_locale();
731 return PMINFO_R_ERROR;
733 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
734 __free_applications);
737 return PMINFO_R_ERROR;
740 ret = _appinfo_get_applications(uid, uid, locale, filter,
741 PMINFO_APPINFO_GET_ALL, list);
742 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
743 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
744 PMINFO_APPINFO_GET_ALL, list);
746 if (ret != PMINFO_R_OK) {
747 g_hash_table_destroy(list);
752 if (!g_hash_table_size(list)) {
753 _LOGD("appinfo for [%s] is not existed for user [%d]",
755 g_hash_table_destroy(list);
757 return PMINFO_R_ENOENT;
760 info = calloc(1, sizeof(pkgmgr_appinfo_x));
762 _LOGE("out of memory");
763 g_hash_table_destroy(list);
765 return PMINFO_R_ERROR;
768 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
769 info->locale = locale;
770 info->package = strdup(info->app_info->package);
772 /* just free list only */
773 g_hash_table_steal(list, (gconstpointer)appid);
774 g_hash_table_destroy(list);
781 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
782 pkgmgrinfo_appinfo_h *handle)
785 pkgmgrinfo_appinfo_filter_h filter;
787 if (appid == NULL || handle == NULL) {
788 LOGE("invalid parameter");
789 return PMINFO_R_EINVAL;
792 ret = pkgmgrinfo_appinfo_filter_create(&filter);
793 if (ret != PMINFO_R_OK)
796 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
797 PMINFO_APPINFO_PROP_APP_ID, appid);
798 if (ret != PMINFO_R_OK) {
799 pkgmgrinfo_appinfo_filter_destroy(filter);
800 return PMINFO_R_ERROR;
803 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
804 PMINFO_APPINFO_PROP_APP_DISABLE, true);
805 if (ret != PMINFO_R_OK) {
806 pkgmgrinfo_appinfo_filter_destroy(filter);
807 return PMINFO_R_ERROR;
810 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
811 pkgmgrinfo_appinfo_filter_destroy(filter);
816 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
818 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
821 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
822 pkgmgrinfo_appinfo_h *handle)
825 pkgmgrinfo_appinfo_filter_h filter;
827 if (appid == NULL || handle == NULL) {
828 LOGE("invalid parameter");
829 return PMINFO_R_EINVAL;
832 ret = pkgmgrinfo_appinfo_filter_create(&filter);
833 if (ret != PMINFO_R_OK)
836 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
837 PMINFO_APPINFO_PROP_APP_ID, appid);
838 if (ret != PMINFO_R_OK) {
839 pkgmgrinfo_appinfo_filter_destroy(filter);
840 return PMINFO_R_ERROR;
843 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
844 PMINFO_APPINFO_PROP_APP_DISABLE, false);
845 if (ret != PMINFO_R_OK) {
846 pkgmgrinfo_appinfo_filter_destroy(filter);
847 return PMINFO_R_ERROR;
850 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
851 PMINFO_APPINFO_PROP_PKG_DISABLE, false);
852 if (ret != PMINFO_R_OK) {
853 pkgmgrinfo_appinfo_filter_destroy(filter);
854 return PMINFO_R_ERROR;
857 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
858 pkgmgrinfo_appinfo_filter_destroy(filter);
862 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
864 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
867 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
868 pkgmgrinfo_appinfo_h *handle)
871 pkgmgrinfo_appinfo_filter_h filter;
873 if (appid == NULL || handle == NULL) {
874 LOGE("invalid parameter");
875 return PMINFO_R_EINVAL;
878 ret = pkgmgrinfo_appinfo_filter_create(&filter);
879 if (ret != PMINFO_R_OK)
882 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
883 PMINFO_APPINFO_PROP_APP_ID, appid);
884 if (ret != PMINFO_R_OK) {
885 pkgmgrinfo_appinfo_filter_destroy(filter);
886 return PMINFO_R_ERROR;
889 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
890 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
891 if (ret != PMINFO_R_OK) {
892 pkgmgrinfo_appinfo_filter_destroy(filter);
893 return PMINFO_R_ERROR;
896 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
897 pkgmgrinfo_appinfo_filter_destroy(filter);
902 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
904 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
907 static gpointer __copy_str(gconstpointer src, gpointer data)
909 const char *tmp = (const char *)src;
912 buffer = strdup(tmp);
913 if (buffer == NULL) {
914 LOGE("memory alloc failed");
922 static gpointer __copy_label(gconstpointer src, gpointer data)
924 label_x *tmp = (label_x *)src;
927 label = calloc(1, sizeof(label_x));
929 LOGE("memory alloc failed");
935 label->name = strdup(tmp->name);
937 label->text = strdup(tmp->text);
939 label->lang = strdup(tmp->lang);
944 static gpointer __copy_icon(gconstpointer src, gpointer data)
946 icon_x *tmp = (icon_x *)src;
949 icon = calloc(1, sizeof(icon_x));
951 LOGE("memory alloc failed");
957 icon->text = strdup(tmp->text);
959 icon->lang = strdup(tmp->lang);
961 icon->section = strdup(tmp->section);
963 icon->size = strdup(tmp->size);
965 icon->resolution = strdup(tmp->resolution);
970 static gpointer __copy_metadata(gconstpointer src, gpointer data)
972 metadata_x *tmp = (metadata_x *)src;
973 metadata_x *metadata;
975 metadata = calloc(1, sizeof(metadata_x));
976 if (metadata == NULL) {
977 LOGE("memory alloc failed");
983 metadata->key = strdup(tmp->key);
985 metadata->value = strdup(tmp->value);
990 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
992 datacontrol_x *tmp = (datacontrol_x *)src;
993 datacontrol_x *datacontrol;
995 datacontrol = calloc(1, sizeof(datacontrol_x));
996 if (datacontrol == NULL) {
997 LOGE("memory alloc failed");
1002 if (tmp->providerid)
1003 datacontrol->providerid = strdup(tmp->providerid);
1005 datacontrol->access = strdup(tmp->access);
1007 datacontrol->type = strdup(tmp->type);
1009 datacontrol->trusted = strdup(tmp->trusted);
1014 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1016 appcontrol_x *tmp = (appcontrol_x *)src;
1017 appcontrol_x *appcontrol;
1019 appcontrol = calloc(1, sizeof(appcontrol_x));
1020 if (appcontrol == NULL) {
1021 LOGE("memory alloc failed");
1027 appcontrol->operation = strdup(tmp->operation);
1029 appcontrol->uri = strdup(tmp->uri);
1031 appcontrol->mime = strdup(tmp->mime);
1036 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1038 splashscreen_x *tmp = (splashscreen_x *)src;
1039 splashscreen_x *splashscreen;
1041 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1042 if (splashscreen == NULL) {
1043 LOGE("memory alloc failed");
1049 splashscreen->src = strdup(tmp->src);
1051 splashscreen->type = strdup(tmp->type);
1052 if (tmp->orientation)
1053 splashscreen->orientation = strdup(tmp->orientation);
1054 if (tmp->indicatordisplay)
1055 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1057 splashscreen->operation = strdup(tmp->operation);
1058 if (tmp->color_depth)
1059 splashscreen->color_depth = strdup(tmp->color_depth);
1061 return splashscreen;
1064 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1066 application_x *app_info;
1069 app_info = calloc(1, sizeof(application_x));
1070 if (app_info == NULL) {
1071 LOGE("memory alloc failed");
1072 return PMINFO_R_ERROR;
1075 if (data->appid != NULL)
1076 app_info->appid = strdup(data->appid);
1077 if (data->exec != NULL)
1078 app_info->exec = strdup(data->exec);
1079 if (data->nodisplay != NULL)
1080 app_info->nodisplay = strdup(data->nodisplay);
1081 if (data->multiple != NULL)
1082 app_info->multiple = strdup(data->multiple);
1083 if (data->taskmanage != NULL)
1084 app_info->taskmanage = strdup(data->taskmanage);
1085 if (data->type != NULL)
1086 app_info->type = strdup(data->type);
1087 if (data->categories != NULL)
1088 app_info->categories = strdup(data->categories);
1089 if (data->hwacceleration != NULL)
1090 app_info->hwacceleration = strdup(data->hwacceleration);
1091 if (data->screenreader != NULL)
1092 app_info->screenreader = strdup(data->screenreader);
1093 if (data->mainapp != NULL)
1094 app_info->mainapp = strdup(data->mainapp);
1095 if (data->package != NULL)
1096 app_info->package = strdup(data->package);
1097 if (data->recentimage != NULL)
1098 app_info->recentimage = strdup(data->recentimage);
1099 if (data->launchcondition != NULL)
1100 app_info->launchcondition = strdup(data->launchcondition);
1101 if (data->indicatordisplay != NULL)
1102 app_info->indicatordisplay = strdup(data->indicatordisplay);
1103 if (data->portraitimg != NULL)
1104 app_info->portraitimg = strdup(data->portraitimg);
1105 if (data->landscapeimg != NULL)
1106 app_info->landscapeimg = strdup(data->landscapeimg);
1107 if (data->guestmode_visibility != NULL)
1108 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1109 if (data->component != NULL)
1110 app_info->component = strdup(data->component);
1111 if (data->permission_type != NULL)
1112 app_info->permission_type = strdup(data->permission_type);
1113 if (data->component_type != NULL)
1114 app_info->component_type = strdup(data->component_type);
1115 if (data->preload != NULL)
1116 app_info->preload = strdup(data->preload);
1117 if (data->submode != NULL)
1118 app_info->submode = strdup(data->submode);
1119 if (data->submode_mainid != NULL)
1120 app_info->submode_mainid = strdup(data->submode_mainid);
1121 if (data->process_pool != NULL)
1122 app_info->process_pool = strdup(data->process_pool);
1123 if (data->installed_storage != NULL)
1124 app_info->installed_storage = strdup(data->installed_storage);
1125 if (data->autorestart != NULL)
1126 app_info->autorestart = strdup(data->autorestart);
1127 if (data->onboot != NULL)
1128 app_info->onboot = strdup(data->onboot);
1129 if (data->support_disable != NULL)
1130 app_info->support_disable = strdup(data->support_disable);
1131 if (data->ui_gadget != NULL)
1132 app_info->ui_gadget = strdup(data->ui_gadget);
1133 if (data->launch_mode != NULL)
1134 app_info->launch_mode = strdup(data->launch_mode);
1135 if (data->package_type != NULL)
1136 app_info->package_type = strdup(data->package_type);
1137 if (data->effective_appid != NULL)
1138 app_info->effective_appid = strdup(data->effective_appid);
1139 if (data->splash_screen_display != NULL)
1140 app_info->splash_screen_display = strdup(data->splash_screen_display);
1144 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1146 LOGE("memory alloc failed");
1147 pkgmgrinfo_basic_free_application(app_info);
1148 return PMINFO_R_ERROR;
1152 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1154 LOGE("memory alloc failed");
1155 pkgmgrinfo_basic_free_application(app_info);
1156 return PMINFO_R_ERROR;
1160 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1162 LOGE("memory alloc failed");
1163 pkgmgrinfo_basic_free_application(app_info);
1164 return PMINFO_R_ERROR;
1168 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1170 LOGE("memory alloc failed");
1171 pkgmgrinfo_basic_free_application(app_info);
1172 return PMINFO_R_ERROR;
1176 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1178 LOGE("memory alloc failed");
1179 pkgmgrinfo_basic_free_application(app_info);
1180 return PMINFO_R_ERROR;
1184 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1186 LOGE("memory alloc failed");
1187 pkgmgrinfo_basic_free_application(app_info);
1188 return PMINFO_R_ERROR;
1192 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1194 LOGE("memory alloc failed");
1195 pkgmgrinfo_basic_free_application(app_info);
1196 return PMINFO_R_ERROR;
1200 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1202 LOGE("memory alloc failed");
1203 pkgmgrinfo_basic_free_application(app_info);
1204 return PMINFO_R_ERROR;
1207 *application = app_info;
1212 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1213 pkgmgrinfo_appinfo_h *clone)
1215 pkgmgr_appinfo_x *info;
1216 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1219 return PMINFO_R_EINVAL;
1221 info = calloc(1, sizeof(pkgmgr_appinfo_x));
1223 LOGE("memory alloc failed");
1224 return PMINFO_R_ERROR;
1227 if (temp->package != NULL)
1228 info->package = strdup(temp->package);
1229 if (temp->locale != NULL)
1230 info->locale = strdup(temp->locale);
1232 info->app_component = temp->app_component;
1234 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1235 LOGE("appinfo copy failed");
1237 free((void *)info->package);
1241 return PMINFO_R_ERROR;
1249 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1250 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1256 pkgmgr_appinfo_x info;
1258 GHashTableIter iter;
1261 locale = _get_system_locale();
1263 return PMINFO_R_ERROR;
1265 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1266 __free_applications);
1269 return PMINFO_R_ERROR;
1272 ret = _appinfo_get_applications(uid, uid, locale, filter,
1273 flag | PMINFO_APPINFO_GET_BASICINFO, list);
1274 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1275 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1276 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1278 if (ret != PMINFO_R_OK) {
1279 g_hash_table_destroy(list);
1284 g_hash_table_iter_init(&iter, list);
1285 while (g_hash_table_iter_next(&iter, NULL, &value)) {
1286 app = (application_x *)value;
1287 info.app_info = app;
1288 info.locale = locale;
1289 info.package = app->package;
1290 if (app_list_cb(&info, user_data) < 0)
1293 g_hash_table_destroy(list);
1299 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1301 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1302 pkgmgrinfo_app_component component,
1303 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1306 pkgmgrinfo_appinfo_filter_h filter;
1308 const char *comp_str = NULL;
1310 if (handle == NULL || app_func == NULL) {
1311 LOGE("invalid parameter");
1312 return PMINFO_R_EINVAL;
1315 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1316 LOGE("invalid parameter");
1317 return PMINFO_R_EINVAL;
1320 if (pkgmgrinfo_appinfo_filter_create(&filter))
1321 return PMINFO_R_ERROR;
1323 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1324 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1325 pkgmgrinfo_appinfo_filter_destroy(filter);
1326 return PMINFO_R_ERROR;
1329 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1330 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1331 pkgmgrinfo_appinfo_filter_destroy(filter);
1332 return PMINFO_R_ERROR;
1335 comp_str = __appcomponent_str(component);
1338 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1339 PMINFO_APPINFO_PROP_APP_COMPONENT,
1341 pkgmgrinfo_appinfo_filter_destroy(filter);
1342 return PMINFO_R_ERROR;
1346 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1347 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1349 pkgmgrinfo_appinfo_filter_destroy(filter);
1354 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1355 pkgmgrinfo_app_component component,
1356 pkgmgrinfo_app_list_cb app_func, void *user_data)
1358 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1361 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1362 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1366 pkgmgrinfo_appinfo_filter_h filter;
1368 if (app_func == NULL) {
1369 LOGE("invalid parameter");
1370 return PMINFO_R_EINVAL;
1373 if (pkgmgrinfo_appinfo_filter_create(&filter))
1374 return PMINFO_R_ERROR;
1376 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1377 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1378 pkgmgrinfo_appinfo_filter_destroy(filter);
1379 return PMINFO_R_ERROR;
1382 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1383 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1384 pkgmgrinfo_appinfo_filter_destroy(filter);
1385 return PMINFO_R_ERROR;
1388 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1389 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1390 pkgmgrinfo_appinfo_filter_destroy(filter);
1391 return PMINFO_R_ERROR;
1394 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1397 pkgmgrinfo_appinfo_filter_destroy(filter);
1402 API int pkgmgrinfo_appinfo_get_installed_list_full(
1403 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1405 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1406 _getuid(), flag, user_data);
1409 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1410 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1413 pkgmgrinfo_appinfo_filter_h filter;
1415 if (app_func == NULL) {
1416 LOGE("invalid parameter");
1417 return PMINFO_R_EINVAL;
1420 /* create an empty filter */
1421 ret = pkgmgrinfo_appinfo_filter_create(&filter);
1422 if (ret != PMINFO_R_OK)
1425 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1426 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1427 pkgmgrinfo_appinfo_filter_destroy(filter);
1428 return PMINFO_R_ERROR;
1431 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1432 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1433 pkgmgrinfo_appinfo_filter_destroy(filter);
1434 return PMINFO_R_ERROR;
1437 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1438 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1440 pkgmgrinfo_appinfo_filter_destroy(filter);
1445 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1448 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1452 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1454 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1456 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1457 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1459 if (info->app_info == NULL || info->app_info->appid == NULL)
1460 return PMINFO_R_ERROR;
1461 *appid = (char *)info->app_info->appid;
1466 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1468 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1470 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1471 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1473 if (info->package == NULL)
1474 return PMINFO_R_ERROR;
1476 *pkg_name = (char *)info->package;
1481 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1483 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1485 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1486 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1488 if (info->package == NULL)
1489 return PMINFO_R_ERROR;
1491 *pkgid = (char *)info->package;
1496 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1498 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1499 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1500 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1502 *pkgtype = (char *)info->app_info->package_type;
1507 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1509 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1512 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1514 if (info->app_info == NULL || info->app_info->exec == NULL)
1515 return PMINFO_R_ERROR;
1516 *exec = (char *)info->app_info->exec;
1522 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1525 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1527 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1528 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1530 if (info->app_info == NULL)
1531 return PMINFO_R_ERROR;
1533 if (info->app_info->icon == NULL) {
1538 ptr = (icon_x *)info->app_info->icon->data;
1540 return PMINFO_R_ERROR;
1542 if (ptr->text == NULL)
1543 return PMINFO_R_ERROR;
1551 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1554 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1559 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1560 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1562 if (info->app_info == NULL)
1563 return PMINFO_R_ERROR;
1565 locale = info->locale;
1567 locale = DEFAULT_LOCALE;
1569 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1570 ptr = (label_x *)tmp->data;
1571 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
1582 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1583 ptr = (label_x *)tmp->data;
1584 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
1590 *label = lbl ? lbl : "";
1595 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1597 char *result = NULL;
1599 sqlite3_stmt *stmt = NULL;
1604 parser_db = getUserPkgParserDBPathUID(uid);
1605 if (parser_db == NULL) {
1606 _LOGE("Failed to get parser db path");
1610 if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1611 _LOGE("DB open fail\n");
1617 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1618 if (query == NULL) {
1619 _LOGE("Out of memory");
1623 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1624 _LOGE("prepare_v2 fail\n");
1628 if (sqlite3_step(stmt) == SQLITE_ROW) {
1629 val = (char *)sqlite3_column_text(stmt, 0);
1631 result = strdup(val);
1635 sqlite3_finalize(stmt);
1636 sqlite3_free(query);
1642 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1646 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1648 val = _get_localed_label(appid, locale, uid);
1650 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1653 val = _get_localed_label(appid, locale, GLOBAL_USER);
1655 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1659 return PMINFO_R_ERROR;
1666 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1668 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1671 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1674 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1675 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1677 GList *list_md = NULL;
1678 metadata_x *metadata = NULL;
1679 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1681 list_md = info->app_info->metadata;
1683 for (; list_md; list_md = list_md->next) {
1684 metadata = (metadata_x *)list_md->data;
1685 if (metadata && metadata->key) {
1686 if (strcasecmp(metadata->key, metadata_key) == 0) {
1687 if (metadata->value == NULL)
1688 *metadata_value = "";
1690 *metadata_value = (char *)metadata->value;
1696 return PMINFO_R_EINVAL;
1699 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1701 if (strcasecmp(comp, "uiapp") == 0)
1702 return PMINFO_UI_APP;
1703 else if (strcasecmp(comp, "svcapp") == 0)
1704 return PMINFO_SVC_APP;
1705 else if (strcasecmp(comp, "widgetapp") == 0)
1706 return PMINFO_WIDGET_APP;
1707 else if (strcasecmp(comp, "watchapp") == 0)
1708 return PMINFO_WATCH_APP;
1713 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1718 case PMINFO_SVC_APP:
1720 case PMINFO_WIDGET_APP:
1722 case PMINFO_WATCH_APP:
1729 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1731 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1734 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1735 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1737 if (info->app_info == NULL)
1738 return PMINFO_R_ERROR;
1740 comp = __appcomponent_convert(info->app_info->component);
1742 return PMINFO_R_ERROR;
1749 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1751 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1753 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1754 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1756 if (info->app_info == NULL || info->app_info->type == NULL)
1757 return PMINFO_R_ERROR;
1758 *app_type = (char *)info->app_info->type;
1763 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1764 int *operation_count, char ***operation)
1766 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1767 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1768 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1769 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1770 *operation_count = data->operation_count;
1771 *operation = data->operation;
1775 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1776 int *uri_count, char ***uri)
1778 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1779 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1780 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1781 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1782 *uri_count = data->uri_count;
1787 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1788 int *mime_count, char ***mime)
1790 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1791 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1792 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1793 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1794 *mime_count = data->mime_count;
1799 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1800 int *subapp_count, char ***subapp)
1802 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1803 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1804 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1805 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1806 *subapp_count = data->subapp_count;
1807 *subapp = data->subapp;
1811 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1816 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1818 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1819 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1821 if (info->app_info == NULL)
1822 return PMINFO_R_ERROR;
1824 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1825 ptr = (icon_x *)tmp->data;
1826 if (ptr == NULL || ptr->section == NULL)
1829 val = (char *)ptr->section;
1830 if (val && strcmp(val, "notification") == 0) {
1831 *icon = (char *)ptr->text;
1836 return PMINFO_R_ERROR;
1839 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1842 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1844 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1845 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1847 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1848 return PMINFO_R_ERROR;
1850 val = (char *)info->app_info->recentimage;
1851 if (strcasecmp(val, "capture") == 0)
1852 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1853 else if (strcasecmp(val, "icon") == 0)
1854 *type = PMINFO_RECENTIMAGE_USE_ICON;
1856 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1861 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1866 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1868 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1869 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1871 if (info->app_info == NULL)
1872 return PMINFO_R_ERROR;
1874 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1875 ptr = (image_x *)tmp->data;
1876 if (ptr == NULL || ptr->section == NULL)
1879 val = (char *)ptr->section;
1880 if (val && strcmp(val, "preview") == 0) {
1881 *preview_img = (char *)ptr->text;
1886 return PMINFO_R_ERROR;
1889 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1892 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1894 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1895 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1897 val = info->app_info->permission_type;
1899 return PMINFO_R_ERROR;
1901 if (strcmp(val, "signature") == 0)
1902 *permission = PMINFO_PERMISSION_SIGNATURE;
1903 else if (strcmp(val, "privilege") == 0)
1904 *permission = PMINFO_PERMISSION_PRIVILEGE;
1906 *permission = PMINFO_PERMISSION_NORMAL;
1911 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1913 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1915 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1916 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1918 if (info->app_info == NULL || info->app_info->component_type == NULL)
1919 return PMINFO_R_ERROR;
1921 *component_type = (char *)info->app_info->component_type;
1926 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1929 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1931 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1932 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1934 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1935 return PMINFO_R_ERROR;
1937 val = (char *)info->app_info->hwacceleration;
1938 if (strcasecmp(val, "off") == 0)
1939 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1940 else if (strcasecmp(val, "on") == 0)
1941 *hwacceleration = PMINFO_HWACCELERATION_ON;
1943 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1948 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1951 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1953 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1954 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1956 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1957 return PMINFO_R_ERROR;
1959 val = (char *)info->app_info->screenreader;
1960 if (strcasecmp(val, "screenreader-off") == 0)
1961 *screenreader = PMINFO_SCREENREADER_OFF;
1962 else if (strcasecmp(val, "screenreader-on") == 0)
1963 *screenreader = PMINFO_SCREENREADER_ON;
1965 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1970 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1972 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1974 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1975 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1976 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1978 if (info->app_info == NULL)
1979 return PMINFO_R_ERROR;
1981 if (info->app_info->portraitimg == NULL)
1984 *portrait_img = (char *)info->app_info->portraitimg;
1986 if (info->app_info->landscapeimg == NULL)
1987 *landscape_img = "";
1989 *landscape_img = (char *)info->app_info->landscapeimg;
1994 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1996 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1998 if (handle == NULL || effectimage_type == NULL) {
1999 LOGE("invalid parameter");
2000 return PMINFO_R_EINVAL;
2003 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
2004 return PMINFO_R_ERROR;
2006 *effectimage_type = (char *)info->app_info->effectimage_type;
2011 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
2013 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2015 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2016 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2018 if (info->app_info == NULL)
2019 return PMINFO_R_ERROR;
2021 if (info->app_info->submode_mainid == NULL)
2022 *submode_mainid = "";
2024 *submode_mainid = (char *)info->app_info->submode_mainid;
2029 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2031 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2032 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2034 if (info->app_info && info->app_info->installed_storage) {
2035 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2036 *storage = PMINFO_INTERNAL_STORAGE;
2037 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2038 *storage = PMINFO_EXTERNAL_STORAGE;
2040 return PMINFO_R_ERROR;
2042 return PMINFO_R_ERROR;
2048 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2050 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2052 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2053 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2055 if (info->app_info->launch_mode == NULL)
2056 return PMINFO_R_ERROR;
2058 *mode = (char *)(info->app_info->launch_mode);
2063 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2065 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2067 if (handle == NULL || alias_appid == NULL) {
2068 LOGE("invalid parameter");
2069 return PMINFO_R_EINVAL;
2072 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2073 return PMINFO_R_ERROR;
2075 *alias_appid = (char *)info->app_info->alias_appid;
2080 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2082 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2084 if (handle == NULL || effective_appid == NULL) {
2085 LOGE("invalid parameter");
2086 return PMINFO_R_EINVAL;
2089 if (info->app_info == NULL)
2090 return PMINFO_R_ERROR;
2092 if (info->app_info->effective_appid == NULL)
2093 *effective_appid = "";
2095 *effective_appid = (char *)info->app_info->effective_appid;
2100 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2102 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2104 if (handle == NULL || tep_name == NULL) {
2105 LOGE("invalid parameter");
2106 return PMINFO_R_EINVAL;
2109 if (info->app_info == NULL)
2110 return PMINFO_R_ERROR;
2112 if (info->app_info->tep_name == NULL)
2115 *tep_name = (char *)info->app_info->tep_name;
2120 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2122 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2124 if (handle == NULL || zip_mount_file == NULL) {
2125 LOGE("invalid parameter");
2126 return PMINFO_R_EINVAL;
2129 if (info->app_info == NULL)
2130 return PMINFO_R_ERROR;
2132 if (info->app_info->zip_mount_file == NULL)
2133 *zip_mount_file = "";
2135 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2140 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2142 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2144 if (handle == NULL || root_path == NULL) {
2145 LOGE("invalid parameter");
2146 return PMINFO_R_EINVAL;
2149 if (info->app_info == NULL || info->app_info->root_path == NULL)
2150 return PMINFO_R_ERROR;
2152 *root_path = (char *)info->app_info->root_path;
2157 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2159 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2161 if (handle == NULL || api_version == NULL) {
2162 LOGE("invalid parameter");
2163 return PMINFO_R_EINVAL;
2166 if (info->app_info == NULL || info->app_info->api_version == NULL)
2167 return PMINFO_R_ERROR;
2169 *api_version = (char *)info->app_info->api_version;
2174 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2176 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2178 if (handle == NULL || installed_time == NULL) {
2179 LOGE("invalid parameter");
2180 return PMINFO_R_EINVAL;
2183 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2184 return PMINFO_R_ERROR;
2186 *installed_time = atoi(info->app_info->package_installed_time);
2191 static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
2192 const char *type, char **appid, char **access)
2194 static const char query[] =
2195 "SELECT app_id, access FROM package_app_data_control "
2196 "WHERE providerid=? AND type=?";
2200 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2201 if (ret != SQLITE_OK) {
2202 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2203 return PMINFO_R_ERROR;
2206 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2207 if (ret != SQLITE_OK) {
2208 LOGE("bind failed: %s", sqlite3_errmsg(db));
2209 sqlite3_finalize(stmt);
2210 return PMINFO_R_ERROR;
2213 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2214 if (ret != SQLITE_OK) {
2215 LOGE("bind failed: %s", sqlite3_errmsg(db));
2216 sqlite3_finalize(stmt);
2217 return PMINFO_R_ERROR;
2220 ret = sqlite3_step(stmt);
2221 if (ret != SQLITE_ROW) {
2222 sqlite3_finalize(stmt);
2223 if (ret == SQLITE_DONE) {
2224 return PMINFO_R_ENOENT;
2226 LOGE("step error: %s", sqlite3_errmsg(db));
2227 return PMINFO_R_ERROR;
2231 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2232 if (*appid == NULL) {
2233 LOGE("out of memory");
2234 sqlite3_finalize(stmt);
2235 return PMINFO_R_ERROR;
2237 *access = strdup((char *)sqlite3_column_text(stmt, 1));
2238 if (*access == NULL) {
2239 LOGE("out of memory");
2241 sqlite3_finalize(stmt);
2242 return PMINFO_R_ERROR;
2245 sqlite3_finalize(stmt);
2250 static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
2251 const char *providerid, const char *type,
2252 char **appid, char **access)
2258 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2260 return PMINFO_R_ERROR;
2262 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2264 if (ret != SQLITE_OK) {
2265 LOGE("open db failed: %s", sqlite3_errmsg(db));
2266 return PMINFO_R_ERROR;
2269 ret = _appinfo_get_datacontrol_info(db, providerid, type, appid,
2271 sqlite3_close_v2(db);
2276 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2277 const char *type, uid_t uid, char **appid, char **access)
2281 if (providerid == NULL || type == NULL || appid == NULL ||
2283 LOGE("invalid parameter");
2284 return PMINFO_R_EINVAL;
2287 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
2288 type, appid, access);
2289 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2290 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
2291 type, appid, access);
2293 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2294 * implementation, return PMINFO_R_ERROR. This should be
2297 if (ret == PMINFO_R_ENOENT) {
2298 LOGE("no datacontrol info of %s", providerid);
2299 ret = PMINFO_R_ERROR;
2305 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2306 const char *type, char **appid, char **access)
2308 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2309 type, _getuid(), appid, access);
2312 static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
2315 static const char query[] =
2316 "SELECT app_id FROM package_app_data_control "
2317 "WHERE providerid=?";
2321 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2322 if (ret != SQLITE_OK) {
2323 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2324 return PMINFO_R_ERROR;
2327 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2328 if (ret != SQLITE_OK) {
2329 LOGE("bind failed: %s", sqlite3_errmsg(db));
2330 sqlite3_finalize(stmt);
2331 return PMINFO_R_ERROR;
2334 ret = sqlite3_step(stmt);
2335 if (ret != SQLITE_ROW) {
2336 sqlite3_finalize(stmt);
2337 if (ret == SQLITE_DONE) {
2338 return PMINFO_R_ENOENT;
2340 LOGE("step error: %s", sqlite3_errmsg(db));
2341 return PMINFO_R_ERROR;
2345 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2347 sqlite3_finalize(stmt);
2349 if (*appid == NULL) {
2350 LOGE("out of memory");
2351 return PMINFO_R_ERROR;
2357 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
2358 const char *providerid, char **appid)
2364 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2366 return PMINFO_R_ERROR;
2368 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2370 if (ret != SQLITE_OK) {
2371 LOGE("open db failed: %s", sqlite3_errmsg(db));
2372 return PMINFO_R_ERROR;
2375 ret = _appinfo_get_datacontrol_appid(db, providerid, appid);
2376 sqlite3_close_v2(db);
2381 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
2382 uid_t uid, char **appid)
2386 if (providerid == NULL || appid == NULL) {
2387 LOGE("invalid parameter");
2388 return PMINFO_R_EINVAL;
2391 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
2393 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2394 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
2397 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2398 * implementation, return PMINFO_R_ERROR. This should be
2401 if (ret == PMINFO_R_ENOENT) {
2402 LOGE("no datacontrol appid of %s", providerid);
2403 ret = PMINFO_R_ERROR;
2409 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2411 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2414 static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
2415 const char *providerid, const char *type, char **appid,
2418 static const char query[] =
2419 "SELECT app_id, trusted FROM package_app_data_control "
2420 "WHERE providerid=? AND type=?";
2424 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2425 if (ret != SQLITE_OK) {
2426 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2427 return PMINFO_R_ERROR;
2430 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2431 if (ret != SQLITE_OK) {
2432 LOGE("bind failed: %s", sqlite3_errmsg(db));
2433 sqlite3_finalize(stmt);
2434 return PMINFO_R_ERROR;
2437 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2438 if (ret != SQLITE_OK) {
2439 LOGE("bind failed: %s", sqlite3_errmsg(db));
2440 sqlite3_finalize(stmt);
2441 return PMINFO_R_ERROR;
2444 ret = sqlite3_step(stmt);
2445 if (ret != SQLITE_ROW) {
2446 sqlite3_finalize(stmt);
2447 if (ret == SQLITE_DONE) {
2448 return PMINFO_R_ENOENT;
2450 LOGE("step error: %s", sqlite3_errmsg(db));
2451 return PMINFO_R_ERROR;
2455 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2456 *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2458 sqlite3_finalize(stmt);
2460 if (*appid == NULL) {
2461 LOGE("out of memory");
2462 return PMINFO_R_ERROR;
2468 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
2469 const char *providerid, const char *type, char **appid,
2476 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2478 return PMINFO_R_ERROR;
2480 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2482 if (ret != SQLITE_OK) {
2483 LOGE("open db failed: %s", sqlite3_errmsg(db));
2484 return PMINFO_R_ERROR;
2487 ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid,
2489 sqlite3_close_v2(db);
2494 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
2495 const char *providerid, const char *type, uid_t uid,
2496 char **appid, bool *is_trusted)
2500 if (providerid == NULL || type == NULL || appid == NULL ||
2501 is_trusted == NULL) {
2502 LOGE("invalid parameter");
2503 return PMINFO_R_EINVAL;
2506 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
2507 providerid, type, appid, is_trusted);
2508 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2509 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
2510 providerid, type, appid, is_trusted);
2512 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2513 * implementation, return PMINFO_R_ERROR. This should be
2516 if (ret == PMINFO_R_ENOENT) {
2517 LOGE("no datacontrol trusted info of %s", providerid);
2518 ret = PMINFO_R_ERROR;
2524 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2525 const char *type, char **appid, bool *is_trusted)
2527 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2528 type, _getuid(), appid, is_trusted);
2531 static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
2532 const char *providerid, const char *type,
2533 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2535 static const char query[] =
2536 "SELECT privilege FROM package_app_data_control_privilege "
2537 "WHERE providerid=? AND type=?";
2542 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2543 if (ret != SQLITE_OK) {
2544 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2545 return PMINFO_R_ERROR;
2548 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2549 if (ret != SQLITE_OK) {
2550 LOGE("bind failed: %s", sqlite3_errmsg(db));
2551 sqlite3_finalize(stmt);
2552 return PMINFO_R_ERROR;
2555 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2556 if (ret != SQLITE_OK) {
2557 LOGE("bind failed: %s", sqlite3_errmsg(db));
2558 sqlite3_finalize(stmt);
2559 return PMINFO_R_ERROR;
2562 while (sqlite3_step(stmt) == SQLITE_ROW) {
2564 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2570 sqlite3_finalize(stmt);
2572 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2575 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
2576 const char *providerid, const char *type,
2577 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2583 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2585 return PMINFO_R_ERROR;
2587 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2589 if (ret != SQLITE_OK) {
2590 LOGE("open db failed: %s", sqlite3_errmsg(db));
2591 return PMINFO_R_ERROR;
2594 ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
2595 callback, user_data);
2596 sqlite3_close_v2(db);
2601 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2602 const char *providerid, const char *type,
2603 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2604 void *user_data, uid_t uid)
2608 if (providerid == NULL || type == NULL || privilege_func == NULL) {
2609 LOGE("invalid parameter");
2610 return PMINFO_R_EINVAL;
2613 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
2614 providerid, type, privilege_func, user_data);
2615 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2616 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
2617 providerid, type, privilege_func, user_data);
2619 if (ret == PMINFO_R_ENOENT)
2625 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
2626 const char *providerid, const char *type,
2627 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2630 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2631 providerid, type, privilege_func, user_data, _getuid());
2634 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
2636 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2637 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2639 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2640 if (info->app_info->support_mode)
2641 *support_mode = atoi(info->app_info->support_mode);
2648 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2649 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2651 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2652 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2654 const char *category;
2656 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2658 if (info->app_info == NULL)
2659 return PMINFO_R_ERROR;
2661 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2662 category = (const char *)tmp->data;
2664 ret = category_func(category, user_data);
2672 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2673 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2675 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2676 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2680 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2682 if (info->app_info == NULL)
2683 return PMINFO_R_ERROR;
2685 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2686 ptr = (metadata_x *)tmp->data;
2690 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2698 static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
2699 const char *appid, const char *operation,
2700 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2702 static const char query[] =
2703 "SELECT app_control, privilege FROM package_app_app_control_privilege "
2707 const char *app_control;
2708 char *dup_app_control;
2710 char *saveptr = NULL;
2711 const char *privilege;
2714 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2715 if (ret != SQLITE_OK) {
2716 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2717 return PMINFO_R_ERROR;
2720 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_STATIC);
2721 if (ret != SQLITE_OK) {
2722 LOGE("bind failed: %s", sqlite3_errmsg(db));
2723 sqlite3_finalize(stmt);
2724 return PMINFO_R_ERROR;
2727 while (sqlite3_step(stmt) == SQLITE_ROW) {
2728 app_control = (const char *)sqlite3_column_text(stmt, 0);
2732 dup_app_control = strdup(app_control);
2733 if (!dup_app_control)
2736 token = strtok_r(dup_app_control, "|", &saveptr);
2737 if (token && !strcmp(token, operation)) {
2739 privilege = (const char *)sqlite3_column_text(stmt, 1);
2740 ret = callback(privilege, user_data);
2742 free(dup_app_control);
2746 free(dup_app_control);
2749 sqlite3_finalize(stmt);
2751 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2754 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
2755 const char *appid, const char *operation,
2756 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2762 dbpath = getUserPkgParserDBPathUID(uid);
2764 return PMINFO_R_ERROR;
2766 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2768 if (ret != SQLITE_OK) {
2769 LOGE("open db failed: %s", sqlite3_errmsg(db));
2770 return PMINFO_R_ERROR;
2773 ret = _appinfo_foreach_appcontrol_privileges(db, appid, operation,
2774 callback, user_data);
2775 sqlite3_close_v2(db);
2780 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
2781 const char *operation,
2782 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2783 void *user_data, uid_t uid)
2787 if (appid == NULL || operation == NULL || privilege_func == NULL) {
2788 LOGE("invalid parameter");
2789 return PMINFO_R_EINVAL;
2792 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
2793 appid, operation, privilege_func, user_data);
2794 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2795 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
2796 appid, operation, privilege_func, user_data);
2798 if (ret == PMINFO_R_ENOENT)
2804 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
2805 const char *operation,
2806 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2809 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
2810 operation, privilege_func, user_data, _getuid());
2813 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2814 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2816 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2817 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2819 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2820 appcontrol_x *appcontrol;
2823 if (info->app_info == NULL)
2824 return PMINFO_R_ERROR;
2826 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2827 appcontrol = (appcontrol_x *)tmp->data;
2828 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "remote-only"))
2830 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2838 API int pkgmgrinfo_appinfo_foreach_remote_appcontrol(pkgmgrinfo_appinfo_h handle,
2839 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2841 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2842 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2844 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2845 appcontrol_x *appcontrol;
2848 if (info->app_info == NULL)
2849 return PMINFO_R_ERROR;
2851 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2852 appcontrol = (appcontrol_x *)tmp->data;
2853 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "local-only"))
2855 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2863 API int pkgmgrinfo_appinfo_foreach_background_category(
2864 pkgmgrinfo_appinfo_h handle,
2865 pkgmgrinfo_app_background_category_list_cb category_func,
2868 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2872 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2873 LOGE("invalid parameter");
2874 return PMINFO_R_EINVAL;
2877 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2878 category = (char *)tmp->data;
2879 if (category == NULL)
2882 if (category_func(category, user_data) < 0)
2889 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2890 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2893 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2894 splashscreen_x *splashscreen;
2898 if (info == NULL || info->app_info == NULL
2899 || splash_screen_func == NULL) {
2900 LOGE("invalid parameter");
2901 return PMINFO_R_EINVAL;
2904 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2905 splashscreen = (splashscreen_x *)tmp->data;
2906 if (splashscreen == NULL)
2908 ret = splash_screen_func(splashscreen->src,
2910 splashscreen->orientation,
2911 splashscreen->indicatordisplay,
2912 splashscreen->operation,
2913 splashscreen->color_depth,
2922 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2924 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2925 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2926 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2928 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2929 return PMINFO_R_ERROR;
2931 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2936 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2938 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2939 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2940 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2942 if (info->app_info == NULL || info->app_info->multiple == NULL)
2943 return PMINFO_R_ERROR;
2945 *multiple = _get_bool_value(info->app_info->multiple);
2950 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2952 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2953 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2954 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2956 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2957 return PMINFO_R_ERROR;
2959 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2964 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2966 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2967 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2968 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2970 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2971 return PMINFO_R_ERROR;
2973 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2978 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2980 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2981 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2982 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2984 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2985 return PMINFO_R_ERROR;
2987 *enabled = !_get_bool_value(info->app_info->is_disabled);
2992 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2994 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2995 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2996 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2998 if (info->app_info == NULL || info->app_info->onboot == NULL)
2999 return PMINFO_R_ERROR;
3001 *onboot = _get_bool_value(info->app_info->onboot);
3006 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
3008 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3009 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3010 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3012 if (info->app_info == NULL || info->app_info->autorestart == NULL)
3013 return PMINFO_R_ERROR;
3015 *autorestart = _get_bool_value(info->app_info->autorestart);
3020 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
3022 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3023 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3024 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3026 if (info->app_info == NULL || info->app_info->mainapp == NULL)
3027 return PMINFO_R_ERROR;
3029 *mainapp = _get_bool_value(info->app_info->mainapp);
3034 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
3036 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3037 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3038 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3040 if (info->app_info == NULL || info->app_info->preload == NULL)
3041 return PMINFO_R_ERROR;
3043 *preload = _get_bool_value(info->app_info->preload);
3048 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
3050 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3051 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3052 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3054 if (info->app_info == NULL || info->app_info->submode == NULL)
3055 return PMINFO_R_ERROR;
3057 *submode = _get_bool_value(info->app_info->submode);
3062 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
3064 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3066 if (handle == NULL || process_pool == NULL) {
3067 LOGE("invalid parameter");
3068 return PMINFO_R_EINVAL;
3071 if (info->app_info == NULL)
3072 return PMINFO_R_ERROR;
3074 *process_pool = _get_bool_value(info->app_info->process_pool);
3079 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
3081 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3082 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
3083 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
3087 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3089 if (info->app_info == NULL)
3090 return PMINFO_R_ERROR;
3093 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
3094 val = (const char *)tmp->data;
3097 if (strcasecmp(val, category) == 0) {
3106 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
3109 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3111 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
3112 _LOGE("invalid parameter");
3113 return PMINFO_R_EINVAL;
3115 if (info->app_info->ui_gadget == NULL)
3116 info->app_info->ui_gadget = strdup("false");
3118 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
3123 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
3124 bool *support_disable)
3126 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3128 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
3129 _LOGE("invalid parameter");
3130 return PMINFO_R_EINVAL;
3133 *support_disable = _get_bool_value(info->app_info->support_disable);
3138 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
3141 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3143 if (info == NULL || info->app_info == NULL || removable == NULL) {
3144 _LOGE("invalid parameter");
3145 return PMINFO_R_EINVAL;
3148 *removable = _get_bool_value(info->app_info->removable);
3153 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
3155 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3157 if (info == NULL || info->app_info == NULL || system == NULL) {
3158 _LOGE("invalid parameter");
3159 return PMINFO_R_EINVAL;
3162 *system = _get_bool_value(info->app_info->package_system);
3167 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
3169 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3170 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3171 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3173 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
3174 return PMINFO_R_ERROR;
3176 *disabled = _get_bool_value(info->app_info->is_disabled);
3181 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
3183 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3185 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3186 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3188 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
3189 return PMINFO_R_ERROR;
3191 *global = _get_bool_value(info->app_info->for_all_users);
3196 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
3198 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3200 if (info == NULL || splash_screen_display == NULL) {
3201 _LOGE("Invalid parameter");
3202 return PMINFO_R_EINVAL;
3205 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
3206 return PMINFO_R_ERROR;
3208 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
3213 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
3215 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3217 if (info == NULL || setup_appid == NULL) {
3218 _LOGE("Invalid parameter");
3219 return PMINFO_R_EINVAL;
3222 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
3223 return PMINFO_R_ERROR;
3225 *setup_appid = info->app_info->setup_appid;
3229 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
3230 bool *support_ambient)
3232 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3234 if (info == NULL || support_ambient == NULL) {
3235 _LOGE("Invalid parameter");
3236 return PMINFO_R_EINVAL;
3239 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
3240 return PMINFO_R_ERROR;
3242 *support_ambient = _get_bool_value(info->app_info->support_ambient);
3247 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
3249 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3250 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3251 __cleanup_appinfo(info);
3255 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
3257 return (pkgmgrinfo_pkginfo_filter_create(handle));
3260 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
3262 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3265 static gint __compare_func(gconstpointer data1, gconstpointer data2)
3267 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
3268 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
3269 if (node1->prop == node2->prop)
3271 else if (node1->prop > node2->prop)
3277 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
3278 const char *property, const int value)
3280 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3281 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3282 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3284 GSList *link = NULL;
3286 prop = _pminfo_appinfo_convert_to_prop_int(property);
3287 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
3288 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
3289 _LOGE("Invalid Integer Property\n");
3290 return PMINFO_R_EINVAL;
3292 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3293 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3295 _LOGE("Out of Memory!!!\n");
3296 return PMINFO_R_ERROR;
3298 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3299 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3301 _LOGE("Out of Memory\n");
3304 return PMINFO_R_ERROR;
3308 /*If API is called multiple times for same property, we should override the previous values.
3309 Last value set will be used for filtering.*/
3310 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3312 filter->list = g_slist_delete_link(filter->list, link);
3313 filter->list = g_slist_append(filter->list, (gpointer)node);
3318 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
3319 const char *property, const bool value)
3321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3322 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3324 GSList *link = NULL;
3326 prop = _pminfo_appinfo_convert_to_prop_bool(property);
3327 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
3328 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
3329 _LOGE("Invalid Boolean Property\n");
3330 return PMINFO_R_EINVAL;
3332 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3333 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3335 _LOGE("Out of Memory!!!\n");
3336 return PMINFO_R_ERROR;
3339 val = strndup("true", 4);
3341 val = strndup("false", 5);
3343 _LOGE("Out of Memory\n");
3346 return PMINFO_R_ERROR;
3350 /*If API is called multiple times for same property, we should override the previous values.
3351 Last value set will be used for filtering.*/
3352 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3354 filter->list = g_slist_delete_link(filter->list, link);
3355 filter->list = g_slist_append(filter->list, (gpointer)node);
3360 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
3361 const char *property, const char *value)
3363 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3364 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3365 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3367 pkgmgrinfo_node_x *ptr = NULL;
3368 char prev[PKG_STRING_LEN_MAX] = {'\0'};
3369 char temp[PKG_STRING_LEN_MAX] = {'\0'};
3370 GSList *link = NULL;
3372 prop = _pminfo_appinfo_convert_to_prop_str(property);
3373 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
3374 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
3375 _LOGE("Invalid String Property\n");
3376 return PMINFO_R_EINVAL;
3378 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3379 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3381 _LOGE("Out of Memory!!!\n");
3382 return PMINFO_R_ERROR;
3386 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
3387 node->value = strdup(value);
3388 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3390 filter->list = g_slist_delete_link(filter->list, link);
3391 filter->list = g_slist_append(filter->list, (gpointer)node);
3393 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
3394 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
3396 _LOGE("Out of Memory\n");
3399 return PMINFO_R_ERROR;
3401 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3403 ptr = (pkgmgrinfo_node_x *)link->data;
3404 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
3405 _LOGI("Previous value is %s\n", prev);
3406 filter->list = g_slist_delete_link(filter->list, link);
3407 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
3408 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3409 _LOGI("New value is %s\n", val);
3411 filter->list = g_slist_append(filter->list, (gpointer)node);
3412 memset(temp, '\0', PKG_STRING_LEN_MAX);
3414 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3415 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3416 _LOGI("First value is %s\n", val);
3418 filter->list = g_slist_append(filter->list, (gpointer)node);
3419 memset(temp, '\0', PKG_STRING_LEN_MAX);
3423 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3424 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3426 filter->list = g_slist_delete_link(filter->list, link);
3427 filter->list = g_slist_append(filter->list, (gpointer)node);
3433 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3439 if (handle == NULL || count == NULL) {
3440 _LOGE("invalid parameter");
3441 return PMINFO_R_EINVAL;
3444 locale = _get_system_locale();
3446 return PMINFO_R_ERROR;
3448 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3449 __free_applications);
3452 return PMINFO_R_ERROR;
3455 if (__check_disable_filter_exist(
3456 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3457 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3458 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
3459 g_hash_table_destroy(list);
3461 return PMINFO_R_ERROR;
3465 if (__check_disable_filter_exist(
3466 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3467 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3468 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
3469 g_hash_table_destroy(list);
3471 return PMINFO_R_ERROR;
3475 ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3476 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3477 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3480 if (ret != PMINFO_R_OK) {
3481 g_hash_table_destroy(list);
3483 return PMINFO_R_ERROR;
3486 *count = g_hash_table_size(list);
3487 g_hash_table_destroy(list);
3493 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3495 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3498 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3499 pkgmgrinfo_appinfo_filter_h handle,
3500 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3502 if (handle == NULL || app_cb == NULL) {
3503 LOGE("invalid parameter");
3504 return PMINFO_R_EINVAL;
3507 if (__check_disable_filter_exist(
3508 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3509 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3510 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3511 return PMINFO_R_ERROR;
3514 if (__check_disable_filter_exist(
3515 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3516 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3517 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3518 return PMINFO_R_ERROR;
3521 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3525 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3526 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3528 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3531 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3533 return (pkgmgrinfo_pkginfo_filter_create(handle));
3536 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3538 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3541 API int pkgmgrinfo_appinfo_metadata_filter_add(
3542 pkgmgrinfo_appinfo_metadata_filter_h handle,
3543 const char *key, const char *value)
3545 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3546 pkgmgrinfo_metadata_node_x *node;
3548 /* value can be NULL.
3549 * In that case all apps with specified key should be displayed
3552 LOGE("invalid parameter");
3553 return PMINFO_R_EINVAL;
3556 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3558 LOGE("out of memory");
3559 return PMINFO_R_ERROR;
3562 node->key = strdup(key);
3563 if (value && strlen(value))
3564 node->value = strdup(value);
3566 filter->list_metadata = g_slist_append(filter->list_metadata,
3572 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3573 pkgmgrinfo_appinfo_metadata_filter_h handle,
3574 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3576 if (handle == NULL || app_cb == NULL) {
3577 LOGE("invalid parameter");
3578 return PMINFO_R_EINVAL;
3581 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3582 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3583 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3584 return PMINFO_R_ERROR;
3586 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3587 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3588 return PMINFO_R_ERROR;
3590 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3594 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3595 pkgmgrinfo_appinfo_metadata_filter_h handle,
3596 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3598 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3599 user_data, _getuid());
3602 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3605 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3607 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3608 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3610 val = info->app_info->guestmode_visibility;
3611 *status = _get_bool_value(val);