Change codes to enable getting disable pkg's appinfo 39/138139/8
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 11 Jul 2017 06:52:18 +0000 (15:52 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 17 Jul 2017 05:58:04 +0000 (14:58 +0900)
- Add app filter to let allow user to set pkg disable flag
- Change implementation of
  pkgmgrinfo_appinfo_usr_filter_count
  pkgmgrinfo_appinfo_filter_foreach_appinfo
  to add pkg and app disable filter automatically when it doesn't exists.

Change-Id: I43afd56a17276d26a90f260e43e4df6fe8fa3aa8
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
include/pkgmgr-info.h
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_private.c
src/pkgmgrinfo_private.h

index 71069fa..cb63b9f 100644 (file)
@@ -165,6 +165,8 @@ extern "C" {
 #define        PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE "PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE"
  /** Boolean property for filtering based on app info*/
 #define        PMINFO_APPINFO_PROP_APP_CHECK_STORAGE   "PMINFO_APPINFO_PROP_APP_CHECK_STORAGE"
+/** Boolean property for filtering based on app info*/
+#define        PMINFO_APPINFO_PROP_PKG_DISABLE "PMINFO_APPINFO_PROP_PKG_DISABLE"
 
  /** will be updated*/
  /** string property for filtering based on pkg info*/
index 2ceb831..beb5a22 100644 (file)
@@ -61,19 +61,13 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        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)
+               return PMINFO_R_OK;
        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;
-       }
-
        for (list = filter->list; list; list = list->next) {
                joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
                if (condition == NULL)
@@ -131,8 +125,6 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        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)
                return PMINFO_R_ERROR;
@@ -381,24 +373,29 @@ static void __free_applications(gpointer data)
        pkgmgrinfo_basic_free_application((application_x *)data);
 }
 
-static gint __app_disable_chk_func(gconstpointer data1, gconstpointer data2)
+static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
 {
        pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
+       pkgmgrinfo_appinfo_disable_type *value =
+                       (pkgmgrinfo_appinfo_disable_type *)data2;
 
-       if (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
-               return 0;
+       if (value == E_APPINFO_DISABLE_TYPE_PKG)
+               return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
+                               ? 0 : 1;
        else
-               return 1;
+               return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
+                               ? 0 : 1;
 }
 
-static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
+static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
+               pkgmgrinfo_appinfo_disable_type type)
 {
        GSList *link;
 
        if (filter == NULL)
                return false;
 
-       link = g_slist_find_custom(filter->list, NULL, __app_disable_chk_func);
+       link = g_slist_find_custom(filter->list, &type, __disable_chk_func);
        if (link)
                return true;
 
@@ -860,6 +857,13 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                return PMINFO_R_ERROR;
        }
 
+       ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_PKG_DISABLE, false);
+       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;
@@ -1275,11 +1279,6 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
                return PMINFO_R_ERROR;
        }
 
-       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)
@@ -1337,6 +1336,12 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
                return PMINFO_R_ERROR;
        }
 
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
        comp_str = __appcomponent_str(component);
 
        if (comp_str) {
@@ -1379,7 +1384,13 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
                return PMINFO_R_ERROR;
 
        if (pkgmgrinfo_appinfo_filter_add_bool(filter,
-                               PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+                       PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
                return PMINFO_R_ERROR;
        }
@@ -1421,6 +1432,18 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list(
        if (ret != PMINFO_R_OK)
                return ret;
 
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
        ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
                        PMINFO_APPINFO_GET_ALL, app_func, user_data);
 
@@ -3103,6 +3126,26 @@ API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle,
                return PMINFO_R_ERROR;
        }
 
+       if (__check_disable_filter_exist(
+                       handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
+               if (pkgmgrinfo_appinfo_filter_add_bool(handle,
+                               PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+                       g_hash_table_destroy(list);
+                       free(locale);
+                       return PMINFO_R_ERROR;
+               }
+       }
+
+       if (__check_disable_filter_exist(
+                       handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
+               if (pkgmgrinfo_appinfo_filter_add_bool(handle,
+                               PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
+                       g_hash_table_destroy(list);
+                       free(locale);
+                       return PMINFO_R_ERROR;
+               }
+       }
+
        ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
        if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
                ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
@@ -3135,6 +3178,20 @@ API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
                return PMINFO_R_EINVAL;
        }
 
+       if (__check_disable_filter_exist(
+                       handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
+               if (pkgmgrinfo_appinfo_filter_add_bool(handle,
+                               PMINFO_APPINFO_PROP_APP_DISABLE, false))
+                       return PMINFO_R_ERROR;
+       }
+
+       if (__check_disable_filter_exist(
+                       handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
+               if (pkgmgrinfo_appinfo_filter_add_bool(handle,
+                               PMINFO_APPINFO_PROP_PKG_DISABLE, false))
+                       return PMINFO_R_ERROR;
+       }
+
        return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
                        user_data);
 }
@@ -3195,6 +3252,15 @@ API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
                return PMINFO_R_EINVAL;
        }
 
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_APP_DISABLE, false))
+               return PMINFO_R_ERROR;
+
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_PKG_DISABLE, false))
+               return PMINFO_R_ERROR;
+
        return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
                        user_data);
 }
