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,
160 if (appcontrol_str == NULL)
163 dup = strdup(appcontrol_str);
165 _LOGE("out of memory");
170 ac = calloc(1, sizeof(appcontrol_x));
172 _LOGE("out of memory");
175 token = strtok_r(dup, "|", &ptr);
176 if (token && strcmp(token, "NULL"))
177 ac->operation = strdup(token);
178 token = strtok_r(NULL, "|", &ptr);
179 if (token && strcmp(token, "NULL"))
180 ac->uri = strdup(token);
181 token = strtok_r(NULL, "|", &ptr);
182 if (token && strcmp(token, "NULL"))
183 ac->mime = strdup(token);
184 ac->visibility = strdup(visibility);
185 *appcontrol = g_list_append(*appcontrol, ac);
186 } while ((token = strtok_r(NULL, ";", &ptr)));
191 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
194 static const char query_raw[] =
195 "SELECT app_control, visibility FROM package_app_app_control "
203 query = sqlite3_mprintf(query_raw, appid);
205 LOGE("out of memory");
206 return PMINFO_R_ERROR;
209 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
211 if (ret != SQLITE_OK) {
212 LOGE("prepare failed: %s", sqlite3_errmsg(db));
213 return PMINFO_R_ERROR;
216 while (sqlite3_step(stmt) == SQLITE_ROW) {
219 _save_column_str(stmt, 0, &str);
220 _save_column_str(stmt, 0, &visibility);
222 __parse_appcontrol(appcontrol, str, visibility);
227 sqlite3_finalize(stmt);
232 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
235 static const char query_raw[] =
236 "SELECT md_key, md_value "
237 "FROM package_app_app_metadata WHERE app_id=%Q";
244 query = sqlite3_mprintf(query_raw, appid);
246 LOGE("out of memory");
247 return PMINFO_R_ERROR;
250 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
252 if (ret != SQLITE_OK) {
253 LOGE("prepare failed: %s", sqlite3_errmsg(db));
254 return PMINFO_R_ERROR;
257 while (sqlite3_step(stmt) == SQLITE_ROW) {
258 info = calloc(1, sizeof(metadata_x));
260 LOGE("out of memory");
261 sqlite3_finalize(stmt);
262 return PMINFO_R_ERROR;
265 _save_column_str(stmt, idx++, &info->key);
266 _save_column_str(stmt, idx++, &info->value);
267 *metadata = g_list_append(*metadata, info);
270 sqlite3_finalize(stmt);
276 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
277 GList **splashscreens)
279 static const char query_raw[] =
280 "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
281 "FROM package_app_splash_screen WHERE app_id=%Q";
286 splashscreen_x *info;
288 query = sqlite3_mprintf(query_raw, appid);
290 LOGE("out of memory");
291 return PMINFO_R_ERROR;
294 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
296 if (ret != SQLITE_OK) {
297 LOGE("prepare failed: %s", sqlite3_errmsg(db));
298 return PMINFO_R_ERROR;
301 while (sqlite3_step(stmt) == SQLITE_ROW) {
302 info = calloc(1, sizeof(splashscreen_x));
304 LOGE("out of memory");
305 sqlite3_finalize(stmt);
306 return PMINFO_R_ERROR;
309 _save_column_str(stmt, idx++, &info->src);
310 _save_column_str(stmt, idx++, &info->type);
311 _save_column_str(stmt, idx++, &info->orientation);
312 _save_column_str(stmt, idx++, &info->indicatordisplay);
313 _save_column_str(stmt, idx++, &info->operation);
314 _save_column_str(stmt, idx++, &info->color_depth);
315 *splashscreens = g_list_append(*splashscreens, info);
318 sqlite3_finalize(stmt);
323 static GList *__get_background_category(const char *value)
325 GList *category_list = NULL;
326 int convert_value = 0;
327 if (!value || strlen(value) == 0)
330 convert_value = atoi(value);
331 if (convert_value < 0)
334 if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
335 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
337 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
339 if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
340 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
342 if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
343 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
345 if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
346 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
348 if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
349 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
351 if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
352 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
354 if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
355 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
357 if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
358 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
360 return category_list;
364 static void __free_applications(gpointer data)
366 pkgmgrinfo_basic_free_application((application_x *)data);
369 static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
371 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
372 pkgmgrinfo_appinfo_disable_type value = GPOINTER_TO_INT(data2);
374 if (value == E_APPINFO_DISABLE_TYPE_PKG)
375 return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
378 return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
382 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
383 pkgmgrinfo_appinfo_disable_type type)
390 link = g_slist_find_custom(filter->list, GINT_TO_POINTER(type), __disable_chk_func);
397 static int __bind_params(sqlite3_stmt *stmt, GList *params)
399 GList *tmp_list = NULL;
403 if (stmt == NULL || params == NULL)
404 return PMINFO_R_EINVAL;
408 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
409 if (ret != SQLITE_OK)
410 return PMINFO_R_ERROR;
411 tmp_list = tmp_list->next;
417 static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter)
419 GSList *tmp_list = NULL;
420 pkgmgrinfo_node_x *tmp_node = NULL;
423 if (tmp_filter == NULL)
426 property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
427 for (tmp_list = tmp_filter->list; tmp_list != NULL;
428 tmp_list = g_slist_next(tmp_list)) {
429 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
430 if (property == tmp_node->prop) {
431 if (strcmp(tmp_node->value, "true") == 0)
441 static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
442 const char *locale, pkgmgrinfo_filter_x *filter, int flag,
443 GHashTable *applications)
445 static const char query_raw[] =
446 "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
447 "ai.app_external_path";
448 static const char query_basic[] =
449 ", ai.app_component, ai.app_exec, "
450 "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
451 "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
452 "ai.app_hwacceleration, ai.app_screenreader, "
453 "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, "
454 "ai.app_indicatordisplay, ai.app_portraitimg, "
455 "ai.app_landscapeimg, ai.app_guestmodevisibility, "
456 "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
457 "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
458 "ai.app_support_disable, ai.app_process_pool, "
459 "ai.app_background_category, ai.app_package_type, "
460 "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
461 "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
462 "ai.app_zip_mount_file, ai.component_type, ai.package, "
463 "ai.app_package_system, ai.app_removable, "
464 "ai.app_package_installed_time, ai.app_support_mode, "
465 "ai.app_support_ambient, ai.app_setup_appid";
466 static const char query_uid_info[] =
467 ", ui.is_disabled, ui.is_splash_screen_enabled";
468 static const char query_label[] =
470 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
471 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
472 static const char query_icon[] =
474 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
475 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
476 static const char query_from_clause[] = " FROM package_app_info as ai";
477 static const char query_uid_info_clause[] =
478 " LEFT OUTER JOIN package_app_info_for_uid AS ui "
479 "ON (ai.app_id=ui.app_id AND ui.uid=?)";
480 int ret = PMINFO_R_ERROR;
483 char *bg_category_str = NULL;
484 char *constraint = NULL;
485 char *tmp_record = NULL;
486 char query[MAX_QUERY_LEN] = { '\0' };
487 char buf[BUFSIZE] = { '\0' };
488 application_x *info = NULL;
489 GList *bind_params = NULL;
491 sqlite3_stmt *stmt = NULL;
492 bool is_check_storage = true;
493 const uid_t global_user_uid = GLOBAL_USER;
495 dbpath = getUserPkgParserDBPathUID(db_uid);
497 return PMINFO_R_ERROR;
499 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
500 if (ret != SQLITE_OK) {
501 _LOGE("failed to open db(%s): %d", dbpath, ret);
503 return PMINFO_R_ERROR;
507 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
509 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
510 strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
511 strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1);
513 if (flag & PMINFO_APPINFO_GET_LABEL) {
514 strncat(query, query_label, sizeof(query) - strlen(query) - 1);
515 bind_params = g_list_append(bind_params, strdup(locale));
517 if (flag & PMINFO_APPINFO_GET_ICON) {
518 strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
519 bind_params = g_list_append(bind_params, strdup(locale));
522 snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
523 bind_params = g_list_append(bind_params, strdup(buf));
525 is_check_storage = __check_app_storage_status(filter);
527 ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
528 if (ret != PMINFO_R_OK) {
529 LOGE("Failed to get WHERE clause");
532 strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
534 strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1);
537 strncat(query, constraint, sizeof(query) - strlen(query) - 1);
539 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
540 if (ret != SQLITE_OK) {
541 LOGE("prepare failed: %s", sqlite3_errmsg(db));
542 ret = PMINFO_R_ERROR;
546 if (g_list_length(bind_params) != 0) {
547 ret = __bind_params(stmt, bind_params);
548 if (ret != SQLITE_OK) {
549 LOGE("Failed to bind parameters");
554 while (sqlite3_step(stmt) == SQLITE_ROW) {
555 info = calloc(1, sizeof(application_x));
557 LOGE("out of memory");
558 ret = PMINFO_R_ERROR;
562 _save_column_str(stmt, idx++, &info->appid);
563 _save_column_str(stmt, idx++, &info->installed_storage);
564 _save_column_str(stmt, idx++ , &info->external_path);
566 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
567 _save_column_str(stmt, idx++, &info->component);
568 _save_column_str(stmt, idx++, &info->exec);
569 _save_column_str(stmt, idx++, &info->nodisplay);
570 _save_column_str(stmt, idx++, &info->type);
571 _save_column_str(stmt, idx++, &info->onboot);
572 _save_column_str(stmt, idx++, &info->multiple);
573 _save_column_str(stmt, idx++, &info->autorestart);
574 _save_column_str(stmt, idx++, &info->taskmanage);
575 _save_column_str(stmt, idx++, &info->hwacceleration);
576 _save_column_str(stmt, idx++, &info->screenreader);
577 _save_column_str(stmt, idx++, &info->mainapp);
578 _save_column_str(stmt, idx++, &info->recentimage);
579 _save_column_str(stmt, idx++, &info->launchcondition);
580 _save_column_str(stmt, idx++, &info->indicatordisplay);
581 _save_column_str(stmt, idx++, &info->portraitimg);
582 _save_column_str(stmt, idx++, &info->landscapeimg);
583 _save_column_str(stmt, idx++, &info->guestmode_visibility);
584 _save_column_str(stmt, idx++, &info->permission_type);
585 _save_column_str(stmt, idx++, &info->preload);
586 _save_column_str(stmt, idx++, &info->submode);
587 _save_column_str(stmt, idx++, &info->submode_mainid);
588 _save_column_str(stmt, idx++, &info->launch_mode);
589 _save_column_str(stmt, idx++, &info->ui_gadget);
590 _save_column_str(stmt, idx++, &info->support_disable);
591 _save_column_str(stmt, idx++, &info->process_pool);
592 _save_column_str(stmt, idx++, &bg_category_str);
593 _save_column_str(stmt, idx++, &info->package_type);
594 _save_column_str(stmt, idx++, &info->root_path);
595 _save_column_str(stmt, idx++, &info->api_version);
596 _save_column_str(stmt, idx++, &info->effective_appid);
597 _save_column_str(stmt, idx++, &info->is_disabled);
598 _save_column_str(stmt, idx++, &info->splash_screen_display);
599 _save_column_str(stmt, idx++, &info->tep_name);
600 _save_column_str(stmt, idx++, &info->zip_mount_file);
601 _save_column_str(stmt, idx++, &info->component_type);
602 _save_column_str(stmt, idx++, &info->package);
603 _save_column_str(stmt, idx++, &info->package_system);
604 _save_column_str(stmt, idx++, &info->removable);
605 _save_column_str(stmt, idx++, &info->package_installed_time);
606 _save_column_str(stmt, idx++, &info->support_mode);
607 _save_column_str(stmt, idx++, &info->support_ambient);
608 _save_column_str(stmt, idx++, &info->setup_appid);
609 info->background_category = __get_background_category(
611 free(bg_category_str);
614 info->for_all_users =
615 strdup((db_uid != global_user_uid) ? "false" : "true");
617 if (db_uid != global_user_uid) {
621 _save_column_str(stmt, idx++, &tmp_record);
622 if (tmp_record != NULL) {
623 if (strcasecmp(info->is_disabled, "false") == 0 &&
624 strcasecmp(tmp_record, "false") == 0) {
625 free(info->is_disabled);
626 info->is_disabled = tmp_record;
632 _save_column_str(stmt, idx++, &tmp_record);
633 if (tmp_record != NULL) {
634 if (strcasecmp(info->splash_screen_display, "false") == 0 &&
635 strcasecmp(tmp_record, "false") == 0) {
636 free(info->splash_screen_display);
637 info->splash_screen_display = tmp_record;
644 if (flag & PMINFO_APPINFO_GET_LABEL) {
646 _save_column_str(stmt, idx++, &tmp_record);
647 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
648 ret = PMINFO_R_ERROR;
653 if (flag & PMINFO_APPINFO_GET_ICON) {
655 _save_column_str(stmt, idx++, &tmp_record);
656 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
657 ret = PMINFO_R_ERROR;
662 if (flag & PMINFO_APPINFO_GET_CATEGORY) {
663 if (_appinfo_get_category(db, info->appid,
665 ret = PMINFO_R_ERROR;
670 if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
671 if (_appinfo_get_app_control(db, info->appid,
672 &info->appcontrol)) {
673 ret = PMINFO_R_ERROR;
678 if (flag & PMINFO_APPINFO_GET_METADATA) {
679 if (_appinfo_get_metadata(db, info->appid,
681 ret = PMINFO_R_ERROR;
686 if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
687 if (_appinfo_get_splashscreens(db, info->appid,
688 &info->splashscreens)) {
689 ret = PMINFO_R_ERROR;
694 if (is_check_storage &&
695 __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
696 ret = PMINFO_R_ERROR;
697 pkgmgrinfo_basic_free_application(info);
702 g_hash_table_insert(applications, (gpointer)info->appid,
712 if (ret != PMINFO_R_OK && info != NULL)
713 pkgmgrinfo_basic_free_application(info);
715 g_list_free_full(bind_params, free);
716 sqlite3_close_v2(db);
717 sqlite3_finalize(stmt);
722 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
723 pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
728 pkgmgr_appinfo_x *info;
730 if (appid == NULL || filter == NULL || handle == NULL) {
731 LOGE("invalid parameter");
732 return PMINFO_R_EINVAL;
735 locale = _get_system_locale();
737 return PMINFO_R_ERROR;
739 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
740 __free_applications);
743 return PMINFO_R_ERROR;
746 ret = _appinfo_get_applications(uid, uid, locale, filter,
747 PMINFO_APPINFO_GET_ALL, list);
748 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
749 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
750 PMINFO_APPINFO_GET_ALL, list);
752 if (ret != PMINFO_R_OK) {
753 g_hash_table_destroy(list);
758 if (!g_hash_table_size(list)) {
759 _LOGD("appinfo for [%s] is not existed for user [%d]",
761 g_hash_table_destroy(list);
763 return PMINFO_R_ENOENT;
766 info = calloc(1, sizeof(pkgmgr_appinfo_x));
768 _LOGE("out of memory");
769 g_hash_table_destroy(list);
771 return PMINFO_R_ERROR;
774 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
775 info->locale = locale;
776 info->package = strdup(info->app_info->package);
778 /* just free list only */
779 g_hash_table_steal(list, (gconstpointer)appid);
780 g_hash_table_destroy(list);
787 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
788 pkgmgrinfo_appinfo_h *handle)
791 pkgmgrinfo_appinfo_filter_h filter;
793 if (appid == NULL || handle == NULL) {
794 LOGE("invalid parameter");
795 return PMINFO_R_EINVAL;
798 ret = pkgmgrinfo_appinfo_filter_create(&filter);
799 if (ret != PMINFO_R_OK)
802 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
803 PMINFO_APPINFO_PROP_APP_ID, appid);
804 if (ret != PMINFO_R_OK) {
805 pkgmgrinfo_appinfo_filter_destroy(filter);
806 return PMINFO_R_ERROR;
809 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
810 PMINFO_APPINFO_PROP_APP_DISABLE, true);
811 if (ret != PMINFO_R_OK) {
812 pkgmgrinfo_appinfo_filter_destroy(filter);
813 return PMINFO_R_ERROR;
816 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
817 pkgmgrinfo_appinfo_filter_destroy(filter);
822 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
824 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
827 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
828 pkgmgrinfo_appinfo_h *handle)
831 pkgmgrinfo_appinfo_filter_h filter;
833 if (appid == NULL || handle == NULL) {
834 LOGE("invalid parameter");
835 return PMINFO_R_EINVAL;
838 ret = pkgmgrinfo_appinfo_filter_create(&filter);
839 if (ret != PMINFO_R_OK)
842 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
843 PMINFO_APPINFO_PROP_APP_ID, appid);
844 if (ret != PMINFO_R_OK) {
845 pkgmgrinfo_appinfo_filter_destroy(filter);
846 return PMINFO_R_ERROR;
849 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
850 PMINFO_APPINFO_PROP_APP_DISABLE, false);
851 if (ret != PMINFO_R_OK) {
852 pkgmgrinfo_appinfo_filter_destroy(filter);
853 return PMINFO_R_ERROR;
856 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
857 PMINFO_APPINFO_PROP_PKG_DISABLE, false);
858 if (ret != PMINFO_R_OK) {
859 pkgmgrinfo_appinfo_filter_destroy(filter);
860 return PMINFO_R_ERROR;
863 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
864 pkgmgrinfo_appinfo_filter_destroy(filter);
868 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
870 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
873 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
874 pkgmgrinfo_appinfo_h *handle)
877 pkgmgrinfo_appinfo_filter_h filter;
879 if (appid == NULL || handle == NULL) {
880 LOGE("invalid parameter");
881 return PMINFO_R_EINVAL;
884 ret = pkgmgrinfo_appinfo_filter_create(&filter);
885 if (ret != PMINFO_R_OK)
888 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
889 PMINFO_APPINFO_PROP_APP_ID, appid);
890 if (ret != PMINFO_R_OK) {
891 pkgmgrinfo_appinfo_filter_destroy(filter);
892 return PMINFO_R_ERROR;
895 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
896 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
897 if (ret != PMINFO_R_OK) {
898 pkgmgrinfo_appinfo_filter_destroy(filter);
899 return PMINFO_R_ERROR;
902 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
903 pkgmgrinfo_appinfo_filter_destroy(filter);
908 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
910 return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
913 static gpointer __copy_str(gconstpointer src, gpointer data)
915 const char *tmp = (const char *)src;
918 buffer = strdup(tmp);
919 if (buffer == NULL) {
920 LOGE("memory alloc failed");
928 static gpointer __copy_label(gconstpointer src, gpointer data)
930 label_x *tmp = (label_x *)src;
933 label = calloc(1, sizeof(label_x));
935 LOGE("memory alloc failed");
941 label->name = strdup(tmp->name);
943 label->text = strdup(tmp->text);
945 label->lang = strdup(tmp->lang);
950 static gpointer __copy_icon(gconstpointer src, gpointer data)
952 icon_x *tmp = (icon_x *)src;
955 icon = calloc(1, sizeof(icon_x));
957 LOGE("memory alloc failed");
963 icon->text = strdup(tmp->text);
965 icon->lang = strdup(tmp->lang);
967 icon->section = strdup(tmp->section);
969 icon->size = strdup(tmp->size);
971 icon->resolution = strdup(tmp->resolution);
976 static gpointer __copy_metadata(gconstpointer src, gpointer data)
978 metadata_x *tmp = (metadata_x *)src;
979 metadata_x *metadata;
981 metadata = calloc(1, sizeof(metadata_x));
982 if (metadata == NULL) {
983 LOGE("memory alloc failed");
989 metadata->key = strdup(tmp->key);
991 metadata->value = strdup(tmp->value);
996 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
998 datacontrol_x *tmp = (datacontrol_x *)src;
999 datacontrol_x *datacontrol;
1001 datacontrol = calloc(1, sizeof(datacontrol_x));
1002 if (datacontrol == NULL) {
1003 LOGE("memory alloc failed");
1008 if (tmp->providerid)
1009 datacontrol->providerid = strdup(tmp->providerid);
1011 datacontrol->access = strdup(tmp->access);
1013 datacontrol->type = strdup(tmp->type);
1015 datacontrol->trusted = strdup(tmp->trusted);
1020 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1022 appcontrol_x *tmp = (appcontrol_x *)src;
1023 appcontrol_x *appcontrol;
1025 appcontrol = calloc(1, sizeof(appcontrol_x));
1026 if (appcontrol == NULL) {
1027 LOGE("memory alloc failed");
1033 appcontrol->operation = strdup(tmp->operation);
1035 appcontrol->uri = strdup(tmp->uri);
1037 appcontrol->mime = strdup(tmp->mime);
1042 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1044 splashscreen_x *tmp = (splashscreen_x *)src;
1045 splashscreen_x *splashscreen;
1047 splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1048 if (splashscreen == NULL) {
1049 LOGE("memory alloc failed");
1055 splashscreen->src = strdup(tmp->src);
1057 splashscreen->type = strdup(tmp->type);
1058 if (tmp->orientation)
1059 splashscreen->orientation = strdup(tmp->orientation);
1060 if (tmp->indicatordisplay)
1061 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1063 splashscreen->operation = strdup(tmp->operation);
1064 if (tmp->color_depth)
1065 splashscreen->color_depth = strdup(tmp->color_depth);
1067 return splashscreen;
1070 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1072 application_x *app_info;
1075 app_info = calloc(1, sizeof(application_x));
1076 if (app_info == NULL) {
1077 LOGE("memory alloc failed");
1078 return PMINFO_R_ERROR;
1081 if (data->appid != NULL)
1082 app_info->appid = strdup(data->appid);
1083 if (data->exec != NULL)
1084 app_info->exec = strdup(data->exec);
1085 if (data->nodisplay != NULL)
1086 app_info->nodisplay = strdup(data->nodisplay);
1087 if (data->multiple != NULL)
1088 app_info->multiple = strdup(data->multiple);
1089 if (data->taskmanage != NULL)
1090 app_info->taskmanage = strdup(data->taskmanage);
1091 if (data->type != NULL)
1092 app_info->type = strdup(data->type);
1093 if (data->categories != NULL)
1094 app_info->categories = strdup(data->categories);
1095 if (data->hwacceleration != NULL)
1096 app_info->hwacceleration = strdup(data->hwacceleration);
1097 if (data->screenreader != NULL)
1098 app_info->screenreader = strdup(data->screenreader);
1099 if (data->mainapp != NULL)
1100 app_info->mainapp = strdup(data->mainapp);
1101 if (data->package != NULL)
1102 app_info->package = strdup(data->package);
1103 if (data->recentimage != NULL)
1104 app_info->recentimage = strdup(data->recentimage);
1105 if (data->launchcondition != NULL)
1106 app_info->launchcondition = strdup(data->launchcondition);
1107 if (data->indicatordisplay != NULL)
1108 app_info->indicatordisplay = strdup(data->indicatordisplay);
1109 if (data->portraitimg != NULL)
1110 app_info->portraitimg = strdup(data->portraitimg);
1111 if (data->landscapeimg != NULL)
1112 app_info->landscapeimg = strdup(data->landscapeimg);
1113 if (data->guestmode_visibility != NULL)
1114 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1115 if (data->component != NULL)
1116 app_info->component = strdup(data->component);
1117 if (data->permission_type != NULL)
1118 app_info->permission_type = strdup(data->permission_type);
1119 if (data->component_type != NULL)
1120 app_info->component_type = strdup(data->component_type);
1121 if (data->preload != NULL)
1122 app_info->preload = strdup(data->preload);
1123 if (data->submode != NULL)
1124 app_info->submode = strdup(data->submode);
1125 if (data->submode_mainid != NULL)
1126 app_info->submode_mainid = strdup(data->submode_mainid);
1127 if (data->process_pool != NULL)
1128 app_info->process_pool = strdup(data->process_pool);
1129 if (data->installed_storage != NULL)
1130 app_info->installed_storage = strdup(data->installed_storage);
1131 if (data->autorestart != NULL)
1132 app_info->autorestart = strdup(data->autorestart);
1133 if (data->onboot != NULL)
1134 app_info->onboot = strdup(data->onboot);
1135 if (data->support_disable != NULL)
1136 app_info->support_disable = strdup(data->support_disable);
1137 if (data->ui_gadget != NULL)
1138 app_info->ui_gadget = strdup(data->ui_gadget);
1139 if (data->launch_mode != NULL)
1140 app_info->launch_mode = strdup(data->launch_mode);
1141 if (data->package_type != NULL)
1142 app_info->package_type = strdup(data->package_type);
1143 if (data->effective_appid != NULL)
1144 app_info->effective_appid = strdup(data->effective_appid);
1145 if (data->splash_screen_display != NULL)
1146 app_info->splash_screen_display = strdup(data->splash_screen_display);
1150 app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1152 LOGE("memory alloc failed");
1153 pkgmgrinfo_basic_free_application(app_info);
1154 return PMINFO_R_ERROR;
1158 app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1160 LOGE("memory alloc failed");
1161 pkgmgrinfo_basic_free_application(app_info);
1162 return PMINFO_R_ERROR;
1166 app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1168 LOGE("memory alloc failed");
1169 pkgmgrinfo_basic_free_application(app_info);
1170 return PMINFO_R_ERROR;
1174 app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1176 LOGE("memory alloc failed");
1177 pkgmgrinfo_basic_free_application(app_info);
1178 return PMINFO_R_ERROR;
1182 app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1184 LOGE("memory alloc failed");
1185 pkgmgrinfo_basic_free_application(app_info);
1186 return PMINFO_R_ERROR;
1190 app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1192 LOGE("memory alloc failed");
1193 pkgmgrinfo_basic_free_application(app_info);
1194 return PMINFO_R_ERROR;
1198 app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1200 LOGE("memory alloc failed");
1201 pkgmgrinfo_basic_free_application(app_info);
1202 return PMINFO_R_ERROR;
1206 app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1208 LOGE("memory alloc failed");
1209 pkgmgrinfo_basic_free_application(app_info);
1210 return PMINFO_R_ERROR;
1213 *application = app_info;
1218 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1219 pkgmgrinfo_appinfo_h *clone)
1221 pkgmgr_appinfo_x *info;
1222 pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1225 return PMINFO_R_EINVAL;
1227 info = calloc(1, sizeof(pkgmgr_appinfo_x));
1229 LOGE("memory alloc failed");
1230 return PMINFO_R_ERROR;
1233 if (temp->package != NULL)
1234 info->package = strdup(temp->package);
1235 if (temp->locale != NULL)
1236 info->locale = strdup(temp->locale);
1238 info->app_component = temp->app_component;
1240 if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1241 LOGE("appinfo copy failed");
1243 free((void *)info->package);
1247 return PMINFO_R_ERROR;
1255 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1256 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1262 pkgmgr_appinfo_x info;
1264 GHashTableIter iter;
1267 locale = _get_system_locale();
1269 return PMINFO_R_ERROR;
1271 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1272 __free_applications);
1275 return PMINFO_R_ERROR;
1278 ret = _appinfo_get_applications(uid, uid, locale, filter,
1279 flag | PMINFO_APPINFO_GET_BASICINFO, list);
1280 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1281 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1282 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1284 if (ret != PMINFO_R_OK) {
1285 g_hash_table_destroy(list);
1290 g_hash_table_iter_init(&iter, list);
1291 while (g_hash_table_iter_next(&iter, NULL, &value)) {
1292 app = (application_x *)value;
1293 info.app_info = app;
1294 info.locale = locale;
1295 info.package = app->package;
1296 if (app_list_cb(&info, user_data) < 0)
1299 g_hash_table_destroy(list);
1305 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1307 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1308 pkgmgrinfo_app_component component,
1309 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1312 pkgmgrinfo_appinfo_filter_h filter;
1314 const char *comp_str = NULL;
1316 if (handle == NULL || app_func == NULL) {
1317 LOGE("invalid parameter");
1318 return PMINFO_R_EINVAL;
1321 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1322 LOGE("invalid parameter");
1323 return PMINFO_R_EINVAL;
1326 if (pkgmgrinfo_appinfo_filter_create(&filter))
1327 return PMINFO_R_ERROR;
1329 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1330 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1331 pkgmgrinfo_appinfo_filter_destroy(filter);
1332 return PMINFO_R_ERROR;
1335 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1336 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1337 pkgmgrinfo_appinfo_filter_destroy(filter);
1338 return PMINFO_R_ERROR;
1341 comp_str = __appcomponent_str(component);
1344 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1345 PMINFO_APPINFO_PROP_APP_COMPONENT,
1347 pkgmgrinfo_appinfo_filter_destroy(filter);
1348 return PMINFO_R_ERROR;
1352 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1353 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1355 pkgmgrinfo_appinfo_filter_destroy(filter);
1360 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1361 pkgmgrinfo_app_component component,
1362 pkgmgrinfo_app_list_cb app_func, void *user_data)
1364 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1367 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1368 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1372 pkgmgrinfo_appinfo_filter_h filter;
1374 if (app_func == NULL) {
1375 LOGE("invalid parameter");
1376 return PMINFO_R_EINVAL;
1379 if (pkgmgrinfo_appinfo_filter_create(&filter))
1380 return PMINFO_R_ERROR;
1382 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1383 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1384 pkgmgrinfo_appinfo_filter_destroy(filter);
1385 return PMINFO_R_ERROR;
1388 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1389 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1390 pkgmgrinfo_appinfo_filter_destroy(filter);
1391 return PMINFO_R_ERROR;
1394 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1395 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1396 pkgmgrinfo_appinfo_filter_destroy(filter);
1397 return PMINFO_R_ERROR;
1400 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1403 pkgmgrinfo_appinfo_filter_destroy(filter);
1408 API int pkgmgrinfo_appinfo_get_installed_list_full(
1409 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1411 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1412 _getuid(), flag, user_data);
1415 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1416 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1419 pkgmgrinfo_appinfo_filter_h filter;
1421 if (app_func == NULL) {
1422 LOGE("invalid parameter");
1423 return PMINFO_R_EINVAL;
1426 /* create an empty filter */
1427 ret = pkgmgrinfo_appinfo_filter_create(&filter);
1428 if (ret != PMINFO_R_OK)
1431 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1432 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1433 pkgmgrinfo_appinfo_filter_destroy(filter);
1434 return PMINFO_R_ERROR;
1437 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1438 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1439 pkgmgrinfo_appinfo_filter_destroy(filter);
1440 return PMINFO_R_ERROR;
1443 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1444 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1446 pkgmgrinfo_appinfo_filter_destroy(filter);
1451 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1454 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1458 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1460 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1462 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1463 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1465 if (info->app_info == NULL || info->app_info->appid == NULL)
1466 return PMINFO_R_ERROR;
1467 *appid = (char *)info->app_info->appid;
1472 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1474 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1476 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1477 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1479 if (info->package == NULL)
1480 return PMINFO_R_ERROR;
1482 *pkg_name = (char *)info->package;
1487 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1489 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1491 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1492 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1494 if (info->package == NULL)
1495 return PMINFO_R_ERROR;
1497 *pkgid = (char *)info->package;
1502 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1504 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1505 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1506 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1508 *pkgtype = (char *)info->app_info->package_type;
1513 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1515 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1517 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1518 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1520 if (info->app_info == NULL || info->app_info->exec == NULL)
1521 return PMINFO_R_ERROR;
1522 *exec = (char *)info->app_info->exec;
1528 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1531 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1533 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1534 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1536 if (info->app_info == NULL)
1537 return PMINFO_R_ERROR;
1539 if (info->app_info->icon == NULL) {
1544 ptr = (icon_x *)info->app_info->icon->data;
1546 return PMINFO_R_ERROR;
1548 if (ptr->text == NULL)
1549 return PMINFO_R_ERROR;
1557 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1560 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1565 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1566 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1568 if (info->app_info == NULL)
1569 return PMINFO_R_ERROR;
1571 locale = info->locale;
1573 locale = DEFAULT_LOCALE;
1575 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1576 ptr = (label_x *)tmp->data;
1577 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
1588 for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1589 ptr = (label_x *)tmp->data;
1590 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
1596 *label = lbl ? lbl : "";
1601 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1603 char *result = NULL;
1605 sqlite3_stmt *stmt = NULL;
1610 parser_db = getUserPkgParserDBPathUID(uid);
1611 if (parser_db == NULL) {
1612 _LOGE("Failed to get parser db path");
1616 if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1617 _LOGE("DB open fail\n");
1623 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1624 if (query == NULL) {
1625 _LOGE("Out of memory");
1629 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1630 _LOGE("prepare_v2 fail\n");
1634 if (sqlite3_step(stmt) == SQLITE_ROW) {
1635 val = (char *)sqlite3_column_text(stmt, 0);
1637 result = strdup(val);
1641 sqlite3_finalize(stmt);
1642 sqlite3_free(query);
1648 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1652 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1654 val = _get_localed_label(appid, locale, uid);
1656 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1659 val = _get_localed_label(appid, locale, GLOBAL_USER);
1661 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1665 return PMINFO_R_ERROR;
1672 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1674 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1677 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1679 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1680 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1681 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1683 GList *list_md = NULL;
1684 metadata_x *metadata = NULL;
1685 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1687 list_md = info->app_info->metadata;
1689 for (; list_md; list_md = list_md->next) {
1690 metadata = (metadata_x *)list_md->data;
1691 if (metadata && metadata->key) {
1692 if (strcasecmp(metadata->key, metadata_key) == 0) {
1693 if (metadata->value == NULL)
1694 *metadata_value = "";
1696 *metadata_value = (char *)metadata->value;
1702 return PMINFO_R_EINVAL;
1705 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1707 if (strcasecmp(comp, "uiapp") == 0)
1708 return PMINFO_UI_APP;
1709 else if (strcasecmp(comp, "svcapp") == 0)
1710 return PMINFO_SVC_APP;
1711 else if (strcasecmp(comp, "widgetapp") == 0)
1712 return PMINFO_WIDGET_APP;
1713 else if (strcasecmp(comp, "watchapp") == 0)
1714 return PMINFO_WATCH_APP;
1719 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1724 case PMINFO_SVC_APP:
1726 case PMINFO_WIDGET_APP:
1728 case PMINFO_WATCH_APP:
1735 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1737 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1740 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1741 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1743 if (info->app_info == NULL)
1744 return PMINFO_R_ERROR;
1746 comp = __appcomponent_convert(info->app_info->component);
1748 return PMINFO_R_ERROR;
1755 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1757 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1759 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1760 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1762 if (info->app_info == NULL || info->app_info->type == NULL)
1763 return PMINFO_R_ERROR;
1764 *app_type = (char *)info->app_info->type;
1769 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1770 int *operation_count, char ***operation)
1772 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1773 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1774 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1775 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1776 *operation_count = data->operation_count;
1777 *operation = data->operation;
1781 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1782 int *uri_count, char ***uri)
1784 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1785 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1786 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1787 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1788 *uri_count = data->uri_count;
1793 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1794 int *mime_count, char ***mime)
1796 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1797 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1798 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1799 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1800 *mime_count = data->mime_count;
1805 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1806 int *subapp_count, char ***subapp)
1808 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1809 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1810 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1811 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1812 *subapp_count = data->subapp_count;
1813 *subapp = data->subapp;
1817 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1822 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1824 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1825 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1827 if (info->app_info == NULL)
1828 return PMINFO_R_ERROR;
1830 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1831 ptr = (icon_x *)tmp->data;
1832 if (ptr == NULL || ptr->section == NULL)
1835 val = (char *)ptr->section;
1836 if (val && strcmp(val, "notification") == 0) {
1837 *icon = (char *)ptr->text;
1842 return PMINFO_R_ERROR;
1845 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1848 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1850 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1851 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1853 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1854 return PMINFO_R_ERROR;
1856 val = (char *)info->app_info->recentimage;
1857 if (strcasecmp(val, "capture") == 0)
1858 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1859 else if (strcasecmp(val, "icon") == 0)
1860 *type = PMINFO_RECENTIMAGE_USE_ICON;
1862 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1867 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1872 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1874 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1875 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1877 if (info->app_info == NULL)
1878 return PMINFO_R_ERROR;
1880 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1881 ptr = (image_x *)tmp->data;
1882 if (ptr == NULL || ptr->section == NULL)
1885 val = (char *)ptr->section;
1886 if (val && strcmp(val, "preview") == 0) {
1887 *preview_img = (char *)ptr->text;
1892 return PMINFO_R_ERROR;
1895 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1898 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1900 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1901 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1903 val = info->app_info->permission_type;
1905 return PMINFO_R_ERROR;
1907 if (strcmp(val, "signature") == 0)
1908 *permission = PMINFO_PERMISSION_SIGNATURE;
1909 else if (strcmp(val, "privilege") == 0)
1910 *permission = PMINFO_PERMISSION_PRIVILEGE;
1912 *permission = PMINFO_PERMISSION_NORMAL;
1917 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1919 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1921 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1922 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1924 if (info->app_info == NULL || info->app_info->component_type == NULL)
1925 return PMINFO_R_ERROR;
1927 *component_type = (char *)info->app_info->component_type;
1932 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1935 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1937 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1938 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1940 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1941 return PMINFO_R_ERROR;
1943 val = (char *)info->app_info->hwacceleration;
1944 if (strcasecmp(val, "off") == 0)
1945 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1946 else if (strcasecmp(val, "on") == 0)
1947 *hwacceleration = PMINFO_HWACCELERATION_ON;
1949 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1954 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1957 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1959 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1960 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1962 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1963 return PMINFO_R_ERROR;
1965 val = (char *)info->app_info->screenreader;
1966 if (strcasecmp(val, "screenreader-off") == 0)
1967 *screenreader = PMINFO_SCREENREADER_OFF;
1968 else if (strcasecmp(val, "screenreader-on") == 0)
1969 *screenreader = PMINFO_SCREENREADER_ON;
1971 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1976 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1978 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1980 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1981 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1982 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1984 if (info->app_info == NULL)
1985 return PMINFO_R_ERROR;
1987 if (info->app_info->portraitimg == NULL)
1990 *portrait_img = (char *)info->app_info->portraitimg;
1992 if (info->app_info->landscapeimg == NULL)
1993 *landscape_img = "";
1995 *landscape_img = (char *)info->app_info->landscapeimg;
2000 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
2002 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2004 if (handle == NULL || effectimage_type == NULL) {
2005 LOGE("invalid parameter");
2006 return PMINFO_R_EINVAL;
2009 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
2010 return PMINFO_R_ERROR;
2012 *effectimage_type = (char *)info->app_info->effectimage_type;
2017 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
2019 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2021 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2022 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2024 if (info->app_info == NULL)
2025 return PMINFO_R_ERROR;
2027 if (info->app_info->submode_mainid == NULL)
2028 *submode_mainid = "";
2030 *submode_mainid = (char *)info->app_info->submode_mainid;
2035 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2037 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2038 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2040 if (info->app_info && info->app_info->installed_storage) {
2041 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2042 *storage = PMINFO_INTERNAL_STORAGE;
2043 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2044 *storage = PMINFO_EXTERNAL_STORAGE;
2046 return PMINFO_R_ERROR;
2048 return PMINFO_R_ERROR;
2054 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2056 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2059 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2061 if (info->app_info->launch_mode == NULL)
2062 return PMINFO_R_ERROR;
2064 *mode = (char *)(info->app_info->launch_mode);
2069 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2071 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2073 if (handle == NULL || alias_appid == NULL) {
2074 LOGE("invalid parameter");
2075 return PMINFO_R_EINVAL;
2078 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2079 return PMINFO_R_ERROR;
2081 *alias_appid = (char *)info->app_info->alias_appid;
2086 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2088 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2090 if (handle == NULL || effective_appid == NULL) {
2091 LOGE("invalid parameter");
2092 return PMINFO_R_EINVAL;
2095 if (info->app_info == NULL)
2096 return PMINFO_R_ERROR;
2098 if (info->app_info->effective_appid == NULL)
2099 *effective_appid = "";
2101 *effective_appid = (char *)info->app_info->effective_appid;
2106 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2108 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2110 if (handle == NULL || tep_name == NULL) {
2111 LOGE("invalid parameter");
2112 return PMINFO_R_EINVAL;
2115 if (info->app_info == NULL)
2116 return PMINFO_R_ERROR;
2118 if (info->app_info->tep_name == NULL)
2121 *tep_name = (char *)info->app_info->tep_name;
2126 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2128 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2130 if (handle == NULL || zip_mount_file == NULL) {
2131 LOGE("invalid parameter");
2132 return PMINFO_R_EINVAL;
2135 if (info->app_info == NULL)
2136 return PMINFO_R_ERROR;
2138 if (info->app_info->zip_mount_file == NULL)
2139 *zip_mount_file = "";
2141 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2146 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2148 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2150 if (handle == NULL || root_path == NULL) {
2151 LOGE("invalid parameter");
2152 return PMINFO_R_EINVAL;
2155 if (info->app_info == NULL || info->app_info->root_path == NULL)
2156 return PMINFO_R_ERROR;
2158 *root_path = (char *)info->app_info->root_path;
2163 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2165 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2167 if (handle == NULL || api_version == NULL) {
2168 LOGE("invalid parameter");
2169 return PMINFO_R_EINVAL;
2172 if (info->app_info == NULL || info->app_info->api_version == NULL)
2173 return PMINFO_R_ERROR;
2175 *api_version = (char *)info->app_info->api_version;
2180 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2182 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2184 if (handle == NULL || installed_time == NULL) {
2185 LOGE("invalid parameter");
2186 return PMINFO_R_EINVAL;
2189 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2190 return PMINFO_R_ERROR;
2192 *installed_time = atoi(info->app_info->package_installed_time);
2197 static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
2198 const char *type, char **appid, char **access)
2200 static const char query[] =
2201 "SELECT app_id, access FROM package_app_data_control "
2202 "WHERE providerid=? AND type=?";
2206 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2207 if (ret != SQLITE_OK) {
2208 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2209 return PMINFO_R_ERROR;
2212 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2213 if (ret != SQLITE_OK) {
2214 LOGE("bind failed: %s", sqlite3_errmsg(db));
2215 sqlite3_finalize(stmt);
2216 return PMINFO_R_ERROR;
2219 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2220 if (ret != SQLITE_OK) {
2221 LOGE("bind failed: %s", sqlite3_errmsg(db));
2222 sqlite3_finalize(stmt);
2223 return PMINFO_R_ERROR;
2226 ret = sqlite3_step(stmt);
2227 if (ret != SQLITE_ROW) {
2228 sqlite3_finalize(stmt);
2229 if (ret == SQLITE_DONE) {
2230 return PMINFO_R_ENOENT;
2232 LOGE("step error: %s", sqlite3_errmsg(db));
2233 return PMINFO_R_ERROR;
2237 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2238 if (*appid == NULL) {
2239 LOGE("out of memory");
2240 sqlite3_finalize(stmt);
2241 return PMINFO_R_ERROR;
2243 *access = strdup((char *)sqlite3_column_text(stmt, 1));
2244 if (*access == NULL) {
2245 LOGE("out of memory");
2247 sqlite3_finalize(stmt);
2248 return PMINFO_R_ERROR;
2251 sqlite3_finalize(stmt);
2256 static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
2257 const char *providerid, const char *type,
2258 char **appid, char **access)
2264 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2266 return PMINFO_R_ERROR;
2268 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2270 if (ret != SQLITE_OK) {
2271 LOGE("open db failed: %s", sqlite3_errmsg(db));
2272 return PMINFO_R_ERROR;
2275 ret = _appinfo_get_datacontrol_info(db, providerid, type, appid,
2277 sqlite3_close_v2(db);
2282 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2283 const char *type, uid_t uid, char **appid, char **access)
2287 if (providerid == NULL || type == NULL || appid == NULL ||
2289 LOGE("invalid parameter");
2290 return PMINFO_R_EINVAL;
2293 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
2294 type, appid, access);
2295 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2296 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
2297 type, appid, access);
2299 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2300 * implementation, return PMINFO_R_ERROR. This should be
2303 if (ret == PMINFO_R_ENOENT) {
2304 LOGE("no datacontrol info of %s", providerid);
2305 ret = PMINFO_R_ERROR;
2311 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2312 const char *type, char **appid, char **access)
2314 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2315 type, _getuid(), appid, access);
2318 static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
2321 static const char query[] =
2322 "SELECT app_id FROM package_app_data_control "
2323 "WHERE providerid=?";
2327 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2328 if (ret != SQLITE_OK) {
2329 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2330 return PMINFO_R_ERROR;
2333 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2334 if (ret != SQLITE_OK) {
2335 LOGE("bind failed: %s", sqlite3_errmsg(db));
2336 sqlite3_finalize(stmt);
2337 return PMINFO_R_ERROR;
2340 ret = sqlite3_step(stmt);
2341 if (ret != SQLITE_ROW) {
2342 sqlite3_finalize(stmt);
2343 if (ret == SQLITE_DONE) {
2344 return PMINFO_R_ENOENT;
2346 LOGE("step error: %s", sqlite3_errmsg(db));
2347 return PMINFO_R_ERROR;
2351 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2353 sqlite3_finalize(stmt);
2355 if (*appid == NULL) {
2356 LOGE("out of memory");
2357 return PMINFO_R_ERROR;
2363 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
2364 const char *providerid, char **appid)
2370 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2372 return PMINFO_R_ERROR;
2374 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2376 if (ret != SQLITE_OK) {
2377 LOGE("open db failed: %s", sqlite3_errmsg(db));
2378 return PMINFO_R_ERROR;
2381 ret = _appinfo_get_datacontrol_appid(db, providerid, appid);
2382 sqlite3_close_v2(db);
2387 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
2388 uid_t uid, char **appid)
2392 if (providerid == NULL || appid == NULL) {
2393 LOGE("invalid parameter");
2394 return PMINFO_R_EINVAL;
2397 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
2399 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2400 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
2403 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2404 * implementation, return PMINFO_R_ERROR. This should be
2407 if (ret == PMINFO_R_ENOENT) {
2408 LOGE("no datacontrol appid of %s", providerid);
2409 ret = PMINFO_R_ERROR;
2415 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2417 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2420 static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
2421 const char *providerid, const char *type, char **appid,
2424 static const char query[] =
2425 "SELECT app_id, trusted FROM package_app_data_control "
2426 "WHERE providerid=? AND type=?";
2430 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2431 if (ret != SQLITE_OK) {
2432 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2433 return PMINFO_R_ERROR;
2436 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2437 if (ret != SQLITE_OK) {
2438 LOGE("bind failed: %s", sqlite3_errmsg(db));
2439 sqlite3_finalize(stmt);
2440 return PMINFO_R_ERROR;
2443 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2444 if (ret != SQLITE_OK) {
2445 LOGE("bind failed: %s", sqlite3_errmsg(db));
2446 sqlite3_finalize(stmt);
2447 return PMINFO_R_ERROR;
2450 ret = sqlite3_step(stmt);
2451 if (ret != SQLITE_ROW) {
2452 sqlite3_finalize(stmt);
2453 if (ret == SQLITE_DONE) {
2454 return PMINFO_R_ENOENT;
2456 LOGE("step error: %s", sqlite3_errmsg(db));
2457 return PMINFO_R_ERROR;
2461 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2462 *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2464 sqlite3_finalize(stmt);
2466 if (*appid == NULL) {
2467 LOGE("out of memory");
2468 return PMINFO_R_ERROR;
2474 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
2475 const char *providerid, const char *type, char **appid,
2482 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2484 return PMINFO_R_ERROR;
2486 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2488 if (ret != SQLITE_OK) {
2489 LOGE("open db failed: %s", sqlite3_errmsg(db));
2490 return PMINFO_R_ERROR;
2493 ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid,
2495 sqlite3_close_v2(db);
2500 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
2501 const char *providerid, const char *type, uid_t uid,
2502 char **appid, bool *is_trusted)
2506 if (providerid == NULL || type == NULL || appid == NULL ||
2507 is_trusted == NULL) {
2508 LOGE("invalid parameter");
2509 return PMINFO_R_EINVAL;
2512 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
2513 providerid, type, appid, is_trusted);
2514 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2515 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
2516 providerid, type, appid, is_trusted);
2518 /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2519 * implementation, return PMINFO_R_ERROR. This should be
2522 if (ret == PMINFO_R_ENOENT) {
2523 LOGE("no datacontrol trusted info of %s", providerid);
2524 ret = PMINFO_R_ERROR;
2530 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2531 const char *type, char **appid, bool *is_trusted)
2533 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2534 type, _getuid(), appid, is_trusted);
2537 static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
2538 const char *providerid, const char *type,
2539 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2541 static const char query[] =
2542 "SELECT privilege FROM package_app_data_control_privilege "
2543 "WHERE providerid=? AND type=?";
2548 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2549 if (ret != SQLITE_OK) {
2550 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2551 return PMINFO_R_ERROR;
2554 ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2555 if (ret != SQLITE_OK) {
2556 LOGE("bind failed: %s", sqlite3_errmsg(db));
2557 sqlite3_finalize(stmt);
2558 return PMINFO_R_ERROR;
2561 ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2562 if (ret != SQLITE_OK) {
2563 LOGE("bind failed: %s", sqlite3_errmsg(db));
2564 sqlite3_finalize(stmt);
2565 return PMINFO_R_ERROR;
2568 while (sqlite3_step(stmt) == SQLITE_ROW) {
2570 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2576 sqlite3_finalize(stmt);
2578 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2581 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
2582 const char *providerid, const char *type,
2583 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2589 dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2591 return PMINFO_R_ERROR;
2593 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2595 if (ret != SQLITE_OK) {
2596 LOGE("open db failed: %s", sqlite3_errmsg(db));
2597 return PMINFO_R_ERROR;
2600 ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
2601 callback, user_data);
2602 sqlite3_close_v2(db);
2607 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2608 const char *providerid, const char *type,
2609 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2610 void *user_data, uid_t uid)
2614 if (providerid == NULL || type == NULL || privilege_func == NULL) {
2615 LOGE("invalid parameter");
2616 return PMINFO_R_EINVAL;
2619 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
2620 providerid, type, privilege_func, user_data);
2621 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2622 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
2623 providerid, type, privilege_func, user_data);
2625 if (ret == PMINFO_R_ENOENT)
2631 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
2632 const char *providerid, const char *type,
2633 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2636 return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2637 providerid, type, privilege_func, user_data, _getuid());
2640 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
2642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2643 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2645 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2646 if (info->app_info->support_mode)
2647 *support_mode = atoi(info->app_info->support_mode);
2654 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2655 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2657 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2658 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2660 const char *category;
2662 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2664 if (info->app_info == NULL)
2665 return PMINFO_R_ERROR;
2667 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2668 category = (const char *)tmp->data;
2670 ret = category_func(category, user_data);
2678 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2679 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2681 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2682 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2686 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2688 if (info->app_info == NULL)
2689 return PMINFO_R_ERROR;
2691 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2692 ptr = (metadata_x *)tmp->data;
2696 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2704 static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
2705 const char *appid, const char *operation,
2706 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2708 static const char query[] =
2709 "SELECT app_control, privilege FROM package_app_app_control_privilege "
2713 const char *app_control;
2714 char *dup_app_control;
2716 char *saveptr = NULL;
2717 const char *privilege;
2720 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2721 if (ret != SQLITE_OK) {
2722 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2723 return PMINFO_R_ERROR;
2726 ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_STATIC);
2727 if (ret != SQLITE_OK) {
2728 LOGE("bind failed: %s", sqlite3_errmsg(db));
2729 sqlite3_finalize(stmt);
2730 return PMINFO_R_ERROR;
2733 while (sqlite3_step(stmt) == SQLITE_ROW) {
2734 app_control = (const char *)sqlite3_column_text(stmt, 0);
2738 dup_app_control = strdup(app_control);
2739 if (!dup_app_control)
2742 token = strtok_r(dup_app_control, "|", &saveptr);
2743 if (token && !strcmp(token, operation)) {
2745 privilege = (const char *)sqlite3_column_text(stmt, 1);
2746 ret = callback(privilege, user_data);
2748 free(dup_app_control);
2752 free(dup_app_control);
2755 sqlite3_finalize(stmt);
2757 return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2760 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
2761 const char *appid, const char *operation,
2762 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2768 dbpath = getUserPkgParserDBPathUID(uid);
2770 return PMINFO_R_ERROR;
2772 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2774 if (ret != SQLITE_OK) {
2775 LOGE("open db failed: %s", sqlite3_errmsg(db));
2776 return PMINFO_R_ERROR;
2779 ret = _appinfo_foreach_appcontrol_privileges(db, appid, operation,
2780 callback, user_data);
2781 sqlite3_close_v2(db);
2786 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
2787 const char *operation,
2788 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2789 void *user_data, uid_t uid)
2793 if (appid == NULL || operation == NULL || privilege_func == NULL) {
2794 LOGE("invalid parameter");
2795 return PMINFO_R_EINVAL;
2798 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
2799 appid, operation, privilege_func, user_data);
2800 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2801 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
2802 appid, operation, privilege_func, user_data);
2804 if (ret == PMINFO_R_ENOENT)
2810 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
2811 const char *operation,
2812 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2815 return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
2816 operation, privilege_func, user_data, _getuid());
2819 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2820 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2822 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2823 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2825 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2826 appcontrol_x *appcontrol;
2829 if (info->app_info == NULL)
2830 return PMINFO_R_ERROR;
2832 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2833 appcontrol = (appcontrol_x *)tmp->data;
2834 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "remote-only"))
2836 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2844 API int pkgmgrinfo_appinfo_foreach_remote_appcontrol(pkgmgrinfo_appinfo_h handle,
2845 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2847 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2848 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2850 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2851 appcontrol_x *appcontrol;
2854 if (info->app_info == NULL)
2855 return PMINFO_R_ERROR;
2857 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2858 appcontrol = (appcontrol_x *)tmp->data;
2859 if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "local-only"))
2861 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2869 API int pkgmgrinfo_appinfo_foreach_background_category(
2870 pkgmgrinfo_appinfo_h handle,
2871 pkgmgrinfo_app_background_category_list_cb category_func,
2874 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2878 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2879 LOGE("invalid parameter");
2880 return PMINFO_R_EINVAL;
2883 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2884 category = (char *)tmp->data;
2885 if (category == NULL)
2888 if (category_func(category, user_data) < 0)
2895 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2896 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2899 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2900 splashscreen_x *splashscreen;
2904 if (info == NULL || info->app_info == NULL
2905 || splash_screen_func == NULL) {
2906 LOGE("invalid parameter");
2907 return PMINFO_R_EINVAL;
2910 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2911 splashscreen = (splashscreen_x *)tmp->data;
2912 if (splashscreen == NULL)
2914 ret = splash_screen_func(splashscreen->src,
2916 splashscreen->orientation,
2917 splashscreen->indicatordisplay,
2918 splashscreen->operation,
2919 splashscreen->color_depth,
2928 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2930 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2931 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2932 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2934 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2935 return PMINFO_R_ERROR;
2937 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2942 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2944 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2945 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2946 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2948 if (info->app_info == NULL || info->app_info->multiple == NULL)
2949 return PMINFO_R_ERROR;
2951 *multiple = _get_bool_value(info->app_info->multiple);
2956 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2958 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2959 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2960 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2962 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2963 return PMINFO_R_ERROR;
2965 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2970 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2972 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2973 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2974 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2976 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2977 return PMINFO_R_ERROR;
2979 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2984 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2986 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2987 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2988 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2990 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2991 return PMINFO_R_ERROR;
2993 *enabled = !_get_bool_value(info->app_info->is_disabled);
2998 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
3000 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3001 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3002 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3004 if (info->app_info == NULL || info->app_info->onboot == NULL)
3005 return PMINFO_R_ERROR;
3007 *onboot = _get_bool_value(info->app_info->onboot);
3012 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
3014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3015 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3016 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3018 if (info->app_info == NULL || info->app_info->autorestart == NULL)
3019 return PMINFO_R_ERROR;
3021 *autorestart = _get_bool_value(info->app_info->autorestart);
3026 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
3028 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3029 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3030 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3032 if (info->app_info == NULL || info->app_info->mainapp == NULL)
3033 return PMINFO_R_ERROR;
3035 *mainapp = _get_bool_value(info->app_info->mainapp);
3040 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
3042 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3043 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3044 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3046 if (info->app_info == NULL || info->app_info->preload == NULL)
3047 return PMINFO_R_ERROR;
3049 *preload = _get_bool_value(info->app_info->preload);
3054 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
3056 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3057 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3058 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3060 if (info->app_info == NULL || info->app_info->submode == NULL)
3061 return PMINFO_R_ERROR;
3063 *submode = _get_bool_value(info->app_info->submode);
3068 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
3070 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3072 if (handle == NULL || process_pool == NULL) {
3073 LOGE("invalid parameter");
3074 return PMINFO_R_EINVAL;
3077 if (info->app_info == NULL)
3078 return PMINFO_R_ERROR;
3080 *process_pool = _get_bool_value(info->app_info->process_pool);
3085 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
3087 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3088 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
3089 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
3093 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3095 if (info->app_info == NULL)
3096 return PMINFO_R_ERROR;
3099 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
3100 val = (const char *)tmp->data;
3103 if (strcasecmp(val, category) == 0) {
3112 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
3115 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3117 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
3118 _LOGE("invalid parameter");
3119 return PMINFO_R_EINVAL;
3121 if (info->app_info->ui_gadget == NULL)
3122 info->app_info->ui_gadget = strdup("false");
3124 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
3129 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
3130 bool *support_disable)
3132 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3134 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
3135 _LOGE("invalid parameter");
3136 return PMINFO_R_EINVAL;
3139 *support_disable = _get_bool_value(info->app_info->support_disable);
3144 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
3147 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3149 if (info == NULL || info->app_info == NULL || removable == NULL) {
3150 _LOGE("invalid parameter");
3151 return PMINFO_R_EINVAL;
3154 *removable = _get_bool_value(info->app_info->removable);
3159 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
3161 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3163 if (info == NULL || info->app_info == NULL || system == NULL) {
3164 _LOGE("invalid parameter");
3165 return PMINFO_R_EINVAL;
3168 *system = _get_bool_value(info->app_info->package_system);
3173 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
3175 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3176 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3177 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3179 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
3180 return PMINFO_R_ERROR;
3182 *disabled = _get_bool_value(info->app_info->is_disabled);
3187 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
3189 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3191 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3192 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3194 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
3195 return PMINFO_R_ERROR;
3197 *global = _get_bool_value(info->app_info->for_all_users);
3202 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
3204 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3206 if (info == NULL || splash_screen_display == NULL) {
3207 _LOGE("Invalid parameter");
3208 return PMINFO_R_EINVAL;
3211 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
3212 return PMINFO_R_ERROR;
3214 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
3219 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
3221 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3223 if (info == NULL || setup_appid == NULL) {
3224 _LOGE("Invalid parameter");
3225 return PMINFO_R_EINVAL;
3228 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
3229 return PMINFO_R_ERROR;
3231 *setup_appid = info->app_info->setup_appid;
3235 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
3236 bool *support_ambient)
3238 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3240 if (info == NULL || support_ambient == NULL) {
3241 _LOGE("Invalid parameter");
3242 return PMINFO_R_EINVAL;
3245 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
3246 return PMINFO_R_ERROR;
3248 *support_ambient = _get_bool_value(info->app_info->support_ambient);
3253 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
3255 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3256 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3257 __cleanup_appinfo(info);
3261 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
3263 return (pkgmgrinfo_pkginfo_filter_create(handle));
3266 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
3268 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3271 static gint __compare_func(gconstpointer data1, gconstpointer data2)
3273 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
3274 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
3275 if (node1->prop == node2->prop)
3277 else if (node1->prop > node2->prop)
3283 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
3284 const char *property, const int value)
3286 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3287 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3288 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3290 GSList *link = NULL;
3292 prop = _pminfo_appinfo_convert_to_prop_int(property);
3293 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
3294 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
3295 _LOGE("Invalid Integer Property\n");
3296 return PMINFO_R_EINVAL;
3298 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3299 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3301 _LOGE("Out of Memory!!!\n");
3302 return PMINFO_R_ERROR;
3304 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3305 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3307 _LOGE("Out of Memory\n");
3310 return PMINFO_R_ERROR;
3314 /*If API is called multiple times for same property, we should override the previous values.
3315 Last value set will be used for filtering.*/
3316 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3318 filter->list = g_slist_delete_link(filter->list, link);
3319 filter->list = g_slist_append(filter->list, (gpointer)node);
3324 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
3325 const char *property, const bool value)
3327 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3328 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3330 GSList *link = NULL;
3332 prop = _pminfo_appinfo_convert_to_prop_bool(property);
3333 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
3334 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
3335 _LOGE("Invalid Boolean Property\n");
3336 return PMINFO_R_EINVAL;
3338 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3339 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3341 _LOGE("Out of Memory!!!\n");
3342 return PMINFO_R_ERROR;
3345 val = strndup("true", 4);
3347 val = strndup("false", 5);
3349 _LOGE("Out of Memory\n");
3352 return PMINFO_R_ERROR;
3356 /*If API is called multiple times for same property, we should override the previous values.
3357 Last value set will be used for filtering.*/
3358 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3360 filter->list = g_slist_delete_link(filter->list, link);
3361 filter->list = g_slist_append(filter->list, (gpointer)node);
3366 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
3367 const char *property, const char *value)
3369 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3370 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3371 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3373 pkgmgrinfo_node_x *ptr = NULL;
3374 char prev[PKG_STRING_LEN_MAX] = {'\0'};
3375 char temp[PKG_STRING_LEN_MAX] = {'\0'};
3376 GSList *link = NULL;
3378 prop = _pminfo_appinfo_convert_to_prop_str(property);
3379 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
3380 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
3381 _LOGE("Invalid String Property\n");
3382 return PMINFO_R_EINVAL;
3384 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3385 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3387 _LOGE("Out of Memory!!!\n");
3388 return PMINFO_R_ERROR;
3392 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
3393 node->value = strdup(value);
3394 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3396 filter->list = g_slist_delete_link(filter->list, link);
3397 filter->list = g_slist_append(filter->list, (gpointer)node);
3399 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
3400 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
3402 _LOGE("Out of Memory\n");
3405 return PMINFO_R_ERROR;
3407 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3409 ptr = (pkgmgrinfo_node_x *)link->data;
3410 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
3411 _LOGI("Previous value is %s\n", prev);
3412 filter->list = g_slist_delete_link(filter->list, link);
3413 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
3414 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3415 _LOGI("New value is %s\n", val);
3417 filter->list = g_slist_append(filter->list, (gpointer)node);
3418 memset(temp, '\0', PKG_STRING_LEN_MAX);
3420 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3421 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3422 _LOGI("First value is %s\n", val);
3424 filter->list = g_slist_append(filter->list, (gpointer)node);
3425 memset(temp, '\0', PKG_STRING_LEN_MAX);
3429 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3430 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3432 filter->list = g_slist_delete_link(filter->list, link);
3433 filter->list = g_slist_append(filter->list, (gpointer)node);
3439 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3445 if (handle == NULL || count == NULL) {
3446 _LOGE("invalid parameter");
3447 return PMINFO_R_EINVAL;
3450 locale = _get_system_locale();
3452 return PMINFO_R_ERROR;
3454 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3455 __free_applications);
3458 return PMINFO_R_ERROR;
3461 if (__check_disable_filter_exist(
3462 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3463 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3464 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
3465 g_hash_table_destroy(list);
3467 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 g_hash_table_destroy(list);
3477 return PMINFO_R_ERROR;
3481 ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3482 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3483 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3486 if (ret != PMINFO_R_OK) {
3487 g_hash_table_destroy(list);
3489 return PMINFO_R_ERROR;
3492 *count = g_hash_table_size(list);
3493 g_hash_table_destroy(list);
3499 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3501 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3504 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3505 pkgmgrinfo_appinfo_filter_h handle,
3506 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3508 if (handle == NULL || app_cb == NULL) {
3509 LOGE("invalid parameter");
3510 return PMINFO_R_EINVAL;
3513 if (__check_disable_filter_exist(
3514 handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3515 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3516 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3517 return PMINFO_R_ERROR;
3520 if (__check_disable_filter_exist(
3521 handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3522 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3523 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3524 return PMINFO_R_ERROR;
3527 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3531 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3532 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3534 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3537 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3539 return (pkgmgrinfo_pkginfo_filter_create(handle));
3542 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3544 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3547 API int pkgmgrinfo_appinfo_metadata_filter_add(
3548 pkgmgrinfo_appinfo_metadata_filter_h handle,
3549 const char *key, const char *value)
3551 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3552 pkgmgrinfo_metadata_node_x *node;
3554 /* value can be NULL.
3555 * In that case all apps with specified key should be displayed
3558 LOGE("invalid parameter");
3559 return PMINFO_R_EINVAL;
3562 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3564 LOGE("out of memory");
3565 return PMINFO_R_ERROR;
3568 node->key = strdup(key);
3569 if (value && strlen(value))
3570 node->value = strdup(value);
3572 filter->list_metadata = g_slist_append(filter->list_metadata,
3578 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3579 pkgmgrinfo_appinfo_metadata_filter_h handle,
3580 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3582 if (handle == NULL || app_cb == NULL) {
3583 LOGE("invalid parameter");
3584 return PMINFO_R_EINVAL;
3587 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3588 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3589 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3590 return PMINFO_R_ERROR;
3592 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3593 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3594 return PMINFO_R_ERROR;
3596 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3600 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3601 pkgmgrinfo_appinfo_metadata_filter_h handle,
3602 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3604 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3605 user_data, _getuid());
3608 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3611 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3613 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3614 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3616 val = info->app_info->guestmode_visibility;
3617 *status = _get_bool_value(val);