"(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 " \
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) {
val = (const char *)sqlite3_column_text(stmt, 0);
ret = atoi(val);
sqlite3_finalize(stmt);
+
return ret;
}
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);
}
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);
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;
}
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);
}
-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");
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");
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;
+}
+
* @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
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
}
* @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);
}
+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)
{
"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;
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) {
_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);
_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);