-static int __bind_params(sqlite3_stmt *stmt, GList *params)
-{
- GList *tmp_list = NULL;
- int idx = 0;
- int ret;
-
- if (stmt == NULL || params == NULL)
- return PMINFO_R_EINVAL;
-
- tmp_list = params;
- while (tmp_list) {
- ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
- if (ret != SQLITE_OK)
- return PMINFO_R_ERROR;
- tmp_list = tmp_list->next;
- }
-
- 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_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_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_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;
- 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 = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
- if (ret != SQLITE_OK) {
- _LOGE("failed to open db(%s): %d", dbpath, ret);
- free(dbpath);
- return PMINFO_R_ERROR;
- }
- free(dbpath);
-
- snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
-
- if (flag & PMINFO_APPINFO_GET_BASICINFO) {
- strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
- strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1);
- }
- if (flag & PMINFO_APPINFO_GET_LABEL) {
- strncat(query, query_label, sizeof(query) - strlen(query) - 1);
- bind_params = g_list_append(bind_params, strdup(locale));
- }
- if (flag & PMINFO_APPINFO_GET_ICON) {
- strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
- 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, sizeof(query) - strlen(query) - 1);
-
- strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1);
-
- if (constraint)
- strncat(query, constraint, sizeof(query) - strlen(query) - 1);
-
- ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- LOGE("prepare failed: %s", sqlite3_errmsg(db));
- ret = PMINFO_R_ERROR;
- goto catch;
- }
-
- if (g_list_length(bind_params) != 0) {
- ret = __bind_params(stmt, bind_params);
- if (ret != SQLITE_OK) {
- LOGE("Failed to bind parameters");
- goto catch;
- }
- }
-
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- info = calloc(1, sizeof(application_x));
- if (info == NULL) {
- LOGE("out of memory");
- ret = PMINFO_R_ERROR;
- goto catch;
- }
- idx = 0;
- _save_column_str(stmt, idx++, &info->appid);
- _save_column_str(stmt, idx++, &info->installed_storage);
- _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);
- }
-
- info->for_all_users =
- strdup((db_uid != global_user_uid) ? "false" : "true");
-
- 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) {
- 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) {
- 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;
- }
- }
-
- if (flag & PMINFO_APPINFO_GET_CATEGORY) {
- if (_appinfo_get_category(db, info->appid,
- &info->category)) {
- ret = PMINFO_R_ERROR;
- goto catch;
- }
- }
-
- if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
- if (_appinfo_get_app_control(db, info->appid,
- &info->appcontrol)) {
- ret = PMINFO_R_ERROR;
- goto catch;
- }
- }
-
- if (flag & PMINFO_APPINFO_GET_METADATA) {
- if (_appinfo_get_metadata(db, info->appid,
- &info->metadata)) {
- ret = PMINFO_R_ERROR;
- goto catch;
- }
- }
-
- if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
- if (_appinfo_get_splashscreens(db, info->appid,
- &info->splashscreens)) {
- ret = PMINFO_R_ERROR;
- goto catch;
- }
- }
-
- 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);
- }
-
- ret = PMINFO_R_OK;
-
-catch:
- if (constraint)
- free(constraint);
-
- if (ret != PMINFO_R_OK && info != NULL)
- pkgmgrinfo_basic_free_application(info);
-
- g_list_free_full(bind_params, free);
- sqlite3_close_v2(db);
- sqlite3_finalize(stmt);
-
- return ret;
-}
-