preserving deleted account information 37/200237/5
authorAbhishek Vijay <abhishek.v@samsung.com>
Wed, 20 Feb 2019 10:55:40 +0000 (16:25 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Fri, 10 May 2019 09:11:11 +0000 (14:41 +0530)
Change-Id: Ica29077ee07a9c843ccd208c75ad1d153c3494b6
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
common/include/account-private.h
common/include/account_db_helper.h
common/src/account_db_helper.c

index ba8a6261b43fa34e98819c33478469f8d3d6b060..775dc2086860ca4a9c478de9713e954514f49378 100644 (file)
@@ -105,11 +105,11 @@ extern "C"
 #define EMAIL_PKG_NAME                 "email-setting-efl"
 #define EXCHANGE_PKG_NAME              "activesync-ui"
 #define IMS_SERVICE_PKG_NAME           "ims-service"
-#define SAMSUNGACCOUNTFRONT_PKG_NAME  "com.samsung.samsung-account-front"
-#define SAMSUNGACCOUNT_PKG_NAME  "com.samsung.samsungaccount"
+#define SAMSUNGACCOUNTFRONT_PKG_NAME   "com.samsung.samsung-account-front"
+#define SAMSUNGACCOUNT_PKG_NAME                "com.samsung.samsungaccount"
 #define CHATON_PKG_NAME                        "xnq5eh9vop.ChatON"
-#define DROPBOX_PKG_NAME  "com.samsung.dropbox"
-#define SYNCHRONISE_PKG_NAME "setting-synchronise-efl"
+#define DROPBOX_PKG_NAME               "com.samsung.dropbox"
+#define SYNCHRONISE_PKG_NAME           "setting-synchronise-efl"
 
 #define USER_TXT_CNT 5
 #define USER_INT_CNT 5
@@ -173,7 +173,6 @@ typedef struct _capability_s {
        int account_id;
 } account_capability_s;
 
-
 typedef struct _account_custom_s {
        int account_id;
        char *app_id;
@@ -192,7 +191,6 @@ typedef struct _account_type_s {
        GSList *provider_feature_list;
 } account_type_s;
 
-
 typedef struct _label_s {
        char *app_id;
        char *label;
index 6e38801a0e1daab022835e8aec43160606ffca8b..09239d7f46ce14b062585c6db29029f85e76d1bf 100644 (file)
@@ -20,7 +20,6 @@
 #include <db-util.h>
 #include <pkgmgr-info.h>
 #include <tzplatform_config.h>
-
 #include "account-private.h"
 
 /* ACCOUNT_TABLE */
 "key TEXT "\
 ");"
 
+/* DELETED_ACCOUNT_TABLE */
+#define DELETED_ACCOUNT_SCHEMA  "create table deleted_account \n"\
+"(\n"\
+"_id INTEGER, "\
+"user_name TEXT, "\
+"email_address TEXT, "\
+"display_name TEXT, "\
+"icon_path TEXT, "\
+"source TEXT, "\
+"package_name TEXT, "\
+"access_token TEXT, "\
+"domain_name TEXT, "\
+"auth_type INTEGER, "\
+"secret INTEGER, "\
+"sync_support INTEGER, "\
+"txt_custom0 TEXT, "\
+"txt_custom1 TEXT, "\
+"txt_custom2 TEXT, "\
+"txt_custom3 TEXT, "\
+"txt_custom4 TEXT, "\
+"int_custom0 INTEGER, "\
+"int_custom1 INTEGER, "\
+"int_custom2 INTEGER, "\
+"int_custom3 INTEGER, "\
+"int_custom4 INTEGER "\
+");"
+
+/* DELETED_CAPABILITY_TABLE */
+#define DELETED_CAPABILITY_SCHEMA  "create table deleted_capability \n"\
+"(\n"\
+"_id INTEGER, "\
+"key TEXT, "\
+"value INTEGER, "\
+"package_name TEXT, "\
+"user_name TEXT, "\
+"account_id INTEGER "\
+");"
+
+/* DELETED_ACCOUNT_CUSTOM_TABLE */
+#define DELETED_ACCOUNT_CUSTOM_SCHEMA  "create table deleted_account_custom \n"\
+"(\n"\
+"AccountId INTEGER, "\
+"AppId TEXT, "\
+"Key TEXT, "\
+"Value TEXT "\
+");"
+
+/* DELETED_TRIGGER_QUERY */
+/* ACCOUNT_TABLE */
+#define TRIGGER_QUERY_DEL_ACC_TAB "create trigger aft_acc_del \n"\
+"after delete on account \n"\
+"begin \n"\
+"insert into deleted_account \n"\
+"values "\
+"(\n"\
+"old._id, "\
+"old.user_name, "\
+"old.email_address, "\
+"old.display_name, "\
+"old.icon_path, "\
+"old.source, "\
+"old.package_name, "\
+"old.access_token, "\
+"old.domain_name, "\
+"old.auth_type, "\
+"old.secret, "\
+"old.sync_support, "\
+"old.txt_custom0, "\
+"old.txt_custom1, "\
+"old.txt_custom2, "\
+"old.txt_custom3, "\
+"old.txt_custom4, "\
+"old.int_custom0, "\
+"old.int_custom1, "\
+"old.int_custom2, "\
+"old.int_custom3, "\
+"old.int_custom4 "\
+");"\
+"end;"
+
+/* CAPABILITY_TABLE */
+#define TRIGGER_QUERY_DEL_CAP_TAB "create trigger aft_capa_del \n"\
+"after delete on capability \n"\
+"begin \n"\
+"insert into deleted_capability \n"\
+"values "\
+"(\n"\
+"old._id, "\
+"old.key, "\
+"old.value, "\
+"old.package_name, "\
+"old.user_name, "\
+"old.account_id "\
+");"\
+"end;"
+
+/* ACCOUNT_CUSTOM_TABLE */
+#define TRIGGER_QUERY_DEL_ACUST_TAB "create trigger aft_cust_del \n"\
+"after delete on account_custom \n"\
+"begin \n"\
+"insert into deleted_account_custom \n"\
+"values "\
+"(\n"\
+"old.AccountId, "\
+"old.AppId, "\
+"old.Key, "\
+"old.Value "\
+");"\
+"end;"
+
 #define OWNER_ROOT 0
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 
            do { \
                        snprintf(dest, size-1, "%s%d%s", tzplatform_mkpath(TZ_SYS_DB, "/"), uid, "/.account.db-journal"); \
                } while (0)
-#define ACCOUNT_TABLE "account"
-#define CAPABILITY_TABLE "capability"
-#define ACCOUNT_CUSTOM_TABLE "account_custom"
-#define ACCOUNT_TYPE_TABLE "account_type"
-#define LABEL_TABLE "label"
-#define PROVIDER_FEATURE_TABLE "provider_feature"
-#define ACCOUNT_SQLITE_SEQ "sqlite_sequence"
-#define ACCOUNT_SQL_LEN_MAX     1024
-#define ACCOUNT_TABLE_TOTAL_COUNT   6
+
+#define ACCOUNT_TABLE                  "account"
+#define CAPABILITY_TABLE               "capability"
+#define ACCOUNT_CUSTOM_TABLE           "account_custom"
+#define ACCOUNT_TYPE_TABLE             "account_type"
+#define LABEL_TABLE                    "label"
+#define PROVIDER_FEATURE_TABLE         "provider_feature"
+#define DELETED_ACCOUNT_TABLE          "deleted_account"
+#define DELETED_CAPABILITY_TABLE       "deleted_capability"
+#define DELETED_ACCOUNT_CUSTOM_TABLE   "deleted_account_custom"
+#define ACCOUNT_SQLITE_SEQ             "sqlite_sequence"
+#define ACCOUNT_SQL_LEN_MAX            1024
+#define ACCOUNT_TABLE_TOTAL_COUNT      9
 
 
 typedef sqlite3_stmt * account_stmt;
@@ -143,7 +256,6 @@ int _remove_sensitive_info_from_non_owning_account(account_s *account, int calle
 int _remove_sensitive_info_from_non_owning_account_list(GList *account_list, int caller_pid, uid_t uid);
 int _remove_sensitive_info_from_non_owning_account_slist(GSList *account_list, int caller_pid, uid_t uid);
 
-
 const char *_account_db_err_msg(sqlite3 *account_db_handle);
 int _account_db_err_code(sqlite3 *account_db_handle);
 int _account_execute_query(sqlite3 *account_db_handle, const char *query);
@@ -162,13 +274,11 @@ void _account_convert_column_to_account(account_stmt hstmt, account_s *account_r
 void _account_convert_column_to_capability(account_stmt hstmt, account_capability_s *capability_record);
 void _account_convert_column_to_custom(account_stmt hstmt, account_custom_s *custom_record);
 
-
 int _account_get_record_count(sqlite3 *account_db_handle, const char *query);
 int _account_create_all_tables(sqlite3 *account_db_handle);
 int _account_check_is_all_table_exists(sqlite3 *account_db_handle);
 int _account_db_handle_close(sqlite3 *account_db_handle);
 
-
 int _account_type_query_app_id_exist_from_all_db(sqlite3 *account_user_db, sqlite3 *account_global_db, const char *app_id);
 void _account_get_appid_from_db(pkgmgrinfo_appinfo_h *ahandle, pkgmgrinfo_pkginfo_h *phandle, char **package_id, const char *appid, uid_t uid, GSList **appid_list);
 int _account_get_represented_appid_from_db(sqlite3 *account_user_db, sqlite3 *account_global_db, const char *appid, uid_t uid, char **verified_appid);
@@ -184,7 +294,6 @@ int _account_delete_table(sqlite3 *account_db_handle, account_stmt *phstmt, GSLi
                                                const char *package_name, const char *app_id, const char* table);
 int _account_delete_account_by_package_name(sqlite3 *account_db_handle, const char *package_name, gboolean permission, int pid, uid_t uid);
 
-
 int _account_type_convert_account_to_sql(account_type_s *account_type, account_stmt hstmt, char *sql_value);
 void _account_type_convert_column_to_provider_feature(account_stmt hstmt, provider_feature_s *feature_record);
 void _account_type_convert_column_to_label(account_stmt hstmt, label_s *label_record);
index 975a747f16a1e37e06df4d1c8f8d3c257bafe87b..3be9c5f33746b28bcb5b8a1d3530e1cb85f947c0 100644 (file)
@@ -700,7 +700,8 @@ int _account_create_all_tables(sqlite3 *account_db_handle)
                rc = _account_execute_query(account_db_handle, ACCOUNT_SCHEMA);
                if (rc == SQLITE_BUSY)
                        return _ACCOUNT_ERROR_DATABASE_BUSY;
-               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", ACCOUNT_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       ACCOUNT_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
 
        }
 
@@ -712,7 +713,8 @@ int _account_create_all_tables(sqlite3 *account_db_handle)
                rc = _account_execute_query(account_db_handle, CAPABILITY_SCHEMA);
                if (rc == SQLITE_BUSY)
                        return _ACCOUNT_ERROR_DATABASE_BUSY;
-               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", CAPABILITY_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       CAPABILITY_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
        }
 
        /* Create account custom table */
@@ -723,7 +725,8 @@ int _account_create_all_tables(sqlite3 *account_db_handle)
                rc = _account_execute_query(account_db_handle, ACCOUNT_CUSTOM_SCHEMA);
                if (rc == SQLITE_BUSY)
                        return _ACCOUNT_ERROR_DATABASE_BUSY;
-               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", query, rc, _account_db_err_msg(account_db_handle)));
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       query, rc, _account_db_err_msg(account_db_handle)));
        }
 
        /* Create account type table */
