major version up : apply multi-user(System) 08/48708/2 accepted/tizen/mobile/20151006.225117 submit/tizen_mobile/20151006.082543 tizen_3.0.m2.a1_mobile_release
authorjang <jiseob.jang@samsung.com>
Fri, 25 Sep 2015 07:33:36 +0000 (16:33 +0900)
committerjang <jiseob.jang@samsung.com>
Mon, 5 Oct 2015 09:05:30 +0000 (18:05 +0900)
- support user and global db.
- add creating account db(User).

Change-Id: I4b747ad17d5c713d38094325b59b3a2f2f2e1fd3
Signed-off-by: jang <jiseob.jang@samsung.com>
packaging/account-manager.spec
packaging/org.tizen.account.manager.conf
packaging/org.tizen.account.manager.service
server/include/account-server-db.h
server/src/account-server-db.c
server/src/account-server.c

index 044d76e..beefa00 100644 (file)
@@ -1,7 +1,7 @@
 
 Name:       account-manager
 Summary:    Account Manager
-Version:    0.0.8
+Version:    0.1.0
 Release:    1
 Group:      Social & Content/Other
 License:    Apache-2.0
@@ -98,8 +98,8 @@ fi
 #chmod 600 %{TZ_SYS_DB}/.account.db-journal
 
 #smack labeling
-#chsmack -a 'System' %{TZ_SYS_DB}/.account.db-journal
-#chsmack -a 'System' %{TZ_SYS_DB}/.account.db
+#chsmack -a 'System::Shared' %{TZ_SYS_DB}/.account.db-journal
+#chsmack -a 'System::Shared' %{TZ_SYS_DB}/.account.db
 %postun -p /sbin/ldconfig
 
 
index 3fb0ac4..164f436 100644 (file)
@@ -7,7 +7,13 @@
                <allow send_interface="org.tizen.account.manager"/>
                <allow receive_sender="org.tizen.account.manager"/>
        </policy>
-       <policy user="system">
+       <policy smack="User">
+               <allow own="org.tizen.account.manager"/>
+               <allow send_destination="org.tizen.account.manager"/>
+               <allow send_interface="org.tizen.account.manager"/>
+               <allow receive_sender="org.tizen.account.manager"/>
+       </policy>
+       <policy smack="System">
                <allow own="org.tizen.account.manager"/>
                <allow send_destination="org.tizen.account.manager"/>
                <allow send_interface="org.tizen.account.manager"/>
index 0891cad..3ec2ce0 100644 (file)
@@ -1,3 +1,6 @@
+[Unit]
+Description=Account Service D-BUS
+
 [D-BUS Service]
 Name=org.tizen.account.manager
 Exec=/usr/bin/account-svcd
index 7c2e4f0..55bcc80 100644 (file)
 
 #include <account-private.h>
 
-//ACCOUNT_TABLE
-#define ACCOUNT_SCHEMA "create table account \n"\
-       "(\n"\
-"_id INTEGER PRIMARY KEY, "\
-"user_name TEXT, "\
-"email_address TEXT, "\
-"display_name TEXT, "\
-"icon_path TEXT, "\
-"source TEXT, "\
-"package_name TEXT, "\
-"access_token TEXT, "\
-"domain_name TEXT, "\
-"auth_method 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 "\
-");"
-
-//CAPABILITY_TABLE
-#define CAPABILITY_SCHEMA  "create table capability \n"\
-       "(\n"\
-"_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
-"key TEXT, "\
-"value INTEGER, "\
-"package_name TEXT, "\
-"user_name TEXT, "\
-"account_id INTEGER "\
-");"
-
-//ACCOUNT_CUSTOM_TABLE
-#define ACCOUNT_CUSTOM_SCHEMA  "create table account_custom \n"\
-       "(\n"\
-"AccountId INTEGER, "\
-"AppId TEXT, "\
-"Key TEXT, "\
-"Value TEXT "\
-");"
-
-//ACCOUNT_TYPE_TABLE
-#define ACCOUNT_TYPE_SCHEMA "create table account_type \n"\
-       "(\n"\
-"_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
-"AppId TEXT, "\
-"ServiceProviderId TEXT, "\
-"IconPath TEXT, "\
-"SmallIconPath TEXT, "\
-"MultipleAccountSupport INTEGER "\
-");"
-
-//LABEL_TABLE
-#define LABEL_SCHEMA "create table label \n"\
-       "(\n"\
-"AppId TEXT, "\
-"Label TEXT, "\
-"Locale TEXT"\
-");"
-
-//PROVIDER_FEATURE_TABLE
-#define PROVIDER_FEATURE_SCHEMA "create table provider_feature \n"\
-       "(\n"\
-"app_id TEXT, "\
-"key TEXT "\
-");"
-
-
 int _account_insert_to_db(account_s* account, int pid, int uid, int *account_id);
-int _account_db_open(int mode, int pid);
+int _account_db_open(int mode, int pid, int uid);
 int _account_db_close(void);
+int _account_global_db_open(void);
+int _account_global_db_close(void);
 int _account_type_insert_to_db(account_type_s* account_type, int* account_type_id);
 GSList* _account_db_query_all(int pid);
 GSList* _account_type_query_all(void);
@@ -123,6 +50,7 @@ int _account_type_delete_by_app_id(const char* app_id);
 GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_code );
 int _account_type_query_by_app_id(const char* app_id, account_type_s **account_type_record);
 int _account_type_query_app_id_exist(const char* app_id);
+int _account_type_query_app_id_exist_from_all_db(const char* app_id);
 int _account_update_to_db_by_id_ex(account_s *account, int account_id);
 
 #endif
index 6df270d..4699467 100644 (file)
@@ -20,6 +20,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <pthread.h>
 #include <glib.h>
 #include <db-util.h>
 #include <pthread.h>
@@ -27,7 +30,6 @@
 
 #include <pkgmgr-info.h>
 #include <aul.h>
-#include <unistd.h>
 #include <tzplatform_config.h>
 
 #include <dbg.h>
@@ -67,14 +69,17 @@ typedef sqlite3_stmt* account_stmt;
 
 #define _TIZEN_PUBLIC_
 #ifndef _TIZEN_PUBLIC_
-//#include <csc-feature.h>
 
 #endif
 
 static sqlite3* g_hAccountDB = NULL;
 static sqlite3* g_hAccountDB2 = NULL;
+static sqlite3* g_hAccountGlobalDB = NULL;
+static sqlite3* g_hAccountGlobalDB2 = NULL;
 pthread_mutex_t account_mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t account_global_mutex = PTHREAD_MUTEX_INITIALIZER;
 
+int _account_db_handle_close(sqlite3* hDB);
 static char *_account_get_text(const char *text_data);
 static const char *_account_query_table_column_text(account_stmt pStmt, int pos);
 static int _account_insert_custom(account_s *account, int account_id);
