[Reform] Apply Coding Style
[platform/core/appfw/pkgmgr-info.git] / src / appinfo_internal.c
index d9cd221..2dd4f82 100644 (file)
 #include "pkgmgr_parser.h"
 #include "pkgmgrinfo_internal.h"
 
-
-static int __free_applications(gpointer key,
-               gpointer value, gpointer user_data)
-{
-       pkgmgrinfo_basic_free_application((application_x *)value);
+static int __free_applications(gpointer key, gpointer value,
+                               gpointer user_data) {
+  pkgmgrinfo_basic_free_application((application_x *)value);
 }
 
 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str,
-               char *visibility, char *id)
-{
-       char *dup;
-       char *token;
-       char *ptr = NULL;
-       appcontrol_x *ac;
-
-       if (appcontrol_str == NULL)
-               return;
-
-       dup = strdup(appcontrol_str);
-       if (dup == NULL) {
-               _LOGE("out of memory");
-               return;
-       }
-
-       do {
-               ac = calloc(1, sizeof(appcontrol_x));
-               if (ac == NULL) {
-                       _LOGE("out of memory");
-                       break;
-               }
-               token = strtok_r(dup, "|", &ptr);
-               if (token && strcmp(token, "NULL"))
-                       ac->operation = strdup(token);
-               token = strtok_r(NULL, "|", &ptr);
-               if (token && strcmp(token, "NULL"))
-                       ac->uri = strdup(token);
-               token = strtok_r(NULL, "|", &ptr);
-               if (token && strcmp(token, "NULL"))
-                       ac->mime = strdup(token);
-               ac->visibility = strdup(visibility);
-               ac->id = strdup(id);
-               *appcontrol = g_list_prepend(*appcontrol, ac);
-       } while ((token = strtok_r(NULL, ";", &ptr)));
-
-       free(dup);
+                               char *visibility, char *id) {
+  char *dup;
+  char *token;
+  char *ptr = NULL;
+  appcontrol_x *ac;
+
+  if (appcontrol_str == NULL) return;
+
+  dup = strdup(appcontrol_str);
+  if (dup == NULL) {
+    _LOGE("out of memory");
+    return;
+  }
+
+  do {
+    ac = calloc(1, sizeof(appcontrol_x));
+    if (ac == NULL) {
+      _LOGE("out of memory");
+      break;
+    }
+    token = strtok_r(dup, "|", &ptr);
+    if (token && strcmp(token, "NULL")) ac->operation = strdup(token);
+    token = strtok_r(NULL, "|", &ptr);
+    if (token && strcmp(token, "NULL")) ac->uri = strdup(token);
+    token = strtok_r(NULL, "|", &ptr);
+    if (token && strcmp(token, "NULL")) ac->mime = strdup(token);
+    ac->visibility = strdup(visibility);
+    ac->id = strdup(id);
+    *appcontrol = g_list_prepend(*appcontrol, ac);
+  } while ((token = strtok_r(NULL, ";", &ptr)));
+
+  free(dup);
 }
 
 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
-               GList **splashscreens)
-{
-       static const char query_raw[] =
-               "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
-               "FROM package_app_splash_screen WHERE app_id=%Q";
-       int ret;
-       char *query;
-       sqlite3_stmt *stmt;
-       int idx;
-       splashscreen_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(splashscreen_x));
-               if (info == NULL) {
-                       LOGE("out of memory");
-                       sqlite3_finalize(stmt);
-                       return PMINFO_R_ERROR;
-               }
-               idx = 0;
-               _save_column_str(stmt, idx++, &info->src);
-               _save_column_str(stmt, idx++, &info->type);
-               _save_column_str(stmt, idx++, &info->orientation);
-               _save_column_str(stmt, idx++, &info->indicatordisplay);
-               _save_column_str(stmt, idx++, &info->operation);
-               _save_column_str(stmt, idx++, &info->color_depth);
-               *splashscreens = g_list_prepend(*splashscreens, info);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return PMINFO_R_OK;
+                                      GList **splashscreens) {
+  static const char query_raw[] =
+      "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
+      "FROM package_app_splash_screen WHERE app_id=%Q";
+  int ret;
+  char *query;
+  sqlite3_stmt *stmt;
+  int idx;
+  splashscreen_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(splashscreen_x));
+    if (info == NULL) {
+      LOGE("out of memory");
+      sqlite3_finalize(stmt);
+      return PMINFO_R_ERROR;
+    }
+    idx = 0;
+    _save_column_str(stmt, idx++, &info->src);
+    _save_column_str(stmt, idx++, &info->type);
+    _save_column_str(stmt, idx++, &info->orientation);
+    _save_column_str(stmt, idx++, &info->indicatordisplay);
+    _save_column_str(stmt, idx++, &info->operation);
+    _save_column_str(stmt, idx++, &info->color_depth);
+    *splashscreens = g_list_prepend(*splashscreens, info);
+  }
+
+  sqlite3_finalize(stmt);
+
+  return PMINFO_R_OK;
 }
 
 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