@@ -734,7 +737,8 @@ int _account_create_all_tables(sqlite3 *account_db_handle)
                rc = _account_execute_query(account_db_handle, ACCOUNT_TYPE_SCHEMA);
                if (rc == SQLITE_BUSY)
                        return _ACCOUNT_ERROR_DATABASE_BUSY;
-               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", ACCOUNT_TYPE_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       ACCOUNT_TYPE_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
        }
 
        /* Create label table */
@@ -745,7 +749,8 @@ int _account_create_all_tables(sqlite3 *account_db_handle)
                rc = _account_execute_query(account_db_handle, LABEL_SCHEMA);
                if (rc == SQLITE_BUSY)
                        return _ACCOUNT_ERROR_DATABASE_BUSY;
-               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", LABEL_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       LABEL_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
        }
 
        /* Create account feature table */
@@ -756,7 +761,53 @@ int _account_create_all_tables(sqlite3 *account_db_handle)
                rc = _account_execute_query(account_db_handle, PROVIDER_FEATURE_SCHEMA);
                if (rc == SQLITE_BUSY)
                        return _ACCOUNT_ERROR_DATABASE_BUSY;
-               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", PROVIDER_FEATURE_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       PROVIDER_FEATURE_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+       }
+
+       /* Create deleted account table */
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", DELETED_ACCOUNT_TABLE);
+       rc = _account_get_record_count(account_db_handle, query);
+       if (rc <= 0) {
+               rc = _account_execute_query(account_db_handle, DELETED_ACCOUNT_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return _ACCOUNT_ERROR_DATABASE_BUSY;
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       DELELTED_ACCOUNT_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+               rc = _account_execute_query(account_db_handle, TRIGGER_QUERY_DEL_ACC_TAB);
+               if (rc == SQLITE_BUSY)
+                       return _ACCOUNT_ERROR_DATABASE_BUSY;
+       }
+
+       /* Create deleted capability table */
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", DELETED_CAPABILITY_TABLE);
+       rc = _account_get_record_count(account_db_handle, query);
+       if (rc <= 0) {
+               rc = _account_execute_query(account_db_handle, DELETED_CAPABILITY_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return _ACCOUNT_ERROR_DATABASE_BUSY;
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       DELETED_CAPABILITY_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+               rc = _account_execute_query(account_db_handle, TRIGGER_QUERY_DEL_CAP_TAB);
+               if (rc == SQLITE_BUSY)
+                       return _ACCOUNT_ERROR_DATABASE_BUSY;
+       }
+
+       /* Create deleted account custom table */
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", DELETED_ACCOUNT_CUSTOM_TABLE);
+       rc = _account_get_record_count(account_db_handle, query);
+       if (rc <= 0) {
+               rc = _account_execute_query(account_db_handle, DELETED_ACCOUNT_CUSTOM_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return _ACCOUNT_ERROR_DATABASE_BUSY;
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+                                       query, rc, _account_db_err_msg(account_db_handle)));
+               rc = _account_execute_query(account_db_handle, TRIGGER_QUERY_DEL_ACUST_TAB);
+               if (rc == SQLITE_BUSY)
+                       return _ACCOUNT_ERROR_DATABASE_BUSY;
        }
 
        _INFO("create all table - END");
@@ -769,8 +820,9 @@ int _account_check_is_all_table_exists(sqlite3 *account_db_handle)
        char query[ACCOUNT_SQL_LEN_MAX] = {0,};
        ACCOUNT_MEMSET(query, 0, sizeof(query));
 
-       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s', '%s', '%s', '%s', '%s')",
-                       ACCOUNT_TABLE, CAPABILITY_TABLE, ACCOUNT_CUSTOM_TABLE, ACCOUNT_TYPE_TABLE, LABEL_TABLE, PROVIDER_FEATURE_TABLE);
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
+                       ACCOUNT_TABLE, CAPABILITY_TABLE, ACCOUNT_CUSTOM_TABLE, ACCOUNT_TYPE_TABLE, LABEL_TABLE, PROVIDER_FEATURE_TABLE,
+                       DELETED_ACCOUNT_TABLE, DELETED_CAPABILITY_TABLE, DELETED_ACCOUNT_CUSTOM_TABLE);
        rc = _account_get_record_count(account_db_handle, query);
 
        if (rc != ACCOUNT_TABLE_TOTAL_COUNT)