فهرست منبع

dirty fix for null occurence

tobiasKaminsky 8 سال پیش
والد
کامیت
ccccbbb4d6

+ 25 - 21
src/com/owncloud/android/services/observer/SyncedFolderObserver.java

@@ -40,29 +40,33 @@ class SyncedFolderObserver extends RecursiveFileObserver {
     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
     @Override
     public void onEvent(int event, String path) {
-        PersistableBundle bundle = new PersistableBundle();
-        // TODO extract
-        bundle.putString("filePath", path);
-        bundle.putString("remotePath", syncedFolder.getRemotePath());
-        bundle.putLong("dateTaken", new Date().getTime());
-        bundle.putString("account", syncedFolder.getAccount());
-        bundle.putInt("uploadBehaviour", syncedFolder.getUploadAction());
-        bundle.putInt("subfolderByDate", syncedFolder.getSubfolderByDate() ? 1 : 0);
+        Log.d(TAG, "Event: " + event + " Path: " + path);
 
-        JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
-        JobInfo job = new JobInfo.Builder(
-                MY_BACKGROUND_JOB,
-                new ComponentName(context, SyncedFolderJobService.class))
-                .setRequiresCharging(syncedFolder.getChargingOnly())
-                .setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY)
-                .setExtras(bundle)
-                .build();
+        File temp = new File(path);
 
-        Integer result = js.schedule(job);
-        if (result <= 0) {
-            Log_OC.d(TAG, "Job failed to start: " + result);
-        }
+        if (!temp.getName().equalsIgnoreCase("null")) {
+            PersistableBundle bundle = new PersistableBundle();
+            // TODO extract
+            bundle.putString("filePath", path);
+            bundle.putString("remotePath", syncedFolder.getRemotePath());
+            bundle.putLong("dateTaken", new Date().getTime());
+            bundle.putString("account", syncedFolder.getAccount());
+            bundle.putInt("uploadBehaviour", syncedFolder.getUploadAction());
+            bundle.putInt("subfolderByDate", syncedFolder.getSubfolderByDate() ? 1 : 0);
 
-        Log.d(TAG, "Event: " + event + " Path: " + path);
+            JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
+            JobInfo job = new JobInfo.Builder(
+                    MY_BACKGROUND_JOB,
+                    new ComponentName(context, SyncedFolderJobService.class))
+                    .setRequiresCharging(syncedFolder.getChargingOnly())
+                    .setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY)
+                    .setExtras(bundle)
+                    .build();
+
+            Integer result = js.schedule(job);
+            if (result <= 0) {
+                Log_OC.d(TAG, "Job failed to start: " + result);
+            }
+        }
     }
 }

+ 1 - 0
src/com/owncloud/android/services/observer/SyncedFolderObserverService.java

@@ -28,6 +28,7 @@ public class SyncedFolderObserverService extends Service {
         Log_OC.d(TAG, "start");
         for (SyncedFolder syncedFolder : mProvider.getSyncedFolders()) {
             if (syncedFolder.isEnabled()) {
+                Log_OC.d(TAG, "start observer: " + syncedFolder.getLocalPath());
                 SyncedFolderObserver observer = new SyncedFolderObserver(syncedFolder);
                 observer.startWatching();
                 syncedFolderMap.put(syncedFolder.getLocalPath(), observer);