13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 static bool _get_bool_value(const char *str)
20 if (str && !strcmp(str, "true"))
26 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
28 pkgmgr_appinfo_x *info = data;
32 free((void *)info->package);
34 free((void *)info->locale);
36 pkgmgrinfo_basic_free_application(info->app_info);
42 static const char join_localized_info[] =
43 " LEFT OUTER JOIN package_app_localized_info"
44 " ON ai.app_id=package_app_localized_info.app_id"
45 " AND package_app_localized_info.app_locale=?";
46 static const char join_category[] =
47 " LEFT OUTER JOIN package_app_app_category"
48 " ON ai.app_id=package_app_app_category.app_id";
49 static const char join_app_control[] =
50 " LEFT OUTER JOIN package_app_app_control"
51 " ON ai.app_id=package_app_app_control.app_id";
52 static const char join_metadata[] =
53 " LEFT OUTER JOIN package_app_app_metadata"
54 " ON ai.app_id=package_app_app_metadata.app_id ";
56 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
57 const char *locale, uid_t uid, char **query, GList **bind_params)
60 char *condition = NULL;
61 char buf[MAX_QUERY_LEN] = { '\0' };
62 char tmp_query[MAX_QUERY_LEN] = { '\0' };
67 strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1);
69 for (list = filter->list; list; list = list->next) {
70 joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
71 if (condition == NULL)
74 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
76 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
81 if (filter->list_metadata)
82 strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1);
83 for (list = filter->list_metadata; list; list = list->next) {
84 joined |= __get_metadata_filter_condition(list->data,
85 &condition, bind_params);
86 if (condition == NULL)
88 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
92 strncat(buf, " OR ", sizeof(buf) - strlen(buf) - 1);
94 if (filter->list_metadata)
95 strncat(buf, "1=0)", sizeof(buf) - strlen(buf) - 1);
97 if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
98 strncat(tmp_query, join_localized_info, sizeof(tmp_query) - strlen(tmp_query) - 1);
99 *bind_params = g_list_append(*bind_params, strdup(locale));
101 if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY)
102 strncat(tmp_query, join_category, sizeof(tmp_query) - strlen(tmp_query) - 1);
103 if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL)
104 strncat(tmp_query, join_app_control, sizeof(tmp_query) - strlen(tmp_query) - 1);
105 if (joined & E_PMINFO_APPINFO_JOIN_METADATA)
106 strncat(tmp_query, join_metadata, sizeof(tmp_query) - strlen(tmp_query) - 1);
108 strncat(tmp_query, buf, sizeof(tmp_query) - strlen(tmp_query) - 1);
110 *query = strdup(tmp_query);
112 return PMINFO_R_ERROR;
117 static int _appinfo_get_category(sqlite3 *db, const char *appid,
120 static const char query_raw[] =
121 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
127 query = sqlite3_mprintf(query_raw, appid);
129 LOGE("out of memory");
130 return PMINFO_R_ERROR;
133 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
135 if (ret != SQLITE_OK) {
136 LOGE("prepare failed: %s", sqlite3_errmsg(db));
137 return PMINFO_R_ERROR;
140 while (sqlite3_step(stmt) == SQLITE_ROW) {
142 _save_column_str(stmt, 0, &val);
144 *category = g_list_append(*category, (gpointer)val);
147 sqlite3_finalize(stmt);
152 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
159 if (appcontrol_str == NULL)
162 dup = strdup(appcontrol_str);
164 ac = calloc(1, sizeof(appcontrol_x));
166 _LOGE("out of memory");
169 token = strtok_r(dup, "|", &ptr);
170 if (token && strcmp(token, "NULL"))
171 ac->operation = strdup(token);
172 token = strtok_r(NULL, "|", &ptr);
173 if (token && strcmp(token, "NULL"))
174 ac->uri = strdup(token);
175 token = strtok_r(NULL, "|", &ptr);
176 if (token && strcmp(token, "NULL"))
177 ac->mime = strdup(token);
178 *appcontrol = g_list_append(*appcontrol, ac);
179 } while ((token = strtok_r(NULL, ";", &ptr)));
184 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
187 static const char query_raw[] =
188 "SELECT app_control FROM package_app_app_control "
195 query = sqlite3_mprintf(query_raw, appid);
197 LOGE("out of memory");
198 return PMINFO_R_ERROR;
201 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
203 if (ret != SQLITE_OK) {
204 LOGE("prepare failed: %s", sqlite3_errmsg(db));
205 return PMINFO_R_ERROR;
208 while (sqlite3_step(stmt) == SQLITE_ROW) {
210 _save_column_str(stmt, 0, &str);
212 __parse_appcontrol(appcontrol, str);
216 sqlite3_finalize(stmt);
221 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
224 static const char query_raw[] =
225 "SELECT md_key, md_value "
226 "FROM package_app_app_metadata WHERE app_id=%Q";
233 query = sqlite3_mprintf(query_raw, appid);
235 LOGE("out of memory");
236 return PMINFO_R_ERROR;
239 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
241 if (ret != SQLITE_OK) {
242 LOGE("prepare failed: %s", sqlite3_errmsg(db));
243 return PMINFO_R_ERROR;
246 while (sqlite3_step(stmt) == SQLITE_ROW) {
247 info = calloc(1, sizeof(metadata_x));
249 LOGE("out of memory");
250 sqlite3_finalize(stmt);
251 return PMINFO_R_ERROR;
254 _save_column_str(stmt, idx++, &info->key);
255 _save_column_str(stmt, idx++, &info->value);
256 *metadata = g_list_append(*metadata, info);
259 sqlite3_finalize(stmt);
265 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
266 GList **splashscreens)
268 static const char query_raw[] =
269 "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
270 "FROM package_app_splash_screen WHERE app_id=%Q";
275 splashscreen_x *info;
277 query = sqlite3_mprintf(query_raw, appid);
279 LOGE("out of memory");
280 return PMINFO_R_ERROR;
283 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
285 if (ret != SQLITE_OK) {
286 LOGE("prepare failed: %s", sqlite3_errmsg(db));
287 return PMINFO_R_ERROR;
290 while (sqlite3_step(stmt) == SQLITE_ROW) {
291 info = calloc(1, sizeof(splashscreen_x));
293 LOGE("out of memory");
294 sqlite3_finalize(stmt);
295 return PMINFO_R_ERROR;
298 _save_column_str(stmt, idx++, &info->src);
299 _save_column_str(stmt, idx++, &info->type);
300 _save_column_str(stmt, idx++, &info->orientation);
301 _save_column_str(stmt, idx++, &info->indicatordisplay);
302 _save_column_str(stmt, idx++, &info->operation);
303 _save_column_str(stmt, idx++, &info->color_depth);
304 *splashscreens = g_list_append(*splashscreens, info);
307 sqlite3_finalize(stmt);
312 static GList *__get_background_category(const char *value)
314 GList *category_list = NULL;
315 int convert_value = 0;
316 if (!value || strlen(value) == 0)
319 convert_value = atoi(value);
320 if (convert_value < 0)
323 if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
324 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
326 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
328 if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
329 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
331 if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
332 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
334 if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
335 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
337 if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
338 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
340 if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
341 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
343 if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
344 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
346 if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
347 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
349 return category_list;
353 static void __free_applications(gpointer data)
355 pkgmgrinfo_basic_free_application((application_x *)data);
358 static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
360 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
361 pkgmgrinfo_appinfo_disable_type value = GPOINTER_TO_INT(data2);
363 if (value == E_APPINFO_DISABLE_TYPE_PKG)
364 return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
367 return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
371 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
372 pkgmgrinfo_appinfo_disable_type type)
379 link = g_slist_find_custom(filter->list, GINT_TO_POINTER(type), __disable_chk_func);
386 static int __bind_params(sqlite3_stmt *stmt, GList *params)
388 GList *tmp_list = NULL;
392 if (stmt == NULL || params == NULL)
393 return PMINFO_R_EINVAL;
397 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
398 if (ret != SQLITE_OK)
399 return PMINFO_R_ERROR;
400 tmp_list = tmp_list->next;
406 static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter)
408 GSList *tmp_list = NULL;
409 pkgmgrinfo_node_x *tmp_node = NULL;
412 if (tmp_filter == NULL)
415 property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
416 for (tmp_list = tmp_filter->list; tmp_list != NULL;
417 tmp_list = g_slist_next(tmp_list)) {
418 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
419 if (property == tmp_node->prop) {
420 if (strcmp(tmp_node->value, "true") == 0)
430 static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
431 const char *locale, pkgmgrinfo_filter_x *filter, int flag,
432 GHashTable *applications)
434 static const char query_raw[] =
435 "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
436 "ai.app_external_path";
437 static const char query_basic[] =
438 ", ai.app_component, ai.app_exec, "
439 "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
440 "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
441 "ai.app_hwacceleration, ai.app_screenreader, "
442 "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, "
443 "ai.app_indicatordisplay, ai.app_portraitimg, "
444 "ai.app_landscapeimg, ai.app_guestmodevisibility, "
445 "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
446 "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
447 "ai.app_support_disable, ai.app_process_pool, "
448 "ai.app_background_category, ai.app_package_type, "
449 "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
450 "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
451 "ai.app_zip_mount_file, ai.component_type, ai.package, "
452 "ai.app_package_system, ai.app_removable, "
453 "ai.app_package_installed_time, ai.app_support_mode, "
454 "ai.app_support_ambient, ai.app_setup_appid";
455 static const char query_uid_info[] =
456 ", ui.is_disabled, ui.is_splash_screen_enabled";
457 static const char query_label[] =
459 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
460 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
461 static const char query_icon[] =
463 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
464 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
465 static const char query_from_clause[] = " FROM package_app_info as ai";
466 static const char query_uid_info_clause[] =
467 " LEFT OUTER JOIN package_app_info_for_uid AS ui "
468 "ON (ai.app_id=ui.app_id AND ui.uid=?)";
469 int ret = PMINFO_R_ERROR;
472 char *bg_category_str = NULL;
473 char *constraint = NULL;
474 char *tmp_record = NULL;
475 char query[MAX_QUERY_LEN] = { '\0' };
476 char buf[BUFSIZE] = { '\0' };
477 application_x *info = NULL;
478 GList *bind_params = NULL;
480 sqlite3_stmt *stmt = NULL;
481 bool is_check_storage = true;
482 const uid_t global_user_uid = GLOBAL_USER;
484 dbpath = getUserPkgParserDBPathUID(db_uid);
486 return PMINFO_R_ERROR;
488 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
489 if (ret != SQLITE_OK) {
490 _LOGE("failed to open db(%s): %d", dbpath, ret);
492 return PMINFO_R_ERROR;
496 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
498 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
499 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
500 strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1);
502 if (flag & PMINFO_APPINFO_GET_LABEL) {
503 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
504 bind_params = g_list_append(bind_params, strdup(locale));
506 if (flag & PMINFO_APPINFO_GET_ICON) {
507 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
508 bind_params = g_list_append(bind_params, strdup(locale));
511 snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
512 bind_params = g_list_append(bind_params, strdup(buf));
514 is_check_storage = __check_app_storage_status(filter);
516 ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
517 if (ret != PMINFO_R_OK) {
518 LOGE("Failed to get WHERE clause");
521 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
523 strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1);
526 strncat(query, constraint, sizeof(query) - strlen(query) - 1);
528 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
529 if (ret != SQLITE_OK) {
530 LOGE("prepare failed: %s", sqlite3_errmsg(db));
531 ret = PMINFO_R_ERROR;
535 if (g_list_length(bind_params) != 0) {
536 ret = __bind_params(stmt, bind_params);
537 if (ret != SQLITE_OK) {
538 LOGE("Failed to bind parameters");
543 while (sqlite3_step(stmt) == SQLITE_ROW) {
544 info = calloc(1, sizeof(application_x));
546 LOGE("out of memory");
547 ret = PMINFO_R_ERROR;
551 _save_column_str(stmt, idx++, &info->appid);
552 _save_column_str(stmt, idx++, &info->installed_storage);
553 _save_column_str(stmt, idx++ , &info->external_path);
555 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
556 _save_column_str(stmt, idx++, &info->component);
557 _save_column_str(stmt, idx++, &info->exec);
558 _save_column_str(stmt, idx++, &info->nodisplay);
559 _save_column_str(stmt, idx++, &info->type);
560 _save_column_str(stmt, idx++, &info->onboot);
561 _save_column_str(stmt, idx++, &info->multiple);
562 _save_column_str(stmt, idx++, &info->autorestart);
563 _save_column_str(stmt, idx++, &info->taskmanage);
564 _save_column_str(stmt, idx++, &info->hwacceleration);
565 _save_column_str(stmt, idx++, &info->screenreader);
566 _save_column_str(stmt, idx++, &info->mainapp);
567 _save_column_str(stmt, idx++, &info->recentimage);
568 _save_column_str(stmt, idx++, &info->launchcondition);
569 _save_column_str(stmt, idx++, &info->indicatordisplay);
570 _save_column_str(stmt, idx++, &info->portraitimg);
571 _save_column_str(stmt, idx++, &info->landscapeimg);
572 _save_column_str(stmt, idx++, &info->guestmode_visibility);
573 _save_column_str(stmt, idx++, &info->permission_type);
574 _save_column_str(stmt, idx++, &info->preload);
575 _save_column_str(stmt, idx++, &info->submode);
576 _save_column_str(stmt, idx++, &info->submode_mainid);
577 _save_column_str(stmt, idx++, &info->launch_mode);
578 _save_column_str(stmt, idx++, &info->ui_gadget);
579 _save_column_str(stmt, idx++, &info->support_disable);
580 _save_column_str(stmt, idx++, &info->process_pool);
581 _save_column_str(stmt, idx++, &bg_category_str);
582 _save_column_str(stmt, idx++, &info->package_type);
583 _save_column_str(stmt, idx++, &info->root_path);
584 _save_column_str(stmt, idx++, &info->api_version);
585 _save_column_str(stmt, idx++, &info->effective_appid);
586 _save_column_str(stmt, idx++, &info->is_disabled);
587 _save_column_str(stmt, idx++, &info->splash_screen_display);
588 _save_column_str(stmt, idx++, &info->tep_name);
589 _save_column_str(stmt, idx++, &info->zip_mount_file);
590 _save_column_str(stmt, idx++, &info->component_type);
591 _save_column_str(stmt, idx++, &info->package);
592 _save_column_str(stmt, idx++, &info->package_system);
593 _save_column_str(stmt, idx++, &info->removable);
594 _save_column_str(stmt, idx++, &info->package_installed_time);
595 _save_column_str(stmt, idx++, &info->support_mode);
596 _save_column_str(stmt, idx++, &info->support_ambient);
597 _save_column_str(stmt, idx++, &info->setup_appid);
598 info->background_category = __get_background_category(
600 free(bg_category_str);
603 info->for_all_users =
604 strdup((db_uid != global_user_uid) ? "false" : "true");
606 if (db_uid != global_user_uid) {
610 _save_column_str(stmt, idx++, &tmp_record);
611 if (tmp_record != NULL) {
612 if (strcasecmp(info->is_disabled, "false") == 0 &&
613 strcasecmp(tmp_record, "false") == 0) {
614 free(info->is_disabled);
615 info->is_disabled = tmp_record;
619 _save_column_str(stmt, idx++, &tmp_record);
620 if (tmp_record != NULL) {
621 if (strcasecmp(info->splash_screen_display, "false") == 0 &&
622 strcasecmp(tmp_record, "false") == 0) {
623 free(info->splash_screen_display);
624 info->splash_screen_display = tmp_record;
629 if (flag & PMINFO_APPINFO_GET_LABEL) {
631 _save_column_str(stmt, idx++, &tmp_record);
632 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
633 ret = PMINFO_R_ERROR;
638 if (flag & PMINFO_APPINFO_GET_ICON) {
640 _save_column_str(stmt, idx++, &tmp_record);
641 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
642 ret = PMINFO_R_ERROR;
647 if (flag & PMINFO_APPINFO_GET_CATEGORY) {
648 if (_appinfo_get_category(db, info->appid,
650 ret = PMINFO_R_ERROR;
655 if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
656 if (_appinfo_get_app_control(db, info->appid,
657 &info->appcontrol)) {
658 ret = PMINFO_R_ERROR;
663 if (flag & PMINFO_APPINFO_GET_METADATA) {
664 if (_appinfo_get_metadata(db, info->appid,
666 ret = PMINFO_R_ERROR;
671 if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
672 if (_appinfo_get_splashscreens(db, info->appid,
673 &info->splashscreens)) {
674 ret = PMINFO_R_ERROR;
679 if (is_check_storage &&
680 __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
681 ret = PMINFO_R_ERROR;
682 pkgmgrinfo_basic_free_application(info);
687 g_hash_table_insert(applications, (gpointer)info->appid,
697 if (ret != PMINFO_R_OK && info != NULL)
698 pkgmgrinfo_basic_free_application(info);
700 g_list_free_full(bind_params, free);
701 sqlite3_close_v2(db);
702 sqlite3_finalize(stmt);
707 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
708 pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
713 pkgmgr_appinfo_x *info;
715 if (appid == NULL || filter == NULL || handle == NULL) {
716 LOGE("invalid parameter");
717 return PMINFO_R_EINVAL;
720 locale = _get_system_locale();
722 return PMINFO_R_ERROR;
724 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
725 __free_applications);
728 return PMINFO_R_ERROR;
731 ret = _appinfo_get_applications(uid, uid, locale, filter,
732 PMINFO_APPINFO_GET_ALL, list);
733 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
734 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
735 PMINFO_APPINFO_GET_ALL, list);
737 if (ret != PMINFO_R_OK) {
738 g_hash_table_destroy(list);
743 if (!g_hash_table_size(list)) {
744 _LOGD("appinfo for [%s] is not existed for user [%d]",
746 g_hash_table_destroy(list);
748 return PMINFO_R_ENOENT;
751 info = calloc(1, sizeof(pkgmgr_appinfo_x));
753 _LOGE("out of memory");
754 g_hash_table_destroy(list);
756 return PMINFO_R_ERROR;
759 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
760 info->locale = locale;
761 info->package = strdup(info->app_info->package);
763 /* just free list only */
764 g_hash_table_steal(list, (gconstpointer)appid);
765 g_hash_table_destroy(list);
772 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
773 pkgmgrinfo_appinfo_h *handle)
776 pkgmgrinfo_appinfo_filter_h filter;
778 if (appid == NULL || handle == NULL) {
779 LOGE("invalid parameter");
780 return PMINFO_R_EINVAL;
783 ret = pkgmgrinfo_appinfo_filter_create(&filter);
784 if (ret != PMINFO_R_OK)
787 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
788 PMINFO_APPINFO_PROP_APP_ID, appid);
789 if (ret != PMINFO_R_OK) {
790 pkgmgrinfo_appinfo_filter_destroy(filter);
791 return PMINFO_R_ERROR;
794 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
795 PMINFO_APPINFO_PROP_APP_DISABLE, true);
796 if (ret != PMINFO_R_OK) {
797 pkgmgrinfo_appinfo_filter_destroy(filter);
798 return PMINFO_R_ERROR;
801 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
802 pkgmgrinfo_appinfo_filter_destroy(filter);
807 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
809 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
812 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
813 pkgmgrinfo_appinfo_h *handle)
816 pkgmgrinfo_appinfo_filter_h filter;
818 if (appid == NULL || handle == NULL) {
819 LOGE("invalid parameter");
820 return PMINFO_R_EINVAL;
823 ret = pkgmgrinfo_appinfo_filter_create(&filter);
824 if (ret != PMINFO_R_OK)
827 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
828 PMINFO_APPINFO_PROP_APP_ID, appid);
829 if (ret != PMINFO_R_OK) {
830 pkgmgrinfo_appinfo_filter_destroy(filter);
831 return PMINFO_R_ERROR;
834 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
835 PMINFO_APPINFO_PROP_APP_DISABLE, false);
836 if (ret != PMINFO_R_OK) {
837 pkgmgrinfo_appinfo_filter_destroy(filter);
838 return PMINFO_R_ERROR;
841 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
842 PMINFO_APPINFO_PROP_PKG_DISABLE, false);
843 if (ret != PMINFO_R_OK) {
844 pkgmgrinfo_appinfo_filter_destroy(filter);
845 return PMINFO_R_ERROR;
848 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
849 pkgmgrinfo_appinfo_filter_destroy(filter);
853 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
855 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
858 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
859 pkgmgrinfo_appinfo_h *handle)
862 pkgmgrinfo_appinfo_filter_h filter;
864 if (appid == NULL || handle == NULL) {
865 LOGE("invalid parameter");
866 return PMINFO_R_EINVAL;
869 ret = pkgmgrinfo_appinfo_filter_create(&filter);
870 if (ret != PMINFO_R_OK)
873 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
874 PMINFO_APPINFO_PROP_APP_ID, appid);
875 if (ret != PMINFO_R_OK) {
876 pkgmgrinfo_appinfo_filter_destroy(filter);
877 return PMINFO_R_ERROR;
880 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
881 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
882 if (ret != PMINFO_R_OK) {
883 pkgmgrinfo_appinfo_filter_destroy(filter);
884 return PMINFO_R_ERROR;
887 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
888 pkgmgrinfo_appinfo_filter_destroy(filter);
893 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
895 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
898 static gpointer __copy_str(gconstpointer src, gpointer data)
900 const char *tmp = (const char *)src;
903 buffer = strdup(tmp);
904 if (buffer == NULL) {
905 LOGE("memory alloc failed");
913 static gpointer __copy_label(gconstpointer src, gpointer data)
915 label_x *tmp = (label_x *)src;
918 label = calloc(1, sizeof(label_x));
920 LOGE("memory alloc failed");
926 label->name = strdup(tmp->name);
928 label->text = strdup(tmp->text);
930 label->lang = strdup(tmp->lang);
935 static gpointer __copy_icon(gconstpointer src, gpointer data)
937 icon_x *tmp = (icon_x *)src;
940 icon = calloc(1, sizeof(icon_x));
942 LOGE("memory alloc failed");
948 icon->text = strdup(tmp->text);
950 icon->lang = strdup(tmp->lang);
952 icon->section = strdup(tmp->section);
954 icon->size = strdup(tmp->size);
956 icon->resolution = strdup(tmp->resolution);
961 static gpointer __copy_metadata(gconstpointer src, gpointer data)
963 metadata_x *tmp = (metadata_x *)src;
964 metadata_x *metadata;
966 metadata = calloc(1, sizeof(metadata_x));
967 if (metadata == NULL) {
968 LOGE("memory alloc failed");
974 metadata->key = strdup(tmp->key);
976 metadata->value = strdup(tmp->value);
981 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
983 datacontrol_x *tmp = (datacontrol_x *)src;
984 datacontrol_x *datacontrol;
986 datacontrol = calloc(1, sizeof(datacontrol_x));
987 if (datacontrol == NULL) {
988 LOGE("memory alloc failed");
994 datacontrol->providerid = strdup(tmp->providerid);
996 datacontrol->access = strdup(tmp->access);
998 datacontrol->type = strdup(tmp->type);
1000 datacontrol->trusted = strdup(tmp->trusted);
1005 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1007 appcontrol_x *tmp = (appcontrol_x *)src;
1008 appcontrol_x *appcontrol;
1010 appcontrol = calloc(1, sizeof(appcontrol_x));
1011 if (appcontrol == NULL) {
1012 LOGE("memory alloc failed");
1018 appcontrol->operation = strdup(tmp->operation);
1020 appcontrol->uri = strdup(tmp->uri);
1022 appcontrol->mime = strdup(tmp->mime);
1027 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1029 splashscreen_x *tmp = (splashscreen_x *)src;
1030 splashscreen_x *splashscreen;
1032 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1033 if (splashscreen == NULL) {
1034 LOGE("memory alloc failed");
1040 splashscreen->src = strdup(tmp->src);
1042 splashscreen->type = strdup(tmp->type);
1043 if (tmp->orientation)
1044 splashscreen->orientation = strdup(tmp->orientation);
1045 if (tmp->indicatordisplay)
1046 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1048 splashscreen->operation = strdup(tmp->operation);
1049 if (tmp->color_depth)
1050 splashscreen->color_depth = strdup(tmp->color_depth);
1052 return splashscreen;
1055 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1057 application_x *app_info;
1060 app_info = calloc(1, sizeof(application_x));
1061 if (app_info == NULL) {
1062 LOGE("memory alloc failed");
1063 return PMINFO_R_ERROR;
1066 if (data->appid != NULL)
1067 app_info->appid = strdup(data->appid);
1068 if (data->exec != NULL)
1069 app_info->exec = strdup(data->exec);
1070 if (data->nodisplay != NULL)
1071 app_info->nodisplay = strdup(data->nodisplay);
1072 if (data->multiple != NULL)
1073 app_info->multiple = strdup(data->multiple);
1074 if (data->taskmanage != NULL)
1075 app_info->taskmanage = strdup(data->taskmanage);
1076 if (data->type != NULL)
1077 app_info->type = strdup(data->type);
1078 if (data->categories != NULL)
1079 app_info->categories = strdup(data->categories);
1080 if (data->hwacceleration != NULL)
1081 app_info->hwacceleration = strdup(data->hwacceleration);
1082 if (data->screenreader != NULL)
1083 app_info->screenreader = strdup(data->screenreader);
1084 if (data->mainapp != NULL)
1085 app_info->mainapp = strdup(data->mainapp);
1086 if (data->package != NULL)
1087 app_info->package = strdup(data->package);
1088 if (data->recentimage != NULL)
1089 app_info->recentimage = strdup(data->recentimage);
1090 if (data->launchcondition != NULL)
1091 app_info->launchcondition = strdup(data->launchcondition);
1092 if (data->indicatordisplay != NULL)
1093 app_info->indicatordisplay = strdup(data->indicatordisplay);
1094 if (data->portraitimg != NULL)
1095 app_info->portraitimg = strdup(data->portraitimg);
1096 if (data->landscapeimg != NULL)
1097 app_info->landscapeimg = strdup(data->landscapeimg);
1098 if (data->guestmode_visibility != NULL)
1099 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1100 if (data->component != NULL)
1101 app_info->component = strdup(data->component);
1102 if (data->permission_type != NULL)
1103 app_info->permission_type = strdup(data->permission_type);
1104 if (data->component_type != NULL)
1105 app_info->component_type = strdup(data->component_type);
1106 if (data->preload != NULL)
1107 app_info->preload = strdup(data->preload);
1108 if (data->submode != NULL)
1109 app_info->submode = strdup(data->submode);
1110 if (data->submode_mainid != NULL)
1111 app_info->submode_mainid = strdup(data->submode_mainid);
1112 if (data->process_pool != NULL)
1113 app_info->process_pool = strdup(data->process_pool);
1114 if (data->installed_storage != NULL)
1115 app_info->installed_storage = strdup(data->installed_storage);
1116 if (data->autorestart != NULL)
1117 app_info->autorestart = strdup(data->autorestart);
1118 if (data->onboot != NULL)
1119 app_info->onboot = strdup(data->onboot);
1120 if (data->support_disable != NULL)
1121 app_info->support_disable = strdup(data->support_disable);
1122 if (data->ui_gadget != NULL)
1123 app_info->ui_gadget = strdup(data->ui_gadget);
1124 if (data->launch_mode != NULL)
1125 app_info->launch_mode = strdup(data->launch_mode);
1126 if (data->package_type != NULL)
1127 app_info->package_type = strdup(data->package_type);
1128 if (data->effective_appid != NULL)
1129 app_info->effective_appid = strdup(data->effective_appid);
1130 if (data->splash_screen_display != NULL)
1131 app_info->splash_screen_display = strdup(data->splash_screen_display);
1135 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1137 LOGE("memory alloc failed");
1138 pkgmgrinfo_basic_free_application(app_info);
1139 return PMINFO_R_ERROR;
1143 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1145 LOGE("memory alloc failed");
1146 pkgmgrinfo_basic_free_application(app_info);
1147 return PMINFO_R_ERROR;
1151 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1153 LOGE("memory alloc failed");
1154 pkgmgrinfo_basic_free_application(app_info);
1155 return PMINFO_R_ERROR;
1159 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1161 LOGE("memory alloc failed");
1162 pkgmgrinfo_basic_free_application(app_info);
1163 return PMINFO_R_ERROR;
1167 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1169 LOGE("memory alloc failed");
1170 pkgmgrinfo_basic_free_application(app_info);
1171 return PMINFO_R_ERROR;
1175 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1177 LOGE("memory alloc failed");
1178 pkgmgrinfo_basic_free_application(app_info);
1179 return PMINFO_R_ERROR;
1183 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1185 LOGE("memory alloc failed");
1186 pkgmgrinfo_basic_free_application(app_info);
1187 return PMINFO_R_ERROR;
1191 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1193 LOGE("memory alloc failed");
1194 pkgmgrinfo_basic_free_application(app_info);
1195 return PMINFO_R_ERROR;
1198 *application = app_info;
1203 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1204 pkgmgrinfo_appinfo_h *clone)
1206 pkgmgr_appinfo_x *info;
1207 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1210 return PMINFO_R_EINVAL;
1212 info = calloc(1, sizeof(pkgmgr_appinfo_x));
1214 LOGE("memory alloc failed");
1215 return PMINFO_R_ERROR;
1218 if (temp->package != NULL)
1219 info->package = strdup(temp->package);
1220 if (temp->locale != NULL)
1221 info->locale = strdup(temp->locale);
1223 info->app_component = temp->app_component;
1225 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1226 LOGE("appinfo copy failed");
1228 free((void *)info->package);
1232 return PMINFO_R_ERROR;
1240 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1241 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1247 pkgmgr_appinfo_x info;
1249 GHashTableIter iter;
1252 locale = _get_system_locale();
1254 return PMINFO_R_ERROR;
1256 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1257 __free_applications);
1260 return PMINFO_R_ERROR;
1263 ret = _appinfo_get_applications(uid, uid, locale, filter,
1264 flag | PMINFO_APPINFO_GET_BASICINFO, list);
1265 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1266 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1267 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1269 if (ret != PMINFO_R_OK) {
1270 g_hash_table_destroy(list);
1275 g_hash_table_iter_init(&iter, list);
1276 while (g_hash_table_iter_next(&iter, NULL, &value)) {
1277 app = (application_x *)value;
1278 info.app_info = app;
1279 info.locale = locale;
1280 info.package = app->package;
1281 if (app_list_cb(&info, user_data) < 0)
1284 g_hash_table_destroy(list);
1290 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1292 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1293 pkgmgrinfo_app_component component,
1294 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1297 pkgmgrinfo_appinfo_filter_h filter;
1299 const char *comp_str = NULL;
1301 if (handle == NULL || app_func == NULL) {
1302 LOGE("invalid parameter");
1303 return PMINFO_R_EINVAL;
1306 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1307 LOGE("invalid parameter");
1308 return PMINFO_R_EINVAL;
1311 if (pkgmgrinfo_appinfo_filter_create(&filter))
1312 return PMINFO_R_ERROR;
1314 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1315 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1316 pkgmgrinfo_appinfo_filter_destroy(filter);
1317 return PMINFO_R_ERROR;
1320 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1321 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1322 pkgmgrinfo_appinfo_filter_destroy(filter);
1323 return PMINFO_R_ERROR;
1326 comp_str = __appcomponent_str(component);
1329 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1330 PMINFO_APPINFO_PROP_APP_COMPONENT,
1332 pkgmgrinfo_appinfo_filter_destroy(filter);
1333 return PMINFO_R_ERROR;
1337 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1338 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1340 pkgmgrinfo_appinfo_filter_destroy(filter);
1345 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1346 pkgmgrinfo_app_component component,
1347 pkgmgrinfo_app_list_cb app_func, void *user_data)
1349 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1352 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1353 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1357 pkgmgrinfo_appinfo_filter_h filter;
1359 if (app_func == NULL) {
1360 LOGE("invalid parameter");
1361 return PMINFO_R_EINVAL;
1364 if (pkgmgrinfo_appinfo_filter_create(&filter))
1365 return PMINFO_R_ERROR;
1367 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1368 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1369 pkgmgrinfo_appinfo_filter_destroy(filter);
1370 return PMINFO_R_ERROR;
1373 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1374 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1375 pkgmgrinfo_appinfo_filter_destroy(filter);
1376 return PMINFO_R_ERROR;
1379 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1380 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1381 pkgmgrinfo_appinfo_filter_destroy(filter);
1382 return PMINFO_R_ERROR;
1385 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1388 pkgmgrinfo_appinfo_filter_destroy(filter);
1393 API int pkgmgrinfo_appinfo_get_installed_list_full(
1394 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1396 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1397 _getuid(), flag, user_data);
1400 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1401 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1404 pkgmgrinfo_appinfo_filter_h filter;
1406 if (app_func == NULL) {
1407 LOGE("invalid parameter");
1408 return PMINFO_R_EINVAL;
1411 /* create an empty filter */
1412 ret = pkgmgrinfo_appinfo_filter_create(&filter);
1413 if (ret != PMINFO_R_OK)
1416 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1417 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1418 pkgmgrinfo_appinfo_filter_destroy(filter);
1419 return PMINFO_R_ERROR;
1422 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1423 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1424 pkgmgrinfo_appinfo_filter_destroy(filter);
1425 return PMINFO_R_ERROR;
1428 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1429 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1431 pkgmgrinfo_appinfo_filter_destroy(filter);
1436 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1439 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1443 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1445 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1447 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1448 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1450 if (info->app_info == NULL || info->app_info->appid == NULL)
1451 return PMINFO_R_ERROR;
1452 *appid = (char *)info->app_info->appid;
1457 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1459 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1461 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1462 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1464 if (info->package == NULL)
1465 return PMINFO_R_ERROR;
1467 *pkg_name = (char *)info->package;
1472 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1474 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1476 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1477 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1479 if (info->package == NULL)
1480 return PMINFO_R_ERROR;
1482 *pkgid = (char *)info->package;
1487 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1489 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1490 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1491 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1493 *pkgtype = (char *)info->app_info->package_type;
1498 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1500 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1502 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1503 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1505 if (info->app_info == NULL || info->app_info->exec == NULL)
1506 return PMINFO_R_ERROR;
1507 *exec = (char *)info->app_info->exec;
1513 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1516 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1518 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1519 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1521 if (info->app_info == NULL)
1522 return PMINFO_R_ERROR;
1524 if (info->app_info->icon == NULL) {
1529 ptr = (icon_x *)info->app_info->icon->data;
1531 return PMINFO_R_ERROR;
1533 if (ptr->text == NULL)
1534 return PMINFO_R_ERROR;
1542 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1545 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1550 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1551 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1553 if (info->app_info == NULL)
1554 return PMINFO_R_ERROR;
1556 locale = info->locale;
1558 locale = DEFAULT_LOCALE;
1560 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1561 ptr = (label_x *)tmp->data;
1562 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
1573 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1574 ptr = (label_x *)tmp->data;
1575 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
1581 *label = lbl ? lbl : "";
1586 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1588 char *result = NULL;
1590 sqlite3_stmt *stmt = NULL;
1595 parser_db = getUserPkgParserDBPathUID(uid);
1596 if (parser_db == NULL) {
1597 _LOGE("Failed to get parser db path");
1601 if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1602 _LOGE("DB open fail\n");
1608 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1609 if (query == NULL) {
1610 _LOGE("Out of memory");
1614 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1615 _LOGE("prepare_v2 fail\n");
1619 if (sqlite3_step(stmt) == SQLITE_ROW) {
1620 val = (char *)sqlite3_column_text(stmt, 0);
1622 result = strdup(val);
1626 sqlite3_finalize(stmt);
1627 sqlite3_free(query);
1633 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1637 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1639 val = _get_localed_label(appid, locale, uid);
1641 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1644 val = _get_localed_label(appid, locale, GLOBAL_USER);
1646 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1650 return PMINFO_R_ERROR;
1657 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1659 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1662 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1664 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1665 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1666 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1668 GList *list_md = NULL;
1669 metadata_x *metadata = NULL;
1670 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1672 list_md = info->app_info->metadata;
1674 for (; list_md; list_md = list_md->next) {
1675 metadata = (metadata_x *)list_md->data;
1676 if (metadata && metadata->key) {
1677 if (strcasecmp(metadata->key, metadata_key) == 0) {
1678 if (metadata->value == NULL)
1679 *metadata_value = "";
1681 *metadata_value = (char *)metadata->value;
1687 return PMINFO_R_EINVAL;
1690 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1692 if (strcasecmp(comp, "uiapp") == 0)
1693 return PMINFO_UI_APP;
1694 else if (strcasecmp(comp, "svcapp") == 0)
1695 return PMINFO_SVC_APP;
1696 else if (strcasecmp(comp, "widgetapp") == 0)
1697 return PMINFO_WIDGET_APP;
1698 else if (strcasecmp(comp, "watchapp") == 0)
1699 return PMINFO_WATCH_APP;
1704 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1709 case PMINFO_SVC_APP:
1711 case PMINFO_WIDGET_APP:
1713 case PMINFO_WATCH_APP:
1720 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1722 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1725 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1726 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1728 if (info->app_info == NULL)
1729 return PMINFO_R_ERROR;
1731 comp = __appcomponent_convert(info->app_info->component);
1733 return PMINFO_R_ERROR;
1740 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1742 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1744 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1745 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1747 if (info->app_info == NULL || info->app_info->type == NULL)
1748 return PMINFO_R_ERROR;
1749 *app_type = (char *)info->app_info->type;
1754 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1755 int *operation_count, char ***operation)
1757 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1758 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1759 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1760 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1761 *operation_count = data->operation_count;
1762 *operation = data->operation;
1766 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1767 int *uri_count, char ***uri)
1769 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1770 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1771 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1772 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1773 *uri_count = data->uri_count;
1778 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1779 int *mime_count, char ***mime)
1781 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1782 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1783 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1784 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1785 *mime_count = data->mime_count;
1790 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1791 int *subapp_count, char ***subapp)
1793 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1794 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1795 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1796 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1797 *subapp_count = data->subapp_count;
1798 *subapp = data->subapp;
1802 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1807 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1809 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1810 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1812 if (info->app_info == NULL)
1813 return PMINFO_R_ERROR;
1815 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1816 ptr = (icon_x *)tmp->data;
1817 if (ptr == NULL || ptr->section == NULL)
1820 val = (char *)ptr->section;
1821 if (val && strcmp(val, "notification") == 0) {
1822 *icon = (char *)ptr->text;
1827 return PMINFO_R_ERROR;
1830 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1833 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1835 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1836 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1838 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1839 return PMINFO_R_ERROR;
1841 val = (char *)info->app_info->recentimage;
1842 if (strcasecmp(val, "capture") == 0)
1843 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1844 else if (strcasecmp(val, "icon") == 0)
1845 *type = PMINFO_RECENTIMAGE_USE_ICON;
1847 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1852 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1857 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1859 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1860 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1862 if (info->app_info == NULL)
1863 return PMINFO_R_ERROR;
1865 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1866 ptr = (image_x *)tmp->data;
1867 if (ptr == NULL || ptr->section == NULL)
1870 val = (char *)ptr->section;
1871 if (val && strcmp(val, "preview") == 0) {
1872 *preview_img = (char *)ptr->text;
1877 return PMINFO_R_ERROR;
1880 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1883 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1885 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1886 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1888 val = info->app_info->permission_type;
1890 return PMINFO_R_ERROR;
1892 if (strcmp(val, "signature") == 0)
1893 *permission = PMINFO_PERMISSION_SIGNATURE;
1894 else if (strcmp(val, "privilege") == 0)
1895 *permission = PMINFO_PERMISSION_PRIVILEGE;
1897 *permission = PMINFO_PERMISSION_NORMAL;
1902 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1904 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1906 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1907 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1909 if (info->app_info == NULL || info->app_info->component_type == NULL)
1910 return PMINFO_R_ERROR;
1912 *component_type = (char *)info->app_info->component_type;
1917 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1920 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1922 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1923 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1925 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1926 return PMINFO_R_ERROR;
1928 val = (char *)info->app_info->hwacceleration;
1929 if (strcasecmp(val, "off") == 0)
1930 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1931 else if (strcasecmp(val, "on") == 0)
1932 *hwacceleration = PMINFO_HWACCELERATION_ON;
1934 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1939 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1942 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1944 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1945 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1947 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1948 return PMINFO_R_ERROR;
1950 val = (char *)info->app_info->screenreader;
1951 if (strcasecmp(val, "screenreader-off") == 0)
1952 *screenreader = PMINFO_SCREENREADER_OFF;
1953 else if (strcasecmp(val, "screenreader-on") == 0)
1954 *screenreader = PMINFO_SCREENREADER_ON;
1956 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1961 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1963 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1965 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1966 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1967 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1969 if (info->app_info == NULL)
1970 return PMINFO_R_ERROR;
1972 if (info->app_info->portraitimg == NULL)
1975 *portrait_img = (char *)info->app_info->portraitimg;
1977 if (info->app_info->landscapeimg == NULL)
1978 *landscape_img = "";
1980 *landscape_img = (char *)info->app_info->landscapeimg;
1985 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1987 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1989 if (handle == NULL || effectimage_type == NULL) {
1990 LOGE("invalid parameter");
1991 return PMINFO_R_EINVAL;
1994 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1995 return PMINFO_R_ERROR;
1997 *effectimage_type = (char *)info->app_info->effectimage_type;
2002 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
2004 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2006 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2007 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2009 if (info->app_info == NULL)
2010 return PMINFO_R_ERROR;
2012 if (info->app_info->submode_mainid == NULL)
2013 *submode_mainid = "";
2015 *submode_mainid = (char *)info->app_info->submode_mainid;
2020 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2022 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2023 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2025 if (info->app_info && info->app_info->installed_storage) {
2026 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2027 *storage = PMINFO_INTERNAL_STORAGE;
2028 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2029 *storage = PMINFO_EXTERNAL_STORAGE;
2031 return PMINFO_R_ERROR;
2033 return PMINFO_R_ERROR;
2039 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2041 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2043 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2044 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2046 if (info->app_info->launch_mode == NULL)
2047 return PMINFO_R_ERROR;
2049 *mode = (char *)(info->app_info->launch_mode);
2054 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2056 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2058 if (handle == NULL || alias_appid == NULL) {
2059 LOGE("invalid parameter");
2060 return PMINFO_R_EINVAL;
2063 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2064 return PMINFO_R_ERROR;
2066 *alias_appid = (char *)info->app_info->alias_appid;
2071 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2073 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2075 if (handle == NULL || effective_appid == NULL) {
2076 LOGE("invalid parameter");
2077 return PMINFO_R_EINVAL;
2080 if (info->app_info == NULL)
2081 return PMINFO_R_ERROR;
2083 if (info->app_info->effective_appid == NULL)
2084 *effective_appid = "";
2086 *effective_appid = (char *)info->app_info->effective_appid;
2091 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2093 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2095 if (handle == NULL || tep_name == NULL) {
2096 LOGE("invalid parameter");
2097 return PMINFO_R_EINVAL;
2100 if (info->app_info == NULL)
2101 return PMINFO_R_ERROR;
2103 if (info->app_info->tep_name == NULL)
2106 *tep_name = (char *)info->app_info->tep_name;
2111 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2113 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2115 if (handle == NULL || zip_mount_file == NULL) {
2116 LOGE("invalid parameter");
2117 return PMINFO_R_EINVAL;
2120 if (info->app_info == NULL)
2121 return PMINFO_R_ERROR;
2123 if (info->app_info->zip_mount_file == NULL)
2124 *zip_mount_file = "";
2126 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2131 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2133 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2135 if (handle == NULL || root_path == NULL) {
2136 LOGE("invalid parameter");
2137 return PMINFO_R_EINVAL;
2140 if (info->app_info == NULL || info->app_info->root_path == NULL)
2141 return PMINFO_R_ERROR;
2143 *root_path = (char *)info->app_info->root_path;
2148 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2150 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2152 if (handle == NULL || api_version == NULL) {
2153 LOGE("invalid parameter");
2154 return PMINFO_R_EINVAL;
2157 if (info->app_info == NULL || info->app_info->api_version == NULL)
2158 return PMINFO_R_ERROR;
2160 *api_version = (char *)info->app_info->api_version;
2165 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2167 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2169 if (handle == NULL || installed_time == NULL) {
2170 LOGE("invalid parameter");
2171 return PMINFO_R_EINVAL;
2174 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2175 return PMINFO_R_ERROR;
2177 *installed_time = atoi(info->app_info->package_installed_time);
2182 static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
2183 const char *type, char **appid, char **access)
2185 static const char query[] =
2186 "SELECT app_id, access FROM package_app_data_control "
2187 "WHERE providerid=? AND type=?";
2191 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2192 if (ret != SQLITE_OK) {
2193 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2194 return PMINFO_R_ERROR;
2197 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2198 if (ret != SQLITE_OK) {
2199 LOGE("bind failed: %s", sqlite3_errmsg(db));
2200 sqlite3_finalize(stmt);
2201 return PMINFO_R_ERROR;
2204 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2205 if (ret != SQLITE_OK) {
2206 LOGE("bind failed: %s", sqlite3_errmsg(db));
2207 sqlite3_finalize(stmt);
2208 return PMINFO_R_ERROR;
2211 ret = sqlite3_step(stmt);
2212 if (ret != SQLITE_ROW) {
2213 sqlite3_finalize(stmt);
2214 if (ret == SQLITE_DONE) {
2215 return PMINFO_R_ENOENT;
2217 LOGE("step error: %s", sqlite3_errmsg(db));
2218 return PMINFO_R_ERROR;
2222 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2223 if (*appid == NULL) {
2224 LOGE("out of memory");
2225 sqlite3_finalize(stmt);
2226 return PMINFO_R_ERROR;
2228 *access = strdup((char *)sqlite3_column_text(stmt, 1));
2229 if (*access == NULL) {
2230 LOGE("out of memory");
2232 sqlite3_finalize(stmt);
2233 return PMINFO_R_ERROR;
2236 sqlite3_finalize(stmt);
2241 static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
2242 const char *providerid, const char *type,
2243 char **appid, char **access)
2249 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2251 return PMINFO_R_ERROR;
2253 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2255 if (ret != SQLITE_OK) {
2256 LOGE("open db failed: %s", sqlite3_errmsg(db));
2257 return PMINFO_R_ERROR;
2260 ret = _appinfo_get_datacontrol_info(db, providerid, type, appid,
2262 sqlite3_close_v2(db);
2267 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2268 const char *type, uid_t uid, char **appid, char **access)
2272 if (providerid == NULL || type == NULL || appid == NULL ||
2274 LOGE("invalid parameter");
2275 return PMINFO_R_EINVAL;
2278 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
2279 type, appid, access);
2280 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2281 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
2282 type, appid, access);
2284 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2285 * implementation, return PMINFO_R_ERROR. This should be
2288 if (ret == PMINFO_R_ENOENT) {
2289 LOGE("no datacontrol info of %s", providerid);
2290 ret = PMINFO_R_ERROR;
2296 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2297 const char *type, char **appid, char **access)
2299 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2300 type, _getuid(), appid, access);
2303 static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
2306 static const char query[] =
2307 "SELECT app_id FROM package_app_data_control "
2308 "WHERE providerid=?";
2312 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2313 if (ret != SQLITE_OK) {
2314 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2315 return PMINFO_R_ERROR;
2318 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2319 if (ret != SQLITE_OK) {
2320 LOGE("bind failed: %s", sqlite3_errmsg(db));
2321 sqlite3_finalize(stmt);
2322 return PMINFO_R_ERROR;
2325 ret = sqlite3_step(stmt);
2326 if (ret != SQLITE_ROW) {
2327 sqlite3_finalize(stmt);
2328 if (ret == SQLITE_DONE) {
2329 return PMINFO_R_ENOENT;
2331 LOGE("step error: %s", sqlite3_errmsg(db));
2332 return PMINFO_R_ERROR;
2336 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2338 sqlite3_finalize(stmt);
2340 if (*appid == NULL) {
2341 LOGE("out of memory");
2342 return PMINFO_R_ERROR;
2348 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
2349 const char *providerid, char **appid)
2355 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2357 return PMINFO_R_ERROR;
2359 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2361 if (ret != SQLITE_OK) {
2362 LOGE("open db failed: %s", sqlite3_errmsg(db));
2363 return PMINFO_R_ERROR;
2366 ret = _appinfo_get_datacontrol_appid(db, providerid, appid);
2367 sqlite3_close_v2(db);
2372 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
2373 uid_t uid, char **appid)
2377 if (providerid == NULL || appid == NULL) {
2378 LOGE("invalid parameter");
2379 return PMINFO_R_EINVAL;
2382 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
2384 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2385 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
2388 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2389 * implementation, return PMINFO_R_ERROR. This should be
2392 if (ret == PMINFO_R_ENOENT) {
2393 LOGE("no datacontrol appid of %s", providerid);
2394 ret = PMINFO_R_ERROR;
2400 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2402 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2405 static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
2406 const char *providerid, const char *type, char **appid,
2409 static const char query[] =
2410 "SELECT app_id, trusted FROM package_app_data_control "
2411 "WHERE providerid=? AND type=?";
2415 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2416 if (ret != SQLITE_OK) {
2417 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2418 return PMINFO_R_ERROR;
2421 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2422 if (ret != SQLITE_OK) {
2423 LOGE("bind failed: %s", sqlite3_errmsg(db));
2424 sqlite3_finalize(stmt);
2425 return PMINFO_R_ERROR;
2428 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2429 if (ret != SQLITE_OK) {
2430 LOGE("bind failed: %s", sqlite3_errmsg(db));
2431 sqlite3_finalize(stmt);
2432 return PMINFO_R_ERROR;
2435 ret = sqlite3_step(stmt);
2436 if (ret != SQLITE_ROW) {
2437 sqlite3_finalize(stmt);
2438 if (ret == SQLITE_DONE) {
2439 return PMINFO_R_ENOENT;
2441 LOGE("step error: %s", sqlite3_errmsg(db));
2442 return PMINFO_R_ERROR;
2446 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2447 *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2449 sqlite3_finalize(stmt);
2451 if (*appid == NULL) {
2452 LOGE("out of memory");
2453 return PMINFO_R_ERROR;
2459 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
2460 const char *providerid, const char *type, char **appid,
2467 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2469 return PMINFO_R_ERROR;
2471 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2473 if (ret != SQLITE_OK) {
2474 LOGE("open db failed: %s", sqlite3_errmsg(db));
2475 return PMINFO_R_ERROR;
2478 ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid,
2480 sqlite3_close_v2(db);
2485 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
2486 const char *providerid, const char *type, uid_t uid,
2487 char **appid, bool *is_trusted)
2491 if (providerid == NULL || type == NULL || appid == NULL ||
2492 is_trusted == NULL) {
2493 LOGE("invalid parameter");
2494 return PMINFO_R_EINVAL;
2497 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
2498 providerid, type, appid, is_trusted);
2499 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2500 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
2501 providerid, type, appid, is_trusted);
2503 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2504 * implementation, return PMINFO_R_ERROR. This should be
2507 if (ret == PMINFO_R_ENOENT) {
2508 LOGE("no datacontrol trusted info of %s", providerid);
2509 ret = PMINFO_R_ERROR;
2515 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2516 const char *type, char **appid, bool *is_trusted)
2518 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2519 type, _getuid(), appid, is_trusted);
2522 static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
2523 const char *providerid, const char *type,
2524 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2526 static const char query[] =
2527 "SELECT privilege FROM package_app_data_control_privilege "
2528 "WHERE providerid=? AND type=?";
2533 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2534 if (ret != SQLITE_OK) {
2535 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2536 return PMINFO_R_ERROR;
2539 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2540 if (ret != SQLITE_OK) {
2541 LOGE("bind failed: %s", sqlite3_errmsg(db));
2542 sqlite3_finalize(stmt);
2543 return PMINFO_R_ERROR;
2546 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2547 if (ret != SQLITE_OK) {
2548 LOGE("bind failed: %s", sqlite3_errmsg(db));
2549 sqlite3_finalize(stmt);
2550 return PMINFO_R_ERROR;
2553 while (sqlite3_step(stmt) == SQLITE_ROW) {
2555 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2561 sqlite3_finalize(stmt);
2563 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2566 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
2567 const char *providerid, const char *type,
2568 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2574 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2576 return PMINFO_R_ERROR;
2578 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2580 if (ret != SQLITE_OK) {
2581 LOGE("open db failed: %s", sqlite3_errmsg(db));
2582 return PMINFO_R_ERROR;
2585 ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
2586 callback, user_data);
2587 sqlite3_close_v2(db);
2592 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2593 const char *providerid, const char *type,
2594 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2595 void *user_data, uid_t uid)
2599 if (providerid == NULL || type == NULL || privilege_func == NULL) {
2600 LOGE("invalid parameter");
2601 return PMINFO_R_EINVAL;
2604 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
2605 providerid, type, privilege_func, user_data);
2606 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2607 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
2608 providerid, type, privilege_func, user_data);
2610 if (ret == PMINFO_R_ENOENT)
2616 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
2617 const char *providerid, const char *type,
2618 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2621 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2622 providerid, type, privilege_func, user_data, _getuid());
2625 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
2627 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2628 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2630 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2631 if (info->app_info->support_mode)
2632 *support_mode = atoi(info->app_info->support_mode);
2639 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2640 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2643 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2645 const char *category;
2647 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2649 if (info->app_info == NULL)
2650 return PMINFO_R_ERROR;
2652 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2653 category = (const char *)tmp->data;
2655 ret = category_func(category, user_data);
2663 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2664 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2666 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2667 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2671 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2673 if (info->app_info == NULL)
2674 return PMINFO_R_ERROR;
2676 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2677 ptr = (metadata_x *)tmp->data;
2681 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2689 static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
2690 const char *appid, const char *app_control,
2691 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2693 static const char query[] =
2694 "SELECT privilege FROM package_app_app_control_privilege "
2695 "WHERE app_id=? AND app_control=?";
2700 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2701 if (ret != SQLITE_OK) {
2702 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2703 return PMINFO_R_ERROR;
2706 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_STATIC);
2707 if (ret != SQLITE_OK) {
2708 LOGE("bind failed: %s", sqlite3_errmsg(db));
2709 sqlite3_finalize(stmt);
2710 return PMINFO_R_ERROR;
2713 ret = sqlite3_bind_text(stmt, 2, app_control, -1, SQLITE_STATIC);
2714 if (ret != SQLITE_OK) {
2715 LOGE("bind failed: %s", sqlite3_errmsg(db));
2716 sqlite3_finalize(stmt);
2717 return PMINFO_R_ERROR;
2720 while (sqlite3_step(stmt) == SQLITE_ROW) {
2722 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2728 sqlite3_finalize(stmt);
2730 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2733 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
2734 const char *appid, const char *app_control,
2735 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2741 dbpath = getUserPkgParserDBPathUID(uid);
2743 return PMINFO_R_ERROR;
2745 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2747 if (ret != SQLITE_OK) {
2748 LOGE("open db failed: %s", sqlite3_errmsg(db));
2749 return PMINFO_R_ERROR;
2752 ret = _appinfo_foreach_appcontrol_privileges(db, appid, app_control,
2753 callback, user_data);
2754 sqlite3_close_v2(db);
2759 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
2760 const char *operation, const char *uri, const char *mime,
2761 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2762 void *user_data, uid_t uid)
2765 char app_control[BUFSIZE];
2767 if (appid == NULL || operation == NULL || privilege_func == NULL) {
2768 LOGE("invalid parameter");
2769 return PMINFO_R_EINVAL;
2772 snprintf(app_control, sizeof(app_control), "%s|%s|%s", operation,
2773 uri ? uri : "NULL", mime ? mime : "NULL");
2775 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
2776 appid, app_control, privilege_func, user_data);
2777 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2778 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
2779 appid, app_control, privilege_func, user_data);
2781 if (ret == PMINFO_R_ENOENT)
2787 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
2788 const char *operation, const char *uri, const char *mime,
2789 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2792 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
2793 operation, uri, mime, privilege_func, user_data,
2797 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2798 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2800 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2801 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2803 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2804 appcontrol_x *appcontrol;
2807 if (info->app_info == NULL)
2808 return PMINFO_R_ERROR;
2810 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2811 appcontrol = (appcontrol_x *)tmp->data;
2812 if (appcontrol == NULL)
2814 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2822 API int pkgmgrinfo_appinfo_foreach_background_category(
2823 pkgmgrinfo_appinfo_h handle,
2824 pkgmgrinfo_app_background_category_list_cb category_func,
2827 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2831 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2832 LOGE("invalid parameter");
2833 return PMINFO_R_EINVAL;
2836 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2837 category = (char *)tmp->data;
2838 if (category == NULL)
2841 if (category_func(category, user_data) < 0)
2848 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2849 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2852 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2853 splashscreen_x *splashscreen;
2857 if (info == NULL || info->app_info == NULL
2858 || splash_screen_func == NULL) {
2859 LOGE("invalid parameter");
2860 return PMINFO_R_EINVAL;
2863 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2864 splashscreen = (splashscreen_x *)tmp->data;
2865 if (splashscreen == NULL)
2867 ret = splash_screen_func(splashscreen->src,
2869 splashscreen->orientation,
2870 splashscreen->indicatordisplay,
2871 splashscreen->operation,
2872 splashscreen->color_depth,
2881 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2883 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2884 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2885 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2887 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2888 return PMINFO_R_ERROR;
2890 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2895 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2897 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2898 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2899 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2901 if (info->app_info == NULL || info->app_info->multiple == NULL)
2902 return PMINFO_R_ERROR;
2904 *multiple = _get_bool_value(info->app_info->multiple);
2909 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2911 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2912 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2913 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2915 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2916 return PMINFO_R_ERROR;
2918 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2923 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2926 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2927 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2929 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2930 return PMINFO_R_ERROR;
2932 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2937 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2939 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2940 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2941 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2943 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2944 return PMINFO_R_ERROR;
2946 *enabled = !_get_bool_value(info->app_info->is_disabled);
2951 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2953 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2954 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2955 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2957 if (info->app_info == NULL || info->app_info->onboot == NULL)
2958 return PMINFO_R_ERROR;
2960 *onboot = _get_bool_value(info->app_info->onboot);
2965 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
2967 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2968 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2969 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2971 if (info->app_info == NULL || info->app_info->autorestart == NULL)
2972 return PMINFO_R_ERROR;
2974 *autorestart = _get_bool_value(info->app_info->autorestart);
2979 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
2981 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2982 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2983 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2985 if (info->app_info == NULL || info->app_info->mainapp == NULL)
2986 return PMINFO_R_ERROR;
2988 *mainapp = _get_bool_value(info->app_info->mainapp);
2993 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2995 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2996 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2997 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2999 if (info->app_info == NULL || info->app_info->preload == NULL)
3000 return PMINFO_R_ERROR;
3002 *preload = _get_bool_value(info->app_info->preload);
3007 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
3009 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3010 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3011 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3013 if (info->app_info == NULL || info->app_info->submode == NULL)
3014 return PMINFO_R_ERROR;
3016 *submode = _get_bool_value(info->app_info->submode);
3021 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
3023 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3025 if (handle == NULL || process_pool == NULL) {
3026 LOGE("invalid parameter");
3027 return PMINFO_R_EINVAL;
3030 if (info->app_info == NULL)
3031 return PMINFO_R_ERROR;
3033 *process_pool = _get_bool_value(info->app_info->process_pool);
3038 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
3040 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3041 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
3042 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
3046 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3048 if (info->app_info == NULL)
3049 return PMINFO_R_ERROR;
3052 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
3053 val = (const char *)tmp->data;
3056 if (strcasecmp(val, category) == 0) {
3065 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
3068 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3070 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
3071 _LOGE("invalid parameter");
3072 return PMINFO_R_EINVAL;
3074 if (info->app_info->ui_gadget == NULL)
3075 info->app_info->ui_gadget = strdup("false");
3077 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
3082 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
3083 bool *support_disable)
3085 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3087 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
3088 _LOGE("invalid parameter");
3089 return PMINFO_R_EINVAL;
3092 *support_disable = _get_bool_value(info->app_info->support_disable);
3097 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
3100 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3102 if (info == NULL || info->app_info == NULL || removable == NULL) {
3103 _LOGE("invalid parameter");
3104 return PMINFO_R_EINVAL;
3107 *removable = _get_bool_value(info->app_info->removable);
3112 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
3114 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3116 if (info == NULL || info->app_info == NULL || system == NULL) {
3117 _LOGE("invalid parameter");
3118 return PMINFO_R_EINVAL;
3121 *system = _get_bool_value(info->app_info->package_system);
3126 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
3128 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3129 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3130 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3132 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
3133 return PMINFO_R_ERROR;
3135 *disabled = _get_bool_value(info->app_info->is_disabled);
3140 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
3142 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3144 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3145 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3147 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
3148 return PMINFO_R_ERROR;
3150 *global = _get_bool_value(info->app_info->for_all_users);
3155 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
3157 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3159 if (info == NULL || splash_screen_display == NULL) {
3160 _LOGE("Invalid parameter");
3161 return PMINFO_R_EINVAL;
3164 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
3165 return PMINFO_R_ERROR;
3167 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
3172 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
3174 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3176 if (info == NULL || setup_appid == NULL) {
3177 _LOGE("Invalid parameter");
3178 return PMINFO_R_EINVAL;
3181 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
3182 return PMINFO_R_ERROR;
3184 *setup_appid = info->app_info->setup_appid;
3188 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
3189 bool *support_ambient)
3191 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3193 if (info == NULL || support_ambient == NULL) {
3194 _LOGE("Invalid parameter");
3195 return PMINFO_R_EINVAL;
3198 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
3199 return PMINFO_R_ERROR;
3201 *support_ambient = _get_bool_value(info->app_info->support_ambient);
3206 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
3208 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3209 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3210 __cleanup_appinfo(info);
3214 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
3216 return (pkgmgrinfo_pkginfo_filter_create(handle));
3219 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
3221 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3224 static gint __compare_func(gconstpointer data1, gconstpointer data2)
3226 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
3227 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
3228 if (node1->prop == node2->prop)
3230 else if (node1->prop > node2->prop)
3236 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
3237 const char *property, const int value)
3239 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3240 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3241 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3243 GSList *link = NULL;
3245 prop = _pminfo_appinfo_convert_to_prop_int(property);
3246 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
3247 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
3248 _LOGE("Invalid Integer Property\n");
3249 return PMINFO_R_EINVAL;
3251 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3252 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3254 _LOGE("Out of Memory!!!\n");
3255 return PMINFO_R_ERROR;
3257 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3258 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3260 _LOGE("Out of Memory\n");
3263 return PMINFO_R_ERROR;
3267 /*If API is called multiple times for same property, we should override the previous values.
3268 Last value set will be used for filtering.*/
3269 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3271 filter->list = g_slist_delete_link(filter->list, link);
3272 filter->list = g_slist_append(filter->list, (gpointer)node);
3277 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
3278 const char *property, const bool 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");
3283 GSList *link = NULL;
3285 prop = _pminfo_appinfo_convert_to_prop_bool(property);
3286 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
3287 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
3288 _LOGE("Invalid Boolean Property\n");
3289 return PMINFO_R_EINVAL;
3291 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3292 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3294 _LOGE("Out of Memory!!!\n");
3295 return PMINFO_R_ERROR;
3298 val = strndup("true", 4);
3300 val = strndup("false", 5);
3302 _LOGE("Out of Memory\n");
3305 return PMINFO_R_ERROR;
3309 /*If API is called multiple times for same property, we should override the previous values.
3310 Last value set will be used for filtering.*/
3311 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3313 filter->list = g_slist_delete_link(filter->list, link);
3314 filter->list = g_slist_append(filter->list, (gpointer)node);
3319 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
3320 const char *property, const char *value)
3322 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3323 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3324 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3326 pkgmgrinfo_node_x *ptr = NULL;
3327 char prev[PKG_STRING_LEN_MAX] = {'\0'};
3328 char temp[PKG_STRING_LEN_MAX] = {'\0'};
3329 GSList *link = NULL;
3331 prop = _pminfo_appinfo_convert_to_prop_str(property);
3332 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
3333 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
3334 _LOGE("Invalid String Property\n");
3335 return PMINFO_R_EINVAL;
3337 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3338 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3340 _LOGE("Out of Memory!!!\n");
3341 return PMINFO_R_ERROR;
3345 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
3346 node->value = strdup(value);
3347 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3349 filter->list = g_slist_delete_link(filter->list, link);
3350 filter->list = g_slist_append(filter->list, (gpointer)node);
3352 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
3353 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
3355 _LOGE("Out of Memory\n");
3358 return PMINFO_R_ERROR;
3360 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3362 ptr = (pkgmgrinfo_node_x *)link->data;
3363 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
3364 _LOGI("Previous value is %s\n", prev);
3365 filter->list = g_slist_delete_link(filter->list, link);
3366 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
3367 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3368 _LOGI("New value is %s\n", val);
3370 filter->list = g_slist_append(filter->list, (gpointer)node);
3371 memset(temp, '\0', PKG_STRING_LEN_MAX);
3373 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3374 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3375 _LOGI("First value is %s\n", val);
3377 filter->list = g_slist_append(filter->list, (gpointer)node);
3378 memset(temp, '\0', PKG_STRING_LEN_MAX);
3382 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3383 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3385 filter->list = g_slist_delete_link(filter->list, link);
3386 filter->list = g_slist_append(filter->list, (gpointer)node);
3392 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3398 if (handle == NULL || count == NULL) {
3399 _LOGE("invalid parameter");
3400 return PMINFO_R_EINVAL;
3403 locale = _get_system_locale();
3405 return PMINFO_R_ERROR;
3407 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3408 __free_applications);
3411 return PMINFO_R_ERROR;
3414 if (__check_disable_filter_exist(
3415 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3416 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3417 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
3418 g_hash_table_destroy(list);
3420 return PMINFO_R_ERROR;
3424 if (__check_disable_filter_exist(
3425 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3426 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3427 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
3428 g_hash_table_destroy(list);
3430 return PMINFO_R_ERROR;
3434 ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3435 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3436 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3439 if (ret != PMINFO_R_OK) {
3440 g_hash_table_destroy(list);
3442 return PMINFO_R_ERROR;
3445 *count = g_hash_table_size(list);
3446 g_hash_table_destroy(list);
3452 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3454 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3457 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3458 pkgmgrinfo_appinfo_filter_h handle,
3459 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3461 if (handle == NULL || app_cb == NULL) {
3462 LOGE("invalid parameter");
3463 return PMINFO_R_EINVAL;
3466 if (__check_disable_filter_exist(
3467 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3468 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3469 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3470 return PMINFO_R_ERROR;
3473 if (__check_disable_filter_exist(
3474 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3475 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3476 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3477 return PMINFO_R_ERROR;
3480 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3484 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3485 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3487 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3490 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3492 return (pkgmgrinfo_pkginfo_filter_create(handle));
3495 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3497 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3500 API int pkgmgrinfo_appinfo_metadata_filter_add(
3501 pkgmgrinfo_appinfo_metadata_filter_h handle,
3502 const char *key, const char *value)
3504 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3505 pkgmgrinfo_metadata_node_x *node;
3507 /* value can be NULL.
3508 * In that case all apps with specified key should be displayed
3511 LOGE("invalid parameter");
3512 return PMINFO_R_EINVAL;
3515 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3517 LOGE("out of memory");
3518 return PMINFO_R_ERROR;
3521 node->key = strdup(key);
3522 if (value && strlen(value))
3523 node->value = strdup(value);
3525 filter->list_metadata = g_slist_append(filter->list_metadata,
3531 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3532 pkgmgrinfo_appinfo_metadata_filter_h handle,
3533 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3535 if (handle == NULL || app_cb == NULL) {
3536 LOGE("invalid parameter");
3537 return PMINFO_R_EINVAL;
3540 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3541 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3542 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3543 return PMINFO_R_ERROR;
3545 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3546 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3547 return PMINFO_R_ERROR;
3549 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3553 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3554 pkgmgrinfo_appinfo_metadata_filter_h handle,
3555 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3557 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3558 user_data, _getuid());
3561 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3564 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3566 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3567 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3569 val = info->app_info->guestmode_visibility;
3570 *status = _get_bool_value(val);