@@ -192,9 +197,9 @@ static char* _account_get_current_appid(int pid)
                        _ACCOUNT_FREE(cmdline);
                        return appid_ret;
                } else if (!g_strcmp0(cmdline, IMS_ENGINE_CMDLINE) || !g_strcmp0(cmdline, IMS_AGENT_CMDLINE)) {
-                       if(_account_type_query_app_id_exist(RCS_APPID)==ACCOUNT_ERROR_NONE){
+                       if(_account_type_query_app_id_exist_from_all_db(RCS_APPID) == ACCOUNT_ERROR_NONE) {
                                appid_ret = _account_get_text(RCS_APPID);
-                       } else if(_account_type_query_app_id_exist(IMS_SERVICE_APPID)==ACCOUNT_ERROR_NONE){
+                       } else if(_account_type_query_app_id_exist_from_all_db(IMS_SERVICE_APPID) == ACCOUNT_ERROR_NONE) {
                                appid_ret = _account_get_text(IMS_SERVICE_APPID);
                        } else {
                                appid_ret = _account_get_text(RCS_APPID);
@@ -229,6 +234,257 @@ static char* _account_get_current_appid(int pid)
        return appid_ret;
 }
 
+static const char *_account_db_err_msg_from_global_db()
+{
+       return sqlite3_errmsg(g_hAccountGlobalDB);
+}
+
+static int _account_db_err_code_from_global_db()
+{
+       return sqlite3_errcode(g_hAccountGlobalDB);
+}
+
+static int _account_get_record_count_from_global_db(const char *query)
+{
+       _INFO("_account_get_record_count_in_global_db");
+
+       int rc = -1;
+       int ncount = 0;
+       account_stmt pStmt = NULL;
+
+       if(!query){
+               _ERR("NULL query\n");
+               return ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
+       }
+
+       if(!g_hAccountGlobalDB) {
+               _ERR("DB is not opened\n");
+               return ACCOUNT_ERROR_DB_NOT_OPENED;
+       }
+
+       rc = sqlite3_prepare_v2(g_hAccountGlobalDB, query, strlen(query), &pStmt, NULL);
+
+       if (SQLITE_BUSY == rc){
+               _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg_from_global_db());
+               sqlite3_finalize(pStmt);
+               return ACCOUNT_ERROR_DATABASE_BUSY;
+       } else if (SQLITE_OK != rc) {
+               _ERR("sqlite3_prepare_v2() failed(%d, %s).", rc, _account_db_err_msg_from_global_db());
+               sqlite3_finalize(pStmt);
+               return ACCOUNT_ERROR_DB_FAILED;
+       }
+
+       rc = sqlite3_step(pStmt);
+       if (SQLITE_BUSY == rc) {
+               _ERR("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg_from_global_db());
+               sqlite3_finalize(pStmt);
+               return ACCOUNT_ERROR_DATABASE_BUSY;
+       } else if (SQLITE_ROW != rc) {
+               _ERR("sqlite3_step() failed(%d, %s).", rc, _account_db_err_msg_from_global_db());
+               sqlite3_finalize(pStmt);
+               return ACCOUNT_ERROR_DB_FAILED;
+       }
+
+       ncount = sqlite3_column_int(pStmt, 0);
+
+       _INFO("account record count [%d]", ncount);
+       sqlite3_finalize(pStmt);
+
+       return ncount;
+}
+/*
+static int _account_execute_query_from_global_db(const char *query)
+{
+       int rc = -1;
+       char* pszErrorMsg = NULL;
+
+       if(!query){
+               ACCOUNT_ERROR("NULL query\n");
+               return ACCOUNT_ERROR_QUERY_SYNTAX_ERROR;
+       }
+
+       if(!g_hAccountGlobalDB){
+               ACCOUNT_ERROR("Global DB is not opened\n");
+               return ACCOUNT_ERROR_DB_NOT_OPENED;
+       }
+
+       rc = sqlite3_exec(g_hAccountGlobalDB, query, NULL, NULL, &pszErrorMsg);
+       if (SQLITE_OK != rc) {
+               ACCOUNT_ERROR("sqlite3_exec rc(%d) query(%s) failed(%s).", rc, query, pszErrorMsg);
+               sqlite3_free(pszErrorMsg);
+       }
+
+       return rc;
+}
+*/
+/*
+static int _account_begin_transaction_from_global_db(void)
+{
+       ACCOUNT_DEBUG("_account_begin_transaction start");
+       int ret = -1;
+
+       ret = _account_execute_query_from_global_db("BEGIN IMMEDIATE TRANSACTION");
+
+       if (ret == SQLITE_BUSY){
+               ACCOUNT_ERROR(" sqlite3 busy = %d", ret);
+               return ACCOUNT_ERROR_DATABASE_BUSY;
+       } else if(ret != SQLITE_OK) {
+               ACCOUNT_ERROR("_account_svc_begin_transaction_in_global_db fail :: %d", ret);
+               return ACCOUNT_ERROR_DB_FAILED;
+       }
+
+       ACCOUNT_DEBUG("_account_begin_transaction_in_global_db end");
+       return ACCOUNT_ERROR_NONE;
+}
+
+static int _account_end_transaction_from_global_db(bool is_success)
+{
+       ACCOUNT_DEBUG("_account_end_transaction_in_global_db start");
+
+       int ret = -1;
+
+       if (is_success == true) {
+               ret = _account_execute_query_from_global_db("COMMIT TRANSACTION");
+               ACCOUNT_DEBUG("_account_end_transaction_in_global_db COMMIT");
+       } else {
+               ret = _account_execute_query_from_global_db("ROLLBACK TRANSACTION");
+               ACCOUNT_DEBUG("_account_end_transaction ROLLBACK");
+       }
+
+       if(ret == SQLITE_PERM) {
+               ACCOUNT_ERROR("Account permission denied :: %d", ret);
+               return ACCOUNT_ERROR_PERMISSION_DENIED;
+       }
+
+       if (ret == SQLITE_BUSY){
+               ACCOUNT_DEBUG(" sqlite3 busy = %d", ret);
+               return ACCOUNT_ERROR_DATABASE_BUSY;
+       }
+
+       if (ret != SQLITE_OK) {
+               ACCOUNT_ERROR("_account_svc_end_transaction_in_global_db fail :: %d", ret);
+               return ACCOUNT_ERROR_DB_FAILED;
+       }
+
+       ACCOUNT_DEBUG("_account_end_transaction_in_global_db end");
+       return ACCOUNT_ERROR_NONE;
+}
+*/
+int _account_type_query_app_id_exist_from_global_db(const char *app_id)
+{
+       char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int rc = 0;
+
+       ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppId = '%s'", ACCOUNT_TYPE_TABLE, app_id);
+/*
+       pthread_mutex_lock(&account_global_mutex);
+
+       ret_transaction = _account_begin_transaction_from_global_db();
+
+       if(_account_db_err_code() == SQLITE_PERM){
+               pthread_mutex_unlock(&account_global_mutex);
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_global());
+               return ACCOUNT_ERROR_PERMISSION_DENIED;
+       }
+
+       if (ret_transaction == ACCOUNT_ERROR_DATABASE_BUSY) {
+               ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
+               pthread_mutex_unlock(&account_global_mutex);
+               return ACCOUNT_ERROR_DATABASE_BUSY;
+       }else if (ret_transaction != ACCOUNT_ERROR_NONE) {
+               ACCOUNT_ERROR("account insert:_account_begin_transaction fail %d\n", ret_transaction);
+               pthread_mutex_unlock(&account_global_mutex);
+               return ret_transaction;
+       }
+*/
+       rc = _account_get_record_count_from_global_db(query);
+
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               _ERR( "Global DB access failed(%s)", _account_db_err_msg_from_global_db());
+
+               return ACCOUNT_ERROR_PERMISSION_DENIED;
+       }
+
+       if (rc <= 0) {
+               return ACCOUNT_ERROR_RECORD_NOT_FOUND;
+       }
+
+       return ACCOUNT_ERROR_NONE;
+}
+
+int _account_global_db_open(void)
+{
+       int  rc = 0;
+       int ret = -1;
+       char account_db_path[256] = {0, };
+
+       _INFO( "start _account_global_db_open()");
+
+       ACCOUNT_MEMSET(account_db_path, 0x00, sizeof(account_db_path));
+       ACCOUNT_GET_GLOBAL_DB_PATH(account_db_path, sizeof(account_db_path));
+
+       if( g_hAccountGlobalDB ) {
+               _ERR( "Account database is using in another app. %x", g_hAccountDB );
+               return ACCOUNT_ERROR_DATABASE_BUSY;
+       }
+
+       ret = _account_db_handle_close(g_hAccountGlobalDB2);
+       if( ret != ACCOUNT_ERROR_NONE )
+               ACCOUNT_DEBUG( "db_util_close(g_hAccountGlobalDB2) fail ret = %d", ret);
+
+       ACCOUNT_DEBUG( "before db_util_open()");
+//     if(mode == ACCOUNT_DB_OPEN_READWRITE)
+//             rc = db_util_open(account_db_path, &g_hAccountDB, DB_UTIL_REGISTER_HOOK_METHOD);
+//     else if(mode == ACCOUNT_DB_OPEN_READONLY)
+       rc = db_util_open_with_options(account_db_path, &g_hAccountGlobalDB, SQLITE_OPEN_READONLY, NULL);
+//     else
+//             return ACCOUNT_ERROR_DB_NOT_OPENED;
+       ACCOUNT_DEBUG( "after db_util_open() sqlite_rc = %d", rc);
+
+       if( rc == SQLITE_PERM || _account_db_err_code_from_global_db() == SQLITE_PERM ) {
+               ACCOUNT_ERROR( "Account permission denied");
+               return ACCOUNT_ERROR_PERMISSION_DENIED;
+       }
+
+       if( rc == SQLITE_BUSY ) {
+               ACCOUNT_ERROR( "busy handler fail.");
+               return ACCOUNT_ERROR_DATABASE_BUSY;
+       }
+
+       if( rc != SQLITE_OK ) {
+               ACCOUNT_ERROR( "The database isn't connected." );
+               return ACCOUNT_ERROR_DB_NOT_OPENED;
+       }
+
+       _INFO( "end _account_global_db_open()");
+       return ACCOUNT_ERROR_NONE;
+}
+
+int _account_global_db_close(void)
+{
+       ACCOUNT_DEBUG( "start account_global_db_close()");
+       int ret = -1;
+/*
+       ret = _account_db_handle_close(g_hAccountGlobalDB2);
+       if( ret != ACCOUNT_ERROR_NONE )
+               ACCOUNT_DEBUG( "db_util_close(g_hAccountGlobalDB2) fail ret = %d", ret);
+*/
+       ret = _account_db_handle_close(g_hAccountGlobalDB);
+       if( ret != ACCOUNT_ERROR_NONE )
+       {
+               ACCOUNT_ERROR( "db_util_close(g_hAccountGlobalDB) fail ret = %d", ret);
+               g_hAccountGlobalDB2 = g_hAccountGlobalDB;
+       }
+       g_hAccountGlobalDB = NULL;
+
+       return ret;
+}
+
 static int _account_check_account_type_with_appid_group(int uid, const char* appid, char** verified_appid)
 {
        int error_code = ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
@@ -310,7 +566,7 @@ static int _account_check_account_type_with_appid_group(int uid, const char* app
        for(iter=appid_list;iter!=NULL;iter=g_slist_next(iter)){
                char* tmp = (char*)iter->data;
                if(tmp) {
-                       if(_account_type_query_app_id_exist(tmp) == ACCOUNT_ERROR_NONE) {
+                       if(_account_type_query_app_id_exist_from_all_db(tmp) == ACCOUNT_ERROR_NONE) {
                                *verified_appid = _account_get_text(tmp);
                                error_code = ACCOUNT_ERROR_NONE;
                                _ACCOUNT_FREE(tmp);
@@ -680,104 +936,95 @@ static bool _account_check_add_more_account(const char* app_id)
 //a) multi-user cases
 //b) to ensure db exist in every connect call
 
-//static int _account_create_all_tables(void)
-//{
-//     int rc = -1;
-//     int error_code = ACCOUNT_ERROR_NONE;
-//     char    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-
-//     ACCOUNT_DEBUG("create all table - BEGIN");
-//     ACCOUNT_MEMSET(query, 0, sizeof(query));
-
-//     /*Create the account table*/
-//     ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_TABLE);
-//     rc = _account_get_record_count(query);
-//     if (rc <= 0) {
-//             rc = _account_execute_query(ACCOUNT_SCHEMA);
-//             if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
-//             ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", ACCOUNT_SCHEMA, rc, _account_db_err_msg()));
-
-//#ifndef _TIZEN_PUBLIC_
-//             if (CSC_FEATURE_BOOL_TRUE == csc_feature_get_bool(CSC_FEATURE_DEF_BOOL_CONTACTS_DOCOMO_SOCIAL_PHONEBOOK)) {
-//                     /* NTT docomo specific area */
-//                     rc = _account_execute_query(DOCOMO_DEFAULT_VAL_INSERT_QUERY);
-//                     if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
-//                     ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", DOCOMO_DEFAULT_VAL_INSERT_QUERY, rc, _account_db_err_msg()));
-//                     /* END of NTT docomo specific area */
-//             }
-//#endif
-//     }
-
-//     /*Create capability table*/
-//     ACCOUNT_MEMSET(query, 0, sizeof(query));
-//     ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", CAPABILITY_TABLE);
-//     rc = _account_get_record_count(query);
-//     if (rc <= 0) {
-//             rc = _account_execute_query(CAPABILITY_SCHEMA);
-//             if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
-//             ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", CAPABILITY_SCHEMA, rc, _account_db_err_msg()));
-//     }
-
-//     /* Create account custom table */
-//     ACCOUNT_MEMSET(query, 0, sizeof(query));
-//     ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_CUSTOM_TABLE);
-//     rc = _account_get_record_count(query);
-//     if (rc <= 0) {
-//             rc = _account_execute_query(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(%s) failed(%d, %s).\n", query, rc, _account_db_err_msg()));
-//     }
-
-//     /* Create account type table */
-//     ACCOUNT_MEMSET(query, 0, sizeof(query));
-//     ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_TYPE_TABLE);
-//     rc = _account_get_record_count(query);
-//     if (rc <= 0) {
-//             rc = _account_execute_query(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(%s) failed(%d, %s).\n", ACCOUNT_TYPE_SCHEMA, rc, _account_db_err_msg()));
-//     }
-
-//     /* Create label table */
-//     ACCOUNT_MEMSET(query, 0, sizeof(query));
-//     ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", LABEL_TABLE);
-//     rc = _account_get_record_count(query);
-//     if (rc <= 0) {
-//             rc = _account_execute_query(LABEL_SCHEMA);
-//             if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
-//             ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", LABEL_SCHEMA, rc, _account_db_err_msg()));
-//     }
-
-//     /* Create account feature table */
-//     ACCOUNT_MEMSET(query, 0, sizeof(query));
-//     ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", PROVIDER_FEATURE_TABLE);
-//     rc = _account_get_record_count(query);
-//     if (rc <= 0) {
-//             rc = _account_execute_query(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(%s) failed(%d, %s).\n", PROVIDER_FEATURE_SCHEMA, rc, _account_db_err_msg()));
-//     }
-
-//     ACCOUNT_DEBUG("create all table - END");
-//     return error_code;
-//}
-
-//static int _account_check_is_all_table_exists()
-//{
-//     int     rc = 0;
-//     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);
-//     rc = _account_get_record_count(query);
-
-//     if (rc != ACCOUNT_TABLE_TOTAL_COUNT) {
-//             ACCOUNT_ERROR("Table count is not matched rc=%d\n", rc);
-//     }
-
-//     return rc;
-//}
+static int _account_create_all_tables(void)
+{
+       int rc = -1;
+       int error_code = ACCOUNT_ERROR_NONE;
+       char    query[ACCOUNT_SQL_LEN_MAX] = {0, };
+
+       _INFO("create all table - BEGIN");
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+
+       /*Create the account table*/
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_TABLE);
+       rc = _account_get_record_count(query);
+       if (rc <= 0) {
+               rc = _account_execute_query(ACCOUNT_SCHEMA);
+               if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", ACCOUNT_SCHEMA, rc, _account_db_err_msg()));
+
+       }
+
+       /*Create capability table*/
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", CAPABILITY_TABLE);
+       rc = _account_get_record_count(query);
+       if (rc <= 0) {
+               rc = _account_execute_query(CAPABILITY_SCHEMA);
+               if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", CAPABILITY_SCHEMA, rc, _account_db_err_msg()));
+       }
+
+       /* Create account custom table */
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_CUSTOM_TABLE);
+       rc = _account_get_record_count(query);
+       if (rc <= 0) {
+               rc = _account_execute_query(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(%s) failed(%d, %s).\n", query, rc, _account_db_err_msg()));
+       }
+
+       /* Create account type table */
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", ACCOUNT_TYPE_TABLE);
+       rc = _account_get_record_count(query);
+       if (rc <= 0) {
+               rc = _account_execute_query(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(%s) failed(%d, %s).\n", ACCOUNT_TYPE_SCHEMA, rc, _account_db_err_msg()));
+       }
+
+       /* Create label table */
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", LABEL_TABLE);
+       rc = _account_get_record_count(query);
+       if (rc <= 0) {
+               rc = _account_execute_query(LABEL_SCHEMA);
+               if(rc == SQLITE_BUSY) return ACCOUNT_ERROR_DATABASE_BUSY;
+               ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(%s) failed(%d, %s).\n", LABEL_SCHEMA, rc, _account_db_err_msg()));
+       }
+
+       /* Create account feature table */
+       ACCOUNT_MEMSET(query, 0, sizeof(query));
+       ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", PROVIDER_FEATURE_TABLE);
+       rc = _account_get_record_count(query);
+       if (rc <= 0) {
+               rc = _account_execute_query(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(%s) failed(%d, %s).\n", PROVIDER_FEATURE_SCHEMA, rc, _account_db_err_msg()));
+       }
+
+       _INFO("create all table - END");
+       return error_code;
+}
+
+static int _account_check_is_all_table_exists()
+{
+       int     rc = 0;
+       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);
+       rc = _account_get_record_count(query);
+
+       if (rc != ACCOUNT_TABLE_TOTAL_COUNT) {
+               ACCOUNT_ERROR("Table count is not matched rc=%d\n", rc);
+       }
+
+       return rc;
+}
 
 int _account_db_handle_close(sqlite3* hDB)
 {
@@ -798,16 +1045,19 @@ int _account_db_handle_close(sqlite3* hDB)
        return ret;
 }
 
-int _account_db_open(int mode, int pid)
+int _account_db_open(int mode, int pid, int uid)
 {
        int  rc = 0;
        int ret = -1;
+       char account_db_dir[256] = {0, };
        char account_db_path[256] = {0, };
 
        _INFO( "start _account_db_open()");
 
+       ACCOUNT_MEMSET(account_db_dir, 0x00, sizeof(account_db_dir));
        ACCOUNT_MEMSET(account_db_path, 0x00, sizeof(account_db_path));
-       ACCOUNT_SNPRINTF(account_db_path, sizeof(account_db_path), "%s", ACCOUNT_DB_PATH);
+
+       ACCOUNT_GET_USER_DB_PATH(account_db_path, sizeof(account_db_path), uid);
 
        if( g_hAccountDB ) {
                _ERR( "Account database is using in another app. %x", g_hAccountDB );
@@ -818,13 +1068,18 @@ int _account_db_open(int mode, int pid)
        if( ret != ACCOUNT_ERROR_NONE )
                ACCOUNT_DEBUG( "db_util_close(g_hAccountDB2) fail ret = %d", ret);
 
+       ACCOUNT_GET_USER_DB_DIR(account_db_dir, sizeof(account_db_dir), uid);
+       if (-1 == access (account_db_dir, F_OK)) {
+               mkdir(account_db_dir, 644);
+       }
+
        ACCOUNT_DEBUG( "before db_util_open()");
-       if(mode == ACCOUNT_DB_OPEN_READWRITE)
+//     if(mode == ACCOUNT_DB_OPEN_READWRITE)
                rc = db_util_open(account_db_path, &g_hAccountDB, DB_UTIL_REGISTER_HOOK_METHOD);
-       else if(mode == ACCOUNT_DB_OPEN_READONLY)
-               rc = db_util_open_with_options(account_db_path, &g_hAccountDB, SQLITE_OPEN_READONLY, NULL);
-       else
-               return ACCOUNT_ERROR_DB_NOT_OPENED;
+//     else if(mode == ACCOUNT_DB_OPEN_READONLY)
+//             rc = db_util_open_with_options(account_db_path, &g_hAccountDB, SQLITE_OPEN_READONLY, NULL);
+//     else
+//             return ACCOUNT_ERROR_DB_NOT_OPENED;
        ACCOUNT_DEBUG( "after db_util_open() sqlite_rc = %d", rc);
 
        if( rc == SQLITE_PERM || _account_db_err_code() == SQLITE_PERM ) {
@@ -842,6 +1097,21 @@ int _account_db_open(int mode, int pid)
                return ACCOUNT_ERROR_DB_NOT_OPENED;
        }
 
+       rc = _account_check_is_all_table_exists();
+
+       if (rc < 0) {
+               _ERR("_account_check_is_all_table_exists rc=[%d]", rc);
+               return rc;
+       } else if (rc == ACCOUNT_TABLE_TOTAL_COUNT) {
+               _INFO("Tables OK");
+       } else {
+               int ret = _account_create_all_tables();
+               if (ret != ACCOUNT_ERROR_NONE) {
+                       _ERR("_account_create_all_tables fail ret=[%d]", ret);
+                       return ret;
+               }
+       }
+
        _INFO( "end _account_db_open()");
        return ACCOUNT_ERROR_NONE;
 }
@@ -980,12 +1250,26 @@ static account_stmt _account_prepare_query(char *query)
        return pStmt;
 }
 
-static int _account_query_bind_int(account_stmt pStmt, int pos, int num)
+static account_stmt _account_prepare_query_from_global_db(char *query)
 {
-       if(!pStmt){
-               ACCOUNT_ERROR("statement is null");
-               return -1;
-       }
+       int                     rc = -1;
+       account_stmt    pStmt = NULL;
+
+       ACCOUNT_RETURN_VAL((query != NULL), {}, NULL, ("query is NULL"));
+
+       rc = sqlite3_prepare_v2(g_hAccountGlobalDB, query, strlen(query), &pStmt, NULL);
+
+       ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, NULL, ("sqlite3_prepare_v2(%s) failed(%s).", query, _account_db_err_msg_from_global_db()));
+
+       return pStmt;
+}
+
+static int _account_query_bind_int(account_stmt pStmt, int pos, int num)
+{
+       if(!pStmt){
+               ACCOUNT_ERROR("statement is null");
+               return -1;
+       }
 
        if(pos < 0){
                ACCOUNT_ERROR("invalid pos");
@@ -1108,6 +1392,27 @@ static int _account_query_finalize(account_stmt pStmt)
        return ACCOUNT_ERROR_NONE;
 }
 
+static int _account_query_finalize_from_global_db(account_stmt pStmt)
+{
+       int rc = -1;
+
+       if (!pStmt) {
+               ACCOUNT_ERROR( "pStmt is NULL");
+               return ACCOUNT_ERROR_INVALID_PARAMETER;
+       }
+
+       rc = sqlite3_finalize(pStmt);
+       if (rc == SQLITE_BUSY){
+               ACCOUNT_ERROR(" sqlite3 busy = %d", rc);
+               return ACCOUNT_ERROR_DATABASE_BUSY;
+       } else if (rc != SQLITE_OK) {
+               ACCOUNT_ERROR( "sqlite3_finalize fail, rc : %d, db_error : %s\n", rc, _account_db_err_msg_from_global_db());
+               return ACCOUNT_ERROR_DB_FAILED;
+       }
+
+       return ACCOUNT_ERROR_NONE;
+}
+
 static int _account_query_step(account_stmt pStmt)
 {
        if(!pStmt){
@@ -4493,16 +4798,88 @@ static void _account_type_convert_column_to_provider_feature(account_stmt hstmt,
 
 }
 
-GSList* _account_type_query_provider_feature_by_app_id(const char* app_id, int *error_code)
+GSList* _account_type_query_provider_feature_by_app_id_from_global_db(const char* app_id, int *error_code)
 {
-       _INFO("_account_type_query_provider_feature_by_app_id");
+       _INFO("_account_type_query_provider_feature_by_app_id_in_global_db app_id=%s", app_id);
+       account_stmt hstmt = NULL;
+       char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int rc = 0, binding_count = 1;
+       GSList* feature_list = NULL;
+
+       ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((error_code != NULL), {_ERR("error_code pointer is NULL");}, NULL, (""));
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER; _ERR("The database isn't connected.");}, NULL, ("The database isn't connected."));
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
+       _INFO("account query=[%s]", query);
+
+       hstmt = _account_prepare_query_from_global_db(query);
+
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+               *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+               return NULL;
+       }
+
+       _INFO("before _account_query_bind_text");
+       _account_query_bind_text(hstmt, binding_count++, app_id);
+
+       rc = _account_query_step(hstmt);
+
+       ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {*error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from global db. rc=[%d]", rc);}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+       provider_feature_s* feature_record = NULL;
+
+       while (rc == SQLITE_ROW) {
+
+               feature_record = (provider_feature_s*) malloc(sizeof(provider_feature_s));
+
+               if (feature_record == NULL) {
+                       ACCOUNT_FATAL("malloc Failed");
+                       break;
+               }
+
+               ACCOUNT_MEMSET(feature_record, 0x00, sizeof(provider_feature_s));
+
+               _account_type_convert_column_to_provider_feature(hstmt, feature_record);
+
+               _INFO("Adding account feature_list");
+               feature_list = g_slist_append(feature_list, feature_record);
+
+               rc = _account_query_step(hstmt);
+       }
+
        *error_code = ACCOUNT_ERROR_NONE;
-       account_stmt    hstmt = NULL;
-       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0, binding_count = 1;
+
+CATCH:
+       if (hstmt != NULL) {
+               rc = _account_query_finalize_from_global_db(hstmt);
+               if (rc != ACCOUNT_ERROR_NONE) {
+                       *error_code = rc;
+                       _ERR("global db fianlize error");
+               }
+       }
+
+       if (*error_code != ACCOUNT_ERROR_NONE) {
+               _account_type_gslist_feature_free(feature_list);
+       }
+
+       _INFO("Returning account feature_list from global db");
+       return feature_list;
+}
+
+GSList* _account_type_query_provider_feature_by_app_id(const char* app_id, int *error_code)
+{
+       _INFO("_account_type_query_provider_feature_by_app_id app_id=%s", app_id);
+       account_stmt hstmt = NULL;
+       char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int rc = 0, binding_count = 1;
        GSList* feature_list = NULL;
 
        ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((error_code != NULL), {_ERR("error_code pointer is NULL");}, NULL, (""));
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
@@ -4521,7 +4898,8 @@ GSList* _account_type_query_provider_feature_by_app_id(const char* app_id, int *
        _account_query_bind_text(hstmt, binding_count++, app_id);
 
        rc = _account_query_step(hstmt);
-       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {*error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;}, NULL, ("The record isn't found.\n"));
+
+       ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {*error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND; _ERR("The record isn't found from user db. rc=[%d]", rc);}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
 
        provider_feature_s* feature_record = NULL;
 
@@ -4544,32 +4922,109 @@ GSList* _account_type_query_provider_feature_by_app_id(const char* app_id, int *
                rc = _account_query_step(hstmt);
        }
 
+       *error_code = ACCOUNT_ERROR_NONE;
+
        rc = _account_query_finalize(hstmt);
-       ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("account finalize error"));
+       ACCOUNT_CATCH_ERROR_P((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, rc, ("account finalize error"));
        hstmt = NULL;
 
-       *error_code = ACCOUNT_ERROR_NONE;
-
 CATCH:
        if (hstmt != NULL) {
                rc = _account_query_finalize(hstmt);
-               ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("account finalize error"));
+               if (rc != ACCOUNT_ERROR_NONE) {
+                       *error_code = rc;
+                       _ERR("account fianlize error");
+               }
                hstmt = NULL;
        }
+       _INFO("*error_code=[%d]", *error_code);
 
-       pthread_mutex_unlock(&account_mutex);
+       if (*error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               feature_list = _account_type_query_provider_feature_by_app_id_from_global_db(app_id, error_code);
+       }
+
+       if (*error_code != ACCOUNT_ERROR_NONE)
+               _account_type_gslist_feature_free(feature_list);
 
        _INFO("Returning account feature_list");
        return feature_list;
 }
 
-int account_type_query_provider_feature_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
+int _account_type_query_provider_feature_cb_by_app_id_from_global_db(provider_feature_cb callback, const char* app_id, void *user_data )
+{
+       int                     error_code = ACCOUNT_ERROR_NONE;
+       account_stmt    hstmt = NULL;
+       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int                     rc = 0, binding_count = 1;
+
+       _INFO("_account_type_query_provider_feature_cb_by_app_id_in_global_db start app_id=%s", app_id);
+       ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE app_id = ?", PROVIDER_FEATURE_TABLE);
+       hstmt = _account_prepare_query_from_global_db(query);
+
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
+               ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_PERMISSION_DENIED, ("global db permission denied.\n"));
+       }
+
+       _account_query_bind_text(hstmt, binding_count++, app_id);
+
+       rc = _account_query_step(hstmt);
+       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {_ERR("The record isn't found. rc=[%d]", rc);}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+       provider_feature_s* feature_record = NULL;
+
+       while (rc == SQLITE_ROW) {
+               bool cb_ret = FALSE;
+               feature_record = (provider_feature_s*) malloc(sizeof(provider_feature_s));
+
+               if (feature_record == NULL) {
+                       ACCOUNT_FATAL("malloc Failed");
+                       break;
+               }
+
+               ACCOUNT_MEMSET(feature_record, 0x00, sizeof(provider_feature_s));
+
+               _account_type_convert_column_to_provider_feature(hstmt, feature_record);
+
+               cb_ret = callback(feature_record->app_id, feature_record->key, user_data);
+
+               _account_type_free_feature_with_items(feature_record);
+
+               ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returns FALSE, its iteration is stopped!!!!\n"));
+
+               rc = _account_query_step(hstmt);
+       }
+
+       error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+       if (hstmt != NULL) {
+               rc = _account_query_finalize_from_global_db(hstmt);
+               if (rc != ACCOUNT_ERROR_NONE) {
+                       error_code = rc;
+                       _ERR("global db finalize error[%d]", rc);
+               }
+               hstmt = NULL;
+       }
+
+       _INFO("_account_type_query_provider_feature_cb_by_app_id_in_global_db end. error_code=[%d]", error_code);
+       return error_code;
+}
+
+int _account_type_query_provider_feature_cb_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
 {
        int                     error_code = ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                     rc = 0, binding_count = 1;
 
+       _INFO("_account_type_query_provider_feature_cb_by_app_id start app_id=%s", app_id);
        ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
        ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
@@ -4587,7 +5042,7 @@ int account_type_query_provider_feature_by_app_id(provider_feature_cb callback,
        _account_query_bind_text(hstmt, binding_count++, app_id);
 
        rc = _account_query_step(hstmt);
-       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found in user db.\n"));
 
        provider_feature_s* feature_record = NULL;
 
@@ -4625,19 +5080,41 @@ CATCH:
                ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
                hstmt = NULL;
        }
+/*
+       if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               error_code = _account_type_query_provider_feature_cb_by_app_id_from_global_db(callback, app_id, user_data);
+       }
+*/
+       _INFO("_account_type_query_provider_feature_cb_by_app_id end");
+       return error_code;
+}
+
+int account_type_query_provider_feature_cb_by_app_id(provider_feature_cb callback, const char* app_id, void *user_data )
+{
+       int                     error_code = ACCOUNT_ERROR_NONE;
+
+       ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+       error_code = _account_type_query_provider_feature_cb_by_app_id(callback, app_id, user_data);
+
+       if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               error_code = _account_type_query_provider_feature_cb_by_app_id_from_global_db(callback, app_id, user_data);
+       }
 
-       pthread_mutex_unlock(&account_mutex);
        return error_code;
 }
 
-bool _account_type_query_supported_feature(const char* app_id, const char* capability, int *error_code)
+bool _account_type_query_supported_feature_from_global_db(const char* app_id, const char* capability, int *error_code)
 {
-       _INFO("_account_type_query_supported_feature start");
+       _INFO("_account_type_query_supported_feature_in_global_db start");
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
 
        *error_code = ACCOUNT_ERROR_NONE;
 
-       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     record_count = 0;
+       char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int record_count = 0;
 
        if (app_id == NULL || capability == NULL)
        {
@@ -4647,12 +5124,11 @@ bool _account_type_query_supported_feature(const char* app_id, const char* capab
 
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s where app_id='%s' and key='%s'", PROVIDER_FEATURE_TABLE, app_id, capability);
 
-       record_count = _account_get_record_count(query);
+       record_count = _account_get_record_count_from_global_db(query);
 
-       if( _account_db_err_code() == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
                *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
-               return false;
        }
 
        if (record_count <= 0)
@@ -4661,66 +5137,45 @@ bool _account_type_query_supported_feature(const char* app_id, const char* capab
                return false;
        }
 
-       _INFO("_account_type_query_supported_feature end");
+       _INFO("_account_type_query_supported_feature_in_global_db end");
        return true;
-
 }
 
-
-int account_type_get_provider_feature_all(account_type_h account_type, provider_feature_cb callback, void* user_data)
+bool _account_type_query_supported_feature(const char* app_id, const char* capability, int *error_code)
 {
-       ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT HANDLE IS NULL"));
-       ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
-
-       GSList *iter;
-       account_type_s *data = (account_type_s*)account_type;
+       _INFO("_account_type_query_supported_feature start");
 
-       for (iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
-               provider_feature_s *feature_data = NULL;
+       *error_code = ACCOUNT_ERROR_NONE;
 
-               feature_data = (provider_feature_s*)iter->data;
+       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int                     record_count = 0;
 
-               if(callback(feature_data->app_id, feature_data->key, user_data)!=TRUE) {
-                       ACCOUNT_DEBUG("Callback func returs FALSE, its iteration is stopped!!!!\n");
-                       return ACCOUNT_ERROR_NONE;
-               }
+       if (app_id == NULL || capability == NULL)
+       {
+               *error_code = ACCOUNT_ERROR_INVALID_PARAMETER;
+               return false;
        }
 
-       return ACCOUNT_ERROR_NONE;
-}
-
-int account_type_set_provider_feature(account_type_h account_type, const char* provider_feature)
-{
-       ACCOUNT_RETURN_VAL((account_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("account type handle is null"));
-       ACCOUNT_RETURN_VAL((provider_feature != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("provider_feature is null"));
-
-       account_type_s *data = (account_type_s*)account_type;
-
-       GSList *iter = NULL;
-       bool b_is_new = TRUE;
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s where app_id='%s' and key='%s'", PROVIDER_FEATURE_TABLE, app_id, capability);
 
-       for(iter = data->provider_feature_list; iter != NULL; iter = g_slist_next(iter)) {
-               provider_feature_s *feature_data = NULL;
-               feature_data = (provider_feature_s*)iter->data;
+       record_count = _account_get_record_count(query);
 
-               if(!strcmp(feature_data->key, provider_feature)) {
-                       b_is_new = FALSE;
-                       break;
-               }
+       if( _account_db_err_code() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+               *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+               return false;
        }
 
-       if(b_is_new) {
-               provider_feature_s* feature_data = (provider_feature_s*)malloc(sizeof(provider_feature_s));
-
-               if (feature_data == NULL)
-                       return ACCOUNT_ERROR_OUT_OF_MEMORY;
-               ACCOUNT_MEMSET(feature_data, 0, sizeof(provider_feature_s));
-
-               feature_data->key = _account_get_text(provider_feature);
-               data->provider_feature_list = g_slist_append(data->provider_feature_list, (gpointer)feature_data);
+       if (record_count <= 0)
+       {
+               bool is_exist = false;
+               is_exist = _account_type_query_supported_feature_from_global_db(app_id, capability, error_code);
+               if (!is_exist)
+                       return false;
        }
 
-       return ACCOUNT_ERROR_NONE;
+       _INFO("_account_type_query_supported_feature end");
+       return true;
 }
 
 static int _account_type_insert_provider_feature(account_type_s *account_type, const char* app_id)
@@ -5246,7 +5701,7 @@ static void _account_type_convert_column_to_label(account_stmt hstmt, label_s *l
 
 }
 
-GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_code )
+GSList* _account_type_get_label_list_by_app_id_from_global_db(const char* app_id, int *error_code )
 {
        *error_code = ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
@@ -5255,23 +5710,24 @@ GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_co
        GSList* label_list = NULL;
 
        ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
-       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
 
        ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
-       hstmt = _account_prepare_query(query);
+       hstmt = _account_prepare_query_from_global_db(query);
 
-       if( _account_db_err_code() == SQLITE_PERM ){
-               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
                *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
-               return NULL;
+
+               goto CATCH;
        }
 
        _account_query_bind_text(hstmt, binding_count++, app_id);
 
        rc = _account_query_step(hstmt);
-       ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+       ACCOUNT_CATCH_ERROR_P((rc == SQLITE_ROW), {_ERR("The record isn't found. rc=[%d] done", rc);}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
 
        label_s* label_record = NULL;
 
@@ -5293,27 +5749,160 @@ GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_co
                rc = _account_query_step(hstmt);
        }
 
-       rc = _account_query_finalize(hstmt);
-       ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
-       hstmt = NULL;
-
        *error_code = ACCOUNT_ERROR_NONE;
 
 CATCH:
        if (hstmt != NULL) {
-               rc = _account_query_finalize(hstmt);
-               ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+               rc = _account_query_finalize_from_global_db(hstmt);
+               if (rc != ACCOUNT_ERROR_NONE) {
+                       _ERR("global db finalize error[%d]", rc);
+               }
                hstmt = NULL;
        }
 
-       pthread_mutex_unlock(&account_mutex);
-       _INFO("Returning account label_list");
+       _INFO("Returning account global label_list");
        return label_list;
 }
 
-int account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
+GSList* _account_type_get_label_list_by_app_id(const char* app_id, int *error_code )
 {
-       int                     error_code = ACCOUNT_ERROR_NONE;
+       *error_code = ACCOUNT_ERROR_NONE;
+       account_stmt    hstmt = NULL;
+       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int                     rc = 0, binding_count = 1;
+       GSList* label_list = NULL;
+
+       ACCOUNT_RETURN_VAL((app_id != NULL), {*error_code = ACCOUNT_ERROR_INVALID_PARAMETER;}, NULL, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {*error_code = ACCOUNT_ERROR_DB_NOT_OPENED;}, NULL, ("The database isn't connected."));
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
+       hstmt = _account_prepare_query(query);
+
+       if( _account_db_err_code() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg());
+               *error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+               return NULL;
+       }
+
+       _account_query_bind_text(hstmt, binding_count++, app_id);
+
+       rc = _account_query_step(hstmt);
+       ACCOUNT_CATCH_ERROR_P(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+       label_s* label_record = NULL;
+
+       while (rc == SQLITE_ROW) {
+               label_record = (label_s*) malloc(sizeof(label_s));
+
+               if (label_record == NULL) {
+                       ACCOUNT_FATAL("malloc Failed");
+                       break;
+               }
+
+               ACCOUNT_MEMSET(label_record, 0x00, sizeof(label_s));
+
+               _account_type_convert_column_to_label(hstmt, label_record);
+
+               _INFO("Adding account label_list");
+               label_list = g_slist_append (label_list, label_record);
+
+               rc = _account_query_step(hstmt);
+       }
+
+       rc = _account_query_finalize(hstmt);
+       ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+       hstmt = NULL;
+
+       *error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+       if (hstmt != NULL) {
+               rc = _account_query_finalize(hstmt);
+               ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {*error_code = rc;}, NULL, ("finalize error"));
+               hstmt = NULL;
+       }
+
+       if (*error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               label_list = _account_type_get_label_list_by_app_id_from_global_db(app_id, error_code);
+       }
+
+       _INFO("Returning account label_list");
+       return label_list;
+}
+
+int _account_type_query_label_by_app_id_from_global_db(account_label_cb callback, const char* app_id, void *user_data )
+{
+       int                     error_code = ACCOUNT_ERROR_NONE;
+       account_stmt    hstmt = NULL;
+       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int                     rc = 0, binding_count = 1;
+
+       _INFO("account_type_query_label_by_app_id_from_global_db start");
+
+       ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", LABEL_TABLE);
+       hstmt = _account_prepare_query_from_global_db(query);
+
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
+               error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+               goto CATCH;
+       }
+
+       _account_query_bind_text(hstmt, binding_count++, app_id);
+
+       rc = _account_query_step(hstmt);
+       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+       label_s* label_record = NULL;
+
+       while (rc == SQLITE_ROW) {
+               bool cb_ret = FALSE;
+               label_record = (label_s*) malloc(sizeof(label_s));
+
+               if (label_record == NULL) {
+                       ACCOUNT_FATAL("malloc Failed");
+                       break;
+               }
+
+               ACCOUNT_MEMSET(label_record, 0x00, sizeof(label_s));
+
+               _account_type_convert_column_to_label(hstmt, label_record);
+
+               cb_ret = callback(label_record->app_id, label_record->label , label_record->locale, user_data);
+
+               _account_type_free_label_with_items(label_record);
+
+               ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
+
+               rc = _account_query_step(hstmt);
+       }
+
+       error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+       if (hstmt != NULL) {
+               rc = _account_query_finalize_from_global_db(hstmt);
+               if (rc != ACCOUNT_ERROR_NONE) {
+                       _ERR("global db finalize error[%d]", rc);
+               }
+               hstmt = NULL;
+       }
+
+       _INFO("account_type_query_label_by_app_id_from_global_db end [%d]", error_code);
+       return error_code;
+}
+
+int _account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
+{
+       int                     error_code = ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                     rc = 0, binding_count = 1;
@@ -5356,7 +5945,11 @@ int account_type_query_label_by_app_id(account_label_cb callback, const char* ap
 
                _account_type_free_label_with_items(label_record);
 
-               ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
+//             ACCOUNT_CATCH_ERROR(cb_ret == TRUE, {}, ACCOUNT_ERROR_NONE, ("Callback func returs FALSE, its iteration is stopped!!!!\n"));
+               if(cb_ret == TRUE) {
+                       _INFO("Callback func returs FALSE, its iteration is stopped!!!!\n");
+                       break;
+               }
 
                rc = _account_query_step(hstmt);
        }
@@ -5373,8 +5966,28 @@ CATCH:
                ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
                hstmt = NULL;
        }
+/*
+       if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               error_code = account_type_query_label_by_app_id_from_global_db(callback, app_id, user_data);
+       }
+*/
+       return error_code;
+}
+
+int account_type_query_label_by_app_id(account_label_cb callback, const char* app_id, void *user_data )
+{
+       int                     error_code = ACCOUNT_ERROR_NONE;
+
+       ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO CALLBACK FUNCTION"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+       error_code = _account_type_query_label_by_app_id(callback, app_id, user_data);
+
+       if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               error_code = _account_type_query_label_by_app_id_from_global_db(callback, app_id, user_data);
+       }
 
-       pthread_mutex_unlock(&account_mutex);
        return error_code;
 }
 
@@ -5438,6 +6051,60 @@ bool _account_get_provider_feature_cb(char* app_id, char* key, void* user_data)
        return TRUE;
 }
 
+int _account_type_query_by_app_id_from_global_db(const char* app_id, account_type_s** account_type_record)
+{
+       _INFO("_account_type_query_by_app_id_from_global_db start");
+
+       int                     error_code = ACCOUNT_ERROR_NONE;
+       account_stmt    hstmt = NULL;
+       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int                     rc = 0, binding_count = 1;
+
+       ACCOUNT_RETURN_VAL((app_id != 0), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("APP ID IS NULL"));
+       ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ?", ACCOUNT_TYPE_TABLE);
+       hstmt = _account_prepare_query_from_global_db(query);
+
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
+               return ACCOUNT_ERROR_PERMISSION_DENIED;
+       }
+
+       _account_query_bind_text(hstmt, binding_count++, app_id);
+
+       rc = _account_query_step(hstmt);
+       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+       *account_type_record = create_empty_account_type_instance();
+
+       while (rc == SQLITE_ROW) {
+               _account_type_convert_column_to_account_type(hstmt, *account_type_record);
+               rc = _account_query_step(hstmt);
+       }
+
+       rc = _account_query_finalize_from_global_db(hstmt);
+       ACCOUNT_CATCH_ERROR((rc == ACCOUNT_ERROR_NONE), {_ERR("global db finalize error rc=[%d]", rc);}, rc, ("finalize error"));
+       _account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb, app_id, (void*)(*account_type_record));
+       _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, app_id,(void*)(*account_type_record));
+
+       hstmt = NULL;
+       error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+       if (hstmt != NULL) {
+               rc = _account_query_finalize(hstmt);
+               ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+               hstmt = NULL;
+       }
+
+       _INFO("_account_type_query_by_app_id_from_global_db end [%d]", error_code);
+       return error_code;
+}
+
 int _account_type_query_by_app_id(const char* app_id, account_type_s** account_type_record)
 {
        _INFO("_account_type_query_by_app_id start");
@@ -5480,8 +6147,8 @@ int _account_type_query_by_app_id(const char* app_id, account_type_s** account_t
 
        rc = _account_query_finalize(hstmt);
        ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
-       account_type_query_label_by_app_id(_account_get_label_text_cb, app_id, (void*)(*account_type_record));
-       account_type_query_provider_feature_by_app_id(_account_get_provider_feature_cb, app_id,(void*)(*account_type_record));
+       _account_type_query_label_by_app_id(_account_get_label_text_cb, app_id, (void*)(*account_type_record));
+       _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, app_id,(void*)(*account_type_record));
 
        hstmt = NULL;
        error_code = ACCOUNT_ERROR_NONE;
@@ -5493,7 +6160,10 @@ CATCH:
                hstmt = NULL;
        }
 
-       pthread_mutex_unlock(&account_mutex);
+       if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               error_code = _account_type_query_by_app_id_from_global_db(app_id, account_type_record);
+       }
+
        _INFO("_account_type_query_by_app_id end [%d]", error_code);
        return error_code;
 }
