Merge branch 'develop' into refactor_remote_operation_to_create_folder
[pub/Android/ownCloud.git] / src / com / owncloud / android / files / services / FileObserverService.java
index d4bf24d..fa1fec2 100644 (file)
@@ -3,9 +3,8 @@
  *   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
@@ -29,6 +28,8 @@ import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
 import com.owncloud.android.files.OwnCloudFileObserver;
 import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.utils.FileStorageUtils;
+import com.owncloud.android.utils.Log_OC;
+
 
 import android.accounts.Account;
 import android.accounts.AccountManager;
@@ -40,7 +41,6 @@ import android.content.IntentFilter;
 import android.database.Cursor;
 import android.os.Binder;
 import android.os.IBinder;
-import android.util.Log;
 
 public class FileObserverService extends Service {
 
@@ -57,7 +57,7 @@ public class FileObserverService extends Service {
     private static Map<String, OwnCloudFileObserver> mObserversMap;
     private static DownloadCompletedReceiverBis mDownloadReceiver;
     private IBinder mBinder = new LocalBinder();
-
+    
     public class LocalBinder extends Binder {
         FileObserverService getService() {
             return FileObserverService.this;
@@ -68,9 +68,10 @@ public class FileObserverService extends Service {
     public void onCreate() {
         super.onCreate();
         mDownloadReceiver = new DownloadCompletedReceiverBis();
+        
         IntentFilter filter = new IntentFilter();
-        filter.addAction(FileDownloader.DOWNLOAD_ADDED_MESSAGE);
-        filter.addAction(FileDownloader.DOWNLOAD_FINISH_MESSAGE);        
+        filter.addAction(FileDownloader.getDownloadAddedMessage());
+        filter.addAction(FileDownloader.getDownloadFinishMessage());        
         registerReceiver(mDownloadReceiver, filter);
         
         mObserversMap = new HashMap<String, OwnCloudFileObserver>();
@@ -83,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");
     }
     
     
@@ -102,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;
         }
 
@@ -119,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;
@@ -161,12 +162,11 @@ public class FileObserverService extends Service {
             OwnCloudFileObserver observer =
                     new OwnCloudFileObserver(   path, 
                                                 account, 
-                                                getApplicationContext(), 
-                                                OwnCloudFileObserver.CHANGES_ONLY);
+                                                getApplicationContext());
             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());
@@ -189,7 +189,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,14 +201,13 @@ public class FileObserverService extends Service {
             /// the local file was never registered to observe before
             observer = new OwnCloudFileObserver(    localPath, 
                                                     account, 
-                                                    getApplicationContext(), 
-                                                    OwnCloudFileObserver.CHANGES_ONLY);
+                                                    getApplicationContext());
             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
         }
         
@@ -229,7 +228,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();
@@ -241,7 +240,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,14 +259,14 @@ public class FileObserverService extends Service {
             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(FileDownloader.getDownloadFinishMessage()) &&
+                        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.d(TAG, "Watching again " + downloadPath);
+                    Log_OC.d(TAG, "Watching again " + downloadPath);
                 
-                } else if (intent.getAction().equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {
+                } else if (intent.getAction().equals(FileDownloader.getDownloadAddedMessage())) {
                     observer.stopWatching();
-                    Log.d(TAG, "Disabling observance of " + downloadPath);
+                    Log_OC.d(TAG, "Disabling observance of " + downloadPath);
                 } 
             }
         }