Implement app signal related with app splash screen display 97/65897/18 accepted/tizen/common/20160426.143102 accepted/tizen/ivi/20160425.231853 accepted/tizen/mobile/20160425.231841 accepted/tizen/tv/20160425.231806 accepted/tizen/wearable/20160425.231831 submit/tizen/20160425.083419
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 14 Apr 2016 01:50:31 +0000 (10:50 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Sun, 24 Apr 2016 23:47:52 +0000 (16:47 -0700)
- Add db trigger to handle the package_app_info_for_uid table.
- Add internal APIs:
pkgmgr_parser_update_app_splash_screen_display_info_in_db()
pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db()

Change-Id: I5a64be7f26af61140439f3b0f2fdfaa5b6556e51
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
parser/pkgmgr_parser_db.c
parser/pkgmgr_parser_db.h
src/pkgmgrinfo_appinfo.c

index 8055368..16f701b 100644 (file)
@@ -328,8 +328,18 @@ sqlite3 *pkgmgr_cert_db;
                                                "(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', " \
+                                               "is_splash_screen_enabled TEXT NOT NULL, " \
                                                "PRIMARY KEY(app_id, uid))"
+#define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
+       "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
+       "AFTER UPDATE ON package_app_info_for_uid " \
+       "BEGIN" \
+       " DELETE FROM package_app_info_for_uid WHERE " \
+       "       is_splash_screen_enabled=" \
+       "       (SELECT package_app_info.app_splash_screen_display FROM " \
+       "       package_app_info, package_app_info_for_uid WHERE " \
+       "       package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
+       "END;"
 
 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
        "create table if not exists package_app_splash_screen " \
@@ -2209,29 +2219,20 @@ 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)
+static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
 {
        int ret = -1;
        char query[MAX_QUERY_LEN] = { '\0', };
        sqlite3_stmt *stmt;
-       char *val = NULL;
+       const 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);
-       }
+       sqlite3_snprintf(MAX_QUERY_LEN, query,
+                       "SELECT COUNT(*) FROM "
+                       "package_app_info_for_uid WHERE app_id=%Q "
+                       "AND uid='%d'", appid, (int)uid);
 
        ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -2248,6 +2249,7 @@ static int __check_appinfo_for_uid_table(const char *appid, uid_t uid,
        val = (const char *)sqlite3_column_text(stmt, 0);
        ret = atoi(val);
        sqlite3_finalize(stmt);
+
        return ret;
 }
 
@@ -2256,19 +2258,20 @@ 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);
-
+       ret = __check_appinfo_for_uid_table(appid, uid);
        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);
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
+                               "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
+                               "VALUES(%Q, '%d', 'true', "
+                               "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
+                               appid, (int)uid, appid);
        } else {
-               sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
-                               "package_app_info_for_uid SET is_disabled='true' " \
+               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);
        }
 
@@ -2284,19 +2287,16 @@ static int __enable_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, "is_disabled");
+       ret = __check_appinfo_for_uid_table(appid, uid);
        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);
+       } 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);
        }
 
        ret = __exec_query(query);
@@ -2306,57 +2306,62 @@ static int __enable_global_app_for_user(const char *appid, uid_t uid)
        return ret;
 }
 
-static int __disable_global_app_splash_screen_for_user(const char *appid, uid_t uid)
+static int __update_global_app_splash_screen_for_user(const char *appid,
+               uid_t uid, int flag)
 {
        int ret = -1;
        char query[MAX_QUERY_LEN] = { '\0', };
 
-       ret = __check_appinfo_for_uid_table(appid, uid, NULL);
-
+       ret = __check_appinfo_for_uid_table(appid, uid);
        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);
+               sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
+                               "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
+                               "VALUES(%Q, '%d', %Q)", appid, (int)uid,
+                               flag ? "true" : "false");
        } 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);
+               sqlite3_snprintf(MAX_QUERY_LEN, query,
+                               "UPDATE package_app_info_for_uid SET "
+                               "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
+                               "uid='%d'", flag ? "true" : "false", appid, (int)uid);
        }
 
        ret = __exec_query(query);
        if (ret == -1)
-               _LOGD("Add global app splash screen info failed\n");
+               _LOGD("update global app splash screen info failed\n");
 
        return ret;
 }
 
