X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fpkgmgrinfo_appinfo.c;h=ed529f777591a52849b7ec8b175099c86ca9f985;hb=c17095e7501de17f67611498b02ad501fc07c7c3;hp=3607bf4cdbd27db5ad537afbb0de80daa372615b;hpb=825b606af22e970e719f76365ebba6a18486cd71;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git diff --git a/src/pkgmgrinfo_appinfo.c b/src/pkgmgrinfo_appinfo.c index 3607bf4..ed529f7 100644 --- a/src/pkgmgrinfo_appinfo.c +++ b/src/pkgmgrinfo_appinfo.c @@ -54,32 +54,60 @@ static const char join_metadata[] = " ON ai.app_id=package_app_app_metadata.app_id "; static int _get_filtered_query(pkgmgrinfo_filter_x *filter, - const char *locale, char **query, GList **bind_params) + const char *locale, uid_t uid, char **query, GList **bind_params) { int joined = 0; size_t len = 0; char *condition = NULL; char buf[MAX_QUERY_LEN] = { '\0' }; char tmp_query[MAX_QUERY_LEN] = { '\0' }; + static const char query_pkg_disable[] = " AND ai.package IN " + "(SELECT package FROM package_info WHERE package_disable='false')"; GSList *list; - if (filter == NULL) + strncat(buf, " WHERE 1=1", MAX_QUERY_LEN - len - 1); + len += strlen(" WHERE 1=1"); + + if (filter == NULL) { + strncat(buf, query_pkg_disable, MAX_QUERY_LEN - len - 1); + *query = strdup(buf); return PMINFO_R_OK; + } - len += strlen(" WHERE 1=1"); - strncat(buf, " WHERE 1=1", MAX_QUERY_LEN - len - 1); for (list = filter->list; list; list = list->next) { - joined |= __get_filter_condition(list->data, &condition, bind_params); + joined |= __get_filter_condition(list->data, uid, &condition, bind_params); if (condition == NULL) continue; - len += strlen(" AND "); strncat(buf, " AND ", MAX_QUERY_LEN - len - 1); + len += strlen(" AND "); + strncat(buf, condition, sizeof(buf) - len - 1); len += strlen(condition); + free(condition); + condition = NULL; + } + + if (filter->list_metadata) { + strncat(buf, " AND (", MAX_QUERY_LEN - len - 1); + len += strlen(" AND ("); + } + for (list = filter->list_metadata; list; list = list->next) { + joined |= __get_metadata_filter_condition(list->data, + &condition, bind_params); + if (condition == NULL) + continue; strncat(buf, condition, sizeof(buf) - len - 1); + len += strlen(condition); free(condition); condition = NULL; + + strncat(buf, " OR ", MAX_QUERY_LEN - len - 1); + len += strlen(" OR "); + } + if (filter->list_metadata) { + strncat(buf, "1=0)", MAX_QUERY_LEN - len - 1); + len += strlen("1=0)"); } if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) { @@ -99,7 +127,11 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter, strncat(tmp_query, join_metadata, MAX_QUERY_LEN - len - 1); len += strlen(join_metadata); } + strncat(tmp_query, buf, MAX_QUERY_LEN - len - 1); + len += strlen(buf); + + strncat(tmp_query, query_pkg_disable, MAX_QUERY_LEN - len - 1); *query = strdup(tmp_query); if (*query == NULL) @@ -108,95 +140,6 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter, return PMINFO_R_OK; } -static int _appinfo_get_label(sqlite3 *db, const char *appid, - const char *locale, GList **label) -{ - static const char query_raw[] = - "SELECT app_label, app_locale " - "FROM package_app_localized_info " - "WHERE app_id=%Q AND app_locale IN (%Q, %Q)"; - int ret; - char *query; - sqlite3_stmt *stmt; - int idx; - label_x *info; - - query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE); - if (query == NULL) { - LOGE("out of memory"); - return PMINFO_R_ERROR; - } - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - sqlite3_free(query); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return PMINFO_R_ERROR; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - info = calloc(1, sizeof(label_x)); - if (info == NULL) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - idx = 0; - _save_column_str(stmt, idx++, &info->text); - _save_column_str(stmt, idx++, &info->lang); - *label = g_list_append(*label, info); - } - - sqlite3_finalize(stmt); - - return PMINFO_R_OK; -} - -static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale, - GList **icon) -{ - static const char query_raw[] = - "SELECT app_icon, app_locale " - "FROM package_app_localized_info " - "WHERE app_id=%Q AND app_locale IN (%Q, %Q)"; - int ret; - char *query; - sqlite3_stmt *stmt; - int idx; - icon_x *info; - - query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE); - if (query == NULL) { - LOGE("out of memory"); - return PMINFO_R_ERROR; - } - - ret = sqlite3_prepare_v2(db, query, strlen(query), - &stmt, NULL); - sqlite3_free(query); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return PMINFO_R_ERROR; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - info = calloc(1, sizeof(icon_x)); - if (info == NULL) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - idx = 0; - _save_column_str(stmt, idx++, &info->text); - _save_column_str(stmt, idx++, &info->lang); - *icon = g_list_append(*icon, info); - } - - sqlite3_finalize(stmt); - - return PMINFO_R_OK; -} - static int _appinfo_get_category(sqlite3 *db, const char *appid, GList **category) { @@ -301,50 +244,6 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid, return PMINFO_R_OK; } -static int _appinfo_get_data_control(sqlite3 *db, const char *appid, - GList **datacontrol) -{ - static const char query_raw[] = - "SELECT providerid, access, type " - "FROM package_app_data_control WHERE app_id=%Q"; - int ret; - char *query; - sqlite3_stmt *stmt; - int idx; - datacontrol_x *info; - - query = sqlite3_mprintf(query_raw, appid); - if (query == NULL) { - LOGE("out of memory"); - return PMINFO_R_ERROR; - } - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - sqlite3_free(query); - if (ret != SQLITE_OK) { - LOGE("prepare failed: %s", sqlite3_errmsg(db)); - return PMINFO_R_ERROR; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - info = calloc(1, sizeof(datacontrol_x)); - if (info == NULL) { - LOGE("out of memory"); - sqlite3_finalize(stmt); - return PMINFO_R_ERROR; - } - idx = 0; - _save_column_str(stmt, idx++, &info->providerid); - _save_column_str(stmt, idx++, &info->access); - _save_column_str(stmt, idx++, &info->type); - *datacontrol = g_list_append(*datacontrol, info); - } - - sqlite3_finalize(stmt); - - return PMINFO_R_OK; -} - static int _appinfo_get_metadata(sqlite3 *db, const char *appid, GList **metadata) { @@ -477,40 +376,33 @@ static GList *__get_background_category(const char *value) } -static void __get_splash_screen_display(sqlite3 *db, const char *appid, uid_t uid, char **value) +static void __free_applications(gpointer data) { - static const char query_raw[] = - "SELECT is_splash_screen_enabled FROM package_app_info_for_uid " - "WHERE app_id='%s' AND uid='%d'"; - int ret; - char *query; - sqlite3_stmt *stmt; - - query = sqlite3_mprintf(query_raw, appid, uid); - if (query == NULL) { - LOGE("out of memory"); - return; - } - - ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); - sqlite3_free(query); - if (ret != SQLITE_OK) { - LOGE("sqlite3_prepare_v2() failed: %s", sqlite3_errmsg(db)); - return; - } + pkgmgrinfo_basic_free_application((application_x *)data); +} - while (sqlite3_step(stmt) == SQLITE_ROW) { - if (*value) - free(*value); - _save_column_str(stmt, 0, value); - } +static gint __app_disable_chk_func(gconstpointer data1, gconstpointer data2) +{ + pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1; - sqlite3_finalize(stmt); + if (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE) + return 0; + else + return 1; } -static void __free_applications(gpointer data) +static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter) { - pkgmgrinfo_basic_free_application((application_x *)data); + GSList *link; + + if (filter == NULL) + return false; + + link = g_slist_find_custom(filter->list, NULL, __app_disable_chk_func); + if (link) + return true; + + return false; } static int __bind_params(sqlite3_stmt *stmt, GList *params) @@ -533,58 +425,135 @@ static int __bind_params(sqlite3_stmt *stmt, GList *params) return PMINFO_R_OK; } +static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter) +{ + GSList *tmp_list = NULL; + pkgmgrinfo_node_x *tmp_node = NULL; + int property = -1; + + if (tmp_filter == NULL) + return true; + + property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE); + for (tmp_list = tmp_filter->list; tmp_list != NULL; + tmp_list = g_slist_next(tmp_list)) { + tmp_node = (pkgmgrinfo_node_x *)tmp_list->data; + if (property == tmp_node->prop) { + if (strcmp(tmp_node->value, "true") == 0) + return true; + else + return false; + } + } + + return true; +} + static int _appinfo_get_applications(uid_t db_uid, uid_t uid, const char *locale, pkgmgrinfo_filter_x *filter, int flag, GHashTable *applications) { static const char query_raw[] = - "SELECT DISTINCT ai.app_id, ai.app_component, ai.app_exec, " + "SELECT DISTINCT ai.app_id, ai.app_installed_storage, " + "ai.app_external_path"; + static const char query_basic[] = + ", ai.app_component, ai.app_exec, " "ai.app_nodisplay, ai.app_type, ai.app_onboot, " "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, " - "ai.app_enabled, ai.app_hwacceleration, ai.app_screenreader, " + "ai.app_hwacceleration, ai.app_screenreader, " "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, " "ai.app_indicatordisplay, ai.app_portraitimg, " "ai.app_landscapeimg, ai.app_guestmodevisibility, " "ai.app_permissiontype, ai.app_preload, ai.app_submode, " "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, " "ai.app_support_disable, ai.app_process_pool, " - "ai.app_installed_storage, ai.app_background_category, " - "ai.app_package_type, ai.app_root_path, ai.app_api_version, " - "ai.app_effective_appid, ai.app_disable, " - "ai.app_splash_screen_display, ai.app_tep_name, " - "ai.app_zip_mount_file, ai.component_type, ai.package " - "FROM package_app_info as ai"; + "ai.app_background_category, ai.app_package_type, " + "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, " + "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, " + "ai.app_zip_mount_file, ai.component_type, ai.package, " + "ai.app_package_system, ai.app_removable, " + "ai.app_package_installed_time, ai.app_support_mode, " + "ai.app_support_ambient, ai.app_setup_appid"; + static const char query_uid_info[] = + ", ui.is_disabled, ui.is_splash_screen_enabled"; + static const char query_label[] = + ", COALESCE(" + "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), " + "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))"; + static const char query_icon[] = + ", COALESCE(" + "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), " + "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))"; + static const char query_from_clause[] = " FROM package_app_info as ai"; + static const char query_uid_info_clause[] = + " LEFT OUTER JOIN package_app_info_for_uid AS ui " + "ON (ai.app_id=ui.app_id AND ui.uid=?)"; int ret = PMINFO_R_ERROR; int idx; - const char *dbpath; + int len = 0; + char *dbpath; char *bg_category_str = NULL; char *constraint = NULL; + char *tmp_record = NULL; char query[MAX_QUERY_LEN] = { '\0' }; + char buf[BUFSIZE] = { '\0' }; application_x *info = NULL; GList *bind_params = NULL; sqlite3 *db = NULL; sqlite3_stmt *stmt = NULL; + bool is_check_storage = true; + const uid_t global_user_uid = GLOBAL_USER; dbpath = getUserPkgParserDBPathUID(db_uid); if (dbpath == NULL) return PMINFO_R_ERROR; - ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL); + ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY); if (ret != SQLITE_OK) { _LOGE("failed to open db: %d", ret); + free(dbpath); return PMINFO_R_ERROR; } + free(dbpath); + + len = strlen(query_raw); + snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw); - ret = _get_filtered_query(filter, locale, &constraint, &bind_params); + if (flag & PMINFO_APPINFO_GET_BASICINFO) { + strncat(query, query_basic, MAX_QUERY_LEN - len - 1); + len += strlen(query_basic); + strncat(query, query_uid_info, MAX_QUERY_LEN - len - 1); + len += strlen(query_uid_info); + } + if (flag & PMINFO_APPINFO_GET_LABEL) { + strncat(query, query_label, MAX_QUERY_LEN - len - 1); + len += strlen(query_label); + bind_params = g_list_append(bind_params, strdup(locale)); + } + if (flag & PMINFO_APPINFO_GET_ICON) { + strncat(query, query_icon, MAX_QUERY_LEN - len - 1); + len += strlen(query_icon); + bind_params = g_list_append(bind_params, strdup(locale)); + } + + snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid); + bind_params = g_list_append(bind_params, strdup(buf)); + + is_check_storage = __check_app_storage_status(filter); + + ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params); if (ret != PMINFO_R_OK) { LOGE("Failed to get WHERE clause"); goto catch; } + strncat(query, query_from_clause, MAX_QUERY_LEN - len - 1); + len += strlen(query_from_clause); + + strncat(query, query_uid_info_clause, MAX_QUERY_LEN - len - 1); + len += strlen(query_uid_info_clause); if (constraint) - snprintf(query, MAX_QUERY_LEN - 1, "%s%s", query_raw, constraint); - else - snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw); + strncat(query, constraint, MAX_QUERY_LEN - len - 1); ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); if (ret != SQLITE_OK) { @@ -610,72 +579,96 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid, } idx = 0; _save_column_str(stmt, idx++, &info->appid); - if (g_hash_table_contains(applications, - (gconstpointer)info->appid)) { - free(info->appid); - free(info); - continue; - } - _save_column_str(stmt, idx++, &info->component); - _save_column_str(stmt, idx++, &info->exec); - _save_column_str(stmt, idx++, &info->nodisplay); - _save_column_str(stmt, idx++, &info->type); - _save_column_str(stmt, idx++, &info->onboot); - _save_column_str(stmt, idx++, &info->multiple); - _save_column_str(stmt, idx++, &info->autorestart); - _save_column_str(stmt, idx++, &info->taskmanage); - _save_column_str(stmt, idx++, &info->enabled); - _save_column_str(stmt, idx++, &info->hwacceleration); - _save_column_str(stmt, idx++, &info->screenreader); - _save_column_str(stmt, idx++, &info->mainapp); - _save_column_str(stmt, idx++, &info->recentimage); - _save_column_str(stmt, idx++, &info->launchcondition); - _save_column_str(stmt, idx++, &info->indicatordisplay); - _save_column_str(stmt, idx++, &info->portraitimg); - _save_column_str(stmt, idx++, &info->landscapeimg); - _save_column_str(stmt, idx++, &info->guestmode_visibility); - _save_column_str(stmt, idx++, &info->permission_type); - _save_column_str(stmt, idx++, &info->preload); - _save_column_str(stmt, idx++, &info->submode); - _save_column_str(stmt, idx++, &info->submode_mainid); - _save_column_str(stmt, idx++, &info->launch_mode); - _save_column_str(stmt, idx++, &info->ui_gadget); - _save_column_str(stmt, idx++, &info->support_disable); - _save_column_str(stmt, idx++, &info->process_pool); _save_column_str(stmt, idx++, &info->installed_storage); - _save_column_str(stmt, idx++, &bg_category_str); - _save_column_str(stmt, idx++, &info->package_type); - _save_column_str(stmt, idx++, &info->root_path); - _save_column_str(stmt, idx++, &info->api_version); - _save_column_str(stmt, idx++, &info->effective_appid); - _save_column_str(stmt, idx++, &info->is_disabled); - _save_column_str(stmt, idx++, &info->splash_screen_display); - _save_column_str(stmt, idx++, &info->tep_name); - _save_column_str(stmt, idx++, &info->zip_mount_file); - _save_column_str(stmt, idx++, &info->component_type); - _save_column_str(stmt, idx++, &info->package); - info->for_all_users = - strdup((uid != GLOBAL_USER) ? "false" : "true"); + _save_column_str(stmt, idx++ , &info->external_path); + + if (flag & PMINFO_APPINFO_GET_BASICINFO) { + _save_column_str(stmt, idx++, &info->component); + _save_column_str(stmt, idx++, &info->exec); + _save_column_str(stmt, idx++, &info->nodisplay); + _save_column_str(stmt, idx++, &info->type); + _save_column_str(stmt, idx++, &info->onboot); + _save_column_str(stmt, idx++, &info->multiple); + _save_column_str(stmt, idx++, &info->autorestart); + _save_column_str(stmt, idx++, &info->taskmanage); + _save_column_str(stmt, idx++, &info->hwacceleration); + _save_column_str(stmt, idx++, &info->screenreader); + _save_column_str(stmt, idx++, &info->mainapp); + _save_column_str(stmt, idx++, &info->recentimage); + _save_column_str(stmt, idx++, &info->launchcondition); + _save_column_str(stmt, idx++, &info->indicatordisplay); + _save_column_str(stmt, idx++, &info->portraitimg); + _save_column_str(stmt, idx++, &info->landscapeimg); + _save_column_str(stmt, idx++, &info->guestmode_visibility); + _save_column_str(stmt, idx++, &info->permission_type); + _save_column_str(stmt, idx++, &info->preload); + _save_column_str(stmt, idx++, &info->submode); + _save_column_str(stmt, idx++, &info->submode_mainid); + _save_column_str(stmt, idx++, &info->launch_mode); + _save_column_str(stmt, idx++, &info->ui_gadget); + _save_column_str(stmt, idx++, &info->support_disable); + _save_column_str(stmt, idx++, &info->process_pool); + _save_column_str(stmt, idx++, &bg_category_str); + _save_column_str(stmt, idx++, &info->package_type); + _save_column_str(stmt, idx++, &info->root_path); + _save_column_str(stmt, idx++, &info->api_version); + _save_column_str(stmt, idx++, &info->effective_appid); + _save_column_str(stmt, idx++, &info->is_disabled); + _save_column_str(stmt, idx++, &info->splash_screen_display); + _save_column_str(stmt, idx++, &info->tep_name); + _save_column_str(stmt, idx++, &info->zip_mount_file); + _save_column_str(stmt, idx++, &info->component_type); + _save_column_str(stmt, idx++, &info->package); + _save_column_str(stmt, idx++, &info->package_system); + _save_column_str(stmt, idx++, &info->removable); + _save_column_str(stmt, idx++, &info->package_installed_time); + _save_column_str(stmt, idx++, &info->support_mode); + _save_column_str(stmt, idx++, &info->support_ambient); + _save_column_str(stmt, idx++, &info->setup_appid); + info->background_category = __get_background_category( + bg_category_str); + free(bg_category_str); + } - if (db_uid == GLOBAL_USER) - __get_splash_screen_display(db, info->appid, db_uid, - &info->splash_screen_display); + info->for_all_users = + strdup((db_uid != global_user_uid) ? "false" : "true"); - info->background_category = __get_background_category( - bg_category_str); - free(bg_category_str); + if (db_uid != global_user_uid) { + idx = idx + 2; + } else { + tmp_record = NULL; + _save_column_str(stmt, idx++, &tmp_record); + if (tmp_record != NULL) { + if (strcasecmp(info->is_disabled, "false") == 0 && + strcasecmp(tmp_record, "false") == 0) { + free(info->is_disabled); + info->is_disabled = tmp_record; + } + } + tmp_record = NULL; + _save_column_str(stmt, idx++, &tmp_record); + if (tmp_record != NULL) { + if (strcasecmp(info->splash_screen_display, "false") == 0 && + strcasecmp(tmp_record, "false") == 0) { + free(info->splash_screen_display); + info->splash_screen_display = tmp_record; + } + } + } if (flag & PMINFO_APPINFO_GET_LABEL) { - if (_appinfo_get_label(db, info->appid, locale, - &info->label)) { + tmp_record = NULL; + _save_column_str(stmt, idx++, &tmp_record); + if (_add_label_info_into_list(locale, tmp_record, &info->label)) { ret = PMINFO_R_ERROR; goto catch; } } if (flag & PMINFO_APPINFO_GET_ICON) { - if (_appinfo_get_icon(db, info->appid, locale, - &info->icon)) { + tmp_record = NULL; + _save_column_str(stmt, idx++, &tmp_record); + if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) { ret = PMINFO_R_ERROR; goto catch; } @@ -697,14 +690,6 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid, } } - if (flag & PMINFO_APPINFO_GET_DATA_CONTROL) { - if (_appinfo_get_data_control(db, info->appid, - &info->datacontrol)) { - ret = PMINFO_R_ERROR; - goto catch; - } - } - if (flag & PMINFO_APPINFO_GET_METADATA) { if (_appinfo_get_metadata(db, info->appid, &info->metadata)) { @@ -721,6 +706,14 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid, } } + if (is_check_storage && + __appinfo_check_installed_storage(info) != PMINFO_R_OK) { + ret = PMINFO_R_ERROR; + pkgmgrinfo_basic_free_application(info); + info = NULL; + continue; + } + g_hash_table_insert(applications, (gpointer)info->appid, (gpointer)info); } @@ -741,49 +734,25 @@ catch: return ret; } -API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid, - pkgmgrinfo_appinfo_h *handle) +static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid, + pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle) { int ret; char *locale; GHashTable *list; - pkgmgrinfo_appinfo_filter_h filter; pkgmgr_appinfo_x *info; - if (appid == NULL || handle == NULL) { - LOGE("invalid parameter"); - return PMINFO_R_EINVAL; + if (appid == NULL || filter == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; } locale = _get_system_locale(); if (locale == NULL) return PMINFO_R_ERROR; - ret = pkgmgrinfo_appinfo_filter_create(&filter); - if (ret != PMINFO_R_OK) { - free(locale); - return ret; - } - - ret = pkgmgrinfo_appinfo_filter_add_string(filter, - PMINFO_APPINFO_PROP_APP_ID, appid); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_appinfo_filter_destroy(filter); - free(locale); - return PMINFO_R_ERROR; - } - - ret = pkgmgrinfo_appinfo_filter_add_bool(filter, - PMINFO_APPINFO_PROP_APP_DISABLE, true); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_appinfo_filter_destroy(filter); - free(locale); - return PMINFO_R_ERROR; - } - list = g_hash_table_new(g_str_hash, g_str_equal); if (list == NULL) { - pkgmgrinfo_appinfo_filter_destroy(filter); free(locale); return PMINFO_R_ERROR; } @@ -791,18 +760,11 @@ API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid ret = _appinfo_get_applications(uid, uid, locale, filter, PMINFO_APPINFO_GET_ALL, list); if (!g_hash_table_size(list) && uid != GLOBAL_USER) - ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, - filter, PMINFO_APPINFO_GET_ALL, list); - - pkgmgrinfo_appinfo_filter_destroy(filter); - if (ret != PMINFO_R_OK) { - g_hash_table_destroy(list); - free(locale); - return ret; - } + ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter, + PMINFO_APPINFO_GET_ALL, list); if (!g_hash_table_size(list)) { - _LOGI("Appinfo for [%s] is not existed for user [%d]", + _LOGI("appinfo for [%s] is not existed for user [%d]", appid, uid); g_hash_table_destroy(list); free(locale); @@ -812,6 +774,7 @@ API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid info = calloc(1, sizeof(pkgmgr_appinfo_x)); if (info == NULL) { _LOGE("out of memory"); + g_hash_table_destroy(list); free(locale); return PMINFO_R_ERROR; } @@ -828,6 +791,41 @@ API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid return ret; } +API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid, + pkgmgrinfo_appinfo_h *handle) +{ + int ret; + pkgmgrinfo_appinfo_filter_h filter; + + if (appid == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = pkgmgrinfo_appinfo_filter_add_string(filter, + PMINFO_APPINFO_PROP_APP_ID, appid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_DISABLE, true); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } + + ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle); + pkgmgrinfo_appinfo_filter_destroy(filter); + + return ret; +} + API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle) { return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle); @@ -837,31 +835,21 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle) { int ret; - char *locale; - GHashTable *list; pkgmgrinfo_appinfo_filter_h filter; - pkgmgr_appinfo_x *info; if (appid == NULL || handle == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - locale = _get_system_locale(); - if (locale == NULL) - return PMINFO_R_ERROR; - ret = pkgmgrinfo_appinfo_filter_create(&filter); - if (ret != PMINFO_R_OK) { - free(locale); + if (ret != PMINFO_R_OK) return ret; - } ret = pkgmgrinfo_appinfo_filter_add_string(filter, PMINFO_APPINFO_PROP_APP_ID, appid); if (ret != PMINFO_R_OK) { pkgmgrinfo_appinfo_filter_destroy(filter); - free(locale); return PMINFO_R_ERROR; } @@ -869,59 +857,57 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, PMINFO_APPINFO_PROP_APP_DISABLE, false); if (ret != PMINFO_R_OK) { pkgmgrinfo_appinfo_filter_destroy(filter); - free(locale); return PMINFO_R_ERROR; } - list = g_hash_table_new(g_str_hash, g_str_equal); - if (list == NULL) { - pkgmgrinfo_appinfo_filter_destroy(filter); - free(locale); - return PMINFO_R_ERROR; - } + ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle); + pkgmgrinfo_appinfo_filter_destroy(filter); + return ret; +} - ret = _appinfo_get_applications(uid, uid, locale, filter, - PMINFO_APPINFO_GET_ALL, list); - if (!g_hash_table_size(list) && uid != GLOBAL_USER) - ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, - filter, PMINFO_APPINFO_GET_ALL, list); +API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle) +{ + return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle); +} - pkgmgrinfo_appinfo_filter_destroy(filter); - if (ret != PMINFO_R_OK) { - g_hash_table_destroy(list); - free(locale); - return ret; - } +API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid, + pkgmgrinfo_appinfo_h *handle) +{ + int ret; + pkgmgrinfo_appinfo_filter_h filter; - if (!g_hash_table_size(list)) { - _LOGI("Appinfo for [%s] is not existed for user [%d]", appid, uid); - g_hash_table_destroy(list); - free(locale); - return PMINFO_R_ENOENT; + if (appid == NULL || handle == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; } - info = calloc(1, sizeof(pkgmgr_appinfo_x)); - if (info == NULL) { - _LOGE("out of memory"); - free(locale); + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = pkgmgrinfo_appinfo_filter_add_string(filter, + PMINFO_APPINFO_PROP_APP_ID, appid); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); return PMINFO_R_ERROR; } - info->app_info = (application_x *)g_hash_table_lookup(list, appid); - info->locale = locale; - info->package = strdup(info->app_info->package); - - /* just free list only */ - g_hash_table_destroy(list); + ret = pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; + } - *handle = info; + ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle); + pkgmgrinfo_appinfo_filter_destroy(filter); return ret; } -API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle) +API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle) { - return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle); + return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle); } static gpointer __copy_str(gconstpointer src, gpointer data) @@ -1025,6 +1011,8 @@ static gpointer __copy_datacontrol(gconstpointer src, gpointer data) datacontrol->access = strdup(tmp->access); if (tmp->type) datacontrol->type = strdup(tmp->type); + if (tmp->trusted) + datacontrol->trusted = strdup(tmp->trusted); return datacontrol; } @@ -1100,8 +1088,6 @@ static int _appinfo_copy_appinfo(application_x **application, application_x *dat app_info->multiple = strdup(data->multiple); if (data->taskmanage != NULL) app_info->taskmanage = strdup(data->taskmanage); - if (data->enabled != NULL) - app_info->enabled = strdup(data->enabled); if (data->type != NULL) app_info->type = strdup(data->type); if (data->categories != NULL) @@ -1289,10 +1275,16 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid, return PMINFO_R_ERROR; } - ret = _appinfo_get_applications(uid, uid, locale, filter, flag, list); + if (__check_disable_filter_exist(filter) == false) { + pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_DISABLE, false); + } + + ret = _appinfo_get_applications(uid, uid, locale, filter, + flag | PMINFO_APPINFO_GET_BASICINFO, list); if (ret == PMINFO_R_OK && uid != GLOBAL_USER) ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, - filter, flag, list); + filter, flag | PMINFO_APPINFO_GET_BASICINFO, list); if (ret != PMINFO_R_OK) { g_hash_table_destroy(list); @@ -1345,15 +1337,6 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, return PMINFO_R_ERROR; } - if (uid == GLOBAL_USER) { - if (pkgmgrinfo_appinfo_filter_add_int(filter, - PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, - (int)getuid())) { - pkgmgrinfo_appinfo_filter_destroy(filter); - return PMINFO_R_ERROR; - } - } - comp_str = __appcomponent_str(component); if (comp_str) { @@ -1401,13 +1384,10 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list_full( return PMINFO_R_ERROR; } - if (uid == GLOBAL_USER) { - if (pkgmgrinfo_appinfo_filter_add_int(filter, - PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, - (int)getuid())) { - pkgmgrinfo_appinfo_filter_destroy(filter); - return PMINFO_R_ERROR; - } + if (pkgmgrinfo_appinfo_filter_add_bool(filter, + PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) { + pkgmgrinfo_appinfo_filter_destroy(filter); + return PMINFO_R_ERROR; } ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func, @@ -1425,30 +1405,28 @@ API int pkgmgrinfo_appinfo_get_installed_list_full( _getuid(), flag, user_data); } -API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, - uid_t uid, void *user_data) -{ - return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func, - uid, PMINFO_APPINFO_GET_ALL, user_data); -} - -API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, - void *user_data) -{ - return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func, - _getuid(), PMINFO_APPINFO_GET_ALL, user_data); -} - API int pkgmgrinfo_appinfo_get_usr_installed_list( pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data) { + int ret; + pkgmgrinfo_appinfo_filter_h filter; + if (app_func == NULL) { LOGE("invalid parameter"); return PMINFO_R_EINVAL; } - return _appinfo_get_filtered_foreach_appinfo(uid, NULL, + /* create an empty filter */ + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) + return ret; + + ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, PMINFO_APPINFO_GET_ALL, app_func, user_data); + + pkgmgrinfo_appinfo_filter_destroy(filter); + + return ret; } API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, @@ -1530,17 +1508,12 @@ API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec) API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon) { - const char *locale; icon_x *ptr; - GList *tmp; pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - locale = info->locale; - retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL"); - if (info->app_info == NULL) return PMINFO_R_ERROR; @@ -1549,66 +1522,61 @@ API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon) return PMINFO_R_OK; } - for (tmp = info->app_info->icon; tmp; tmp = tmp->next) { - ptr = (icon_x *)tmp->data; - if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || - !strcasecmp(ptr->text, "") || - strcmp(ptr->lang, locale)) - continue; - *icon = (char *)ptr->text; - return PMINFO_R_OK; - } + ptr = (icon_x *)info->app_info->icon->data; + if (ptr == NULL) + return PMINFO_R_ERROR; - locale = DEFAULT_LOCALE; - for (tmp = info->app_info->icon; tmp; tmp = tmp->next) { - ptr = (icon_x *)tmp->data; - if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || - strcmp(ptr->lang, locale)) - continue; - *icon = (char *)ptr->text; - return PMINFO_R_OK; - } + if (ptr->text == NULL) + return PMINFO_R_ERROR; + else + *icon = ptr->text; - return PMINFO_R_ERROR; + return PMINFO_R_OK; } API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label) { - const char *locale; label_x *ptr; - GList *tmp; pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + char *lbl = NULL; + const char *locale; + GList *tmp; retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); - locale = info->locale; - retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL"); - if (info->app_info == NULL) return PMINFO_R_ERROR; + locale = info->locale; + if (locale == NULL) + locale = DEFAULT_LOCALE; + for (tmp = info->app_info->label; tmp; tmp = tmp->next) { ptr = (label_x *)tmp->data; - if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || - strcmp(ptr->lang, locale)) + if (ptr == NULL || strcmp(locale, ptr->lang) != 0) continue; - *label = (char *)ptr->text; + lbl = ptr->text; + break; + } + + if (lbl != NULL) { + *label = lbl; return PMINFO_R_OK; } - locale = DEFAULT_LOCALE; for (tmp = info->app_info->label; tmp; tmp = tmp->next) { ptr = (label_x *)tmp->data; - if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL || - strcmp(ptr->lang, locale)) + if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0) continue; - *label = (char *)ptr->text; - return PMINFO_R_OK; + lbl = ptr->text; + break; } - return PMINFO_R_ERROR; + *label = lbl ? lbl : ""; + + return PMINFO_R_OK; } static char *_get_localed_label(const char *appid, const char *locale, uid_t uid) @@ -1618,18 +1586,20 @@ static char *_get_localed_label(const char *appid, const char *locale, uid_t uid sqlite3_stmt *stmt = NULL; sqlite3 *db = NULL; char *val; - const char *manifest_db; + char *parser_db; - manifest_db = getUserPkgParserDBPathUID(uid); - if (manifest_db == NULL) { - _LOGE("Failed to get manifest db path"); + parser_db = getUserPkgParserDBPathUID(uid); + if (parser_db == NULL) { + _LOGE("Failed to get parser db path"); goto err; } - if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) { + if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) { _LOGE("DB open fail\n"); + free(parser_db); goto err; } + free(parser_db); query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale); if (query == NULL) { @@ -1666,6 +1636,12 @@ API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char * if (val == NULL) val = _get_localed_label(appid, DEFAULT_LOCALE, uid); + if (val == NULL) { + val = _get_localed_label(appid, locale, GLOBAL_USER); + if (val == NULL) + val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER); + } + if (val == NULL) return PMINFO_R_ERROR; @@ -1696,8 +1672,9 @@ API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const if (metadata && metadata->key) { if (strcasecmp(metadata->key, metadata_key) == 0) { if (metadata->value == NULL) - metadata->value = strdup(""); - *metadata_value = (char*)metadata->value; + *metadata_value = ""; + else + *metadata_value = (char *)metadata->value; return PMINFO_R_OK; } } @@ -2016,13 +1993,16 @@ API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **p if (info->app_info == NULL) return PMINFO_R_ERROR; + if (info->app_info->portraitimg == NULL) - info->app_info->portraitimg = strdup(""); - if (info->app_info->landscapeimg == NULL) - info->app_info->landscapeimg = strdup(""); + *portrait_img = ""; + else + *portrait_img = (char *)info->app_info->portraitimg; - *portrait_img = (char *)info->app_info->portraitimg; - *landscape_img = (char *)info->app_info->landscapeimg; + if (info->app_info->landscapeimg == NULL) + *landscape_img = ""; + else + *landscape_img = (char *)info->app_info->landscapeimg; return PMINFO_R_OK; } @@ -2053,10 +2033,11 @@ API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char if (info->app_info == NULL) return PMINFO_R_ERROR; - if (info->app_info->submode_mainid == NULL) - info->app_info->submode_mainid = strdup(""); - *submode_mainid = (char *)info->app_info->submode_mainid; + if (info->app_info->submode_mainid == NULL) + *submode_mainid = ""; + else + *submode_mainid = (char *)info->app_info->submode_mainid; return PMINFO_R_OK; } @@ -2123,10 +2104,11 @@ API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char if (info->app_info == NULL) return PMINFO_R_ERROR; - if (info->app_info->effective_appid == NULL) - info->app_info->effective_appid = strdup(""); - *effective_appid = (char *)info->app_info->effective_appid; + if (info->app_info->effective_appid == NULL) + *effective_appid = ""; + else + *effective_appid = (char *)info->app_info->effective_appid; return PMINFO_R_OK; } @@ -2142,10 +2124,11 @@ API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_ if (info->app_info == NULL) return PMINFO_R_ERROR; - if (info->app_info->tep_name == NULL) - info->app_info->tep_name = strdup(""); - *tep_name = (char *)info->app_info->tep_name; + if (info->app_info->tep_name == NULL) + *tep_name = ""; + else + *tep_name = (char *)info->app_info->tep_name; return PMINFO_R_OK; } @@ -2161,10 +2144,11 @@ API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char if (info->app_info == NULL) return PMINFO_R_ERROR; - if (info->app_info->zip_mount_file == NULL) - info->app_info->zip_mount_file = strdup(""); - *zip_mount_file = (char *)info->app_info->zip_mount_file; + if (info->app_info->zip_mount_file == NULL) + *zip_mount_file = ""; + else + *zip_mount_file = (char *)info->app_info->zip_mount_file; return PMINFO_R_OK; } @@ -2203,7 +2187,25 @@ API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **a return PMINFO_R_OK; } -API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access) +API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (handle == NULL || installed_time == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->app_info == NULL || info->app_info->package_installed_time == NULL) + return PMINFO_R_ERROR; + + *installed_time = atoi(info->app_info->package_installed_time); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, + const char *type, uid_t uid, char **appid, char **access) { retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); @@ -2242,9 +2244,11 @@ catch: return ret; } -API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access) +API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, + const char *type, char **appid, char **access) { - return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, _getuid(), appid, access); + return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, + type, _getuid(), appid, access); } API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid) @@ -2288,6 +2292,112 @@ API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char ** return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid); } +API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(const char *providerid, + const char *type, uid_t uid, char **appid, bool *is_trusted) +{ + retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); + retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n"); + + int ret = PMINFO_R_OK; + char *query = NULL; + sqlite3_stmt *stmt = NULL; + + /*open db*/ + ret = __open_manifest_db(uid, true); + retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB); + + /*Start constructing query*/ + query = sqlite3_mprintf("SELECT app_id, trusted FROM package_app_data_control WHERE providerid=%Q AND type=%Q", providerid, type); + tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory"); + + /*prepare query*/ + ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL); + tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query); + + /*step query*/ + ret = sqlite3_step(stmt); + tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found"); + + _save_column_str(stmt, 0, appid); + *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1)); + + ret = PMINFO_R_OK; + +catch: + sqlite3_free(query); + sqlite3_finalize(stmt); + __close_manifest_db(); + return ret; +} + +API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid, + const char *type, char **appid, bool *is_trusted) +{ + return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid, + type, _getuid(), appid, is_trusted); +} + +API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(const char *providerid, const char *type, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data, uid_t uid) +{ + retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n"); + retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL"); + + int ret = PMINFO_R_OK; + char *query = NULL; + sqlite3_stmt *stmt = NULL; + + /*open db*/ + ret = __open_manifest_db(uid, true); + retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB); + + /*Start constructing query*/ + query = sqlite3_mprintf("SELECT privilege FROM package_app_data_control_privilege " + "WHERE providerid=%Q AND type=%Q", providerid, type); + tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory"); + + /*prepare query*/ + ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL); + tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query); + + while (sqlite3_step(stmt) == SQLITE_ROW) { + char *privilege; + privilege = (char *)sqlite3_column_text(stmt, 0); + ret = privilege_func(privilege, user_data); + if (ret < 0) + break; + } + + ret = PMINFO_R_OK; + +catch: + sqlite3_free(query); + sqlite3_finalize(stmt); + __close_manifest_db(); + return ret; +} + +API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(const char *providerid, const char *type, + pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data) +{ + return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(providerid, type, privilege_func, + user_data, _getuid()); +} + +API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h handle, int *support_mode) +{ + retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); + retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); + + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + if (info->app_info->support_mode) + *support_mode = atoi(info->app_info->support_mode); + else + *support_mode = 0; + + return PMINFO_R_OK; +} + API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_permission_list_cb permission_func, void *user_data) { @@ -2356,9 +2466,7 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle, if (ptr == NULL) continue; if (ptr->key) { - if (ptr->value == NULL) - ptr->value = strdup(""); - ret = metadata_func(ptr->key, ptr->value, user_data); + ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data); if (ret < 0) break; } @@ -2512,10 +2620,10 @@ API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enable retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL"); pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; - if (info->app_info == NULL || info->app_info->enabled == NULL) + if (info->app_info == NULL || info->app_info->is_disabled == NULL) return PMINFO_R_ERROR; - *enabled = _get_bool_value(info->app_info->enabled); + *enabled = !_get_bool_value(info->app_info->is_disabled); return PMINFO_R_OK; } @@ -2666,6 +2774,35 @@ API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle, return PMINFO_R_OK; } +API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle, + bool *removable) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || info->app_info == NULL || removable == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + *removable = _get_bool_value(info->app_info->removable); + + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || info->app_info == NULL || system == NULL) { + _LOGE("invalid parameter"); + return PMINFO_R_EINVAL; + } + + *system = _get_bool_value(info->app_info->package_system); + + return PMINFO_R_OK; +} + API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); @@ -2712,6 +2849,40 @@ API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle return PMINFO_R_OK; } +API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || setup_appid == NULL) { + _LOGE("Invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->app_info == NULL || info->app_info->setup_appid == NULL) + return PMINFO_R_ERROR; + + *setup_appid = info->app_info->setup_appid; + return PMINFO_R_OK; +} + +API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle, + bool *support_ambient) +{ + pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle; + + if (info == NULL || support_ambient == NULL) { + _LOGE("Invalid parameter"); + return PMINFO_R_EINVAL; + } + + if (info->app_info == NULL || info->app_info->support_ambient == NULL) + return PMINFO_R_ERROR; + + *support_ambient = _get_bool_value(info->app_info->support_ambient); + + return PMINFO_R_OK; +} + API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle) { retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL"); @@ -2732,8 +2903,8 @@ API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle) static gint __compare_func(gconstpointer data1, gconstpointer data2) { - pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1; - pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2; + pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1; + pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2; if (node1->prop == node2->prop) return 0; else if (node1->prop > node2->prop) @@ -2757,8 +2928,8 @@ API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle, _LOGE("Invalid Integer Property\n"); return PMINFO_R_EINVAL; } - pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle; - pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x)); + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x)); if (node == NULL) { _LOGE("Out of Memory!!!\n"); return PMINFO_R_ERROR; @@ -2797,8 +2968,8 @@ API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle, _LOGE("Invalid Boolean Property\n"); return PMINFO_R_EINVAL; } - pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle; - pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x)); + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x)); if (node == NULL) { _LOGE("Out of Memory!!!\n"); return PMINFO_R_ERROR; @@ -2843,8 +3014,8 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle, _LOGE("Invalid String Property\n"); return PMINFO_R_EINVAL; } - pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle; - pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x)); + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x)); if (node == NULL) { _LOGE("Out of Memory!!!\n"); return PMINFO_R_ERROR; @@ -2957,7 +3128,7 @@ API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo( } API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle, - pkgmgrinfo_app_list_cb app_cb, void * user_data) + pkgmgrinfo_app_list_cb app_cb, void *user_data) { return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid()); } @@ -2976,23 +3147,30 @@ API int pkgmgrinfo_appinfo_metadata_filter_add( pkgmgrinfo_appinfo_metadata_filter_h handle, const char *key, const char *value) { - int ret; - - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_METADATA_KEY, key); - if (ret != PMINFO_R_OK) - return ret; + pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle; + pkgmgrinfo_metadata_node_x *node; /* value can be NULL. * In that case all apps with specified key should be displayed */ - if (value) { - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value); - if (ret != PMINFO_R_OK) - return ret; + if (key == NULL) { + LOGE("invalid parameter"); + return PMINFO_R_EINVAL; } + node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x)); + if (node == NULL) { + LOGE("out of memory"); + return PMINFO_R_ERROR; + } + + node->key = strdup(key); + if (value && strlen(value)) + node->value = strdup(value); + + filter->list_metadata = g_slist_append(filter->list_metadata, + (gpointer)node); + return PMINFO_R_OK; }