浏览代码

Merge pull request #944 from nextcloud/fix-autoupload-after-acc-delete

Fix an auto upload still occurring after acc delete
Andy Scherzinger 8 年之前
父节点
当前提交
292b4bf83e

+ 18 - 0
src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java

@@ -19,6 +19,7 @@
  */
 package com.owncloud.android.datamodel;
 
+import android.accounts.Account;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
@@ -189,6 +190,22 @@ public class SyncedFolderProvider extends Observable {
 
     }
 
+    /**
+     *  Delete all synced folders for an account
+     *
+     *  @param account whose synced folders should be deleted
+     */
+    public int deleteSyncFoldersForAccount(Account account) {
+        int result = mContentResolver.delete(
+                ProviderMeta.ProviderTableMeta.CONTENT_URI_SYNCED_FOLDERS,
+                ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " = ?",
+                new String[]{String.valueOf(account.name)}
+        );
+
+        return result;
+
+    }
+
     /**
      * Delete a synced folder from the db
      *
@@ -205,6 +222,7 @@ public class SyncedFolderProvider extends Observable {
         return result;
     }
 
+
     /**
      * Try to figure out if a path exists for synced folder, and if not, go one folder back
      * Otherwise, delete the entry

+ 10 - 0
src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java

@@ -20,6 +20,7 @@
  */
 package com.owncloud.android.datamodel;
 
+import android.accounts.Account;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
@@ -413,6 +414,15 @@ public class UploadsStorageManager extends Observable {
         return list;
     }
 
+    public void cancelPendingAutoUploadJobsForAccount(Account account) {
+        JobManager jobManager = JobManager.create(mContext);
+        for (JobRequest ji: jobManager.getAllJobRequestsForTag(AutoUploadJob.TAG)) {
+            if (ji.getExtras().getString(AutoUploadJob.ACCOUNT, "").equalsIgnoreCase(account.name)) {
+                jobManager.cancel(ji.getJobId());
+            }
+        }
+    }
+
     @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
     public void cancelPendingJob(String accountName, String remotePath){
         JobManager jobManager = JobManager.create(mContext);

+ 14 - 1
src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java

@@ -29,6 +29,7 @@ import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.DialogFragment;
 import android.app.FragmentManager;
+import android.content.ContentResolver;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
@@ -53,6 +54,8 @@ import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.PushConfigurationState;
+import com.owncloud.android.datamodel.SyncedFolderProvider;
+import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.lib.common.UserInfo;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -346,9 +349,19 @@ public class UserInfoActivity extends FileActivity {
                                     // remove contact backup job
                                     ContactsPreferenceActivity.cancelContactBackupJobForAccount(getActivity(), account);
 
+                                    ContentResolver contentResolver = getActivity().getContentResolver();
+                                    // delete all synced folder for an account
+                                    SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(
+                                            contentResolver);
+                                    syncedFolderProvider.deleteSyncFoldersForAccount(account);
+
+                                    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(
+                                            contentResolver, getActivity());
+                                    uploadsStorageManager.cancelPendingAutoUploadJobsForAccount(account);
+
                                     // disable daily backup
                                     ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(
-                                            getActivity().getContentResolver());
+                                            contentResolver);
 
                                     arbitraryDataProvider.storeOrUpdateKeyValue(account,
                                             ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP,