X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/92080afefcab6de830d6a5c099b04e3c3a7db47f..aef73a5263c94e34a38bc45ce1506651d80c7f78:/src/com/owncloud/android/files/services/FileObserverService.java diff --git a/src/com/owncloud/android/files/services/FileObserverService.java b/src/com/owncloud/android/files/services/FileObserverService.java index 88bf0b91..41e4e52b 100644 --- a/src/com/owncloud/android/files/services/FileObserverService.java +++ b/src/com/owncloud/android/files/services/FileObserverService.java @@ -18,6 +18,7 @@ package com.owncloud.android.files.services; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -50,7 +51,7 @@ public class FileObserverService extends Service implements FileObserverStatusLi public final static int CMD_DEL_OBSERVED_FILE = 3; public final static int CMD_ADD_DOWNLOADING_FILE = 4; - private static String TAG = "FileObserverService"; + private static String TAG = FileObserverService.class.getSimpleName(); private static List mObservers; private static List mDownloadReceivers; private static Object mReceiverListLock = new Object(); @@ -157,12 +158,12 @@ public class FileObserverService extends Service implements FileObserverStatusLi observer = mObservers.get(i); if (observer.getPath().equals(path)) duplicate = true; - observer.setContext(getBaseContext()); + observer.setContext(getApplicationContext()); } if (duplicate) return; observer = new OwnCloudFileObserver(path, OwnCloudFileObserver.CHANGES_ONLY); - observer.setContext(getBaseContext()); - Account account = AccountUtils.getCurrentOwnCloudAccount(getBaseContext()); + observer.setContext(getApplicationContext()); + Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()); observer.setAccount(account); FileDataStorageManager storage = new FileDataStorageManager(account, getContentResolver()); @@ -181,17 +182,16 @@ public class FileObserverService extends Service implements FileObserverStatusLi if (path == null) return; if (mObservers == null) { initializeObservedList(); - return; } for (int i = 0; i < mObservers.size(); ++i) { OwnCloudFileObserver observer = mObservers.get(i); if (observer.getPath().equals(path)) { observer.stopWatching(); mObservers.remove(i); + Log.d(TAG, "Stopped watching " + path); break; } } - Log.d(TAG, "Stopped watching " + path); } private void addDownloadingFile(String remotePath) { @@ -229,6 +229,7 @@ public class FileObserverService extends Service implements FileObserverStatusLi switch (status) { case CONFLICT: { + // ISSUE 5: if the user is not running the app (this is a service!), this can be very intrusive; a notification should be preferred Intent i = new Intent(getApplicationContext(), ConflictsResolveActivity.class); i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra("remotepath", remotePath); @@ -258,11 +259,15 @@ public class FileObserverService extends Service implements FileObserverStatusLi @Override public void onReceive(Context context, Intent intent) { if (mPath.equals(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH))) { - context.unregisterReceiver(this); - removeReceiverFromList(this); - mObserver.startWatching(); - Log.d(TAG, "Started watching " + mPath); - return; + if ((new File(mPath)).exists()) { + // the download could be successful, or not; in both cases, the file could be down, due to a former download or upload + context.unregisterReceiver(this); + removeReceiverFromList(this); + mObserver.startWatching(); + Log.d(TAG, "Started watching " + mPath); + return; + } // else - keep waiting for a future retry of the download ; + // mObserver.startWatching() won't ever work if the file is not in the device when it's called } }