X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/3fd56ecff8c7446e9462e43e899360822d3abb91..5a25a6a698c75d437f794f1993bbd1d281af75e9:/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 a4d12fd4..635571fb 100644 --- a/src/com/owncloud/android/files/services/FileObserverService.java +++ b/src/com/owncloud/android/files/services/FileObserverService.java @@ -1,9 +1,10 @@ /* ownCloud Android client application * Copyright (C) 2012 Bartek Przybylski + * 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 3 of the License, or + * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -22,6 +23,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import com.owncloud.android.Log_OC; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; @@ -82,7 +84,7 @@ public class FileObserverService extends Service { super.onDestroy(); unregisterReceiver(mDownloadReceiver); mObserversMap = null; // TODO study carefully the life cycle of Services to grant the best possible observance - Log.d(TAG, "Bye, bye"); + Log_OC.d(TAG, "Bye, bye"); } @@ -101,7 +103,7 @@ public class FileObserverService extends Service { } if (!intent.hasExtra(KEY_FILE_CMD)) { - Log.e(TAG, "No KEY_FILE_CMD argument given"); + Log_OC.e(TAG, "No KEY_FILE_CMD argument given"); return Service.START_STICKY; } @@ -118,7 +120,7 @@ public class FileObserverService extends Service { (Account)intent.getParcelableExtra(KEY_CMD_ARG_ACCOUNT)); break; default: - Log.wtf(TAG, "Incorrect key given"); + Log_OC.wtf(TAG, "Incorrect key given"); } return Service.START_STICKY; @@ -137,7 +139,7 @@ public class FileObserverService extends Service { ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ?", new String[] {String.valueOf(1)}, null); - if (!c.moveToFirst()) return; + if (c == null || !c.moveToFirst()) return; AccountManager acm = AccountManager.get(this); Account[] accounts = acm.getAccounts(); do { @@ -155,6 +157,8 @@ public class FileObserverService extends Service { continue; String path = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)); + if (path == null || path.length() <= 0) + continue; OwnCloudFileObserver observer = new OwnCloudFileObserver( path, account, @@ -163,7 +167,7 @@ public class FileObserverService extends Service { mObserversMap.put(path, observer); if (new File(path).exists()) { observer.startWatching(); - Log.d(TAG, "Started watching file " + path); + Log_OC.d(TAG, "Started watching file " + path); } } while (c.moveToNext()); @@ -186,7 +190,7 @@ public class FileObserverService extends Service { */ private void addObservedFile(OCFile file, Account account) { if (file == null) { - Log.e(TAG, "Trying to add a NULL file to observer"); + Log_OC.e(TAG, "Trying to add a NULL file to observer"); return; } String localPath = file.getStoragePath(); @@ -201,11 +205,11 @@ public class FileObserverService extends Service { getApplicationContext(), OwnCloudFileObserver.CHANGES_ONLY); mObserversMap.put(localPath, observer); - Log.d(TAG, "Observer added for path " + localPath); + Log_OC.d(TAG, "Observer added for path " + localPath); if (file.isDown()) { observer.startWatching(); - Log.d(TAG, "Started watching " + localPath); + Log_OC.d(TAG, "Started watching " + localPath); } // else - the observance can't be started on a file not already down; mDownloadReceiver will get noticed when the download of the file finishes } @@ -226,7 +230,7 @@ public class FileObserverService extends Service { */ private void removeObservedFile(OCFile file, Account account) { if (file == null) { - Log.e(TAG, "Trying to remove a NULL file"); + Log_OC.e(TAG, "Trying to remove a NULL file"); return; } String localPath = file.getStoragePath(); @@ -238,7 +242,7 @@ public class FileObserverService extends Service { if (observer != null) { observer.stopWatching(); mObserversMap.remove(observer); - Log.d(TAG, "Stopped watching " + localPath); + Log_OC.d(TAG, "Stopped watching " + localPath); } } @@ -260,11 +264,11 @@ public class FileObserverService extends Service { 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 observer.startWatching(); - Log.d(TAG, "Watching again " + downloadPath); + Log_OC.d(TAG, "Watching again " + downloadPath); } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) { observer.stopWatching(); - Log.d(TAG, "Disabling observance of " + downloadPath); + Log_OC.d(TAG, "Disabling observance of " + downloadPath); } } }