X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/9093ef8f9fc64c290d0fed5f66106fa6a20330df..ec6b9d7c70deb50152bfab5cb5f25c9a2dde28e7:/src/com/owncloud/android/services/OperationsService.java diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index db303557..581a686d 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -103,7 +103,7 @@ public class OperationsService extends Service { public static final String ACTION_CREATE_FOLDER = "CREATE_FOLDER"; public static final String ACTION_SYNC_FILE = "SYNC_FILE"; public static final String ACTION_SYNC_FOLDER = "SYNC_FOLDER"; // for the moment, just to download - public static final String ACTION_CANCEL_SYNC_FOLDER = "CANCEL_SYNC_FOLDER"; // for the moment, just to download + //public static final String ACTION_CANCEL_SYNC_FOLDER = "CANCEL_SYNC_FOLDER"; // for the moment, just to download public static final String ACTION_MOVE_FILE = "MOVE_FILE"; public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED"; @@ -144,6 +144,8 @@ public class OperationsService extends Service { @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(); @@ -165,7 +167,9 @@ public class OperationsService extends Service { */ @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())) { @@ -187,21 +191,6 @@ public class OperationsService extends Service { mSyncFolderHandler.sendMessage(msg); } - } else if (ACTION_CANCEL_SYNC_FOLDER.equals(intent.getAction())) { - if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) { - Log_OC.e(TAG, "Not enough information provided in intent"); - return START_NOT_STICKY; - } - final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT); - final OCFile file = intent.getParcelableExtra(EXTRA_FILE); - // Cancel operation - new Thread(new Runnable() { - public void run() { - // Cancel the download - mSyncFolderHandler.cancel(account,file); - } - }).start(); - } else { Message msg = mOperationsHandler.obtainMessage(); msg.arg1 = startId; @@ -213,7 +202,7 @@ public class OperationsService extends Service { @Override public void onDestroy() { - //Log_OC.wtf(TAG, "onDestroy init" ); + Log_OC.v(TAG, "Destroying service" ); // Saving cookies try { OwnCloudClientManagerFactory.getDefaultSingleton(). @@ -230,10 +219,16 @@ public class OperationsService extends Service { e.printStackTrace(); } - //Log_OC.wtf(TAG, "Clear mUndispatchedFinisiedOperations" ); mUndispatchedFinishedOperations.clear(); - - //Log_OC.wtf(TAG, "onDestroy end" ); + + mOperationsBinder = null; + + mOperationsHandler.getLooper().quit(); + mOperationsHandler = null; + + mSyncFolderHandler.getLooper().quit(); + mSyncFolderHandler = null; + super.onDestroy(); } @@ -272,23 +267,23 @@ public class OperationsService extends Service { new ConcurrentHashMap(); private ServiceHandler mServiceHandler = null; - - + public OperationsServiceBinder(ServiceHandler serviceHandler) { mServiceHandler = serviceHandler; } /** - * Cancels an operation + * Cancels a pending or current synchronization. * - * TODO + * @param account ownCloud account where the remote folder is stored. + * @param file A folder in the queue of pending synchronizations */ - public void cancel() { - // TODO + public void cancel(Account account, OCFile file) { + mSyncFolderHandler.cancel(account, file); } - - + + public void clearListeners() { mBoundListeners.clear(); @@ -418,6 +413,7 @@ public class OperationsService extends Service { @Override public void handleMessage(Message msg) { nextOperation(); + Log_OC.d(TAG, "Stopping after command with id " + msg.arg1); mService.stopSelf(msg.arg1); }