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)
61 char *condition = NULL;
62 char buf[MAX_QUERY_LEN] = { '\0' };
63 char tmp_query[MAX_QUERY_LEN] = { '\0' };
64 static const char query_pkg_disable[] = " AND ai.package IN "
65 "(SELECT package FROM package_info WHERE package_disable='false')";
68 strncat(buf, " WHERE 1=1", MAX_QUERY_LEN - len - 1);
69 len += strlen(" WHERE 1=1");
72 strncat(buf, query_pkg_disable, MAX_QUERY_LEN - len - 1);
77 for (list = filter->list; list; list = list->next) {
78 joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
79 if (condition == NULL)
82 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
83 len += strlen(" AND ");
85 strncat(buf, condition, sizeof(buf) - len - 1);
86 len += strlen(condition);
91 if (filter->list_metadata) {
92 strncat(buf, " AND (", MAX_QUERY_LEN - len - 1);
93 len += strlen(" AND (");
95 for (list = filter->list_metadata; list; list = list->next) {
96 joined |= __get_metadata_filter_condition(list->data,
97 &condition, bind_params);
98 if (condition == NULL)
100 strncat(buf, condition, sizeof(buf) - len - 1);
101 len += strlen(condition);
105 strncat(buf, " OR ", MAX_QUERY_LEN - len - 1);
106 len += strlen(" OR ");
108 if (filter->list_metadata) {
109 strncat(buf, "1=0)", MAX_QUERY_LEN - len - 1);
110 len += strlen("1=0)");
113 if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
114 strncat(tmp_query, join_localized_info, MAX_QUERY_LEN - len - 1);
115 len += strlen(join_localized_info);
116 *bind_params = g_list_append(*bind_params, strdup(locale));
118 if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY) {
119 strncat(tmp_query, join_category, MAX_QUERY_LEN - len - 1);
120 len += strlen(join_category);
122 if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL) {
123 strncat(tmp_query, join_app_control, MAX_QUERY_LEN - len - 1);
124 len += strlen(join_app_control);
126 if (joined & E_PMINFO_APPINFO_JOIN_METADATA) {
127 strncat(tmp_query, join_metadata, MAX_QUERY_LEN - len - 1);
128 len += strlen(join_metadata);
131 strncat(tmp_query, buf, MAX_QUERY_LEN - len - 1);
134 strncat(tmp_query, query_pkg_disable, MAX_QUERY_LEN - len - 1);
136 *query = strdup(tmp_query);
138 return PMINFO_R_ERROR;
143 static int _appinfo_get_category(sqlite3 *db, const char *appid,
146 static const char query_raw[] =
147 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
153 query = sqlite3_mprintf(query_raw, appid);
155 LOGE("out of memory");
156 return PMINFO_R_ERROR;
159 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
161 if (ret != SQLITE_OK) {
162 LOGE("prepare failed: %s", sqlite3_errmsg(db));
163 return PMINFO_R_ERROR;
166 while (sqlite3_step(stmt) == SQLITE_ROW) {
168 _save_column_str(stmt, 0, &val);
170 *category = g_list_append(*category, (gpointer)val);
173 sqlite3_finalize(stmt);
178 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
185 if (appcontrol_str == NULL)
188 dup = strdup(appcontrol_str);
190 ac = calloc(1, sizeof(appcontrol_x));
192 _LOGE("out of memory");
195 token = strtok_r(dup, "|", &ptr);
196 if (token && strcmp(token, "NULL"))
197 ac->operation = strdup(token);
198 token = strtok_r(NULL, "|", &ptr);
199 if (token && strcmp(token, "NULL"))
200 ac->uri = strdup(token);
201 token = strtok_r(NULL, "|", &ptr);
202 if (token && strcmp(token, "NULL"))
203 ac->mime = strdup(token);
204 *appcontrol = g_list_append(*appcontrol, ac);
205 } while ((token = strtok_r(NULL, ";", &ptr)));
210 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
213 static const char query_raw[] =
214 "SELECT app_control FROM package_app_app_control "
221 query = sqlite3_mprintf(query_raw, appid);
223 LOGE("out of memory");
224 return PMINFO_R_ERROR;
227 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
229 if (ret != SQLITE_OK) {
230 LOGE("prepare failed: %s", sqlite3_errmsg(db));
231 return PMINFO_R_ERROR;
234 while (sqlite3_step(stmt) == SQLITE_ROW) {
236 _save_column_str(stmt, 0, &str);
238 __parse_appcontrol(appcontrol, str);
242 sqlite3_finalize(stmt);
247 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
250 static const char query_raw[] =
251 "SELECT md_key, md_value "
252 "FROM package_app_app_metadata WHERE app_id=%Q";
259 query = sqlite3_mprintf(query_raw, appid);
261 LOGE("out of memory");
262 return PMINFO_R_ERROR;
265 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
267 if (ret != SQLITE_OK) {
268 LOGE("prepare failed: %s", sqlite3_errmsg(db));
269 return PMINFO_R_ERROR;
272 while (sqlite3_step(stmt) == SQLITE_ROW) {
273 info = calloc(1, sizeof(metadata_x));
275 LOGE("out of memory");
276 sqlite3_finalize(stmt);
277 return PMINFO_R_ERROR;
280 _save_column_str(stmt, idx++, &info->key);
281 _save_column_str(stmt, idx++, &info->value);
282 *metadata = g_list_append(*metadata, info);
285 sqlite3_finalize(stmt);
291 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
292 GList **splashscreens)
294 static const char query_raw[] =
295 "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
296 "FROM package_app_splash_screen WHERE app_id=%Q";
301 splashscreen_x *info;
303 query = sqlite3_mprintf(query_raw, appid);
305 LOGE("out of memory");
306 return PMINFO_R_ERROR;
309 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
311 if (ret != SQLITE_OK) {
312 LOGE("prepare failed: %s", sqlite3_errmsg(db));
313 return PMINFO_R_ERROR;
316 while (sqlite3_step(stmt) == SQLITE_ROW) {
317 info = calloc(1, sizeof(splashscreen_x));
319 LOGE("out of memory");
320 sqlite3_finalize(stmt);
321 return PMINFO_R_ERROR;
324 _save_column_str(stmt, idx++, &info->src);
325 _save_column_str(stmt, idx++, &info->type);
326 _save_column_str(stmt, idx++, &info->orientation);
327 _save_column_str(stmt, idx++, &info->indicatordisplay);
328 _save_column_str(stmt, idx++, &info->operation);
329 _save_column_str(stmt, idx++, &info->color_depth);
330 *splashscreens = g_list_append(*splashscreens, info);
333 sqlite3_finalize(stmt);
338 static GList *__get_background_category(const char *value)
340 GList *category_list = NULL;
341 int convert_value = 0;
342 if (!value || strlen(value) == 0)
345 convert_value = atoi(value);
346 if (convert_value < 0)
349 if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
350 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
352 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
354 if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
355 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
357 if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
358 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
360 if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
361 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
363 if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
364 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
366 if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
367 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
369 if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
370 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
372 if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
373 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
375 return category_list;
379 static void __free_applications(gpointer data)
381 pkgmgrinfo_basic_free_application((application_x *)data);
384 static gint __app_disable_chk_func(gconstpointer data1, gconstpointer data2)
386 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
388 if (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
394 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
401 link = g_slist_find_custom(filter->list, NULL, __app_disable_chk_func);
408 static int __bind_params(sqlite3_stmt *stmt, GList *params)
410 GList *tmp_list = NULL;
414 if (stmt == NULL || params == NULL)
415 return PMINFO_R_EINVAL;
419 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
420 if (ret != SQLITE_OK)
421 return PMINFO_R_ERROR;
422 tmp_list = tmp_list->next;
428 static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter)
430 GSList *tmp_list = NULL;
431 pkgmgrinfo_node_x *tmp_node = NULL;
434 if (tmp_filter == NULL)
437 property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
438 for (tmp_list = tmp_filter->list; tmp_list != NULL;
439 tmp_list = g_slist_next(tmp_list)) {
440 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
441 if (property == tmp_node->prop) {
442 if (strcmp(tmp_node->value, "true") == 0)
452 static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
453 const char *locale, pkgmgrinfo_filter_x *filter, int flag,
454 GHashTable *applications)
456 static const char query_raw[] =
457 "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
458 "ai.app_external_path";
459 static const char query_basic[] =
460 ", ai.app_component, ai.app_exec, "
461 "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
462 "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
463 "ai.app_hwacceleration, ai.app_screenreader, "
464 "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, "
465 "ai.app_indicatordisplay, ai.app_portraitimg, "
466 "ai.app_landscapeimg, ai.app_guestmodevisibility, "
467 "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
468 "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
469 "ai.app_support_disable, ai.app_process_pool, "
470 "ai.app_background_category, ai.app_package_type, "
471 "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
472 "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
473 "ai.app_zip_mount_file, ai.component_type, ai.package, "
474 "ai.app_package_system, ai.app_removable, "
475 "ai.app_package_installed_time, ai.app_support_mode, "
476 "ai.app_support_ambient, ai.app_setup_appid";
477 static const char query_uid_info[] =
478 ", ui.is_disabled, ui.is_splash_screen_enabled";
479 static const char query_label[] =
481 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
482 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
483 static const char query_icon[] =
485 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
486 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
487 static const char query_from_clause[] = " FROM package_app_info as ai";
488 static const char query_uid_info_clause[] =
489 " LEFT OUTER JOIN package_app_info_for_uid AS ui "
490 "ON (ai.app_id=ui.app_id AND ui.uid=?)";
491 int ret = PMINFO_R_ERROR;
495 char *bg_category_str = NULL;
496 char *constraint = NULL;
497 char *tmp_record = NULL;
498 char query[MAX_QUERY_LEN] = { '\0' };
499 char buf[BUFSIZE] = { '\0' };
500 application_x *info = NULL;
501 GList *bind_params = NULL;
503 sqlite3_stmt *stmt = NULL;
504 bool is_check_storage = true;
505 const uid_t global_user_uid = GLOBAL_USER;
507 dbpath = getUserPkgParserDBPathUID(db_uid);
509 return PMINFO_R_ERROR;
511 ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
512 if (ret != SQLITE_OK) {
513 _LOGE("failed to open db: %d", ret);
515 return PMINFO_R_ERROR;
519 len = strlen(query_raw);
520 snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
522 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
523 strncat(query, query_basic, MAX_QUERY_LEN - len - 1);
524 len += strlen(query_basic);
525 strncat(query, query_uid_info, MAX_QUERY_LEN - len - 1);
526 len += strlen(query_uid_info);
528 if (flag & PMINFO_APPINFO_GET_LABEL) {
529 strncat(query, query_label, MAX_QUERY_LEN - len - 1);
530 len += strlen(query_label);
531 bind_params = g_list_append(bind_params, strdup(locale));
533 if (flag & PMINFO_APPINFO_GET_ICON) {
534 strncat(query, query_icon, MAX_QUERY_LEN - len - 1);
535 len += strlen(query_icon);
536 bind_params = g_list_append(bind_params, strdup(locale));
539 snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
540 bind_params = g_list_append(bind_params, strdup(buf));
542 is_check_storage = __check_app_storage_status(filter);
544 ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
545 if (ret != PMINFO_R_OK) {
546 LOGE("Failed to get WHERE clause");
549 strncat(query, query_from_clause, MAX_QUERY_LEN - len - 1);
550 len += strlen(query_from_clause);
552 strncat(query, query_uid_info_clause, MAX_QUERY_LEN - len - 1);
553 len += strlen(query_uid_info_clause);
556 strncat(query, constraint, MAX_QUERY_LEN - len - 1);
558 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
559 if (ret != SQLITE_OK) {
560 LOGE("prepare failed: %s", sqlite3_errmsg(db));
561 ret = PMINFO_R_ERROR;
565 if (g_list_length(bind_params) != 0) {
566 ret = __bind_params(stmt, bind_params);
567 if (ret != SQLITE_OK) {
568 LOGE("Failed to bind parameters");
573 while (sqlite3_step(stmt) == SQLITE_ROW) {
574 info = calloc(1, sizeof(application_x));
576 LOGE("out of memory");
577 ret = PMINFO_R_ERROR;
581 _save_column_str(stmt, idx++, &info->appid);
582 _save_column_str(stmt, idx++, &info->installed_storage);
583 _save_column_str(stmt, idx++ , &info->external_path);
585 if (flag & PMINFO_APPINFO_GET_BASICINFO) {
586 _save_column_str(stmt, idx++, &info->component);
587 _save_column_str(stmt, idx++, &info->exec);
588 _save_column_str(stmt, idx++, &info->nodisplay);
589 _save_column_str(stmt, idx++, &info->type);
590 _save_column_str(stmt, idx++, &info->onboot);
591 _save_column_str(stmt, idx++, &info->multiple);
592 _save_column_str(stmt, idx++, &info->autorestart);
593 _save_column_str(stmt, idx++, &info->taskmanage);
594 _save_column_str(stmt, idx++, &info->hwacceleration);
595 _save_column_str(stmt, idx++, &info->screenreader);
596 _save_column_str(stmt, idx++, &info->mainapp);
597 _save_column_str(stmt, idx++, &info->recentimage);
598 _save_column_str(stmt, idx++, &info->launchcondition);
599 _save_column_str(stmt, idx++, &info->indicatordisplay);
600 _save_column_str(stmt, idx++, &info->portraitimg);
601 _save_column_str(stmt, idx++, &info->landscapeimg);
602 _save_column_str(stmt, idx++, &info->guestmode_visibility);
603 _save_column_str(stmt, idx++, &info->permission_type);
604 _save_column_str(stmt, idx++, &info->preload);
605 _save_column_str(stmt, idx++, &info->submode);
606 _save_column_str(stmt, idx++, &info->submode_mainid);
607 _save_column_str(stmt, idx++, &info->launch_mode);
608 _save_column_str(stmt, idx++, &info->ui_gadget);
609 _save_column_str(stmt, idx++, &info->support_disable);
610 _save_column_str(stmt, idx++, &info->process_pool);
611 _save_column_str(stmt, idx++, &bg_category_str);
612 _save_column_str(stmt, idx++, &info->package_type);
613 _save_column_str(stmt, idx++, &info->root_path);
614 _save_column_str(stmt, idx++, &info->api_version);
615 _save_column_str(stmt, idx++, &info->effective_appid);
616 _save_column_str(stmt, idx++, &info->is_disabled);
617 _save_column_str(stmt, idx++, &info->splash_screen_display);
618 _save_column_str(stmt, idx++, &info->tep_name);
619 _save_column_str(stmt, idx++, &info->zip_mount_file);
620 _save_column_str(stmt, idx++, &info->component_type);
621 _save_column_str(stmt, idx++, &info->package);
622 _save_column_str(stmt, idx++, &info->package_system);
623 _save_column_str(stmt, idx++, &info->removable);
624 _save_column_str(stmt, idx++, &info->package_installed_time);
625 _save_column_str(stmt, idx++, &info->support_mode);
626 _save_column_str(stmt, idx++, &info->support_ambient);
627 _save_column_str(stmt, idx++, &info->setup_appid);
628 info->background_category = __get_background_category(
630 free(bg_category_str);
633 info->for_all_users =
634 strdup((db_uid != global_user_uid) ? "false" : "true");
636 if (db_uid != global_user_uid) {
640 _save_column_str(stmt, idx++, &tmp_record);
641 if (tmp_record != NULL) {
642 if (strcasecmp(info->is_disabled, "false") == 0 &&
643 strcasecmp(tmp_record, "false") == 0) {
644 free(info->is_disabled);
645 info->is_disabled = tmp_record;
649 _save_column_str(stmt, idx++, &tmp_record);
650 if (tmp_record != NULL) {
651 if (strcasecmp(info->splash_screen_display, "false") == 0 &&
652 strcasecmp(tmp_record, "false") == 0) {
653 free(info->splash_screen_display);
654 info->splash_screen_display = tmp_record;
659 if (flag & PMINFO_APPINFO_GET_LABEL) {
661 _save_column_str(stmt, idx++, &tmp_record);
662 if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
663 ret = PMINFO_R_ERROR;
668 if (flag & PMINFO_APPINFO_GET_ICON) {
670 _save_column_str(stmt, idx++, &tmp_record);
671 if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
672 ret = PMINFO_R_ERROR;
677 if (flag & PMINFO_APPINFO_GET_CATEGORY) {
678 if (_appinfo_get_category(db, info->appid,
680 ret = PMINFO_R_ERROR;
685 if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
686 if (_appinfo_get_app_control(db, info->appid,
687 &info->appcontrol)) {
688 ret = PMINFO_R_ERROR;
693 if (flag & PMINFO_APPINFO_GET_METADATA) {
694 if (_appinfo_get_metadata(db, info->appid,
696 ret = PMINFO_R_ERROR;
701 if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
702 if (_appinfo_get_splashscreens(db, info->appid,
703 &info->splashscreens)) {
704 ret = PMINFO_R_ERROR;
709 if (is_check_storage &&
710 __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
711 ret = PMINFO_R_ERROR;
712 pkgmgrinfo_basic_free_application(info);
717 g_hash_table_insert(applications, (gpointer)info->appid,
727 if (ret != PMINFO_R_OK && info != NULL)
728 pkgmgrinfo_basic_free_application(info);
730 g_list_free_full(bind_params, free);
731 sqlite3_close_v2(db);
732 sqlite3_finalize(stmt);
737 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
738 pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
743 pkgmgr_appinfo_x *info;
745 if (appid == NULL || filter == NULL || handle == NULL) {
746 LOGE("invalid parameter");
747 return PMINFO_R_EINVAL;
750 locale = _get_system_locale();
752 return PMINFO_R_ERROR;
754 list = g_hash_table_new(g_str_hash, g_str_equal);
757 return PMINFO_R_ERROR;
760 ret = _appinfo_get_applications(uid, uid, locale, filter,
761 PMINFO_APPINFO_GET_ALL, list);
762 if (!g_hash_table_size(list) && uid != GLOBAL_USER)
763 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
764 PMINFO_APPINFO_GET_ALL, list);
766 if (!g_hash_table_size(list)) {
767 _LOGI("appinfo for [%s] is not existed for user [%d]",
769 g_hash_table_destroy(list);
771 return PMINFO_R_ENOENT;
774 info = calloc(1, sizeof(pkgmgr_appinfo_x));
776 _LOGE("out of memory");
777 g_hash_table_destroy(list);
779 return PMINFO_R_ERROR;
782 info->app_info = (application_x *)g_hash_table_lookup(list, appid);
783 info->locale = locale;
784 info->package = strdup(info->app_info->package);
786 /* just free list only */
787 g_hash_table_destroy(list);
794 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
795 pkgmgrinfo_appinfo_h *handle)
798 pkgmgrinfo_appinfo_filter_h filter;
800 if (appid == NULL || handle == NULL) {
801 LOGE("invalid parameter");
802 return PMINFO_R_EINVAL;
805 ret = pkgmgrinfo_appinfo_filter_create(&filter);
806 if (ret != PMINFO_R_OK)
809 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
810 PMINFO_APPINFO_PROP_APP_ID, appid);
811 if (ret != PMINFO_R_OK) {
812 pkgmgrinfo_appinfo_filter_destroy(filter);
813 return PMINFO_R_ERROR;
816 ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
817 PMINFO_APPINFO_PROP_APP_DISABLE, true);
818 if (ret != PMINFO_R_OK) {
819 pkgmgrinfo_appinfo_filter_destroy(filter);
820 return PMINFO_R_ERROR;
823 ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
824 pkgmgrinfo_appinfo_filter_destroy(filter);
829 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
831 return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
834 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
835 pkgmgrinfo_appinfo_h *handle)
838 pkgmgrinfo_appinfo_filter_h filter;
840 if (appid == NULL || handle == NULL) {
841 LOGE("invalid parameter");
842 return PMINFO_R_EINVAL;
845 ret = pkgmgrinfo_appinfo_filter_create(&filter);
846 if (ret != PMINFO_R_OK)
849 ret = pkgmgrinfo_appinfo_filter_add_string(filter,
850 PMINFO_APPINFO_PROP_APP_ID, appid);
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_APP_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 if (__check_disable_filter_exist(filter) == false) {
1279 pkgmgrinfo_appinfo_filter_add_bool(filter,
1280 PMINFO_APPINFO_PROP_APP_DISABLE, false);
1283 ret = _appinfo_get_applications(uid, uid, locale, filter,
1284 flag | PMINFO_APPINFO_GET_BASICINFO, list);
1285 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1286 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1287 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1289 if (ret != PMINFO_R_OK) {
1290 g_hash_table_destroy(list);
1295 g_hash_table_iter_init(&iter, list);
1296 while (g_hash_table_iter_next(&iter, NULL, &value)) {
1297 app = (application_x *)value;
1298 info.app_info = app;
1299 info.locale = locale;
1300 info.package = app->package;
1301 if (app_list_cb(&info, user_data) < 0)
1304 g_hash_table_destroy(list);
1310 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1312 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1313 pkgmgrinfo_app_component component,
1314 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1317 pkgmgrinfo_appinfo_filter_h filter;
1319 const char *comp_str = NULL;
1321 if (handle == NULL || app_func == NULL) {
1322 LOGE("invalid parameter");
1323 return PMINFO_R_EINVAL;
1326 if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1327 LOGE("invalid parameter");
1328 return PMINFO_R_EINVAL;
1331 if (pkgmgrinfo_appinfo_filter_create(&filter))
1332 return PMINFO_R_ERROR;
1334 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1335 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1336 pkgmgrinfo_appinfo_filter_destroy(filter);
1337 return PMINFO_R_ERROR;
1340 comp_str = __appcomponent_str(component);
1343 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1344 PMINFO_APPINFO_PROP_APP_COMPONENT,
1346 pkgmgrinfo_appinfo_filter_destroy(filter);
1347 return PMINFO_R_ERROR;
1351 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1352 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1354 pkgmgrinfo_appinfo_filter_destroy(filter);
1359 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1360 pkgmgrinfo_app_component component,
1361 pkgmgrinfo_app_list_cb app_func, void *user_data)
1363 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1366 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1367 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1371 pkgmgrinfo_appinfo_filter_h filter;
1373 if (app_func == NULL) {
1374 LOGE("invalid parameter");
1375 return PMINFO_R_EINVAL;
1378 if (pkgmgrinfo_appinfo_filter_create(&filter))
1379 return PMINFO_R_ERROR;
1381 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1382 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1383 pkgmgrinfo_appinfo_filter_destroy(filter);
1384 return PMINFO_R_ERROR;
1387 if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1388 PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1389 pkgmgrinfo_appinfo_filter_destroy(filter);
1390 return PMINFO_R_ERROR;
1393 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1396 pkgmgrinfo_appinfo_filter_destroy(filter);
1401 API int pkgmgrinfo_appinfo_get_installed_list_full(
1402 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1404 return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1405 _getuid(), flag, user_data);
1408 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1409 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1412 pkgmgrinfo_appinfo_filter_h filter;
1414 if (app_func == NULL) {
1415 LOGE("invalid parameter");
1416 return PMINFO_R_EINVAL;
1419 /* create an empty filter */
1420 ret = pkgmgrinfo_appinfo_filter_create(&filter);
1421 if (ret != PMINFO_R_OK)
1424 ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1425 PMINFO_APPINFO_GET_ALL, app_func, user_data);
1427 pkgmgrinfo_appinfo_filter_destroy(filter);
1432 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1435 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1439 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1441 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1443 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1444 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1446 if (info->app_info == NULL || info->app_info->appid == NULL)
1447 return PMINFO_R_ERROR;
1448 *appid = (char *)info->app_info->appid;
1453 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1455 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1457 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1458 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1460 if (info->package == NULL)
1461 return PMINFO_R_ERROR;
1463 *pkg_name = (char *)info->package;
1468 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1470 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1472 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1473 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1475 if (info->package == NULL)
1476 return PMINFO_R_ERROR;
1478 *pkgid = (char *)info->package;
1483 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h handle, char **pkgtype)
1485 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1486 retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1487 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1489 *pkgtype = (char *)info->app_info->package_type;
1494 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1496 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1498 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1499 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1501 if (info->app_info == NULL || info->app_info->exec == NULL)
1502 return PMINFO_R_ERROR;
1503 *exec = (char *)info->app_info->exec;
1509 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1512 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1514 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1515 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1517 if (info->app_info == NULL)
1518 return PMINFO_R_ERROR;
1520 if (info->app_info->icon == NULL) {
1525 ptr = (icon_x *)info->app_info->icon->data;
1527 return PMINFO_R_ERROR;
1529 if (ptr->text == NULL)
1530 return PMINFO_R_ERROR;
1538 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1541 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1543 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1544 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1546 if (info->app_info == NULL || info->app_info->label == NULL)
1547 return PMINFO_R_ERROR;
1549 ptr = (label_x *)info->app_info->label->data;
1551 return PMINFO_R_ERROR;
1553 if (ptr->text == NULL)
1554 return PMINFO_R_ERROR;
1561 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1563 char *result = NULL;
1565 sqlite3_stmt *stmt = NULL;
1570 parser_db = getUserPkgParserDBPathUID(uid);
1571 if (parser_db == NULL) {
1572 _LOGE("Failed to get parser db path");
1576 if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1577 _LOGE("DB open fail\n");
1583 query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1584 if (query == NULL) {
1585 _LOGE("Out of memory");
1589 if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1590 _LOGE("prepare_v2 fail\n");
1594 if (sqlite3_step(stmt) == SQLITE_ROW) {
1595 val = (char *)sqlite3_column_text(stmt, 0);
1597 result = strdup(val);
1601 sqlite3_finalize(stmt);
1602 sqlite3_free(query);
1608 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1612 retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1614 val = _get_localed_label(appid, locale, uid);
1616 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1619 val = _get_localed_label(appid, locale, GLOBAL_USER);
1621 val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1625 return PMINFO_R_ERROR;
1632 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1634 return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1637 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1639 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1640 retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1641 retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1643 GList *list_md = NULL;
1644 metadata_x *metadata = NULL;
1645 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1647 list_md = info->app_info->metadata;
1649 for (; list_md; list_md = list_md->next) {
1650 metadata = (metadata_x *)list_md->data;
1651 if (metadata && metadata->key) {
1652 if (strcasecmp(metadata->key, metadata_key) == 0) {
1653 if (metadata->value == NULL)
1654 *metadata_value = "";
1656 *metadata_value = (char *)metadata->value;
1662 return PMINFO_R_EINVAL;
1665 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1667 if (strcasecmp(comp, "uiapp") == 0)
1668 return PMINFO_UI_APP;
1669 else if (strcasecmp(comp, "svcapp") == 0)
1670 return PMINFO_SVC_APP;
1671 else if (strcasecmp(comp, "widgetapp") == 0)
1672 return PMINFO_WIDGET_APP;
1673 else if (strcasecmp(comp, "watchapp") == 0)
1674 return PMINFO_WATCH_APP;
1679 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1684 case PMINFO_SVC_APP:
1686 case PMINFO_WIDGET_APP:
1688 case PMINFO_WATCH_APP:
1695 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1697 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1700 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1701 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1703 if (info->app_info == NULL)
1704 return PMINFO_R_ERROR;
1706 comp = __appcomponent_convert(info->app_info->component);
1708 return PMINFO_R_ERROR;
1715 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1717 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1719 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1720 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1722 if (info->app_info == NULL || info->app_info->type == NULL)
1723 return PMINFO_R_ERROR;
1724 *app_type = (char *)info->app_info->type;
1729 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
1730 int *operation_count, char ***operation)
1732 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1733 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1734 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1735 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1736 *operation_count = data->operation_count;
1737 *operation = data->operation;
1741 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
1742 int *uri_count, char ***uri)
1744 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1745 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1746 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1747 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1748 *uri_count = data->uri_count;
1753 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
1754 int *mime_count, char ***mime)
1756 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1757 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1758 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1759 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1760 *mime_count = data->mime_count;
1765 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
1766 int *subapp_count, char ***subapp)
1768 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1769 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1770 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1771 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1772 *subapp_count = data->subapp_count;
1773 *subapp = data->subapp;
1777 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1782 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1784 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1785 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1787 if (info->app_info == NULL)
1788 return PMINFO_R_ERROR;
1790 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1791 ptr = (icon_x *)tmp->data;
1792 if (ptr == NULL || ptr->section == NULL)
1795 val = (char *)ptr->section;
1796 if (val && strcmp(val, "setting") == 0) {
1797 *icon = (char *)ptr->text;
1802 return PMINFO_R_ERROR;
1806 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1811 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1813 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1814 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1816 if (info->app_info == NULL)
1817 return PMINFO_R_ERROR;
1819 for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1820 ptr = (icon_x *)tmp->data;
1821 if (ptr == NULL || ptr->section == NULL)
1824 val = (char *)ptr->section;
1825 if (val && strcmp(val, "notification") == 0) {
1826 *icon = (char *)ptr->text;
1831 return PMINFO_R_ERROR;
1834 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1837 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1839 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1840 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1842 if (info->app_info == NULL || info->app_info->recentimage == NULL)
1843 return PMINFO_R_ERROR;
1845 val = (char *)info->app_info->recentimage;
1846 if (strcasecmp(val, "capture") == 0)
1847 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1848 else if (strcasecmp(val, "icon") == 0)
1849 *type = PMINFO_RECENTIMAGE_USE_ICON;
1851 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1856 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1861 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1863 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1864 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1866 if (info->app_info == NULL)
1867 return PMINFO_R_ERROR;
1869 for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1870 ptr = (image_x *)tmp->data;
1871 if (ptr == NULL || ptr->section == NULL)
1874 val = (char *)ptr->section;
1875 if (val && strcmp(val, "preview") == 0) {
1876 *preview_img = (char *)ptr->text;
1881 return PMINFO_R_ERROR;
1884 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1887 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1889 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1890 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1892 val = info->app_info->permission_type;
1894 return PMINFO_R_ERROR;
1896 if (strcmp(val, "signature") == 0)
1897 *permission = PMINFO_PERMISSION_SIGNATURE;
1898 else if (strcmp(val, "privilege") == 0)
1899 *permission = PMINFO_PERMISSION_PRIVILEGE;
1901 *permission = PMINFO_PERMISSION_NORMAL;
1906 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1908 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1910 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1911 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1913 if (info->app_info == NULL || info->app_info->component_type == NULL)
1914 return PMINFO_R_ERROR;
1916 *component_type = (char *)info->app_info->component_type;
1921 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1924 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1926 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1927 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1929 if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1930 return PMINFO_R_ERROR;
1932 val = (char *)info->app_info->hwacceleration;
1933 if (strcasecmp(val, "off") == 0)
1934 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1935 else if (strcasecmp(val, "on") == 0)
1936 *hwacceleration = PMINFO_HWACCELERATION_ON;
1938 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1943 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1946 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1948 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1949 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1951 if (info->app_info == NULL || info->app_info->screenreader == NULL)
1952 return PMINFO_R_ERROR;
1954 val = (char *)info->app_info->screenreader;
1955 if (strcasecmp(val, "screenreader-off") == 0)
1956 *screenreader = PMINFO_SCREENREADER_OFF;
1957 else if (strcasecmp(val, "screenreader-on") == 0)
1958 *screenreader = PMINFO_SCREENREADER_ON;
1960 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1965 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1967 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1969 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1970 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1971 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1973 if (info->app_info == NULL)
1974 return PMINFO_R_ERROR;
1976 if (info->app_info->portraitimg == NULL)
1979 *portrait_img = (char *)info->app_info->portraitimg;
1981 if (info->app_info->landscapeimg == NULL)
1982 *landscape_img = "";
1984 *landscape_img = (char *)info->app_info->landscapeimg;
1989 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1991 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1993 if (handle == NULL || effectimage_type == NULL) {
1994 LOGE("invalid parameter");
1995 return PMINFO_R_EINVAL;
1998 if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1999 return PMINFO_R_ERROR;
2001 *effectimage_type = (char *)info->app_info->effectimage_type;
2006 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
2008 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2010 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2011 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2013 if (info->app_info == NULL)
2014 return PMINFO_R_ERROR;
2016 if (info->app_info->submode_mainid == NULL)
2017 *submode_mainid = "";
2019 *submode_mainid = (char *)info->app_info->submode_mainid;
2024 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2026 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2027 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2029 if (info->app_info && info->app_info->installed_storage) {
2030 if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2031 *storage = PMINFO_INTERNAL_STORAGE;
2032 else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2033 *storage = PMINFO_EXTERNAL_STORAGE;
2035 return PMINFO_R_ERROR;
2037 return PMINFO_R_ERROR;
2043 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2045 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2047 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2048 retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2050 if (info->app_info->launch_mode == NULL)
2051 return PMINFO_R_ERROR;
2053 *mode = (char *)(info->app_info->launch_mode);
2058 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2060 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2062 if (handle == NULL || alias_appid == NULL) {
2063 LOGE("invalid parameter");
2064 return PMINFO_R_EINVAL;
2067 if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2068 return PMINFO_R_ERROR;
2070 *alias_appid = (char *)info->app_info->alias_appid;
2075 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2077 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2079 if (handle == NULL || effective_appid == NULL) {
2080 LOGE("invalid parameter");
2081 return PMINFO_R_EINVAL;
2084 if (info->app_info == NULL)
2085 return PMINFO_R_ERROR;
2087 if (info->app_info->effective_appid == NULL)
2088 *effective_appid = "";
2090 *effective_appid = (char *)info->app_info->effective_appid;
2095 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2097 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2099 if (handle == NULL || tep_name == NULL) {
2100 LOGE("invalid parameter");
2101 return PMINFO_R_EINVAL;
2104 if (info->app_info == NULL)
2105 return PMINFO_R_ERROR;
2107 if (info->app_info->tep_name == NULL)
2110 *tep_name = (char *)info->app_info->tep_name;
2115 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2117 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2119 if (handle == NULL || zip_mount_file == NULL) {
2120 LOGE("invalid parameter");
2121 return PMINFO_R_EINVAL;
2124 if (info->app_info == NULL)
2125 return PMINFO_R_ERROR;
2127 if (info->app_info->zip_mount_file == NULL)
2128 *zip_mount_file = "";
2130 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2135 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2137 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2139 if (handle == NULL || root_path == NULL) {
2140 LOGE("invalid parameter");
2141 return PMINFO_R_EINVAL;
2144 if (info->app_info == NULL || info->app_info->root_path == NULL)
2145 return PMINFO_R_ERROR;
2147 *root_path = (char *)info->app_info->root_path;
2152 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2154 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2156 if (handle == NULL || api_version == NULL) {
2157 LOGE("invalid parameter");
2158 return PMINFO_R_EINVAL;
2161 if (info->app_info == NULL || info->app_info->api_version == NULL)
2162 return PMINFO_R_ERROR;
2164 *api_version = (char *)info->app_info->api_version;
2169 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2171 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2173 if (handle == NULL || installed_time == NULL) {
2174 LOGE("invalid parameter");
2175 return PMINFO_R_EINVAL;
2178 if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2179 return PMINFO_R_ERROR;
2181 *installed_time = atoi(info->app_info->package_installed_time);
2186 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2187 const char *type, uid_t uid, char **appid, char **access)
2189 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2190 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2191 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2192 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2194 int ret = PMINFO_R_OK;
2196 sqlite3_stmt *stmt = NULL;
2199 ret = __open_manifest_db(uid, true);
2200 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2202 /*Start constructing query*/
2203 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
2204 tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2207 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2208 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2211 ret = sqlite3_step(stmt);
2212 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2214 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2215 *access = strdup((char *)sqlite3_column_text(stmt, 2));
2220 sqlite3_free(query);
2221 sqlite3_finalize(stmt);
2222 __close_manifest_db();
2226 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2227 const char *type, char **appid, char **access)
2229 return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2230 type, _getuid(), appid, access);
2233 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
2235 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2236 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2238 int ret = PMINFO_R_OK;
2240 sqlite3_stmt *stmt = NULL;
2243 ret = __open_manifest_db(uid, true);
2244 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2246 /*Start constructing query*/
2247 query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
2248 tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2251 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2252 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2255 ret = sqlite3_step(stmt);
2256 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2258 *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2263 sqlite3_free(query);
2264 sqlite3_finalize(stmt);
2265 __close_manifest_db();
2269 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2271 return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2274 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(const char *providerid,
2275 const char *type, uid_t uid, char **appid, bool *is_trusted)
2277 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2278 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2280 int ret = PMINFO_R_OK;
2282 sqlite3_stmt *stmt = NULL;
2285 ret = __open_manifest_db(uid, true);
2286 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2288 /*Start constructing query*/
2289 query = sqlite3_mprintf("SELECT app_id, trusted FROM package_app_data_control WHERE providerid=%Q AND type=%Q", providerid, type);
2290 tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2293 ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2294 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2297 ret = sqlite3_step(stmt);
2298 tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2300 _save_column_str(stmt, 0, appid);
2301 *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2306 sqlite3_free(query);
2307 sqlite3_finalize(stmt);
2308 __close_manifest_db();
2312 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2313 const char *type, char **appid, bool *is_trusted)
2315 return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2316 type, _getuid(), appid, is_trusted);
2320 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode)
2322 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2323 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2325 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2326 if (info->app_info->support_mode)
2327 *support_mode = atoi(info->app_info->support_mode);
2334 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
2335 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
2337 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2338 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2342 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2344 if (info->app_info == NULL)
2345 return PMINFO_R_ERROR;
2347 for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
2348 ptr = (permission_x *)tmp->data;
2352 ret = permission_func(ptr->value, user_data);
2360 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2361 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2363 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2364 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2366 const char *category;
2368 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2370 if (info->app_info == NULL)
2371 return PMINFO_R_ERROR;
2373 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2374 category = (const char *)tmp->data;
2376 ret = category_func(category, user_data);
2384 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2385 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2387 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2388 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2392 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2394 if (info->app_info == NULL)
2395 return PMINFO_R_ERROR;
2397 for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2398 ptr = (metadata_x *)tmp->data;
2402 ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2410 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2411 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2413 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2414 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2416 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2417 appcontrol_x *appcontrol;
2420 if (info->app_info == NULL)
2421 return PMINFO_R_ERROR;
2423 for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2424 appcontrol = (appcontrol_x *)tmp->data;
2425 if (appcontrol == NULL)
2427 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2435 API int pkgmgrinfo_appinfo_foreach_background_category(
2436 pkgmgrinfo_appinfo_h handle,
2437 pkgmgrinfo_app_background_category_list_cb category_func,
2440 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2444 if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2445 LOGE("invalid parameter");
2446 return PMINFO_R_EINVAL;
2449 for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2450 category = (char *)tmp->data;
2451 if (category == NULL)
2454 if (category_func(category, user_data) < 0)
2461 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2462 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2465 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2466 splashscreen_x *splashscreen;
2470 if (info == NULL || info->app_info == NULL
2471 || splash_screen_func == NULL) {
2472 LOGE("invalid parameter");
2473 return PMINFO_R_EINVAL;
2476 for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2477 splashscreen = (splashscreen_x *)tmp->data;
2478 if (splashscreen == NULL)
2480 ret = splash_screen_func(splashscreen->src,
2482 splashscreen->orientation,
2483 splashscreen->indicatordisplay,
2484 splashscreen->operation,
2485 splashscreen->color_depth,
2494 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2496 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2497 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2498 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2500 if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2501 return PMINFO_R_ERROR;
2503 *nodisplay = _get_bool_value(info->app_info->nodisplay);
2508 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2510 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2511 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2512 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2514 if (info->app_info == NULL || info->app_info->multiple == NULL)
2515 return PMINFO_R_ERROR;
2517 *multiple = _get_bool_value(info->app_info->multiple);
2522 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2524 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2525 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2526 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2528 if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2529 return PMINFO_R_ERROR;
2531 *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2536 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
2538 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2539 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2540 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2542 if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2543 return PMINFO_R_ERROR;
2545 *taskmanage = _get_bool_value(info->app_info->taskmanage);
2550 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
2552 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2553 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2554 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2556 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2557 return PMINFO_R_ERROR;
2559 *enabled = !_get_bool_value(info->app_info->is_disabled);
2564 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
2566 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2567 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2568 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2570 if (info->app_info == NULL || info->app_info->onboot == NULL)
2571 return PMINFO_R_ERROR;
2573 *onboot = _get_bool_value(info->app_info->onboot);
2578 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
2580 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2581 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2582 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2584 if (info->app_info == NULL || info->app_info->autorestart == NULL)
2585 return PMINFO_R_ERROR;
2587 *autorestart = _get_bool_value(info->app_info->autorestart);
2592 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
2594 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2595 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2596 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2598 if (info->app_info == NULL || info->app_info->mainapp == NULL)
2599 return PMINFO_R_ERROR;
2601 *mainapp = _get_bool_value(info->app_info->mainapp);
2606 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2608 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2609 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2610 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2612 if (info->app_info == NULL || info->app_info->preload == NULL)
2613 return PMINFO_R_ERROR;
2615 *preload = _get_bool_value(info->app_info->preload);
2620 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2622 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2623 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2624 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2626 if (info->app_info == NULL || info->app_info->submode == NULL)
2627 return PMINFO_R_ERROR;
2629 *submode = _get_bool_value(info->app_info->submode);
2634 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2636 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2638 if (handle == NULL || process_pool == NULL) {
2639 LOGE("invalid parameter");
2640 return PMINFO_R_EINVAL;
2643 if (info->app_info == NULL)
2644 return PMINFO_R_ERROR;
2646 *process_pool = _get_bool_value(info->app_info->process_pool);
2651 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2653 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2654 retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2655 retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2659 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2661 if (info->app_info == NULL)
2662 return PMINFO_R_ERROR;
2665 for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2666 val = (const char *)tmp->data;
2669 if (strcasecmp(val, category) == 0) {
2678 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2681 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2683 if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2684 _LOGE("invalid parameter");
2685 return PMINFO_R_EINVAL;
2687 if (info->app_info->ui_gadget == NULL)
2688 info->app_info->ui_gadget = strdup("false");
2690 *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2695 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2696 bool *support_disable)
2698 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2700 if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2701 _LOGE("invalid parameter");
2702 return PMINFO_R_EINVAL;
2705 *support_disable = _get_bool_value(info->app_info->support_disable);
2710 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
2713 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2715 if (info == NULL || info->app_info == NULL || removable == NULL) {
2716 _LOGE("invalid parameter");
2717 return PMINFO_R_EINVAL;
2720 *removable = _get_bool_value(info->app_info->removable);
2725 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
2727 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2729 if (info == NULL || info->app_info == NULL || system == NULL) {
2730 _LOGE("invalid parameter");
2731 return PMINFO_R_EINVAL;
2734 *system = _get_bool_value(info->app_info->package_system);
2739 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2741 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2742 retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2743 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2745 if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2746 return PMINFO_R_ERROR;
2748 *disabled = _get_bool_value(info->app_info->is_disabled);
2753 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2755 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2757 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2758 retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2760 if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2761 return PMINFO_R_ERROR;
2763 *global = _get_bool_value(info->app_info->for_all_users);
2768 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
2770 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2772 if (info == NULL || splash_screen_display == NULL) {
2773 _LOGE("Invalid parameter");
2774 return PMINFO_R_EINVAL;
2777 if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
2778 return PMINFO_R_ERROR;
2780 *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
2785 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
2787 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2789 if (info == NULL || setup_appid == NULL) {
2790 _LOGE("Invalid parameter");
2791 return PMINFO_R_EINVAL;
2794 if (info->app_info == NULL || info->app_info->setup_appid == NULL)
2795 return PMINFO_R_ERROR;
2797 *setup_appid = info->app_info->setup_appid;
2801 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
2802 bool *support_ambient)
2804 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2806 if (info == NULL || support_ambient == NULL) {
2807 _LOGE("Invalid parameter");
2808 return PMINFO_R_EINVAL;
2811 if (info->app_info == NULL || info->app_info->support_ambient == NULL)
2812 return PMINFO_R_ERROR;
2814 *support_ambient = _get_bool_value(info->app_info->support_ambient);
2819 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2821 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2822 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2823 __cleanup_appinfo(info);
2827 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2829 return (pkgmgrinfo_pkginfo_filter_create(handle));
2832 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2834 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2837 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2839 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
2840 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
2841 if (node1->prop == node2->prop)
2843 else if (node1->prop > node2->prop)
2849 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2850 const char *property, const int value)
2852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2853 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2854 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2856 GSList *link = NULL;
2858 prop = _pminfo_appinfo_convert_to_prop_int(property);
2859 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2860 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2861 _LOGE("Invalid Integer Property\n");
2862 return PMINFO_R_EINVAL;
2864 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2865 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2867 _LOGE("Out of Memory!!!\n");
2868 return PMINFO_R_ERROR;
2870 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2871 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2873 _LOGE("Out of Memory\n");
2876 return PMINFO_R_ERROR;
2880 /*If API is called multiple times for same property, we should override the previous values.
2881 Last value set will be used for filtering.*/
2882 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2884 filter->list = g_slist_delete_link(filter->list, link);
2885 filter->list = g_slist_append(filter->list, (gpointer)node);
2890 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2891 const char *property, const bool value)
2893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2894 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2896 GSList *link = NULL;
2898 prop = _pminfo_appinfo_convert_to_prop_bool(property);
2899 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2900 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2901 _LOGE("Invalid Boolean Property\n");
2902 return PMINFO_R_EINVAL;
2904 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2905 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2907 _LOGE("Out of Memory!!!\n");
2908 return PMINFO_R_ERROR;
2911 val = strndup("true", 4);
2913 val = strndup("false", 5);
2915 _LOGE("Out of Memory\n");
2918 return PMINFO_R_ERROR;
2922 /*If API is called multiple times for same property, we should override the previous values.
2923 Last value set will be used for filtering.*/
2924 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2926 filter->list = g_slist_delete_link(filter->list, link);
2927 filter->list = g_slist_append(filter->list, (gpointer)node);
2932 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2933 const char *property, const char *value)
2935 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2936 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2937 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2939 pkgmgrinfo_node_x *ptr = NULL;
2940 char prev[PKG_STRING_LEN_MAX] = {'\0'};
2941 char temp[PKG_STRING_LEN_MAX] = {'\0'};
2942 GSList *link = NULL;
2944 prop = _pminfo_appinfo_convert_to_prop_str(property);
2945 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2946 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2947 _LOGE("Invalid String Property\n");
2948 return PMINFO_R_EINVAL;
2950 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2951 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2953 _LOGE("Out of Memory!!!\n");
2954 return PMINFO_R_ERROR;
2958 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2959 node->value = strdup(value);
2960 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2962 filter->list = g_slist_delete_link(filter->list, link);
2963 filter->list = g_slist_append(filter->list, (gpointer)node);
2965 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2966 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2968 _LOGE("Out of Memory\n");
2971 return PMINFO_R_ERROR;
2973 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2975 ptr = (pkgmgrinfo_node_x *)link->data;
2976 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2977 _LOGI("Previous value is %s\n", prev);
2978 filter->list = g_slist_delete_link(filter->list, link);
2979 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
2980 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2981 _LOGI("New value is %s\n", val);
2983 filter->list = g_slist_append(filter->list, (gpointer)node);
2984 memset(temp, '\0', PKG_STRING_LEN_MAX);
2986 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
2987 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2988 _LOGI("First value is %s\n", val);
2990 filter->list = g_slist_append(filter->list, (gpointer)node);
2991 memset(temp, '\0', PKG_STRING_LEN_MAX);
2995 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2996 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2998 filter->list = g_slist_delete_link(filter->list, link);
2999 filter->list = g_slist_append(filter->list, (gpointer)node);
3005 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3011 if (handle == NULL || count == NULL) {
3012 _LOGE("invalid parameter");
3013 return PMINFO_R_EINVAL;
3016 locale = _get_system_locale();
3018 return PMINFO_R_ERROR;
3020 list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3021 __free_applications);
3024 return PMINFO_R_ERROR;
3027 ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3028 if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3029 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3032 if (ret != PMINFO_R_OK) {
3033 g_hash_table_destroy(list);
3035 return PMINFO_R_ERROR;
3038 *count = g_hash_table_size(list);
3039 g_hash_table_destroy(list);
3045 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3047 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3050 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3051 pkgmgrinfo_appinfo_filter_h handle,
3052 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3054 if (handle == NULL || app_cb == NULL) {
3055 LOGE("invalid parameter");
3056 return PMINFO_R_EINVAL;
3059 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3063 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3064 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3066 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3069 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3071 return (pkgmgrinfo_pkginfo_filter_create(handle));
3074 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3076 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3079 API int pkgmgrinfo_appinfo_metadata_filter_add(
3080 pkgmgrinfo_appinfo_metadata_filter_h handle,
3081 const char *key, const char *value)
3083 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3084 pkgmgrinfo_metadata_node_x *node;
3086 /* value can be NULL.
3087 * In that case all apps with specified key should be displayed
3090 LOGE("invalid parameter");
3091 return PMINFO_R_EINVAL;
3094 node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3096 LOGE("out of memory");
3097 return PMINFO_R_ERROR;
3100 node->key = strdup(key);
3101 if (value && strlen(value))
3102 node->value = strdup(value);
3104 filter->list_metadata = g_slist_append(filter->list_metadata,
3110 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3111 pkgmgrinfo_appinfo_metadata_filter_h handle,
3112 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3114 if (handle == NULL || app_cb == NULL) {
3115 LOGE("invalid parameter");
3116 return PMINFO_R_EINVAL;
3119 return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3123 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3124 pkgmgrinfo_appinfo_metadata_filter_h handle,
3125 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3127 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3128 user_data, _getuid());
3131 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3134 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3136 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3137 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3139 val = info->app_info->guestmode_visibility;
3140 *status = _get_bool_value(val);