@Override
public void onCreate() {
super.onCreate();
+ Log_OC.d(TAG, "Creating service");
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- HandlerThread thread = new HandlerThread("FileDownloaderThread",
- Process.THREAD_PRIORITY_BACKGROUND);
+ HandlerThread thread = new HandlerThread("FileDownloaderThread", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper, this);
mBinder = new FileDownloaderBinder();
}
+
+ /**
+ * Service clean up
+ */
+ @Override
+ public void onDestroy() {
+ Log_OC.v(TAG, "Destroying service" );
+ mBinder = null;
+ mServiceHandler = null;
+ mServiceLooper.quit();
+ mServiceLooper = null;
+ mNotificationManager = null;
+ super.onDestroy();
+ }
+
+
/**
* Entry point to add one or several files to the queue of downloads.
*
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+ Log_OC.d(TAG, "Starting command with id " + startId);
+
if ( !intent.hasExtra(EXTRA_ACCOUNT) ||
!intent.hasExtra(EXTRA_FILE)
) {
Iterator<String> it = requestedDownloads.iterator();
while (it.hasNext()) {
String next = it.next();
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Handling download file " + next);*/
mService.downloadFile(next);
}
}
+ Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
mService.stopSelf(msg.arg1);
}
}
@Override
public void onCreate() {
super.onCreate();
- Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size());
+ Log_OC.d(TAG, "Creating service");
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
HandlerThread thread = new HandlerThread("FileUploaderThread", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
}
/**
+ * Service clean up
+ */
+ @Override
+ public void onDestroy() {
+ Log_OC.v(TAG, "Destroying service" );
+ mBinder = null;
+ mServiceHandler = null;
+ mServiceLooper.quit();
+ mServiceLooper = null;
+ mNotificationManager = null;
+ super.onDestroy();
+ }
+
+
+ /**
* Entry point to add one or several files to the queue of uploads.
*
* New uploads are added calling to startService(), resulting in a call to
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+ Log_OC.d(TAG, "Starting command with id " + startId);
+
if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
|| !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
Log_OC.e(TAG, "Not enough information provided in intent");
mService.uploadFile(it.next());
}
}
+ Log_OC.d(TAG, "Stopping command after id " + msg.arg1);
mService.stopSelf(msg.arg1);
}
}
*/
private void startContentSynchronizations(List<SyncOperation> filesToSyncContents, OwnCloudClient client)
throws OperationCancelledException {
-
+
+ Log_OC.v(TAG, "Starting content synchronization... ");
RemoteOperationResult contentsResult = null;
for (SyncOperation op: filesToSyncContents) {
if (mCancellationRequested.get()) {
@Override
public void onCreate() {
super.onCreate();
+ Log_OC.d(TAG, "Creating service");
+
/// First worker thread for most of operations
HandlerThread thread = new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- // WIP: for the moment, only SYNC_FOLDER and CANCEL_SYNC_FOLDER is expected here;
+ Log_OC.d(TAG, "Starting command with id " + startId);
+
+ // WIP: for the moment, only SYNC_FOLDER is expected here;
// the rest of the operations are requested through the Binder
if (ACTION_SYNC_FOLDER.equals(intent.getAction())) {
- /*Log_OC.v("NOW " + TAG + ", thread " + Thread.currentThread().getName(), "Received request to sync folder");*/
-
if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) {
Log_OC.e(TAG, "Not enough information provided in intent");
return START_NOT_STICKY;
Message msg = mSyncFolderHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = itemSyncKey;
- /*Log_OC.v(
- "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Sync folder " + remotePath + " added to queue"
- );*/
mSyncFolderHandler.sendMessage(msg);
}
@Override
public void onDestroy() {
- //Log_OC.wtf(TAG, "onDestroy init" );
+ Log_OC.v(TAG, "Destroying service" );
// Saving cookies
try {
OwnCloudClientManagerFactory.getDefaultSingleton().
e.printStackTrace();
}
- //Log_OC.wtf(TAG, "Clear mUndispatchedFinishedOperations" );
mUndispatchedFinishedOperations.clear();
-
- //Log_OC.wtf(TAG, "onDestroy end" );
+
+ mOperationsBinder = null;
+
+ mOperationsHandler.getLooper().quit();
+ mOperationsHandler = null;
+
+ mSyncFolderHandler.getLooper().quit();
+ mSyncFolderHandler = null;
+
super.onDestroy();
}
* @param file A folder in the queue of pending synchronizations
*/
public void cancel(Account account, OCFile file) {
- /*Log_OC.v(
- "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Received request to cancel folder " + file.getRemotePath()
- );*/
mSyncFolderHandler.cancel(account, file);
}
@Override
public void handleMessage(Message msg) {
nextOperation();
+ Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
mService.stopSelf(msg.arg1);
}
@Override
public void handleMessage(Message msg) {
Pair<Account, String> itemSyncKey = (Pair<Account, String>) msg.obj;
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Handling sync folder " + itemSyncKey.second);*/
doOperation(itemSyncKey.first, itemSyncKey.second);
+ Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
mService.stopSelf(msg.arg1);
}
*/
private void doOperation(Account account, String remotePath) {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Getting sync folder " + remotePath);*/
mCurrentSyncOperation = mPendingOperations.get(account, remotePath);
if (mCurrentSyncOperation != null) {
mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mService);
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Executing sync folder " + remotePath);*/
result = mCurrentSyncOperation.execute(mOwnCloudClient, mStorageManager);
} catch (AccountsException e) {
} catch (IOException e) {
Log_OC.e(TAG, "Error while trying to get authorization", e);
} finally {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Removing payload " + remotePath);*/
-
mPendingOperations.removePayload(account, remotePath);
mService.dispatchResultToOperationListeners(null, mCurrentSyncOperation, result);
Log_OC.e(TAG, "Cannot cancel with NULL parameters");
return;
}
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Removing sync folder " + file.getRemotePath());*/
Pair<SynchronizeFolderOperation, String> removeResult =
mPendingOperations.remove(account, file.getRemotePath());
SynchronizeFolderOperation synchronization = removeResult.first;
if (synchronization != null) {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Canceling returned sync of " + file.getRemotePath());*/
synchronization.cancel();
} else {
// TODO synchronize?
if (mCurrentSyncOperation != null && mCurrentAccount != null &&
mCurrentSyncOperation.getRemotePath().startsWith(file.getRemotePath()) &&
account.name.equals(mCurrentAccount.name)) {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Canceling current sync as descendant: " + mCurrentSyncOperation.getRemotePath());*/
mCurrentSyncOperation.cancel();
- } else {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Nothing else in cancelation of " + file.getRemotePath());*/
}
}