+ if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
+ category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
+
+ if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
+ category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
+
+ if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
+ category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
+
+ if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
+ category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
+
+ if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
+ category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
+
+ if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
+ category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
+
+ if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
+ category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
+
+ return category_list;
+
+}
+
+static int __get_appinfo_for_uid(sqlite3 *db, application_x *info, uid_t uid)
+{
+ static const char query_raw[] =
+ "SELECT is_splash_screen_enabled, is_disabled "
+ "FROM package_app_info_for_uid WHERE app_id='%s' AND uid='%d'";
+ int ret;
+ char *query;
+ char *is_disabled = NULL;
+ sqlite3_stmt *stmt;
+
+ query = sqlite3_mprintf(query_raw, info->appid, uid);
+ 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("sqlite3_prepare_v2() failed: %s", sqlite3_errmsg(db));
+ return PMINFO_R_ERROR;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ if (info->splash_screen_display)
+ free(info->splash_screen_display);
+ _save_column_str(stmt, 0, &info->splash_screen_display);
+ if (strcasecmp(info->is_disabled, "false") == 0) {
+ _save_column_str(stmt, 1, &is_disabled);
+ if (strcasecmp(is_disabled, "true") == 0) {
+ free(info->is_disabled);
+ info->is_disabled = is_disabled;
+ } else {
+ free(is_disabled);
+ }
+ }
+ }
+
+ sqlite3_finalize(stmt);
+ return PMINFO_R_OK;
+}
+
+static void __free_applications(gpointer data)
+{
+ pkgmgrinfo_basic_free_application((application_x *)data);
+}
+
+static gint __app_disable_chk_func(gconstpointer data1, gconstpointer data2)
+{
+ pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
+
+ if (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
+ return 0;
+ else
+ return 1;
+}
+
+static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
+{
+ 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)
+{
+ 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_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_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, "
+ "ai.app_external_path, 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_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";
+ int ret = PMINFO_R_ERROR;
+ int idx;
+ int len = 0;
+ char *dbpath;
+ char *bg_category_str = NULL;
+ char *constraint = NULL;
+ char *tmp_record = NULL;
+ char query[MAX_QUERY_LEN] = { '\0' };
+ application_x *info = NULL;
+ GList *bind_params = NULL;
+ sqlite3 *db = NULL;
+ sqlite3_stmt *stmt = NULL;
+ bool is_check_storage = true;
+
+ 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: %d", ret);
+ free(dbpath);
+ return PMINFO_R_ERROR;
+ }
+ free(dbpath);
+
+ len = strlen(query_raw);
+ snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
+ 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));
+ }
+
+ 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);
+
+ if (constraint)
+ strncat(query, constraint, MAX_QUERY_LEN - len - 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);
+ if (g_hash_table_contains(applications,
+ (gconstpointer)info->appid)) {
+ free(info->appid);
+ free(info);
+ info = NULL;
+ 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->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);
+ _save_column_str(stmt, idx++, &info->external_path);
+ _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->for_all_users =
+ strdup((db_uid != GLOBAL_USER) ? "false" : "true");
+
+ if (db_uid == GLOBAL_USER) {
+ ret = __get_appinfo_for_uid(db, info, uid);
+ if (ret != PMINFO_R_OK) {
+ LOGI("Failed to get appinfo for given uid[%d]", (int)uid);
+ pkgmgrinfo_basic_free_application(info);
+ info = NULL;
+ continue;
+ }
+ }
+
+ info->background_category = __get_background_category(
+ bg_category_str);
+ free(bg_category_str);
+
+ 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_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)) {
+ ret = PMINFO_R_ERROR;
+ goto catch;
+ }
+ }