-static int __enable_global_app_splash_screen_for_user(const char *appid, uid_t uid)
+static int __disable_app_splash_screen(const char *appid)
 {
-       int ret = -1;
+       int ret;
        char query[MAX_QUERY_LEN] = {'\0'};
 
-       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);
-       }
+       sqlite3_snprintf(MAX_QUERY_LEN, query,
+                       "UPDATE package_app_info set app_splash_screen_display='false' where app_id=%Q",
+                       appid);
+       ret = __exec_query(query);
+       if (ret == -1)
+               _LOGD("Failed to update app_palsh_screen_display");
+
+       return ret;
+}
 
+static int __enable_app_splash_screen(const char *appid)
+{
+       int ret;
+       char query[MAX_QUERY_LEN] = {'\0'};
+
+       sqlite3_snprintf(MAX_QUERY_LEN, query,
+                       "UPDATE package_app_info set app_splash_screen_display='true' where app_id=%Q",
+                       appid);
        ret = __exec_query(query);
        if (ret == -1)
-               _LOGD("Remove global app splash screen info failed\n");
+               _LOGD("Failed to update app_splash_screen_display");
 
        return ret;
 }
@@ -2470,6 +2475,13 @@ API int pkgmgr_parser_initialize_db(uid_t uid)
                return ret;
        }
 
+       /* Trigger package_app_info_for_uid */
+       ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
+       if (ret == -1) {
+               _LOGD("package app info for uid DB initialization failed\n");
+               return ret;
+       }
+
        /*Cert DB*/
        /* TODO: refactor this code */
        ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
@@ -2975,17 +2987,22 @@ err:
 
 }
 
-API int pkgmgr_parser_update_global_app_splash_screen_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
+API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
 {
        int ret = -1;
 
-       ret = pkgmgr_parser_check_and_create_db(uid);
+       if (appid == NULL) {
+               _LOGD("Invalid parameter");
+               return -1;
+       }
+
+       ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
        if (ret == -1) {
                _LOGD("Failed to open DB\n");
                return ret;
        }
 
-       /*Begin transaction*/
+       /* Begin transaction */
        ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGD("Failed to begin transaction\n");
@@ -2993,16 +3010,14 @@ API int pkgmgr_parser_update_global_app_splash_screen_info_in_usr_db(const char
                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);
+
+       ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
        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*/
+       /* Commit transaction */
        ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
        if (ret != SQLITE_OK) {
                _LOGD("Failed to commit transaction, Rollback now\n");
@@ -3015,3 +3030,57 @@ err:
        pkgmgr_parser_close_db();
        return ret;
 }
+
+API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
+{
+       return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
+}
+
+API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
+{
+       int ret;
+
+       if (appid == NULL) {
+               _LOGD("Invalid parameter");
+               return -1;
+       }
+
+       ret = pkgmgr_parser_check_and_create_db(uid);
+       if (ret == -1) {
+               _LOGD("Failed to open DB");
+               return -1;
+       }
+
+       /* Begin transaction */
+       ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN_EXCLUSIVE", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGD("Failed to begin transaction");
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Begin");
+
+       if (flag)
+               ret = __enable_app_splash_screen(appid);
+       else
+               ret = __disable_app_splash_screen(appid);
+       if (ret == -1) {
+               _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
+               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");
+               sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
+               ret = -1;
+               goto err;
+       }
+       _LOGD("Transaction Commit and End");
+
+err:
+       pkgmgr_parser_close_db();
+       return ret;
+}
+
index 10790cf..c894eb5 100644 (file)
@@ -197,7 +197,7 @@ int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid
  * @par Sync (or) Async : Synchronous API
  *
  * @param[in]  appid   application ID to be enabled or disabled
- * @param[in]is_disable        determine enable or disable of app
+ * @param[in]  is_disable      determine enable or disable of app
  * @return     0 if success, error code(<0) if fail
  * @pre                None
  * @post               None
@@ -216,15 +216,15 @@ int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disabl
 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
+ * @fn int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
+ * @brief      This API updates splash screen display 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
+ * @param[in]  uid     user ID
+ * @param[in]  flag    determine enable or disable of app
  * @return     0 if success, error code(<0) if fail
  * @pre                None
  * @post               None
@@ -239,7 +239,46 @@ static int disable_global_app_splash_screen_for_uid(const char *appid, uid_t uid
 }
  * @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_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag);
