Add package_app_info_for_uid table 43/65443/4 accepted/tizen/common/20160412.130721 accepted/tizen/ivi/20160412.063701 accepted/tizen/mobile/20160412.063518 accepted/tizen/tv/20160412.063719 accepted/tizen/wearable/20160412.063623 submit/tizen/20160411.223138
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 11 Apr 2016 04:59:07 +0000 (13:59 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 11 Apr 2016 10:49:42 +0000 (19:49 +0900)
integrate user-specific info about global app to
package_app_info_for_uid table

Change-Id: Ia4cb54e1bb48c0364469e14cee857656fbfaa1e2
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
parser/pkgmgr_parser_db.c
parser/pkgmgr_parser_db.h
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_private.c

index 2b36c38..02c7243 100644 (file)
@@ -324,9 +324,11 @@ sqlite3 *pkgmgr_cert_db;
                                                "REFERENCES package_app_info(app_id) " \
                                                "ON DELETE CASCADE)"
 
-#define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
-                                               "(app_id text not null, " \
-                                               "uid text not null, " \
+#define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
+                                               "(app_id TEXT NOT NULL, " \
+                                               "uid TEXT NOT NULL, " \
+                                               "is_disabled TEXT NOT NULL DEFAULT 'false', " \
+                                               "is_splash_screen_disabled TEXT NOT NULL DEFAULT 'false', " \
                                                "PRIMARY KEY(app_id, uid))"
 
 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
@@ -2207,32 +2209,154 @@ static int __enable_app(const char *appid)
        return ret;
 }
 
+static int __check_appinfo_for_uid_table(const char *appid, uid_t uid,
+               const char *except_col_name)
+{
+       int ret = -1;
+       char query[MAX_QUERY_LEN] = { '\0', };
+       sqlite3_stmt *stmt;
+       char *val = NULL;
+
+       if (appid == NULL)
+               return -1;
+
+       if (except_col_name == NULL) {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT COUNT(*) FROM " \
+                       "package_app_info_for_uid WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
+       } else if (strcmp(except_col_name, "is_disabled") == 0) {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT COUNT(*) FROM " \
+                               "package_app_info_for_uid WHERE app_id=%Q AND uid='%d' " \
+                               "AND is_splash_screen_disabled='false'", appid, (int)uid);
+       } else if (strcmp(except_col_name, "is_splash_screen_disabled") == 0) {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT COUNT(*) FROM " \
+                               "package_app_info_for_uid WHERE app_id=%Q AND uid='%d' " \
+                               "AND is_disabled='false'", appid, (int)uid);
+       }
+
+       ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
+               return PMINFO_R_ERROR;
+       }
+
+       if (sqlite3_step(stmt) != SQLITE_ROW) {
+               LOGE("failed to step");
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       val = (const char *)sqlite3_column_text(stmt, 0);
+       ret = atoi(val);
+       sqlite3_finalize(stmt);
+       return ret;
+}
+
 static int __disable_global_app_for_user(const char *appid, uid_t uid)
 {
        int ret = -1;
+       char query[MAX_QUERY_LEN] = { '\0', };
+
+       ret = __check_appinfo_for_uid_table(appid, uid, NULL);
+
+       if (ret < 0) {
+               _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
+                               appid, (int)uid);
+               return -1;
+       } else if (ret == 0) {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
+                               "package_app_info_for_uid(app_id, uid, is_disabled) " \
+                               "VALUES(%Q, '%d', 'true')", appid, (int)uid);
+       } else {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
+                               "package_app_info_for_uid SET is_disabled='true' " \
+                               "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
+       }
+
+       ret = __exec_query(query);
+       if (ret == -1)
+               _LOGD("Add global app disable info failed\n");
+
+       return ret;
+}
+
+static int __enable_global_app_for_user(const char *appid, uid_t uid)
+{
+       int ret = -1;
        char query[MAX_QUERY_LEN] = {'\0'};
 
-       sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
-                       "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
+       ret = __check_appinfo_for_uid_table(appid, uid, "is_disabled");
+       if (ret < 0) {
+               _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
+                               appid, (int)uid);
+               return -1;
+       } else if (ret == 0) {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
+                       "package_app_info_for_uid SET is_disabled='false' " \
+                       "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
+       } else {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
+                       "package_app_info_for_uid WHERE app_id=%Q AND uid='%d'",
                        appid, (int)uid);
+       }
+
        ret = __exec_query(query);
        if (ret == -1)
-               _LOGD("Insert global app disable failed\n");
+               _LOGD("Remove global app disable info failed\n");
 
        return ret;
 }
 
-static int __enable_global_app_for_user(const char *appid, uid_t uid)
+static int __disable_global_app_splash_screen_for_user(const char *appid, uid_t uid)
+{
+       int ret = -1;
+       char query[MAX_QUERY_LEN] = { '\0', };
+
+       ret = __check_appinfo_for_uid_table(appid, uid, NULL);
+
+       if (ret < 0) {
+               _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
+                               appid, (int)uid);
+               return -1;
+       } else if (ret == 0) {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
+                               "package_app_info_for_uid(app_id, uid, is_splash_screen_disabled) " \
+                               "VALUES(%Q, '%d', 'true')", appid, (int)uid);
+       } else {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
+                               "package_app_info_for_uid SET is_splash_screen_disabled='true' " \
+                               "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
+       }
+
+       ret = __exec_query(query);
+       if (ret == -1)
+               _LOGD("Add global app splash screen info failed\n");
+
+       return ret;
+}
+
+static int __enable_global_app_splash_screen_for_user(const char *appid, uid_t uid)
 {
        int ret = -1;
        char query[MAX_QUERY_LEN] = {'\0'};
 
-       sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
-                       "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
+       ret = __check_appinfo_for_uid_table(appid, uid, "is_splash_screen_disabled");
+       if (ret < 0) {
+               _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
+                               appid, (int)uid);
+               return -1;
+       } else if (ret == 0) {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
+                       "package_app_info_for_uid SET is_splash_screen_disabled='false' " \
+                       "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
+       } else {
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
+                       "package_app_info_for_uid WHERE app_id=%Q AND uid='%d'",
                        appid, (int)uid);
