Add support for watch-application to pkgmgr-parser
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.c
index d961abb..15383a0 100644 (file)
@@ -250,20 +250,6 @@ static int _appinfo_get_label(sqlite3 *db, const char *appid,
        return PMINFO_R_OK;
 }
 
-static void _appinfo_modify_icon(const char *appid, const char **icon)
-{
-       char buf[PKG_VALUE_STRING_LEN_MAX];
-       const char *tmp;
-
-       if (*icon == NULL || (*icon)[0] == '/' || !strcasecmp(*icon, ""))
-               return;
-
-       tmp = *icon;
-       snprintf(buf, sizeof(buf), "%s%s.png", getIconPath(getuid()), appid);
-       *icon = strdup(buf);
-       free((char *)tmp);
-}
-
 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
                GList **icon)
 {
@@ -300,8 +286,6 @@ static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
                }
                idx = 0;
                _save_column_str(stmt, idx++, &info->text);
-               /* FIXME: this is a workaround. this must be removed later */
-               _appinfo_modify_icon(appid, &info->text);
                _save_column_str(stmt, idx++, &info->lang);
                *icon = g_list_append(*icon, info);
        }
@@ -507,7 +491,7 @@ static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
                GList **splashscreens)
 {
        static const char query_raw[] =
-               "SELECT src, type, orientation, indicatordisplay "
+               "SELECT src, type, orientation, indicatordisplay, operation "
                "FROM package_app_splash_screen WHERE app_id=%Q";
        int ret;
        char *query;
@@ -540,6 +524,7 @@ static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
                _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);
                *splashscreens = g_list_append(*splashscreens, info);
        }
 
@@ -590,7 +575,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 +590,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 +714,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 +745,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 +763,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 +799,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);
@@ -944,6 +962,8 @@ static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
                splashscreen->orientation = strdup(tmp->orientation);
        if (tmp->indicatordisplay)
                splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
+       if (tmp->operation)
+               splashscreen->operation = strdup(tmp->operation);
 
        return splashscreen;
 }
@@ -1149,10 +1169,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;
@@ -1489,10 +1509,14 @@ API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *loca
 
 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
 {
-       if ( strcasecmp(comp, "uiapp") == 0)
+       if (strcasecmp(comp, "uiapp") == 0)
                return PMINFO_UI_APP;
-       else if ( strcasecmp(comp, "svcapp") == 0)
+       else if (strcasecmp(comp, "svcapp") == 0)
                return PMINFO_SVC_APP;
+       else if (strcasecmp(comp, "widgetapp") == 0)
+               return PMINFO_WIDGET_APP;
+       else if (strcasecmp(comp, "watchapp") == 0)
+               return PMINFO_WATCH_APP;
        else
                return -1;
 }
@@ -2117,6 +2141,7 @@ API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
                                splashscreen->type,
                                splashscreen->orientation,
                                splashscreen->indicatordisplay,
+                               splashscreen->operation,
                                user_data);
                if (ret < 0)
                        break;