+
+/**
+ * @fn int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
+ * @brief      This API updates splash screen display info about app
+ *
+ * @par                This API is for package-manager installer backends
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in]  appid   application ID to be enabled or disabled
+ * @param[in]  flag    determine enable or disable of app
+ * @return     0 if success, error code(<0) if fail
+ * @pre                None
+ * @post               None
+ * @code
+static int disable_app_splash_screen(const char *appid)
+{
+       int ret = 0;
+       ret = pkgmgr_parser_update_app_splash_screen_info_in_db(appid, 1);
+       if (ret < 0)
+               return -1;
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag);
+
+/**
+ * @fn int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
+ * @brief      This API updates splash screen display info about app for user specified by uid
+ *
+ * @par                This API is for package-manager installer backends
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in]  appid   application ID to be enabled or disabled
+ * @param[in]  uid     user ID
+ * @param[in]  flag    determine enable or disable of app
+ * @return     0 if success, error code(<0) if fail
+ */
+int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag);
 
 int pkgmgr_parser_create_and_initialize_db(uid_t uid);
 
index 13c31ba..4092952 100644 (file)
@@ -580,6 +580,37 @@ static GList *__get_background_category(const char *value)
 
 }
 
+static void __get_splash_screen_display(sqlite3 *db, const char *appid, uid_t uid, char **value)
+{
+       static const char query_raw[] =
+               "SELECT is_splash_screen_enabled FROM package_app_info_for_uid "
+               "WHERE app_id='%s' AND uid='%d'";
+       int ret;
+       char *query;
+       sqlite3_stmt *stmt;
+
+       query = sqlite3_mprintf(query_raw, appid, uid);
+       if (query == NULL) {
+               LOGE("out of memory");
+               return;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       sqlite3_free(query);
+       if (ret != SQLITE_OK) {
+               LOGE("sqlite3_prepare_v2() failed: %s", sqlite3_errmsg(db));
+               return;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               if (*value)
+                       free(*value);
+               _save_column_str(stmt, 0, value);
+       }
+
+       sqlite3_finalize(stmt);
+}
+
 static int _appinfo_get_application(sqlite3 *db, const char *appid,
                const char *locale, application_x **application, bool is_disabled, uid_t db_uid, uid_t target_uid)
 {
@@ -600,7 +631,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_info_for_uid WHERE uid='%d' AND is_disabled='%s'))";
+               "(SELECT app_id from package_app_info_for_uid WHERE uid='%d' AND is_disabled='true'))";
        int ret;
        char query[MAX_QUERY_LEN] = { '\0' };
        sqlite3_stmt *stmt;
@@ -612,8 +643,7 @@ static int _appinfo_get_application(sqlite3 *db, const char *appid,
                        is_disabled ? "true" : "false",
                        is_disabled ? "OR" : "AND",
                        is_disabled ? "" : "NOT",
-                       (int)target_uid,
-                       is_disabled ? "true" : "false");
+                       (int)target_uid);
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -674,8 +704,12 @@ static int _appinfo_get_application(sqlite3 *db, const char *appid,
        _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->is_disabled);
+       _save_column_str(stmt, idx++, &info->splash_screen_display);
+
+       if (db_uid == GLOBAL_USER)
+               __get_splash_screen_display(db, info->appid, db_uid,
+                               &info->splash_screen_display);
 
        info->background_category = __get_background_category(bg_category_str);
        free(bg_category_str);
@@ -867,8 +901,12 @@ int _appinfo_get_applist(uid_t uid, const char *locale, GHashTable **appinfo_tab
                _save_column_str(stmt, idx++, &appinfo->api_version);
 
                _save_column_str(stmt, idx++, &appinfo->effective_appid);
-                _save_column_str(stmt, idx++, &appinfo->is_disabled);
-                _save_column_str(stmt, idx++, &appinfo->splash_screen_display);
+               _save_column_str(stmt, idx++, &appinfo->is_disabled);
+               _save_column_str(stmt, idx++, &appinfo->splash_screen_display);
+
+               if (uid == GLOBAL_USER)
+                       __get_splash_screen_display(db, appinfo->appid, uid,
+                                       &appinfo->splash_screen_display);
 
                appinfo->background_category = __get_background_category(bg_category_str);
                free(bg_category_str);