fix getting appinfo functions to get enabled/disabled appinfo properly 15/59715/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 17 Feb 2016 23:44:00 +0000 (08:44 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 19 Feb 2016 08:30:58 +0000 (00:30 -0800)
Change-Id: Ic91719ef3c4bd92812069800fe2867b7b183bd11
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
include/pkgmgr-info.h
src/pkgmgrinfo_appinfo.c

index 0a97fcc..d85ff86 100644 (file)
@@ -2162,6 +2162,46 @@ int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void
 int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data);
 
 /**
+ * @fn int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
+ * @brief      This API creates the disabled application information handle from db
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in]  appid   pointer to appid
+ * @param[out] handle          pointer to the application info handle.
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ERROR  internal error
+ * @pre                None
+ * @post               pkgmgrinfo_appinfo_destroy_appinfo()
+ * @see                pkgmgrinfo_appinfo_get_pkgid()
+ * @see                pkgmgrinfo_appinfo_is_multiple()
+ * @code
+static int get_disabled_app_type(const char *appid)
+{
+       int ret = 0;
+       char *type = NULL;
+       pkgmgrinfo_appinfo_h handle;
+       ret = pkgmgrinfo_appinfo_get_disabled_appinfo(appid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_appinfo_get_apptype(handle, &type);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+               return -1;
+       }
+       printf("apptype: %s\n", type);
+       pkgmgrinfo_appinfo_destroy_appinfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle);
+int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle);
+
+/**
  * @fn int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
  * @brief      This API creates the application information handle from db
  *
@@ -2200,6 +2240,7 @@ static int get_app_type(const char *appid)
  */
 int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle);
 int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle);
+
 /**
  * @fn int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
  * @brief      This API gets the application ID
index d961abb..714070c 100644 (file)
@@ -590,7 +590,7 @@ static GList *__get_background_category(char *value)
 }
 
 static int _appinfo_get_application(sqlite3 *db, const char *appid,
-               const char *locale, application_x **application)
+               const char *locale, application_x **application, bool is_disabled)
 {
        static const char query_raw[] =
                "SELECT app_id, app_component, app_exec, app_nodisplay, "
@@ -605,15 +605,22 @@ static int _appinfo_get_application(sqlite3 *db, const char *appid,
                "component_type, package, app_process_pool, app_installed_storage, "
                "app_background_category, app_package_type "
                "FROM package_app_info WHERE app_id='%s' "
-               "AND app_id NOT IN "
-               "(SELECT app_id from package_app_disable_for_user WHERE uid='%d')";
+               "AND (app_disable='%s' "
+               "%s app_id %s IN "
+               "(SELECT app_id from package_app_disable_for_user WHERE uid='%d'))";
        int ret;
        char query[MAX_QUERY_LEN] = { '\0' };
        sqlite3_stmt *stmt;
        int idx;
        application_x *info;
        char *bg_category_str = NULL;
-       snprintf(query, MAX_QUERY_LEN - 1, query_raw, appid, (int)getuid());
+       snprintf(query, MAX_QUERY_LEN - 1, query_raw,
+                       appid,
+                       is_disabled ? "true" : "false",
+                       is_disabled ? "OR" : "AND",
+                       is_disabled ? "" : "NOT",
+                       (int)getuid());
+
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
                LOGE("prepare failed: %s", sqlite3_errmsg(db));
@@ -722,7 +729,7 @@ static int _appinfo_get_application(sqlite3 *db, const char *appid,
 }
 
 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
-               pkgmgr_appinfo_x **appinfo)
+               pkgmgr_appinfo_x **appinfo, bool is_disabled)
 {
        int ret;
        sqlite3 *db;
@@ -753,7 +760,7 @@ static int _appinfo_get_appinfo(const char *appid, uid_t uid,
                return PMINFO_R_ERROR;
        }
 
-       ret = _appinfo_get_application(db, appid, locale, &info->app_info);
+       ret = _appinfo_get_application(db, appid, locale, &info->app_info, is_disabled);
        if (ret != PMINFO_R_OK) {
                free(info);
                free(locale);
@@ -771,6 +778,32 @@ static int _appinfo_get_appinfo(const char *appid, uid_t uid,
        return ret;
 }
 
+API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
+               pkgmgrinfo_appinfo_h *handle)
+{
+       int ret;
+
+       if (appid == NULL || handle == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle, true);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
+                               (pkgmgr_appinfo_x **)handle, true);
+
+       if (ret != PMINFO_R_OK)
+               _LOGE("failed to get appinfo of %s for user %d", appid, uid);
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
+{
+       return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, GLOBAL_USER, handle);
+}
+
 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                pkgmgrinfo_appinfo_h *handle)
 {
@@ -781,10 +814,10 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                return PMINFO_R_EINVAL;
        }
 
-       ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
+       ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle, false);
        if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
                ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
-                               (pkgmgr_appinfo_x **)handle);
+                               (pkgmgr_appinfo_x **)handle, false);
 
        if (ret != PMINFO_R_OK)
                _LOGE("failed to get appinfo of %s for user %d", appid, uid);
@@ -1149,10 +1182,10 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
        for (tmp = list; tmp; tmp = tmp->next) {
                appid = (char *)tmp->data;
                if (stop == 0) {
-                       ret = _appinfo_get_appinfo(appid, uid, &info);
+                       ret = _appinfo_get_appinfo(appid, uid, &info, false);
                        if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
                                ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
-                                               &info);
+                                               &info, false);
                        if (ret != PMINFO_R_OK) {
                                free(appid);
                                continue;