-               GList **metadata)
-{
-       static const char query_raw[] =
-               "SELECT md_key, md_value "
-               "FROM package_app_app_metadata WHERE app_id=%Q";
-       int ret;
-       char *query;
-       sqlite3_stmt *stmt;
-       int idx;
-       metadata_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(metadata_x));
-               if (info == NULL) {
-                       LOGE("out of memory");
-                       sqlite3_finalize(stmt);
-                       return PMINFO_R_ERROR;
-               }
-               idx = 0;
-               _save_column_str(stmt, idx++, &info->key);
-               _save_column_str(stmt, idx++, &info->value);
-               *metadata = g_list_prepend(*metadata, info);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return PMINFO_R_OK;
-
+                                 GList **metadata) {
+  static const char query_raw[] =
+      "SELECT md_key, md_value "
+      "FROM package_app_app_metadata WHERE app_id=%Q";
+  int ret;
+  char *query;
+  sqlite3_stmt *stmt;
+  int idx;
+  metadata_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(metadata_x));
+    if (info == NULL) {
+      LOGE("out of memory");
+      sqlite3_finalize(stmt);
+      return PMINFO_R_ERROR;
+    }
+    idx = 0;
+    _save_column_str(stmt, idx++, &info->key);
+    _save_column_str(stmt, idx++, &info->value);
+    *metadata = g_list_prepend(*metadata, info);
+  }
+
+  sqlite3_finalize(stmt);
+
+  return PMINFO_R_OK;
 }
 
 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
-               GList **appcontrol)
-{
-       static const char query_raw[] =
-               "SELECT app_control, visibility, app_control_id "
-               "FROM package_app_app_control WHERE app_id=%Q";
-       int ret;
-       int idx;
-       char *query;
-       sqlite3_stmt *stmt;
-       char *str;
-       char *visibility;
-       char *id;
-
-       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) {
-               str = NULL;
-               visibility = NULL;
-               id = NULL;
-               idx = 0;
-               _save_column_str(stmt, idx++, &str);
-               _save_column_str(stmt, idx++, &visibility);
-               _save_column_str(stmt, idx++, &id);
-               /* TODO: revise */
-               __parse_appcontrol(appcontrol, str, visibility, id);
-               free(str);
-               free(visibility);
-               free(id);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return PMINFO_R_OK;
+                                    GList **appcontrol) {
+  static const char query_raw[] =
+      "SELECT app_control, visibility, app_control_id "
+      "FROM package_app_app_control WHERE app_id=%Q";
+  int ret;
+  int idx;
+  char *query;
+  sqlite3_stmt *stmt;
+  char *str;
+  char *visibility;
+  char *id;
+
+  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) {
+    str = NULL;
+    visibility = NULL;
+    id = NULL;
+    idx = 0;
+    _save_column_str(stmt, idx++, &str);
+    _save_column_str(stmt, idx++, &visibility);
+    _save_column_str(stmt, idx++, &id);
+    /* TODO: revise */
+    __parse_appcontrol(appcontrol, str, visibility, id);
+    free(str);
+    free(visibility);
+    free(id);
+  }
+
+  sqlite3_finalize(stmt);
+
+  return PMINFO_R_OK;
 }
 
 static int _appinfo_get_category(sqlite3 *db, const char *appid,
-               GList **category)
-{
-       static const char query_raw[] =
-               "SELECT category FROM package_app_app_category WHERE app_id=%Q";
-       int ret;
-       char *query;
-       sqlite3_stmt *stmt;
-       char *val;
-
-       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) {
-               val = NULL;
-               _save_column_str(stmt, 0, &val);
-               if (val)
-                       *category = g_list_prepend(*category, (gpointer)val);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return PMINFO_R_OK;
+                                 GList **category) {
+  static const char query_raw[] =
+      "SELECT category FROM package_app_app_category WHERE app_id=%Q";
+  int ret;
+  char *query;
+  sqlite3_stmt *stmt;
+  char *val;
+
+  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) {
+    val = NULL;
+    _save_column_str(stmt, 0, &val);
+    if (val) *category = g_list_prepend(*category, (gpointer)val);
+  }
+
+  sqlite3_finalize(stmt);
+
+  return PMINFO_R_OK;
 }
 
