13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 static bool _get_bool_value(const char *str)
20 if (str && !strcmp(str, "true"))
26 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
28 pkgmgr_appinfo_x *info = data;
32 free((void *)info->package);
34 free((void *)info->locale);
36 pkgmgrinfo_basic_free_application(info->app_info);
42 static const char join_localized_info[] =
43 " LEFT OUTER JOIN package_app_localized_info"
44 " ON ai.app_id=package_app_localized_info.app_id"
45 " AND package_app_localized_info.app_locale=?";
46 static const char join_category[] =
47 " LEFT OUTER JOIN package_app_app_category"
48 " ON ai.app_id=package_app_app_category.app_id";
49 static const char join_app_control[] =
50 " LEFT OUTER JOIN package_app_app_control"
51 " ON ai.app_id=package_app_app_control.app_id";
52 static const char join_metadata[] =
53 " LEFT OUTER JOIN package_app_app_metadata"
54 " ON ai.app_id=package_app_app_metadata.app_id ";
56 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
57 const char *locale, uid_t uid, char **query, GList **bind_params)
60 char *condition = NULL;
61 char buf[MAX_QUERY_LEN] = { '\0' };
62 char tmp_query[MAX_QUERY_LEN] = { '\0' };
67 strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1);
69 for (list = filter->list; list; list = list->next) {
70 joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
71 if (condition == NULL)
74 strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
76 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
81 if (filter->list_metadata)
82 strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1);
83 for (list = filter->list_metadata; list; list = list->next) {
84 joined |= __get_metadata_filter_condition(list->data,
85 &condition, bind_params);
86 if (condition == NULL)
88 strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
92 strncat(buf, " OR ", sizeof(buf) - strlen(buf) - 1);
94 if (filter->list_metadata)
95 strncat(buf, "1=0)", sizeof(buf) - strlen(buf) - 1);
97 if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
98 strncat(tmp_query, join_localized_info, sizeof(tmp_query) - strlen(tmp_query) - 1);
99 *bind_params = g_list_append(*bind_params, strdup(locale));
101 if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY)
102 strncat(tmp_query, join_category, sizeof(tmp_query) - strlen(tmp_query) - 1);
103 if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL)
104 strncat(tmp_query, join_app_control, sizeof(tmp_query) - strlen(tmp_query) - 1);
105 if (joined & E_PMINFO_APPINFO_JOIN_METADATA)
106 strncat(tmp_query, join_metadata, sizeof(tmp_query) - strlen(tmp_query) - 1);
108 strncat(tmp_query, buf, sizeof(tmp_query) - strlen(tmp_query) - 1);
110 *query = strdup(tmp_query);
112 return PMINFO_R_ERROR;
117 static int _appinfo_get_category(sqlite3 *db, const char *appid,
120 static const char query_raw[] =
121 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
127 query = sqlite3_mprintf(query_raw, appid);
129 LOGE("out of memory");
130 return PMINFO_R_ERROR;
133 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
135 if (ret != SQLITE_OK) {
136 LOGE("prepare failed: %s", sqlite3_errmsg(db));
137 return PMINFO_R_ERROR;
140 while (sqlite3_step(stmt) == SQLITE_ROW) {
142 _save_column_str(stmt, 0, &val);
144 *category = g_list_append(*category, (gpointer)val);
147 sqlite3_finalize(stmt);
152 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
159 if (appcontrol_str == NULL)
162 dup = strdup(appcontrol_str);
164 ac = calloc(1, sizeof(appcontrol_x));
166 _LOGE("out of memory");
169 token = strtok_r(dup, "|", &ptr);
170 if (token && strcmp(token, "NULL"))
171 ac->operation = strdup(token);
172 token = strtok_r(NULL, "|", &ptr);
173 if (token && strcmp(token, "NULL"))
174 ac->uri = strdup(token);
175 token = strtok_r(NULL, "|", &ptr);
176 if (token && strcmp(token, "NULL"))
177 ac->mime = strdup(token);
178 *appcontrol = g_list_append(*appcontrol, ac);
179 } while ((token = strtok_r(NULL, ";", &ptr)));
184 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
187 static const char query_raw[] =
188 "SELECT app_control FROM package_app_app_control "
195 query = sqlite3_mprintf(query_raw, appid);
197 LOGE("out of memory");
198 return PMINFO_R_ERROR;
201 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
203 if (ret != SQLITE_OK) {
204 LOGE("prepare failed: %s", sqlite3_errmsg(db));
205 return PMINFO_R_ERROR;
208 while (sqlite3_step(stmt) == SQLITE_ROW) {
210 _save_column_str(stmt, 0, &str);
212 __parse_appcontrol(appcontrol, str);
216 sqlite3_finalize(stmt);
221 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
224 static const char query_raw[] =
225 "SELECT md_key, md_value "
226 "FROM package_app_app_metadata WHERE app_id=%Q";
233 query = sqlite3_mprintf(query_raw, appid);
235 LOGE("out of memory");
236 return PMINFO_R_ERROR;
239 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
241 if (ret != SQLITE_OK) {
242 LOGE("prepare failed: %s", sqlite3_errmsg(db));
243 return PMINFO_R_ERROR;
246 while (sqlite3_step(stmt) == SQLITE_ROW) {
247 info = calloc(1, sizeof(metadata_x));
249 LOGE("out of memory");
250 sqlite3_finalize(stmt);
251 return PMINFO_R_ERROR;
254 _save_column_str(stmt, idx++, &info->key);
255 _save_column_str(stmt, idx++, &info->value);
256 *metadata = g_list_append(*metadata, info);
259 sqlite3_finalize(stmt);
265 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
266 GList **splashscreens)
268 static const char query_raw[] =
269 "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
270 "FROM package_app_splash_screen WHERE app_id=%Q";
275 splashscreen_x *info;
277 query = sqlite3_mprintf(query_raw, appid);
279 LOGE("out of memory");
280 return PMINFO_R_ERROR;
283 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
285 if (ret != SQLITE_OK) {
286 LOGE("prepare failed: %s", sqlite3_errmsg(db));
287 return PMINFO_R_ERROR;
290 while (sqlite3_step(stmt) == SQLITE_ROW) {
291 info = calloc(1, sizeof(splashscreen_x));
293 LOGE("out of memory");
294 sqlite3_finalize(stmt);
295 return PMINFO_R_ERROR;
298 _save_column_str(stmt, idx++, &info->src);
299 _save_column_str(stmt, idx++, &info->type);
300 _save_column_str(stmt, idx++, &info->orientation);
301 _save_column_str(stmt, idx++, &info->indicatordisplay);
302 _save_column_str(stmt, idx++, &info->operation);
303 _save_column_str(stmt, idx++, &info->color_depth);
304 *splashscreens = g_list_append(*splashscreens, info);
307 sqlite3_finalize(stmt);
312 static GList *__get_background_category(const char *value)
314 GList *category_list = NULL;
315 int convert_value = 0;
316 if (!value || strlen(value) == 0)
319 convert_value = atoi(value);
320 if (convert_value < 0)
323 if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
324 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
326 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
328 if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
329 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
331 if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
332 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
334 if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
335 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
337 if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
338 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
340 if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
341 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
343 if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
344 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
346 if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
347 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
349 return category_list;
353 static void __free_applications(gpointer data)
355 pkgmgrinfo_basic_free_application((application_x *)data);
358 static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
360 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
361 pkgmgrinfo_appinfo_disable_type *value =
362 (pkgmgrinfo_appinfo_disable_type *)data2;
364 if (value == E_APPINFO_DISABLE_TYPE_PKG)
365 return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
368 return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
372 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
373 pkgmgrinfo_appinfo_disable_type type)
380 link = g_slist_find_custom(filter->list, &type, __disable_chk_func);
387 static int __bind_params(sqlite3_stmt *stmt, GList *params)
389 GList *tmp_list = NULL;
393 if (stmt == NULL || params == NULL)
394 return PMINFO_R_EINVAL;
398 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
399 if (ret != SQLITE_OK)
400 return PMINFO_R_ERROR;
401 tmp_list = tmp_list->next;
407 static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter)
409 GSList *tmp_list = NULL;
410 pkgmgrinfo_node_x *tmp_node = NULL;
413 if (tmp_filter == NULL)
416 property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
417 for (tmp_list = tmp_filter->list; tmp_list != NULL;
418 tmp_list = g_slist_next(tmp_list)) {
419 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
420 if (property == tmp_node->prop) {
421 if (strcmp(tmp_node->value, "true") == 0)
431 static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
432 const char *locale, pkgmgrinfo_filter_x *filter, int flag,
433 GHashTable *applications)
435 static const char query_raw[] =
436 "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
437 "ai.app_external_path";
438 static const char query_basic[] =
439 ", ai.app_component, ai.app_exec, "
440 "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
441 "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
442 "ai.app_hwacceleration, ai.app_screenreader, "
443 "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, "
444 "ai.app_indicatordisplay, ai.app_portraitimg, "
445 "ai.app_landscapeimg, ai.app_guestmodevisibility, "
446 "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
447 "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
448 "ai.app_support_disable, ai.app_process_pool, "
449 "ai.app_background_category, ai.app_package_type, "
450 "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
451 "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
452 "ai.app_zip_mount_file, ai.component_type, ai.package, "
453 "ai.app_package_system, ai.app_removable, "
454 "ai.app_package_installed_time, ai.app_support_mode, "
455 "ai.app_support_ambient, ai.app_setup_appid";
456 static const char query_uid_info[] =
457 ", ui.is_disabled, ui.is_splash_screen_enabled";
458 static const char query_label[] =
460 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
461 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
462 static const char query_icon[] =
464 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
465 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
466 static const char query_from_clause[] = " FROM package_app_info as ai";
467 static const char query_uid_info_clause[] =
468 " LEFT OUTER JOIN package_app_info_for_uid AS ui "
469 "ON (ai.app_id=ui.app_id AND ui.uid=?)";
470 int ret = PMINFO_R_ERROR;
473 char *bg_category_str = NULL;
474 char *constraint = NULL;
475 char *tmp_record = NULL;
476 char query[MAX_QUERY_LEN] = { '\0' };
477 char buf[BUFSIZE] = { '\0' };
478 application_x *info = NULL;
479 GList *bind_params = NULL;
481 sqlite3_stmt *stmt = NULL;
482 bool is_check_storage = true;
483 const uid_t global_user_uid = GLOBAL_USER;
485 dbpath = getUserPkgParserDBPathUID(db_uid);
487 return PMINFO_R_ERROR;
489 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
490 if (ret != SQLITE_OK) {
491 _LOGE("failed to open db(%s): %d", dbpath, ret);
493 return PMINFO_R_ERROR;
497 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
499 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
500 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
501 strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1);
503 if (flag & PMINFO_APPINFO_GET_LABEL) {
504 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
505 bind_params = g_list_append(bind_params, strdup(locale));
507 if (flag & PMINFO_APPINFO_GET_ICON) {
508 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
509 bind_params = g_list_append(bind_params, strdup(locale));
512 snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
513 bind_params = g_list_append(bind_params, strdup(buf));
515 is_check_storage = __check_app_storage_status(filter);
517 ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
518 if (ret != PMINFO_R_OK) {
519 LOGE("Failed to get WHERE clause");
522 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
524 strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1);
527 strncat(query, constraint, sizeof(query) - strlen(query) - 1);
529 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
530 if (ret != SQLITE_OK) {
531 LOGE("prepare failed: %s", sqlite3_errmsg(db));
532 ret = PMINFO_R_ERROR;
536 if (g_list_length(bind_params) != 0) {
537 ret = __bind_params(stmt, bind_params);
538 if (ret != SQLITE_OK) {
539 LOGE("Failed to bind parameters");
544 while (sqlite3_step(stmt) == SQLITE_ROW) {
545 info = calloc(1, sizeof(application_x));
547 LOGE("out of memory");
548 ret = PMINFO_R_ERROR;
552 _save_column_str(stmt, idx++, &info->appid);
553 _save_column_str(stmt, idx++, &info->installed_storage);
554 _save_column_str(stmt, idx++ , &info->external_path);
556 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
557 _save_column_str(stmt, idx++, &info->component);
558 _save_column_str(stmt, idx++, &info->exec);
559 _save_column_str(stmt, idx++, &info->nodisplay);
560 _save_column_str(stmt, idx++, &info->type);
561 _save_column_str(stmt, idx++, &info->onboot);
562 _save_column_str(stmt, idx++, &info->multiple);
563 _save_column_str(stmt, idx++, &info->autorestart);
564 _save_column_str(stmt, idx++, &info->taskmanage);
565 _save_column_str(stmt, idx++, &info->hwacceleration);
566 _save_column_str(stmt, idx++, &info->screenreader);
567 _save_column_str(stmt, idx++, &info->mainapp);
568 _save_column_str(stmt, idx++, &info->recentimage);
569 _save_column_str(stmt, idx++, &info->launchcondition);
570 _save_column_str(stmt, idx++, &info->indicatordisplay);
571 _save_column_str(stmt, idx++, &info->portraitimg);
572 _save_column_str(stmt, idx++, &info->landscapeimg);
573 _save_column_str(stmt, idx++, &info->guestmode_visibility);
574 _save_column_str(stmt, idx++, &info->permission_type);
575 _save_column_str(stmt, idx++, &info->preload);
576 _save_column_str(stmt, idx++, &info->submode);
577 _save_column_str(stmt, idx++, &info->submode_mainid);
578 _save_column_str(stmt, idx++, &info->launch_mode);
579 _save_column_str(stmt, idx++, &info->ui_gadget);
580 _save_column_str(stmt, idx++, &info->support_disable);
581 _save_column_str(stmt, idx++, &info->process_pool);
582 _save_column_str(stmt, idx++, &bg_category_str);
583 _save_column_str(stmt, idx++, &info->package_type);
584 _save_column_str(stmt, idx++, &info->root_path);
585 _save_column_str(stmt, idx++, &info->api_version);
586 _save_column_str(stmt, idx++, &info->effective_appid);
587 _save_column_str(stmt, idx++, &info->is_disabled);
588 _save_column_str(stmt, idx++, &info->splash_screen_display);
589 _save_column_str(stmt, idx++, &info->tep_name);
590 _save_column_str(stmt, idx++, &info->zip_mount_file);
591 _save_column_str(stmt, idx++, &info->component_type);
592 _save_column_str(stmt, idx++, &info->package);
593 _save_column_str(stmt, idx++, &info->package_system);
594 _save_column_str(stmt, idx++, &info->removable);
595 _save_column_str(stmt, idx++, &info->package_installed_time);
596 _save_column_str(stmt, idx++, &info->support_mode);
597 _save_column_str(stmt, idx++, &info->support_ambient);
598 _save_column_str(stmt, idx++, &info->setup_appid);
599 info->background_category = __get_background_category(
601 free(bg_category_str);
604 info->for_all_users =
605 strdup((db_uid != global_user_uid) ? "false" : "true");
607 if (db_uid != global_user_uid) {
611 _save_column_str(stmt, idx++, &tmp_record);
612 if (tmp_record != NULL) {
613 if (strcasecmp(info->is_disabled, "false") == 0 &&
614 strcasecmp(tmp_record, "false") == 0) {
615 free(info->is_disabled);
616 info->is_disabled = tmp_record;
620 _save_column_str(stmt, idx++, &tmp_record);
621 if (tmp_record != NULL) {
622 if (strcasecmp(info->splash_screen_display, "false") == 0 &&
623 strcasecmp(tmp_record, "false") == 0) {
624 free(info->splash_screen_display);
625 info->splash_screen_display = tmp_record;
630 if (flag & PMINFO_APPINFO_GET_LABEL) {
632 _save_column_str(stmt, idx++, &tmp_record);
633 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
634 ret = PMINFO_R_ERROR;
639 if (flag & PMINFO_APPINFO_GET_ICON) {
641 _save_column_str(stmt, idx++, &tmp_record);
642 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
643 ret = PMINFO_R_ERROR;
648 if (flag & PMINFO_APPINFO_GET_CATEGORY) {
649 if (_appinfo_get_category(db, info->appid,
651 ret = PMINFO_R_ERROR;
656 if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
657 if (_appinfo_get_app_control(db, info->appid,
658 &info->appcontrol)) {
659 ret = PMINFO_R_ERROR;
664 if (flag & PMINFO_APPINFO_GET_METADATA) {
665 if (_appinfo_get_metadata(db, info->appid,
667 ret = PMINFO_R_ERROR;
672 if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
673 if (_appinfo_get_splashscreens(db, info->appid,
674 &info->splashscreens)) {
675 ret = PMINFO_R_ERROR;
680 if (is_check_storage &&
681 __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
682 ret = PMINFO_R_ERROR;
683 pkgmgrinfo_basic_free_application(info);
688 g_hash_table_insert(applications, (gpointer)info->appid,
698 if (ret != PMINFO_R_OK && info != NULL)
699 pkgmgrinfo_basic_free_application(info);
701 g_list_free_full(bind_params, free);
702 sqlite3_close_v2(db);
703 sqlite3_finalize(stmt);
708 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
709 pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
714 pkgmgr_appinfo_x *info;
716 if (appid == NULL || filter == NULL || handle == NULL) {
717 LOGE("invalid parameter");
718 return PMINFO_R_EINVAL;
721 locale = _get_system_locale();
723 return PMINFO_R_ERROR;
725 list = g_hash_table_new(g_str_hash, g_str_equal);
728 return PMINFO_R_ERROR;
731 ret = _appinfo_get_applications(uid, uid, locale, filter,
732 PMINFO_APPINFO_GET_ALL, list);
733 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
734 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
735 PMINFO_APPINFO_GET_ALL, list);
737 if (!g_hash_table_size(list)) {
738 _LOGD("appinfo for [%s] is not existed for user [%d]",
740 g_hash_table_destroy(list);
742 return PMINFO_R_ENOENT;
745 info = calloc(1, sizeof(pkgmgr_appinfo_x));
747 _LOGE("out of memory");
748 g_hash_table_destroy(list);
750 return PMINFO_R_ERROR;
753 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
754 info->locale = locale;
755 info->package = strdup(info->app_info->package);
757 /* just free list only */
758 g_hash_table_destroy(list);
765 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
766 pkgmgrinfo_appinfo_h *handle)
769 pkgmgrinfo_appinfo_filter_h filter;
771 if (appid == NULL || handle == NULL) {
772 LOGE("invalid parameter");
773 return PMINFO_R_EINVAL;
776 ret = pkgmgrinfo_appinfo_filter_create(&filter);
777 if (ret != PMINFO_R_OK)
780 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
781 PMINFO_APPINFO_PROP_APP_ID, appid);
782 if (ret != PMINFO_R_OK) {
783 pkgmgrinfo_appinfo_filter_destroy(filter);
784 return PMINFO_R_ERROR;
787 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
788 PMINFO_APPINFO_PROP_APP_DISABLE, true);
789 if (ret != PMINFO_R_OK) {
790 pkgmgrinfo_appinfo_filter_destroy(filter);
791 return PMINFO_R_ERROR;
794 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
795 pkgmgrinfo_appinfo_filter_destroy(filter);
800 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
802 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
805 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
806 pkgmgrinfo_appinfo_h *handle)
809 pkgmgrinfo_appinfo_filter_h filter;
811 if (appid == NULL || handle == NULL) {
812 LOGE("invalid parameter");
813 return PMINFO_R_EINVAL;
816 ret = pkgmgrinfo_appinfo_filter_create(&filter);
817 if (ret != PMINFO_R_OK)
820 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
821 PMINFO_APPINFO_PROP_APP_ID, appid);
822 if (ret != PMINFO_R_OK) {
823 pkgmgrinfo_appinfo_filter_destroy(filter);
824 return PMINFO_R_ERROR;
827 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
828 PMINFO_APPINFO_PROP_APP_DISABLE, false);
829 if (ret != PMINFO_R_OK) {
830 pkgmgrinfo_appinfo_filter_destroy(filter);
831 return PMINFO_R_ERROR;
834 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
835 PMINFO_APPINFO_PROP_PKG_DISABLE, false);
836 if (ret != PMINFO_R_OK) {
837 pkgmgrinfo_appinfo_filter_destroy(filter);
838 return PMINFO_R_ERROR;
841 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
842 pkgmgrinfo_appinfo_filter_destroy(filter);
846 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
848 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
851 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
852 pkgmgrinfo_appinfo_h *handle)
855 pkgmgrinfo_appinfo_filter_h filter;
857 if (appid == NULL || handle == NULL) {
858 LOGE("invalid parameter");
859 return PMINFO_R_EINVAL;
862 ret = pkgmgrinfo_appinfo_filter_create(&filter);
863 if (ret != PMINFO_R_OK)
866 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
867 PMINFO_APPINFO_PROP_APP_ID, appid);
868 if (ret != PMINFO_R_OK) {
869 pkgmgrinfo_appinfo_filter_destroy(filter);
870 return PMINFO_R_ERROR;
873 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
874 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
875 if (ret != PMINFO_R_OK) {
876 pkgmgrinfo_appinfo_filter_destroy(filter);
877 return PMINFO_R_ERROR;
880 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
881 pkgmgrinfo_appinfo_filter_destroy(filter);
886 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
888 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
891 static gpointer __copy_str(gconstpointer src, gpointer data)
893 const char *tmp = (const char *)src;
896 buffer = strdup(tmp);
897 if (buffer == NULL) {
898 LOGE("memory alloc failed");
906 static gpointer __copy_label(gconstpointer src, gpointer data)
908 label_x *tmp = (label_x *)src;
911 label = calloc(1, sizeof(label_x));
913 LOGE("memory alloc failed");
919 label->name = strdup(tmp->name);
921 label->text = strdup(tmp->text);
923 label->lang = strdup(tmp->lang);
928 static gpointer __copy_icon(gconstpointer src, gpointer data)
930 icon_x *tmp = (icon_x *)src;
933 icon = calloc(1, sizeof(icon_x));
935 LOGE("memory alloc failed");
941 icon->text = strdup(tmp->text);
943 icon->lang = strdup(tmp->lang);
945 icon->section = strdup(tmp->section);
947 icon->size = strdup(tmp->size);
949 icon->resolution = strdup(tmp->resolution);
954 static gpointer __copy_metadata(gconstpointer src, gpointer data)
956 metadata_x *tmp = (metadata_x *)src;
957 metadata_x *metadata;
959 metadata = calloc(1, sizeof(metadata_x));
960 if (metadata == NULL) {
961 LOGE("memory alloc failed");
967 metadata->key = strdup(tmp->key);
969 metadata->value = strdup(tmp->value);
974 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
976 datacontrol_x *tmp = (datacontrol_x *)src;
977 datacontrol_x *datacontrol;
979 datacontrol = calloc(1, sizeof(datacontrol_x));
980 if (datacontrol == NULL) {
981 LOGE("memory alloc failed");
987 datacontrol->providerid = strdup(tmp->providerid);
989 datacontrol->access = strdup(tmp->access);
991 datacontrol->type = strdup(tmp->type);
993 datacontrol->trusted = strdup(tmp->trusted);
998 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1000 appcontrol_x *tmp = (appcontrol_x *)src;
1001 appcontrol_x *appcontrol;
1003 appcontrol = calloc(1, sizeof(appcontrol_x));
1004 if (appcontrol == NULL) {
1005 LOGE("memory alloc failed");
1011 appcontrol->operation = strdup(tmp->operation);
1013 appcontrol->uri = strdup(tmp->uri);
1015 appcontrol->mime = strdup(tmp->mime);
1020 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1022 splashscreen_x *tmp = (splashscreen_x *)src;
1023 splashscreen_x *splashscreen;
1025 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1026 if (splashscreen == NULL) {
1027 LOGE("memory alloc failed");
1033 splashscreen->src = strdup(tmp->src);
1035 splashscreen->type = strdup(tmp->type);
1036 if (tmp->orientation)
1037 splashscreen->orientation = strdup(tmp->orientation);
1038 if (tmp->indicatordisplay)
1039 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1041 splashscreen->operation = strdup(tmp->operation);
1042 if (tmp->color_depth)
1043 splashscreen->color_depth = strdup(tmp->color_depth);
1045 return splashscreen;
1048 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1050 application_x *app_info;
1053 app_info = calloc(1, sizeof(application_x));
1054 if (app_info == NULL) {
1055 LOGE("memory alloc failed");
1056 return PMINFO_R_ERROR;
1059 if (data->appid != NULL)
1060 app_info->appid = strdup(data->appid);
1061 if (data->exec != NULL)
1062 app_info->exec = strdup(data->exec);
1063 if (data->nodisplay != NULL)
1064 app_info->nodisplay = strdup(data->nodisplay);
1065 if (data->multiple != NULL)
1066 app_info->multiple = strdup(data->multiple);
1067 if (data->taskmanage != NULL)
1068 app_info->taskmanage = strdup(data->taskmanage);
1069 if (data->type != NULL)
1070 app_info->type = strdup(data->type);
1071 if (data->categories != NULL)
1072 app_info->categories = strdup(data->categories);
1073 if (data->hwacceleration != NULL)
1074 app_info->hwacceleration = strdup(data->hwacceleration);
1075 if (data->screenreader != NULL)
1076 app_info->screenreader = strdup(data->screenreader);
1077 if (data->mainapp != NULL)
1078 app_info->mainapp = strdup(data->mainapp);
1079 if (data->package != NULL)
1080 app_info->package = strdup(data->package);
1081 if (data->recentimage != NULL)
1082 app_info->recentimage = strdup(data->recentimage);
1083 if (data->launchcondition != NULL)
1084 app_info->launchcondition = strdup(data->launchcondition);
1085 if (data->indicatordisplay != NULL)
1086 app_info->indicatordisplay = strdup(data->indicatordisplay);
1087 if (data->portraitimg != NULL)
1088 app_info->portraitimg = strdup(data->portraitimg);
1089 if (data->landscapeimg != NULL)
1090 app_info->landscapeimg = strdup(data->landscapeimg);
1091 if (data->guestmode_visibility != NULL)
1092 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1093 if (data->component != NULL)
1094 app_info->component = strdup(data->component);
1095 if (data->permission_type != NULL)
1096 app_info->permission_type = strdup(data->permission_type);
1097 if (data->component_type != NULL)
1098 app_info->component_type = strdup(data->component_type);
1099 if (data->preload != NULL)
1100 app_info->preload = strdup(data->preload);
1101 if (data->submode != NULL)
1102 app_info->submode = strdup(data->submode);
1103 if (data->submode_mainid != NULL)
1104 app_info->submode_mainid = strdup(data->submode_mainid);
1105 if (data->process_pool != NULL)
1106 app_info->process_pool = strdup(data->process_pool);
1107 if (data->installed_storage != NULL)
1108 app_info->installed_storage = strdup(data->installed_storage);
1109 if (data->autorestart != NULL)
1110 app_info->autorestart = strdup(data->autorestart);
1111 if (data->onboot != NULL)
1112 app_info->onboot = strdup(data->onboot);
1113 if (data->support_disable != NULL)
1114 app_info->support_disable = strdup(data->support_disable);
1115 if (data->ui_gadget != NULL)
1116 app_info->ui_gadget = strdup(data->ui_gadget);
1117 if (data->launch_mode != NULL)
1118 app_info->launch_mode = strdup(data->launch_mode);
1119 if (data->package_type != NULL)
1120 app_info->package_type = strdup(data->package_type);
1121 if (data->effective_appid != NULL)
1122 app_info->effective_appid = strdup(data->effective_appid);
1123 if (data->splash_screen_display != NULL)
1124 app_info->splash_screen_display = strdup(data->splash_screen_display);
1128 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1130 LOGE("memory alloc failed");
1131 pkgmgrinfo_basic_free_application(app_info);
1132 return PMINFO_R_ERROR;
1136 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1138 LOGE("memory alloc failed");
1139 pkgmgrinfo_basic_free_application(app_info);
1140 return PMINFO_R_ERROR;
1144 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1146 LOGE("memory alloc failed");
1147 pkgmgrinfo_basic_free_application(app_info);
1148 return PMINFO_R_ERROR;
1152 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1154 LOGE("memory alloc failed");
1155 pkgmgrinfo_basic_free_application(app_info);
1156 return PMINFO_R_ERROR;
1160 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1162 LOGE("memory alloc failed");
1163 pkgmgrinfo_basic_free_application(app_info);
1164 return PMINFO_R_ERROR;
1168 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1170 LOGE("memory alloc failed");
1171 pkgmgrinfo_basic_free_application(app_info);
1172 return PMINFO_R_ERROR;
1176 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1178 LOGE("memory alloc failed");
1179 pkgmgrinfo_basic_free_application(app_info);
1180 return PMINFO_R_ERROR;
1184 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1186 LOGE("memory alloc failed");
1187 pkgmgrinfo_basic_free_application(app_info);
1188 return PMINFO_R_ERROR;
1191 *application = app_info;
1196 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1197 pkgmgrinfo_appinfo_h *clone)
1199 pkgmgr_appinfo_x *info;
1200 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1203 return PMINFO_R_EINVAL;
1205 info = calloc(1, sizeof(pkgmgr_appinfo_x));
1207 LOGE("memory alloc failed");
1208 return PMINFO_R_ERROR;
1211 if (temp->package != NULL)
1212 info->package = strdup(temp->package);
1213 if (temp->locale != NULL)
1214 info->locale = strdup(temp->locale);
1216 info->app_component = temp->app_component;
1218 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1219 LOGE("appinfo copy failed");
1221 free((void *)info->package);
1225 return PMINFO_R_ERROR;
1233 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1234 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1240 pkgmgr_appinfo_x info;
1242 GHashTableIter iter;
1245 locale = _get_system_locale();
1247 return PMINFO_R_ERROR;
1249 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1250 __free_applications);
1253 return PMINFO_R_ERROR;
1256 ret = _appinfo_get_applications(uid, uid, locale, filter,
1257 flag | PMINFO_APPINFO_GET_BASICINFO, list);
1258 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1259 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1260 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1262 if (ret != PMINFO_R_OK) {
1263 g_hash_table_destroy(list);
1268 g_hash_table_iter_init(&iter, list);
1269 while (g_hash_table_iter_next(&iter, NULL, &value)) {
1270 app = (application_x *)value;
1271 info.app_info = app;
1272 info.locale = locale;
1273 info.package = app->package;
1274 if (app_list_cb(&info, user_data) < 0)
1277 g_hash_table_destroy(list);
1283 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1285 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1286 pkgmgrinfo_app_component component,
1287 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1290 pkgmgrinfo_appinfo_filter_h filter;
1292 const char *comp_str = NULL;
1294 if (handle == NULL || app_func == NULL) {
1295 LOGE("invalid parameter");
1296 return PMINFO_R_EINVAL;
1299 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1300 LOGE("invalid parameter");
1301 return PMINFO_R_EINVAL;
1304 if (pkgmgrinfo_appinfo_filter_create(&filter))
1305 return PMINFO_R_ERROR;
1307 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1308 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1309 pkgmgrinfo_appinfo_filter_destroy(filter);
1310 return PMINFO_R_ERROR;
1313 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1314 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1315 pkgmgrinfo_appinfo_filter_destroy(filter);
1316 return PMINFO_R_ERROR;
1319 comp_str = __appcomponent_str(component);
1322 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1323 PMINFO_APPINFO_PROP_APP_COMPONENT,
1325 pkgmgrinfo_appinfo_filter_destroy(filter);
1326 return PMINFO_R_ERROR;
1330 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1331 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1333 pkgmgrinfo_appinfo_filter_destroy(filter);
1338 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1339 pkgmgrinfo_app_component component,
1340 pkgmgrinfo_app_list_cb app_func, void *user_data)
1342 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1345 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1346 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1350 pkgmgrinfo_appinfo_filter_h filter;
1352 if (app_func == NULL) {
1353 LOGE("invalid parameter");
1354 return PMINFO_R_EINVAL;
1357 if (pkgmgrinfo_appinfo_filter_create(&filter))
1358 return PMINFO_R_ERROR;
1360 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1361 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1362 pkgmgrinfo_appinfo_filter_destroy(filter);
1363 return PMINFO_R_ERROR;
1366 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1367 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1368 pkgmgrinfo_appinfo_filter_destroy(filter);
1369 return PMINFO_R_ERROR;
1372 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1373 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1374 pkgmgrinfo_appinfo_filter_destroy(filter);
1375 return PMINFO_R_ERROR;
1378 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1381 pkgmgrinfo_appinfo_filter_destroy(filter);
1386 API int pkgmgrinfo_appinfo_get_installed_list_full(
1387 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1389 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1390 _getuid(), flag, user_data);
1393 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1394 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1397 pkgmgrinfo_appinfo_filter_h filter;
1399 if (app_func == NULL) {
1400 LOGE("invalid parameter");
1401 return PMINFO_R_EINVAL;
1404 /* create an empty filter */
1405 ret = pkgmgrinfo_appinfo_filter_create(&filter);
1406 if (ret != PMINFO_R_OK)
1409 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1410 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1411 pkgmgrinfo_appinfo_filter_destroy(filter);
1412 return PMINFO_R_ERROR;
1415 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1416 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1417 pkgmgrinfo_appinfo_filter_destroy(filter);
1418 return PMINFO_R_ERROR;
1421 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1422 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1424 pkgmgrinfo_appinfo_filter_destroy(filter);
1429 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1432 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1436 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1438 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1440 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1441 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1443 if (info->app_info == NULL || info->app_info->appid == NULL)
1444 return PMINFO_R_ERROR;
1445 *appid = (char *)info->app_info->appid;
1450 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1452 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1454 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1455 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1457 if (info->package == NULL)
1458 return PMINFO_R_ERROR;
1460 *pkg_name = (char *)info->package;
1465 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1467 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1469 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1470 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1472 if (info->package == NULL)
1473 return PMINFO_R_ERROR;
1475 *pkgid = (char *)info->package;
1480 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1483 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1484 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1486 *pkgtype = (char *)info->app_info->package_type;
1491 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1493 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1495 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1496 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1498 if (info->app_info == NULL || info->app_info->exec == NULL)
1499 return PMINFO_R_ERROR;
1500 *exec = (char *)info->app_info->exec;
1506 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1509 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1512 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1514 if (info->app_info == NULL)
1515 return PMINFO_R_ERROR;
1517 if (info->app_info->icon == NULL) {
1522 ptr = (icon_x *)info->app_info->icon->data;
1524 return PMINFO_R_ERROR;
1526 if (ptr->text == NULL)
1527 return PMINFO_R_ERROR;
1535 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1538 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1544 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1546 if (info->app_info == NULL)
1547 return PMINFO_R_ERROR;
1549 locale = info->locale;
1551 locale = DEFAULT_LOCALE;
1553 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1554 ptr = (label_x *)tmp->data;
1555 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
1566 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1567 ptr = (label_x *)tmp->data;
1568 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
1574 *label = lbl ? lbl : "";
1579 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1581 char *result = NULL;
1583 sqlite3_stmt *stmt = NULL;
1588 parser_db = getUserPkgParserDBPathUID(uid);
1589 if (parser_db == NULL) {
1590 _LOGE("Failed to get parser db path");
1594 if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1595 _LOGE("DB open fail\n");
1601 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1602 if (query == NULL) {
1603 _LOGE("Out of memory");
1607 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1608 _LOGE("prepare_v2 fail\n");
1612 if (sqlite3_step(stmt) == SQLITE_ROW) {
1613 val = (char *)sqlite3_column_text(stmt, 0);
1615 result = strdup(val);
1619 sqlite3_finalize(stmt);
1620 sqlite3_free(query);
1626 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1630 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1632 val = _get_localed_label(appid, locale, uid);
1634 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1637 val = _get_localed_label(appid, locale, GLOBAL_USER);
1639 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1643 return PMINFO_R_ERROR;
1650 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1652 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1655 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1657 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1658 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1659 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1661 GList *list_md = NULL;
1662 metadata_x *metadata = NULL;
1663 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1665 list_md = info->app_info->metadata;
1667 for (; list_md; list_md = list_md->next) {
1668 metadata = (metadata_x *)list_md->data;
1669 if (metadata && metadata->key) {
1670 if (strcasecmp(metadata->key, metadata_key) == 0) {
1671 if (metadata->value == NULL)
1672 *metadata_value = "";
1674 *metadata_value = (char *)metadata->value;
1680 return PMINFO_R_EINVAL;
1683 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1685 if (strcasecmp(comp, "uiapp") == 0)
1686 return PMINFO_UI_APP;
1687 else if (strcasecmp(comp, "svcapp") == 0)
1688 return PMINFO_SVC_APP;
1689 else if (strcasecmp(comp, "widgetapp") == 0)
1690 return PMINFO_WIDGET_APP;
1691 else if (strcasecmp(comp, "watchapp") == 0)
1692 return PMINFO_WATCH_APP;
1697 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1702 case PMINFO_SVC_APP:
1704 case PMINFO_WIDGET_APP:
1706 case PMINFO_WATCH_APP:
1713 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1715 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1718 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1719 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1721 if (info->app_info == NULL)
1722 return PMINFO_R_ERROR;
1724 comp = __appcomponent_convert(info->app_info->component);
1726 return PMINFO_R_ERROR;
1733 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1735 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1737 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1738 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1740 if (info->app_info == NULL || info->app_info->type == NULL)
1741 return PMINFO_R_ERROR;
1742 *app_type = (char *)info->app_info->type;
1747 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1748 int *operation_count, char ***operation)
1750 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1751 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1752 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1753 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1754 *operation_count = data->operation_count;
1755 *operation = data->operation;
1759 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1760 int *uri_count, char ***uri)
1762 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1763 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1764 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1765 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1766 *uri_count = data->uri_count;
1771 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1772 int *mime_count, char ***mime)
1774 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1775 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1776 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1777 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1778 *mime_count = data->mime_count;
1783 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1784 int *subapp_count, char ***subapp)
1786 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1787 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1788 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1789 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1790 *subapp_count = data->subapp_count;
1791 *subapp = data->subapp;
1795 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1800 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1802 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1803 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1805 if (info->app_info == NULL)
1806 return PMINFO_R_ERROR;
1808 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1809 ptr = (icon_x *)tmp->data;
1810 if (ptr == NULL || ptr->section == NULL)
1813 val = (char *)ptr->section;
1814 if (val && strcmp(val, "notification") == 0) {
1815 *icon = (char *)ptr->text;
1820 return PMINFO_R_ERROR;
1823 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1826 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1828 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1829 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1831 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1832 return PMINFO_R_ERROR;
1834 val = (char *)info->app_info->recentimage;
1835 if (strcasecmp(val, "capture") == 0)
1836 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1837 else if (strcasecmp(val, "icon") == 0)
1838 *type = PMINFO_RECENTIMAGE_USE_ICON;
1840 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1845 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1850 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1853 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1855 if (info->app_info == NULL)
1856 return PMINFO_R_ERROR;
1858 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1859 ptr = (image_x *)tmp->data;
1860 if (ptr == NULL || ptr->section == NULL)
1863 val = (char *)ptr->section;
1864 if (val && strcmp(val, "preview") == 0) {
1865 *preview_img = (char *)ptr->text;
1870 return PMINFO_R_ERROR;
1873 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1876 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1878 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1879 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1881 val = info->app_info->permission_type;
1883 return PMINFO_R_ERROR;
1885 if (strcmp(val, "signature") == 0)
1886 *permission = PMINFO_PERMISSION_SIGNATURE;
1887 else if (strcmp(val, "privilege") == 0)
1888 *permission = PMINFO_PERMISSION_PRIVILEGE;
1890 *permission = PMINFO_PERMISSION_NORMAL;
1895 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1897 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1899 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1900 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1902 if (info->app_info == NULL || info->app_info->component_type == NULL)
1903 return PMINFO_R_ERROR;
1905 *component_type = (char *)info->app_info->component_type;
1910 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1913 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1915 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1916 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1918 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1919 return PMINFO_R_ERROR;
1921 val = (char *)info->app_info->hwacceleration;
1922 if (strcasecmp(val, "off") == 0)
1923 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1924 else if (strcasecmp(val, "on") == 0)
1925 *hwacceleration = PMINFO_HWACCELERATION_ON;
1927 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1932 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1935 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1937 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1938 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1940 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1941 return PMINFO_R_ERROR;
1943 val = (char *)info->app_info->screenreader;
1944 if (strcasecmp(val, "screenreader-off") == 0)
1945 *screenreader = PMINFO_SCREENREADER_OFF;
1946 else if (strcasecmp(val, "screenreader-on") == 0)
1947 *screenreader = PMINFO_SCREENREADER_ON;
1949 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1954 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1956 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1958 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1959 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1960 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1962 if (info->app_info == NULL)
1963 return PMINFO_R_ERROR;
1965 if (info->app_info->portraitimg == NULL)
1968 *portrait_img = (char *)info->app_info->portraitimg;
1970 if (info->app_info->landscapeimg == NULL)
1971 *landscape_img = "";
1973 *landscape_img = (char *)info->app_info->landscapeimg;
1978 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1980 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1982 if (handle == NULL || effectimage_type == NULL) {
1983 LOGE("invalid parameter");
1984 return PMINFO_R_EINVAL;
1987 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1988 return PMINFO_R_ERROR;
1990 *effectimage_type = (char *)info->app_info->effectimage_type;
1995 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
1997 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1999 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2000 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2002 if (info->app_info == NULL)
2003 return PMINFO_R_ERROR;
2005 if (info->app_info->submode_mainid == NULL)
2006 *submode_mainid = "";
2008 *submode_mainid = (char *)info->app_info->submode_mainid;
2013 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2015 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2016 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2018 if (info->app_info && info->app_info->installed_storage) {
2019 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2020 *storage = PMINFO_INTERNAL_STORAGE;
2021 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2022 *storage = PMINFO_EXTERNAL_STORAGE;
2024 return PMINFO_R_ERROR;
2026 return PMINFO_R_ERROR;
2032 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2034 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2036 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2037 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2039 if (info->app_info->launch_mode == NULL)
2040 return PMINFO_R_ERROR;
2042 *mode = (char *)(info->app_info->launch_mode);
2047 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2049 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2051 if (handle == NULL || alias_appid == NULL) {
2052 LOGE("invalid parameter");
2053 return PMINFO_R_EINVAL;
2056 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2057 return PMINFO_R_ERROR;
2059 *alias_appid = (char *)info->app_info->alias_appid;
2064 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2066 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2068 if (handle == NULL || effective_appid == NULL) {
2069 LOGE("invalid parameter");
2070 return PMINFO_R_EINVAL;
2073 if (info->app_info == NULL)
2074 return PMINFO_R_ERROR;
2076 if (info->app_info->effective_appid == NULL)
2077 *effective_appid = "";
2079 *effective_appid = (char *)info->app_info->effective_appid;
2084 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2086 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2088 if (handle == NULL || tep_name == NULL) {
2089 LOGE("invalid parameter");
2090 return PMINFO_R_EINVAL;
2093 if (info->app_info == NULL)
2094 return PMINFO_R_ERROR;
2096 if (info->app_info->tep_name == NULL)
2099 *tep_name = (char *)info->app_info->tep_name;
2104 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2106 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2108 if (handle == NULL || zip_mount_file == NULL) {
2109 LOGE("invalid parameter");
2110 return PMINFO_R_EINVAL;
2113 if (info->app_info == NULL)
2114 return PMINFO_R_ERROR;
2116 if (info->app_info->zip_mount_file == NULL)
2117 *zip_mount_file = "";
2119 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2124 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2126 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2128 if (handle == NULL || root_path == NULL) {
2129 LOGE("invalid parameter");
2130 return PMINFO_R_EINVAL;
2133 if (info->app_info == NULL || info->app_info->root_path == NULL)
2134 return PMINFO_R_ERROR;
2136 *root_path = (char *)info->app_info->root_path;
2141 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2143 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2145 if (handle == NULL || api_version == NULL) {
2146 LOGE("invalid parameter");
2147 return PMINFO_R_EINVAL;
2150 if (info->app_info == NULL || info->app_info->api_version == NULL)
2151 return PMINFO_R_ERROR;
2153 *api_version = (char *)info->app_info->api_version;
2158 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2160 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2162 if (handle == NULL || installed_time == NULL) {
2163 LOGE("invalid parameter");
2164 return PMINFO_R_EINVAL;
2167 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2168 return PMINFO_R_ERROR;
2170 *installed_time = atoi(info->app_info->package_installed_time);
2175 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2176 const char *type, uid_t uid, char **appid, char **access)
2178 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2179 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2180 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2181 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2183 int ret = PMINFO_R_OK;
2185 sqlite3_stmt *stmt = NULL;
2188 ret = __open_manifest_db(uid, true);
2189 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2191 /*Start constructing query*/
2192 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
2193 tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2196 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2197 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2200 ret = sqlite3_step(stmt);
2201 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2203 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2204 *access = strdup((char *)sqlite3_column_text(stmt, 2));
2209 sqlite3_free(query);
2210 sqlite3_finalize(stmt);
2211 __close_manifest_db();
2215 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2216 const char *type, char **appid, char **access)
2218 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2219 type, _getuid(), appid, access);
2222 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
2224 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2225 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2227 int ret = PMINFO_R_OK;
2229 sqlite3_stmt *stmt = NULL;
2232 ret = __open_manifest_db(uid, true);
2233 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2235 /*Start constructing query*/
2236 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
2237 tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2240 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2241 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2244 ret = sqlite3_step(stmt);
2245 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2247 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2252 sqlite3_free(query);
2253 sqlite3_finalize(stmt);
2254 __close_manifest_db();
2258 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2260 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2263 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(const char *providerid,
2264 const char *type, uid_t uid, char **appid, bool *is_trusted)
2266 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2267 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2269 int ret = PMINFO_R_OK;
2271 sqlite3_stmt *stmt = NULL;
2274 ret = __open_manifest_db(uid, true);
2275 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2277 /*Start constructing query*/
2278 query = sqlite3_mprintf("SELECT app_id, trusted FROM package_app_data_control WHERE providerid=%Q AND type=%Q", providerid, type);
2279 tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2282 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2283 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2286 ret = sqlite3_step(stmt);
2287 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2289 _save_column_str(stmt, 0, appid);
2290 *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2295 sqlite3_free(query);
2296 sqlite3_finalize(stmt);
2297 __close_manifest_db();
2301 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2302 const char *type, char **appid, bool *is_trusted)
2304 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2305 type, _getuid(), appid, is_trusted);
2308 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(const char *providerid, const char *type,
2309 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data, uid_t uid)
2311 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2312 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2314 int ret = PMINFO_R_OK;
2316 sqlite3_stmt *stmt = NULL;
2319 ret = __open_manifest_db(uid, true);
2320 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2322 /*Start constructing query*/
2323 query = sqlite3_mprintf("SELECT privilege FROM package_app_data_control_privilege "
2324 "WHERE providerid=%Q AND type=%Q", providerid, type);
2325 tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2328 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2329 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2331 while (sqlite3_step(stmt) == SQLITE_ROW) {
2333 privilege = (char *)sqlite3_column_text(stmt, 0);
2334 ret = privilege_func(privilege, user_data);
2342 sqlite3_free(query);
2343 sqlite3_finalize(stmt);
2344 __close_manifest_db();
2348 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(const char *providerid, const char *type,
2349 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
2351 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(providerid, type, privilege_func,
2352 user_data, _getuid());
2355 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
2357 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2358 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2360 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2361 if (info->app_info->support_mode)
2362 *support_mode = atoi(info->app_info->support_mode);
2369 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2370 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2372 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2373 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2375 const char *category;
2377 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2379 if (info->app_info == NULL)
2380 return PMINFO_R_ERROR;
2382 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2383 category = (const char *)tmp->data;
2385 ret = category_func(category, user_data);
2393 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2394 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2396 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2397 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2401 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2403 if (info->app_info == NULL)
2404 return PMINFO_R_ERROR;
2406 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2407 ptr = (metadata_x *)tmp->data;
2411 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2419 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
2420 const char *operation, const char *uri, const char *mime,
2421 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2422 void *user_data, uid_t uid)
2424 static const char query_raw[] =
2425 "SELECT privilege FROM package_app_app_control_privilege "
2426 "WHERE app_id=%Q AND app_control=%Q";
2431 char app_control[BUFSIZE];
2433 if (appid == NULL || operation == NULL || privilege_func == NULL) {
2434 LOGE("invalid parameter");
2435 return PMINFO_R_EINVAL;
2438 snprintf(app_control, sizeof(app_control), "%s|%s|%s", operation,
2439 uri ? uri : "NULL", mime ? mime : "NULL");
2441 ret = __open_manifest_db(uid, true);
2442 if (ret != SQLITE_OK) {
2443 LOGE("open db failed");
2444 return PMINFO_R_ERROR;
2447 query = sqlite3_mprintf(query_raw, appid, app_control);
2448 if (query == NULL) {
2449 LOGE("out of memory");
2450 __close_manifest_db();
2451 return PMINFO_R_ERROR;
2454 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
2456 sqlite3_free(query);
2457 if (ret != PMINFO_R_OK) {
2458 LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
2459 __close_manifest_db();
2460 return PMINFO_R_ERROR;
2463 while (sqlite3_step(stmt) == SQLITE_ROW) {
2464 privilege = (char *)sqlite3_column_text(stmt, 0);
2465 ret = privilege_func(privilege, user_data);
2470 sqlite3_finalize(stmt);
2471 __close_manifest_db();
2476 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
2477 const char *operation, const char *uri, const char *mime,
2478 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2481 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
2482 operation, uri, mime, privilege_func, user_data,
2486 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2487 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2489 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2490 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2492 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2493 appcontrol_x *appcontrol;
2496 if (info->app_info == NULL)
2497 return PMINFO_R_ERROR;
2499 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2500 appcontrol = (appcontrol_x *)tmp->data;
2501 if (appcontrol == NULL)
2503 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2511 API int pkgmgrinfo_appinfo_foreach_background_category(
2512 pkgmgrinfo_appinfo_h handle,
2513 pkgmgrinfo_app_background_category_list_cb category_func,
2516 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2520 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2521 LOGE("invalid parameter");
2522 return PMINFO_R_EINVAL;
2525 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2526 category = (char *)tmp->data;
2527 if (category == NULL)
2530 if (category_func(category, user_data) < 0)
2537 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2538 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2541 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2542 splashscreen_x *splashscreen;
2546 if (info == NULL || info->app_info == NULL
2547 || splash_screen_func == NULL) {
2548 LOGE("invalid parameter");
2549 return PMINFO_R_EINVAL;
2552 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2553 splashscreen = (splashscreen_x *)tmp->data;
2554 if (splashscreen == NULL)
2556 ret = splash_screen_func(splashscreen->src,
2558 splashscreen->orientation,
2559 splashscreen->indicatordisplay,
2560 splashscreen->operation,
2561 splashscreen->color_depth,
2570 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2572 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2573 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2574 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2576 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2577 return PMINFO_R_ERROR;
2579 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2584 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2586 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2587 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2588 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2590 if (info->app_info == NULL || info->app_info->multiple == NULL)
2591 return PMINFO_R_ERROR;
2593 *multiple = _get_bool_value(info->app_info->multiple);
2598 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2600 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2601 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2602 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2604 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2605 return PMINFO_R_ERROR;
2607 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2612 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2614 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2615 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2616 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2618 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2619 return PMINFO_R_ERROR;
2621 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2626 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2628 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2629 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2630 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2632 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2633 return PMINFO_R_ERROR;
2635 *enabled = !_get_bool_value(info->app_info->is_disabled);
2640 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2643 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2644 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2646 if (info->app_info == NULL || info->app_info->onboot == NULL)
2647 return PMINFO_R_ERROR;
2649 *onboot = _get_bool_value(info->app_info->onboot);
2654 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
2656 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2657 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2658 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2660 if (info->app_info == NULL || info->app_info->autorestart == NULL)
2661 return PMINFO_R_ERROR;
2663 *autorestart = _get_bool_value(info->app_info->autorestart);
2668 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
2670 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2671 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2672 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2674 if (info->app_info == NULL || info->app_info->mainapp == NULL)
2675 return PMINFO_R_ERROR;
2677 *mainapp = _get_bool_value(info->app_info->mainapp);
2682 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2684 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2685 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2686 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2688 if (info->app_info == NULL || info->app_info->preload == NULL)
2689 return PMINFO_R_ERROR;
2691 *preload = _get_bool_value(info->app_info->preload);
2696 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2698 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2699 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2700 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2702 if (info->app_info == NULL || info->app_info->submode == NULL)
2703 return PMINFO_R_ERROR;
2705 *submode = _get_bool_value(info->app_info->submode);
2710 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2712 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2714 if (handle == NULL || process_pool == NULL) {
2715 LOGE("invalid parameter");
2716 return PMINFO_R_EINVAL;
2719 if (info->app_info == NULL)
2720 return PMINFO_R_ERROR;
2722 *process_pool = _get_bool_value(info->app_info->process_pool);
2727 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2729 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2730 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2731 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2735 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2737 if (info->app_info == NULL)
2738 return PMINFO_R_ERROR;
2741 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2742 val = (const char *)tmp->data;
2745 if (strcasecmp(val, category) == 0) {
2754 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2757 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2759 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2760 _LOGE("invalid parameter");
2761 return PMINFO_R_EINVAL;
2763 if (info->app_info->ui_gadget == NULL)
2764 info->app_info->ui_gadget = strdup("false");
2766 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2771 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2772 bool *support_disable)
2774 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2776 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2777 _LOGE("invalid parameter");
2778 return PMINFO_R_EINVAL;
2781 *support_disable = _get_bool_value(info->app_info->support_disable);
2786 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
2789 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2791 if (info == NULL || info->app_info == NULL || removable == NULL) {
2792 _LOGE("invalid parameter");
2793 return PMINFO_R_EINVAL;
2796 *removable = _get_bool_value(info->app_info->removable);
2801 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
2803 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2805 if (info == NULL || info->app_info == NULL || system == NULL) {
2806 _LOGE("invalid parameter");
2807 return PMINFO_R_EINVAL;
2810 *system = _get_bool_value(info->app_info->package_system);
2815 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2817 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2818 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2819 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2821 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2822 return PMINFO_R_ERROR;
2824 *disabled = _get_bool_value(info->app_info->is_disabled);
2829 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2831 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2833 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2834 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2836 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2837 return PMINFO_R_ERROR;
2839 *global = _get_bool_value(info->app_info->for_all_users);
2844 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
2846 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2848 if (info == NULL || splash_screen_display == NULL) {
2849 _LOGE("Invalid parameter");
2850 return PMINFO_R_EINVAL;
2853 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
2854 return PMINFO_R_ERROR;
2856 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
2861 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
2863 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2865 if (info == NULL || setup_appid == NULL) {
2866 _LOGE("Invalid parameter");
2867 return PMINFO_R_EINVAL;
2870 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
2871 return PMINFO_R_ERROR;
2873 *setup_appid = info->app_info->setup_appid;
2877 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
2878 bool *support_ambient)
2880 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2882 if (info == NULL || support_ambient == NULL) {
2883 _LOGE("Invalid parameter");
2884 return PMINFO_R_EINVAL;
2887 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
2888 return PMINFO_R_ERROR;
2890 *support_ambient = _get_bool_value(info->app_info->support_ambient);
2895 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2897 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2898 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2899 __cleanup_appinfo(info);
2903 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2905 return (pkgmgrinfo_pkginfo_filter_create(handle));
2908 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2910 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2913 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2915 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
2916 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
2917 if (node1->prop == node2->prop)
2919 else if (node1->prop > node2->prop)
2925 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2926 const char *property, const int value)
2928 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2929 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2930 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2932 GSList *link = NULL;
2934 prop = _pminfo_appinfo_convert_to_prop_int(property);
2935 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2936 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2937 _LOGE("Invalid Integer Property\n");
2938 return PMINFO_R_EINVAL;
2940 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2941 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2943 _LOGE("Out of Memory!!!\n");
2944 return PMINFO_R_ERROR;
2946 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2947 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2949 _LOGE("Out of Memory\n");
2952 return PMINFO_R_ERROR;
2956 /*If API is called multiple times for same property, we should override the previous values.
2957 Last value set will be used for filtering.*/
2958 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2960 filter->list = g_slist_delete_link(filter->list, link);
2961 filter->list = g_slist_append(filter->list, (gpointer)node);
2966 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2967 const char *property, const bool value)
2969 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2970 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2972 GSList *link = NULL;
2974 prop = _pminfo_appinfo_convert_to_prop_bool(property);
2975 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2976 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2977 _LOGE("Invalid Boolean Property\n");
2978 return PMINFO_R_EINVAL;
2980 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2981 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2983 _LOGE("Out of Memory!!!\n");
2984 return PMINFO_R_ERROR;
2987 val = strndup("true", 4);
2989 val = strndup("false", 5);
2991 _LOGE("Out of Memory\n");
2994 return PMINFO_R_ERROR;
2998 /*If API is called multiple times for same property, we should override the previous values.
2999 Last value set will be used for filtering.*/
3000 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3002 filter->list = g_slist_delete_link(filter->list, link);
3003 filter->list = g_slist_append(filter->list, (gpointer)node);
3008 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
3009 const char *property, const char *value)
3011 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3012 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3013 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3015 pkgmgrinfo_node_x *ptr = NULL;
3016 char prev[PKG_STRING_LEN_MAX] = {'\0'};
3017 char temp[PKG_STRING_LEN_MAX] = {'\0'};
3018 GSList *link = NULL;
3020 prop = _pminfo_appinfo_convert_to_prop_str(property);
3021 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
3022 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
3023 _LOGE("Invalid String Property\n");
3024 return PMINFO_R_EINVAL;
3026 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3027 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3029 _LOGE("Out of Memory!!!\n");
3030 return PMINFO_R_ERROR;
3034 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
3035 node->value = strdup(value);
3036 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3038 filter->list = g_slist_delete_link(filter->list, link);
3039 filter->list = g_slist_append(filter->list, (gpointer)node);
3041 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
3042 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
3044 _LOGE("Out of Memory\n");
3047 return PMINFO_R_ERROR;
3049 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3051 ptr = (pkgmgrinfo_node_x *)link->data;
3052 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
3053 _LOGI("Previous value is %s\n", prev);
3054 filter->list = g_slist_delete_link(filter->list, link);
3055 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
3056 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3057 _LOGI("New value is %s\n", val);
3059 filter->list = g_slist_append(filter->list, (gpointer)node);
3060 memset(temp, '\0', PKG_STRING_LEN_MAX);
3062 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3063 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3064 _LOGI("First value is %s\n", val);
3066 filter->list = g_slist_append(filter->list, (gpointer)node);
3067 memset(temp, '\0', PKG_STRING_LEN_MAX);
3071 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3072 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3074 filter->list = g_slist_delete_link(filter->list, link);
3075 filter->list = g_slist_append(filter->list, (gpointer)node);
3081 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3087 if (handle == NULL || count == NULL) {
3088 _LOGE("invalid parameter");
3089 return PMINFO_R_EINVAL;
3092 locale = _get_system_locale();
3094 return PMINFO_R_ERROR;
3096 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3097 __free_applications);
3100 return PMINFO_R_ERROR;
3103 if (__check_disable_filter_exist(
3104 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3105 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3106 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
3107 g_hash_table_destroy(list);
3109 return PMINFO_R_ERROR;
3113 if (__check_disable_filter_exist(
3114 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3115 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3116 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
3117 g_hash_table_destroy(list);
3119 return PMINFO_R_ERROR;
3123 ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3124 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3125 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3128 if (ret != PMINFO_R_OK) {
3129 g_hash_table_destroy(list);
3131 return PMINFO_R_ERROR;
3134 *count = g_hash_table_size(list);
3135 g_hash_table_destroy(list);
3141 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3143 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3146 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3147 pkgmgrinfo_appinfo_filter_h handle,
3148 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3150 if (handle == NULL || app_cb == NULL) {
3151 LOGE("invalid parameter");
3152 return PMINFO_R_EINVAL;
3155 if (__check_disable_filter_exist(
3156 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3157 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3158 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3159 return PMINFO_R_ERROR;
3162 if (__check_disable_filter_exist(
3163 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3164 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3165 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3166 return PMINFO_R_ERROR;
3169 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3173 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3174 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3176 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3179 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3181 return (pkgmgrinfo_pkginfo_filter_create(handle));
3184 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3186 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3189 API int pkgmgrinfo_appinfo_metadata_filter_add(
3190 pkgmgrinfo_appinfo_metadata_filter_h handle,
3191 const char *key, const char *value)
3193 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3194 pkgmgrinfo_metadata_node_x *node;
3196 /* value can be NULL.
3197 * In that case all apps with specified key should be displayed
3200 LOGE("invalid parameter");
3201 return PMINFO_R_EINVAL;
3204 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3206 LOGE("out of memory");
3207 return PMINFO_R_ERROR;
3210 node->key = strdup(key);
3211 if (value && strlen(value))
3212 node->value = strdup(value);
3214 filter->list_metadata = g_slist_append(filter->list_metadata,
3220 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3221 pkgmgrinfo_appinfo_metadata_filter_h handle,
3222 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3224 if (handle == NULL || app_cb == NULL) {
3225 LOGE("invalid parameter");
3226 return PMINFO_R_EINVAL;
3229 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3230 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3231 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3232 return PMINFO_R_ERROR;
3234 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3235 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3236 return PMINFO_R_ERROR;
3238 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3242 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3243 pkgmgrinfo_appinfo_metadata_filter_h handle,
3244 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3246 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3247 user_data, _getuid());
3250 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3253 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3255 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3256 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3258 val = info->app_info->guestmode_visibility;
3259 *status = _get_bool_value(val);