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;
/**
* @brief This is calendar capability string.
- * @since_tizen @if MOBILE 2.4 @endif WEARABLE 4.0 @endif
- * @remarks If you want to receive notification about calendar DB change, add it through sync_manager_add_data_change_sync_job().
+ * @since_tizen @if MOBILE 2.4 @endif
+ * @remarks This capability is supported on Mobile profile only. If you want to receive notification about calendar DB change, add it through sync_manager_add_data_change_sync_job().
* @see sync_manager_add_data_change_sync_job()
*/
#define SYNC_SUPPORTS_CAPABILITY_CALENDAR "http://tizen.org/sync/capability/calendar"
%global __provides_exclude_from ^.*\\.extension-calendar
Name: sync-service
-Version: 0.2.26
+Version: 0.1.24
Release: 1
License: Apache-2.0
Summary: Sync manager daemon
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)
BuildRequires: pkgconfig(cynara-client)
BuildRequires: pkgconfig(cynara-session)
BuildRequires: pkgconfig(cynara-creds-gdbus)
+# If it is mobile, common, or "unified (undefined)"
+%if "%{?profile}" != "wearable" && "%{?profile}" != "tv" && "%{?profile}" != "ivi"
BuildRequires: pkgconfig(calendar-service2)
+%endif
BuildRequires: pkgconfig(contacts-service2)
BuildRequires: pkgconfig(capi-content-media-content)
BuildRequires: pkgconfig(libtzplatform-config)
%define _pkgdir /usr
%define _upgrade_script_path %{_pkgdir}/share/upgrade/scripts/
%define _upgrade_script 500.sync-manager.sh
+#%define _bindir %{_pkgdir}/bin
+#%define _systemd_dir /usr/lib/systemd/system
%prep
%setup -q
%build
_FEATURE_CONTAINER_ENABLE=OFF
+# If it is mobile, common, or "unified (undefined)"
+%if "%{?profile}" != "wearable" && "%{?profile}" != "tv" && "%{?profile}" != "ivi"
+# Support runtime feature on/off
+_RUNTIME_PROFILE_TEST=ON
+%else
+# Always off.
+_RUNTIME_PROFILE_TEST=OFF
+%endif
+
cmake \
-DCMAKE_INSTALL_PREFIX=%{_pkgdir} \
-DPACKAGE_NAME=%{name} \
-DLIBDIR=%{_libdir} \
-DINCLUDEDIR=%{_includedir} \
-D_FEATURE_CONTAINER_ENABLE:BOOL=${_FEATURE_CONTAINER_ENABLE} \
+ -D_RUNTIME_PROFILE_TEST:BOOL=${_RUNTIME_PROFILE_TEST} \
-DVERSION=%{version}
+
make %{?jobs:-j%jobs}
%install
%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
%postun -n libcore-sync-client -p /sbin/ldconfig
%postun -n libcore-sync-client-devel -p /sbin/ldconfig
%defattr(-,root,root,-)
%config %{_sysconfdir}/dbus-1/session.d/org.tizen.sync.conf
%{_bindir}/*
+#%{_unitdir}/*
+#%{TZ_SYS_DATA}/sync-manager/
%{_unitdir_user}/sync-manager.service
%{_unitdir_user}/default.target.wants/sync-manager.service
%attr(0644,root,root) /usr/share/dbus-1/services/org.tizen.sync.service
ENDIF(NOT DEFINED PACKAGE_NAME)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+#SET(LIBDIR "${PREFIX}/lib")
+#SET(INCLUDEDIR "${PREFIX}/include")
SET(VERSION_MAJOR 1)
SET(FULLVER "${VERSION_MAJOR}.0")
+IF(_RUNTIME_PROFILE_TEST)
+ ADD_DEFINITIONS("-D_RUNTIME_PROFILE_TEST=1")
+ENDIF(_RUNTIME_PROFILE_TEST)
+
+
INCLUDE_DIRECTORIES(
+# ./
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/common
)
&error);
SYNC_LOGE_RET_RES(error == NULL && ipcObj != NULL, SYNC_ERROR_IO_ERROR, "tizen_sync_manager_proxy_new_sync failed %s", error->message);
- char buf[8] = {0, };
- snprintf(buf, 8, "%d", (int)getuid());
-
+ bool ret = true;
char *command_line = proc_get_cmdline_self();
if (flag) {
- bool ret = true;
- ret = tizen_sync_manager_call_add_sync_adapter_sync(ipcObj, (const gchar*)buf, command_line, NULL, &error);
+ ret = tizen_sync_manager_call_add_sync_adapter_sync(ipcObj, 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, (const gchar*)buf, command_line, NULL, &error);
+ tizen_sync_manager_call_remove_sync_adapter_sync(ipcObj, command_line, NULL, &error);
}
free(command_line);
#define SYNC_ADAPTER_DBUS_PATH "/org/tizen/sync/adapter"
#define SYNC_ERROR_PREFIX "org.tizen.sync.Error"
-
+#ifdef _RUNTIME_PROFILE_TEST
#include <system_info.h>
typedef enum {
TIZEN_PROFILE_UNKNOWN = 0,
return profile;
}
+#define _FEATURE_CALENDAR_ENABLE (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
+
+#else /* _RUNTIME_PROFILE_TEST */
+#define _FEATURE_CALENDAR_ENABLE (0)
+
+#endif /* _RUNTIME_PROFILE_TEST */
typedef struct sync_manager_s {
TizenSyncManager *ipcObj;
LOG_LOGC("appid [%s] sync_job_name [%s]", g_sync_manager->appid, sync_job_name);
}
- char buf[8] = {0, };
- snprintf(buf, 8, "%d", (int)getuid());
-
- GError *error = NULL;
GVariant *user_data = marshal_bundle(sync_job_user_data);
+ GError *error = NULL;
- 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);
+ 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);
if (!is_success || error) {
int error_code = _sync_get_error_code(is_success, error);
LOG_LOGC("sync client: gdbus error [%s]", error->message);
int sync_interval = get_interval(sync_period);
- char buf[8] = {0, };
- snprintf(buf, 8, "%d", (int)getuid());
-
- GError *error = NULL;
GVariant *user_data = marshal_bundle(sync_job_user_data);
+ GError *error = NULL;
- 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);
+ 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);
if (!is_success || error) {
int error_code = _sync_get_error_code(is_success, error);
LOG_LOGC("sync client: gdbus error [%s]", error->message);
int sync_manager_add_data_change_sync_job(account_h account, const char *sync_capability, sync_option_e sync_option, bundle *sync_job_user_data, int *sync_job_id)
{
if (sync_capability != NULL) {
- if (!(strcmp(sync_capability, "http://tizen.org/sync/capability/calendar")) ||
+ if (
+ ((_FEATURE_CALENDAR_ENABLE) ? !(strcmp(sync_capability, "http://tizen.org/sync/capability/calendar")) : 0) ||
!(strcmp(sync_capability, "http://tizen.org/sync/capability/contact")) ||
!(strcmp(sync_capability, "http://tizen.org/sync/capability/image")) ||
!(strcmp(sync_capability, "http://tizen.org/sync/capability/video")) ||
LOG_LOGC("appid [%s] capability [%s]", g_sync_manager->appid, sync_capability);
}
- char buf[8] = {0, };
- snprintf(buf, 8, "%d", (int)getuid());
-
- GError *error = NULL;
GVariant *user_data = marshal_bundle(sync_job_user_data);
+ GError *error = NULL;
- 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);
+ 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);
if (!is_success || error) {
int error_code = _sync_get_error_code(is_success, error);
LOG_LOGC("sync client: gdbus error [%s]", error->message);
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, (const gchar*)buf, g_sync_manager->appid, sync_job_id, NULL, &error);
+ bool is_success = tizen_sync_manager_call_remove_job_sync(g_sync_manager->ipcObj, 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);
g_sync_manager->sync_job_cb = sync_job_cb;
- char buf[8] = {0, };
- snprintf(buf, 8, "%d", (int)getuid());
-
- GError *error = NULL;
GVariant *sync_job_list_variant = NULL;
+ 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);
- 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);
# ADD_DEFINITIONS("-D_FEATURE_CONTAINER_ENABLE=1")
#ENDIF(_FEATURE_CONTAINER_ENABLE)
+IF(_RUNTIME_PROFILE_TEST)
+ ADD_DEFINITIONS("-D_RUNTIME_PROFILE_TEST=1")
+ENDIF(_RUNTIME_PROFILE_TEST)
+
ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE_NAME}\"")
INCLUDE(FindPkgConfig)
pkgmgr
pkgmgr-info
dlog
- db-util
appcore-efl
glib-2.0
vconf
gio-unix-2.0
alarm-service
bundle
- calendar-service2
contacts-service2
cynara-client
cynara-session
SET(PACKAGES ${PACKAGES} vasum)
ENDIF(_FEATURE_CONTAINER_ENABLE)
+IF(_RUNTIME_PROFILE_TEST)
+ SET(PACKAGES ${PACKAGES} calendar-service2)
+ENDIF(_RUNTIME_PROFILE_TEST)
+
pkg_check_modules(PKGS REQUIRED ${PACKAGES})
FOREACH(flag ${PKGS_CFLAGS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} "-ldl")
#TARGET_LINK_LIBRARIES(${PROJECT_NAME} core-sync-client)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
-
* @brief This is the implementation file for the DataChangeListener class.
*/
-
+#if defined(_RUNTIME_PROFILE_TEST)
#include <calendar.h>
+#endif
+
#include <contacts.h>
#include <media_content.h>
#include "sync-error.h"
/* LCOV_EXCL_START */
+#if defined(_RUNTIME_PROFILE_TEST)
void OnCalendarBookChanged(const char* view_uri, void* user_data) {
LOG_LOGD("On Calendar Book Changed");
DataChangeSyncScheduler* pDCScheduler = (DataChangeSyncScheduler*) (user_data);
pDCScheduler->HandleDataChangeEvent(SYNC_SUPPORTS_CAPABILITY_CALENDAR);
}
+#endif
void OnContactsDataChanged(const char* view_uri, void* user_data) {
/* LCOV_EXCL_STOP */
+#if defined(_RUNTIME_PROFILE_TEST)
int
DataChangeSyncScheduler::SubscribeCalendarCallback(void) {
SYNC_LOGE_RET_RES(!calendar_subscription_started, SYNC_ERROR_NONE, "Calendar Callback Already Subscribed");
return SYNC_ERROR_NONE;
}
+#endif
int
/* LCOV_EXCL_START */
+#if defined(_RUNTIME_PROFILE_TEST)
int
DataChangeSyncScheduler::UnSubscribeCalendarCallback(void) {
SYNC_LOGE_RET_RES(calendar_subscription_started, SYNC_ERROR_NONE, "Calendar Callback Already UnSubscribed");
return SYNC_ERROR_NONE;
}
+#endif
int
DataChangeSyncScheduler::RegisterDataChangeListeners(void) {
int err = SYNC_ERROR_NONE;
- err = SubscribeCalendarCallback();
- if (err != SYNC_ERROR_NONE) {
- /* LCOV_EXCL_START */
- LOG_LOGD("Registration of Calendar DataChangeListener Failed");
- return SYNC_ERROR_INVALID_OPERATION;
- /* LCOV_EXCL_STOP */
+ if (_FEATURE_CALENDAR_ENABLE) {
+ err = SubscribeCalendarCallback();
+ if (err != SYNC_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ LOG_LOGD("Registration of Calendar DataChangeListener Failed");
+ return SYNC_ERROR_INVALID_OPERATION;
+ /* LCOV_EXCL_STOP */
+ }
}
err = SubscribeContactsCallback();
DataChangeSyncScheduler::DeRegisterDataChangeListeners(void) {
int err = VALUE_UNDEFINED;
- err = UnSubscribeCalendarCallback();
- if (err != SYNC_ERROR_NONE) {
- LOG_LOGD("DeRegistration of Calendar DataChangeListener Failed");
- return SYNC_ERROR_INVALID_OPERATION;
+ if (_FEATURE_CALENDAR_ENABLE) {
+ err = UnSubscribeCalendarCallback();
+ if (err != SYNC_ERROR_NONE) {
+ LOG_LOGD("DeRegistration of Calendar DataChangeListener Failed");
+ return SYNC_ERROR_INVALID_OPERATION;
+ }
}
err = UnSubscribeContactsCallback();
}
}
}
-
}
-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)
+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)
, __capability(capability) {
}
public:
~DataSyncJob(void);
- DataSyncJob(const string appId, int uid, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type, string capability);
+ DataSyncJob(const string appId, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type, string capability);
DataSyncJob(const DataSyncJob&);
LOG_LOGD("Network connection changed %d", type);
switch (type) {
- case CONNECTION_TYPE_BT: {
- SyncManager::GetInstance()->OnBTStatusChanged(true);
- break;
- }
case CONNECTION_TYPE_WIFI: {
SyncManager::GetInstance()->OnWifiStatusChanged(true);
break;
SyncManager::GetInstance()->OnDNetStatusChanged(true);
break;
}
+ case CONNECTION_TYPE_BT: {
+ SyncManager::GetInstance()->OnBluetoothStatusChanged(true);
+ break;
+ }
case CONNECTION_TYPE_DISCONNECTED: {
- SyncManager::GetInstance()->OnBTStatusChanged(false);
SyncManager::GetInstance()->OnWifiStatusChanged(false);
SyncManager::GetInstance()->OnEthernetStatusChanged(false);
SyncManager::GetInstance()->OnDNetStatusChanged(false);
+ SyncManager::GetInstance()->OnBluetoothStatusChanged(false);
break;
}
default:
/* LCOV_EXCL_STOP */
-bool
-NetworkChangeListener::IsBTConnected() {
- connection_bt_state_e state = CONNECTION_BT_STATE_DEACTIVATED;
- int ret = connection_get_bt_state(connection, &state);
- if (ret != CONNECTION_ERROR_NONE)
- LOG_LOGD("Connection BT failure %d, %s", ret, get_error_message(ret)); /* LCOV_EXCL_LINE */
-
- return (state == CONNECTION_BT_STATE_CONNECTED);
-}
-
-
bool
NetworkChangeListener::IsWifiConnected() {
+ int ret;
connection_wifi_state_e state = CONNECTION_WIFI_STATE_DEACTIVATED;
- int ret = connection_get_wifi_state(connection, &state);
+ ret = connection_get_wifi_state(connection, &state);
if (ret != CONNECTION_ERROR_NONE)
- LOG_LOGD("Connection WiFi failure %d, %s", ret, get_error_message(ret)); /* LCOV_EXCL_LINE */
+ LOG_LOGD("Connection wifi failure %d, %s", ret, get_error_message(ret)); /* LCOV_EXCL_LINE */
return (state == CONNECTION_WIFI_STATE_CONNECTED);
}
bool
NetworkChangeListener::IsEthernetConnected() {
+ int ret;
connection_ethernet_state_e state = CONNECTION_ETHERNET_STATE_DEACTIVATED;
- int ret = connection_get_ethernet_state(connection, &state);
+ ret = connection_get_ethernet_state(connection, &state);
if (ret == CONNECTION_ERROR_NOT_SUPPORTED)
LOG_LOGD("Ethernet connection does not be supported on this target"); /* LCOV_EXCL_LINE */
else if (ret != CONNECTION_ERROR_NONE)
- LOG_LOGD("Connection Ethernet failure %d, %s", ret, get_error_message(ret)); /* LCOV_EXCL_LINE */
+ LOG_LOGD("Connection ethernet failure %d, %s", ret, get_error_message(ret)); /* LCOV_EXCL_LINE */
return (state == CONNECTION_ETHERNET_STATE_CONNECTED);
}
bool
NetworkChangeListener::IsDataConnectionPresent() {
+ int ret;
connection_cellular_state_e state = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
- int ret = connection_get_cellular_state(connection, &state);
+ ret = connection_get_cellular_state(connection, &state);
if (ret == CONNECTION_ERROR_NOT_SUPPORTED)
LOG_LOGD("Telephony does not be supported on this target"); /* LCOV_EXCL_LINE */
else if (ret != CONNECTION_ERROR_NONE)
NetworkChangeListener::DeRegisterNetworkChangeListener(void) {
LOG_LOGD("Removing network change listener");
- int ret = connection_unset_type_changed_cb(connection);
+ int ret;
+ ret = connection_unset_type_changed_cb(connection);
if (ret != CONNECTION_ERROR_NONE)
LOG_LOGD("Removal of network change listener failed");
int RegisterNetworkChangeListener(void);
- bool IsBTConnected(void);
-
bool IsWifiConnected(void);
bool IsEthernetConnected(void);
}
-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)
+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)
, __period(frequency) {
}
public:
~PeriodicSyncJob(void);
- PeriodicSyncJob(const string appId, int uid, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type, long frequency);
+ PeriodicSyncJob(const string appId, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type, long frequency);
PeriodicSyncJob(const PeriodicSyncJob&);
{
*/
+#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";
/* 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("__capabilityInfoMutex init failed"); /* LCOV_EXCL_LINE */
- return;
- }
- if (pthread_mutex_init(&__syncDBReadWriteMutex, NULL) != 0) {
- LOG_LOGD("__syncDBReadWriteMutex init failed"); /* LCOV_EXCL_LINE */
+ LOG_LOGD("\n __syncJobQueueMutex init failed\n"); /* LCOV_EXCL_LINE */
return;
}
}
void
RepositoryEngine::OnBooting() {
- if (!ReadSyncAdaptersFromDB())
- ReadSyncAdapters();
- if (!ReadSyncJobsDataFromDB())
- ReadSyncJobsData();
+ ReadSyncAdapters();
+ ReadSyncJobsData();
}
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;
/* 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");
}
+/* 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;
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;
if (doc == NULL) {
/* LCOV_EXCL_START */
LOG_LOGD("Failed to parse syncjobs.xml");
+ SaveCurrentSyncJob();
doc = xmlParseFile(pDocName);
/* LCOV_EXCL_STOP */
}
/* 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");
xmlFreeDoc(doc);
- /* 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();
+ // 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
LOG_LOGD("sync jobs are figured out");
}
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;
if (doc == NULL) {
/* LCOV_EXCL_START */
LOG_LOGD("Failed to parse syncadapters.xml");
+ SaveCurrentSyncAdapter();
doc = xmlParseFile(pDocName);
/* LCOV_EXCL_STOP */
}
/* 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");
/* 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();
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if (!xmlStrcmp(cur->name, XML_NODE_SYNCADAPTER)) {
- xmlChar* pServiceAppId = xmlGetProp(cur, XML_ATTR_SYNCADAPTER_SERVICE_APP_ID);
+ xmlChar* pServiceAppUID = xmlGetProp(cur, XML_ATTR_SYNCADAPTER_SERVICE_APP_ID);
+ if (!pServiceAppUID)
+ return;
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*)pServiceAppId, "enabled");
+ pAggregator->SetAppStatus((char*)pAppUID, "enabled");
else
- pAggregator->SetAppStatus((char*)pServiceAppId, (char*)pAppStatus);
+ pAggregator->SetAppStatus((char*)pAppUID, (char*)pAppStatus);
- pAggregator->AddSyncAdapter((char*)pPackageId, (char*)pServiceAppId);
- InsertSyncAdapterToDB((char*)pServiceAppId, (char*)pPackageId, 5001, (char*)pAppStatus);
+ pAggregator->AddSyncAdapter((char*)pPackageId, (char*)pAppUID);
pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
} else {
pAggregator->HandlePackageUninstalled((char*)pPackageId);
}
if (pServiceAppId)
- xmlFree(pServiceAppId);
+ free(pServiceAppId);
+ if (ptr)
+ free(ptr);
+ if (pServiceAppUID)
+ xmlFree(pServiceAppUID);
if (pPackageId)
xmlFree(pPackageId);
if (pAppStatus)
}
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");
}
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);
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);
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 accountId = (pAccId == NULL) ? -1 : atoi((char*)pAccId);
- int syncJobId = -1;
+ int acountId = (pAccId == NULL) ? -1 : atoi((char*)pAccId);
+ int jobId = (pJobId == NULL) ? -1 : atoi((char*)pJobId);
int syncOption = (noretry) ? 0x02 : 0x00;
syncOption |= (expedit) ? 0x01 : 0x00;
switch (type) {
case SYNC_TYPE_DATA_CHANGE: {
- 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);
+ SyncManager::GetInstance()->AddDataSyncJob((char*)pPackage, (char*)pJobName, acountId, pExtra, syncOption, jobId, (char*)pJobName);
break;
}
case SYNC_TYPE_ON_DEMAND: {
+ SyncManager::GetInstance()->AddOnDemandSync((char*)pPackage, (char*)pJobName, acountId, pExtra, syncOption, jobId);
break;
}
case SYNC_TYPE_PERIODIC: {
- 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);
+ 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);
break;
}
case SYNC_TYPE_UNKNOWN:
void
-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;
+RepositoryEngine::SaveCurrentState(void) {
+ LOG_LOGD("saving states during shutdown");
+ pthread_mutex_lock(&__capabilityInfoMutex);
+ WriteSyncJobsData();
+ pthread_mutex_unlock(&__capabilityInfoMutex);
+ WriteSyncAdapters();
}
/* LCOV_EXCL_START */
void
-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");
+RepositoryEngine::SaveCurrentSyncAdapter(void) {
+ LOG_LOGD("saving states of registered Sync Adapters");
+ pthread_mutex_lock(&__capabilityInfoMutex);
+ WriteSyncAdapters();
+ pthread_mutex_unlock(&__capabilityInfoMutex);
}
-/* LCOV_EXCL_STOP */
-/* LCOV_EXCL_START */
void
-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");
+RepositoryEngine::SaveCurrentSyncJob(void) {
+ LOG_LOGD("saving states of added Sync Jobs");
+ pthread_mutex_lock(&__capabilityInfoMutex);
+ WriteSyncJobsData();
+ pthread_mutex_unlock(&__capabilityInfoMutex);
}
/* 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
#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
{
void OnBooting();
- void CheckSyncJobsData(void);
-
- void CheckSyncJobsDataOnDB(void);
-
- void StartPackageSyncJobs(const char *PackageName, int uid);
-
- void CancelPackageSyncJobs(const char *PackageName, int uid);
-
- bool CheckAdapterStatus(const char *PackageName);
+ void SaveCurrentState(void);
- void RecordSyncAdapter(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus);
+ void SaveCurrentSyncAdapter(void);
- void RecordSyncAdapter(const char *SvcAppId, int UserId, const char *AppStatus);
+ void SaveCurrentSyncJob(void);
- 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 CheckSyncJobsData(void);
- void RecordSyncJob(const char *PkgName, int UserId);
+ void CancelPackageSyncJobs(const char *PackageName);
- void DeleteAllSyncData(const char *PkgName, int UserId);
+ bool CheckAdapterStatus(const char *PackageName);
public:
static const long NOT_IN_BACKOFF_MODE;
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 */
/* LCOV_EXCL_START */
void
-SyncAdapterAggregator::SetAppStatus(const char* pServiceAppId, const char* pAppStatus) {
- /* Update the application's status */
+SyncAdapterAggregator::SetAppStatus(const char* pServiceAppUID, const char* pAppStatus) {
+ /* Update the application status */
for (map<string, string>::iterator iter = __syncAppStatus.begin(); iter != __syncAppStatus.end(); ++iter) {
string appID = iter->first;
- if (!strcmp(pServiceAppId, appID.c_str())) {
+ if (!strcmp(pServiceAppUID, 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> (pServiceAppId, pAppStatus));
+ __syncAppStatus.insert(pair<string, string> (pServiceAppUID, pAppStatus));
}
/* LCOV_EXCL_STOP */
void
-SyncAdapterAggregator::AddSyncAdapter(const char* pPackageId, const char* pServiceAppId) {
+SyncAdapterAggregator::AddSyncAdapter(const char* pPackageId, const char* pServiceAppUID) {
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]", pServiceAppId, pPackageId);
- __syncAdapterList.insert(pair<string, string> (pPackageId, pServiceAppId));
+ LOG_LOGD("Registering sync-adapter [%s] for package [%s]", pServiceAppUID, pPackageId);
+ __syncAdapterList.insert(pair<string, string> (pPackageId, pServiceAppUID));
/* Check the application status was written */
for (map<string, string>::iterator iter = __syncAppStatus.begin(); iter != __syncAppStatus.end(); ++iter) {
string appID = iter->first;
- if (!strcmp(pServiceAppId, appID.c_str())) {
+ if (!strcmp(pServiceAppUID, 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> (pServiceAppId, "enabled"));
+ __syncAppStatus.insert(pair<string, string> (pServiceAppUID, "enabled"));
}
}
const char*
-SyncAdapterAggregator::GetSyncAdapter(const char* pAppId) {
- string PkgId(pAppId);
- if (PkgId.empty()) {
- //PkgId = SyncManager::GetInstance()->GetPkgIdByCommandline(pAppId);
- if (PkgId.empty()) /* LCOV_EXCL_LINE */
- return NULL;
+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;
}
- map<string, string>::iterator it = __syncAdapterList.find(PkgId.c_str());
+ map<string, string>::iterator it = __syncAdapterList.find(pkgName.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 account provider id %s", pAppId);
+ LOG_LOGD("Sync adapter is not found for the package [%s]", pPackageId);
return NULL;
}
} tizen_profile_t;
extern tizen_profile_t _get_tizen_profile();
+#ifdef _RUNTIME_PROFILE_TEST
+#define _FEATURE_CALENDAR_ENABLE (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
+#else /* _RUNTIME_PROFILE_TEST */
+#define _FEATURE_CALENDAR_ENABLE (0)
+#endif /* _RUNTIME_PROFILE_TEST */
#endif /* SYNC_SERVICE_SYNC_DEFINES_H */
/* 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);
SyncJob&
SyncJob::operator = (const SyncJob& job) {
__appId = job.__appId;
- __uid = job.__uid;
__accountId = job.__accountId;
__syncJobName = job.__syncJobName;
__pExtras = bundle_dup(job.__pExtras);
/* LCOV_EXCL_STOP */
-SyncJob::SyncJob(const string appId, int uid, const string syncJobName, int account, bundle* pExtras, int syncOption, int syncJobId, SyncType syncType)
+SyncJob::SyncJob(const string appId, 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();
}
SyncJob &operator = (const SyncJob &job);
- SyncJob(const string appId, int uid, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type);
+ SyncJob(const string appId, const string syncJobName, int accountId, bundle *pUserData, int syncOption, int syncJobId, SyncType type);
void Reset(int accountId, bundle* pUserData, int syncOption);
public:
string __appId;
- int __uid;
string __syncJobName;
int __accountId;
bundle* __pExtras;
int
SyncJobDispatcher::DispatchSyncJob(SyncJob* syncJob) {
- LOG_LOGD("Dispatching sync job [%s], [%d], [%s]", syncJob->__appId.c_str(), syncJob->__uid, syncJob->__syncJobName.c_str());
+ LOG_LOGD("Dispatching sync job [%s], [%s]", syncJob->__appId.c_str(), 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->__uid, syncJob->__accountId, syncJob->__syncJobName.c_str(), isDataSync, syncJob->__pExtras);
+ ret = SyncService::GetInstance()->TriggerStartSync(syncJob->__appId.c_str(), 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) {
case SYNC_STATUS_CANCELLED:
LOG_LOGD("Handle Sync event : SYNC_STATUS_CANCELLED");
- SyncService::GetInstance()->TriggerStopSync(pJob->__appId.c_str(), pJob->__uid, pJob->__accountId, pJob->__syncJobName.c_str(), (pJob->GetSyncType() == SYNC_TYPE_DATA_CHANGE), pJob->__pExtras);
+ SyncService::GetInstance()->TriggerStopSync(pJob->__appId.c_str(), pJob->__accountId, pJob->__syncJobName.c_str(), (pJob->GetSyncType() == SYNC_TYPE_DATA_CHANGE), pJob->__pExtras);
delete pJob;
break;
void
SyncJobDispatcher::TryStartingNextJobLocked() {
- if (SyncManager::GetInstance()->__isSimDataConnectionPresent == false
- && SyncManager::GetInstance()->__isWifiConnectionPresent == false
- && SyncManager::GetInstance()->__isEthernetConnectionPresent == false
- && SyncManager::GetInstance()->__isBTConnectionPresent == false) {
+ if (SyncManager::GetInstance()->__isWifiConnectionPresent == false && SyncManager::GetInstance()->__isEthernetConnectionPresent == false && SyncManager::GetInstance()->__isSimDataConnectionPresent == false) {
LOG_LOGD("No network available: Skipping sync");
return;
}
bool
-SyncJobsAggregator::HasSyncJob(const char* pPackageId, int uid, const char* pSyncJobName) {
- ISyncJob* pSyncJob = GetSyncJob(pPackageId, uid, pSyncJobName);
+SyncJobsAggregator::HasSyncJob(const char* pPackageId, const char* pSyncJobName) {
+ ISyncJob* pSyncJob = GetSyncJob(pPackageId, pSyncJobName);
return pSyncJob != NULL;
}
/* LCOV_EXCL_STOP */
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));
void
-SyncJobsAggregator::AddSyncJob(const char* pPackageId, int uid, const char* pSyncJobName, ISyncJob* pSyncJob) {
+SyncJobsAggregator::AddSyncJob(const char* pPackageId, 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, uid, pSyncJob);
+ pPackageSyncJobsInfo->AddSyncJob(pSyncJobName, 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, uid, pSyncJob);
+ pPackageSyncJobsInfo->AddSyncJob(pSyncJobName, pSyncJob);
__syncJobsContainer.insert(make_pair(pPackageId, pPackageSyncJobsInfo));
/* LCOV_EXCL_STOP */
}
int
-SyncJobsAggregator::RemoveSyncJob(const char* pPackageId, int uid, int syncJobId) {
+SyncJobsAggregator::RemoveSyncJob(const char* pPackageId, int syncJobId) {
map<string, SyncJobsInfo*>::iterator itr = __syncJobsContainer.find(pPackageId);
if (itr != __syncJobsContainer.end()) {
SyncJobsInfo* pPackageSyncJobsInfo = itr->second;
- if (pPackageSyncJobsInfo->CheckUid(uid, syncJobId)) {
- int ret = pPackageSyncJobsInfo->RemoveSyncJob(syncJobId);
- if (pPackageSyncJobsInfo->GetSyncJobsCount() == 0) {
- delete pPackageSyncJobsInfo;
- __syncJobsContainer.erase(itr);
- }
- return ret;
+ int ret = pPackageSyncJobsInfo->RemoveSyncJob(syncJobId);
+ if (pPackageSyncJobsInfo->GetSyncJobsCount() == 0) {
+ delete pPackageSyncJobsInfo;
+ __syncJobsContainer.erase(itr);
}
+ return ret;
}
return -1;
/* 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;
int
-SyncJobsAggregator::GetSyncJobId(const char* pPackageId, int uid, const char* pSyncJobName) {
- ISyncJob* pSyncJob = GetSyncJob(pPackageId, uid, pSyncJobName);
+SyncJobsAggregator::GetSyncJobId(const char* pPackageId, const char* pSyncJobName) {
+ ISyncJob* pSyncJob = GetSyncJob(pPackageId, pSyncJobName);
int id = (pSyncJob == NULL) ? -1 : pSyncJob->GetSyncJobId();
return id;
ISyncJob*
-SyncJobsAggregator::GetSyncJob(const char* pPackageId, int uid, const char* pSyncJobName) {
+SyncJobsAggregator::GetSyncJob(const char* pPackageId, 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;
}
ISyncJob*
-SyncJobsAggregator::GetSyncJob(const char* pPackageId, int uid, int syncJobId) {
+SyncJobsAggregator::GetSyncJob(const char* pPackageId, int syncJobId) {
ISyncJob* pSyncJob = NULL;
map<string, SyncJobsInfo*>::iterator itr = __syncJobsContainer.find(pPackageId);
if (itr != __syncJobsContainer.end()) {
SyncJobsInfo* pPackageSyncJobsInfo = itr->second;
- if (uid == 0 || pPackageSyncJobsInfo->CheckUid(uid, syncJobId))
- pSyncJob = pPackageSyncJobsInfo->GetSyncJob(syncJobId);
+ pSyncJob = pPackageSyncJobsInfo->GetSyncJob(syncJobId);
} else {
LOG_LOGD("Sync jobs for package %s are not found", pPackageId); /* LCOV_EXCL_LINE */
}
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;
}
class SyncJobsAggregator {
public:
- void AddSyncJob(const char* pPackageId, int uid, const char* pSyncJobName, ISyncJob* pSyncJob);
+ void AddSyncJob(const char* pPackageId, const char* pSyncJobName, ISyncJob* pSyncJob);
- int RemoveSyncJob(const char* pPackageId, int uid, int jobId);
+ int RemoveSyncJob(const char* pPackageId, int jobId);
int RemoveSyncJob(const char* pPackageId, const char* pSyncJobName);
- bool HasSyncJob(const char* pPackageId, int uid, const char* pSyncJobName);
+ bool HasSyncJob(const char* pPackageId, const char* pSyncJobName);
- int GetSyncJobId(const char* pPackageId, int uid, const char* pSyncJobName);
+ int GetSyncJobId(const char* pPackageId, const char* pSyncJobName);
int GenerateSyncJobId(const char* pPackageId);
- ISyncJob* GetSyncJob(const char* pPackageId, int uid, const char* pSyncJobName);
+ ISyncJob* GetSyncJob(const char* pPackageId, const char* pSyncJobName);
- ISyncJob* GetSyncJob(const char* pPackageId, int uid, int syncJobId);
+ ISyncJob* GetSyncJob(const char* pPackageId, int syncJobId);
vector < int > GetSyncJobIDList(const char* pPackageId);
SyncJobsInfo::SyncJobsInfo(string packageId)
: __packageId(packageId) {
- for (int i = 0; i < SYNC_JOB_LIMIT; i++)
- __syncJobId[i] = 0;
+ for (int i = 0; i < SYNC_JOB_LIMIT; i++) {
+ __syncJobId[i] = false;
+ }
}
int
-SyncJobsInfo::AddSyncJob(string syncJobName, int uid, ISyncJob* pSyncJob) {
+SyncJobsInfo::AddSyncJob(string syncJobName, ISyncJob* pSyncJob) {
__syncJobsList.insert(make_pair(syncJobName, pSyncJob));
__syncIdList.insert(make_pair(pSyncJob->GetSyncJobId(), pSyncJob));
- __syncJobId[pSyncJob->GetSyncJobId()] = uid;
+ __syncJobId[pSyncJob->GetSyncJobId()] = true;
return SYNC_ERROR_NONE;
}
}
-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);
if (itr != __syncJobsList.end()) {
ISyncJob* pSyncJob = itr->second;
int syncJobId = pSyncJob->GetSyncJobId();
- __syncJobId[syncJobId] = 0;
+ __syncJobId[syncJobId] = false;
LOG_LOGD("Removing job name [%s] id [%d] from package [%s]", syncJobname.c_str(), syncJobId, __packageId.c_str());
delete pSyncJob;
map<int, ISyncJob*>::iterator itr = __syncIdList.begin();
while (itr != __syncIdList.end()) {
- /* 0 means that can get and remove sync jobs without condition */
- SyncManager::GetInstance()->RemoveSyncJob(__packageId.c_str(), 0, itr->first);
+ SyncManager::GetInstance()->RemoveSyncJob(__packageId.c_str(), itr->first);
itr++;
}
}
}
}
- if (idx == SYNC_JOB_LIMIT)
+ if (idx == SYNC_JOB_LIMIT) {
value = SYNC_JOB_LIMIT + 1;
+ }
return value;
}
int idx;
for (idx = 0; idx < SYNC_JOB_LIMIT; idx++) {
- if (__syncJobId[idx])
+ if (__syncJobId[idx]) {
idList.push_back(idx);
+ }
}
return idList;
}
ISyncJob* GetSyncJob(int syncJobId);
- bool CheckUid(int uid, int syncJobId);
-
int RemoveSyncJob(int syncJobId);
int RemoveSyncJob(string syncJobName);
- int AddSyncJob(string syncJobName, int uid, ISyncJob* pSyncJob);
+ int AddSyncJob(string syncJobName, ISyncJob* pSyncJob);
int GetNextSyncJobId();
map < string, ISyncJob * > __syncJobsList;
map < int, ISyncJob * > __syncIdList;
string __packageId;
- int __syncJobId[SYNC_JOB_LIMIT + 1];
+ bool __syncJobId[SYNC_JOB_LIMIT + 1];
};
/*
int
-SyncManager::AddOnDemandSync(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId) {
+SyncManager::AddOnDemandSync(string pPackageId, 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());
/* LCOV_EXCL_STOP */
}
- SyncJob* pJob = new (std::nothrow) SyncJob(pSyncAdapterApp, uid, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_ON_DEMAND);
+ SyncJob* pJob = new (std::nothrow) SyncJob(pSyncAdapterApp, 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(), uid, syncJobName, pJob);
+ __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), syncJobName, pJob);
ScheduleSyncJob(pJob);
int
-SyncManager::AddPeriodicSyncJob(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, long period) {
+SyncManager::AddPeriodicSyncJob(string pPackageId, 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);
/* LCOV_EXCL_STOP */
}
- PeriodicSyncJob* pRequestedJob = new (std::nothrow) PeriodicSyncJob(pSyncAdapterApp, uid, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_PERIODIC, period / 60);
+ PeriodicSyncJob* pRequestedJob = new (std::nothrow) PeriodicSyncJob(pSyncAdapterApp, 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(), uid, syncJobName, pRequestedJob);
+ __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), syncJobName, pRequestedJob);
__pPeriodicSyncScheduler->SchedulePeriodicSyncJob(pRequestedJob);
if (pRequestedJob->IsExpedited()) {
int
-SyncManager::AddDataSyncJob(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, const char* pCapability) {
+SyncManager::AddDataSyncJob(string pPackageId, 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);
/* LCOV_EXCL_STOP */
}
- DataSyncJob* pRequestedJob = new (std::nothrow) DataSyncJob(pSyncAdapterApp, uid, syncJobName, accountId, pExtras, syncOption, syncJobId, SYNC_TYPE_DATA_CHANGE, pCapability);
+ DataSyncJob* pRequestedJob = new (std::nothrow) DataSyncJob(pSyncAdapterApp, 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(), uid, syncJobName, pRequestedJob);
+ __pSyncJobsAggregator->AddSyncJob(pPackageId.c_str(), syncJobName, pRequestedJob);
__pDataChangeSyncScheduler->AddDataSyncJob(syncJobName, pRequestedJob);
if (pRequestedJob->IsExpedited()) {
int
-SyncManager::RemoveSyncJob(string packageId, int uid, int syncJobId) {
+SyncManager::RemoveSyncJob(string packageId, int syncJobId) {
LOG_LOGD("Starts");
int ret = SYNC_ERROR_NONE;
- ISyncJob* pSyncJob = __pSyncJobsAggregator->GetSyncJob(packageId.c_str(), uid, syncJobId);
+ ISyncJob* pSyncJob = __pSyncJobsAggregator->GetSyncJob(packageId.c_str(), 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();
CancelSync(pJob);
- __pSyncJobsAggregator->RemoveSyncJob(packageId.c_str(), uid, syncJobId);
+ __pSyncJobsAggregator->RemoveSyncJob(packageId.c_str(), syncJobId);
return ret;
}
void
SyncManager::OnDNetStatusChanged(bool connected) {
LOG_LOGD("Data network change detected %d", connected);
+
//bool wasConnected = __isSimDataConnectionPresent;
__isSimDataConnectionPresent = connected;
- if (__isSimDataConnectionPresent)
- SendSyncCheckAlarmMessage();
-}
-
-
-void
-SyncManager::OnBTStatusChanged(bool connected) {
- LOG_LOGD("Bluetooth status %d", connected);
- __isBTConnectionPresent = connected;
- if (__isBTConnectionPresent)
+ if (__isSimDataConnectionPresent) {
SendSyncCheckAlarmMessage();
+ }
}
void
SyncManager::OnWifiStatusChanged(bool connected) {
LOG_LOGD("Wifi network change detected %d", connected);
+
//bool wasConnected = __isWifiConnectionPresent;
__isWifiConnectionPresent = connected;
- if (__isWifiConnectionPresent)
+ if (__isWifiConnectionPresent) {
SendSyncCheckAlarmMessage();
+ }
}
void
SyncManager::OnEthernetStatusChanged(bool connected) {
LOG_LOGD("Ethernet change detected %d", connected);
+
__isEthernetConnectionPresent = connected;
- if (__isEthernetConnectionPresent)
+ if (__isEthernetConnectionPresent) {
SendSyncCheckAlarmMessage();
+ }
+}
+
+
+void
+SyncManager::OnBluetoothStatusChanged(bool connected) {
+ LOG_LOGD("Bluetooth status %d", connected);
}
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()->RecordSyncAdapter(pPkgId, userId);
- SyncManager::GetInstance()->GetSyncRepositoryEngine()->RecordSyncJob(pPkgId, userId);
- SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsDataOnDB();
}
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->SaveCurrentState();
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsData();
+
return 0;
}
/* LCOV_EXCL_STOP */
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;
if (!strcmp(val, "enable_app")) {
pAggregator->SetAppStatus(app_id, "enabled");
- 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);
+ SyncManager::GetInstance()->RecordSyncAdapter();
} else if (!strcmp(val, "disable_app")) {
pAggregator->SetAppStatus(app_id, "disabled");
- 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();
+ SyncManager::GetInstance()->RecordSyncAdapter();
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->CancelPackageSyncJobs(package_name);
+ SyncManager::GetInstance()->RecordSyncJob();
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsData();
}
return 0;
SyncManager::SyncManager(void)
: __isStorageLow(false)
- , __isBTConnectionPresent(false)
, __isWifiConnectionPresent(false)
, __isEthernetConnectionPresent(false)
, __isSimDataConnectionPresent(false)
__pSyncJobDispatcher = new (std::nothrow) SyncJobDispatcher();
LOG_LOGE_BOOL(__pSyncJobDispatcher, "Failed to construct SyncJobDispatcher");
- __isBTConnectionPresent = __pNetworkChangeListener->IsBTConnected();
__isWifiConnectionPresent = __pNetworkChangeListener->IsWifiConnected();
__isEthernetConnectionPresent = __pNetworkChangeListener->IsEthernetConnected();
__isSimDataConnectionPresent = __pNetworkChangeListener->IsDataConnectionPresent();
- LOG_LOGD("WiFi %d, Ethernet %d, SIM %d, BT %d, storage %d", __isWifiConnectionPresent, __isEthernetConnectionPresent, __isSimDataConnectionPresent, __isBTConnectionPresent, __isStorageLow);
+ LOG_LOGD("wifi %d, ethernet %d, sim %d, storage %d", __isWifiConnectionPresent, __isEthernetConnectionPresent, __isSimDataConnectionPresent, __isStorageLow);
LOG_LOGD("Register event listeners");
RegisterForNetworkChange();
void
SyncManager::HandleShutdown(void) {
pthread_mutex_lock(&__syncJobQueueMutex);
+ __pSyncRepositoryEngine->SaveCurrentState();
SyncManager::GetInstance()->Destruct();
pthread_mutex_unlock(&__syncJobQueueMutex);
}
/* LCOV_EXCL_START */
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) {
+SyncManager::RecordSyncAdapter(void) {
pthread_mutex_lock(&__syncJobQueueMutex);
- __pSyncRepositoryEngine->RecordSyncJob(PkgName, UserId, JobId);
+ __pSyncRepositoryEngine->SaveCurrentSyncAdapter();
pthread_mutex_unlock(&__syncJobQueueMutex);
}
void
-SyncManager::RecordSyncJob(const char *PkgName, int UserId) {
+SyncManager::RecordSyncJob(void) {
pthread_mutex_lock(&__syncJobQueueMutex);
- __pSyncRepositoryEngine->RecordSyncJob(PkgName, UserId);
+ __pSyncRepositoryEngine->SaveCurrentSyncJob();
pthread_mutex_unlock(&__syncJobQueueMutex);
}
/* LCOV_EXCL_STOP */
void
-SyncManager::OnResultReceived(SyncStatus res, string svcAppId, string packageId, const char* syncJobName) {
+SyncManager::OnResultReceived(SyncStatus res, string svcAppUID, string packageId, const char* syncJobName) {
string key;
- key.append("id:").append(svcAppId).append(syncJobName);
+ key.append("id:").append(svcAppUID).append(syncJobName);
LOG_LOGD("Close Sync context for key %s", key.c_str());
#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"
bool GetSyncSetting();
- int AddOnDemandSync(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId);
+ int AddOnDemandSync(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId);
int CancelSync(SyncJob* pJob);
- int AddPeriodicSyncJob(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, long period);
+ int AddPeriodicSyncJob(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, long period);
- int AddDataSyncJob(string pPackageId, int uid, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, const char* pCapability);
+ int AddDataSyncJob(string pPackageId, const char* syncJobName, int accountId, bundle* pExtras, int syncOption, int syncJobId, const char* pCapability);
- int RemoveSyncJob(string packageId, int uid, int syncJobId);
+ int RemoveSyncJob(string packageId, int syncJobId);
SyncJobQueue* GetSyncJobQueue(void) const;
/* Callback on wifi, ethernet, cellular, bt and wifidirect status change */
void OnDNetStatusChanged(bool connected);
- void OnBTStatusChanged(bool connected);
-
void OnWifiStatusChanged(bool connected);
void OnEthernetStatusChanged(bool connected);
+ void OnBluetoothStatusChanged(bool connected);
+
void OnStorageStatusChanged(int value);
void OnBatteryStatusChanged(int value);
void AlertForChange();
- void OnResultReceived(SyncStatus res, string svcAppId, string packageId, const char* syncJobName);
+ void OnResultReceived(SyncStatus res, string svcAppUID, string packageId, const char* syncJobName);
string GetPkgIdByAppId(const char* pAppId);
void HandleShutdown(void);
- void RecordSyncAdapter(const char *SvcAppId, const char *PkgName, int UserId, const char *AppStatus);
-
- 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 RecordSyncAdapter(void);
- void RecordSyncJob(const char *PkgName, int UserId);
+ void RecordSyncJob(void);
void CloseCurrentSyncContext(CurrentSyncContext *activeSyncContext);
private:
bool __isStorageLow;
- bool __isBTConnectionPresent;
bool __isWifiConnectionPresent;
bool __isEthernetConnectionPresent;
bool __isSimDataConnectionPresent;
/* LCOV_EXCL_START */
int
-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);
+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, "#");
+ }
int ret = SYNC_ERROR_NONE;
- ret = aul_app_get_status_for_uid(appId, uid);
+ ret = aul_app_get_status_for_uid(pServiceAppId, uid);
if (ret == -1) {
/* Send launch request to wake application */
- LOG_LOGD("[%s] is not running, launch the app and wait for signal", appId);
+ LOG_LOGD("[%s] is not running, launch the app and wait for signal", pServiceAppId);
- /* 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]", appId, 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]", 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));
+ 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));
sa_app_id.clear();
return SYNC_ERROR_SYSTEM;
} else {
- LOG_LOGD("[%s] app is already running", appId);
- TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*)g_hash_table_lookup(g_hash_table, appId);
+ 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);
if (!pSyncAdapter) {
LOG_LOGD("Sync adapter entry not found. Preparing sync adapter object");
app_context_h app_context = NULL;
pid_t pid;
- int ret = app_manager_get_app_context(appId, &app_context);
+ int ret = app_manager_get_app_context(pServiceAppId, &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);
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);
- LOG_LOGD("inserting sync adapter ipc %s %x", appId, pSyncAdapter);
- g_hash_table_insert(g_hash_table, (gchar*)appId, pSyncAdapter);
+ /* appId#uid */
+ LOG_LOGD("inserting sync adapter ipc %s %x", appUID, pSyncAdapter);
+ g_hash_table_insert(g_hash_table, strdup(appUID), pSyncAdapter);
} else {
SYNC_LOGE_RET_RES(!(error->message), SYNC_ERROR_SYSTEM, "export failed [%s]", error->message);
return SYNC_ERROR_SYSTEM;
void
-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);
+SyncService::TriggerStopSync(const char* appUID, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras) {
+ LOG_LOGD("Trigger stop sync [%s]", appUID);
- TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*)g_hash_table_lookup(g_hash_table, appId);
+ TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, appUID);
if (!pSyncAdapter) {
LOG_LOGD("Failed to lookup syncadapter");
return;
int
-SyncService::RequestOnDemandSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, int* pSyncJobId) {
+SyncService::RequestOnDemandSync(const char* pPackageId, 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, uid, pSyncJobName);
+ ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName);
if (pSyncJob) {
SyncJob* pSyncJobEntry = dynamic_cast< SyncJob* > (pSyncJob);
SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get sync job");
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, uid, pSyncJobName, accountId, pExtras, syncOption, syncJobId);
+ ret = __pSyncManagerInstance->AddOnDemandSync(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId);
}
if (ret == SYNC_ERROR_NONE)
int
-SyncService::RequestPeriodicSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId) {
+SyncService::RequestPeriodicSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId) {
int ret = SYNC_ERROR_NONE;
int syncJobId = -1;
pSyncJobsAggregator->SetMinPeriod((int)pollFrequency / 60);
pSyncJobsAggregator->SetLimitTime(pSyncJobsAggregator->GetMinPeriod());
- ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, uid, pSyncJobName);
+ ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName);
if (pSyncJob) {
PeriodicSyncJob* pSyncJobEntry = dynamic_cast< PeriodicSyncJob* > (pSyncJob);
SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get syn job");
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, uid, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pollFrequency);
+ ret = __pSyncManagerInstance->AddPeriodicSyncJob(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pollFrequency);
}
if (ret == SYNC_ERROR_NONE)
int
-SyncService::RequestDataSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, const char* pCapability, int* pSyncJobId) {
+SyncService::RequestDataSync(const char* pPackageId, 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, uid, pSyncJobName);
+ ISyncJob* pSyncJob = pSyncJobsAggregator->GetSyncJob(pPackageId, pSyncJobName);
if (pSyncJob) {
DataSyncJob* pSyncJobEntry = dynamic_cast< DataSyncJob* > (pSyncJob);
SYNC_LOGE_RET_RES(pSyncJobEntry != NULL, SYNC_ERROR_SYSTEM, "Failed to get syn job");
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, uid, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pCapability);
+ ret = __pSyncManagerInstance->AddDataSyncJob(pPackageId, pSyncJobName, accountId, pExtras, syncOption, syncJobId, pCapability);
}
if (ret == SYNC_ERROR_NONE)
g_variant_get(va, "s", &name);
*pAppId = strdup(name);
LOG_LOGD("DBus service [%s]", *pAppId);
- free(name);
}
}
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, pAppId, pkgIdStr, sync_job_name);
+ SyncManager::GetInstance()->OnResultReceived((SyncStatus)sync_result, pServiceAppUID, pkgIdStr, sync_job_name);
+ free(pAppId);
} 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;
}
*/
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;
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(), atoi((char*)uid), pSyncJobName, accountId, pBundle, sync_option, &sync_job_id);
+ ret = SyncService::GetInstance()->RequestOnDemandSync(pkgIdStr.c_str(), pSyncJobName, accountId, pBundle, sync_option, &sync_job_id);
bundle_free(pBundle);
} else {
LOG_LOGD("Failed to get package id"); /* LCOV_EXCL_LINE */
gboolean
-sync_manager_remove_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* uid, const gchar* pCommandLine, gint sync_job_id) {
+sync_manager_remove_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, 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_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);
free(pAppId);
if (!pkgIdStr.empty()) {
LOG_LOGD("package id [%s]", pkgIdStr.c_str());
- ret = SyncManager::GetInstance()->RemoveSyncJob(pkgIdStr, atoi((char*)uid), sync_job_id);
+ ret = SyncManager::GetInstance()->RemoveSyncJob(pkgIdStr, sync_job_id);
} else {
LOG_LOGD("sync service: Get package Id fail %d", ret); /* LCOV_EXCL_LINE */
}
}
LOG_LOGD("sync service: recoding the change of registered sync job");
-
- SyncManager::GetInstance()->RecordSyncJob((char*)pkgIdStr.c_str(), atoi((char*)uid), (int)sync_job_id);
- SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsDataOnDB();
+ SyncManager::GetInstance()->RecordSyncJob();
+ SyncManager::GetInstance()->GetSyncRepositoryEngine()->CheckSyncJobsData();
LOG_LOGD("sync service: remove sync job ends");
gboolean
sync_manager_add_periodic_job(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation,
- const gchar* uid,
const gchar* pCommandLine,
gint accountId,
const gchar* pSyncJobName,
gint sync_option,
GVariant* pSyncJobUserData) {
LOG_LOGD("Received Period Sync request");
- LOG_LOGD("Caller UID : %s", (const char*)uid);
int ret = SYNC_ERROR_NONE;
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);
/* LCOV_EXCL_STOP */
}
- bundle *pBundle = NULL;
+ int sync_job_id = 0;
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());
- pBundle = umarshal_bundle(pSyncJobUserData);
+ bundle* pBundle = umarshal_bundle(pSyncJobUserData);
SyncManager::GetInstance()->AddRunningAccount(accountId, pid);
- ret = SyncService::GetInstance()->RequestPeriodicSync(pkgIdStr.c_str(), atoi((char*)uid), pSyncJobName, accountId, pBundle, sync_option, sync_interval, &sync_job_id);
+ ret = SyncService::GetInstance()->RequestPeriodicSync(pkgIdStr.c_str(), pSyncJobName, accountId, pBundle, sync_option, sync_interval, &sync_job_id);
+ bundle_free(pBundle);
} else {
LOG_LOGD("sync service: Get package Id fail %d", ret); /* LCOV_EXCL_LINE */
}
pManageIdleState->ResetTermTimer();
LOG_LOGD("sync service: recoding the change of registered sync job");
-
- 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);
+ SyncManager::GetInstance()->RecordSyncJob();
LOG_LOGD("sync service: add periodic sync job ends");
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;
- const char *capability = (char *)pCapabilityArg;
- if (!strcmp(capability, "http://tizen.org/sync/capability/calendar") ||
- !strcmp(capability, "http://tizen.org/sync/capability/contact")) {
- if (!strcmp(capability, "http://tizen.org/sync/capability/calendar"))
- ret = _check_privilege_calendar_read(pInvocation);
- else
- ret = _check_privilege_contact_read(pInvocation);
-
- if (ret != SYNC_ERROR_NONE) {
- /* LCOV_EXCL_START */
- GError* error = NULL;
+ if (_FEATURE_CALENDAR_ENABLE) {
+ const char *capability = (char *)pCapabilityArg;
+ if (!strcmp(capability, "http://tizen.org/sync/capability/calendar") ||
+ !strcmp(capability, "http://tizen.org/sync/capability/contact")) {
if (!strcmp(capability, "http://tizen.org/sync/capability/calendar"))
- error = g_error_new(_sync_error_quark(), ret, "sync service: calendar.read permission denied");
+ ret = _check_privilege_calendar_read(pInvocation);
else
+ ret = _check_privilege_contact_read(pInvocation);
+
+ if (ret != SYNC_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ GError* error = NULL;
+ if (!strcmp(capability, "http://tizen.org/sync/capability/calendar"))
+ error = g_error_new(_sync_error_quark(), ret, "sync service: calendar.read permission denied");
+ else
+ error = g_error_new(_sync_error_quark(), ret, "sync service: contact.read permission denied");
+
+ g_dbus_method_invocation_return_gerror(pInvocation, error);
+ g_clear_error(&error);
+ /* LCOV_EXCL_STOP */
+ return true;
+ }
+ }
+ } else {
+ const char *capability = (char *)pCapabilityArg;
+ if (!strcmp(capability, "http://tizen.org/sync/capability/contact")) {
+ ret = _check_privilege_contact_read(pInvocation);
+
+ if (ret != SYNC_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ GError* error = NULL;
error = g_error_new(_sync_error_quark(), ret, "sync service: contact.read permission denied");
- g_dbus_method_invocation_return_gerror(pInvocation, error);
- g_clear_error(&error);
- /* LCOV_EXCL_STOP */
- return true;
+ g_dbus_method_invocation_return_gerror(pInvocation, error);
+ g_clear_error(&error);
+ /* LCOV_EXCL_STOP */
+ return true;
+ }
}
}
guint pid = get_caller_pid(pInvocation);
string pkgIdStr;
- int sync_job_id = 0;
char* pAppId;
ret = app_manager_get_app_id(pid, &pAppId);
/* LCOV_EXCL_STOP */
}
- bundle *pBundle = NULL;
+ int sync_job_id = 0;
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());
- pBundle = umarshal_bundle(pSyncJobUserData);
+
+ bundle* pBundle = umarshal_bundle(pSyncJobUserData);
SyncManager::GetInstance()->AddRunningAccount(accountId, pid);
- ret = SyncService::GetInstance()->RequestDataSync(pkgIdStr.c_str(), atoi((char*)uid), pCapabilityArg, accountId, pBundle, sync_option, pCapabilityArg, &sync_job_id);
+ ret = SyncService::GetInstance()->RequestDataSync(pkgIdStr.c_str(), pCapabilityArg, accountId, pBundle, sync_option, pCapabilityArg, &sync_job_id);
+
+ bundle_free(pBundle);
} else {
LOG_LOGD("sync service: Get package Id fail %d", ret); /* LCOV_EXCL_LINE */
}
pManageIdleState->ResetTermTimer();
LOG_LOGD("sync service: recoding the change of registered sync job");
-
- 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);
+ SyncManager::GetInstance()->RecordSyncJob();
LOG_LOGD("sync service: add data sync job ends");
gboolean
-sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* uid, const gchar* pCommandLine) {
+sync_manager_add_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* pCommandLine) {
LOG_LOGD("Received sync adapter registration request");
- LOG_LOGD("Caller UID : %s", (const char*)uid);
guint pid = get_caller_pid(pInvocation);
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);
- LOG_LOGD("inserting sync adapter ipc %s", pAppId);
- g_hash_table_insert(g_hash_table, (gchar*)pAppId, syncAdapterObj);
+ 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);
ret = SYNC_ERROR_NONE;
} else {
}
LOG_LOGD("sync service: recoding the change of registered sync adapter");
- SyncManager::GetInstance()->RecordSyncAdapter((const char*)pAppId, pkgIdStr.c_str(), atoi(uid), "enabled");
+ SyncManager::GetInstance()->RecordSyncAdapter();
LOG_LOGD("sync service: adding sync adapter ends");
gboolean
-sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* uid, const gchar* pCommandLine) {
+sync_manager_remove_sync_adapter(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, 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);
}
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);
} else {
LOG_LOGD("sync service: Get package Id fail [%d]", ret); /* LCOV_EXCL_LINE */
}
- TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, pAppId);
+ char pAppUID[100];
+ snprintf(pAppUID, 100, "%s#%d", pAppId, getuid());
+
+ TizenSyncAdapter* pSyncAdapter = (TizenSyncAdapter*) g_hash_table_lookup(g_hash_table, pAppUID);
if (pSyncAdapter == NULL) {
/* LCOV_EXCL_START */
- LOG_LOGD("Failed to lookup syncadapter gdbus object for [%s]", pAppId);
+ LOG_LOGD("Failed to lookup syncadapter gdbus object for [%s]", pAppUID);
char object_path[50];
snprintf(object_path, 50, "%s%d", SYNC_ADAPTER_DBUS_PATH, pid);
g_signal_connect(syncAdapterObj, "handle-send-result", G_CALLBACK(sync_adapter_handle_send_result), NULL);
pAggregator->RemoveSyncAdapter(pkgIdStr.c_str());
- LOG_LOGD("deleting sync adapter ipc [%s]", pAppId);
+ LOG_LOGD("deletting sync adapter ipc [%s]", pAppUID);
ret = SYNC_ERROR_NONE;
} else {
tizen_sync_manager_complete_remove_sync_adapter(pObject, pInvocation);
LOG_LOGD("sync service: recoding the change of registered sync adapter");
- SyncManager::GetInstance()->RecordSyncAdapter(pkgIdStr.c_str(), atoi(uid));
+ SyncManager::GetInstance()->RecordSyncAdapter();
LOG_LOGD("sync service: removing sync adapter ends");
}
+
gboolean
-sync_manager_get_all_sync_jobs(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, const gchar* uid, const gchar* pCommandLine) {
+sync_manager_get_all_sync_jobs(TizenSyncManager* pObject, GDBusMethodInvocation* pInvocation, 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;
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());
public:
int StartService(void);
- int TriggerStartSync(const char* appId, int uid, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras);
+ int TriggerStartSync(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);
+ void TriggerStopSync(const char* appUID, int accountId, const char* syncJobName, bool isDataSync, bundle* pExtras);
- int RequestOnDemandSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, int* pSyncJobId);
+ int RequestOnDemandSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, int* pSyncJobId);
- int RequestPeriodicSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId);
+ int RequestPeriodicSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, unsigned long pollFrequency, int* pSyncJobId);
- int RequestDataSync(const char* pPackageId, int uid, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, const char* pCapability, int* pSyncJobId);
+ int RequestDataSync(const char* pPackageId, const char* pSyncJobName, int accountId, bundle* pExtras, int syncOption, const char* pCapability, int* pSyncJobId);
void HandleShutdown(void);
<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" />
<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" />
<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" />
<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">