+       }
+
        ret = __exec_query(query);
        if (ret == -1)
-               _LOGD("Delete global app disable failed\n");
+               _LOGD("Remove global app splash screen info failed\n");
 
        return ret;
 }
@@ -2334,9 +2458,9 @@ API int pkgmgr_parser_initialize_db(uid_t uid)
                return ret;
        }
 
-       ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
+       ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
        if (ret == -1) {
-               _LOGD("package app disable for user DB initialization failed\n");
+               _LOGD("package_app_info_for_uid for user DB initialization failed\n");
                return ret;
        }
 
@@ -2930,3 +3054,44 @@ err:
        return ret;
 
 }
+
+API int pkgmgr_parser_update_global_app_splash_screen_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
+{
+       int ret = -1;
+
+       ret = pkgmgr_parser_check_and_create_db(uid);
+       if (ret == -1) {
+               _LOGD("Failed to open DB\n");
+               return ret;
+       }
+
+       /*Begin transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to begin transaction\n");
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Begin\n");
+       if (is_disable)
+               ret = __disable_global_app_splash_screen_for_user(appid, uid);
+       else
+               ret = __enable_global_app_splash_screen_for_user(appid, uid);
+       if (ret == -1) {
+               _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               goto err;
+       }
+       /*Commit transaction*/
+       ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to commit transaction, Rollback now\n");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Commit and End\n");
+err:
+       pkgmgr_parser_close_db();
+       return ret;
+}
index 33918e4..10790cf 100644 (file)
@@ -215,6 +215,32 @@ static int disable_app(const char *appid)
 int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable);
 int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable);
 
+/**
+ * @fn int pkgmgr_parser_update_global_app_splash_screen_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
+ * @brief      This API updates splash screen disable info about global app for user specified by uid
+ *
+ * @par                This API is for package-manager installer backends
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in]  appid   global application ID to be enabled or disabled
+ * @param[in]  uid     the addressee user id of the instruction
+ * @param[in]is_disable        determine enable or disable of app
+ * @return     0 if success, error code(<0) if fail
+ * @pre                None
+ * @post               None
+ * @code
+static int disable_global_app_splash_screen_for_uid(const char *appid, uid_t uid)
+{
+       int ret = 0;
+       ret = pkgmgr_parser_update_global_app_splash_screen_info_in_usr_db(appid, uid, 1);
+       if (ret < 0)
+               return -1;
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgr_parser_update_global_app_splash_screen_info_in_usr_db(const char *appid, uid_t uid, int is_disable);
+
 int pkgmgr_parser_create_and_initialize_db(uid_t uid);
 
 
index 11a968a..4004fc0 100644 (file)
@@ -600,7 +600,7 @@ static int _appinfo_get_application(sqlite3 *db, const char *appid,
                "FROM package_app_info WHERE app_id='%s' "
                "AND (app_disable='%s' "
                "%s app_id %s IN "
-               "(SELECT app_id from package_app_disable_for_user WHERE uid='%d'))";
+               "(SELECT app_id from package_app_info_for_uid WHERE uid='%d' AND is_disabled='%s'))";
        int ret;
        char query[MAX_QUERY_LEN] = { '\0' };
        sqlite3_stmt *stmt;
@@ -612,7 +612,8 @@ static int _appinfo_get_application(sqlite3 *db, const char *appid,
                        is_disabled ? "true" : "false",
                        is_disabled ? "OR" : "AND",
                        is_disabled ? "" : "NOT",
-                       (int)target_uid);
+                       (int)target_uid,
+                       is_disabled ? "true" : "false");
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -812,8 +813,8 @@ int _appinfo_get_applist(uid_t uid, const char *locale, GHashTable **appinfo_tab
                        "app_background_category, app_root_path, app_api_version, "
                         "app_effective_appid, app_disable, app_splash_screen_display, "
                        "(CASE WHEN A.app_disable='true' THEN 'true' "
-                       "ELSE (CASE WHEN (SELECT app_id FROM package_app_disable_for_user "
-                       "WHERE app_id=A.app_id AND uid='%d') IS NULL "
+                       "ELSE (CASE WHEN (SELECT app_id FROM package_app_info_for_uid "
+                       "WHERE app_id=A.app_id AND uid='%d' AND is_disabled='true') IS NULL "
                        "THEN 'false' ELSE 'true' END) END) AS app_disable "
                        "FROM package_app_info A", (int)getuid());
 
index b687716..c00e0cc 100644 (file)
@@ -357,7 +357,8 @@ void __get_filter_condition(gpointer data, char **condition)
                break;
        case E_PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER:
                snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id NOT IN "
-                               "(SELECT app_id from package_app_disable_for_user WHERE uid='%s')", node->value);
+                               "(SELECT app_id from package_app_info_for_uid WHERE uid='%s' " \
+                               "AND is_disabled='true')", node->value);
                break;
        default:
                _LOGE("Invalid Property Type\n");