* Copyright (C) 2012-2013 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
import android.database.Cursor;
import android.os.Binder;
import android.os.IBinder;
-import android.util.Log;
public class FileObserverService extends Service {
private static Map<String, OwnCloudFileObserver> mObserversMap;
private static DownloadCompletedReceiverBis mDownloadReceiver;
private IBinder mBinder = new LocalBinder();
+
+ private String mDownloadAddedMessage;
+ private String mDownloadFinishMessage;
public class LocalBinder extends Binder {
FileObserverService getService() {
public void onCreate() {
super.onCreate();
mDownloadReceiver = new DownloadCompletedReceiverBis();
+
+ FileDownloader downloader = new FileDownloader();
+ mDownloadAddedMessage = downloader.getDownloadAddedMessage();
+ mDownloadFinishMessage= downloader.getDownloadFinishMessage();
+
IntentFilter filter = new IntentFilter();
- filter.addAction(FileDownloader.DOWNLOAD_ADDED_MESSAGE);
- filter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE);
+ filter.addAction(mDownloadAddedMessage);
+ filter.addAction(mDownloadFinishMessage);
registerReceiver(mDownloadReceiver, filter);
mObserversMap = new HashMap<String, OwnCloudFileObserver>();
String downloadPath = intent.getStringExtra(FileDownloader.EXTRA_FILE_PATH);
OwnCloudFileObserver observer = mObserversMap.get(downloadPath);
if (observer != null) {
- if (intent.getAction().equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE) &&
- new File(downloadPath).exists()) { // the download could be successful, or not; in both cases, the file could be down, due to a former download or upload
+ if (intent.getAction().equals(mDownloadFinishMessage) &&
+ new File(downloadPath).exists()) { // the download could be successful. not; in both cases, the file could be down, due to a former download or upload
observer.startWatching();
Log_OC.d(TAG, "Watching again " + downloadPath);
- } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {
+ } else if (intent.getAction().equals(mDownloadAddedMessage)) {
observer.stopWatching();
Log_OC.d(TAG, "Disabling observance of " + downloadPath);
}