+ 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;
+ }
+ }
+
+ 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;
+}
+
+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;
+ pkgmgr_appinfo_x *info;
+
+ 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;
+
+ list = g_hash_table_new(g_str_hash, g_str_equal);
+ if (list == NULL) {
+ free(locale);
+ return PMINFO_R_ERROR;
+ }
+
+ 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);
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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);
+
+ *handle = info;
+
+ 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);
+}
+
+API int pkgmgrinfo_appinfo_get_usr_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);