summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIckhee Woo <ickhee.woo@samsung.com>2017-06-02 16:42:50 +0900
committerIckhee Woo <ickhee.woo@samsung.com>2017-06-15 09:32:44 +0000
commit08f455dd2acf5595df6ffb2806bc5c7e229f6a73 (patch)
treeaeb6da927b84f42a6be93878dcd5f1d22b4039b2
parentcc0fc9216ef6e7df5b2c6a4b4f49417b4f5b2925 (diff)
downloadsync-manager-08f455dd2acf5595df6ffb2806bc5c7e229f6a73.tar.gz
sync-manager-08f455dd2acf5595df6ffb2806bc5c7e229f6a73.tar.bz2
sync-manager-08f455dd2acf5595df6ffb2806bc5c7e229f6a73.zip
implementation for multiuser
- added uid as gdbus function param - added code for initializing DB - added code for inserting, updating, deleting data in DB - added service termination code after removing all sync jobs - added AppStatus in sync job table - added code for treating UserData key-value - added code for all sync jobs running with their uid - fixed svace issue Change-Id: I6f4720eb9fc7a13ae9b23a410d35d3443d654371
-rw-r--r--include/sync-error.h4
-rw-r--r--packaging/sync-manager.spec19
-rw-r--r--src/sync-client/sync_adapter.c9
-rw-r--r--src/sync-client/sync_manager.c33
-rw-r--r--src/sync-service/CMakeLists.txt1
-rw-r--r--src/sync-service/SyncManager_DataSyncJob.cpp4
-rw-r--r--src/sync-service/SyncManager_DataSyncJob.h2
-rw-r--r--src/sync-service/SyncManager_PeriodicSyncJob.cpp4
-rw-r--r--src/sync-service/SyncManager_PeriodicSyncJob.h2
-rw-r--r--src/sync-service/SyncManager_RepositoryEngine.cpp1294
-rw-r--r--src/sync-service/SyncManager_RepositoryEngine.h55
-rw-r--r--src/sync-service/SyncManager_SyncAdapterAggregator.cpp33
-rw-r--r--src/sync-service/SyncManager_SyncJob.cpp11
-rw-r--r--src/sync-service/SyncManager_SyncJob.h3
-rw-r--r--src/sync-service/SyncManager_SyncJobDispatcher.cpp6
-rw-r--r--src/sync-service/SyncManager_SyncJobsAggregator.cpp46
-rw-r--r--src/sync-service/SyncManager_SyncJobsAggregator.h12
-rw-r--r--src/sync-service/SyncManager_SyncJobsInfo.cpp31
-rw-r--r--src/sync-service/SyncManager_SyncJobsInfo.h6
-rw-r--r--src/sync-service/SyncManager_SyncManager.cpp97
-rw-r--r--src/sync-service/SyncManager_SyncManager.h24
-rw-r--r--src/sync-service/SyncManager_SyncService.cpp179
-rw-r--r--src/sync-service/SyncManager_SyncService.h10
-rw-r--r--sync_manager.xml7
24 files changed, 1493 insertions, 399 deletions
diff --git a/include/sync-error.h b/include/sync-error.h
index d22927f..fe0cc7c 100644
--- a/include/sync-error.h
+++ b/include/sync-error.h
@@ -50,10 +50,10 @@ typedef enum {
SYNC_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
SYNC_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
SYNC_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Duplicate data */
- SYNC_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Error in Operation */
+ SYNC_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Error in operation */
SYNC_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
SYNC_ERROR_QUOTA_EXCEEDED = TIZEN_ERROR_QUOTA_EXCEEDED, /**< Quota exceeded */
- SYNC_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN, /**< Unknown Error */
+ SYNC_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN, /**< Unknown error */
SYNC_ERROR_SYSTEM = TIZEN_ERROR_SYNC_MANAGER | 0x01, /**< System error */
SYNC_ERROR_SYNC_ADAPTER_NOT_FOUND = TIZEN_ERROR_SYNC_MANAGER | 0x02 /**< Sync adapter is not registered */
} sync_error_e;
diff --git a/packaging/sync-manager.spec b/packaging/sync-manager.spec
index e1b87a0..676c72c 100644
--- a/packaging/sync-manager.spec
+++ b/packaging/sync-manager.spec
@@ -2,7 +2,7 @@
%global __provides_exclude_from ^.*\\.extension-calendar
Name: sync-service
-Version: 0.1.24
+Version: 0.2.24
Release: 1
License: Apache-2.0
Summary: Sync manager daemon
@@ -19,6 +19,7 @@ BuildRequires: pkgconfig(capi-network-connection)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(appcore-efl)
BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(db-util)
BuildRequires: pkgconfig(pkgmgr)
BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(vconf)
@@ -113,6 +114,22 @@ cp -f scripts/%{_upgrade_script} %{buildroot}%{_upgrade_script_path}
%post -n libcore-sync-client-devel -p /sbin/ldconfig
%post
+/sbin/ldconfig
+mkdir -p %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace
+if [ ! -f %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace/.sync-manager.db ]
+then
+ sqlite3 %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace/.sync-manager.db 'PRAGMA journal_mode = PERSIST;
+ CREATE TABLE if not exists syncadapter (SvcAppId TEXT, PkgName TEXT, UserId TEXT, AppStatus TEXT);
+ CREATE TABLE if not exists syncjob (SvcAppId TEXT, PkgName TEXT, UserId TEXT, AppStatus TEXT, SyncJobId TEXT, SyncType TEXT, AccountId TEXT, JobName TEXT, Interval TEXT, Expedit TEXT, NoRetry TEXT, UserDataKey TEXT, UserDataValue TEXT);'
+fi
+
+chown owner:users %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace/.sync-manager.db
+chown owner:users %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace/.sync-manager.db-journal
+chmod 644 %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace/.sync-manager.db
+chmod 644 %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace/.sync-manager.db-journal
+chsmack -a "*" %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace/.sync-manager.db
+chsmack -a "*" %{TZ_SYS_HOME}/%{TZ_SYS_DEFAULT_USER}/.applications/dbspace/.sync-manager.db-journal
+
#chown system:system %{TZ_SYS_DATA}/sync-manager/
#systemctl enable sync-manager.service
#systemctl start sync-manager.service
diff --git a/src/sync-client/sync_adapter.c b/src/sync-client/sync_adapter.c
index 31d89ec..d829ad3 100644
--- a/src/sync-client/sync_adapter.c
+++ b/src/sync-client/sync_adapter.c
@@ -166,13 +166,16 @@ int __register_sync_adapter(bool flag)
&error);
SYNC_LOGE_RET_RES(error == NULL && ipcObj != NULL, SYNC_ERROR_IO_ERROR, "tizen_sync_manager_proxy_new_sync failed %s", error->message);
- bool ret = true;
+ char buf[8] = {0, };
+ snprintf(buf, 8, "%d", (int)getuid());
+
char *command_line = proc_get_cmdline_self();
if (flag) {
- ret = tizen_sync_manager_call_add_sync_adapter_sync(ipcObj, command_line, NULL, &error);
+ bool ret = true;
+ ret = tizen_sync_manager_call_add_sync_adapter_sync(ipcObj, (const gchar*)buf, command_line, NULL, &error);
SYNC_LOGE_RET_RES(ret && !error, SYNC_ERROR_QUOTA_EXCEEDED, "Register sync adapter failed %s", error->message);
} else {
- tizen_sync_manager_call_remove_sync_adapter_sync(ipcObj, command_line, NULL, &error);
+ tizen_sync_manager_call_remove_sync_adapter_sync(ipcObj, (const gchar*)buf, command_line, NULL, &error);
}
free(command_line);
diff --git a/src/sync-client/sync_manager.c b/src/sync-client/sync_manager.c
index e546674..b809a76 100644
--- a/src/sync-client/sync_manager.c
+++ b/src/sync-client/sync_manager.c
@@ -310,10 +310,13 @@ int sync_manager_on_demand_sync_job(account_h account, const char *sync_job_name
LOG_LOGC("appid [%s] sync_job_name [%s]", g_sync_manager->appid, sync_job_name);
}
- GVariant *user_data = marshal_bundle(sync_job_user_data);
+ char buf[8] = {0, };
+ snprintf(buf, 8, "%d", (int)getuid());
+
GError *error = NULL;
+ GVariant *user_data = marshal_bundle(sync_job_user_data);
- bool is_success = tizen_sync_manager_call_add_on_demand_job_sync(g_sync_manager->ipcObj, g_sync_manager->appid, id, sync_job_name, sync_option, user_data, sync_job_id, NULL, &error);
+ bool is_success = tizen_sync_manager_call_add_on_demand_job_sync(g_sync_manager->ipcObj, (const gchar*)buf, g_sync_manager->appid, id, sync_job_name, sync_option, user_data, sync_job_id, NULL, &error);
if (!is_success || error) {
int error_code = _sync_get_error_code(is_success, error);
LOG_LOGC("sync client: gdbus error [%s]", error->message);
@@ -354,10 +357,13 @@ int sync_manager_add_periodic_sync_job(account_h account, const char *sync_job_n
int sync_interval = get_interval(sync_period);
- GVariant *user_data = marshal_bundle(sync_job_user_data);
+ char buf[8] = {0, };
+ snprintf(buf, 8, "%d", (int)getuid());
+
GError *error = NULL;
+ GVariant *user_data = marshal_bundle(sync_job_user_data);
- bool is_success = tizen_sync_manager_call_add_periodic_job_sync(g_sync_manager->ipcObj, g_sync_manager->appid, id, sync_job_name, sync_interval, sync_option, user_data, sync_job_id, NULL, &error);
+ bool is_success = tizen_sync_manager_call_add_periodic_job_sync(g_sync_manager->ipcObj, (const gchar*)buf, g_sync_manager->appid, id, sync_job_name, sync_interval, sync_option, user_data, sync_job_id, NULL, &error);
if (!is_success || error) {
int error_code = _sync_get_error_code(is_success, error);
LOG_LOGC("sync client: gdbus error [%s]", error->message);
@@ -409,10 +415,13 @@ int sync_manager_add_data_change_sync_job(account_h account, const char *sync_ca
LOG_LOGC("appid [%s] capability [%s]", g_sync_manager->appid, sync_capability);
}
- GVariant *user_data = marshal_bundle(sync_job_user_data);
+ char buf[8] = {0, };
+ snprintf(buf, 8, "%d", (int)getuid());
+
GError *error = NULL;
+ GVariant *user_data = marshal_bundle(sync_job_user_data);
- bool is_success = tizen_sync_manager_call_add_data_change_job_sync(g_sync_manager->ipcObj, g_sync_manager->appid, id, sync_capability, sync_option, user_data, sync_job_id, NULL, &error);
+ bool is_success = tizen_sync_manager_call_add_data_change_job_sync(g_sync_manager->ipcObj, (const gchar*)buf, g_sync_manager->appid, id, sync_capability, sync_option, user_data, sync_job_id, NULL, &error);
if (!is_success || error) {
int error_code = _sync_get_error_code(is_success, error);
LOG_LOGC("sync client: gdbus error [%s]", error->message);
@@ -435,9 +444,12 @@ int sync_manager_remove_sync_job(int sync_job_id)
LOG_LOGC("sync client: [%s] removing sync job with sync_job_id [%d]", g_sync_manager->appid, sync_job_id);
+ char buf[8] = {0, };
+ snprintf(buf, 8, "%d", (int)getuid());
+
GError *error = NULL;
- bool is_success = tizen_sync_manager_call_remove_job_sync(g_sync_manager->ipcObj, g_sync_manager->appid, sync_job_id, NULL, &error);
+ bool is_success = tizen_sync_manager_call_remove_job_sync(g_sync_manager->ipcObj, (const gchar*)buf, g_sync_manager->appid, sync_job_id, NULL, &error);
if (!is_success || error) {
int error_code = _sync_get_error_code(is_success, error);
LOG_LOGC("sync client: gdbus error [%s]", error->message);
@@ -461,10 +473,13 @@ int sync_manager_foreach_sync_job(sync_manager_sync_job_cb sync_job_cb, void *us
g_sync_manager->sync_job_cb = sync_job_cb;
- GVariant *sync_job_list_variant = NULL;
+ char buf[8] = {0, };
+ snprintf(buf, 8, "%d", (int)getuid());
+
GError *error = NULL;
- gboolean is_success = tizen_sync_manager_call_get_all_sync_jobs_sync(g_sync_manager->ipcObj, g_sync_manager->appid, &sync_job_list_variant, NULL, &error);
+ GVariant *sync_job_list_variant = NULL;
+ gboolean is_success = tizen_sync_manager_call_get_all_sync_jobs_sync(g_sync_manager->ipcObj, (const gchar*)buf, g_sync_manager->appid, &sync_job_list_variant, NULL, &error);
if (!is_success || error) {
int error_code = _sync_get_error_code(is_success, error);
LOG_LOGC("sync client: gdbus error [%s]", error->message);
diff --git a/src/sync-service/CMakeLists.txt b/src/sync-service/CMakeLists.txt
index 04fdf50..ba7a852 100644
--- a/src/sync-service/CMakeLists.txt
+++ b/src/sync-service/CMakeLists.txt
@@ -84,6 +84,7 @@ SET(PACKAGES
pkgmgr
pkgmgr-info
dlog
+ db-util
appcore-efl
glib-2.0
vconf
diff --git a/src/sync-service/SyncManager_DataSyncJob.cpp b/src/sync-service/SyncManager_DataSyncJob.cpp
index 36d3638..33d4497 100644
--- a/src/sync-service/SyncManager_DataSyncJob.cpp
+++ b/src/sync-service/SyncManager_DataSyncJob.cpp
@@ -30,8 +30,8 @@ DataSyncJob::~DataSyncJob(void) {
}
-DataSyncJob::DataSyncJob(const string appId, const string syncJobName, int accountId, bundle* pUserData, int syncOption, int syncJobId, SyncType type, string capability)
- : SyncJob(appId, syncJobName, accountId, pUserData, syncOption, syncJobId, type)
+DataSyncJob::DataSyncJob(const string appId, int uid, const string syncJobName, int accountId, bundle* pUserData, int syncOption, int syncJobId, SyncType type, string capability)
+ : SyncJob(appId, uid, syncJobName, accountId, pUserData, syncOption, syncJobId, type)
, __capability(capability) {
}
diff --git a/src/sync-service/SyncManager_DataSyncJob.h b/src/sync-service/SyncManager_DataSyncJob.h
index b796e42..f64d3ae 100644
--- a/src/sync-service/SyncManager_DataSyncJob.h
+++ b/src/sync-service/SyncManager_DataSyncJob.h
@@ -39,7 +39,7 @@ class DataSyncJob
public:
~DataSyncJob(void);
- DataSyncJob(const string appId, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type, string capability);
+ DataSyncJob(const string appId, int uid, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type, string capability);
DataSyncJob(const DataSyncJob&);
diff --git a/src/sync-service/SyncManager_PeriodicSyncJob.cpp b/src/sync-service/SyncManager_PeriodicSyncJob.cpp
index 1a7ecd5..64dc8e7 100644
--- a/src/sync-service/SyncManager_PeriodicSyncJob.cpp
+++ b/src/sync-service/SyncManager_PeriodicSyncJob.cpp
@@ -30,8 +30,8 @@ PeriodicSyncJob::~PeriodicSyncJob(void) {
}
-PeriodicSyncJob::PeriodicSyncJob(const string appId, const string syncJobName, int accountId, bundle* pUserData, int syncOption, int syncJobId, SyncType type, long frequency)
- : SyncJob(appId, syncJobName, accountId, pUserData, syncOption, syncJobId, type)
+PeriodicSyncJob::PeriodicSyncJob(const string appId, int uid, const string syncJobName, int accountId, bundle* pUserData, int syncOption, int syncJobId, SyncType type, long frequency)
+ : SyncJob(appId, uid, syncJobName, accountId, pUserData, syncOption, syncJobId, type)
, __period(frequency) {
}
diff --git a/src/sync-service/SyncManager_PeriodicSyncJob.h b/src/sync-service/SyncManager_PeriodicSyncJob.h
index b4db747..319a32d 100644
--- a/src/sync-service/SyncManager_PeriodicSyncJob.h
+++ b/src/sync-service/SyncManager_PeriodicSyncJob.h
@@ -40,7 +40,7 @@ class PeriodicSyncJob
public:
~PeriodicSyncJob(void);
- PeriodicSyncJob(const string appId, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type, long frequency);
+ PeriodicSyncJob(const string appId, int uid, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type, long frequency);
PeriodicSyncJob(const PeriodicSyncJob&);
diff --git a/src/sync-service/SyncManager_RepositoryEngine.cpp b/src/sync-service/SyncManager_RepositoryEngine.cpp
index 722647d..7e9c310 100644
--- a/src/sync-service/SyncManager_RepositoryEngine.cpp
+++ b/src/sync-service/SyncManager_RepositoryEngine.cpp
@@ -44,27 +44,16 @@
{
*/
-#define SYNC_DIRECTORY "sync-manager"
-#define SYNC_DATA_DIR tzplatform_mkpath(TZ_USER_DATA, "/sync-manager")
-#define PATH_ACCOUNT tzplatform_mkpath(TZ_USER_DATA, "/sync-manager/accounts.xml")
#define PATH_SYNCJOBS tzplatform_mkpath(TZ_USER_DATA, "/sync-manager/syncjobs.xml")
#define PATH_SYNCADAPTERS tzplatform_mkpath(TZ_USER_DATA, "/sync-manager/syncadapters.xml")
-#define PATH_STATUS tzplatform_mkpath(TZ_USER_DATA, "/sync-manager/statusinfo.bin")
#ifndef MAX
#define MAX(a, b) a > b ? a : b
#endif
-//xml Tags Definitions
-//For Accounts.xml
-//static char PATH_ACCOUNT[] = "/opt/usr/data/sync-manager/accounts.xml";
-//static char PATH_SYNCJOBS[] = "/opt/usr/data/sync-manager/syncjobs.xml";
-//static char PATH_SYNCADAPTERS[] = "/opt/usr/data/sync-manager/syncadapters.xml";
-//static char PATH_STATUS[] = "/opt/usr/data/sync-manager/statusinfo.bin";
static const xmlChar _VERSION[] = "1.0";
-
static const xmlChar XML_NODE_ACCOUNTS[] = "accounts";
static const xmlChar XML_ATTR_NEXT_CAPABILITY_ID[] = "nextCapabilityId";
static const xmlChar XML_ATTR_SYNC_RANDOM_OFFSET[] = "randomOffsetInSec";
@@ -140,13 +129,18 @@ RepositoryEngine::GetInstance(void) {
/* LCOV_EXCL_START */
RepositoryEngine::~RepositoryEngine(void) {
pthread_mutex_destroy(&__capabilityInfoMutex);
+ pthread_mutex_destroy(&__syncDBReadWriteMutex);
}
/* LCOV_EXCL_STOP */
RepositoryEngine::RepositoryEngine(void) {
if (pthread_mutex_init(&__capabilityInfoMutex, NULL) != 0) {
- LOG_LOGD("\n __syncJobQueueMutex init failed\n"); /* LCOV_EXCL_LINE */
+ LOG_LOGD("__capabilityInfoMutex init failed"); /* LCOV_EXCL_LINE */
+ return;
+ }
+ if (pthread_mutex_init(&__syncDBReadWriteMutex, NULL) != 0) {
+ LOG_LOGD("__syncDBReadWriteMutex init failed"); /* LCOV_EXCL_LINE */
return;
}
}
@@ -154,8 +148,10 @@ RepositoryEngine::RepositoryEngine(void) {
void
RepositoryEngine::OnBooting() {
- ReadSyncAdapters();
- ReadSyncJobsData();
+ if (!ReadSyncAdaptersFromDB())
+ ReadSyncAdapters();
+ if (!ReadSyncJobsDataFromDB())
+ ReadSyncJobsData();
}
@@ -173,7 +169,7 @@ void
RepositoryEngine::CheckSyncJobsData(void) {
LOG_LOGD("Verifying Sync jobs");
- //Parse the Xml file
+ /* Parse the Xml file */
const char* pDocName;
xmlDocPtr doc = NULL;
xmlNodePtr cur = NULL;
@@ -197,7 +193,7 @@ RepositoryEngine::CheckSyncJobsData(void) {
/* LCOV_EXCL_STOP */
}
- //Parse sync jobs
+ /* Parse sync jobs */
if (xmlStrcmp(cur->name, XML_NODE_JOBS)) {
/* LCOV_EXCL_START */
LOG_LOGD("Found empty document while parsing syncjobs.xml");
@@ -219,80 +215,6 @@ RepositoryEngine::CheckSyncJobsData(void) {
}
-/* LCOV_EXCL_START */
-void
-RepositoryEngine::CancelPackageSyncJobs(const char *PackageName) {
- LOG_LOGD("Cancelling Sync jobs");
-
- const char* pDocName;
- xmlDocPtr doc = NULL;
- xmlNodePtr cur = NULL;
-
- pDocName = PATH_SYNCJOBS;
- doc = xmlParseFile(pDocName);
-
- if (doc == NULL) {
- /* LCOV_EXCL_START */
- LOG_LOGD("Failed to parse syncjobs.xml");
- SaveCurrentSyncJob();
- doc = xmlParseFile(pDocName);
- /* LCOV_EXCL_STOP */
- }
-
- cur = xmlDocGetRootElement(doc);
- if (cur == NULL) {
- /* LCOV_EXCL_START */
- LOG_LOGD("Found empty document while parsing syncjobs.xml");
- xmlFreeDoc(doc);
- return;
- /* LCOV_EXCL_STOP */
- }
-
- /* Parse sync jobs */
- if (xmlStrcmp(cur->name, XML_NODE_JOBS)) {
- /* LCOV_EXCL_START */
- LOG_LOGD("Found empty document while parsing syncjobs.xml");
- xmlFreeDoc(doc);
- return;
- /* LCOV_EXCL_STOP */
- } else {
- cur = cur->xmlChildrenNode;
- while (cur != NULL) {
- /* LCOV_EXCL_START */
- if (!xmlStrcmp(cur->name, XML_NODE_PACKAGE)) {
- xmlChar* pPackageId;
- pPackageId = xmlGetProp(cur, XML_ATTR_PACKAGE_ID);
-
- if (pPackageId != NULL && !strcmp((char*)pPackageId, PackageName)) {
- xmlNodePtr curJob = cur->xmlChildrenNode;
- while (curJob != NULL) {
- xmlChar* pSyncJobId;
- pSyncJobId = xmlGetProp(curJob, XML_ATTR_JOB_ID);
-
- int sync_job_id = (pSyncJobId == NULL) ? 0 : atoi((char*)pSyncJobId);
-
- if (sync_job_id) {
- LOG_LOGD("Cancel Sync job id [%d]", sync_job_id);
- SyncManager::GetInstance()->RemoveSyncJob(PackageName, sync_job_id);
- }
-
- curJob = curJob->next;
- }
- break;
- }
- }
- cur = cur->next;
- /* LCOV_EXCL_STOP */
- }
- }
-
- xmlFreeDoc(doc);
-
- LOG_LOGD("Cancel sync jobs over");
-}
-/* LCOV_EXCL_STOP */
-
-
bool
RepositoryEngine::CheckAdapterStatus(const char *PackageName) {
bool is_enabled = true;
@@ -345,7 +267,7 @@ void
RepositoryEngine::ReadSyncJobsData(void) {
LOG_LOGD("Reading Sync jobs");
- //Parse the Xml file
+ /* Parse the Xml file */
const char* pDocName;
xmlDocPtr doc = NULL;
xmlNodePtr cur = NULL;
@@ -356,7 +278,6 @@ RepositoryEngine::ReadSyncJobsData(void) {
if (doc == NULL) {
/* LCOV_EXCL_START */
LOG_LOGD("Failed to parse syncjobs.xml");
- SaveCurrentSyncJob();
doc = xmlParseFile(pDocName);
/* LCOV_EXCL_STOP */
}
@@ -370,7 +291,7 @@ RepositoryEngine::ReadSyncJobsData(void) {
/* LCOV_EXCL_STOP */
}
- //Parse sync jobs
+ /* Parse sync jobs */
if (xmlStrcmp(cur->name, XML_NODE_JOBS)) {
/* LCOV_EXCL_START */
LOG_LOGD("Found empty document while parsing syncjobs.xml");
@@ -418,26 +339,23 @@ RepositoryEngine::ReadSyncJobsData(void) {
xmlFreeDoc(doc);
- // Test code
- /*
- int size = SyncManager::GetInstance()->GetSyncJobQueue()->GetSyncJobQueue().size();
- map<const string, SyncJob*> queue = SyncManager::GetInstance()->GetSyncJobQueue()->GetSyncJobQueue();
- map<const string, SyncJob*>::iterator it;
- LOG_LOGD("SyncJobQueue size %d", size);
- for (it = queue.begin(); it != queue.end(); it++)
- {
- SyncJob* pJob = it->second;
- LOG_LOGD("SyncJobQueue appId %s", pJob->appId.c_str());
- LOG_LOGD("SyncJobQueue capability %s", pJob->capability.c_str());
- LOG_LOGD("SyncJobQueue backoff %ld, delay %ld", pJob->backoff, pJob->delayUntil);
- LOG_LOGD("SyncJobQueue key %s, reason %d, source %d", pJob->key.c_str(), pJob->reason, pJob->syncSource);
- //string str;
- //str.append("[");
- //bundle_iterate(pJob->pExtras, bndl_iterator_test, &str);
- //str.append("]");
- }
- */
- //Till here
+ /* process for removing previous data */
+ xmlNodePtr rootNode;
+ stringstream ss;
+
+ doc = xmlNewDoc(_VERSION);
+
+ rootNode = xmlNewNode(NULL, XML_NODE_JOBS);
+ xmlDocSetRootElement(doc, rootNode);
+
+ xmlNewProp(rootNode, XML_ATTR_COUNT, (const xmlChar*)"0");
+
+ int ret = xmlSaveFormatFileEnc(PATH_SYNCJOBS, doc, "UTF-8" , 1);
+ if (ret < 0)
+ LOG_LOGD("Failed to write account data, error [%d], errno [%d]", ret, errno); /* LCOV_EXCL_LINE */
+
+ xmlFreeDoc(doc);
+ xmlCleanupParser();
LOG_LOGD("sync jobs are figured out");
}
@@ -447,7 +365,7 @@ void
RepositoryEngine::ReadSyncAdapters(void) {
LOG_LOGD("Reading sync adapters");
- //Parse the Xml file
+ /* Parse the Xml file */
const char* pDocName;
xmlDocPtr doc = NULL;
xmlNodePtr cur = NULL;
@@ -458,7 +376,6 @@ RepositoryEngine::ReadSyncAdapters(void) {
if (doc == NULL) {
/* LCOV_EXCL_START */
LOG_LOGD("Failed to parse syncadapters.xml");
- SaveCurrentSyncAdapter();
doc = xmlParseFile(pDocName);
/* LCOV_EXCL_STOP */
}
@@ -472,7 +389,7 @@ RepositoryEngine::ReadSyncAdapters(void) {
/* LCOV_EXCL_STOP */
}
- //Parse sync jobs
+ /* Parse sync jobs */
if (xmlStrcmp(cur->name, XML_NODE_SYNCADAPTERS)) {
/* LCOV_EXCL_START */
LOG_LOGD("Found empty document while parsing syncadapters.xml");
@@ -481,10 +398,8 @@ RepositoryEngine::ReadSyncAdapters(void) {
/* LCOV_EXCL_STOP */
} else {
xmlChar* pSACount;
-
pSACount = xmlGetProp(cur, XML_ATTR_COUNT);
int count = (pSACount == NULL) ? 0 : atoi((char*)pSACount);
-
LOG_LOGD("sync adapter count [%d]", count);
SyncAdapterAggregator* pAggregator = SyncManager::GetInstance()->GetSyncAdapterAggregator();
@@ -492,42 +407,25 @@ RepositoryEngine::ReadSyncAdapters(void) {
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if (!xmlStrcmp(cur->name, XML_NODE_SYNCADAPTER)) {
- xmlChar* pServiceAppUID = xmlGetProp(cur, XML_ATTR_SYNCADAPTER_SERVICE_APP_ID);
- if (!pServiceAppUID)
- return;
+ xmlChar* pServiceAppId = xmlGetProp(cur, XML_ATTR_SYNCADAPTER_SERVICE_APP_ID);
xmlChar* pPackageId = xmlGetProp(cur, XML_ATTR_PACKAGE_ID);
xmlChar* pAppStatus = xmlGetProp(cur, XML_ATTR_APP_STATUS);
- char pAppUID[100] = { 0, };
- if (!strstr((char*)pServiceAppUID, "#"))
- snprintf(pAppUID, 100, "%s#%d", pServiceAppUID, 5001);
- else
- strncpy(pAppUID, (char*)pServiceAppUID, sizeof(pServiceAppUID));
-
- char *pServiceAppId;
- char *ptr;
- pServiceAppId = strtok_r((char*)pServiceAppUID, "#", &ptr);
-
- LOG_LOGD("pAppUID [%s], pServiceAppId [%s]", pAppUID, pServiceAppId);
-
pkgmgrinfo_appinfo_h handle_appinfo;
if (pkgmgrinfo_appinfo_get_appinfo((char*)pServiceAppId, &handle_appinfo) == PMINFO_R_OK) {
if (!pAppStatus)
- pAggregator->SetAppStatus((char*)pAppUID, "enabled");
+ pAggregator->SetAppStatus((char*)pServiceAppId, "enabled");
else
- pAggregator->SetAppStatus((char*)pAppUID, (char*)pAppStatus);
+ pAggregator->SetAppStatus((char*)pServiceAppId, (char*)pAppStatus);
- pAggregator->AddSyncAdapter((char*)pPackageId, (char*)pAppUID);
+ pAggregator->AddSyncAdapter((char*)pPackageId, (char*)pServiceAppId);
+ InsertSyncAdapterToDB((char*)pServiceAppId, (char*)pPackageId, 5001, (char*)pAppStatus);
pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
} else {
pAggregator->HandlePackageUninstalled((char*)pPackageId);
}
if (pServiceAppId)
- free(pServiceAppId);
- if (ptr)
- free(ptr);
- if (pServiceAppUID)
- xmlFree(pServiceAppUID);
+ xmlFree(pServiceAppId);
if (pPackageId)
xmlFree(pPackageId);
if (pAppStatus)
@@ -535,11 +433,26 @@ RepositoryEngine::ReadSyncAdapters(void) {
}
cur = cur->next;
}
- WriteSyncAdapters();
pAggregator->dumpSyncAdapters();
}
+ /* process for removing previous data */
+ xmlNodePtr rootNode;
+ stringstream ss;
+
+ doc = xmlNewDoc(_VERSION);
+
+ rootNode = xmlNewNode(NULL, XML_NODE_SYNCADAPTERS);
+ xmlDocSetRootElement(doc, rootNode);
+
+ xmlNewProp(rootNode, XML_ATTR_COUNT, (const xmlChar*)"0");
+
+ int ret = xmlSaveFormatFileEnc(PATH_SYNCADAPTERS, doc, "UTF-8", 1);
+ if (ret < 0)
+ LOG_LOGD("Failed to write sync adapter data, error [%d]", ret); /* LCOV_EXCL_LINE */
+
xmlFreeDoc(doc);
+ xmlCleanupParser();
LOG_LOGD("sync adapters are initialized");
}
@@ -549,7 +462,6 @@ RepositoryEngine::ReadSyncAdapters(void) {
static void
bndl_iterator(const char* pKey, const char* pVal, void* pData) {
xmlNodePtr parentNode = *((xmlNodePtr*)pData);
-
xmlNodePtr extraNode = xmlNewChild(parentNode, NULL, XML_NODE_SYNC_EXTRA, NULL);
xmlNewProp(extraNode, XML_ATTR_SYNC_EXTRA_KEY, (const xmlChar*)pKey);
xmlNewProp(extraNode, XML_ATTR_SYNC_EXTRA_VALUE, (const xmlChar*)pVal);
@@ -726,9 +638,9 @@ RepositoryEngine::ParseExtras(xmlNodePtr cur, bundle* pExtra) {
void
RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage) {
- //xmlChar* pAppId = xmlGetProp(cur, XML_ATTR_JOB_APP_ID);
+ xmlChar* pAppId = xmlGetProp(cur, XML_ATTR_JOB_APP_ID);
xmlChar* pAccId = xmlGetProp(cur, XML_ATTR_JOB_ACCOUNT_ID);
- xmlChar* pJobId = xmlGetProp(cur, XML_ATTR_JOB_ID);
+ //xmlChar* pJobId = xmlGetProp(cur, XML_ATTR_JOB_ID);
xmlChar* pJobName = xmlGetProp(cur, XML_ATTR_JOB_NAME);
xmlChar* pJobNoRetry = xmlGetProp(cur, XML_ATTR_JOB_OPTION_NORETRY);
xmlChar* pJobExpedit = xmlGetProp(cur, XML_ATTR_JOB_OPTION_EXPEDIT);
@@ -739,8 +651,8 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage) {
SyncType type = (pJobType == NULL) ? SYNC_TYPE_UNKNOWN : (SyncType)atoi((char*)pJobType);
bool noretry = (pJobNoRetry == NULL) ? false : atoi((char*)pJobNoRetry);
bool expedit = (pJobExpedit == NULL) ? false : atoi((char*)pJobExpedit);
- int acountId = (pAccId == NULL) ? -1 : atoi((char*)pAccId);
- int jobId = (pJobId == NULL) ? -1 : atoi((char*)pJobId);
+ int accountId = (pAccId == NULL) ? -1 : atoi((char*)pAccId);
+ int syncJobId = -1;
int syncOption = (noretry) ? 0x02 : 0x00;
syncOption |= (expedit) ? 0x01 : 0x00;
@@ -755,19 +667,18 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage) {
switch (type) {
case SYNC_TYPE_DATA_CHANGE: {
- SyncManager::GetInstance()->AddDataSyncJob((char*)pPackage, (char*)pJobName, acountId, pExtra, syncOption, jobId, (char*)pJobName);
+ SyncService::GetInstance()->RequestDataSync((const char*)pPackage, 5001, (const char*)pJobName, accountId, pExtra, syncOption, (const char*)pJobName, &syncJobId);
+ if (syncJobId > 0)
+ InsertSyncJobToDB((const char*)pAppId, (const char*)pPackage, 5001, "enabled", syncJobId, (const char*)pJobType, accountId, (const char*)pJobName, -1, syncOption, pExtra);
break;
}
case SYNC_TYPE_ON_DEMAND: {
- SyncManager::GetInstance()->AddOnDemandSync((char*)pPackage, (char*)pJobName, acountId, pExtra, syncOption, jobId);
break;
}
case SYNC_TYPE_PERIODIC: {
- SyncJobsAggregator* pSyncJobsAggregator = SyncManager::GetInstance()->GetSyncJobsAggregator();
- pSyncJobsAggregator->SetMinPeriod(period / 60);
- pSyncJobsAggregator->SetLimitTime(pSyncJobsAggregator->GetMinPeriod());
-
- SyncManager::GetInstance()->AddPeriodicSyncJob((char*)pPackage, (char*)pJobName, acountId, pExtra, syncOption, jobId, period);
+ SyncService::GetInstance()->RequestPeriodicSync((const char*)pPackage, 5001, (const char*)pJobName, accountId, pExtra, syncOption, period, &syncJobId);
+ if (syncJobId > 0)
+ InsertSyncJobToDB((const char*)pAppId, (const char*)pPackage, 5001, "enabled", syncJobId, (const char*)pJobType, accountId, (const char*)pJobName, period, syncOption, pExtra);
break;
}
case SYNC_TYPE_UNKNOWN:
@@ -782,32 +693,1075 @@ RepositoryEngine::ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage) {
void
-RepositoryEngine::SaveCurrentState(void) {
- LOG_LOGD("saving states during shutdown");
- pthread_mutex_lock(&__capabilityInfoMutex);
- WriteSyncJobsData();
- pthread_mutex_unlock(&__capabilityInfoMutex);
- WriteSyncAdapters();
+RepositoryEngine::RecordSyncAdapter(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus) {
+ InsertSyncAdapterToDB(SvcAppId, PkgName, UserId, AppStatus);
+}
+
+
+void
+RepositoryEngine::RecordSyncAdapter(const char *SvcAppId, int UserId, const char *AppStatus) {
+ UpdateSyncAdapterToDB(SvcAppId, UserId, AppStatus);
+}
+
+
+void
+RepositoryEngine::RecordSyncAdapter(const char *PkgName, int UserId) {
+ DeleteSyncAdapterFromDB(PkgName, UserId);
+}
+
+
+void
+RepositoryEngine::RecordSyncJob(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus, int JobId,
+ const char *SyncType, int AccountId, const char *JobName, int Interval, int Option, bundle *UserData) {
+ InsertSyncJobToDB(SvcAppId, PkgName, UserId, AppStatus, JobId, SyncType, AccountId, JobName, Interval, Option, UserData);
+}
+
+
+void
+RepositoryEngine::RecordSyncJob(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus) {
+ UpdateAppStatusToDB(SvcAppId, PkgName, UserId, AppStatus);
+}
+
+
+void
+RepositoryEngine::RecordSyncJob(const char *PkgName, int UserId, int JobId) {
+ DeleteSyncJobFromDB(PkgName, UserId, JobId);
+}
+
+
+void
+RepositoryEngine::RecordSyncJob(const char *PkgName, int UserId) {
+ DeleteAllSyncJobsFromDB(PkgName, UserId);
+}
+
+
+static sqlite3 *db_open(void) {
+ sqlite3 *db;
+ int ret = db_util_open(SYNC_SYS_DB_FILE, &db, 0);
+ if (ret)
+ return NULL;
+ return db;
+}
+
+
+static void db_close(sqlite3 *db) {
+ db_util_close(db);
+}
+
+
+int
+RepositoryEngine::ReadSyncAdaptersFromDB(void) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return 0;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ char *search_query = NULL;
+ int ret = SQLITE_OK;
+
+ search_query = sqlite3_mprintf("SELECT * FROM %Q", SYNC_ADAPTER_TABLE);
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, search_query, strlen(search_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : search query[%s] ret[%d] err_msg[%s]", search_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return 0;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ SyncAdapterAggregator* pAggregator = SyncManager::GetInstance()->GetSyncAdapterAggregator();
+
+ char **SqlResult;
+ int RecordCount;
+ int ColumnCount;
+ char *error_msg = NULL;
+
+ sqlite3_get_table(db, search_query, &SqlResult, &RecordCount, &ColumnCount, &error_msg);
+
+ /* exclude column title (0 ~ 3) */
+ LOG_LOGD("[idx] : [SvcAppId][PkgName][UserId][AppStatus]");
+ for (int idx = ADAPTER_COLUMN_NUM; idx < (RecordCount + 1) * (ColumnCount); idx += ADAPTER_COLUMN_NUM) {
+ if (idx % ADAPTER_COLUMN_NUM == 0) {
+ LOG_LOGD("[%d] : [%s] [%s] [%s] [%s]", idx / ADAPTER_COLUMN_NUM,
+ SqlResult[idx], SqlResult[idx + 1], SqlResult[idx + 2], SqlResult[idx + 3]);
+
+ pkgmgrinfo_appinfo_h handle_appinfo;
+ if (pkgmgrinfo_appinfo_get_appinfo(SqlResult[idx], &handle_appinfo) == PMINFO_R_OK) {
+ /*
+ * pAggregator->SetAppStatus(app_id, app_status);
+ * pAggregator->AddSyncAdapter(pkg_name, app_id);
+ */
+ pAggregator->SetAppStatus(SqlResult[idx], SqlResult[idx + 3]);
+ pAggregator->AddSyncAdapter(SqlResult[idx + 1], SqlResult[idx]);
+
+ pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
+ } else {
+ pAggregator->HandlePackageUninstalled(SqlResult[idx + 1]);
+ }
+ }
+ }
+
+ pAggregator->dumpSyncAdapters();
+
+ LOG_LOGD("result : Read sync adapters from DB complete [%s]", search_query);
+ } else if (ret == SQLITE_DONE) {
+ LOG_LOGD("There is no sync adapter in the DB");
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return 0;
+ } else {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), search_query);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return 0;
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+
+ return 1;
+}
+
+
+int
+RepositoryEngine::InsertSyncAdapterToDB(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return -1;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ if (SvcAppId && strlen(SvcAppId) > 0) {
+ char uid[10] = { 0, };
+ snprintf(uid, 10, "%d", UserId);
+
+ char *search_query = NULL;
+ char *insert_query = NULL;
+ int ret = SQLITE_OK;
+
+ search_query = sqlite3_mprintf("SELECT * FROM %Q WHERE SvcAppId=%Q AND UserId=%Q", SYNC_ADAPTER_TABLE, SvcAppId, uid);
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, search_query, strlen(search_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : search query[%s] ret[%d] err_msg[%s]", search_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_DONE) {
+ sqlite3_reset(stmt);
+ if (!PkgName || strlen(PkgName) <= 0) {
+ insert_query = sqlite3_mprintf("INSERT INTO %Q (SvcAppId, PkgName, UserId, AppStatus) VALUES (%Q, %Q, %Q, %Q)",
+ SYNC_ADAPTER_TABLE, SvcAppId, SyncManager::GetInstance()->GetPkgIdByAppId(SvcAppId).c_str(),
+ uid, AppStatus ? AppStatus : "enabled");
+ } else {
+ insert_query = sqlite3_mprintf("INSERT INTO %Q (SvcAppId, PkgName, UserId, AppStatus) VALUES (%Q, %Q, %Q, %Q)",
+ SYNC_ADAPTER_TABLE, SvcAppId, PkgName, uid, AppStatus ? AppStatus : "enabled");
+ }
+
+ ret = sqlite3_prepare_v2(db, insert_query, strlen(insert_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : insert query[%s] ret[%d] err_msg[%s]", insert_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ sqlite3_free(insert_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_OK && ret != SQLITE_DONE)
+ LOG_LOGD("step : insert query[%s] ret[%d] err_msg[%s]", insert_query, ret, sqlite3_errmsg(db));
+
+ LOG_LOGD("result : Insert to DB complete [%s]", insert_query);
+ sqlite3_free(insert_query);
+ } else if (ret == SQLITE_ROW) {
+ LOG_LOGD("[%s] is already registered in sync-manager DB", SvcAppId);
+ } else {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), search_query);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ } else {
+ LOG_LOGD("Insert sync-adapter fail : invalid service-app-id");
+ }
+
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 0;
+}
+
+
+int
+RepositoryEngine::UpdateSyncAdapterToDB(const char *SvcAppId, int UserId, const char *AppStatus) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return -1;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ if (SvcAppId && strlen(SvcAppId) > 0) {
+ char uid[10] = { 0, };
+ snprintf(uid, 10, "%d", UserId);
+
+ char *update_query = NULL;
+
+ update_query = sqlite3_mprintf("UPDATE %Q SET AppStatus=%Q WHERE SvcAppId=%Q AND UserId=%Q",
+ SYNC_ADAPTER_TABLE, AppStatus, SvcAppId, uid);
+
+ int ret = SQLITE_OK;
+ sqlite3_stmt *stmt = NULL;
+ ret = sqlite3_prepare_v2(db, update_query, strlen(update_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : update query[%s] ret[%d] err_msg[%s]", update_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_OK || ret == SQLITE_DONE) {
+ LOG_LOGD("result : Update to DB complete [%s]", update_query);
+ } else {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), update_query);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ } else {
+ LOG_LOGD("Update sync-adapter fail : invalid service-app-id");
+ }
+
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 0;
+}
+
+
+int
+RepositoryEngine::DeleteSyncAdapterFromDB(const char *PkgName, int UserId) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return -1;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ char uid[10] = { 0, };
+ snprintf(uid, 10, "%d", UserId);
+
+ char *delete_query = NULL;
+ int ret = SQLITE_OK;
+
+ if (PkgName && strlen(PkgName) > 0) {
+ delete_query = sqlite3_mprintf("DELETE FROM %Q WHERE PkgName=%Q AND UserId=%Q", SYNC_ADAPTER_TABLE, PkgName, uid);
+ } else {
+ LOG_LOGD("Delete sync-adapter fail : package-name");
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, delete_query, strlen(delete_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : delete query[%s] ret[%d] err_msg[%s]", delete_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(delete_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_OK && ret != SQLITE_DONE)
+ LOG_LOGD("step : delete query[%s] ret[%d] err_msg[%s]", delete_query, ret, sqlite3_errmsg(db));
+ else
+ LOG_LOGD("result : Delete sync adapter from DB complete [%s]", delete_query);
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(delete_query);
+
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 0;
}
/* LCOV_EXCL_START */
void
-RepositoryEngine::SaveCurrentSyncAdapter(void) {
- LOG_LOGD("saving states of registered Sync Adapters");
- pthread_mutex_lock(&__capabilityInfoMutex);
- WriteSyncAdapters();
- pthread_mutex_unlock(&__capabilityInfoMutex);
+RepositoryEngine::StartPackageSyncJobs(const char *PackageName, int uid) {
+ LOG_LOGD("Starting Sync jobs");
+
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ char *search_query = NULL;
+ int ret = SQLITE_OK;
+
+ char UserId[10] = { 0, };
+ snprintf(UserId, 10, "%d", uid);
+
+ search_query = sqlite3_mprintf("SELECT * FROM %Q WHERE PkgName=%Q AND UserId=%Q", SYNC_JOB_TABLE, PackageName, UserId);
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, search_query, strlen(search_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : search query[%s] ret[%d] err_msg[%s]", search_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ SyncType type;
+
+ char **SqlResult;
+ int RecordCount;
+ int ColumnCount;
+ char *error_msg = NULL;
+
+ sqlite3_get_table(db, search_query, &SqlResult, &RecordCount, &ColumnCount, &error_msg);
+
+ /* exclude column title (0 ~ 12) */
+ LOG_LOGD("[idx] : [SvcAppId][PkgName][UserId][AppStatus][SyncJobId][SyncType][AccountId][JobName][Interval][Expedit][NoRetry][UserDataKey][UserDataValue]");
+ for (int idx = JOB_COLUMN_NUM; idx < (RecordCount + 1) * (ColumnCount); idx += JOB_COLUMN_NUM) {
+ if (idx % JOB_COLUMN_NUM == 0) {
+ LOG_LOGD("[%d] : [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s]", idx / JOB_COLUMN_NUM,
+ SqlResult[idx], SqlResult[idx + 1], SqlResult[idx + 2], SqlResult[idx + 3], SqlResult[idx + 4],
+ SqlResult[idx + 5], SqlResult[idx + 6], SqlResult[idx + 7], SqlResult[idx + 8], SqlResult[idx + 9],
+ SqlResult[idx + 10], SqlResult[idx + 11], SqlResult[idx + 12]);
+
+ /* request sync jobs without condition */
+ type = (SqlResult[idx + 5] == NULL) ? SYNC_TYPE_UNKNOWN : (SyncType)atoi((char*)SqlResult[idx + 5]);
+
+ bundle* pExtra = NULL;
+ if (strcmp(SqlResult[idx + 11], "")) {
+ pExtra = bundle_create();
+ bundle_add_str(pExtra, SqlResult[idx + 11], SqlResult[idx + 12]);
+ }
+
+ int syncOption = (atoi(SqlResult[idx + 10])) ? 0x02 : 0x00;
+ syncOption |= (atoi(SqlResult[idx + 9])) ? 0x01 : 0x00;
+ int syncJobId = -1;
+
+ switch (type) {
+ case SYNC_TYPE_DATA_CHANGE: {
+ SyncService::GetInstance()->RequestDataSync(SqlResult[idx + 1], atoi(SqlResult[idx + 2]), SqlResult[idx + 7], atoi(SqlResult[idx + 6]), pExtra, syncOption, SqlResult[idx + 7], &syncJobId);
+ break;
+ }
+ case SYNC_TYPE_ON_DEMAND: {
+ break;
+ }
+ case SYNC_TYPE_PERIODIC: {
+ SyncService::GetInstance()->RequestPeriodicSync(SqlResult[idx + 1], atoi(SqlResult[idx + 2]), SqlResult[idx + 7], atoi(SqlResult[idx + 6]), pExtra, syncOption, (unsigned long)atoi(SqlResult[idx + 8]), &syncJobId);
+ break;
+ }
+ case SYNC_TYPE_UNKNOWN:
+ default: {
+ LOG_LOGD("failed add sync job: sync type is SYNC_TYPE_UNKNOWN");
+ break;
+ }
+ }
+ }
+ }
+
+ LOG_LOGD("result : Read sync jobs from DB complete [%s]", search_query);
+ } else if (ret == SQLITE_DONE) {
+ LOG_LOGD("There is no sync-adapter");
+ } else {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), search_query);
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ LOG_LOGD("Start package sync jobs over");
}
+/* LCOV_EXCL_STOP */
+/* LCOV_EXCL_START */
void
-RepositoryEngine::SaveCurrentSyncJob(void) {
- LOG_LOGD("saving states of added Sync Jobs");
- pthread_mutex_lock(&__capabilityInfoMutex);
- WriteSyncJobsData();
- pthread_mutex_unlock(&__capabilityInfoMutex);
+RepositoryEngine::CancelPackageSyncJobs(const char *PackageName, int uid) {
+ LOG_LOGD("Cancelling Sync jobs");
+
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ char *search_query = NULL;
+ int ret = SQLITE_OK;
+
+ char UserId[10] = { 0, };
+ snprintf(UserId, 10, "%d", uid);
+
+ search_query = sqlite3_mprintf("SELECT * FROM %Q WHERE PkgName=%Q AND UserId=%Q", SYNC_JOB_TABLE, PackageName, UserId);
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, search_query, strlen(search_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : search query[%s] ret[%d] err_msg[%s]", search_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ char **SqlResult;
+ int RecordCount;
+ int ColumnCount;
+ char *error_msg = NULL;
+
+ sqlite3_get_table(db, search_query, &SqlResult, &RecordCount, &ColumnCount, &error_msg);
+
+ /* exclude column title (0 ~ 12) */
+ LOG_LOGD("[idx] : [SvcAppId][PkgName][UserId][AppStatus][SyncJobId][SyncType][AccountId][JobName][Interval][Expedit][NoRetry][UserDataKey][UserDataValue]");
+ for (int idx = JOB_COLUMN_NUM; idx < (RecordCount + 1) * (ColumnCount); idx += JOB_COLUMN_NUM) {
+ if (idx % JOB_COLUMN_NUM == 0) {
+ LOG_LOGD("[%d] : [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s]", idx / JOB_COLUMN_NUM,
+ SqlResult[idx], SqlResult[idx + 1], SqlResult[idx + 2], SqlResult[idx + 3], SqlResult[idx + 4],
+ SqlResult[idx + 5], SqlResult[idx + 6], SqlResult[idx + 7], SqlResult[idx + 8], SqlResult[idx + 9],
+ SqlResult[idx + 10], SqlResult[idx + 11], SqlResult[idx + 12]);
+
+ /* cancel the package sync job */
+
+ /* find syncJobId from SyncJobsAggregartor
+ int syncJobId = -1;
+ SyncJobsAggregator* pAggregator = SyncManager::GetInstance()->GetSyncJobsAggregator();
+ syncJobId = pAggregator->GetSyncJobId(SqlResult[idx + 1], atoi(SqlResult[idx + 2]), SqlResult[idx + 7]);
+ SyncManager::GetInstance()->RemoveSyncJob(SqlResult[idx + 1], atoi(SqlResult[idx + 2]), syncJobId);
+ */
+
+ SyncManager::GetInstance()->RemoveSyncJob(SqlResult[idx + 1], atoi(SqlResult[idx + 2]), atoi(SqlResult[idx + 4]));
+ }
+ }
+
+ LOG_LOGD("result : Read sync jobs from DB complete [%s]", search_query);
+ } else if (ret == SQLITE_DONE) {
+ LOG_LOGD("There is no sync-adapter");
+ } else {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), search_query);
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ LOG_LOGD("Cancel pacakge sync jobs over");
}
/* LCOV_EXCL_STOP */
+
+void
+RepositoryEngine::CheckSyncJobsDataOnDB(void) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ char *search_query = NULL;
+ int ret = SQLITE_OK;
+
+ search_query = sqlite3_mprintf("SELECT * FROM %Q WHERE AppStatus=%Q", SYNC_JOB_TABLE, "enabled");
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, search_query, strlen(search_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : search query[%s] ret[%d] err_msg[%s]", search_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_DONE) {
+ LOG_LOGD("There is no remained Sync job");
+ ManageIdleState* pManageIdleState = SyncManager::GetInstance()->GetManageIdleState();
+ pManageIdleState->SetTermTimer();
+ } else if (ret == SQLITE_ROW) {
+ LOG_LOGD("There are remained Sync jobs");
+ } else {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), search_query);
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+}
+
+
+int
+RepositoryEngine::ReadSyncJobsDataFromDB(void) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return 0;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ char *search_query = NULL;
+ int ret = SQLITE_OK;
+
+ search_query = sqlite3_mprintf("SELECT * FROM %Q WHERE AppStatus=%Q", SYNC_JOB_TABLE, "enabled");
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, search_query, strlen(search_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : search query[%s] ret[%d] err_msg[%s]", search_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return 0;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ROW) {
+ SyncType type;
+
+ char **SqlResult;
+ int RecordCount;
+ int ColumnCount;
+ char *error_msg = NULL;
+
+ sqlite3_get_table(db, search_query, &SqlResult, &RecordCount, &ColumnCount, &error_msg);
+
+ /* exclude column title (0 ~ 12) */
+ LOG_LOGD("[idx] : [SvcAppId][PkgName][UserId][AppStatus][SyncJobId][SyncType][AccountId][JobName][Interval][Expedit][NoRetry][UserDataKey][UserDataValue]");
+ for (int idx = JOB_COLUMN_NUM; idx < (RecordCount + 1) * (ColumnCount); idx += JOB_COLUMN_NUM) {
+ if (idx % JOB_COLUMN_NUM == 0) {
+ LOG_LOGD("[%d] : [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s]", idx / JOB_COLUMN_NUM,
+ SqlResult[idx], SqlResult[idx + 1], SqlResult[idx + 2], SqlResult[idx + 3], SqlResult[idx + 4],
+ SqlResult[idx + 5], SqlResult[idx + 6], SqlResult[idx + 7], SqlResult[idx + 8], SqlResult[idx + 9],
+ SqlResult[idx + 10], SqlResult[idx + 11], SqlResult[idx + 12]);
+
+ /* request sync jobs which are enabled */
+ if (!strcmp(SqlResult[idx + 3], "enabled")) {
+ type = (SqlResult[idx + 5] == NULL) ? SYNC_TYPE_UNKNOWN : (SyncType)atoi((char*)SqlResult[idx + 5]);
+
+ bundle* pExtra = NULL;
+ if (strcmp(SqlResult[idx + 11], "")) {
+ pExtra = bundle_create();
+ bundle_add_str(pExtra, SqlResult[idx + 11], SqlResult[idx + 12]);
+ }
+
+ int syncOption = (atoi(SqlResult[idx + 10])) ? 0x02 : 0x00;
+ syncOption |= (atoi(SqlResult[idx + 9])) ? 0x01 : 0x00;
+ int syncJobId = -1;
+
+ switch (type) {
+ case SYNC_TYPE_DATA_CHANGE: {
+ SyncService::GetInstance()->RequestDataSync(SqlResult[idx + 1], atoi(SqlResult[idx + 2]), SqlResult[idx + 7], atoi(SqlResult[idx + 6]), pExtra, syncOption, SqlResult[idx + 7], &syncJobId);
+ break;
+ }
+ case SYNC_TYPE_ON_DEMAND: {
+ break;
+ }
+ case SYNC_TYPE_PERIODIC: {
+ SyncService::GetInstance()->RequestPeriodicSync(SqlResult[idx + 1], atoi(SqlResult[idx + 2]), SqlResult[idx + 7], atoi(SqlResult[idx + 6]), pExtra, syncOption, (unsigned long)atoi(SqlResult[idx + 8]), &syncJobId);
+ break;
+ }
+ case SYNC_TYPE_UNKNOWN:
+ default: {
+ LOG_LOGD("failed add sync job: sync type is SYNC_TYPE_UNKNOWN");
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ LOG_LOGD("result : Read sync jobs from DB complete [%s]", search_query);
+ } else if (ret == SQLITE_DONE) {
+ LOG_LOGD("There is no sync-adapter");
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return 0;
+ } else {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), search_query);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return 0;
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 1;
+}
+
+
+static char *UserKey = NULL;
+static char *UserValue = NULL;
+
+
+static void
+bundIterCb(const char *key, const char *value, void *user_data) {
+ UserKey = const_cast<char *>(key);
+ UserValue = const_cast<char *>(value);
+}
+
+
+static std::string
+setEmpty(void) {
+ return "";
+}
+
+
+int
+RepositoryEngine::InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus, int JobId,
+ const char *SyncType, int AccountId, const char *JobName, int Interval, int Option, bundle *UserData) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return -1;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ if (SvcAppId && strlen(SvcAppId) > 0) {
+ char uid[10] = { 0, };
+ snprintf(uid, 10, "%d", UserId);
+ char jobId[10] = { 0, };
+ snprintf(jobId, 10, "%d", JobId);
+ char accId[10] = { 0, };
+ snprintf(accId, 10, "%d", AccountId);
+ char interval[10] = { 0, };
+ snprintf(interval, 10, "%d", Interval);
+ char expedit[2] = { 0, };
+ snprintf(expedit, 2, "%d", Option & SYNC_OPTION_EXPEDITED);
+ char noRetry[2] = { 0, };
+ snprintf(noRetry, 2, "%d", Option & SYNC_OPTION_NO_RETRY);
+
+ UserKey = const_cast<char *>(setEmpty().c_str());
+ UserValue = const_cast<char *>(setEmpty().c_str());
+
+ if (UserData)
+ bundle_iterate(UserData, bundIterCb, NULL);
+
+ char *search_query = NULL;
+ char *insert_query = NULL;
+ int ret = SQLITE_OK;
+
+ search_query = sqlite3_mprintf("SELECT * FROM %Q WHERE SvcAppId=%Q AND UserId=%Q AND AppStatus=%Q AND JobName=%Q", SYNC_JOB_TABLE, SvcAppId, uid, AppStatus, JobName);
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, search_query, strlen(search_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : search query[%s] ret[%d] err_msg[%s]", search_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_DONE) {
+ sqlite3_reset(stmt);
+ insert_query = sqlite3_mprintf("INSERT INTO %Q (SvcAppId, PkgName, UserId, AppStatus, SyncJobId, SyncType, "
+ "AccountId, JobName, Interval, Expedit, NoRetry, UserDataKey, UserDataValue) "
+ "VALUES (%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q)",
+ SYNC_JOB_TABLE, SvcAppId, PkgName, uid, AppStatus, jobId, SyncType,
+ accId, JobName, interval, expedit, noRetry, UserKey, UserValue);
+
+ ret = sqlite3_prepare_v2(db, insert_query, strlen(insert_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : insert query[%s] ret[%d] err_msg[%s]", insert_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ sqlite3_free(insert_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_OK && ret != SQLITE_DONE) {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), insert_query);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ sqlite3_free(insert_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ LOG_LOGD("result : Insert sync job to DB complete [%s]", insert_query);
+ sqlite3_free(insert_query);
+ } else if (ret == SQLITE_ROW) {
+ LOG_LOGD("[%s] is already registered for [%s] in sync-manager DB", JobName, SvcAppId);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return UpdateSyncJobToDB(SvcAppId, UserId, AppStatus, JobId, SyncType, AccountId, JobName, Interval, Option, UserData);
+ } else {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), search_query);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(search_query);
+ } else {
+ LOG_LOGD("Insert sync job fail : invalid service-app-id");
+ }
+
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 0;
+}
+
+
+int
+RepositoryEngine::UpdateAppStatusToDB(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return -1;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ if (SvcAppId && strlen(SvcAppId) > 0) {
+ char uid[10] = { 0, };
+ snprintf(uid, 10, "%d", UserId);
+
+ char *update_query = NULL;
+ update_query = sqlite3_mprintf("UPDATE %Q SET AppStatus=%Q WHERE SvcAppId=%Q AND PkgName=%Q AND UserId=%Q",
+ SYNC_JOB_TABLE, AppStatus, SvcAppId, PkgName, uid);
+
+ sqlite3_stmt *stmt = NULL;
+ int ret = SQLITE_OK;
+ ret = sqlite3_prepare_v2(db, update_query, strlen(update_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : update query[%s] ret[%d] err_msg[%s]", update_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_OK && ret != SQLITE_DONE) {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), update_query);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ LOG_LOGD("result : Update sync job to DB complete [%s]", update_query);
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ } else {
+ LOG_LOGD("update sync job fail : invalid service-app-id");
+ }
+
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 0;
+}
+
+
+int
+RepositoryEngine::UpdateSyncJobToDB(const char *SvcAppId, int UserId, const char *AppStatus, int JobId, const char *SyncType,
+ int AccountId, const char *JobName, int Interval, int Option, bundle *UserData) {
+
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return -1;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ if (SvcAppId && strlen(SvcAppId) > 0) {
+ char uid[10] = { 0, };
+ snprintf(uid, 10, "%d", UserId);
+ char jobId[10] = { 0, };
+ snprintf(jobId, 10, "%d", JobId);
+ char accId[10] = { 0, };
+ snprintf(accId, 10, "%d", AccountId);
+ char interval[10] = { 0, };
+ snprintf(interval, 10, "%d", Interval);
+ char expedit[2] = { 0, };
+ snprintf(expedit, 2, "%d", Option & SYNC_OPTION_EXPEDITED);
+ char noRetry[2] = { 0, };
+ snprintf(noRetry, 2, "%d", Option & SYNC_OPTION_NO_RETRY);
+
+ UserKey = const_cast<char *>(setEmpty().c_str());
+ UserValue = const_cast<char *>(setEmpty().c_str());
+
+ if (UserData)
+ bundle_iterate(UserData, bundIterCb, NULL);
+
+ char *update_query = NULL;
+
+ update_query = sqlite3_mprintf("UPDATE %Q SET AppStatus=%Q, SyncJobId=%Q, AccountId=%Q, Interval=%Q, "
+ "Expedit=%Q, NoRetry=%Q, UserDataKey=%Q, UserDataValue=%Q "
+ "WHERE SvcAppId=%Q AND PkgName=%Q AND UserId=%Q AND SyncType=%Q AND JobName=%Q",
+ SYNC_JOB_TABLE, AppStatus, jobId, accId, interval, expedit, noRetry, UserKey, UserValue,
+ SvcAppId, SyncManager::GetInstance()->GetPkgIdByAppId(SvcAppId).c_str(), uid, SyncType, JobName);
+
+ sqlite3_stmt *stmt = NULL;
+ int ret = SQLITE_OK;
+ ret = sqlite3_prepare_v2(db, update_query, strlen(update_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : update query[%s] ret[%d] err_msg[%s]", update_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_OK && ret != SQLITE_DONE) {
+ LOG_LOGD("DB error [%d : %s] for [%s]", ret, sqlite3_errmsg(db), update_query);
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ LOG_LOGD("result : Update sync job to DB complete [%s]", update_query);
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(update_query);
+ } else {
+ LOG_LOGD("update sync job fail : invalid service-app-id");
+ }
+
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 0;
+}
+
+
+int
+RepositoryEngine::DeleteSyncJobFromDB(const char *PkgName, int UserId, int JobId) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return -1;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ char uid[10] = { 0, };
+ snprintf(uid, 10, "%d", UserId);
+ char jobId[10] = { 0, };
+ snprintf(jobId, 10, "%d", JobId);
+
+ char *delete_query = NULL;
+ int ret = SQLITE_OK;
+
+ if (PkgName && strlen(PkgName) > 0) {
+ delete_query = sqlite3_mprintf("DELETE FROM %Q WHERE PkgName=%Q AND UserId=%Q AND SyncJobId=%Q", SYNC_JOB_TABLE, PkgName, uid, jobId);
+ } else {
+ LOG_LOGD("Delete sync job fail : invalid package-name");
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, delete_query, strlen(delete_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : delete query[%s] ret[%d] err_msg[%s]", delete_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(delete_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_OK && ret != SQLITE_DONE)
+ LOG_LOGD("step : delete query[%s] ret[%d] err_msg[%s]", delete_query, ret, sqlite3_errmsg(db));
+ else
+ LOG_LOGD("result : Delete sync job from DB complete [%s]", delete_query);
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(delete_query);
+
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 0;
+}
+
+
+int
+RepositoryEngine::DeleteAllSyncJobsFromDB(const char *PkgName, int UserId) {
+ sqlite3 *db = NULL;
+ db = db_open();
+ if (!db) {
+ LOG_LOGD("DB open error");
+ return -1;
+ }
+ LOG_LOGD("sync-manager DB open");
+
+ char uid[10] = { 0, };
+ snprintf(uid, 10, "%d", UserId);
+
+ char *delete_query = NULL;
+ int ret = SQLITE_OK;
+
+ if (PkgName && strlen(PkgName) > 0) {
+ delete_query = sqlite3_mprintf("DELETE FROM %Q WHERE PkgName=%Q AND UserId=%Q", SYNC_JOB_TABLE, PkgName, uid);
+ } else {
+ LOG_LOGD("Delete sync job fail : invalid package-name");
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ sqlite3_stmt *stmt = NULL;
+
+ ret = sqlite3_prepare_v2(db, delete_query, strlen(delete_query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOG_LOGD("prepare : delete query[%s] ret[%d] err_msg[%s]", delete_query, ret, sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_free(delete_query);
+ db_close(db);
+ LOG_LOGD("sync-manager DB close");
+ return -1;
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_OK && ret != SQLITE_DONE)
+ LOG_LOGD("step : delete query[%s] ret[%d] err_msg[%s]", delete_query, ret, sqlite3_errmsg(db));
+ else
+ LOG_LOGD("result : Delete sync job from DB complete [%s]", delete_query);
+
+ sqlite3_reset(stmt);
+ sqlite3_finalize(stmt);
+ sqlite3_free(delete_query);
+
+ db_close(db);
+
+ LOG_LOGD("sync-manager DB close");
+
+ return 0;
+}
+
+
//}//_SyncManager
diff --git a/src/sync-service/SyncManager_RepositoryEngine.h b/src/sync-service/SyncManager_RepositoryEngine.h
index fa10694..5378f93 100644
--- a/src/sync-service/SyncManager_RepositoryEngine.h
+++ b/src/sync-service/SyncManager_RepositoryEngine.h
@@ -38,6 +38,11 @@
#include "SyncManager_SyncJob.h"
#include "SyncManager_PeriodicSyncJob.h"
+#define SYNC_SYS_DB_FILE tzplatform_mkpath(TZ_SYS_HOME, "/owner/.applications/dbspace/.sync-manager.db")
+#define SYNC_ADAPTER_TABLE "syncadapter"
+#define SYNC_JOB_TABLE "syncjob"
+#define ADAPTER_COLUMN_NUM 4
+#define JOB_COLUMN_NUM 13
/*namespace _SyncManager
{
@@ -59,18 +64,33 @@ public:
void OnBooting();
- void SaveCurrentState(void);
-
- void SaveCurrentSyncAdapter(void);
+ void CheckSyncJobsData(void);
- void SaveCurrentSyncJob(void);
+ void CheckSyncJobsDataOnDB(void);
- void CheckSyncJobsData(void);
+ void StartPackageSyncJobs(const char *PackageName, int uid);
- void CancelPackageSyncJobs(const char *PackageName);
+ void CancelPackageSyncJobs(const char *PackageName, int uid);
bool CheckAdapterStatus(const char *PackageName);
+ void RecordSyncAdapter(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus);
+
+ void RecordSyncAdapter(const char *SvcAppId, int UserId, const char *AppStatus);
+
+ void RecordSyncAdapter(const char *PkgName, int UserId);
+
+ void RecordSyncJob(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus, int JobId, const char *SyncType,
+ int AccountId, const char *JobName, int Interval, int Option, bundle *UserData);
+
+ void RecordSyncJob(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus);
+
+ void RecordSyncJob(const char *PkgName, int UserId, int JobId);
+
+ void RecordSyncJob(const char *PkgName, int UserId);
+
+ void DeleteAllSyncData(const char *PkgName, int UserId);
+
public:
static const long NOT_IN_BACKOFF_MODE;
@@ -97,8 +117,31 @@ private:
void ParseSyncJobsN(xmlNodePtr cur, xmlChar* pPackage);
+ int ReadSyncAdaptersFromDB(void);
+
+ int InsertSyncAdapterToDB(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus);
+
+ int UpdateSyncAdapterToDB(const char *SvcAppId, int UserId, const char *AppStatus);
+
+ int DeleteSyncAdapterFromDB(const char *PkgName, int UserId);
+
+ int ReadSyncJobsDataFromDB(void);
+
+ int InsertSyncJobToDB(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus, int JobId, const char *SyncType,
+ int AccountId, const char *JobName, int Interval, int Option, bundle *UserData);
+
+ int UpdateAppStatusToDB(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus);
+
+ int UpdateSyncJobToDB(const char *SvcAppId, int UserId, const char *AppStatus, int JobId, const char *SyncType,
+ int AccountId, const char *JobName, int Interval, int Option, bundle *UserData);
+
+ int DeleteSyncJobFromDB(const char *PkgName, int UserId, int JobId);
+
+ int DeleteAllSyncJobsFromDB(const char *PkgName, int UserId);
+
private:
pthread_mutex_t __capabilityInfoMutex;
+ pthread_mutex_t __syncDBReadWriteMutex;
vector < PeriodicSyncJob * > __pendingJobList; /* Pending periodic job list to be scheduled */
/* map < string, DataSyncJob * > __pendingDataSyncJobList; */ /* Data sync job list to be scheduled */
diff --git a/src/sync-service/SyncManager_SyncAdapterAggregator.cpp b/src/sync-service/SyncManager_SyncAdapterAggregator.cpp
index cbff735..be2b512 100644
--- a/src/sync-service/SyncManager_SyncAdapterAggregator.cpp
+++ b/src/sync-service/SyncManager_SyncAdapterAggregator.cpp
@@ -51,41 +51,41 @@ SyncAdapterAggregator::~SyncAdapterAggregator(void) {
/* LCOV_EXCL_START */
void
-SyncAdapterAggregator::SetAppStatus(const char* pServiceAppUID, const char* pAppStatus) {
- /* Update the application status */
+SyncAdapterAggregator::SetAppStatus(const char* pServiceAppId, const char* pAppStatus) {
+ /* Update the application's status */
for (map<string, string>::iterator iter = __syncAppStatus.begin(); iter != __syncAppStatus.end(); ++iter) {
string appID = iter->first;
- if (!strcmp(pServiceAppUID, appID.c_str())) {
+ if (!strcmp(pServiceAppId, appID.c_str())) {
LOG_LOGD("Sync status already exist and it is set as [%s]", pAppStatus);
iter->second = pAppStatus;
return;
}
}
LOG_LOGD("Sync status is set as [%s]", pAppStatus);
- __syncAppStatus.insert(pair<string, string> (pServiceAppUID, pAppStatus));
+ __syncAppStatus.insert(pair<string, string> (pServiceAppId, pAppStatus));
}
/* LCOV_EXCL_STOP */
void
-SyncAdapterAggregator::AddSyncAdapter(const char* pPackageId, const char* pServiceAppUID) {
+SyncAdapterAggregator::AddSyncAdapter(const char* pPackageId, const char* pServiceAppId) {
if (HasSyncAdapter(pPackageId)) {
LOG_LOGD("Sync adapter already registered for package [%s]", pPackageId); /* LCOV_EXCL_LINE */
} else {
- LOG_LOGD("Registering sync-adapter [%s] for package [%s]", pServiceAppUID, pPackageId);
- __syncAdapterList.insert(pair<string, string> (pPackageId, pServiceAppUID));
+ LOG_LOGD("Registering sync-adapter [%s] for package [%s]", pServiceAppId, pPackageId);
+ __syncAdapterList.insert(pair<string, string> (pPackageId, pServiceAppId));
/* Check the application status was written */
for (map<string, string>::iterator iter = __syncAppStatus.begin(); iter != __syncAppStatus.end(); ++iter) {
string appID = iter->first;
- if (!strcmp(pServiceAppUID, appID.c_str())) {
+ if (!strcmp(pServiceAppId, appID.c_str())) {
LOG_LOGD("Sync status already exist");
return;
}
}
LOG_LOGD("Sync status does not exist and it is set as default value");
- __syncAppStatus.insert(pair<string, string> (pServiceAppUID, "enabled"));
+ __syncAppStatus.insert(pair<string, string> (pServiceAppId, "enabled"));
}
}
@@ -103,20 +103,21 @@ SyncAdapterAggregator::dumpSyncAdapters() {
const char*
-SyncAdapterAggregator::GetSyncAdapter(const char* pPackageId) {
- string pkgName(pPackageId);
- if (pkgName.empty()) {
- LOG_LOGD("Finding sync adapter is failed : pkgName is empty [%s]", pPackageId);
- return NULL;
+SyncAdapterAggregator::GetSyncAdapter(const char* pAppId) {
+ string PkgId(pAppId);
+ if (PkgId.empty()) {
+ //PkgId = SyncManager::GetInstance()->GetPkgIdByCommandline(pAppId);
+ if (PkgId.empty()) /* LCOV_EXCL_LINE */
+ return NULL;
}
- map<string, string>::iterator it = __syncAdapterList.find(pkgName.c_str());
+ map<string, string>::iterator it = __syncAdapterList.find(PkgId.c_str());
if (it != __syncAdapterList.end()) {
LOG_LOGD("Sync adapter is found for account provider id [%s]", it->second.c_str());
return it->second.c_str();
}
- LOG_LOGD("Sync adapter is not found for the package [%s]", pPackageId);
+ LOG_LOGD("Sync adapter is not found for account provider id %s", pAppId);
return NULL;
}
diff --git a/src/sync-service/SyncManager_SyncJob.cpp b/src/sync-service/SyncManager_SyncJob.cpp
index afe1266..2c16ff9 100644
--- a/src/sync-service/SyncManager_SyncJob.cpp
+++ b/src/sync-service/SyncManager_SyncJob.cpp
@@ -48,6 +48,7 @@ SyncJob::~SyncJob(void) {
/* LCOV_EXCL_START */
SyncJob::SyncJob(const SyncJob& job) {
__appId = job.__appId;
+ __uid = job.__uid;
__accountId = job.__accountId;
__syncJobName = job.__syncJobName;
__pExtras = bundle_dup(job.__pExtras);
@@ -61,6 +62,7 @@ SyncJob::SyncJob(const SyncJob& job) {
SyncJob&
SyncJob::operator = (const SyncJob& job) {
__appId = job.__appId;
+ __uid = job.__uid;
__accountId = job.__accountId;
__syncJobName = job.__syncJobName;
__pExtras = bundle_dup(job.__pExtras);
@@ -79,21 +81,24 @@ SyncJob::CleanBundle(bundle* pData) {
/* LCOV_EXCL_STOP */
-SyncJob::SyncJob(const string appId, const string syncJobName, int account, bundle* pExtras, int syncOption, int syncJobId, SyncType syncType)
+SyncJob::SyncJob(const string appId, int uid, const string syncJobName, int account, bundle* pExtras, int syncOption, int syncJobId, SyncType syncType)
: ISyncJob(syncJobId, syncType)
, __appId(appId)
+ , __uid(uid)
, __syncJobName(syncJobName)
, __accountId(account)
, __pExtras(NULL)
, __isExpedited(syncOption & SYNC_OPTION_EXPEDITED)
, __noRetry(syncOption & SYNC_OPTION_NO_RETRY)
, __waitCounter(0) {
+
+ LOG_LOGD("uid: %d", uid);
LOG_LOGD("syncOption: %d", syncOption);
LOG_LOGD("__isExpedited: %d", __isExpedited);
- if (pExtras) {
+ if (pExtras)
__pExtras = bundle_dup(pExtras);
- }
+
__key = ToKey();
}
diff --git a/src/sync-service/SyncManager_SyncJob.h b/src/sync-service/SyncManager_SyncJob.h
index 6c38f4d..adb12a6 100644
--- a/src/sync-service/SyncManager_SyncJob.h
+++ b/src/sync-service/SyncManager_SyncJob.h
@@ -51,7 +51,7 @@ public:
SyncJob &operator = (const SyncJob &job);
- SyncJob(const string appId, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type);
+ SyncJob(const string appId, int uid, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type);
void Reset(int accountId, bundle* pUserData, int syncOption);
@@ -73,6 +73,7 @@ public:
public:
string __appId;
+ int __uid;
string __syncJobName;
int __accountId;
bundle* __pExtras;
diff --git a/src/sync-service/SyncManager_SyncJobDispatcher.cpp b/src/sync-service/SyncManager_SyncJobDispatcher.cpp
index e243176..3ed08f1 100644
--- a/src/sync-service/SyncManager_SyncJobDispatcher.cpp
+++ b/src/sync-service/SyncManager_SyncJobDispatcher.cpp
@@ -66,11 +66,11 @@ SyncJobDispatcher::~SyncJobDispatcher(void) {
int
SyncJobDispatcher::DispatchSyncJob(SyncJob* syncJob) {
- LOG_LOGD("Dispatching sync job [%s], [%s]", syncJob->__appId.c_str(), syncJob->__syncJobName.c_str());
+ LOG_LOGD("Dispatching sync job [%s], [%d], [%s]", syncJob->__appId.c_str(), syncJob->__uid, syncJob->__syncJobName.c_str());
bool isDataSync = (syncJob->GetSyncType() == SYNC_TYPE_DATA_CHANGE);
int ret = SYNC_ERROR_NONE;
- ret = SyncService::GetInstance()->TriggerStartSync(syncJob->__appId.c_str(), syncJob->__accountId, syncJob->__syncJobName.c_str(), isDataSync, syncJob->__pExtras);
+ ret = SyncService::GetInstance()->TriggerStartSync(syncJob->__appId.c_str(), syncJob->__uid, syncJob->__accountId, syncJob->__syncJobName.c_str(), isDataSync, syncJob->__pExtras);
SYNC_LOGE_RET_RES(ret == SYNC_ERROR_NONE, ret, "Failed to start sync job")
if (SyncManager::GetInstance()->__pCurrentSyncJobQueue) {
@@ -105,7 +105,7 @@ SyncJobDispatcher::HandleJobCompletedOrCancelledLocked(SyncStatus res, SyncJob *
case SYNC_STATUS_CANCELLED:
LOG_LOGD("Handle Sync event : SYNC_STATUS_CANCELLED");
- SyncService::GetInstance()->TriggerStopSync(pJob->__appId.c_str(), pJob->__accountId, pJob->__syncJobName.c_str(), (pJob->GetSyncType() == SYNC_TYPE_DATA_CHANGE), pJob->__pExtras);
+ SyncService::GetInstance()->TriggerStopSync(pJob->__appId.c_str(), pJob->__uid, pJob->__accountId, pJob->__syncJobName.c_str(), (pJob->GetSyncType() == SYNC_TYPE_DATA_CHANGE), pJob->__pExtras);
delete pJob;
break;
diff --git a/src/sync-service/SyncManager_SyncJobsAggregator.cpp b/src/sync-service/SyncManager_SyncJobsAggregator.cpp
index 61e9424..b378639 100644
--- a/src/sync-service/SyncManager_SyncJobsAggregator.cpp
+++ b/src/sync-service/SyncManager_SyncJobsAggregator.cpp
@@ -64,8 +64,8 @@ SyncJobsAggregator::GetOrCreateSyncJob(const char* pPackageId, const char* pSync
bool
-SyncJobsAggregator::HasSyncJob(const char* pPackageId, const char* pSyncJobName) {
- ISyncJob* pSyncJob = GetSyncJob(pPackageId, pSyncJobName);
+SyncJobsAggregator::HasSyncJob(const char* pPackageId, int uid, const char* pSyncJobName) {
+ ISyncJob* pSyncJob = GetSyncJob(pPackageId, uid, pSyncJobName);
return pSyncJob != NULL;
}
/* LCOV_EXCL_STOP */
@@ -80,7 +80,6 @@ SyncJobsAggregator::GenerateSyncJobId(const char* pPackageId) {
id = pPackageSyncJobsInfo->GetNextSyncJobId();
} else {
LOG_LOGD("First request for the package [%s]", pPackageId);
-
SyncJobsInfo* pPackageSyncJobsInfo = new (std::nothrow) SyncJobsInfo(pPackageId);
id = pPackageSyncJobsInfo->GetNextSyncJobId();
__syncJobsContainer.insert(make_pair(pPackageId, pPackageSyncJobsInfo));
@@ -91,17 +90,17 @@ SyncJobsAggregator::GenerateSyncJobId(const char* pPackageId) {
void
-SyncJobsAggregator::AddSyncJob(const char* pPackageId, const char* pSyncJobName, ISyncJob* pSyncJob) {
+SyncJobsAggregator::AddSyncJob(const char* pPackageId, int uid, const char* pSyncJobName, ISyncJob* pSyncJob) {
map<string, SyncJobsInfo*>::iterator itr = __syncJobsContainer.find(pPackageId);
if (itr != __syncJobsContainer.end()) {
LOG_LOGD("Sync Jobs info found for package %s", pPackageId);
SyncJobsInfo* pPackageSyncJobsInfo = itr->second;
- pPackageSyncJobsInfo->AddSyncJob(pSyncJobName, pSyncJob);
+ pPackageSyncJobsInfo->AddSyncJob(pSyncJobName, uid, pSyncJob);
} else {
/* LCOV_EXCL_START */
LOG_LOGD("Creating new Sync Jobs info handle for package %s", pPackageId);
SyncJobsInfo* pPackageSyncJobsInfo = new (std::nothrow) SyncJobsInfo(pPackageId);
- pPackageSyncJobsInfo->AddSyncJob(pSyncJobName, pSyncJob);
+ pPackageSyncJobsInfo->AddSyncJob(pSyncJobName, uid, pSyncJob);
__syncJobsContainer.insert(make_pair(pPackageId, pPackageSyncJobsInfo));
/* LCOV_EXCL_STOP */
}
@@ -109,16 +108,18 @@ SyncJobsAggregator::AddSyncJob(const char* pPackageId, const char* pSyncJobName,
int
-SyncJobsAggregator::RemoveSyncJob(const char* pPackageId, int syncJobId) {
+SyncJobsAggregator::RemoveSyncJob(const char* pPackageId, int uid, int syncJobId) {
map<string, SyncJobsInfo*>::iterator itr = __syncJobsContainer.find(pPackageId);
if (itr != __syncJobsContainer.end()) {
SyncJobsInfo* pPackageSyncJobsInfo = itr->second;
- int ret = pPackageSyncJobsInfo->RemoveSyncJob(syncJobId);
- if (pPackageSyncJobsInfo->GetSyncJobsCount() == 0) {
- delete pPackageSyncJobsInfo;
- __syncJobsContainer.erase(itr);
+ if (pPackageSyncJobsInfo->CheckUid(uid, syncJobId)) {
+ int ret = pPackageSyncJobsInfo->RemoveSyncJob(syncJobId);
+ if (pPackageSyncJobsInfo->GetSyncJobsCount() == 0) {
+ delete pPackageSyncJobsInfo;
+ __syncJobsContainer.erase(itr);
+ }
+ return ret;
}
- return ret;
}
return -1;
@@ -128,6 +129,7 @@ SyncJobsAggregator::RemoveSyncJob(const char* pPackageId, int syncJobId) {
/* LCOV_EXCL_START */
int
SyncJobsAggregator::RemoveSyncJob(const char* pPackageId, const char* pSyncJobName) {
+ /* This is for removing OnDemand job after processing it */
map<string, SyncJobsInfo*>::iterator itr = __syncJobsContainer.find(pPackageId);
if (itr != __syncJobsContainer.end()) {
SyncJobsInfo* pPackageSyncJobsInfo = itr->second;
@@ -146,8 +148,8 @@ SyncJobsAggregator::RemoveSyncJob(const char* pPackageId, const char* pSyncJobNa
int
-SyncJobsAggregator::GetSyncJobId(const char* pPackageId, const char* pSyncJobName) {
- ISyncJob* pSyncJob = GetSyncJob(pPackageId, pSyncJobName);
+SyncJobsAggregator::GetSyncJobId(const char* pPackageId, int uid, const char* pSyncJobName) {
+ ISyncJob* pSyncJob = GetSyncJob(pPackageId, uid, pSyncJobName);
int id = (pSyncJob == NULL) ? -1 : pSyncJob->GetSyncJobId();
return id;
@@ -156,14 +158,18 @@ SyncJobsAggregator::GetSyncJobId(const char* pPackageId, const char* pSyncJobNam
ISyncJob*
-SyncJobsAggregator::GetSyncJob(const char* pPackageId, const char* pSyncJobName) {
+SyncJobsAggregator::GetSyncJob(const char* pPackageId, int uid, const char* pSyncJobName) {
ISyncJob* pSyncJob = NULL;
map<string, SyncJobsInfo*>::iterator itr = __syncJobsContainer.find(pPackageId);
if (itr != __syncJobsContainer.end()) {
SyncJobsInfo* pPackageSyncJobsInfo = itr->second;
pSyncJob = pPackageSyncJobsInfo->GetSyncJob(pSyncJobName);
+ if (pSyncJob) {
+ /* If there is no syncJob has same uid */
+ if (uid != pPackageSyncJobsInfo->__syncJobId[pSyncJob->GetSyncJobId()])
+ return NULL;
+ }
}
-
return pSyncJob;
}
@@ -184,12 +190,13 @@ SyncJobsAggregator::HandlePackageUninstalled(const char* pPackageId) {
ISyncJob*
-SyncJobsAggregator::GetSyncJob(const char* pPackageId, int syncJobId) {
+SyncJobsAggregator::GetSyncJob(const char* pPackageId, int uid, int syncJobId) {
ISyncJob* pSyncJob = NULL;
map<string, SyncJobsInfo*>::iterator itr = __syncJobsContainer.find(pPackageId);
if (itr != __syncJobsContainer.end()) {
SyncJobsInfo* pPackageSyncJobsInfo = itr->second;
- pSyncJob = pPackageSyncJobsInfo->GetSyncJob(syncJobId);
+ if (uid == 0 || pPackageSyncJobsInfo->CheckUid(uid, syncJobId))
+ pSyncJob = pPackageSyncJobsInfo->GetSyncJob(syncJobId);
} else {
LOG_LOGD("Sync jobs for package %s are not found", pPackageId); /* LCOV_EXCL_LINE */
}
@@ -214,9 +221,8 @@ SyncJobsAggregator::GetSyncJobIDList(const char* pPackageId) {
SyncJobsInfo*
SyncJobsAggregator::GetSyncJobsInfo(const char* pPackageId) {
map<string, SyncJobsInfo*>::iterator itr = __syncJobsContainer.find(pPackageId);
- if (itr != __syncJobsContainer.end()) {
+ if (itr != __syncJobsContainer.end())
return itr->second;
- }
return NULL;
}
diff --git a/src/sync-service/SyncManager_SyncJobsAggregator.h b/src/sync-service/SyncManager_SyncJobsAggregator.h
index 99a42b2..4abbf87 100644
--- a/src/sync-service/SyncManager_SyncJobsAggregator.h
+++ b/src/sync-service/SyncManager_SyncJobsAggregator.h
@@ -44,21 +44,21 @@ using namespace std;
class SyncJobsAggregator {
public:
- void AddSyncJob(const char* pPackageId, const char* pSyncJobName, ISyncJob* pSyncJob);
+ void AddSyncJob(const char* pPackageId, int uid, const char* pSyncJobName, ISyncJob* pSyncJob);
- int RemoveSyncJob(const char* pPackageId, int jobId);
+ int RemoveSyncJob(const char* pPackageId, int uid, int jobId);
int RemoveSyncJob(const char* pPackageId, const char* pSyncJobName);
- bool HasSyncJob(const char* pPackageId, const char* pSyncJobName);
+ bool HasSyncJob(const char* pPackageId, int uid, const char* pSyncJobName);
- int GetSyncJobId(const char* pPackageId, const char* pSyncJobName);
+ int GetSyncJobId(const char* pPackageId, int uid, const char* pSyncJobName);
int GenerateSyncJobId(const char* pPackageId);
- ISyncJob* GetSyncJob(const char* pPackageId, const char* pSyncJobName);
+ ISyncJob* GetSyncJob(const char* pPackageId, int uid, const char* pSyncJobName);
- ISyncJob* GetSyncJob(const char* pPackageId, int syncJobId);
+ ISyncJob* GetSyncJob(const char* pPackageId, int uid, int syncJobId);
vector < int > GetSyncJobIDList(const char* pPackageId);
diff --git a/src/sync-service/SyncManager_SyncJobsInfo.cpp b/src/sync-service/SyncManager_SyncJobsInfo.cpp
index 69f4128..efef10a 100644
--- a/src/sync-service/SyncManager_SyncJobsInfo.cpp
+++ b/src/sync-service/SyncManager_SyncJobsInfo.cpp
@@ -37,17 +37,16 @@ SyncJobsInfo::~SyncJobsInfo(void) {
SyncJobsInfo::SyncJobsInfo(string packageId)
: __packageId(packageId) {
- for (int i = 0; i < SYNC_JOB_LIMIT; i++) {
- __syncJobId[i] = false;
- }
+ for (int i = 0; i < SYNC_JOB_LIMIT; i++)
+ __syncJobId[i] = 0;
}
int
-SyncJobsInfo::AddSyncJob(string syncJobName, ISyncJob* pSyncJob) {
+SyncJobsInfo::AddSyncJob(string syncJobName, int uid, ISyncJob* pSyncJob) {
__syncJobsList.insert(make_pair(syncJobName, pSyncJob));
__syncIdList.insert(make_pair(pSyncJob->GetSyncJobId(), pSyncJob));
- __syncJobId[pSyncJob->GetSyncJobId()] = true;
+ __syncJobId[pSyncJob->GetSyncJobId()] = uid;
return SYNC_ERROR_NONE;
}
@@ -75,6 +74,17 @@ SyncJobsInfo::GetSyncJob(int syncJobId) {
}
+bool
+SyncJobsInfo::CheckUid(int uid, int syncJobId) {
+ if (uid == __syncJobId[syncJobId]) {
+ LOG_LOGD("caller uid[%d] and syncJob's uid[%d] are same", uid, __syncJobId[syncJobId]);
+ return true;
+ }
+ LOG_LOGD("caller uid[%d] and syncJob's uid[%d] are different", uid, __syncJobId[syncJobId]);
+ return false;
+}
+
+
int
SyncJobsInfo::RemoveSyncJob(int syncJobId) {
map<int, ISyncJob*>::iterator itr = __syncIdList.find(syncJobId);
@@ -95,7 +105,7 @@ SyncJobsInfo::RemoveSyncJob(string syncJobname) {
if (itr != __syncJobsList.end()) {
ISyncJob* pSyncJob = itr->second;
int syncJobId = pSyncJob->GetSyncJobId();
- __syncJobId[syncJobId] = false;
+ __syncJobId[syncJobId] = 0;
LOG_LOGD("Removing job name [%s] id [%d] from package [%s]", syncJobname.c_str(), syncJobId, __packageId.c_str());
delete pSyncJob;
@@ -116,7 +126,8 @@ SyncJobsInfo::RemoveAllSyncJobs() {
map<int, ISyncJob*>::iterator itr = __syncIdList.begin();
while (itr != __syncIdList.end()) {
- SyncManager::GetInstance()->RemoveSyncJob(__packageId.c_str(), itr->first);
+ /* 0 means that can get and remove sync jobs without condition */
+ SyncManager::GetInstance()->RemoveSyncJob(__packageId.c_str(), 0, itr->first);
itr++;
}
}
@@ -135,9 +146,8 @@ SyncJobsInfo::GetNextSyncJobId() {
}
}
- if (idx == SYNC_JOB_LIMIT) {
+ if (idx == SYNC_JOB_LIMIT)
value = SYNC_JOB_LIMIT + 1;
- }
return value;
}
@@ -150,9 +160,8 @@ SyncJobsInfo::GetSyncJobIdList() {
int idx;
for (idx = 0; idx < SYNC_JOB_LIMIT; idx++) {
- if (__syncJobId[idx]) {
+ if (__syncJobId[idx])
idList.push_back(idx);
- }
}
return idList;
}
diff --git a/src/sync-service/SyncManager_SyncJobsInfo.h b/src/sync-service/SyncManager_SyncJobsInfo.h
index d939ca7..cbacf18 100644
--- a/src/sync-service/SyncManager_SyncJobsInfo.h
+++ b/src/sync-service/SyncManager_SyncJobsInfo.h
@@ -46,11 +46,13 @@ public:
ISyncJob* GetSyncJob(int syncJobId);
+ bool CheckUid(int uid, int syncJobId);
+
int RemoveSyncJob(int syncJobId);
int RemoveSyncJob(string syncJobName);
- int AddSyncJob(string syncJobName, ISyncJob* pSyncJob);
+ int AddSyncJob(string syncJobName, int uid, ISyncJob* pSyncJob);
int GetNextSyncJobId();
@@ -71,7 +73,7 @@ public:
map < string, ISyncJob * > __syncJobsList;
map < int, ISyncJob * > __syncIdList;
string __packageId;
- bool __syncJobId[SYNC_JOB_LIMIT + 1];
+ int __syncJobId[SYNC_JOB_LIMIT + 1];
};
/*
diff --git a/src/sync-service/SyncManager_SyncManager.cpp b/src/sync-service/SyncManager_SyncManager.cpp
index 9e1d8f0..45cf0ed 100644
--- a/src/sync-service/SyncManager_SyncManager.cpp
+++ b/src/sync-service/SyncManager_SyncManager.cpp
@@ -71,7 +71,7 @@ SyncManager::GetSyncSetting() {
int
-SyncManager::AddOnDemandSync(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId) {
+SyncManager::AddOnDemandSync(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId) {
const char* pSyncAdapterApp = __pSyncAdapterAggregator->GetSyncAdapter(pPackageId.c_str());
SYNC_LOGE_RET_RES(pSyncAdapterApp != NULL, SYNC_ERROR_SYNC_ADAPTER_NOT_FOUND, "Sync adapter cannot be found for package %s", pPackageId.c_str());
@@ -82,10 +82,10 @@ SyncManager::AddOnDemandSync(string pPackageId, const char* syncJobName, int acc
/* LCOV_EXCL_STOP */
}
- SyncJob* pJob = new (std::nothrow) SyncJob(pSyncAdapterApp, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_ON_DEMAND);
+ SyncJob* pJob = new (std::nothrow) SyncJob(pSyncAdapterApp, uid, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_ON_DEMAND);
SYNC_LOGE_RET_RES(pJob != NULL, SYNC_ERROR_OUT_OF_MEMORY, "Failed to construct SyncJob");
- __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), syncJobName, pJob);
+ __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), uid, syncJobName, pJob);
ScheduleSyncJob(pJob);
@@ -107,7 +107,7 @@ SyncManager::CancelSync(SyncJob* pSyncJob) {
int
-SyncManager::AddPeriodicSyncJob(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, long period) {
+SyncManager::AddPeriodicSyncJob(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, long period) {
if (period < 1800) {
/* LCOV_EXCL_START */
LOG_LOGD("Requested period %d is less than minimum, rounding up to 30 mins", period);
@@ -126,10 +126,10 @@ SyncManager::AddPeriodicSyncJob(string pPackageId, const char* syncJobName, int
/* LCOV_EXCL_STOP */
}
- PeriodicSyncJob* pRequestedJob = new (std::nothrow) PeriodicSyncJob(pSyncAdapterApp, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_PERIODIC, period / 60);
+ PeriodicSyncJob* pRequestedJob = new (std::nothrow) PeriodicSyncJob(pSyncAdapterApp, uid, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_PERIODIC, period / 60);
SYNC_LOGE_RET_RES(pRequestedJob != NULL, SYNC_ERROR_OUT_OF_MEMORY, "Failed to construct periodic SyncJob");
- __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), syncJobName, pRequestedJob);
+ __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), uid, syncJobName, pRequestedJob);
__pPeriodicSyncScheduler->SchedulePeriodicSyncJob(pRequestedJob);
if (pRequestedJob->IsExpedited()) {
@@ -144,7 +144,7 @@ SyncManager::AddPeriodicSyncJob(string pPackageId, const char* syncJobName, int
int
-SyncManager::AddDataSyncJob(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, const char* pCapability) {
+SyncManager::AddDataSyncJob(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, const char* pCapability) {
const char* pSyncAdapterApp = __pSyncAdapterAggregator->GetSyncAdapter(pPackageId.c_str());
SYNC_LOGE_RET_RES(pSyncAdapterApp != NULL, SYNC_ERROR_SYNC_ADAPTER_NOT_FOUND, "Sync adapter cannot be found for package %s", pPackageId.c_str());
LOG_LOGD("Found sync adapter [%s]", pSyncAdapterApp);
@@ -156,10 +156,10 @@ SyncManager::AddDataSyncJob(string pPackageId, const char* syncJobName, int acco
/* LCOV_EXCL_STOP */
}
- DataSyncJob* pRequestedJob = new (std::nothrow) DataSyncJob(pSyncAdapterApp, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_DATA_CHANGE, pCapability);
+ DataSyncJob* pRequestedJob = new (std::nothrow) DataSyncJob(pSyncAdapterApp, uid, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_DATA_CHANGE, pCapability);
SYNC_LOGE_RET_RES(pRequestedJob != NULL, SYNC_ERROR_OUT_OF_MEMORY, "Failed to construct periodic SyncJob");
- __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), syncJobName, pRequestedJob);
+ __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), uid, syncJobName, pRequestedJob);
__pDataChangeSyncScheduler->AddDataSyncJob(syncJobName, pRequestedJob);
if (pRequestedJob->IsExpedited()) {
@@ -174,11 +174,11 @@ SyncManager::AddDataSyncJob(string pPackageId, const char* syncJobName, int acco
int
-SyncManager::RemoveSyncJob(string packageId, int syncJobId) {
+SyncManager::RemoveSyncJob(string packageId, int uid, int syncJobId) {
LOG_LOGD("Starts");
int ret = SYNC_ERROR_NONE;
- ISyncJob* pSyncJob = __pSyncJobsAggregator->GetSyncJob(packageId.c_str(), syncJobId);
+ ISyncJob* pSyncJob = __pSyncJobsAggregator->GetSyncJob(packageId.c_str(), uid, syncJobId);
SYNC_LOGE_RET_RES(pSyncJob != NULL, SYNC_ERROR_UNKNOWN, "Sync job for id [%d] doesnt exist or already removed", syncJobId);
SyncType syncType = pSyncJob->GetSyncType();
@@ -200,7 +200,7 @@ SyncManager::RemoveSyncJob(string packageId, int syncJobId) {
CancelSync(pJob);
- __pSyncJobsAggregator->RemoveSyncJob(packageId.c_str(), syncJobId);
+ __pSyncJobsAggregator->RemoveSyncJob(packageId.c_str(), uid, syncJobId);
return ret;
}
@@ -363,14 +363,20 @@ SyncManager::OnBatteryStatusChanged(int value) {
static int
OnPackageUninstalled(unsigned int userId, int reqId, const char* pPkgType, const char* pPkgId, const char* pKey, const char* pVal, const void* pMsg, void* pData) {
- LOG_LOGD("OnPackageUninstalled [type %s] type [pkdId:%s]", pPkgType, pPkgId);
+ LOG_LOGD("OnPackageUninstalled [type: %s] type [pkdId: %s]", pPkgType, pPkgId);
if (!strcmp("end", pKey) && !strcmp("ok", pVal)) {
+ if (userId <= 5000)
+ userId = 5001;
+
+ LOG_LOGD("OnPackageUninstalled [package type : %s] [package Id : %s] [uid : %d]", pPkgType, pPkgId, (int)userId);
+ //TODO: Should below functions consider uid ?
SyncManager::GetInstance()->GetSyncAdapterAggregator()->HandlePackageUninstalled(pPkgId);
SyncManager::GetInstance()->GetSyncJobsAggregator()->HandlePackageUninstalled(pPkgId);
- }
- SyncManager::GetInstance()->GetSyncRepositoryEngine()->SaveCurrentState();
- SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsData();
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->RecordSyncAdapter(pPkgId, userId);
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->RecordSyncJob(pPkgId, userId);
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsDataOnDB();
+ }
return 0;
}
@@ -386,7 +392,6 @@ OnAppStatusChanged(uid_t uid, int req_id, const char *pkg_type, const char *pack
LOG_LOGD("package_name: [%s], app_id: [%s], key: [%s], val: [%s], req_id: [%d], uid: [%d]", package_name, app_id, key, val, req_id, uid);
SyncAdapterAggregator* pAggregator = SyncManager::GetInstance()->GetSyncAdapterAggregator();
-
if (!pAggregator->HasSyncAdapter(package_name)) {
LOG_LOGD("[%s] doesn't use sync-manager", package_name);
return 0;
@@ -394,13 +399,15 @@ OnAppStatusChanged(uid_t uid, int req_id, const char *pkg_type, const char *pack
if (!strcmp(val, "enable_app")) {
pAggregator->SetAppStatus(app_id, "enabled");
- SyncManager::GetInstance()->RecordSyncAdapter();
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->RecordSyncJob(app_id, package_name, (int)uid, "enabled");
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->RecordSyncAdapter(app_id, (int)uid, "enabled");
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->StartPackageSyncJobs(package_name, (int)uid);
} else if (!strcmp(val, "disable_app")) {
pAggregator->SetAppStatus(app_id, "disabled");
- SyncManager::GetInstance()->RecordSyncAdapter();
- SyncManager::GetInstance()->GetSyncRepositoryEngine()->CancelPackageSyncJobs(package_name);
- SyncManager::GetInstance()->RecordSyncJob();
- SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsData();
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->RecordSyncJob(app_id, package_name, (int)uid, "disabled");
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->RecordSyncAdapter(app_id, (int)uid, "disabled");
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->CancelPackageSyncJobs(package_name, (int)uid);
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsDataOnDB();
}
return 0;
@@ -917,7 +924,6 @@ SyncManager::GetManageIdleState() {
void
SyncManager::HandleShutdown(void) {
pthread_mutex_lock(&__syncJobQueueMutex);
- __pSyncRepositoryEngine->SaveCurrentState();
SyncManager::GetInstance()->Destruct();
pthread_mutex_unlock(&__syncJobQueueMutex);
}
@@ -925,17 +931,50 @@ SyncManager::HandleShutdown(void) {
/* LCOV_EXCL_START */
void
-SyncManager::RecordSyncAdapter(void) {
+SyncManager::RecordSyncAdapter(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus) {
+ pthread_mutex_lock(&__syncJobQueueMutex);
+ __pSyncRepositoryEngine->RecordSyncAdapter(SvcAppId, PkgName, UserId, AppStatus);
+ pthread_mutex_unlock(&__syncJobQueueMutex);
+}
+
+
+void
+SyncManager::RecordSyncAdapter(const char *PkgName, int UserId, const char *AppStatus) {
+ pthread_mutex_lock(&__syncJobQueueMutex);
+ __pSyncRepositoryEngine->RecordSyncAdapter(PkgName, UserId, AppStatus);
+ pthread_mutex_unlock(&__syncJobQueueMutex);
+}
+
+
+void
+SyncManager::RecordSyncAdapter(const char *PkgName, int UserId) {
+ pthread_mutex_lock(&__syncJobQueueMutex);
+ __pSyncRepositoryEngine->RecordSyncAdapter(PkgName, UserId);
+ pthread_mutex_unlock(&__syncJobQueueMutex);
+}
+
+
+void
+SyncManager::RecordSyncJob(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus, int JobId, const char *SyncType,
+ int AccountId, const char *JobName, int Interval, int Option, bundle *UserData) {
+ pthread_mutex_lock(&__syncJobQueueMutex);
+ __pSyncRepositoryEngine->RecordSyncJob(SvcAppId, PkgName, UserId, AppStatus, JobId, SyncType, AccountId, JobName, Interval, Option, UserData);
+ pthread_mutex_unlock(&__syncJobQueueMutex);
+}
+
+
+void
+SyncManager::RecordSyncJob(const char *PkgName, int UserId, int JobId) {
pthread_mutex_lock(&__syncJobQueueMutex);
- __pSyncRepositoryEngine->SaveCurrentSyncAdapter();
+ __pSyncRepositoryEngine->RecordSyncJob(PkgName, UserId, JobId);
pthread_mutex_unlock(&__syncJobQueueMutex);
}
void
-SyncManager::RecordSyncJob(void) {
+SyncManager::RecordSyncJob(const char *PkgName, int UserId) {
pthread_mutex_lock(&__syncJobQueueMutex);
- __pSyncRepositoryEngine->SaveCurrentSyncJob();
+ __pSyncRepositoryEngine->RecordSyncJob(PkgName, UserId);
pthread_mutex_unlock(&__syncJobQueueMutex);
}
/* LCOV_EXCL_STOP */
@@ -989,9 +1028,9 @@ SyncManager::SendCancelSyncsMessage(SyncJob* pJob) {
void
-SyncManager::OnResultReceived(SyncStatus res, string svcAppUID, string packageId, const char* syncJobName) {
+SyncManager::OnResultReceived(SyncStatus res, string svcAppId, string packageId, const char* syncJobName) {
string key;
- key.append("id:").append(svcAppUID).append(syncJobName);
+ key.append("id:").append(svcAppId).append(syncJobName);
LOG_LOGD("Close Sync context for key %s", key.c_str());
diff --git a/src/sync-service/SyncManager_SyncManager.h b/src/sync-service/SyncManager_SyncManager.h
index b93fdfe..000e0c9 100644
--- a/src/sync-service/SyncManager_SyncManager.h
+++ b/src/sync-service/SyncManager_SyncManager.h
@@ -30,6 +30,7 @@
#include <account.h>
#include <aul.h>
#include <aul_svc.h>
+#include <db-util.h>
#include <package-manager.h>
#include <media_content_type.h>
#include "sync_manager.h"
@@ -69,15 +70,15 @@ public:
bool GetSyncSetting();
- int AddOnDemandSync(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId);
+ int AddOnDemandSync(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId);
int CancelSync(SyncJob* pJob);
- int AddPeriodicSyncJob(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, long period);
+ int AddPeriodicSyncJob(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, long period);
- int AddDataSyncJob(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, const char* pCapability);
+ int AddDataSyncJob(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, const char* pCapability);
- int RemoveSyncJob(string packageId, int syncJobId);
+ int RemoveSyncJob(string packageId, int uid, int syncJobId);
SyncJobQueue* GetSyncJobQueue(void) const;
@@ -124,7 +125,7 @@ public:
void AlertForChange();
- void OnResultReceived(SyncStatus res, string svcAppUID, string packageId, const char* syncJobName);
+ void OnResultReceived(SyncStatus res, string svcAppId, string packageId, const char* syncJobName);
string GetPkgIdByAppId(const char* pAppId);
@@ -132,9 +133,18 @@ public:
void HandleShutdown(void);
- void RecordSyncAdapter(void);
+ void RecordSyncAdapter(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus);
- void RecordSyncJob(void);
+ void RecordSyncAdapter(const char *PkgName, int UserId, const char *AppStatus);
+
+ void RecordSyncAdapter(const char *PkgName, int UserId);
+
+ void RecordSyncJob(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus, int JobId, const char *SyncType,
+ int AccountId, const char *JobName, int Interval, int Option, bundle *UserData);
+
+ void RecordSyncJob(const char *PkgName, int UserId, int JobId);
+
+ void RecordSyncJob(const char *PkgName, int UserId);
void CloseCurrentSyncContext(CurrentSyncContext *activeSyncContext);
diff --git a/src/sync-service/SyncManager_SyncService.cpp b/src/sync-service/SyncManager_SyncService.cpp
index 3728d45..1882f41 100644
--- a/src/sync-service/SyncManager_SyncService.cpp
+++ b/src/sync-service/SyncManager_SyncService.cpp
@@ -339,54 +339,28 @@ gboolean sync_adapter_handle_send_result(TizenSyncAdapter* pObject, GDBusMethodI
/* LCOV_EXCL_START */
int
-SyncService::TriggerStartSync(const char* appUID, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras) {
- LOG_LOGD("appUID [%s] syncJobName [%s]", appUID, syncJobName);
-
- char pAppId[strlen(appUID) + 1] = { 0, };
- strcpy(pAppId, appUID);
-
- char pServiceAppId[strlen(pAppId) + 1] = { 0, };
- char *temp;
- int uid = -1;
- int stage = 1;
-
- /* Divide appId#uid */
- temp = strtok(pAppId, "#");
- while (temp != NULL) {
- if (stage == 1) {
- strcpy(pServiceAppId, temp);
- LOG_LOGD("step %d. pServiceAppId [%s]", stage, pServiceAppId);
- } else if (stage == 2) {
- uid = atoi(temp);
- LOG_LOGD("step %d. uid [%d]", stage, uid);
- }
- stage++;
- temp = strtok(NULL, "#");
- }
+SyncService::TriggerStartSync(const char* appId, int uid, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras) {
+ LOG_LOGD("Trigger start sync [%s], uid [%d], syncJobName [%s]", appId, uid, syncJobName);
int ret = SYNC_ERROR_NONE;
- ret = aul_app_get_status_for_uid(pServiceAppId, uid);
+ ret = aul_app_get_status_for_uid(appId, uid);
if (ret == -1) {
/* Send launch request to wake application */
- LOG_LOGD("[%s] is not running, launch the app and wait for signal", pServiceAppId);
+ LOG_LOGD("[%s] is not running, launch the app and wait for signal", appId);
- /*
- // for setting background launch
+ /* For setting background launch */
ret = aul_svc_set_background_launch(pExtras, true);
- SYNC_LOGE_RET_RES(ret >= AUL_R_OK, SYNC_ERROR_SYSTEM, "ERROR : aul_svc_set_background_launch() failed for appId[%s], result[%d : %s]", pServiceAppId, ret, get_error_message(ret));
- */
+ SYNC_LOGE_RET_RES(ret >= AUL_R_OK, SYNC_ERROR_SYSTEM, "ERROR : aul_svc_set_background_launch() failed for appId[%s], result[%d : %s]", appId, ret, get_error_message(ret));
- ret = aul_launch_app_for_uid(pServiceAppId, pExtras, uid);
- SYNC_LOGE_RET_RES(ret >= AUL_R_OK, SYNC_ERROR_SYSTEM, "ERROR : aul_launch_app_for_uid() failed for appId[%s], result[%d : %s]", pServiceAppId, ret, get_error_message(ret));
+ aul_launch_app_for_uid(appId, pExtras, uid);
+ SYNC_LOGE_RET_RES(ret >= AUL_R_OK, SYNC_ERROR_SYSTEM, "ERROR : aul_launch_app_for_uid() failed for appId[%s], result[%d : %s]", appId, ret, get_error_message(ret));
sa_app_id.clear();
return SYNC_ERROR_SYSTEM;
} else {
- LOG_LOGD("[%s] app is already running", pServiceAppId);
-
- /* Find pSyncAdapter in hash table with appId#uid */
- TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, appUID);
+ LOG_LOGD("[%s] app is already running", appId);
+ TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*)g_hash_table_lookup(g_hash_table, appId);
if (!pSyncAdapter) {
LOG_LOGD("Sync adapter entry not found. Preparing sync adapter object");
@@ -394,7 +368,7 @@ SyncService::TriggerStartSync(const char* appUID, int accountId, const char* syn
app_context_h app_context = NULL;
pid_t pid;
- int ret = app_manager_get_app_context(pServiceAppId, &app_context);
+ int ret = app_manager_get_app_context(appId, &app_context);
SYNC_LOGE_RET_RES(ret == APP_MANAGER_ERROR_NONE, SYNC_ERROR_SYSTEM, "getting app_context is failed");
ret = app_context_get_pid(app_context, &pid);
@@ -412,9 +386,8 @@ SyncService::TriggerStartSync(const char* appUID, int accountId, const char* syn
if (g_dbus_interface_skeleton_export(interface, gdbusConnection, obj_path, &error)) {
g_signal_connect(pSyncAdapter, "handle-send-result", G_CALLBACK(sync_adapter_handle_send_result), NULL);
- /* appId#uid */
- LOG_LOGD("inserting sync adapter ipc %s %x", appUID, pSyncAdapter);
- g_hash_table_insert(g_hash_table, strdup(appUID), pSyncAdapter);
+ LOG_LOGD("inserting sync adapter ipc %s %x", appId, pSyncAdapter);
+ g_hash_table_insert(g_hash_table, (gchar*)appId, pSyncAdapter);
} else {
SYNC_LOGE_RET_RES(!(error->message), SYNC_ERROR_SYSTEM, "export failed [%s]", error->message);
return SYNC_ERROR_SYSTEM;
@@ -433,10 +406,10 @@ SyncService::TriggerStartSync(const char* appUID, int accountId, const char* syn
void
-SyncService::TriggerStopSync(const char* appUID, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras) {
- LOG_LOGD("Trigger stop sync [%s]", appUID);
+SyncService::TriggerStopSync(const char* appId, int uid, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras) {
+ LOG_LOGD("Trigger stop sync [%s], uid [%d], syncJobName [%s]", appId, uid, syncJobName);
- TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, appUID);
+ TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*)g_hash_table_lookup(g_hash_table, appId);
if (!pSyncAdapter) {
LOG_LOGD("Failed to lookup syncadapter");
return;
@@ -450,13 +423,13 @@ SyncService::TriggerStopSync(const char* appUID, int accountId, const char* sync
int
-SyncService::RequestOnDemandSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, int* pSyncJobId) {
+SyncService::RequestOnDemandSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, int* pSyncJobId) {
int ret = SYNC_ERROR_NONE;
int syncJobId = -1;
SyncJobsAggregator* pSyncJobsAggregator = __pSyncManagerInstance->GetSyncJobsAggregator();
- ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName);
+ ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, uid, pSyncJobName);
if (pSyncJob) {
SyncJob* pSyncJobEntry = dynamic_cast< SyncJob* > (pSyncJob);
SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get sync job");
@@ -471,7 +444,7 @@ SyncService::RequestOnDemandSync(const char* pPackageId, const char* pSyncJobNam
SYNC_LOGE_RET_RES(syncJobId <= SYNC_JOB_LIMIT, SYNC_ERROR_QUOTA_EXCEEDED, "Sync job quota exceeded");
LOG_LOGD("New sync request. Adding sync job with Sync job name [%s] Sync job id [%d]", pSyncJobName, syncJobId);
- ret = __pSyncManagerInstance->AddOnDemandSync(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId);
+ ret = __pSyncManagerInstance->AddOnDemandSync(pPackageId, uid, pSyncJobName, accountId, pExtras, syncOption, syncJobId);
}
if (ret == SYNC_ERROR_NONE)
@@ -482,7 +455,7 @@ SyncService::RequestOnDemandSync(const char* pPackageId, const char* pSyncJobNam
int
-SyncService::RequestPeriodicSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId) {
+SyncService::RequestPeriodicSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId) {
int ret = SYNC_ERROR_NONE;
int syncJobId = -1;
@@ -491,7 +464,7 @@ SyncService::RequestPeriodicSync(const char* pPackageId, const char* pSyncJobNam
pSyncJobsAggregator->SetMinPeriod((int)pollFrequency / 60);
pSyncJobsAggregator->SetLimitTime(pSyncJobsAggregator->GetMinPeriod());
- ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName);
+ ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, uid, pSyncJobName);
if (pSyncJob) {
PeriodicSyncJob* pSyncJobEntry = dynamic_cast< PeriodicSyncJob* > (pSyncJob);
SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get syn job");
@@ -511,7 +484,7 @@ SyncService::RequestPeriodicSync(const char* pPackageId, const char* pSyncJobNam
SYNC_LOGE_RET_RES(syncJobId <= SYNC_JOB_LIMIT, SYNC_ERROR_QUOTA_EXCEEDED, "Sync job quota exceeded");
LOG_LOGD("New sync request. Adding sync job with Sync job name [%s] Sync job id [%d]", pSyncJobName, syncJobId);
- ret = __pSyncManagerInstance->AddPeriodicSyncJob(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pollFrequency);
+ ret = __pSyncManagerInstance->AddPeriodicSyncJob(pPackageId, uid, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pollFrequency);
}
if (ret == SYNC_ERROR_NONE)
@@ -522,12 +495,12 @@ SyncService::RequestPeriodicSync(const char* pPackageId, const char* pSyncJobNam
int
-SyncService::RequestDataSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, const char* pCapability, int* pSyncJobId) {
+SyncService::RequestDataSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, const char* pCapability, int* pSyncJobId) {
int ret = SYNC_ERROR_NONE;
SyncJobsAggregator* pSyncJobsAggregator = __pSyncManagerInstance->GetSyncJobsAggregator();
int syncJobId = -1;
- ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName);
+ ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, uid, pSyncJobName);
if (pSyncJob) {
DataSyncJob* pSyncJobEntry = dynamic_cast< DataSyncJob* > (pSyncJob);
SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get syn job");
@@ -547,7 +520,7 @@ SyncService::RequestDataSync(const char* pPackageId, const char* pSyncJobName, i
SYNC_LOGE_RET_RES(syncJobId <= SYNC_JOB_LIMIT, SYNC_ERROR_QUOTA_EXCEEDED, "Sync job quota exceeded");
LOG_LOGD("New sync request. Adding sync job with Sync job name [%s] Sync job id [%d]", pSyncJobName, syncJobId);
- ret = __pSyncManagerInstance->AddDataSyncJob(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pCapability);
+ ret = __pSyncManagerInstance->AddDataSyncJob(pPackageId, uid, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pCapability);
}
if (ret == SYNC_ERROR_NONE)
@@ -627,6 +600,7 @@ get_service_name_by_pid(guint pid, char** pAppId) {
g_variant_get(va, "s", &name);
*pAppId = strdup(name);
LOG_LOGD("DBus service [%s]", *pAppId);
+ free(name);
}
}
@@ -681,20 +655,18 @@ sync_adapter_handle_send_result(TizenSyncAdapter* pObject, GDBusMethodInvocation
pkgIdStr = SyncManager::GetInstance()->GetPkgIdByCommandline(pCommandLine);
}
- char pServiceAppUID[100];
- snprintf(pServiceAppUID, 100, "%s#%d", pAppId, getuid());
- LOG_LOGD("pid[%d], pServiceAppUID [%s]", (int)pid, pServiceAppUID);
-
if (!pkgIdStr.empty()) {
LOG_LOGD("Sync result received from [%s]: sync_job_name [%s] result [%d]", pAppId, sync_job_name, sync_result);
- SyncManager::GetInstance()->OnResultReceived((SyncStatus)sync_result, pServiceAppUID, pkgIdStr, sync_job_name);
- free(pAppId);
+ SyncManager::GetInstance()->OnResultReceived((SyncStatus)sync_result, pAppId, pkgIdStr, sync_job_name);
} else {
LOG_LOGD("sync service: Get package Id fail %d", ret);
}
tizen_sync_adapter_complete_send_result(pObject, pInvocation);
+ if (pAppId)
+ free(pAppId);
+
return true;
}
@@ -725,12 +697,14 @@ sync_adapter_handle_init_complete(TizenSyncAdapter* pObject, GDBusMethodInvocati
*/
gboolean
sync_manager_add_on_demand_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation,
+ const gchar* uid,
const gchar* pCommandLine,
gint accountId,
const gchar* pSyncJobName,
gint sync_option,
GVariant* pSyncJobUserData) {
LOG_LOGD("Received On-Demand Sync request");
+ LOG_LOGD("Caller UID : %s", (const char*)uid);
guint pid = get_caller_pid(pInvocation);
string pkgIdStr;
@@ -751,7 +725,7 @@ sync_manager_add_on_demand_job(TizenSyncManager* pObject, GDBusMethodInvocation*
LOG_LOGD("Params acc[%d] name[%s] option[%d] package[%s]", accountId, pSyncJobName, sync_option, pkgIdStr.c_str());
bundle* pBundle = umarshal_bundle(pSyncJobUserData);
SyncManager::GetInstance()->AddRunningAccount(accountId, pid);
- ret = SyncService::GetInstance()->RequestOnDemandSync(pkgIdStr.c_str(), pSyncJobName, accountId, pBundle, sync_option, &sync_job_id);
+ ret = SyncService::GetInstance()->RequestOnDemandSync(pkgIdStr.c_str(), atoi((char*)uid), pSyncJobName, accountId, pBundle, sync_option, &sync_job_id);
bundle_free(pBundle);
} else {
LOG_LOGD("Failed to get package id"); /* LCOV_EXCL_LINE */
@@ -778,13 +752,16 @@ sync_manager_add_on_demand_job(TizenSyncManager* pObject, GDBusMethodInvocation*
gboolean
-sync_manager_remove_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* pCommandLine, gint sync_job_id) {
+sync_manager_remove_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* uid, const gchar* pCommandLine, gint sync_job_id) {
LOG_LOGD("Request to remove sync job %d", sync_job_id);
+ LOG_LOGD("Caller UID : %s", (const char*)uid);
guint pid = get_caller_pid(pInvocation);
string pkgIdStr;
char* pAppId;
- int ret = app_manager_get_app_id(pid, &pAppId);
+ int ret = APP_MANAGER_ERROR_NONE;
+
+ ret = app_manager_get_app_id(pid, &pAppId);
if (ret == APP_MANAGER_ERROR_NONE) {
pkgIdStr = SyncManager::GetInstance()->GetPkgIdByAppId(pAppId);
free(pAppId);
@@ -797,7 +774,7 @@ sync_manager_remove_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvoc
if (!pkgIdStr.empty()) {
LOG_LOGD("package id [%s]", pkgIdStr.c_str());
- ret = SyncManager::GetInstance()->RemoveSyncJob(pkgIdStr, sync_job_id);
+ ret = SyncManager::GetInstance()->RemoveSyncJob(pkgIdStr, atoi((char*)uid), sync_job_id);
} else {
LOG_LOGD("sync service: Get package Id fail %d", ret); /* LCOV_EXCL_LINE */
}
@@ -813,8 +790,9 @@ sync_manager_remove_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvoc
}
LOG_LOGD("sync service: recoding the change of registered sync job");
- SyncManager::GetInstance()->RecordSyncJob();
- SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsData();
+
+ SyncManager::GetInstance()->RecordSyncJob((char*)pkgIdStr.c_str(), atoi((char*)uid), (int)sync_job_id);
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsDataOnDB();
LOG_LOGD("sync service: remove sync job ends");
@@ -824,6 +802,7 @@ sync_manager_remove_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvoc
gboolean
sync_manager_add_periodic_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation,
+ const gchar* uid,
const gchar* pCommandLine,
gint accountId,
const gchar* pSyncJobName,
@@ -831,6 +810,7 @@ sync_manager_add_periodic_job(TizenSyncManager* pObject, GDBusMethodInvocation*
gint sync_option,
GVariant* pSyncJobUserData) {
LOG_LOGD("Received Period Sync request");
+ LOG_LOGD("Caller UID : %s", (const char*)uid);
int ret = SYNC_ERROR_NONE;
@@ -846,7 +826,9 @@ sync_manager_add_periodic_job(TizenSyncManager* pObject, GDBusMethodInvocation*
guint pid = get_caller_pid(pInvocation);
string pkgIdStr;
+ int sync_job_id = 0;
char* pAppId;
+
ret = app_manager_get_app_id(pid, &pAppId);
if (ret == APP_MANAGER_ERROR_NONE) {
pkgIdStr = SyncManager::GetInstance()->GetPkgIdByAppId(pAppId);
@@ -858,13 +840,12 @@ sync_manager_add_periodic_job(TizenSyncManager* pObject, GDBusMethodInvocation*
/* LCOV_EXCL_STOP */
}
- int sync_job_id = 0;
+ bundle *pBundle = NULL;
if (!pkgIdStr.empty()) {
LOG_LOGD("Params acc[%d] name[%s] option[%d] period[%d] package[%s]", accountId, pSyncJobName, sync_option, sync_interval, pkgIdStr.c_str());
- bundle* pBundle = umarshal_bundle(pSyncJobUserData);
+ pBundle = umarshal_bundle(pSyncJobUserData);
SyncManager::GetInstance()->AddRunningAccount(accountId, pid);
- ret = SyncService::GetInstance()->RequestPeriodicSync(pkgIdStr.c_str(), pSyncJobName, accountId, pBundle, sync_option, sync_interval, &sync_job_id);
- bundle_free(pBundle);
+ ret = SyncService::GetInstance()->RequestPeriodicSync(pkgIdStr.c_str(), atoi((char*)uid), pSyncJobName, accountId, pBundle, sync_option, sync_interval, &sync_job_id);
} else {
LOG_LOGD("sync service: Get package Id fail %d", ret); /* LCOV_EXCL_LINE */
}
@@ -886,7 +867,9 @@ sync_manager_add_periodic_job(TizenSyncManager* pObject, GDBusMethodInvocation*
pManageIdleState->ResetTermTimer();
LOG_LOGD("sync service: recoding the change of registered sync job");
- SyncManager::GetInstance()->RecordSyncJob();
+
+ SyncManager::GetInstance()->RecordSyncJob(SyncManager::GetInstance()->GetSyncAdapterAggregator()->GetSyncAdapter((char*)pkgIdStr.c_str()), (char*)pkgIdStr.c_str(), atoi((char*)uid), "enabled", sync_job_id, "1", (int)accountId, pSyncJobName, (int)sync_interval, (int)sync_option, pBundle);
+ bundle_free(pBundle);
LOG_LOGD("sync service: add periodic sync job ends");
@@ -896,12 +879,14 @@ sync_manager_add_periodic_job(TizenSyncManager* pObject, GDBusMethodInvocation*
gboolean
sync_manager_add_data_change_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation,
+ const gchar* uid,
const gchar* pCommandLine,
gint accountId,
const gchar* pCapabilityArg,
gint sync_option,
GVariant* pSyncJobUserData) {
LOG_LOGD("Received data change Sync request");
+ LOG_LOGD("Caller UID : %s", (const char*)uid);
int ret = SYNC_ERROR_NONE;
@@ -948,6 +933,7 @@ sync_manager_add_data_change_job(TizenSyncManager* pObject, GDBusMethodInvocatio
guint pid = get_caller_pid(pInvocation);
string pkgIdStr;
+ int sync_job_id = 0;
char* pAppId;
ret = app_manager_get_app_id(pid, &pAppId);
@@ -961,15 +947,12 @@ sync_manager_add_data_change_job(TizenSyncManager* pObject, GDBusMethodInvocatio
/* LCOV_EXCL_STOP */
}
- int sync_job_id = 0;
+ bundle *pBundle = NULL;
if (!pkgIdStr.empty()) {
LOG_LOGD("Params account [%d] job_name [%s] sync_option[%d] sync_job_id[%d] package [%s] ", accountId, pCapabilityArg, sync_option, sync_job_id, pkgIdStr.c_str());
-
- bundle* pBundle = umarshal_bundle(pSyncJobUserData);
+ pBundle = umarshal_bundle(pSyncJobUserData);
SyncManager::GetInstance()->AddRunningAccount(accountId, pid);
- ret = SyncService::GetInstance()->RequestDataSync(pkgIdStr.c_str(), pCapabilityArg, accountId, pBundle, sync_option, pCapabilityArg, &sync_job_id);
-
- bundle_free(pBundle);
+ ret = SyncService::GetInstance()->RequestDataSync(pkgIdStr.c_str(), atoi((char*)uid), pCapabilityArg, accountId, pBundle, sync_option, pCapabilityArg, &sync_job_id);
} else {
LOG_LOGD("sync service: Get package Id fail %d", ret); /* LCOV_EXCL_LINE */
}
@@ -991,7 +974,9 @@ sync_manager_add_data_change_job(TizenSyncManager* pObject, GDBusMethodInvocatio
pManageIdleState->ResetTermTimer();
LOG_LOGD("sync service: recoding the change of registered sync job");
- SyncManager::GetInstance()->RecordSyncJob();
+
+ SyncManager::GetInstance()->RecordSyncJob(SyncManager::GetInstance()->GetSyncAdapterAggregator()->GetSyncAdapter((char*)pkgIdStr.c_str()), (char*)pkgIdStr.c_str(), atoi((char*)uid), "enabled", sync_job_id, "2", (int)accountId, pCapabilityArg, -1, (int)sync_option, pBundle);
+ bundle_free(pBundle);
LOG_LOGD("sync service: add data sync job ends");
@@ -1076,8 +1061,9 @@ static inline int __read_proc(const char *path, char *buf, int size) {
gboolean
-sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* pCommandLine) {
+sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* uid, const gchar* pCommandLine) {
LOG_LOGD("Received sync adapter registration request");
+ LOG_LOGD("Caller UID : %s", (const char*)uid);
guint pid = get_caller_pid(pInvocation);
@@ -1140,15 +1126,10 @@ sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation*
interface = G_DBUS_INTERFACE_SKELETON(syncAdapterObj);
if (g_dbus_interface_skeleton_export(interface, gdbusConnection, object_path, &error)) {
g_signal_connect(syncAdapterObj, "handle-send-result", G_CALLBACK(sync_adapter_handle_send_result), NULL);
+ pAggregator->AddSyncAdapter(pkgIdStr.c_str(), pAppId);
- char pAppUID[100];
- snprintf(pAppUID, 100, "%s#%d", pAppId, getuid());
-
- /* Add sync adapter as form of appId#uid */
- pAggregator->AddSyncAdapter(pkgIdStr.c_str(), pAppUID);
-
- LOG_LOGD("inserting sync adapter ipc %s", pAppUID);
- g_hash_table_insert(g_hash_table, strdup(pAppUID), syncAdapterObj);
+ LOG_LOGD("inserting sync adapter ipc %s", pAppId);
+ g_hash_table_insert(g_hash_table, (gchar*)pAppId, syncAdapterObj);
ret = SYNC_ERROR_NONE;
} else {
@@ -1176,7 +1157,7 @@ sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation*
}
LOG_LOGD("sync service: recoding the change of registered sync adapter");
- SyncManager::GetInstance()->RecordSyncAdapter();
+ SyncManager::GetInstance()->RecordSyncAdapter((const char*)pAppId, pkgIdStr.c_str(), atoi(uid), "enabled");
LOG_LOGD("sync service: adding sync adapter ends");
@@ -1185,8 +1166,9 @@ sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation*
gboolean
-sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* pCommandLine) {
+sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* uid, const gchar* pCommandLine) {
LOG_LOGD("Request to remove sync adapter");
+ LOG_LOGD("Caller UID : %s", (const char*)uid);
string pkgIdStr;
guint pid = get_caller_pid(pInvocation);
@@ -1200,9 +1182,7 @@ sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocatio
}
char* pAppId;
- int ret = APP_MANAGER_ERROR_NONE;
- ret = app_manager_get_app_id(pid, &pAppId);
-
+ int ret = app_manager_get_app_id(pid, &pAppId);
if (ret == APP_MANAGER_ERROR_NONE) {
pkgIdStr = SyncManager::GetInstance()->GetPkgIdByAppId(pAppId);
} else {
@@ -1221,13 +1201,10 @@ sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocatio
LOG_LOGD("sync service: Get package Id fail [%d]", ret); /* LCOV_EXCL_LINE */
}
- char pAppUID[100];
- snprintf(pAppUID, 100, "%s#%d", pAppId, getuid());
-
- TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, pAppUID);
+ TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, pAppId);
if (pSyncAdapter == NULL) {
/* LCOV_EXCL_START */
- LOG_LOGD("Failed to lookup syncadapter gdbus object for [%s]", pAppUID);
+ LOG_LOGD("Failed to lookup syncadapter gdbus object for [%s]", pAppId);
char object_path[50];
snprintf(object_path, 50, "%s%d", SYNC_ADAPTER_DBUS_PATH, pid);
@@ -1240,7 +1217,7 @@ sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocatio
g_signal_connect(syncAdapterObj, "handle-send-result", G_CALLBACK(sync_adapter_handle_send_result), NULL);
pAggregator->RemoveSyncAdapter(pkgIdStr.c_str());
- LOG_LOGD("deletting sync adapter ipc [%s]", pAppUID);
+ LOG_LOGD("deleting sync adapter ipc [%s]", pAppId);
ret = SYNC_ERROR_NONE;
} else {
@@ -1259,7 +1236,7 @@ sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocatio
tizen_sync_manager_complete_remove_sync_adapter(pObject, pInvocation);
LOG_LOGD("sync service: recoding the change of registered sync adapter");
- SyncManager::GetInstance()->RecordSyncAdapter();
+ SyncManager::GetInstance()->RecordSyncAdapter(pkgIdStr.c_str(), atoi(uid));
LOG_LOGD("sync service: removing sync adapter ends");
@@ -1292,10 +1269,10 @@ marshal_sync_job(ISyncJob* syncJob) {
}
-
gboolean
-sync_manager_get_all_sync_jobs(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* pCommandLine) {
+sync_manager_get_all_sync_jobs(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* uid, const gchar* pCommandLine) {
LOG_LOGD("Received request to get Sync job ids");
+ LOG_LOGD("Caller UID : %s", (const char*)uid);
guint pid = get_caller_pid(pInvocation);
string pkgId;
@@ -1320,6 +1297,10 @@ sync_manager_get_all_sync_jobs(TizenSyncManager* pObject, GDBusMethodInvocation*
SyncJobsAggregator* pSyncJobsAggregator = SyncManager::GetInstance()->GetSyncJobsAggregator();
SyncJobsInfo* pPackageSyncJobs = pSyncJobsAggregator->GetSyncJobsInfo(pkgId.c_str());
+ /*
+ SyncJobsInfo* pPackageSyncJobs = pSyncJobsAggregator->GetSyncJobsInfo(pkgId.c_str(), atoi((char*)uid));
+ */
+
if (pPackageSyncJobs != NULL) {
LOG_LOGD("Package ID [%s]", pkgId.c_str());
diff --git a/src/sync-service/SyncManager_SyncService.h b/src/sync-service/SyncManager_SyncService.h
index 3bb6e82..2def69a 100644
--- a/src/sync-service/SyncManager_SyncService.h
+++ b/src/sync-service/SyncManager_SyncService.h
@@ -42,15 +42,15 @@ class SyncService
public:
int StartService(void);
- int TriggerStartSync(const char* appUID, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras);
+ int TriggerStartSync(const char* appId, int uid, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras);
- void TriggerStopSync(const char* appUID, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras);
+ void TriggerStopSync(const char* appId, int uid, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras);
- int RequestOnDemandSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, int* pSyncJobId);
+ int RequestOnDemandSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, int* pSyncJobId);
- int RequestPeriodicSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId);
+ int RequestPeriodicSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId);
- int RequestDataSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, const char* pCapability, int* pSyncJobId);
+ int RequestDataSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, const char* pCapability, int* pSyncJobId);
void HandleShutdown(void);
diff --git a/sync_manager.xml b/sync_manager.xml
index 0f8d892..ffeac89 100644
--- a/sync_manager.xml
+++ b/sync_manager.xml
@@ -2,6 +2,7 @@
<node name="/org/tizen/sync/manager">
<interface name="org.tizen.sync.manager">
<method name="add_on_demand_job">
+ <arg type="s" name="app_uid" direction="in" />
<arg type="s" name="command_line" direction="in" />
<arg type="i" name="account_id" direction="in" />
<arg type="s" name="sync_job_name" direction="in" />
@@ -10,6 +11,7 @@
<arg type="i" name="sync_job_id" direction="out" />
</method>
<method name="add_periodic_job">
+ <arg type="s" name="app_uid" direction="in" />
<arg type="s" name="command_line" direction="in" />
<arg type="i" name="account_id" direction="in" />
<arg type="s" name="sync_job_name" direction="in" />
@@ -19,6 +21,7 @@
<arg type="i" name="sync_job_id" direction="out" />
</method>
<method name="add_data_change_job">
+ <arg type="s" name="app_uid" direction="in" />
<arg type="s" name="command_line" direction="in" />
<arg type="i" name="account_id" direction="in" />
<arg type="s" name="sync_capability" direction="in" />
@@ -27,17 +30,21 @@
<arg type="i" name="sync_job_id" direction="out" />
</method>
<method name="get_all_sync_jobs">
+ <arg type="s" name="app_uid" direction="in" />
<arg type="s" name="command_line" direction="in" />
<arg type="aa{sv}" name="sync_jobs" direction="out" />
</method>
<method name="remove_job">
+ <arg type="s" name="app_uid" direction="in" />
<arg type="s" name="command_line" direction="in" />
<arg type="i" name="sync_job_id" direction="in" />
</method>
<method name="add_sync_adapter">
+ <arg type="s" name="app_uid" direction="in" />
<arg type="s" name="command_line" direction="in" />
</method>
<method name="remove_sync_adapter">
+ <arg type="s" name="app_uid" direction="in" />
<arg type="s" name="command_line" direction="in" />
</method>
<method name="set_sync_status">