@@ -5523,14 +6193,140 @@ int _account_type_query_app_id_exist(const char* app_id)
        return ACCOUNT_ERROR_NONE;
 }
 
-GSList* _account_type_query_by_provider_feature(const char* key, int *error_code)
+int _account_type_query_app_id_exist_from_all_db(const char *app_id)
 {
-       *error_code = ACCOUNT_ERROR_NONE;
+       _INFO("_account_type_query_app_id_exist_from_all_db start app_id=%s", app_id);
+       int return_code = ACCOUNT_ERROR_NONE;
+
+       return_code = _account_type_query_app_id_exist(app_id);
+
+       if (return_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               return_code = _account_type_query_app_id_exist_from_global_db(app_id);
+       } else {
+               return return_code;
+       }
+       _INFO("_account_type_query_app_id_exist_from_all_db end");
+       return return_code;
+}
+
+int _account_type_query_by_provider_feature_from_global_db(const char* key, GSList **account_type_list_all)
+{
+       int error_code = ACCOUNT_ERROR_NONE;
        account_stmt    hstmt = NULL;
        char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
        int                     rc = 0;
        GSList                  *account_type_list = NULL;
 
+       _INFO("_account_type_query_by_provider_feature_from_global_db start key=%s", key);
+       if(key == NULL)
+       {
+               ACCOUNT_ERROR("capability_type IS NULL.");
+               error_code = ACCOUNT_ERROR_INVALID_PARAMETER;
+               goto CATCH;
+       }
+
+       if(g_hAccountGlobalDB == NULL)
+       {
+               ACCOUNT_ERROR("The database isn't connected.");
+               error_code = ACCOUNT_ERROR_DB_NOT_OPENED;
+               goto CATCH;
+       }
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId IN (SELECT app_id from %s WHERE key=?)", ACCOUNT_TYPE_TABLE, PROVIDER_FEATURE_TABLE);
+
+       hstmt = _account_prepare_query_from_global_db(query);
+
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM )
+       {
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
+               error_code = ACCOUNT_ERROR_PERMISSION_DENIED;
+               goto CATCH;
+       }
+
+       int binding_count = 1;
+       _account_query_bind_text(hstmt, binding_count++, key);
+
+       rc = _account_query_step(hstmt);
+
+       account_type_s *account_type_record = NULL;
+
+       if(rc != SQLITE_ROW)
+       {
+               ACCOUNT_ERROR("The record isn't found. rc=[%d]", rc);
+               error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
+               goto CATCH;
+       }
+
+       while(rc == SQLITE_ROW) {
+               account_type_record = (account_type_s*) malloc(sizeof(account_type_s));
+
+               if (account_type_record == NULL) {
+                       ACCOUNT_FATAL("malloc Failed");
+                       break;
+               }
+
+               ACCOUNT_MEMSET(account_type_record, 0x00, sizeof(account_type_s));
+               _account_type_convert_column_to_account_type(hstmt, account_type_record);
+               account_type_list = g_slist_append(account_type_list, account_type_record);
+               rc = _account_query_step(hstmt);
+       }
+
+       rc = _account_query_finalize_from_global_db(hstmt);
+       if (rc != ACCOUNT_ERROR_NONE )
+       {
+               _account_type_gslist_account_type_free(account_type_list);
+               ACCOUNT_ERROR("finalize error(%s)", rc);
+               error_code = rc;
+               goto CATCH;
+       }
+       hstmt = NULL;
+
+       GSList* iter;
+
+       for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
+               account_type_s *account_type = NULL;
+               account_type = (account_type_s*)iter->data;
+               _account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
+               _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+               _INFO("add label & provider_feature");
+       }
+
+       for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
+
+               account_type_s *account_type = NULL;
+               account_type = (account_type_s*)iter->data;
+               *account_type_list_all = g_slist_append(*account_type_list_all, account_type);
+               _INFO("add account_type");
+       }
+
+       error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+       if (hstmt != NULL) {
+               rc = _account_query_finalize_from_global_db(hstmt);
+               if (rc != ACCOUNT_ERROR_NONE)
+               {
+                       ACCOUNT_ERROR("finalize error(%s)", rc);
+                       return rc;
+               }
+               hstmt = NULL;
+       }
+
+       _INFO("_account_type_query_by_provider_feature_from_global_db end. error_code=[%d]", error_code);
+       return error_code;
+}
+
+GSList* _account_type_query_by_provider_feature(const char* key, int *error_code)
+{
+       *error_code = ACCOUNT_ERROR_NONE;
+       account_stmt hstmt = NULL;
+       char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int rc = 0;
+       GSList *account_type_list = NULL;
+
+       _INFO("account_type_query_by_provider_feature start key=%s", key);
        if(key == NULL)
        {
                ACCOUNT_ERROR("capability_type IS NULL.");
@@ -5567,7 +6363,7 @@ GSList* _account_type_query_by_provider_feature(const char* key, int *error_code
 
        if(rc != SQLITE_ROW)
        {
-               ACCOUNT_ERROR("The record isn't found.");
+               ACCOUNT_ERROR("The record isn't found. rc=[%d]", rc);
                *error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
                goto CATCH;
        }
@@ -5601,8 +6397,8 @@ GSList* _account_type_query_by_provider_feature(const char* key, int *error_code
        for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
                account_type_s *account_type = NULL;
                account_type = (account_type_s*)iter->data;
-               account_type_query_label_by_app_id(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
-               account_type_query_provider_feature_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+               _account_type_query_label_by_app_id(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
+               _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
        }
 
        *error_code = ACCOUNT_ERROR_NONE;
@@ -5618,17 +6414,108 @@ CATCH:
                hstmt = NULL;
        }
 
+       if (*error_code == ACCOUNT_ERROR_NONE || *error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               rc = _account_type_query_by_provider_feature_from_global_db(key, &account_type_list);
+               if (rc != ACCOUNT_ERROR_NONE && rc != ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+                       ACCOUNT_ERROR( "_account_type_query_by_provider_feature_from_global_db fail=[%d]", rc);
+                       _account_type_gslist_account_type_free(account_type_list);
+                       return NULL;
+               }
+               if (rc == ACCOUNT_ERROR_NONE)
+                       *error_code = rc;
+       }
+
+       _INFO("account_type_query_by_provider_feature end");
        return account_type_list;
 }
 
+int _account_type_query_all_from_global_db(GSList **account_type_list_all)
+{
+       account_stmt    hstmt = NULL;
+       char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int rc = ACCOUNT_ERROR_NONE;
+       int error_code = ACCOUNT_ERROR_NONE;
+       GSList *account_type_list = NULL;
+
+       _INFO("_account_type_query_all_in_global_db start");
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, NULL, ("The database isn't connected."));
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s ", ACCOUNT_TYPE_TABLE);
+       hstmt = _account_prepare_query_from_global_db(query);
+
+       rc = _account_query_step(hstmt);
+
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
+               return ACCOUNT_ERROR_PERMISSION_DENIED;
+       }
+
+       account_type_s *account_type_record = NULL;
+
+       if (rc != SQLITE_ROW)
+       {
+               _INFO("[ACCOUNT_ERROR_RECORD_NOT_FOUND]The record isn't found.");
+               error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
+               goto CATCH;
+       }
+
+       while(rc == SQLITE_ROW) {
+               account_type_record = (account_type_s*) malloc(sizeof(account_type_s));
+
+               if (account_type_record == NULL) {
+                       ACCOUNT_FATAL("malloc Failed");
+                       break;
+               }
+
+               ACCOUNT_MEMSET(account_type_record, 0x00, sizeof(account_type_s));
+               _account_type_convert_column_to_account_type(hstmt, account_type_record);
+               account_type_list = g_slist_append(account_type_list, account_type_record);
+               rc = _account_query_step(hstmt);
+       }
+
+       rc = _account_query_finalize_from_global_db(hstmt);
+       ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+       hstmt = NULL;
+
+       GSList* iter;
+
+       for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
+               account_type_s *account_type = NULL;
+               account_type = (account_type_s*)iter->data;
+               _account_type_query_label_by_app_id_from_global_db(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
+               _account_type_query_provider_feature_cb_by_app_id_from_global_db(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+       }
+
+       for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
+               account_type_s *account_type = NULL;
+               account_type = (account_type_s*)iter->data;
+               *account_type_list_all = g_slist_append(*account_type_list_all, account_type);
+       }
+
+       error_code = ACCOUNT_ERROR_NONE;
+CATCH:
+       if (hstmt != NULL)
+       {
+               rc = _account_query_finalize_from_global_db(hstmt);
+               ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {_account_type_gslist_account_type_free(account_type_list);}, rc, ("finalize error"));
+               hstmt = NULL;
+       }
+
+       _INFO("_account_type_query_all_in_global_db end");
+       return error_code;
+}
 
 GSList* _account_type_query_all(void)
 {
-       account_stmt    hstmt = NULL;
-       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
-       int                     rc = 0;
-       GSList                  *account_type_list = NULL;
+       account_stmt hstmt = NULL;
+       char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int rc = 0;
+       int error_code = ACCOUNT_ERROR_NONE;
+       GSList *account_type_list = NULL;
 
+       _INFO("_account_type_query_all start");
        ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, NULL, ("The database isn't connected."));
 
        ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
