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 (ret != PMINFO_R_OK) {
737 g_hash_table_destroy(list);
742 if (!g_hash_table_size(list)) {
743 _LOGD("appinfo for [%s] is not existed for user [%d]",
745 g_hash_table_destroy(list);
747 return PMINFO_R_ENOENT;
750 info = calloc(1, sizeof(pkgmgr_appinfo_x));
752 _LOGE("out of memory");
753 g_hash_table_destroy(list);
755 return PMINFO_R_ERROR;
758 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
759 info->locale = locale;
760 info->package = strdup(info->app_info->package);
762 /* just free list only */
763 g_hash_table_destroy(list);
770 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
771 pkgmgrinfo_appinfo_h *handle)
774 pkgmgrinfo_appinfo_filter_h filter;
776 if (appid == NULL || handle == NULL) {
777 LOGE("invalid parameter");
778 return PMINFO_R_EINVAL;
781 ret = pkgmgrinfo_appinfo_filter_create(&filter);
782 if (ret != PMINFO_R_OK)
785 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
786 PMINFO_APPINFO_PROP_APP_ID, appid);
787 if (ret != PMINFO_R_OK) {
788 pkgmgrinfo_appinfo_filter_destroy(filter);
789 return PMINFO_R_ERROR;
792 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
793 PMINFO_APPINFO_PROP_APP_DISABLE, true);
794 if (ret != PMINFO_R_OK) {
795 pkgmgrinfo_appinfo_filter_destroy(filter);
796 return PMINFO_R_ERROR;
799 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
800 pkgmgrinfo_appinfo_filter_destroy(filter);
805 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
807 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
810 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
811 pkgmgrinfo_appinfo_h *handle)
814 pkgmgrinfo_appinfo_filter_h filter;
816 if (appid == NULL || handle == NULL) {
817 LOGE("invalid parameter");
818 return PMINFO_R_EINVAL;
821 ret = pkgmgrinfo_appinfo_filter_create(&filter);
822 if (ret != PMINFO_R_OK)
825 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
826 PMINFO_APPINFO_PROP_APP_ID, appid);
827 if (ret != PMINFO_R_OK) {
828 pkgmgrinfo_appinfo_filter_destroy(filter);
829 return PMINFO_R_ERROR;
832 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
833 PMINFO_APPINFO_PROP_APP_DISABLE, false);
834 if (ret != PMINFO_R_OK) {
835 pkgmgrinfo_appinfo_filter_destroy(filter);
836 return PMINFO_R_ERROR;
839 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
840 PMINFO_APPINFO_PROP_PKG_DISABLE, false);
841 if (ret != PMINFO_R_OK) {
842 pkgmgrinfo_appinfo_filter_destroy(filter);
843 return PMINFO_R_ERROR;
846 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
847 pkgmgrinfo_appinfo_filter_destroy(filter);
851 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
853 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
856 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
857 pkgmgrinfo_appinfo_h *handle)
860 pkgmgrinfo_appinfo_filter_h filter;
862 if (appid == NULL || handle == NULL) {
863 LOGE("invalid parameter");
864 return PMINFO_R_EINVAL;
867 ret = pkgmgrinfo_appinfo_filter_create(&filter);
868 if (ret != PMINFO_R_OK)
871 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
872 PMINFO_APPINFO_PROP_APP_ID, appid);
873 if (ret != PMINFO_R_OK) {
874 pkgmgrinfo_appinfo_filter_destroy(filter);
875 return PMINFO_R_ERROR;
878 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
879 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
880 if (ret != PMINFO_R_OK) {
881 pkgmgrinfo_appinfo_filter_destroy(filter);
882 return PMINFO_R_ERROR;
885 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
886 pkgmgrinfo_appinfo_filter_destroy(filter);
891 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
893 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
896 static gpointer __copy_str(gconstpointer src, gpointer data)
898 const char *tmp = (const char *)src;
901 buffer = strdup(tmp);
902 if (buffer == NULL) {
903 LOGE("memory alloc failed");
911 static gpointer __copy_label(gconstpointer src, gpointer data)
913 label_x *tmp = (label_x *)src;
916 label = calloc(1, sizeof(label_x));
918 LOGE("memory alloc failed");
924 label->name = strdup(tmp->name);
926 label->text = strdup(tmp->text);
928 label->lang = strdup(tmp->lang);
933 static gpointer __copy_icon(gconstpointer src, gpointer data)
935 icon_x *tmp = (icon_x *)src;
938 icon = calloc(1, sizeof(icon_x));
940 LOGE("memory alloc failed");
946 icon->text = strdup(tmp->text);
948 icon->lang = strdup(tmp->lang);
950 icon->section = strdup(tmp->section);
952 icon->size = strdup(tmp->size);
954 icon->resolution = strdup(tmp->resolution);
959 static gpointer __copy_metadata(gconstpointer src, gpointer data)
961 metadata_x *tmp = (metadata_x *)src;
962 metadata_x *metadata;
964 metadata = calloc(1, sizeof(metadata_x));
965 if (metadata == NULL) {
966 LOGE("memory alloc failed");
972 metadata->key = strdup(tmp->key);
974 metadata->value = strdup(tmp->value);
979 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
981 datacontrol_x *tmp = (datacontrol_x *)src;
982 datacontrol_x *datacontrol;
984 datacontrol = calloc(1, sizeof(datacontrol_x));
985 if (datacontrol == NULL) {
986 LOGE("memory alloc failed");
992 datacontrol->providerid = strdup(tmp->providerid);
994 datacontrol->access = strdup(tmp->access);
996 datacontrol->type = strdup(tmp->type);
998 datacontrol->trusted = strdup(tmp->trusted);
1003 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1005 appcontrol_x *tmp = (appcontrol_x *)src;
1006 appcontrol_x *appcontrol;
1008 appcontrol = calloc(1, sizeof(appcontrol_x));
1009 if (appcontrol == NULL) {
1010 LOGE("memory alloc failed");
1016 appcontrol->operation = strdup(tmp->operation);
1018 appcontrol->uri = strdup(tmp->uri);
1020 appcontrol->mime = strdup(tmp->mime);
1025 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1027 splashscreen_x *tmp = (splashscreen_x *)src;
1028 splashscreen_x *splashscreen;
1030 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1031 if (splashscreen == NULL) {
1032 LOGE("memory alloc failed");
1038 splashscreen->src = strdup(tmp->src);
1040 splashscreen->type = strdup(tmp->type);
1041 if (tmp->orientation)
1042 splashscreen->orientation = strdup(tmp->orientation);
1043 if (tmp->indicatordisplay)
1044 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1046 splashscreen->operation = strdup(tmp->operation);
1047 if (tmp->color_depth)
1048 splashscreen->color_depth = strdup(tmp->color_depth);
1050 return splashscreen;
1053 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1055 application_x *app_info;
1058 app_info = calloc(1, sizeof(application_x));
1059 if (app_info == NULL) {
1060 LOGE("memory alloc failed");
1061 return PMINFO_R_ERROR;
1064 if (data->appid != NULL)
1065 app_info->appid = strdup(data->appid);
1066 if (data->exec != NULL)
1067 app_info->exec = strdup(data->exec);
1068 if (data->nodisplay != NULL)
1069 app_info->nodisplay = strdup(data->nodisplay);
1070 if (data->multiple != NULL)
1071 app_info->multiple = strdup(data->multiple);
1072 if (data->taskmanage != NULL)
1073 app_info->taskmanage = strdup(data->taskmanage);
1074 if (data->type != NULL)
1075 app_info->type = strdup(data->type);
1076 if (data->categories != NULL)
1077 app_info->categories = strdup(data->categories);
1078 if (data->hwacceleration != NULL)
1079 app_info->hwacceleration = strdup(data->hwacceleration);
1080 if (data->screenreader != NULL)
1081 app_info->screenreader = strdup(data->screenreader);
1082 if (data->mainapp != NULL)
1083 app_info->mainapp = strdup(data->mainapp);
1084 if (data->package != NULL)
1085 app_info->package = strdup(data->package);
1086 if (data->recentimage != NULL)
1087 app_info->recentimage = strdup(data->recentimage);
1088 if (data->launchcondition != NULL)
1089 app_info->launchcondition = strdup(data->launchcondition);
1090 if (data->indicatordisplay != NULL)
1091 app_info->indicatordisplay = strdup(data->indicatordisplay);
1092 if (data->portraitimg != NULL)
1093 app_info->portraitimg = strdup(data->portraitimg);
1094 if (data->landscapeimg != NULL)
1095 app_info->landscapeimg = strdup(data->landscapeimg);
1096 if (data->guestmode_visibility != NULL)
1097 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1098 if (data->component != NULL)
1099 app_info->component = strdup(data->component);
1100 if (data->permission_type != NULL)
1101 app_info->permission_type = strdup(data->permission_type);
1102 if (data->component_type != NULL)
1103 app_info->component_type = strdup(data->component_type);
1104 if (data->preload != NULL)
1105 app_info->preload = strdup(data->preload);
1106 if (data->submode != NULL)
1107 app_info->submode = strdup(data->submode);
1108 if (data->submode_mainid != NULL)
1109 app_info->submode_mainid = strdup(data->submode_mainid);
1110 if (data->process_pool != NULL)
1111 app_info->process_pool = strdup(data->process_pool);
1112 if (data->installed_storage != NULL)
1113 app_info->installed_storage = strdup(data->installed_storage);
1114 if (data->autorestart != NULL)
1115 app_info->autorestart = strdup(data->autorestart);
1116 if (data->onboot != NULL)
1117 app_info->onboot = strdup(data->onboot);
1118 if (data->support_disable != NULL)
1119 app_info->support_disable = strdup(data->support_disable);
1120 if (data->ui_gadget != NULL)
1121 app_info->ui_gadget = strdup(data->ui_gadget);
1122 if (data->launch_mode != NULL)
1123 app_info->launch_mode = strdup(data->launch_mode);
1124 if (data->package_type != NULL)
1125 app_info->package_type = strdup(data->package_type);
1126 if (data->effective_appid != NULL)
1127 app_info->effective_appid = strdup(data->effective_appid);
1128 if (data->splash_screen_display != NULL)
1129 app_info->splash_screen_display = strdup(data->splash_screen_display);
1133 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1135 LOGE("memory alloc failed");
1136 pkgmgrinfo_basic_free_application(app_info);
1137 return PMINFO_R_ERROR;
1141 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1143 LOGE("memory alloc failed");
1144 pkgmgrinfo_basic_free_application(app_info);
1145 return PMINFO_R_ERROR;
1149 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1151 LOGE("memory alloc failed");
1152 pkgmgrinfo_basic_free_application(app_info);
1153 return PMINFO_R_ERROR;
1157 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1159 LOGE("memory alloc failed");
1160 pkgmgrinfo_basic_free_application(app_info);
1161 return PMINFO_R_ERROR;
1165 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1167 LOGE("memory alloc failed");
1168 pkgmgrinfo_basic_free_application(app_info);
1169 return PMINFO_R_ERROR;
1173 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1175 LOGE("memory alloc failed");
1176 pkgmgrinfo_basic_free_application(app_info);
1177 return PMINFO_R_ERROR;
1181 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1183 LOGE("memory alloc failed");
1184 pkgmgrinfo_basic_free_application(app_info);
1185 return PMINFO_R_ERROR;
1189 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1191 LOGE("memory alloc failed");
1192 pkgmgrinfo_basic_free_application(app_info);
1193 return PMINFO_R_ERROR;
1196 *application = app_info;
1201 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1202 pkgmgrinfo_appinfo_h *clone)
1204 pkgmgr_appinfo_x *info;
1205 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1208 return PMINFO_R_EINVAL;
1210 info = calloc(1, sizeof(pkgmgr_appinfo_x));
1212 LOGE("memory alloc failed");
1213 return PMINFO_R_ERROR;
1216 if (temp->package != NULL)
1217 info->package = strdup(temp->package);
1218 if (temp->locale != NULL)
1219 info->locale = strdup(temp->locale);
1221 info->app_component = temp->app_component;
1223 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1224 LOGE("appinfo copy failed");
1226 free((void *)info->package);
1230 return PMINFO_R_ERROR;
1238 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1239 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1245 pkgmgr_appinfo_x info;
1247 GHashTableIter iter;
1250 locale = _get_system_locale();
1252 return PMINFO_R_ERROR;
1254 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1255 __free_applications);
1258 return PMINFO_R_ERROR;
1261 ret = _appinfo_get_applications(uid, uid, locale, filter,
1262 flag | PMINFO_APPINFO_GET_BASICINFO, list);
1263 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1264 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1265 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1267 if (ret != PMINFO_R_OK) {
1268 g_hash_table_destroy(list);
1273 g_hash_table_iter_init(&iter, list);
1274 while (g_hash_table_iter_next(&iter, NULL, &value)) {
1275 app = (application_x *)value;
1276 info.app_info = app;
1277 info.locale = locale;
1278 info.package = app->package;
1279 if (app_list_cb(&info, user_data) < 0)
1282 g_hash_table_destroy(list);
1288 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1290 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1291 pkgmgrinfo_app_component component,
1292 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1295 pkgmgrinfo_appinfo_filter_h filter;
1297 const char *comp_str = NULL;
1299 if (handle == NULL || app_func == NULL) {
1300 LOGE("invalid parameter");
1301 return PMINFO_R_EINVAL;
1304 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1305 LOGE("invalid parameter");
1306 return PMINFO_R_EINVAL;
1309 if (pkgmgrinfo_appinfo_filter_create(&filter))
1310 return PMINFO_R_ERROR;
1312 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1313 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1314 pkgmgrinfo_appinfo_filter_destroy(filter);
1315 return PMINFO_R_ERROR;
1318 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1319 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1320 pkgmgrinfo_appinfo_filter_destroy(filter);
1321 return PMINFO_R_ERROR;
1324 comp_str = __appcomponent_str(component);
1327 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1328 PMINFO_APPINFO_PROP_APP_COMPONENT,
1330 pkgmgrinfo_appinfo_filter_destroy(filter);
1331 return PMINFO_R_ERROR;
1335 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1336 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1338 pkgmgrinfo_appinfo_filter_destroy(filter);
1343 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1344 pkgmgrinfo_app_component component,
1345 pkgmgrinfo_app_list_cb app_func, void *user_data)
1347 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1350 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1351 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1355 pkgmgrinfo_appinfo_filter_h filter;
1357 if (app_func == NULL) {
1358 LOGE("invalid parameter");
1359 return PMINFO_R_EINVAL;
1362 if (pkgmgrinfo_appinfo_filter_create(&filter))
1363 return PMINFO_R_ERROR;
1365 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1366 PMINFO_APPINFO_PROP_APP_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_PKG_DISABLE, false)) {
1373 pkgmgrinfo_appinfo_filter_destroy(filter);
1374 return PMINFO_R_ERROR;
1377 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1378 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1379 pkgmgrinfo_appinfo_filter_destroy(filter);
1380 return PMINFO_R_ERROR;
1383 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1386 pkgmgrinfo_appinfo_filter_destroy(filter);
1391 API int pkgmgrinfo_appinfo_get_installed_list_full(
1392 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1394 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1395 _getuid(), flag, user_data);
1398 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1399 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1402 pkgmgrinfo_appinfo_filter_h filter;
1404 if (app_func == NULL) {
1405 LOGE("invalid parameter");
1406 return PMINFO_R_EINVAL;
1409 /* create an empty filter */
1410 ret = pkgmgrinfo_appinfo_filter_create(&filter);
1411 if (ret != PMINFO_R_OK)
1414 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1415 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1416 pkgmgrinfo_appinfo_filter_destroy(filter);
1417 return PMINFO_R_ERROR;
1420 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1421 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1422 pkgmgrinfo_appinfo_filter_destroy(filter);
1423 return PMINFO_R_ERROR;
1426 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1427 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1429 pkgmgrinfo_appinfo_filter_destroy(filter);
1434 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1437 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1441 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1443 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1445 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1446 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1448 if (info->app_info == NULL || info->app_info->appid == NULL)
1449 return PMINFO_R_ERROR;
1450 *appid = (char *)info->app_info->appid;
1455 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1457 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1459 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1460 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1462 if (info->package == NULL)
1463 return PMINFO_R_ERROR;
1465 *pkg_name = (char *)info->package;
1470 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1472 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1474 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1475 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1477 if (info->package == NULL)
1478 return PMINFO_R_ERROR;
1480 *pkgid = (char *)info->package;
1485 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1487 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1488 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1489 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1491 *pkgtype = (char *)info->app_info->package_type;
1496 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1498 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1500 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1501 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1503 if (info->app_info == NULL || info->app_info->exec == NULL)
1504 return PMINFO_R_ERROR;
1505 *exec = (char *)info->app_info->exec;
1511 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1514 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1516 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1517 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1519 if (info->app_info == NULL)
1520 return PMINFO_R_ERROR;
1522 if (info->app_info->icon == NULL) {
1527 ptr = (icon_x *)info->app_info->icon->data;
1529 return PMINFO_R_ERROR;
1531 if (ptr->text == NULL)
1532 return PMINFO_R_ERROR;
1540 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1543 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1548 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1549 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1551 if (info->app_info == NULL)
1552 return PMINFO_R_ERROR;
1554 locale = info->locale;
1556 locale = DEFAULT_LOCALE;
1558 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1559 ptr = (label_x *)tmp->data;
1560 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
1571 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1572 ptr = (label_x *)tmp->data;
1573 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
1579 *label = lbl ? lbl : "";
1584 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1586 char *result = NULL;
1588 sqlite3_stmt *stmt = NULL;
1593 parser_db = getUserPkgParserDBPathUID(uid);
1594 if (parser_db == NULL) {
1595 _LOGE("Failed to get parser db path");
1599 if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1600 _LOGE("DB open fail\n");
1606 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1607 if (query == NULL) {
1608 _LOGE("Out of memory");
1612 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1613 _LOGE("prepare_v2 fail\n");
1617 if (sqlite3_step(stmt) == SQLITE_ROW) {
1618 val = (char *)sqlite3_column_text(stmt, 0);
1620 result = strdup(val);
1624 sqlite3_finalize(stmt);
1625 sqlite3_free(query);
1631 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1635 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1637 val = _get_localed_label(appid, locale, uid);
1639 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1642 val = _get_localed_label(appid, locale, GLOBAL_USER);
1644 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1648 return PMINFO_R_ERROR;
1655 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1657 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1660 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1662 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1663 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1664 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1666 GList *list_md = NULL;
1667 metadata_x *metadata = NULL;
1668 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1670 list_md = info->app_info->metadata;
1672 for (; list_md; list_md = list_md->next) {
1673 metadata = (metadata_x *)list_md->data;
1674 if (metadata && metadata->key) {
1675 if (strcasecmp(metadata->key, metadata_key) == 0) {
1676 if (metadata->value == NULL)
1677 *metadata_value = "";
1679 *metadata_value = (char *)metadata->value;
1685 return PMINFO_R_EINVAL;
1688 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1690 if (strcasecmp(comp, "uiapp") == 0)
1691 return PMINFO_UI_APP;
1692 else if (strcasecmp(comp, "svcapp") == 0)
1693 return PMINFO_SVC_APP;
1694 else if (strcasecmp(comp, "widgetapp") == 0)
1695 return PMINFO_WIDGET_APP;
1696 else if (strcasecmp(comp, "watchapp") == 0)
1697 return PMINFO_WATCH_APP;
1702 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1707 case PMINFO_SVC_APP:
1709 case PMINFO_WIDGET_APP:
1711 case PMINFO_WATCH_APP:
1718 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1720 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1723 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1724 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1726 if (info->app_info == NULL)
1727 return PMINFO_R_ERROR;
1729 comp = __appcomponent_convert(info->app_info->component);
1731 return PMINFO_R_ERROR;
1738 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1740 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1742 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1743 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1745 if (info->app_info == NULL || info->app_info->type == NULL)
1746 return PMINFO_R_ERROR;
1747 *app_type = (char *)info->app_info->type;
1752 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1753 int *operation_count, char ***operation)
1755 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1756 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1757 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1758 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1759 *operation_count = data->operation_count;
1760 *operation = data->operation;
1764 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1765 int *uri_count, char ***uri)
1767 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1768 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1769 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1770 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1771 *uri_count = data->uri_count;
1776 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1777 int *mime_count, char ***mime)
1779 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1780 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1781 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1782 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1783 *mime_count = data->mime_count;
1788 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1789 int *subapp_count, char ***subapp)
1791 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1792 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1793 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1794 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1795 *subapp_count = data->subapp_count;
1796 *subapp = data->subapp;
1800 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1805 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1807 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1808 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1810 if (info->app_info == NULL)
1811 return PMINFO_R_ERROR;
1813 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1814 ptr = (icon_x *)tmp->data;
1815 if (ptr == NULL || ptr->section == NULL)
1818 val = (char *)ptr->section;
1819 if (val && strcmp(val, "notification") == 0) {
1820 *icon = (char *)ptr->text;
1825 return PMINFO_R_ERROR;
1828 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1831 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1833 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1834 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1836 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1837 return PMINFO_R_ERROR;
1839 val = (char *)info->app_info->recentimage;
1840 if (strcasecmp(val, "capture") == 0)
1841 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1842 else if (strcasecmp(val, "icon") == 0)
1843 *type = PMINFO_RECENTIMAGE_USE_ICON;
1845 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1850 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1855 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1857 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1858 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1860 if (info->app_info == NULL)
1861 return PMINFO_R_ERROR;
1863 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1864 ptr = (image_x *)tmp->data;
1865 if (ptr == NULL || ptr->section == NULL)
1868 val = (char *)ptr->section;
1869 if (val && strcmp(val, "preview") == 0) {
1870 *preview_img = (char *)ptr->text;
1875 return PMINFO_R_ERROR;
1878 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1881 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1883 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1884 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1886 val = info->app_info->permission_type;
1888 return PMINFO_R_ERROR;
1890 if (strcmp(val, "signature") == 0)
1891 *permission = PMINFO_PERMISSION_SIGNATURE;
1892 else if (strcmp(val, "privilege") == 0)
1893 *permission = PMINFO_PERMISSION_PRIVILEGE;
1895 *permission = PMINFO_PERMISSION_NORMAL;
1900 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1902 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1904 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1905 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1907 if (info->app_info == NULL || info->app_info->component_type == NULL)
1908 return PMINFO_R_ERROR;
1910 *component_type = (char *)info->app_info->component_type;
1915 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1918 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1920 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1921 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1923 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1924 return PMINFO_R_ERROR;
1926 val = (char *)info->app_info->hwacceleration;
1927 if (strcasecmp(val, "off") == 0)
1928 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1929 else if (strcasecmp(val, "on") == 0)
1930 *hwacceleration = PMINFO_HWACCELERATION_ON;
1932 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1937 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1940 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1942 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1943 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1945 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1946 return PMINFO_R_ERROR;
1948 val = (char *)info->app_info->screenreader;
1949 if (strcasecmp(val, "screenreader-off") == 0)
1950 *screenreader = PMINFO_SCREENREADER_OFF;
1951 else if (strcasecmp(val, "screenreader-on") == 0)
1952 *screenreader = PMINFO_SCREENREADER_ON;
1954 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1959 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1961 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1963 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1964 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1965 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1967 if (info->app_info == NULL)
1968 return PMINFO_R_ERROR;
1970 if (info->app_info->portraitimg == NULL)
1973 *portrait_img = (char *)info->app_info->portraitimg;
1975 if (info->app_info->landscapeimg == NULL)
1976 *landscape_img = "";
1978 *landscape_img = (char *)info->app_info->landscapeimg;
1983 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1985 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1987 if (handle == NULL || effectimage_type == NULL) {
1988 LOGE("invalid parameter");
1989 return PMINFO_R_EINVAL;
1992 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1993 return PMINFO_R_ERROR;
1995 *effectimage_type = (char *)info->app_info->effectimage_type;
2000 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
2002 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2004 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2005 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2007 if (info->app_info == NULL)
2008 return PMINFO_R_ERROR;
2010 if (info->app_info->submode_mainid == NULL)
2011 *submode_mainid = "";
2013 *submode_mainid = (char *)info->app_info->submode_mainid;
2018 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2020 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2021 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2023 if (info->app_info && info->app_info->installed_storage) {
2024 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2025 *storage = PMINFO_INTERNAL_STORAGE;
2026 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2027 *storage = PMINFO_EXTERNAL_STORAGE;
2029 return PMINFO_R_ERROR;
2031 return PMINFO_R_ERROR;
2037 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2039 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2041 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2042 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2044 if (info->app_info->launch_mode == NULL)
2045 return PMINFO_R_ERROR;
2047 *mode = (char *)(info->app_info->launch_mode);
2052 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2054 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2056 if (handle == NULL || alias_appid == NULL) {
2057 LOGE("invalid parameter");
2058 return PMINFO_R_EINVAL;
2061 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2062 return PMINFO_R_ERROR;
2064 *alias_appid = (char *)info->app_info->alias_appid;
2069 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2071 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2073 if (handle == NULL || effective_appid == NULL) {
2074 LOGE("invalid parameter");
2075 return PMINFO_R_EINVAL;
2078 if (info->app_info == NULL)
2079 return PMINFO_R_ERROR;
2081 if (info->app_info->effective_appid == NULL)
2082 *effective_appid = "";
2084 *effective_appid = (char *)info->app_info->effective_appid;
2089 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2091 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2093 if (handle == NULL || tep_name == NULL) {
2094 LOGE("invalid parameter");
2095 return PMINFO_R_EINVAL;
2098 if (info->app_info == NULL)
2099 return PMINFO_R_ERROR;
2101 if (info->app_info->tep_name == NULL)
2104 *tep_name = (char *)info->app_info->tep_name;
2109 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2111 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2113 if (handle == NULL || zip_mount_file == NULL) {
2114 LOGE("invalid parameter");
2115 return PMINFO_R_EINVAL;
2118 if (info->app_info == NULL)
2119 return PMINFO_R_ERROR;
2121 if (info->app_info->zip_mount_file == NULL)
2122 *zip_mount_file = "";
2124 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2129 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2131 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2133 if (handle == NULL || root_path == NULL) {
2134 LOGE("invalid parameter");
2135 return PMINFO_R_EINVAL;
2138 if (info->app_info == NULL || info->app_info->root_path == NULL)
2139 return PMINFO_R_ERROR;
2141 *root_path = (char *)info->app_info->root_path;
2146 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2148 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2150 if (handle == NULL || api_version == NULL) {
2151 LOGE("invalid parameter");
2152 return PMINFO_R_EINVAL;
2155 if (info->app_info == NULL || info->app_info->api_version == NULL)
2156 return PMINFO_R_ERROR;
2158 *api_version = (char *)info->app_info->api_version;
2163 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2165 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2167 if (handle == NULL || installed_time == NULL) {
2168 LOGE("invalid parameter");
2169 return PMINFO_R_EINVAL;
2172 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2173 return PMINFO_R_ERROR;
2175 *installed_time = atoi(info->app_info->package_installed_time);
2180 static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
2181 const char *type, char **appid, char **access)
2183 static const char query[] =
2184 "SELECT app_id, access FROM package_app_data_control "
2185 "WHERE providerid=? AND type=?";
2189 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2190 if (ret != SQLITE_OK) {
2191 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2192 return PMINFO_R_ERROR;
2195 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2196 if (ret != SQLITE_OK) {
2197 LOGE("bind failed: %s", sqlite3_errmsg(db));
2198 sqlite3_finalize(stmt);
2199 return PMINFO_R_ERROR;
2202 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2203 if (ret != SQLITE_OK) {
2204 LOGE("bind failed: %s", sqlite3_errmsg(db));
2205 sqlite3_finalize(stmt);
2206 return PMINFO_R_ERROR;
2209 ret = sqlite3_step(stmt);
2210 if (ret != SQLITE_ROW) {
2211 sqlite3_finalize(stmt);
2212 if (ret == SQLITE_DONE) {
2213 return PMINFO_R_ENOENT;
2215 LOGE("step error: %s", sqlite3_errmsg(db));
2216 return PMINFO_R_ERROR;
2220 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2221 if (*appid == NULL) {
2222 LOGE("out of memory");
2223 sqlite3_finalize(stmt);
2224 return PMINFO_R_ERROR;
2226 *access = strdup((char *)sqlite3_column_text(stmt, 1));
2227 if (*access == NULL) {
2228 LOGE("out of memory");
2230 sqlite3_finalize(stmt);
2231 return PMINFO_R_ERROR;
2234 sqlite3_finalize(stmt);
2239 static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
2240 const char *providerid, const char *type,
2241 char **appid, char **access)
2247 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2249 return PMINFO_R_ERROR;
2251 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2253 if (ret != SQLITE_OK) {
2254 LOGE("open db failed: %s", sqlite3_errmsg(db));
2255 return PMINFO_R_ERROR;
2258 ret = _appinfo_get_datacontrol_info(db, providerid, type, appid,
2260 sqlite3_close_v2(db);
2265 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2266 const char *type, uid_t uid, char **appid, char **access)
2270 if (providerid == NULL || type == NULL || appid == NULL ||
2272 LOGE("invalid parameter");
2273 return PMINFO_R_EINVAL;
2276 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
2277 type, appid, access);
2278 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2279 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
2280 type, appid, access);
2282 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2283 * implementation, return PMINFO_R_ERROR. This should be
2286 if (ret == PMINFO_R_ENOENT) {
2287 LOGE("no datacontrol info of %s", providerid);
2288 ret = PMINFO_R_ERROR;
2294 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2295 const char *type, char **appid, char **access)
2297 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2298 type, _getuid(), appid, access);
2301 static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
2304 static const char query[] =
2305 "SELECT app_id FROM package_app_data_control "
2306 "WHERE providerid=?";
2310 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2311 if (ret != SQLITE_OK) {
2312 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2313 return PMINFO_R_ERROR;
2316 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2317 if (ret != SQLITE_OK) {
2318 LOGE("bind failed: %s", sqlite3_errmsg(db));
2319 sqlite3_finalize(stmt);
2320 return PMINFO_R_ERROR;
2323 ret = sqlite3_step(stmt);
2324 if (ret != SQLITE_ROW) {
2325 sqlite3_finalize(stmt);
2326 if (ret == SQLITE_DONE) {
2327 return PMINFO_R_ENOENT;
2329 LOGE("step error: %s", sqlite3_errmsg(db));
2330 return PMINFO_R_ERROR;
2334 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2336 sqlite3_finalize(stmt);
2338 if (*appid == NULL) {
2339 LOGE("out of memory");
2340 return PMINFO_R_ERROR;
2346 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
2347 const char *providerid, char **appid)
2353 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2355 return PMINFO_R_ERROR;
2357 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2359 if (ret != SQLITE_OK) {
2360 LOGE("open db failed: %s", sqlite3_errmsg(db));
2361 return PMINFO_R_ERROR;
2364 ret = _appinfo_get_datacontrol_appid(db, providerid, appid);
2365 sqlite3_close_v2(db);
2370 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
2371 uid_t uid, char **appid)
2375 if (providerid == NULL || appid == NULL) {
2376 LOGE("invalid parameter");
2377 return PMINFO_R_EINVAL;
2380 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
2382 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2383 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
2386 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2387 * implementation, return PMINFO_R_ERROR. This should be
2390 if (ret == PMINFO_R_ENOENT) {
2391 LOGE("no datacontrol appid of %s", providerid);
2392 ret = PMINFO_R_ERROR;
2398 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2400 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2403 static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
2404 const char *providerid, const char *type, char **appid,
2407 static const char query[] =
2408 "SELECT app_id, trusted FROM package_app_data_control "
2409 "WHERE providerid=? AND type=?";
2413 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2414 if (ret != SQLITE_OK) {
2415 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2416 return PMINFO_R_ERROR;
2419 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2420 if (ret != SQLITE_OK) {
2421 LOGE("bind failed: %s", sqlite3_errmsg(db));
2422 sqlite3_finalize(stmt);
2423 return PMINFO_R_ERROR;
2426 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2427 if (ret != SQLITE_OK) {
2428 LOGE("bind failed: %s", sqlite3_errmsg(db));
2429 sqlite3_finalize(stmt);
2430 return PMINFO_R_ERROR;
2433 ret = sqlite3_step(stmt);
2434 if (ret != SQLITE_ROW) {
2435 sqlite3_finalize(stmt);
2436 if (ret == SQLITE_DONE) {
2437 return PMINFO_R_ENOENT;
2439 LOGE("step error: %s", sqlite3_errmsg(db));
2440 return PMINFO_R_ERROR;
2444 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2445 *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2447 sqlite3_finalize(stmt);
2449 if (*appid == NULL) {
2450 LOGE("out of memory");
2451 return PMINFO_R_ERROR;
2457 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
2458 const char *providerid, const char *type, char **appid,
2465 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2467 return PMINFO_R_ERROR;
2469 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2471 if (ret != SQLITE_OK) {
2472 LOGE("open db failed: %s", sqlite3_errmsg(db));
2473 return PMINFO_R_ERROR;
2476 ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid,
2478 sqlite3_close_v2(db);
2483 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
2484 const char *providerid, const char *type, uid_t uid,
2485 char **appid, bool *is_trusted)
2489 if (providerid == NULL || type == NULL || appid == NULL ||
2490 is_trusted == NULL) {
2491 LOGE("invalid parameter");
2492 return PMINFO_R_EINVAL;
2495 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
2496 providerid, type, appid, is_trusted);
2497 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2498 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
2499 providerid, type, appid, is_trusted);
2501 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2502 * implementation, return PMINFO_R_ERROR. This should be
2505 if (ret == PMINFO_R_ENOENT) {
2506 LOGE("no datacontrol trusted info of %s", providerid);
2507 ret = PMINFO_R_ERROR;
2513 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2514 const char *type, char **appid, bool *is_trusted)
2516 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2517 type, _getuid(), appid, is_trusted);
2520 static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
2521 const char *providerid, const char *type,
2522 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2524 static const char query[] =
2525 "SELECT privilege FROM package_app_data_control_privilege "
2526 "WHERE providerid=? AND type=?";
2531 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2532 if (ret != SQLITE_OK) {
2533 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2534 return PMINFO_R_ERROR;
2537 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2538 if (ret != SQLITE_OK) {
2539 LOGE("bind failed: %s", sqlite3_errmsg(db));
2540 sqlite3_finalize(stmt);
2541 return PMINFO_R_ERROR;
2544 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2545 if (ret != SQLITE_OK) {
2546 LOGE("bind failed: %s", sqlite3_errmsg(db));
2547 sqlite3_finalize(stmt);
2548 return PMINFO_R_ERROR;
2551 while (sqlite3_step(stmt) == SQLITE_ROW) {
2553 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2559 sqlite3_finalize(stmt);
2561 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2564 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
2565 const char *providerid, const char *type,
2566 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2572 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2574 return PMINFO_R_ERROR;
2576 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2578 if (ret != SQLITE_OK) {
2579 LOGE("open db failed: %s", sqlite3_errmsg(db));
2580 return PMINFO_R_ERROR;
2583 ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
2584 callback, user_data);
2585 sqlite3_close_v2(db);
2590 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2591 const char *providerid, const char *type,
2592 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2593 void *user_data, uid_t uid)
2597 if (providerid == NULL || type == NULL || privilege_func == NULL) {
2598 LOGE("invalid parameter");
2599 return PMINFO_R_EINVAL;
2602 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
2603 providerid, type, privilege_func, user_data);
2604 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2605 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
2606 providerid, type, privilege_func, user_data);
2608 if (ret == PMINFO_R_ENOENT)
2614 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
2615 const char *providerid, const char *type,
2616 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2619 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2620 providerid, type, privilege_func, user_data, _getuid());
2623 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
2625 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2626 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2628 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2629 if (info->app_info->support_mode)
2630 *support_mode = atoi(info->app_info->support_mode);
2637 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2638 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2640 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2641 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2643 const char *category;
2645 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2647 if (info->app_info == NULL)
2648 return PMINFO_R_ERROR;
2650 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2651 category = (const char *)tmp->data;
2653 ret = category_func(category, user_data);
2661 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2662 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2664 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2665 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2669 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2671 if (info->app_info == NULL)
2672 return PMINFO_R_ERROR;
2674 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2675 ptr = (metadata_x *)tmp->data;
2679 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2687 static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
2688 const char *appid, const char *app_control,
2689 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2691 static const char query[] =
2692 "SELECT privilege FROM package_app_app_control_privilege "
2693 "WHERE app_id=? AND app_control=?";
2698 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2699 if (ret != SQLITE_OK) {
2700 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2701 return PMINFO_R_ERROR;
2704 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_STATIC);
2705 if (ret != SQLITE_OK) {
2706 LOGE("bind failed: %s", sqlite3_errmsg(db));
2707 sqlite3_finalize(stmt);
2708 return PMINFO_R_ERROR;
2711 ret = sqlite3_bind_text(stmt, 2, app_control, -1, SQLITE_STATIC);
2712 if (ret != SQLITE_OK) {
2713 LOGE("bind failed: %s", sqlite3_errmsg(db));
2714 sqlite3_finalize(stmt);
2715 return PMINFO_R_ERROR;
2718 while (sqlite3_step(stmt) == SQLITE_ROW) {
2720 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2726 sqlite3_finalize(stmt);
2728 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2731 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
2732 const char *appid, const char *app_control,
2733 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2739 dbpath = getUserPkgParserDBPathUID(uid);
2741 return PMINFO_R_ERROR;
2743 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2745 if (ret != SQLITE_OK) {
2746 LOGE("open db failed: %s", sqlite3_errmsg(db));
2747 return PMINFO_R_ERROR;
2750 ret = _appinfo_foreach_appcontrol_privileges(db, appid, app_control,
2751 callback, user_data);
2752 sqlite3_close_v2(db);
2757 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
2758 const char *operation, const char *uri, const char *mime,
2759 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2760 void *user_data, uid_t uid)
2763 char app_control[BUFSIZE];
2765 if (appid == NULL || operation == NULL || privilege_func == NULL) {
2766 LOGE("invalid parameter");
2767 return PMINFO_R_EINVAL;
2770 snprintf(app_control, sizeof(app_control), "%s|%s|%s", operation,
2771 uri ? uri : "NULL", mime ? mime : "NULL");
2773 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
2774 appid, app_control, privilege_func, user_data);
2775 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2776 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
2777 appid, app_control, privilege_func, user_data);
2779 if (ret == PMINFO_R_ENOENT)
2785 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
2786 const char *operation, const char *uri, const char *mime,
2787 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2790 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
2791 operation, uri, mime, privilege_func, user_data,
2795 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2796 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2798 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2799 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2801 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2802 appcontrol_x *appcontrol;
2805 if (info->app_info == NULL)
2806 return PMINFO_R_ERROR;
2808 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2809 appcontrol = (appcontrol_x *)tmp->data;
2810 if (appcontrol == NULL)
2812 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2820 API int pkgmgrinfo_appinfo_foreach_background_category(
2821 pkgmgrinfo_appinfo_h handle,
2822 pkgmgrinfo_app_background_category_list_cb category_func,
2825 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2829 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2830 LOGE("invalid parameter");
2831 return PMINFO_R_EINVAL;
2834 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2835 category = (char *)tmp->data;
2836 if (category == NULL)
2839 if (category_func(category, user_data) < 0)
2846 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2847 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2850 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2851 splashscreen_x *splashscreen;
2855 if (info == NULL || info->app_info == NULL
2856 || splash_screen_func == NULL) {
2857 LOGE("invalid parameter");
2858 return PMINFO_R_EINVAL;
2861 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2862 splashscreen = (splashscreen_x *)tmp->data;
2863 if (splashscreen == NULL)
2865 ret = splash_screen_func(splashscreen->src,
2867 splashscreen->orientation,
2868 splashscreen->indicatordisplay,
2869 splashscreen->operation,
2870 splashscreen->color_depth,
2879 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2881 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2882 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2883 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2885 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2886 return PMINFO_R_ERROR;
2888 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2893 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2895 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2896 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2897 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2899 if (info->app_info == NULL || info->app_info->multiple == NULL)
2900 return PMINFO_R_ERROR;
2902 *multiple = _get_bool_value(info->app_info->multiple);
2907 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2909 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2910 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2911 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2913 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2914 return PMINFO_R_ERROR;
2916 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2921 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2923 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2924 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2925 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2927 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2928 return PMINFO_R_ERROR;
2930 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2935 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2937 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2938 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2939 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2941 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2942 return PMINFO_R_ERROR;
2944 *enabled = !_get_bool_value(info->app_info->is_disabled);
2949 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2951 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2952 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2953 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2955 if (info->app_info == NULL || info->app_info->onboot == NULL)
2956 return PMINFO_R_ERROR;
2958 *onboot = _get_bool_value(info->app_info->onboot);
2963 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
2965 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2966 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2967 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2969 if (info->app_info == NULL || info->app_info->autorestart == NULL)
2970 return PMINFO_R_ERROR;
2972 *autorestart = _get_bool_value(info->app_info->autorestart);
2977 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
2979 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2980 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2981 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2983 if (info->app_info == NULL || info->app_info->mainapp == NULL)
2984 return PMINFO_R_ERROR;
2986 *mainapp = _get_bool_value(info->app_info->mainapp);
2991 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2993 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2994 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2995 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2997 if (info->app_info == NULL || info->app_info->preload == NULL)
2998 return PMINFO_R_ERROR;
3000 *preload = _get_bool_value(info->app_info->preload);
3005 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
3007 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3008 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3009 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3011 if (info->app_info == NULL || info->app_info->submode == NULL)
3012 return PMINFO_R_ERROR;
3014 *submode = _get_bool_value(info->app_info->submode);
3019 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
3021 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3023 if (handle == NULL || process_pool == NULL) {
3024 LOGE("invalid parameter");
3025 return PMINFO_R_EINVAL;
3028 if (info->app_info == NULL)
3029 return PMINFO_R_ERROR;
3031 *process_pool = _get_bool_value(info->app_info->process_pool);
3036 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
3038 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3039 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
3040 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
3044 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3046 if (info->app_info == NULL)
3047 return PMINFO_R_ERROR;
3050 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
3051 val = (const char *)tmp->data;
3054 if (strcasecmp(val, category) == 0) {
3063 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
3066 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3068 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
3069 _LOGE("invalid parameter");
3070 return PMINFO_R_EINVAL;
3072 if (info->app_info->ui_gadget == NULL)
3073 info->app_info->ui_gadget = strdup("false");
3075 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
3080 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
3081 bool *support_disable)
3083 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3085 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
3086 _LOGE("invalid parameter");
3087 return PMINFO_R_EINVAL;
3090 *support_disable = _get_bool_value(info->app_info->support_disable);
3095 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
3098 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3100 if (info == NULL || info->app_info == NULL || removable == NULL) {
3101 _LOGE("invalid parameter");
3102 return PMINFO_R_EINVAL;
3105 *removable = _get_bool_value(info->app_info->removable);
3110 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
3112 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3114 if (info == NULL || info->app_info == NULL || system == NULL) {
3115 _LOGE("invalid parameter");
3116 return PMINFO_R_EINVAL;
3119 *system = _get_bool_value(info->app_info->package_system);
3124 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
3126 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3127 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3128 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3130 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
3131 return PMINFO_R_ERROR;
3133 *disabled = _get_bool_value(info->app_info->is_disabled);
3138 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
3140 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3142 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3143 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3145 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
3146 return PMINFO_R_ERROR;
3148 *global = _get_bool_value(info->app_info->for_all_users);
3153 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
3155 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3157 if (info == NULL || splash_screen_display == NULL) {
3158 _LOGE("Invalid parameter");
3159 return PMINFO_R_EINVAL;
3162 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
3163 return PMINFO_R_ERROR;
3165 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
3170 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
3172 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3174 if (info == NULL || setup_appid == NULL) {
3175 _LOGE("Invalid parameter");
3176 return PMINFO_R_EINVAL;
3179 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
3180 return PMINFO_R_ERROR;
3182 *setup_appid = info->app_info->setup_appid;
3186 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
3187 bool *support_ambient)
3189 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3191 if (info == NULL || support_ambient == NULL) {
3192 _LOGE("Invalid parameter");
3193 return PMINFO_R_EINVAL;
3196 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
3197 return PMINFO_R_ERROR;
3199 *support_ambient = _get_bool_value(info->app_info->support_ambient);
3204 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
3206 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3207 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3208 __cleanup_appinfo(info);
3212 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
3214 return (pkgmgrinfo_pkginfo_filter_create(handle));
3217 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
3219 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3222 static gint __compare_func(gconstpointer data1, gconstpointer data2)
3224 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
3225 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
3226 if (node1->prop == node2->prop)
3228 else if (node1->prop > node2->prop)
3234 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
3235 const char *property, const int value)
3237 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3238 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3239 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3241 GSList *link = NULL;
3243 prop = _pminfo_appinfo_convert_to_prop_int(property);
3244 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
3245 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
3246 _LOGE("Invalid Integer Property\n");
3247 return PMINFO_R_EINVAL;
3249 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3250 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3252 _LOGE("Out of Memory!!!\n");
3253 return PMINFO_R_ERROR;
3255 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3256 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3258 _LOGE("Out of Memory\n");
3261 return PMINFO_R_ERROR;
3265 /*If API is called multiple times for same property, we should override the previous values.
3266 Last value set will be used for filtering.*/
3267 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3269 filter->list = g_slist_delete_link(filter->list, link);
3270 filter->list = g_slist_append(filter->list, (gpointer)node);
3275 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
3276 const char *property, const bool value)
3278 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3279 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3281 GSList *link = NULL;
3283 prop = _pminfo_appinfo_convert_to_prop_bool(property);
3284 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
3285 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
3286 _LOGE("Invalid Boolean Property\n");
3287 return PMINFO_R_EINVAL;
3289 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3290 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3292 _LOGE("Out of Memory!!!\n");
3293 return PMINFO_R_ERROR;
3296 val = strndup("true", 4);
3298 val = strndup("false", 5);
3300 _LOGE("Out of Memory\n");
3303 return PMINFO_R_ERROR;
3307 /*If API is called multiple times for same property, we should override the previous values.
3308 Last value set will be used for filtering.*/
3309 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3311 filter->list = g_slist_delete_link(filter->list, link);
3312 filter->list = g_slist_append(filter->list, (gpointer)node);
3317 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
3318 const char *property, const char *value)
3320 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3321 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3322 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3324 pkgmgrinfo_node_x *ptr = NULL;
3325 char prev[PKG_STRING_LEN_MAX] = {'\0'};
3326 char temp[PKG_STRING_LEN_MAX] = {'\0'};
3327 GSList *link = NULL;
3329 prop = _pminfo_appinfo_convert_to_prop_str(property);
3330 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
3331 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
3332 _LOGE("Invalid String Property\n");
3333 return PMINFO_R_EINVAL;
3335 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3336 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3338 _LOGE("Out of Memory!!!\n");
3339 return PMINFO_R_ERROR;
3343 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
3344 node->value = strdup(value);
3345 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3347 filter->list = g_slist_delete_link(filter->list, link);
3348 filter->list = g_slist_append(filter->list, (gpointer)node);
3350 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
3351 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
3353 _LOGE("Out of Memory\n");
3356 return PMINFO_R_ERROR;
3358 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3360 ptr = (pkgmgrinfo_node_x *)link->data;
3361 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
3362 _LOGI("Previous value is %s\n", prev);
3363 filter->list = g_slist_delete_link(filter->list, link);
3364 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
3365 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3366 _LOGI("New value is %s\n", val);
3368 filter->list = g_slist_append(filter->list, (gpointer)node);
3369 memset(temp, '\0', PKG_STRING_LEN_MAX);
3371 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3372 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3373 _LOGI("First value is %s\n", val);
3375 filter->list = g_slist_append(filter->list, (gpointer)node);
3376 memset(temp, '\0', PKG_STRING_LEN_MAX);
3380 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3381 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3383 filter->list = g_slist_delete_link(filter->list, link);
3384 filter->list = g_slist_append(filter->list, (gpointer)node);
3390 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3396 if (handle == NULL || count == NULL) {
3397 _LOGE("invalid parameter");
3398 return PMINFO_R_EINVAL;
3401 locale = _get_system_locale();
3403 return PMINFO_R_ERROR;
3405 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3406 __free_applications);
3409 return PMINFO_R_ERROR;
3412 if (__check_disable_filter_exist(
3413 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3414 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3415 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
3416 g_hash_table_destroy(list);
3418 return PMINFO_R_ERROR;
3422 if (__check_disable_filter_exist(
3423 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3424 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3425 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
3426 g_hash_table_destroy(list);
3428 return PMINFO_R_ERROR;
3432 ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3433 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3434 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3437 if (ret != PMINFO_R_OK) {
3438 g_hash_table_destroy(list);
3440 return PMINFO_R_ERROR;
3443 *count = g_hash_table_size(list);
3444 g_hash_table_destroy(list);
3450 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3452 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3455 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3456 pkgmgrinfo_appinfo_filter_h handle,
3457 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3459 if (handle == NULL || app_cb == NULL) {
3460 LOGE("invalid parameter");
3461 return PMINFO_R_EINVAL;
3464 if (__check_disable_filter_exist(
3465 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3466 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3467 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3468 return PMINFO_R_ERROR;
3471 if (__check_disable_filter_exist(
3472 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3473 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3474 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3475 return PMINFO_R_ERROR;
3478 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3482 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3483 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3485 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3488 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3490 return (pkgmgrinfo_pkginfo_filter_create(handle));
3493 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3495 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3498 API int pkgmgrinfo_appinfo_metadata_filter_add(
3499 pkgmgrinfo_appinfo_metadata_filter_h handle,
3500 const char *key, const char *value)
3502 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3503 pkgmgrinfo_metadata_node_x *node;
3505 /* value can be NULL.
3506 * In that case all apps with specified key should be displayed
3509 LOGE("invalid parameter");
3510 return PMINFO_R_EINVAL;
3513 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3515 LOGE("out of memory");
3516 return PMINFO_R_ERROR;
3519 node->key = strdup(key);
3520 if (value && strlen(value))
3521 node->value = strdup(value);
3523 filter->list_metadata = g_slist_append(filter->list_metadata,
3529 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3530 pkgmgrinfo_appinfo_metadata_filter_h handle,
3531 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3533 if (handle == NULL || app_cb == NULL) {
3534 LOGE("invalid parameter");
3535 return PMINFO_R_EINVAL;
3538 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3539 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3540 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3541 return PMINFO_R_ERROR;
3543 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3544 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3545 return PMINFO_R_ERROR;
3547 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3551 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3552 pkgmgrinfo_appinfo_metadata_filter_h handle,
3553 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3555 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3556 user_data, _getuid());
3559 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3562 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3564 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3565 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3567 val = info->app_info->guestmode_visibility;
3568 *status = _get_bool_value(val);