-static GList *__get_background_category(const char *value)
-{
-       GList *category_list = NULL;
-       int convert_value = 0;
-       if (!value || strlen(value) == 0)
-               return NULL;
-
-       convert_value = atoi(value);
-       if (convert_value < 0)
-               return NULL;
+static GList *__get_background_category(const char *value) {
+  GList *category_list = NULL;
+  int convert_value = 0;
+  if (!value || strlen(value) == 0) return NULL;
 
-       if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
-       else
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
+  convert_value = atoi(value);
+  if (convert_value < 0) return NULL;
 
-       if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
+  if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
+    category_list = g_list_prepend(
+        category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
+  else
+    category_list = g_list_prepend(
+        category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
 
-       if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
+  if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
+    category_list =
+        g_list_prepend(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
 
-       if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
+  if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
+    category_list =
+        g_list_prepend(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
 
-       if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
+  if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
+    category_list =
+        g_list_prepend(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
 
-       if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
+  if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
+    category_list =
+        g_list_prepend(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
 
-       if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
+  if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
+    category_list =
+        g_list_prepend(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
 
-       if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
-               category_list = g_list_prepend(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
+  if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
+    category_list =
+        g_list_prepend(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
 
-       return category_list;
+  if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
+    category_list =
+        g_list_prepend(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
 
+  return category_list;
 }
 
-static int __bind_params(sqlite3_stmt *stmt, GList *params)
-{
-       GList *tmp_list = NULL;
-       int idx = 0;
-       int ret;
+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;
+  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;
-       }
+  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;
+  return PMINFO_R_OK;
 }
 
 static const char join_localized_info[] =
-       " LEFT OUTER JOIN package_app_localized_info"
-       "  ON ai.app_id=package_app_localized_info.app_id"
-       "  AND package_app_localized_info.app_locale=?";
+    " LEFT OUTER JOIN package_app_localized_info"
+    "  ON ai.app_id=package_app_localized_info.app_id"
+    "  AND package_app_localized_info.app_locale=?";
 static const char join_category[] =
-       " LEFT OUTER JOIN package_app_app_category"
-       " ON ai.app_id=package_app_app_category.app_id";
+    " LEFT OUTER JOIN package_app_app_category"
+    " ON ai.app_id=package_app_app_category.app_id";
 static const char join_app_control[] =
-       " LEFT OUTER JOIN package_app_app_control"
-       "  ON ai.app_id=package_app_app_control.app_id";
+    " LEFT OUTER JOIN package_app_app_control"
+    "  ON ai.app_id=package_app_app_control.app_id";
 static const char join_metadata[] =
-       " LEFT OUTER JOIN package_app_app_metadata"
-       "  ON ai.app_id=package_app_app_metadata.app_id ";
+    " LEFT OUTER JOIN package_app_app_metadata"
+    "  ON ai.app_id=package_app_app_metadata.app_id ";
 static const char join_privilege[] =
-       " LEFT OUTER JOIN package_privilege_info"
-       " ON ai.package=package_privilege_info.package ";
-
-static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
-       const char *locale, uid_t uid, char **query, GList **bind_params)
-{
-       int joined = 0;
-       int size;
-       char *condition = NULL;
-       char buf[MAX_QUERY_LEN] = { '\0' };
-       char tmp_query[MAX_QUERY_LEN] = { '\0' };
-       GSList *list;
-
-       if (!filter)
-               return PMINFO_R_OK;
-       strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1);
-
-       for (list = filter->list; list; list = list->next) {
-               joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
-               if (condition == NULL)
-                       continue;
-
-               strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
-
-               strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
-               free(condition);
-               condition = NULL;
-       }
-
-       if (filter->list_metadata)
-               strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1);
-       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) - strlen(buf) - 1);
-               free(condition);
-               condition = NULL;
-
-               strncat(buf, " OR ", sizeof(buf) - strlen(buf) - 1);
-       }
-       if (filter->list_metadata)
-               strncat(buf, "1=0)", sizeof(buf) - strlen(buf) - 1);
-
-       if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
-               strncat(tmp_query, join_localized_info, sizeof(tmp_query) - strlen(tmp_query) - 1);
-               *bind_params = g_list_append(*bind_params, strdup(locale));
-       }
-       if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY)
-               strncat(tmp_query, join_category, sizeof(tmp_query) - strlen(tmp_query) - 1);
-       if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL)
-               strncat(tmp_query, join_app_control, sizeof(tmp_query) - strlen(tmp_query) - 1);
-       if (joined & E_PMINFO_APPINFO_JOIN_METADATA)
-               strncat(tmp_query, join_metadata, sizeof(tmp_query) - strlen(tmp_query) - 1);
-       if (joined & E_PMINFO_APPINFO_JOIN_PRIVILEGE)
-               strncat(tmp_query, join_privilege, sizeof(tmp_query) - strlen(tmp_query) - 1);
-
-       size = strlen(tmp_query) + strlen(buf) + 1;
-       *query = (char *)calloc(1, size);
-       if (*query == NULL)
-               return PMINFO_R_ERROR;
-       snprintf(*query, size, "%s%s", tmp_query, buf);
-
-       return PMINFO_R_OK;
+    " LEFT OUTER JOIN package_privilege_info"
+    " ON ai.package=package_privilege_info.package ";
+
+static int _get_filtered_query(pkgmgrinfo_filter_x *filter, const char *locale,
+                               uid_t uid, char **query, GList **bind_params) {
+  int joined = 0;
+  int size;
+  char *condition = NULL;
+  char buf[MAX_QUERY_LEN] = {'\0'};
+  char tmp_query[MAX_QUERY_LEN] = {'\0'};
+  GSList *list;
+
+  if (!filter) return PMINFO_R_OK;
+  strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1);
+
+  for (list = filter->list; list; list = list->next) {
+    joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
+    if (condition == NULL) continue;
+
+    strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
+
+    strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
+    free(condition);
+    condition = NULL;
+  }
+
+  if (filter->list_metadata)
+    strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1);
+  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) - strlen(buf) - 1);
+    free(condition);
+    condition = NULL;
+
+    strncat(buf, " OR ", sizeof(buf) - strlen(buf) - 1);
+  }
+  if (filter->list_metadata)
+    strncat(buf, "1=0)", sizeof(buf) - strlen(buf) - 1);
+
+  if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
+    strncat(tmp_query, join_localized_info,
+            sizeof(tmp_query) - strlen(tmp_query) - 1);
+    *bind_params = g_list_append(*bind_params, strdup(locale));
+  }
+  if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY)
+    strncat(tmp_query, join_category,
+            sizeof(tmp_query) - strlen(tmp_query) - 1);
+  if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL)
+    strncat(tmp_query, join_app_control,
+            sizeof(tmp_query) - strlen(tmp_query) - 1);
+  if (joined & E_PMINFO_APPINFO_JOIN_METADATA)
+    strncat(tmp_query, join_metadata,
+            sizeof(tmp_query) - strlen(tmp_query) - 1);
+  if (joined & E_PMINFO_APPINFO_JOIN_PRIVILEGE)
+    strncat(tmp_query, join_privilege,
+            sizeof(tmp_query) - strlen(tmp_query) - 1);
+
+  size = strlen(tmp_query) + strlen(buf) + 1;
+  *query = (char *)calloc(1, size);
+  if (*query == NULL) return PMINFO_R_ERROR;
+  snprintf(*query, size, "%s%s", tmp_query, buf);
+
+  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 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(sqlite3 *db, 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 *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_stmt *stmt = NULL;
-       bool is_check_storage = true;
-       const uid_t global_user_uid = GLOBAL_USER;
-
-       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);
-                       bg_category_str = NULL;
-               }
-
-               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;
-                               } else {
-                                       free(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;
-                               } else {
-                                       free(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:
-       sqlite3_finalize(stmt);
-
-       if (constraint)
-               free(constraint);
-
-       if (ret != PMINFO_R_OK && info != NULL)
-               pkgmgrinfo_basic_free_application(info);
-
-       g_list_free_full(bind_params, free);
-
-       return ret;
+                                     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 *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_stmt *stmt = NULL;
+  bool is_check_storage = true;
+  const uid_t global_user_uid = GLOBAL_USER;
+
+  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);
+      bg_category_str = NULL;
+    }
+
+    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;
+        } else {
+          free(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;
+        } else {
+          free(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 : sqlite3_finalize(stmt);
+
+  if (constraint) free(constraint);
+
+  if (ret != PMINFO_R_OK && info != NULL)
+    pkgmgrinfo_basic_free_application(info);
+
+  g_list_free_full(bind_params, free);
+
+  return ret;
 }
 
-API int appinfo_internal_filter_get_list(
-               sqlite3 *db,
-               pkgmgrinfo_appinfo_filter_h filter,
-               uid_t uid, const char *locale, GHashTable **appinfo_list) {
-       int ret;
-       GHashTable *list;
-
-       if (db == NULL || filter == NULL || appinfo_list == NULL) {
-                       // TODO: add log
-                       return PMINFO_R_EINVAL;
-       }
-
-       list = g_hash_table_new(g_str_hash, g_str_equal);
-       if (list == NULL)
-               return PMINFO_R_ERROR;
-
-       ret = _appinfo_get_applications(db, uid, uid, locale, filter,
-                       PMINFO_APPINFO_GET_ALL, list);
-       if (!g_hash_table_size(list) && uid != GLOBAL_USER)
-               ret = _appinfo_get_applications(db, GLOBAL_USER, uid, locale, filter,
-                               PMINFO_APPINFO_GET_ALL, list);
-
-       if (ret != PMINFO_R_OK) {
-               g_hash_table_foreach_remove(list, __free_applications, NULL);
-               g_hash_table_destroy(list);
-               return ret;
-       }
-
-       if (!g_hash_table_size(list)) {
-               // TODO: add logs that failed to find appid
-               g_hash_table_destroy(list);
-               return PMINFO_R_ENOENT;
-       }
-
-       *appinfo_list = list;
-       return ret;
+API int appinfo_internal_filter_get_list(sqlite3 *db,
+                                         pkgmgrinfo_appinfo_filter_h filter,
+                                         uid_t uid, const char *locale,
+                                         GHashTable **appinfo_list) {
+  int ret;
+  GHashTable *list;
+
+  if (db == NULL || filter == NULL || appinfo_list == NULL) {
+    // TODO: add log
+    return PMINFO_R_EINVAL;
+  }
+
+  list = g_hash_table_new(g_str_hash, g_str_equal);
+  if (list == NULL) return PMINFO_R_ERROR;
+
+  ret = _appinfo_get_applications(db, uid, uid, locale, filter,
+                                  PMINFO_APPINFO_GET_ALL, list);
+  if (!g_hash_table_size(list) && uid != GLOBAL_USER)
+    ret = _appinfo_get_applications(db, GLOBAL_USER, uid, locale, filter,
+                                    PMINFO_APPINFO_GET_ALL, list);
+
+  if (ret != PMINFO_R_OK) {
+    g_hash_table_foreach_remove(list, __free_applications, NULL);
+    g_hash_table_destroy(list);
+    return ret;
+  }
+
+  if (!g_hash_table_size(list)) {
+    // TODO: add logs that failed to find appid
+    g_hash_table_destroy(list);
+    return PMINFO_R_ENOENT;
+  }
+
+  *appinfo_list = list;
+  return ret;
 }