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(g_str_hash, g_str_equal);
727 return PMINFO_R_ERROR;
730 ret = _appinfo_get_applications(uid, uid, locale, filter,
731 PMINFO_APPINFO_GET_ALL, list);
732 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
733 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
734 PMINFO_APPINFO_GET_ALL, list);
736 if (!g_hash_table_size(list)) {
737 _LOGD("appinfo for [%s] is not existed for user [%d]",
739 g_hash_table_destroy(list);
741 return PMINFO_R_ENOENT;
744 info = calloc(1, sizeof(pkgmgr_appinfo_x));
746 _LOGE("out of memory");
747 g_hash_table_destroy(list);
749 return PMINFO_R_ERROR;
752 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
753 info->locale = locale;
754 info->package = strdup(info->app_info->package);
756 /* just free list only */
757 g_hash_table_destroy(list);
764 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
765 pkgmgrinfo_appinfo_h *handle)
768 pkgmgrinfo_appinfo_filter_h filter;
770 if (appid == NULL || handle == NULL) {
771 LOGE("invalid parameter");
772 return PMINFO_R_EINVAL;
775 ret = pkgmgrinfo_appinfo_filter_create(&filter);
776 if (ret != PMINFO_R_OK)
779 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
780 PMINFO_APPINFO_PROP_APP_ID, appid);
781 if (ret != PMINFO_R_OK) {
782 pkgmgrinfo_appinfo_filter_destroy(filter);
783 return PMINFO_R_ERROR;
786 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
787 PMINFO_APPINFO_PROP_APP_DISABLE, true);
788 if (ret != PMINFO_R_OK) {
789 pkgmgrinfo_appinfo_filter_destroy(filter);
790 return PMINFO_R_ERROR;
793 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
794 pkgmgrinfo_appinfo_filter_destroy(filter);
799 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
801 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
804 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
805 pkgmgrinfo_appinfo_h *handle)
808 pkgmgrinfo_appinfo_filter_h filter;
810 if (appid == NULL || handle == NULL) {
811 LOGE("invalid parameter");
812 return PMINFO_R_EINVAL;
815 ret = pkgmgrinfo_appinfo_filter_create(&filter);
816 if (ret != PMINFO_R_OK)
819 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
820 PMINFO_APPINFO_PROP_APP_ID, appid);
821 if (ret != PMINFO_R_OK) {
822 pkgmgrinfo_appinfo_filter_destroy(filter);
823 return PMINFO_R_ERROR;
826 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
827 PMINFO_APPINFO_PROP_APP_DISABLE, false);
828 if (ret != PMINFO_R_OK) {
829 pkgmgrinfo_appinfo_filter_destroy(filter);
830 return PMINFO_R_ERROR;
833 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
834 PMINFO_APPINFO_PROP_PKG_DISABLE, false);
835 if (ret != PMINFO_R_OK) {
836 pkgmgrinfo_appinfo_filter_destroy(filter);
837 return PMINFO_R_ERROR;
840 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
841 pkgmgrinfo_appinfo_filter_destroy(filter);
845 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
847 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
850 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
851 pkgmgrinfo_appinfo_h *handle)
854 pkgmgrinfo_appinfo_filter_h filter;
856 if (appid == NULL || handle == NULL) {
857 LOGE("invalid parameter");
858 return PMINFO_R_EINVAL;
861 ret = pkgmgrinfo_appinfo_filter_create(&filter);
862 if (ret != PMINFO_R_OK)
865 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
866 PMINFO_APPINFO_PROP_APP_ID, appid);
867 if (ret != PMINFO_R_OK) {
868 pkgmgrinfo_appinfo_filter_destroy(filter);
869 return PMINFO_R_ERROR;
872 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
873 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
874 if (ret != PMINFO_R_OK) {
875 pkgmgrinfo_appinfo_filter_destroy(filter);
876 return PMINFO_R_ERROR;
879 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
880 pkgmgrinfo_appinfo_filter_destroy(filter);
885 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
887 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
890 static gpointer __copy_str(gconstpointer src, gpointer data)
892 const char *tmp = (const char *)src;
895 buffer = strdup(tmp);
896 if (buffer == NULL) {
897 LOGE("memory alloc failed");
905 static gpointer __copy_label(gconstpointer src, gpointer data)
907 label_x *tmp = (label_x *)src;
910 label = calloc(1, sizeof(label_x));
912 LOGE("memory alloc failed");
918 label->name = strdup(tmp->name);
920 label->text = strdup(tmp->text);
922 label->lang = strdup(tmp->lang);
927 static gpointer __copy_icon(gconstpointer src, gpointer data)
929 icon_x *tmp = (icon_x *)src;
932 icon = calloc(1, sizeof(icon_x));
934 LOGE("memory alloc failed");
940 icon->text = strdup(tmp->text);
942 icon->lang = strdup(tmp->lang);
944 icon->section = strdup(tmp->section);
946 icon->size = strdup(tmp->size);
948 icon->resolution = strdup(tmp->resolution);
953 static gpointer __copy_metadata(gconstpointer src, gpointer data)
955 metadata_x *tmp = (metadata_x *)src;
956 metadata_x *metadata;
958 metadata = calloc(1, sizeof(metadata_x));
959 if (metadata == NULL) {
960 LOGE("memory alloc failed");
966 metadata->key = strdup(tmp->key);
968 metadata->value = strdup(tmp->value);
973 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
975 datacontrol_x *tmp = (datacontrol_x *)src;
976 datacontrol_x *datacontrol;
978 datacontrol = calloc(1, sizeof(datacontrol_x));
979 if (datacontrol == NULL) {
980 LOGE("memory alloc failed");
986 datacontrol->providerid = strdup(tmp->providerid);
988 datacontrol->access = strdup(tmp->access);
990 datacontrol->type = strdup(tmp->type);
992 datacontrol->trusted = strdup(tmp->trusted);
997 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
999 appcontrol_x *tmp = (appcontrol_x *)src;
1000 appcontrol_x *appcontrol;
1002 appcontrol = calloc(1, sizeof(appcontrol_x));
1003 if (appcontrol == NULL) {
1004 LOGE("memory alloc failed");
1010 appcontrol->operation = strdup(tmp->operation);
1012 appcontrol->uri = strdup(tmp->uri);
1014 appcontrol->mime = strdup(tmp->mime);
1019 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1021 splashscreen_x *tmp = (splashscreen_x *)src;
1022 splashscreen_x *splashscreen;
1024 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1025 if (splashscreen == NULL) {
1026 LOGE("memory alloc failed");
1032 splashscreen->src = strdup(tmp->src);
1034 splashscreen->type = strdup(tmp->type);
1035 if (tmp->orientation)
1036 splashscreen->orientation = strdup(tmp->orientation);
1037 if (tmp->indicatordisplay)
1038 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1040 splashscreen->operation = strdup(tmp->operation);
1041 if (tmp->color_depth)
1042 splashscreen->color_depth = strdup(tmp->color_depth);
1044 return splashscreen;
1047 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1049 application_x *app_info;
1052 app_info = calloc(1, sizeof(application_x));
1053 if (app_info == NULL) {
1054 LOGE("memory alloc failed");
1055 return PMINFO_R_ERROR;
1058 if (data->appid != NULL)
1059 app_info->appid = strdup(data->appid);
1060 if (data->exec != NULL)
1061 app_info->exec = strdup(data->exec);
1062 if (data->nodisplay != NULL)
1063 app_info->nodisplay = strdup(data->nodisplay);
1064 if (data->multiple != NULL)
1065 app_info->multiple = strdup(data->multiple);
1066 if (data->taskmanage != NULL)
1067 app_info->taskmanage = strdup(data->taskmanage);
1068 if (data->type != NULL)
1069 app_info->type = strdup(data->type);
1070 if (data->categories != NULL)
1071 app_info->categories = strdup(data->categories);
1072 if (data->hwacceleration != NULL)
1073 app_info->hwacceleration = strdup(data->hwacceleration);
1074 if (data->screenreader != NULL)
1075 app_info->screenreader = strdup(data->screenreader);
1076 if (data->mainapp != NULL)
1077 app_info->mainapp = strdup(data->mainapp);
1078 if (data->package != NULL)
1079 app_info->package = strdup(data->package);
1080 if (data->recentimage != NULL)
1081 app_info->recentimage = strdup(data->recentimage);
1082 if (data->launchcondition != NULL)
1083 app_info->launchcondition = strdup(data->launchcondition);
1084 if (data->indicatordisplay != NULL)
1085 app_info->indicatordisplay = strdup(data->indicatordisplay);
1086 if (data->portraitimg != NULL)
1087 app_info->portraitimg = strdup(data->portraitimg);
1088 if (data->landscapeimg != NULL)
1089 app_info->landscapeimg = strdup(data->landscapeimg);
1090 if (data->guestmode_visibility != NULL)
1091 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1092 if (data->component != NULL)
1093 app_info->component = strdup(data->component);
1094 if (data->permission_type != NULL)
1095 app_info->permission_type = strdup(data->permission_type);
1096 if (data->component_type != NULL)
1097 app_info->component_type = strdup(data->component_type);
1098 if (data->preload != NULL)
1099 app_info->preload = strdup(data->preload);
1100 if (data->submode != NULL)
1101 app_info->submode = strdup(data->submode);
1102 if (data->submode_mainid != NULL)
1103 app_info->submode_mainid = strdup(data->submode_mainid);
1104 if (data->process_pool != NULL)
1105 app_info->process_pool = strdup(data->process_pool);
1106 if (data->installed_storage != NULL)
1107 app_info->installed_storage = strdup(data->installed_storage);
1108 if (data->autorestart != NULL)
1109 app_info->autorestart = strdup(data->autorestart);
1110 if (data->onboot != NULL)
1111 app_info->onboot = strdup(data->onboot);
1112 if (data->support_disable != NULL)
1113 app_info->support_disable = strdup(data->support_disable);
1114 if (data->ui_gadget != NULL)
1115 app_info->ui_gadget = strdup(data->ui_gadget);
1116 if (data->launch_mode != NULL)
1117 app_info->launch_mode = strdup(data->launch_mode);
1118 if (data->package_type != NULL)
1119 app_info->package_type = strdup(data->package_type);
1120 if (data->effective_appid != NULL)
1121 app_info->effective_appid = strdup(data->effective_appid);
1122 if (data->splash_screen_display != NULL)
1123 app_info->splash_screen_display = strdup(data->splash_screen_display);
1127 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1129 LOGE("memory alloc failed");
1130 pkgmgrinfo_basic_free_application(app_info);
1131 return PMINFO_R_ERROR;
1135 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1137 LOGE("memory alloc failed");
1138 pkgmgrinfo_basic_free_application(app_info);
1139 return PMINFO_R_ERROR;
1143 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1145 LOGE("memory alloc failed");
1146 pkgmgrinfo_basic_free_application(app_info);
1147 return PMINFO_R_ERROR;
1151 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1153 LOGE("memory alloc failed");
1154 pkgmgrinfo_basic_free_application(app_info);
1155 return PMINFO_R_ERROR;
1159 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1161 LOGE("memory alloc failed");
1162 pkgmgrinfo_basic_free_application(app_info);
1163 return PMINFO_R_ERROR;
1167 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1169 LOGE("memory alloc failed");
1170 pkgmgrinfo_basic_free_application(app_info);
1171 return PMINFO_R_ERROR;
1175 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1177 LOGE("memory alloc failed");
1178 pkgmgrinfo_basic_free_application(app_info);
1179 return PMINFO_R_ERROR;
1183 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1185 LOGE("memory alloc failed");
1186 pkgmgrinfo_basic_free_application(app_info);
1187 return PMINFO_R_ERROR;
1190 *application = app_info;
1195 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1196 pkgmgrinfo_appinfo_h *clone)
1198 pkgmgr_appinfo_x *info;
1199 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1202 return PMINFO_R_EINVAL;
1204 info = calloc(1, sizeof(pkgmgr_appinfo_x));
1206 LOGE("memory alloc failed");
1207 return PMINFO_R_ERROR;
1210 if (temp->package != NULL)
1211 info->package = strdup(temp->package);
1212 if (temp->locale != NULL)
1213 info->locale = strdup(temp->locale);
1215 info->app_component = temp->app_component;
1217 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1218 LOGE("appinfo copy failed");
1220 free((void *)info->package);
1224 return PMINFO_R_ERROR;
1232 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1233 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1239 pkgmgr_appinfo_x info;
1241 GHashTableIter iter;
1244 locale = _get_system_locale();
1246 return PMINFO_R_ERROR;
1248 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1249 __free_applications);
1252 return PMINFO_R_ERROR;
1255 ret = _appinfo_get_applications(uid, uid, locale, filter,
1256 flag | PMINFO_APPINFO_GET_BASICINFO, list);
1257 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1258 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1259 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1261 if (ret != PMINFO_R_OK) {
1262 g_hash_table_destroy(list);
1267 g_hash_table_iter_init(&iter, list);
1268 while (g_hash_table_iter_next(&iter, NULL, &value)) {
1269 app = (application_x *)value;
1270 info.app_info = app;
1271 info.locale = locale;
1272 info.package = app->package;
1273 if (app_list_cb(&info, user_data) < 0)
1276 g_hash_table_destroy(list);
1282 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1284 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1285 pkgmgrinfo_app_component component,
1286 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1289 pkgmgrinfo_appinfo_filter_h filter;
1291 const char *comp_str = NULL;
1293 if (handle == NULL || app_func == NULL) {
1294 LOGE("invalid parameter");
1295 return PMINFO_R_EINVAL;
1298 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1299 LOGE("invalid parameter");
1300 return PMINFO_R_EINVAL;
1303 if (pkgmgrinfo_appinfo_filter_create(&filter))
1304 return PMINFO_R_ERROR;
1306 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1307 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1308 pkgmgrinfo_appinfo_filter_destroy(filter);
1309 return PMINFO_R_ERROR;
1312 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1313 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1314 pkgmgrinfo_appinfo_filter_destroy(filter);
1315 return PMINFO_R_ERROR;
1318 comp_str = __appcomponent_str(component);
1321 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1322 PMINFO_APPINFO_PROP_APP_COMPONENT,
1324 pkgmgrinfo_appinfo_filter_destroy(filter);
1325 return PMINFO_R_ERROR;
1329 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1330 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1332 pkgmgrinfo_appinfo_filter_destroy(filter);
1337 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1338 pkgmgrinfo_app_component component,
1339 pkgmgrinfo_app_list_cb app_func, void *user_data)
1341 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1344 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1345 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1349 pkgmgrinfo_appinfo_filter_h filter;
1351 if (app_func == NULL) {
1352 LOGE("invalid parameter");
1353 return PMINFO_R_EINVAL;
1356 if (pkgmgrinfo_appinfo_filter_create(&filter))
1357 return PMINFO_R_ERROR;
1359 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1360 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1361 pkgmgrinfo_appinfo_filter_destroy(filter);
1362 return PMINFO_R_ERROR;
1365 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1366 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1367 pkgmgrinfo_appinfo_filter_destroy(filter);
1368 return PMINFO_R_ERROR;
1371 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1372 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1373 pkgmgrinfo_appinfo_filter_destroy(filter);
1374 return PMINFO_R_ERROR;
1377 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1380 pkgmgrinfo_appinfo_filter_destroy(filter);
1385 API int pkgmgrinfo_appinfo_get_installed_list_full(
1386 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1388 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1389 _getuid(), flag, user_data);
1392 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1393 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1396 pkgmgrinfo_appinfo_filter_h filter;
1398 if (app_func == NULL) {
1399 LOGE("invalid parameter");
1400 return PMINFO_R_EINVAL;
1403 /* create an empty filter */
1404 ret = pkgmgrinfo_appinfo_filter_create(&filter);
1405 if (ret != PMINFO_R_OK)
1408 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1409 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1410 pkgmgrinfo_appinfo_filter_destroy(filter);
1411 return PMINFO_R_ERROR;
1414 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1415 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1416 pkgmgrinfo_appinfo_filter_destroy(filter);
1417 return PMINFO_R_ERROR;
1420 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1421 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1423 pkgmgrinfo_appinfo_filter_destroy(filter);
1428 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1431 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1435 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1437 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1439 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1440 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1442 if (info->app_info == NULL || info->app_info->appid == NULL)
1443 return PMINFO_R_ERROR;
1444 *appid = (char *)info->app_info->appid;
1449 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1451 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1453 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1454 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1456 if (info->package == NULL)
1457 return PMINFO_R_ERROR;
1459 *pkg_name = (char *)info->package;
1464 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1466 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1468 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1469 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1471 if (info->package == NULL)
1472 return PMINFO_R_ERROR;
1474 *pkgid = (char *)info->package;
1479 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1481 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1482 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1483 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1485 *pkgtype = (char *)info->app_info->package_type;
1490 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1492 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1495 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1497 if (info->app_info == NULL || info->app_info->exec == NULL)
1498 return PMINFO_R_ERROR;
1499 *exec = (char *)info->app_info->exec;
1505 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1508 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1510 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1511 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1513 if (info->app_info == NULL)
1514 return PMINFO_R_ERROR;
1516 if (info->app_info->icon == NULL) {
1521 ptr = (icon_x *)info->app_info->icon->data;
1523 return PMINFO_R_ERROR;
1525 if (ptr->text == NULL)
1526 return PMINFO_R_ERROR;
1534 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1537 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1543 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1545 if (info->app_info == NULL)
1546 return PMINFO_R_ERROR;
1548 locale = info->locale;
1550 locale = DEFAULT_LOCALE;
1552 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1553 ptr = (label_x *)tmp->data;
1554 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
1565 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1566 ptr = (label_x *)tmp->data;
1567 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
1573 *label = lbl ? lbl : "";
1578 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1580 char *result = NULL;
1582 sqlite3_stmt *stmt = NULL;
1587 parser_db = getUserPkgParserDBPathUID(uid);
1588 if (parser_db == NULL) {
1589 _LOGE("Failed to get parser db path");
1593 if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1594 _LOGE("DB open fail\n");
1600 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1601 if (query == NULL) {
1602 _LOGE("Out of memory");
1606 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1607 _LOGE("prepare_v2 fail\n");
1611 if (sqlite3_step(stmt) == SQLITE_ROW) {
1612 val = (char *)sqlite3_column_text(stmt, 0);
1614 result = strdup(val);
1618 sqlite3_finalize(stmt);
1619 sqlite3_free(query);
1625 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1629 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1631 val = _get_localed_label(appid, locale, uid);
1633 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1636 val = _get_localed_label(appid, locale, GLOBAL_USER);
1638 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1642 return PMINFO_R_ERROR;
1649 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1651 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1654 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1656 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1657 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1658 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1660 GList *list_md = NULL;
1661 metadata_x *metadata = NULL;
1662 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1664 list_md = info->app_info->metadata;
1666 for (; list_md; list_md = list_md->next) {
1667 metadata = (metadata_x *)list_md->data;
1668 if (metadata && metadata->key) {
1669 if (strcasecmp(metadata->key, metadata_key) == 0) {
1670 if (metadata->value == NULL)
1671 *metadata_value = "";
1673 *metadata_value = (char *)metadata->value;
1679 return PMINFO_R_EINVAL;
1682 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1684 if (strcasecmp(comp, "uiapp") == 0)
1685 return PMINFO_UI_APP;
1686 else if (strcasecmp(comp, "svcapp") == 0)
1687 return PMINFO_SVC_APP;
1688 else if (strcasecmp(comp, "widgetapp") == 0)
1689 return PMINFO_WIDGET_APP;
1690 else if (strcasecmp(comp, "watchapp") == 0)
1691 return PMINFO_WATCH_APP;
1696 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1701 case PMINFO_SVC_APP:
1703 case PMINFO_WIDGET_APP:
1705 case PMINFO_WATCH_APP:
1712 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1714 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1717 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1718 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1720 if (info->app_info == NULL)
1721 return PMINFO_R_ERROR;
1723 comp = __appcomponent_convert(info->app_info->component);
1725 return PMINFO_R_ERROR;
1732 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1734 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1736 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1737 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1739 if (info->app_info == NULL || info->app_info->type == NULL)
1740 return PMINFO_R_ERROR;
1741 *app_type = (char *)info->app_info->type;
1746 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1747 int *operation_count, char ***operation)
1749 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1750 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1751 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1752 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1753 *operation_count = data->operation_count;
1754 *operation = data->operation;
1758 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1759 int *uri_count, char ***uri)
1761 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1762 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1763 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1764 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1765 *uri_count = data->uri_count;
1770 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1771 int *mime_count, char ***mime)
1773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1774 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1775 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1776 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1777 *mime_count = data->mime_count;
1782 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1783 int *subapp_count, char ***subapp)
1785 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1786 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1787 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1788 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1789 *subapp_count = data->subapp_count;
1790 *subapp = data->subapp;
1794 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1799 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1801 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1802 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1804 if (info->app_info == NULL)
1805 return PMINFO_R_ERROR;
1807 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1808 ptr = (icon_x *)tmp->data;
1809 if (ptr == NULL || ptr->section == NULL)
1812 val = (char *)ptr->section;
1813 if (val && strcmp(val, "notification") == 0) {
1814 *icon = (char *)ptr->text;
1819 return PMINFO_R_ERROR;
1822 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1825 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1827 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1828 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1830 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1831 return PMINFO_R_ERROR;
1833 val = (char *)info->app_info->recentimage;
1834 if (strcasecmp(val, "capture") == 0)
1835 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1836 else if (strcasecmp(val, "icon") == 0)
1837 *type = PMINFO_RECENTIMAGE_USE_ICON;
1839 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1844 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1849 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1851 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1852 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1854 if (info->app_info == NULL)
1855 return PMINFO_R_ERROR;
1857 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1858 ptr = (image_x *)tmp->data;
1859 if (ptr == NULL || ptr->section == NULL)
1862 val = (char *)ptr->section;
1863 if (val && strcmp(val, "preview") == 0) {
1864 *preview_img = (char *)ptr->text;
1869 return PMINFO_R_ERROR;
1872 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1875 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1877 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1878 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1880 val = info->app_info->permission_type;
1882 return PMINFO_R_ERROR;
1884 if (strcmp(val, "signature") == 0)
1885 *permission = PMINFO_PERMISSION_SIGNATURE;
1886 else if (strcmp(val, "privilege") == 0)
1887 *permission = PMINFO_PERMISSION_PRIVILEGE;
1889 *permission = PMINFO_PERMISSION_NORMAL;
1894 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1896 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1898 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1899 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1901 if (info->app_info == NULL || info->app_info->component_type == NULL)
1902 return PMINFO_R_ERROR;
1904 *component_type = (char *)info->app_info->component_type;
1909 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1912 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1914 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1915 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1917 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1918 return PMINFO_R_ERROR;
1920 val = (char *)info->app_info->hwacceleration;
1921 if (strcasecmp(val, "off") == 0)
1922 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1923 else if (strcasecmp(val, "on") == 0)
1924 *hwacceleration = PMINFO_HWACCELERATION_ON;
1926 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1931 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1934 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1936 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1937 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1939 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1940 return PMINFO_R_ERROR;
1942 val = (char *)info->app_info->screenreader;
1943 if (strcasecmp(val, "screenreader-off") == 0)
1944 *screenreader = PMINFO_SCREENREADER_OFF;
1945 else if (strcasecmp(val, "screenreader-on") == 0)
1946 *screenreader = PMINFO_SCREENREADER_ON;
1948 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1953 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1955 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1957 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1958 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1959 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1961 if (info->app_info == NULL)
1962 return PMINFO_R_ERROR;
1964 if (info->app_info->portraitimg == NULL)
1967 *portrait_img = (char *)info->app_info->portraitimg;
1969 if (info->app_info->landscapeimg == NULL)
1970 *landscape_img = "";
1972 *landscape_img = (char *)info->app_info->landscapeimg;
1977 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1979 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1981 if (handle == NULL || effectimage_type == NULL) {
1982 LOGE("invalid parameter");
1983 return PMINFO_R_EINVAL;
1986 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1987 return PMINFO_R_ERROR;
1989 *effectimage_type = (char *)info->app_info->effectimage_type;
1994 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1996 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1998 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1999 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2001 if (info->app_info == NULL)
2002 return PMINFO_R_ERROR;
2004 if (info->app_info->submode_mainid == NULL)
2005 *submode_mainid = "";
2007 *submode_mainid = (char *)info->app_info->submode_mainid;
2012 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2015 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2017 if (info->app_info && info->app_info->installed_storage) {
2018 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2019 *storage = PMINFO_INTERNAL_STORAGE;
2020 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2021 *storage = PMINFO_EXTERNAL_STORAGE;
2023 return PMINFO_R_ERROR;
2025 return PMINFO_R_ERROR;
2031 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2033 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2035 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2036 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2038 if (info->app_info->launch_mode == NULL)
2039 return PMINFO_R_ERROR;
2041 *mode = (char *)(info->app_info->launch_mode);
2046 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2048 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2050 if (handle == NULL || alias_appid == NULL) {
2051 LOGE("invalid parameter");
2052 return PMINFO_R_EINVAL;
2055 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2056 return PMINFO_R_ERROR;
2058 *alias_appid = (char *)info->app_info->alias_appid;
2063 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2065 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2067 if (handle == NULL || effective_appid == NULL) {
2068 LOGE("invalid parameter");
2069 return PMINFO_R_EINVAL;
2072 if (info->app_info == NULL)
2073 return PMINFO_R_ERROR;
2075 if (info->app_info->effective_appid == NULL)
2076 *effective_appid = "";
2078 *effective_appid = (char *)info->app_info->effective_appid;
2083 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2085 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2087 if (handle == NULL || tep_name == NULL) {
2088 LOGE("invalid parameter");
2089 return PMINFO_R_EINVAL;
2092 if (info->app_info == NULL)
2093 return PMINFO_R_ERROR;
2095 if (info->app_info->tep_name == NULL)
2098 *tep_name = (char *)info->app_info->tep_name;
2103 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2105 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2107 if (handle == NULL || zip_mount_file == NULL) {
2108 LOGE("invalid parameter");
2109 return PMINFO_R_EINVAL;
2112 if (info->app_info == NULL)
2113 return PMINFO_R_ERROR;
2115 if (info->app_info->zip_mount_file == NULL)
2116 *zip_mount_file = "";
2118 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2123 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2125 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2127 if (handle == NULL || root_path == NULL) {
2128 LOGE("invalid parameter");
2129 return PMINFO_R_EINVAL;
2132 if (info->app_info == NULL || info->app_info->root_path == NULL)
2133 return PMINFO_R_ERROR;
2135 *root_path = (char *)info->app_info->root_path;
2140 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2142 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2144 if (handle == NULL || api_version == NULL) {
2145 LOGE("invalid parameter");
2146 return PMINFO_R_EINVAL;
2149 if (info->app_info == NULL || info->app_info->api_version == NULL)
2150 return PMINFO_R_ERROR;
2152 *api_version = (char *)info->app_info->api_version;
2157 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2159 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2161 if (handle == NULL || installed_time == NULL) {
2162 LOGE("invalid parameter");
2163 return PMINFO_R_EINVAL;
2166 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2167 return PMINFO_R_ERROR;
2169 *installed_time = atoi(info->app_info->package_installed_time);
2174 static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
2175 const char *type, char **appid, char **access)
2177 static const char query[] =
2178 "SELECT app_id, access FROM package_app_data_control "
2179 "WHERE providerid=? AND type=?";
2183 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2184 if (ret != SQLITE_OK) {
2185 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2186 return PMINFO_R_ERROR;
2189 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2190 if (ret != SQLITE_OK) {
2191 LOGE("bind failed: %s", sqlite3_errmsg(db));
2192 sqlite3_finalize(stmt);
2193 return PMINFO_R_ERROR;
2196 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2197 if (ret != SQLITE_OK) {
2198 LOGE("bind failed: %s", sqlite3_errmsg(db));
2199 sqlite3_finalize(stmt);
2200 return PMINFO_R_ERROR;
2203 ret = sqlite3_step(stmt);
2204 if (ret != SQLITE_ROW) {
2205 sqlite3_finalize(stmt);
2206 if (ret == SQLITE_DONE) {
2207 return PMINFO_R_ENOENT;
2209 LOGE("step error: %s", sqlite3_errmsg(db));
2210 return PMINFO_R_ERROR;
2214 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2215 if (*appid == NULL) {
2216 LOGE("out of memory");
2217 sqlite3_finalize(stmt);
2218 return PMINFO_R_ERROR;
2220 *access = strdup((char *)sqlite3_column_text(stmt, 1));
2221 if (*access == NULL) {
2222 LOGE("out of memory");
2224 sqlite3_finalize(stmt);
2225 return PMINFO_R_ERROR;
2228 sqlite3_finalize(stmt);
2233 static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
2234 const char *providerid, const char *type,
2235 char **appid, char **access)
2241 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2243 return PMINFO_R_ERROR;
2245 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2247 if (ret != SQLITE_OK) {
2248 LOGE("open db failed: %s", sqlite3_errmsg(db));
2249 return PMINFO_R_ERROR;
2252 ret = _appinfo_get_datacontrol_info(db, providerid, type, appid,
2254 sqlite3_close_v2(db);
2259 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2260 const char *type, uid_t uid, char **appid, char **access)
2264 if (providerid == NULL || type == NULL || appid == NULL ||
2266 LOGE("invalid parameter");
2267 return PMINFO_R_EINVAL;
2270 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
2271 type, appid, access);
2272 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2273 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
2274 type, appid, access);
2276 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2277 * implementation, return PMINFO_R_ERROR. This should be
2280 if (ret == PMINFO_R_ENOENT) {
2281 LOGE("no datacontrol info of %s", providerid);
2282 ret = PMINFO_R_ERROR;
2288 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2289 const char *type, char **appid, char **access)
2291 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2292 type, _getuid(), appid, access);
2295 static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
2298 static const char query[] =
2299 "SELECT app_id FROM package_app_data_control "
2300 "WHERE providerid=?";
2304 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2305 if (ret != SQLITE_OK) {
2306 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2307 return PMINFO_R_ERROR;
2310 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2311 if (ret != SQLITE_OK) {
2312 LOGE("bind failed: %s", sqlite3_errmsg(db));
2313 sqlite3_finalize(stmt);
2314 return PMINFO_R_ERROR;
2317 ret = sqlite3_step(stmt);
2318 if (ret != SQLITE_ROW) {
2319 sqlite3_finalize(stmt);
2320 if (ret == SQLITE_DONE) {
2321 return PMINFO_R_ENOENT;
2323 LOGE("step error: %s", sqlite3_errmsg(db));
2324 return PMINFO_R_ERROR;
2328 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2330 sqlite3_finalize(stmt);
2332 if (*appid == NULL) {
2333 LOGE("out of memory");
2334 return PMINFO_R_ERROR;
2340 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
2341 const char *providerid, char **appid)
2347 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2349 return PMINFO_R_ERROR;
2351 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2353 if (ret != SQLITE_OK) {
2354 LOGE("open db failed: %s", sqlite3_errmsg(db));
2355 return PMINFO_R_ERROR;
2358 ret = _appinfo_get_datacontrol_appid(db, providerid, appid);
2359 sqlite3_close_v2(db);
2364 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
2365 uid_t uid, char **appid)
2369 if (providerid == NULL || appid == NULL) {
2370 LOGE("invalid parameter");
2371 return PMINFO_R_EINVAL;
2374 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
2376 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2377 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
2380 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2381 * implementation, return PMINFO_R_ERROR. This should be
2384 if (ret == PMINFO_R_ENOENT) {
2385 LOGE("no datacontrol appid of %s", providerid);
2386 ret = PMINFO_R_ERROR;
2392 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2394 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2397 static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
2398 const char *providerid, const char *type, char **appid,
2401 static const char query[] =
2402 "SELECT app_id, trusted FROM package_app_data_control "
2403 "WHERE providerid=? AND type=?";
2407 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2408 if (ret != SQLITE_OK) {
2409 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2410 return PMINFO_R_ERROR;
2413 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2414 if (ret != SQLITE_OK) {
2415 LOGE("bind failed: %s", sqlite3_errmsg(db));
2416 sqlite3_finalize(stmt);
2417 return PMINFO_R_ERROR;
2420 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2421 if (ret != SQLITE_OK) {
2422 LOGE("bind failed: %s", sqlite3_errmsg(db));
2423 sqlite3_finalize(stmt);
2424 return PMINFO_R_ERROR;
2427 ret = sqlite3_step(stmt);
2428 if (ret != SQLITE_ROW) {
2429 sqlite3_finalize(stmt);
2430 if (ret == SQLITE_DONE) {
2431 return PMINFO_R_ENOENT;
2433 LOGE("step error: %s", sqlite3_errmsg(db));
2434 return PMINFO_R_ERROR;
2438 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2439 *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2441 sqlite3_finalize(stmt);
2443 if (*appid == NULL) {
2444 LOGE("out of memory");
2445 return PMINFO_R_ERROR;
2451 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
2452 const char *providerid, const char *type, char **appid,
2459 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2461 return PMINFO_R_ERROR;
2463 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2465 if (ret != SQLITE_OK) {
2466 LOGE("open db failed: %s", sqlite3_errmsg(db));
2467 return PMINFO_R_ERROR;
2470 ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid,
2472 sqlite3_close_v2(db);
2477 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
2478 const char *providerid, const char *type, uid_t uid,
2479 char **appid, bool *is_trusted)
2483 if (providerid == NULL || type == NULL || appid == NULL ||
2484 is_trusted == NULL) {
2485 LOGE("invalid parameter");
2486 return PMINFO_R_EINVAL;
2489 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
2490 providerid, type, appid, is_trusted);
2491 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2492 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
2493 providerid, type, appid, is_trusted);
2495 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2496 * implementation, return PMINFO_R_ERROR. This should be
2499 if (ret == PMINFO_R_ENOENT) {
2500 LOGE("no datacontrol trusted info of %s", providerid);
2501 ret = PMINFO_R_ERROR;
2507 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2508 const char *type, char **appid, bool *is_trusted)
2510 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2511 type, _getuid(), appid, is_trusted);
2514 static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
2515 const char *providerid, const char *type,
2516 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2518 static const char query[] =
2519 "SELECT privilege FROM package_app_data_control_privilege "
2520 "WHERE providerid=? AND type=?";
2525 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2526 if (ret != SQLITE_OK) {
2527 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2528 return PMINFO_R_ERROR;
2531 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2532 if (ret != SQLITE_OK) {
2533 LOGE("bind failed: %s", sqlite3_errmsg(db));
2534 sqlite3_finalize(stmt);
2535 return PMINFO_R_ERROR;
2538 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2539 if (ret != SQLITE_OK) {
2540 LOGE("bind failed: %s", sqlite3_errmsg(db));
2541 sqlite3_finalize(stmt);
2542 return PMINFO_R_ERROR;
2545 while (sqlite3_step(stmt) == SQLITE_ROW) {
2547 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2553 sqlite3_finalize(stmt);
2555 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2558 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
2559 const char *providerid, const char *type,
2560 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2566 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2568 return PMINFO_R_ERROR;
2570 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2572 if (ret != SQLITE_OK) {
2573 LOGE("open db failed: %s", sqlite3_errmsg(db));
2574 return PMINFO_R_ERROR;
2577 ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
2578 callback, user_data);
2579 sqlite3_close_v2(db);
2584 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2585 const char *providerid, const char *type,
2586 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2587 void *user_data, uid_t uid)
2591 if (providerid == NULL || type == NULL || privilege_func == NULL) {
2592 LOGE("invalid parameter");
2593 return PMINFO_R_EINVAL;
2596 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
2597 providerid, type, privilege_func, user_data);
2598 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2599 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
2600 providerid, type, privilege_func, user_data);
2602 if (ret == PMINFO_R_ENOENT)
2608 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
2609 const char *providerid, const char *type,
2610 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2613 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2614 providerid, type, privilege_func, user_data, _getuid());
2617 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
2619 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2620 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2622 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2623 if (info->app_info->support_mode)
2624 *support_mode = atoi(info->app_info->support_mode);
2631 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2632 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2634 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2635 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2637 const char *category;
2639 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2641 if (info->app_info == NULL)
2642 return PMINFO_R_ERROR;
2644 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2645 category = (const char *)tmp->data;
2647 ret = category_func(category, user_data);
2655 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2656 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2658 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2659 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2663 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2665 if (info->app_info == NULL)
2666 return PMINFO_R_ERROR;
2668 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2669 ptr = (metadata_x *)tmp->data;
2673 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2681 static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
2682 const char *appid, const char *app_control,
2683 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2685 static const char query[] =
2686 "SELECT privilege FROM package_app_app_control_privilege "
2687 "WHERE app_id=? AND app_control=?";
2692 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2693 if (ret != SQLITE_OK) {
2694 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2695 return PMINFO_R_ERROR;
2698 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_STATIC);
2699 if (ret != SQLITE_OK) {
2700 LOGE("bind failed: %s", sqlite3_errmsg(db));
2701 sqlite3_finalize(stmt);
2702 return PMINFO_R_ERROR;
2705 ret = sqlite3_bind_text(stmt, 2, app_control, -1, SQLITE_STATIC);
2706 if (ret != SQLITE_OK) {
2707 LOGE("bind failed: %s", sqlite3_errmsg(db));
2708 sqlite3_finalize(stmt);
2709 return PMINFO_R_ERROR;
2712 while (sqlite3_step(stmt) == SQLITE_ROW) {
2714 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2720 sqlite3_finalize(stmt);
2722 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2725 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
2726 const char *appid, const char *app_control,
2727 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2733 dbpath = getUserPkgParserDBPathUID(uid);
2735 return PMINFO_R_ERROR;
2737 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2739 if (ret != SQLITE_OK) {
2740 LOGE("open db failed: %s", sqlite3_errmsg(db));
2741 return PMINFO_R_ERROR;
2744 ret = _appinfo_foreach_appcontrol_privileges(db, appid, app_control,
2745 callback, user_data);
2746 sqlite3_close_v2(db);
2751 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
2752 const char *operation, const char *uri, const char *mime,
2753 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2754 void *user_data, uid_t uid)
2757 char app_control[BUFSIZE];
2759 if (appid == NULL || operation == NULL || privilege_func == NULL) {
2760 LOGE("invalid parameter");
2761 return PMINFO_R_EINVAL;
2764 snprintf(app_control, sizeof(app_control), "%s|%s|%s", operation,
2765 uri ? uri : "NULL", mime ? mime : "NULL");
2767 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
2768 appid, app_control, privilege_func, user_data);
2769 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2770 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
2771 appid, app_control, privilege_func, user_data);
2773 if (ret == PMINFO_R_ENOENT)
2779 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
2780 const char *operation, const char *uri, const char *mime,
2781 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2784 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
2785 operation, uri, mime, privilege_func, user_data,
2789 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2790 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2792 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2793 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2795 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2796 appcontrol_x *appcontrol;
2799 if (info->app_info == NULL)
2800 return PMINFO_R_ERROR;
2802 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2803 appcontrol = (appcontrol_x *)tmp->data;
2804 if (appcontrol == NULL)
2806 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2814 API int pkgmgrinfo_appinfo_foreach_background_category(
2815 pkgmgrinfo_appinfo_h handle,
2816 pkgmgrinfo_app_background_category_list_cb category_func,
2819 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2823 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2824 LOGE("invalid parameter");
2825 return PMINFO_R_EINVAL;
2828 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2829 category = (char *)tmp->data;
2830 if (category == NULL)
2833 if (category_func(category, user_data) < 0)
2840 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2841 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2844 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2845 splashscreen_x *splashscreen;
2849 if (info == NULL || info->app_info == NULL
2850 || splash_screen_func == NULL) {
2851 LOGE("invalid parameter");
2852 return PMINFO_R_EINVAL;
2855 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2856 splashscreen = (splashscreen_x *)tmp->data;
2857 if (splashscreen == NULL)
2859 ret = splash_screen_func(splashscreen->src,
2861 splashscreen->orientation,
2862 splashscreen->indicatordisplay,
2863 splashscreen->operation,
2864 splashscreen->color_depth,
2873 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2875 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2876 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2877 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2879 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2880 return PMINFO_R_ERROR;
2882 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2887 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2889 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2890 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2891 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2893 if (info->app_info == NULL || info->app_info->multiple == NULL)
2894 return PMINFO_R_ERROR;
2896 *multiple = _get_bool_value(info->app_info->multiple);
2901 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2903 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2904 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2905 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2907 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2908 return PMINFO_R_ERROR;
2910 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2915 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2917 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2918 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2919 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2921 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2922 return PMINFO_R_ERROR;
2924 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2929 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2931 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2932 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2933 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2935 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2936 return PMINFO_R_ERROR;
2938 *enabled = !_get_bool_value(info->app_info->is_disabled);
2943 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2945 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2946 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2947 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2949 if (info->app_info == NULL || info->app_info->onboot == NULL)
2950 return PMINFO_R_ERROR;
2952 *onboot = _get_bool_value(info->app_info->onboot);
2957 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
2959 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2960 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2961 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2963 if (info->app_info == NULL || info->app_info->autorestart == NULL)
2964 return PMINFO_R_ERROR;
2966 *autorestart = _get_bool_value(info->app_info->autorestart);
2971 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
2973 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2974 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2975 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2977 if (info->app_info == NULL || info->app_info->mainapp == NULL)
2978 return PMINFO_R_ERROR;
2980 *mainapp = _get_bool_value(info->app_info->mainapp);
2985 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2987 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2988 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2989 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2991 if (info->app_info == NULL || info->app_info->preload == NULL)
2992 return PMINFO_R_ERROR;
2994 *preload = _get_bool_value(info->app_info->preload);
2999 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
3001 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3002 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3003 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3005 if (info->app_info == NULL || info->app_info->submode == NULL)
3006 return PMINFO_R_ERROR;
3008 *submode = _get_bool_value(info->app_info->submode);
3013 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
3015 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3017 if (handle == NULL || process_pool == NULL) {
3018 LOGE("invalid parameter");
3019 return PMINFO_R_EINVAL;
3022 if (info->app_info == NULL)
3023 return PMINFO_R_ERROR;
3025 *process_pool = _get_bool_value(info->app_info->process_pool);
3030 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
3032 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3033 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
3034 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
3038 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3040 if (info->app_info == NULL)
3041 return PMINFO_R_ERROR;
3044 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
3045 val = (const char *)tmp->data;
3048 if (strcasecmp(val, category) == 0) {
3057 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
3060 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3062 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
3063 _LOGE("invalid parameter");
3064 return PMINFO_R_EINVAL;
3066 if (info->app_info->ui_gadget == NULL)
3067 info->app_info->ui_gadget = strdup("false");
3069 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
3074 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
3075 bool *support_disable)
3077 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3079 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
3080 _LOGE("invalid parameter");
3081 return PMINFO_R_EINVAL;
3084 *support_disable = _get_bool_value(info->app_info->support_disable);
3089 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
3092 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3094 if (info == NULL || info->app_info == NULL || removable == NULL) {
3095 _LOGE("invalid parameter");
3096 return PMINFO_R_EINVAL;
3099 *removable = _get_bool_value(info->app_info->removable);
3104 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
3106 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3108 if (info == NULL || info->app_info == NULL || system == NULL) {
3109 _LOGE("invalid parameter");
3110 return PMINFO_R_EINVAL;
3113 *system = _get_bool_value(info->app_info->package_system);
3118 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
3120 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3121 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3122 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3124 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
3125 return PMINFO_R_ERROR;
3127 *disabled = _get_bool_value(info->app_info->is_disabled);
3132 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
3134 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3136 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3137 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3139 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
3140 return PMINFO_R_ERROR;
3142 *global = _get_bool_value(info->app_info->for_all_users);
3147 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
3149 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3151 if (info == NULL || splash_screen_display == NULL) {
3152 _LOGE("Invalid parameter");
3153 return PMINFO_R_EINVAL;
3156 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
3157 return PMINFO_R_ERROR;
3159 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
3164 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
3166 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3168 if (info == NULL || setup_appid == NULL) {
3169 _LOGE("Invalid parameter");
3170 return PMINFO_R_EINVAL;
3173 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
3174 return PMINFO_R_ERROR;
3176 *setup_appid = info->app_info->setup_appid;
3180 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
3181 bool *support_ambient)
3183 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3185 if (info == NULL || support_ambient == NULL) {
3186 _LOGE("Invalid parameter");
3187 return PMINFO_R_EINVAL;
3190 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
3191 return PMINFO_R_ERROR;
3193 *support_ambient = _get_bool_value(info->app_info->support_ambient);
3198 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
3200 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3201 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3202 __cleanup_appinfo(info);
3206 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
3208 return (pkgmgrinfo_pkginfo_filter_create(handle));
3211 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
3213 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3216 static gint __compare_func(gconstpointer data1, gconstpointer data2)
3218 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
3219 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
3220 if (node1->prop == node2->prop)
3222 else if (node1->prop > node2->prop)
3228 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
3229 const char *property, const int value)
3231 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3232 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3233 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3235 GSList *link = NULL;
3237 prop = _pminfo_appinfo_convert_to_prop_int(property);
3238 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
3239 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
3240 _LOGE("Invalid Integer Property\n");
3241 return PMINFO_R_EINVAL;
3243 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3244 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3246 _LOGE("Out of Memory!!!\n");
3247 return PMINFO_R_ERROR;
3249 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3250 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3252 _LOGE("Out of Memory\n");
3255 return PMINFO_R_ERROR;
3259 /*If API is called multiple times for same property, we should override the previous values.
3260 Last value set will be used for filtering.*/
3261 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3263 filter->list = g_slist_delete_link(filter->list, link);
3264 filter->list = g_slist_append(filter->list, (gpointer)node);
3269 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
3270 const char *property, const bool value)
3272 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3273 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3275 GSList *link = NULL;
3277 prop = _pminfo_appinfo_convert_to_prop_bool(property);
3278 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
3279 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
3280 _LOGE("Invalid Boolean Property\n");
3281 return PMINFO_R_EINVAL;
3283 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3284 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3286 _LOGE("Out of Memory!!!\n");
3287 return PMINFO_R_ERROR;
3290 val = strndup("true", 4);
3292 val = strndup("false", 5);
3294 _LOGE("Out of Memory\n");
3297 return PMINFO_R_ERROR;
3301 /*If API is called multiple times for same property, we should override the previous values.
3302 Last value set will be used for filtering.*/
3303 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3305 filter->list = g_slist_delete_link(filter->list, link);
3306 filter->list = g_slist_append(filter->list, (gpointer)node);
3311 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
3312 const char *property, const char *value)
3314 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3315 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3316 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3318 pkgmgrinfo_node_x *ptr = NULL;
3319 char prev[PKG_STRING_LEN_MAX] = {'\0'};
3320 char temp[PKG_STRING_LEN_MAX] = {'\0'};
3321 GSList *link = NULL;
3323 prop = _pminfo_appinfo_convert_to_prop_str(property);
3324 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
3325 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
3326 _LOGE("Invalid String Property\n");
3327 return PMINFO_R_EINVAL;
3329 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3330 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3332 _LOGE("Out of Memory!!!\n");
3333 return PMINFO_R_ERROR;
3337 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
3338 node->value = strdup(value);
3339 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3341 filter->list = g_slist_delete_link(filter->list, link);
3342 filter->list = g_slist_append(filter->list, (gpointer)node);
3344 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
3345 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
3347 _LOGE("Out of Memory\n");
3350 return PMINFO_R_ERROR;
3352 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3354 ptr = (pkgmgrinfo_node_x *)link->data;
3355 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
3356 _LOGI("Previous value is %s\n", prev);
3357 filter->list = g_slist_delete_link(filter->list, link);
3358 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
3359 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3360 _LOGI("New value is %s\n", val);
3362 filter->list = g_slist_append(filter->list, (gpointer)node);
3363 memset(temp, '\0', PKG_STRING_LEN_MAX);
3365 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3366 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3367 _LOGI("First value is %s\n", val);
3369 filter->list = g_slist_append(filter->list, (gpointer)node);
3370 memset(temp, '\0', PKG_STRING_LEN_MAX);
3374 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3375 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3377 filter->list = g_slist_delete_link(filter->list, link);
3378 filter->list = g_slist_append(filter->list, (gpointer)node);
3384 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3390 if (handle == NULL || count == NULL) {
3391 _LOGE("invalid parameter");
3392 return PMINFO_R_EINVAL;
3395 locale = _get_system_locale();
3397 return PMINFO_R_ERROR;
3399 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3400 __free_applications);
3403 return PMINFO_R_ERROR;
3406 if (__check_disable_filter_exist(
3407 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3408 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3409 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
3410 g_hash_table_destroy(list);
3412 return PMINFO_R_ERROR;
3416 if (__check_disable_filter_exist(
3417 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3418 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3419 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
3420 g_hash_table_destroy(list);
3422 return PMINFO_R_ERROR;
3426 ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3427 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3428 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3431 if (ret != PMINFO_R_OK) {
3432 g_hash_table_destroy(list);
3434 return PMINFO_R_ERROR;
3437 *count = g_hash_table_size(list);
3438 g_hash_table_destroy(list);
3444 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3446 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3449 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3450 pkgmgrinfo_appinfo_filter_h handle,
3451 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3453 if (handle == NULL || app_cb == NULL) {
3454 LOGE("invalid parameter");
3455 return PMINFO_R_EINVAL;
3458 if (__check_disable_filter_exist(
3459 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3460 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3461 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3462 return PMINFO_R_ERROR;
3465 if (__check_disable_filter_exist(
3466 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3467 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3468 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3469 return PMINFO_R_ERROR;
3472 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3476 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3477 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3479 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3482 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3484 return (pkgmgrinfo_pkginfo_filter_create(handle));
3487 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3489 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3492 API int pkgmgrinfo_appinfo_metadata_filter_add(
3493 pkgmgrinfo_appinfo_metadata_filter_h handle,
3494 const char *key, const char *value)
3496 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3497 pkgmgrinfo_metadata_node_x *node;
3499 /* value can be NULL.
3500 * In that case all apps with specified key should be displayed
3503 LOGE("invalid parameter");
3504 return PMINFO_R_EINVAL;
3507 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3509 LOGE("out of memory");
3510 return PMINFO_R_ERROR;
3513 node->key = strdup(key);
3514 if (value && strlen(value))
3515 node->value = strdup(value);
3517 filter->list_metadata = g_slist_append(filter->list_metadata,
3523 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3524 pkgmgrinfo_appinfo_metadata_filter_h handle,
3525 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3527 if (handle == NULL || app_cb == NULL) {
3528 LOGE("invalid parameter");
3529 return PMINFO_R_EINVAL;
3532 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3533 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3534 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3535 return PMINFO_R_ERROR;
3537 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3538 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3539 return PMINFO_R_ERROR;
3541 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3545 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3546 pkgmgrinfo_appinfo_metadata_filter_h handle,
3547 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3549 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3550 user_data, _getuid());
3553 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3556 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3558 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3559 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3561 val = info->app_info->guestmode_visibility;
3562 *status = _get_bool_value(val);