index 21b4840..121a658 100644 (file)
@@ -126,7 +126,8 @@ static struct _appinfo_bool_map_t appinfo_bool_prop_map[] = {
        {E_PMINFO_APPINFO_PROP_APP_UI_GADGET,           PMINFO_APPINFO_PROP_APP_UI_GADGET},
        {E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE,             PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE},
        {E_PMINFO_APPINFO_PROP_APP_DISABLE,             PMINFO_APPINFO_PROP_APP_DISABLE},
-       {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE,               PMINFO_APPINFO_PROP_APP_CHECK_STORAGE}
+       {E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE,               PMINFO_APPINFO_PROP_APP_CHECK_STORAGE},
+       {E_PMINFO_APPINFO_PROP_PKG_DISABLE,             PMINFO_APPINFO_PROP_PKG_DISABLE}
 };
 
 inline pkgmgrinfo_pkginfo_filter_prop_str _pminfo_pkginfo_convert_to_prop_str(const char *property)
@@ -404,6 +405,11 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p
        case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
                snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
                break;
+       case E_PMINFO_APPINFO_PROP_PKG_DISABLE:
+               snprintf(buf, MAX_QUERY_LEN,
+                               "ai.package IN (SELECT package FROM " \
+                               "package_info WHERE package_disable=?)");
+               break;
        case E_PMINFO_APPINFO_PROP_APP_SUPPORT_MODE:
                snprintf(buf, sizeof(buf), "ai.app_support_mode=?");
                break;
index 333b5e3..09e88e9 100644 (file)
@@ -145,7 +145,8 @@ typedef enum _pkgmgrinfo_appinfo_filter_prop_bool {
        E_PMINFO_APPINFO_PROP_APP_DISABLE,
        E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE,
        E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE,
-       E_PMINFO_APPINFO_PROP_APP_MAX_BOOL = E_PMINFO_APPINFO_PROP_APP_CHECK_STORAGE
+       E_PMINFO_APPINFO_PROP_PKG_DISABLE,
+       E_PMINFO_APPINFO_PROP_APP_MAX_BOOL = E_PMINFO_APPINFO_PROP_PKG_DISABLE
 } pkgmgrinfo_appinfo_filter_prop_bool;
 
 /*Integer properties for filtering based on app info*/
@@ -176,6 +177,11 @@ typedef enum _pkgmgrinfo_appinfo_join_flag {
        E_PMINFO_APPINFO_JOIN_METADATA = 0x0008,
 } pkgmgrinfo_appinfo_join_flag;
 
+typedef enum _pkgmgrinfo_appinfo_disable_type {
+       E_APPINFO_DISABLE_TYPE_PKG = 0,
+       E_APPINFO_DISABLE_TYPE_APP
+} pkgmgrinfo_appinfo_disable_type;
+
 typedef struct _pkgmgr_pkginfo_x {
        uid_t uid;
        package_x *pkg_info;