@@ -5648,6 +6535,7 @@ GSList* _account_type_query_all(void)
        if (rc != SQLITE_ROW)
        {
                _INFO("[ACCOUNT_ERROR_RECORD_NOT_FOUND]The record isn't found.");
+               error_code = ACCOUNT_ERROR_RECORD_NOT_FOUND;
                goto CATCH;
        }
 
@@ -5674,10 +6562,11 @@ GSList* _account_type_query_all(void)
        for (iter = account_type_list; iter != NULL; iter = g_slist_next(iter)) {
                account_type_s *account_type = NULL;
                account_type = (account_type_s*)iter->data;
-               account_type_query_label_by_app_id(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
-               account_type_query_provider_feature_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
+               _account_type_query_label_by_app_id(_account_get_label_text_cb,account_type->app_id,(void*)account_type);
+               _account_type_query_provider_feature_cb_by_app_id(_account_get_provider_feature_cb, account_type->app_id,(void*)account_type);
        }
 
+       error_code = ACCOUNT_ERROR_NONE;
 CATCH:
        if (hstmt != NULL)
        {
@@ -5686,10 +6575,107 @@ CATCH:
                hstmt = NULL;
        }
 
+       if (error_code == ACCOUNT_ERROR_NONE || error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               error_code = _account_type_query_all_from_global_db(&account_type_list);
+               if (rc != ACCOUNT_ERROR_NONE && rc != ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+                       ACCOUNT_ERROR( "_account_type_query_all_from_global_db fail=[%d]", rc);
+                       _account_type_gslist_account_type_free(account_type_list);
+                       return NULL;
+               }
+       }
+
+       _INFO("_account_type_query_all end");
        return account_type_list;
 }
 
 // output parameter label must be free
