X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/e7b5284983869ab254c176f4f034a3bc37819d75..b12ca42b45b69cee9e15de0abe5758f3d75f527e:/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 4cb16de1..44713d11 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; @@ -157,17 +158,17 @@ 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()); observer.setStorageManager(storage); - observer.setOCFile(storage.getFileByLocalPath(path)); + observer.setOCFile(storage.getFileByLocalPath(path)); // ISSUE 10 - the fix in FileDetailsFragment to avoid path == null was not enough; it the file was never down before, this sets a NULL OCFile in the observer observer.addObserverStatusListener(this); DownloadCompletedReceiver receiver = new DownloadCompletedReceiver(path, observer); @@ -257,12 +258,16 @@ public class FileObserverService extends Service implements FileObserverStatusLi @Override public void onReceive(Context context, Intent intent) { - if (mPath.equals(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH))) { // ISSUE 3: this condition will be false if the download failed; in that case, the download won't ever be retried - context.unregisterReceiver(this); - removeReceiverFromList(this); - mObserver.startWatching(); - Log.d(TAG, "Started watching " + mPath); - return; + if (mPath.equals(intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH))) { + 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 } }