+int _account_type_query_label_by_locale_from_global_db(const char* app_id, const char* locale, char **label)
+{
+       int                     error_code = ACCOUNT_ERROR_NONE;
+       account_stmt    hstmt = NULL;
+       char                    query[ACCOUNT_SQL_LEN_MAX] = {0, };
+       int                     rc = 0, binding_count = 1;
+       char*                   converted_locale = NULL;
+
+       ACCOUNT_RETURN_VAL((app_id != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("NO APP ID"));
+       ACCOUNT_RETURN_VAL((g_hAccountGlobalDB != NULL), {}, ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+       ACCOUNT_RETURN_VAL((label != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("label char is null"));
+       ACCOUNT_RETURN_VAL((locale != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("locale char is null"));
+       //Making label newly created
+
+       ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+
+       converted_locale = _account_get_text(locale);
+       gchar** tokens = g_strsplit(converted_locale, "-", 2);
+
+       if(tokens != NULL) {
+               if((char*)(tokens[1]) != NULL) {
+                       char* upper_token = g_ascii_strup(tokens[1], strlen(tokens[1]));
+                       if(upper_token != NULL) {
+                               _ACCOUNT_FREE(converted_locale);
+                               converted_locale = g_strdup_printf("%s_%s", tokens[0], upper_token);
+                       }
+                       _ACCOUNT_FREE(upper_token);
+               }
+       }
+       g_strfreev(tokens);
+
+       ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE AppId = ? AND Locale = '%s' ", LABEL_TABLE, converted_locale);
+       _ACCOUNT_FREE(converted_locale);
+
+       hstmt = _account_prepare_query_from_global_db(query);
+
+       if( _account_db_err_code_from_global_db() == SQLITE_PERM ){
+               ACCOUNT_ERROR( "Access failed(%s)", _account_db_err_msg_from_global_db());
+               return ACCOUNT_ERROR_PERMISSION_DENIED;
+       }
+
+       _account_query_bind_text(hstmt, binding_count++, app_id);
+
+       rc = _account_query_step(hstmt);
+       ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+       label_s* label_record = NULL;
+
+       while (rc == SQLITE_ROW) {
+               label_record = (label_s*) malloc(sizeof(label_s));
+
+               if (label_record == NULL) {
+                       ACCOUNT_FATAL("malloc Failed");
+                       break;
+               }
+
+               ACCOUNT_MEMSET(label_record, 0x00, sizeof(label_s));
+
+               _account_type_convert_column_to_label(hstmt,label_record);
+
+               _ACCOUNT_FREE(*label);
+               //Making label newly created
+               *label = _account_get_text(label_record->label);
+
+               _account_type_free_label_with_items(label_record);
+
+               rc = _account_query_step(hstmt);
+       }
+
+       rc = _account_query_finalize_from_global_db(hstmt);
+       ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+       hstmt = NULL;
+
+       error_code = ACCOUNT_ERROR_NONE;
+
+CATCH:
+       if (hstmt != NULL) {
+               rc = _account_query_finalize_from_global_db(hstmt);
+               ACCOUNT_RETURN_VAL((rc == ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+               hstmt = NULL;
+       }
+
+       _INFO("_account_type_query_label_by_locale_from_global_db() end : error_code = %d", error_code);
+       return error_code;
+}
+
+// output parameter label must be free
 int _account_type_query_label_by_locale(const char* app_id, const char* locale, char **label)
 {
        int                     error_code = ACCOUNT_ERROR_NONE;
@@ -5772,7 +6758,10 @@ int _account_type_query_label_by_locale(const char* app_id, const char* locale,
                hstmt = NULL;
        }
 
-       pthread_mutex_unlock(&account_mutex);
+       if (error_code == ACCOUNT_ERROR_RECORD_NOT_FOUND) {
+               error_code = _account_type_query_label_by_locale_from_global_db(app_id, locale, label);
+       }
+
        _INFO("_account_type_query_label_by_locale() end : error_code = %d", error_code);
        return error_code;
 }
index b4e8e2f..f3bc73d 100644 (file)
@@ -262,7 +262,7 @@ gboolean account_manager_account_add(AccountManager *obj, GDBusMethodInvocation
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -270,6 +270,14 @@ gboolean account_manager_account_add(AccountManager *obj, GDBusMethodInvocation
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        account = umarshal_account(account_data);
        if (account == NULL)
        {
@@ -309,12 +317,19 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        _account_free_account_with_items(account);
 
        return true;
 }
 
-gboolean account_manager_account_query_all(AccountManager *obj, GDBusMethodInvocation *invocation)
+gboolean account_manager_account_query_all(AccountManager *obj, GDBusMethodInvocation *invocation, gint uid)
 {
        _INFO("account_manager_account_query_all start");
 
@@ -330,7 +345,7 @@ gboolean account_manager_account_query_all(AccountManager *obj, GDBusMethodInvoc
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -338,6 +353,14 @@ gboolean account_manager_account_query_all(AccountManager *obj, GDBusMethodInvoc
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        //Mode checking not required, since default mode is read.
 
        GSList* account_list = NULL;
@@ -377,10 +400,17 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
-gboolean account_manager_account_type_query_all(AccountManager *obj, GDBusMethodInvocation *invocation)
+gboolean account_manager_account_type_query_all(AccountManager *obj, GDBusMethodInvocation *invocation, gint uid)
 {
        _INFO("account_manager_account_query_all start");
 
@@ -395,7 +425,7 @@ gboolean account_manager_account_type_query_all(AccountManager *obj, GDBusMethod
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -403,6 +433,14 @@ gboolean account_manager_account_type_query_all(AccountManager *obj, GDBusMethod
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        //Mode checking not required, since default mode is read.
 
        GSList* account_type_list = NULL;
@@ -442,10 +480,17 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
-gboolean account_manager_account_type_add(AccountManager *obj, GDBusMethodInvocation *invocation, GVariant *account_type_data, gpointer user_data)
+gboolean account_manager_account_type_add(AccountManager *obj, GDBusMethodInvocation *invocation, GVariant *account_type_data, gint uid, gpointer user_data)
 {
        int db_id = -1;
        account_type_s* account_type = NULL;
@@ -468,7 +513,7 @@ gboolean account_manager_account_type_add(AccountManager *obj, GDBusMethodInvoca
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -476,6 +521,14 @@ gboolean account_manager_account_type_add(AccountManager *obj, GDBusMethodInvoca
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        account_type = umarshal_account_type(account_type_data);
        if (account_type == NULL)
        {
@@ -514,6 +567,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        _account_type_free_account_type_with_items(account_type);
        return true;
 }
@@ -541,7 +601,7 @@ gboolean account_manager_account_delete_from_db_by_id(AccountManager *object,
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -549,6 +609,14 @@ gboolean account_manager_account_delete_from_db_by_id(AccountManager *object,
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_delete");
        return_code = _account_delete(pid, uid, account_db_id);
        _INFO("after _account_delete=[%d]", return_code);
@@ -580,6 +648,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
@@ -607,7 +682,7 @@ gboolean account_manager_account_delete_from_db_by_user_name(AccountManager *obj
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -615,6 +690,14 @@ gboolean account_manager_account_delete_from_db_by_user_name(AccountManager *obj
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_delete_from_db_by_user_name");
        return_code = _account_delete_from_db_by_user_name(pid, uid, user_name, package_name);
        _INFO("after _account_delete_from_db_by_user_name=[%d]", return_code);
@@ -646,6 +729,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
@@ -676,13 +766,21 @@ gboolean account_manager_account_delete_from_db_by_package_name(AccountManager *
                }
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before account_delete_from_db_by_package_name");
        return_code = _account_delete_from_db_by_package_name(pid, uid, package_name, permission);
        _INFO("after account_delete_from_db_by_package_name=[%d]", return_code);
@@ -714,6 +812,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
@@ -742,7 +847,7 @@ gboolean account_manager_account_update_to_db_by_id(AccountManager *object,
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -750,6 +855,14 @@ gboolean account_manager_account_update_to_db_by_id(AccountManager *object,
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        account = umarshal_account(account_data);
        if (account == NULL)
        {
@@ -789,6 +902,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        _account_free_account_with_items(account);
 
        return true;
@@ -820,7 +940,7 @@ gboolean account_manager_handle_account_update_to_db_by_user_name(AccountManager
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -828,6 +948,14 @@ gboolean account_manager_handle_account_update_to_db_by_user_name(AccountManager
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        account = umarshal_account(account_data);
        if (account == NULL)
        {
@@ -867,6 +995,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        _account_free_account_with_items(account);
 
        return true;
@@ -876,7 +1011,8 @@ gboolean
 account_manager_handle_account_type_query_label_by_locale(AccountManager *object,
                                                                                                                        GDBusMethodInvocation *invocation,
                                                                                                                        const gchar *app_id,
-                                                                                                                       const gchar *locale)
+                                                                                                                       const gchar *locale,
+                                                                                                                       gint uid)
 {
        _INFO("account_manager_handle_account_type_query_label_by_locale start");
        guint pid = _get_client_pid(invocation);
@@ -890,7 +1026,7 @@ account_manager_handle_account_type_query_label_by_locale(AccountManager *object
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -898,6 +1034,14 @@ account_manager_handle_account_type_query_label_by_locale(AccountManager *object
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_type_query_label_by_locale");
        char *label_name = NULL;
        return_code = _account_type_query_label_by_locale(app_id, locale, &label_name);
@@ -929,13 +1073,21 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean
 account_manager_handle_account_type_query_by_provider_feature(AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
-                                                                                                                       const gchar *key)
+                                                                                                                       const gchar *key,
+                                                                                                                       gint uid)
 {
        _INFO("account_manager_handle_account_type_query_by_provider_feature start");
        GVariant* account_type_list_variant = NULL;
@@ -951,7 +1103,7 @@ account_manager_handle_account_type_query_by_provider_feature(AccountManager *ob
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -959,6 +1111,14 @@ account_manager_handle_account_type_query_by_provider_feature(AccountManager *ob
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        //Mode checking not required, since default mode is read.
 
        GSList* account_type_list = NULL;
@@ -1008,10 +1168,17 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
-gboolean account_manager_account_get_total_count_from_db(AccountManager *object, GDBusMethodInvocation *invocation, gboolean include_hidden)
+gboolean account_manager_account_get_total_count_from_db(AccountManager *object, GDBusMethodInvocation *invocation, gboolean include_hidden, gint uid)
 {
        _INFO("account_manager_account_get_total_count_from_db start");
        guint pid = _get_client_pid(invocation);
@@ -1025,7 +1192,7 @@ gboolean account_manager_account_get_total_count_from_db(AccountManager *object,
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1033,6 +1200,14 @@ gboolean account_manager_account_get_total_count_from_db(AccountManager *object,
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
 
        _INFO("before account_get_total_count_from_db");
        int count = -1;
@@ -1065,11 +1240,18 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean account_manager_handle_account_query_account_by_account_id(AccountManager *object, GDBusMethodInvocation *invocation,
-               gint account_db_id)
+               gint account_db_id, gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_account_id start");
        GVariant* account_variant = NULL;
@@ -1086,7 +1268,7 @@ gboolean account_manager_handle_account_query_account_by_account_id(AccountManag
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1094,6 +1276,14 @@ gboolean account_manager_handle_account_query_account_by_account_id(AccountManag
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        account_data = create_empty_account_instance();
        if (account_data == NULL)
        {
@@ -1136,6 +1326,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        _account_free_account_with_items(account_data);
 
        return true;
@@ -1144,7 +1341,8 @@ RETURN:
 gboolean
 account_manager_handle_account_query_account_by_user_name(AccountManager *obj,
                                                                                                                  GDBusMethodInvocation *invocation,
-                                                                                                                 const gchar *user_name)
+                                                                                                                 const gchar *user_name,
+                                                                                                                 gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_user_name start");
 
@@ -1160,7 +1358,7 @@ account_manager_handle_account_query_account_by_user_name(AccountManager *obj,
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1168,6 +1366,14 @@ account_manager_handle_account_query_account_by_user_name(AccountManager *obj,
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        //Mode checking not required, since default mode is read.
 
        GList* account_list = NULL;
@@ -1212,13 +1418,21 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean
 account_manager_handle_account_query_account_by_package_name(AccountManager *obj,
                                                                                                                  GDBusMethodInvocation *invocation,
-                                                                                                                 const gchar *package_name)
+                                                                                                                 const gchar *package_name,
+                                                                                                                 gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_package_name start");
 
@@ -1234,7 +1448,7 @@ account_manager_handle_account_query_account_by_package_name(AccountManager *obj
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1242,6 +1456,14 @@ account_manager_handle_account_query_account_by_package_name(AccountManager *obj
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        //Mode checking not required, since default mode is read.
 
        GList* account_list = NULL;
@@ -1286,6 +1508,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
@@ -1293,7 +1522,8 @@ gboolean
 account_manager_handle_account_query_account_by_capability(AccountManager *obj,
                                                                                                                  GDBusMethodInvocation *invocation,
                                                                                                                  const gchar *capability_type,
-                                                                                                                 gint capability_value)
+                                                                                                                 gint capability_value,
+                                                                                                                 gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_capability start");
 
@@ -1310,7 +1540,7 @@ account_manager_handle_account_query_account_by_capability(AccountManager *obj,
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1318,6 +1548,14 @@ account_manager_handle_account_query_account_by_capability(AccountManager *obj,
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        //Mode checking not required, since default mode is read.
 
        GList* account_list = NULL;
@@ -1363,13 +1601,21 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean
 account_manager_handle_account_query_account_by_capability_type(AccountManager *obj,
                                                                                                                  GDBusMethodInvocation *invocation,
-                                                                                                                 const gchar *capability_type)
+                                                                                                                 const gchar *capability_type,
+                                                                                                                 gint uid)
 {
        _INFO("account_manager_handle_account_query_account_by_capability_type start");
 
@@ -1386,7 +1632,7 @@ account_manager_handle_account_query_account_by_capability_type(AccountManager *
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1394,6 +1640,14 @@ account_manager_handle_account_query_account_by_capability_type(AccountManager *
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        //Mode checking not required, since default mode is read.
 
        GList* account_list = NULL;
@@ -1439,13 +1693,21 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean
 account_manager_handle_account_query_capability_by_account_id(AccountManager *obj,
                                                                                                                  GDBusMethodInvocation *invocation,
-                                                                                                                 const int account_id)
+                                                                                                                 const int account_id,
+                                                                                                                 gint uid)
 {
        _INFO("account_manager_handle_account_query_capability_by_account_id start");
 
@@ -1462,7 +1724,7 @@ account_manager_handle_account_query_capability_by_account_id(AccountManager *ob
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1470,6 +1732,14 @@ account_manager_handle_account_query_capability_by_account_id(AccountManager *ob
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        //Mode checking not required, since default mode is read.
 
        GSList* capability_list = NULL;
@@ -1515,6 +1785,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
@@ -1542,7 +1819,7 @@ gboolean account_manager_handle_account_update_sync_status_by_id(AccountManager
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1550,6 +1827,14 @@ gboolean account_manager_handle_account_update_sync_status_by_id(AccountManager
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_update_sync_status_by_id");
        return_code = _account_update_sync_status_by_id(uid, account_db_id, sync_status);
        _INFO("after _account_update_sync_status_by_id=[%d]", return_code);
@@ -1581,12 +1866,20 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean account_manager_handle_account_type_query_provider_feature_by_app_id(AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
-                                                                                                                       const gchar* app_id)
+                                                                                                                       const gchar* app_id,
+                                                                                                                       gint uid)
 {
        GSList* feature_record_list = NULL;
        GVariant* feature_record_list_variant = NULL;
@@ -1604,7 +1897,7 @@ gboolean account_manager_handle_account_type_query_provider_feature_by_app_id(Ac
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1612,6 +1905,14 @@ gboolean account_manager_handle_account_type_query_provider_feature_by_app_id(Ac
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_type_query_provider_feature_by_app_id");
        feature_record_list = _account_type_query_provider_feature_by_app_id(app_id, &return_code);
        _INFO("after account_type_query_provider_feature_by_app_id=[%d]", return_code);
@@ -1652,13 +1953,21 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean account_manager_handle_account_type_query_supported_feature(AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
                                                                                                                        const gchar* app_id,
-                                                                                                                       const gchar* capability)
+                                                                                                                       const gchar* capability,
+                                                                                                                       gint uid)
 {
        int is_supported = 0;
 
@@ -1674,7 +1983,7 @@ gboolean account_manager_handle_account_type_query_supported_feature(AccountMana
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1682,6 +1991,14 @@ gboolean account_manager_handle_account_type_query_supported_feature(AccountMana
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_type_query_supported_feature");
        is_supported = _account_type_query_supported_feature(app_id, capability, &return_code);
        _INFO("after _account_type_query_supported_feature=[%d]", return_code);
@@ -1712,13 +2029,21 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean account_manager_handle_account_type_update_to_db_by_app_id (AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
                                                                                                                        GVariant *account_type_variant,
-                                                                                                                       const gchar *app_id)
+                                                                                                                       const gchar *app_id,
+                                                                                                                       gint uid)
 {
        _INFO("account_manager_handle_account_type_update_to_db_by_app_id start");
        account_type_s* account_type = NULL;
@@ -1740,7 +2065,7 @@ gboolean account_manager_handle_account_type_update_to_db_by_app_id (AccountMana
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1748,6 +2073,14 @@ gboolean account_manager_handle_account_type_update_to_db_by_app_id (AccountMana
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        account_type = umarshal_account_type(account_type_variant);
 
        _INFO("before _account_type_update_to_db_by_app_id");
@@ -1780,6 +2113,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        _account_type_free_account_type_with_items(account_type);
 
        return true;
@@ -1787,7 +2127,8 @@ RETURN:
 
 gboolean account_manager_handle_account_type_delete_by_app_id (AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
-                                                                                                                       const gchar *app_id)
+                                                                                                                       const gchar *app_id,
+                                                                                                                       gint uid)
 {
        _INFO("account_manager_handle_account_type_delete_by_app_id start");
 
@@ -1808,7 +2149,7 @@ gboolean account_manager_handle_account_type_delete_by_app_id (AccountManager *o
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1816,6 +2157,14 @@ gboolean account_manager_handle_account_type_delete_by_app_id (AccountManager *o
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_type_delete_by_app_id");
        return_code = _account_type_delete_by_app_id (app_id);
        _INFO("after _account_type_delete_by_app_id=[%d]", return_code);
@@ -1846,12 +2195,20 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean account_manager_handle_account_type_query_label_by_app_id (AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
-                                                                                                                       const gchar *app_id)
+                                                                                                                       const gchar *app_id,
+                                                                                                                       gint uid)
 {
        _INFO("account_manager_handle_account_type_query_label_by_app_id start");
        GSList* label_list = NULL;
@@ -1868,7 +2225,7 @@ gboolean account_manager_handle_account_type_query_label_by_app_id (AccountManag
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1876,6 +2233,14 @@ gboolean account_manager_handle_account_type_query_label_by_app_id (AccountManag
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_type_get_label_list_by_app_id");
        label_list = _account_type_get_label_list_by_app_id (app_id, &return_code);
        _INFO("after _account_type_get_label_list_by_app_id=[%d]", return_code);
@@ -1908,12 +2273,20 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean account_manager_handle_account_type_query_by_app_id (AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
-                                                                                                                       const gchar *app_id)
+                                                                                                                       const gchar *app_id,
+                                                                                                                       gint uid)
 {
        _INFO("account_manager_handle_account_type_query_by_app_id start");
        GVariant* account_type_variant = NULL;
@@ -1929,7 +2302,7 @@ gboolean account_manager_handle_account_type_query_by_app_id (AccountManager *ob
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -1937,6 +2310,14 @@ gboolean account_manager_handle_account_type_query_by_app_id (AccountManager *ob
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        _INFO("before _account_type_query_by_app_id");
        account_type_s* account_type = NULL;
        return_code = _account_type_query_by_app_id (app_id, &account_type);
@@ -1977,6 +2358,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        _account_type_free_account_type_with_items(account_type);
 
        return true;
@@ -1984,7 +2372,8 @@ RETURN:
 
 gboolean account_manager_handle_account_type_query_app_id_exist (AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
-                                                                                                                       const gchar *app_id)
+                                                                                                                       const gchar *app_id,
+                                                                                                                       gint uid)
 {
        _INFO("account_manager_handle_account_type_query_app_id_exist start");
        guint pid = _get_client_pid(invocation);
@@ -1998,7 +2387,7 @@ gboolean account_manager_handle_account_type_query_app_id_exist (AccountManager
                goto RETURN;
        }
 
-       return_code = _account_db_open(0, pid);
+       return_code = _account_db_open(0, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -2006,13 +2395,21 @@ gboolean account_manager_handle_account_type_query_app_id_exist (AccountManager
                goto RETURN;
        }
 
-       _INFO("before _account_type_query_app_id_exist");
-       return_code = _account_type_query_app_id_exist (app_id);
-       _INFO("after _account_type_query_app_id_exist=[%d]", return_code);
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
+       _INFO("before _account_type_query_app_id_exist_from_all_db");
+       return_code = _account_type_query_app_id_exist_from_all_db (app_id);
+       _INFO("after _account_type_query_app_id_exist_from_all_db=[%d]", return_code);
 
        if (return_code != ACCOUNT_ERROR_NONE)
        {
-               _ERR("_account_type_query_app_id_exist = [%d]", return_code);
+               _ERR("_account_type_query_app_id_exist_from_all_db = [%d]", return_code);
                goto RETURN;
        }
 
@@ -2037,13 +2434,21 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        return true;
 }
 
 gboolean account_manager_handle_account_update_to_db_by_id_ex (AccountManager *obj,
                                                                                                                        GDBusMethodInvocation *invocation,
                                                                                                                        GVariant *account_data,
-                                                                                                                       gint account_id)
+                                                                                                                       gint account_id,
+                                                                                                                       gint uid)
 {
        _INFO("account_manager_handle_account_update_to_db_by_id_ex start");
        account_s* account = NULL;
@@ -2064,7 +2469,7 @@ gboolean account_manager_handle_account_update_to_db_by_id_ex (AccountManager *o
                goto RETURN;
        }
 
-       return_code = _account_db_open(1, pid);
+       return_code = _account_db_open(1, pid, uid);
        if (return_code != ACCOUNT_ERROR_NONE)
        {
                _ERR("_account_db_open() error, ret = %d", return_code);
@@ -2072,6 +2477,14 @@ gboolean account_manager_handle_account_update_to_db_by_id_ex (AccountManager *o
                goto RETURN;
        }
 
+       return_code = _account_global_db_open();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               _ERR("_account_global_db_open() error, ret = %d", return_code);
+
+               goto RETURN;
+       }
+
        account = umarshal_account(account_data);
        if (account == NULL)
        {
@@ -2111,6 +2524,13 @@ RETURN:
                return_code = ACCOUNT_ERROR_NONE;
        }
 
+       return_code = _account_global_db_close();
+       if (return_code != ACCOUNT_ERROR_NONE)
+       {
+               ACCOUNT_DEBUG("_account_global_db_close() fail[%d]", return_code);
+               return_code = ACCOUNT_ERROR_NONE;
+       }
+
        _account_free_account_with_items(account);
 
        return true;