diff --git a/scripts/lint/lint-results.txt b/scripts/lint/lint-results.txt index 28fa064970..686010b195 100644 --- a/scripts/lint/lint-results.txt +++ b/scripts/lint/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 1 error and 519 warnings + Lint Report: 1 error and 511 warnings diff --git a/src/main/java/com/owncloud/android/datamodel/FilesystemDataProvider.java b/src/main/java/com/owncloud/android/datamodel/FilesystemDataProvider.java index 7b16fe14de..72c6930e17 100644 --- a/src/main/java/com/owncloud/android/datamodel/FilesystemDataProvider.java +++ b/src/main/java/com/owncloud/android/datamodel/FilesystemDataProvider.java @@ -46,6 +46,14 @@ public class FilesystemDataProvider { this.contentResolver = contentResolver; } + public int deleteAllEntriesForSyncedFolder(String syncedFolderId) { + return contentResolver.delete( + ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM, + ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ?", + new String[]{syncedFolderId} + ); + } + public void updateFilesystemFileAsSentForUpload(String path, String syncedFolderId) { ContentValues cv = new ContentValues(); cv.put(ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD, 1); diff --git a/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java b/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java index 9d139771be..2546b7187f 100644 --- a/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java @@ -601,4 +601,12 @@ public class UploadsStorageManager extends Observable { return result; } + + public int removeAccountUploads(Account account) { + Log_OC.v(TAG, "Delete all uploads for account " + account.name); + return getDB().delete( + ProviderTableMeta.CONTENT_URI_UPLOADS, + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?", + new String[]{account.name}); + } } diff --git a/src/main/java/com/owncloud/android/jobs/AccountRemovalJob.java b/src/main/java/com/owncloud/android/jobs/AccountRemovalJob.java index 97024961f5..b6ce79255a 100644 --- a/src/main/java/com/owncloud/android/jobs/AccountRemovalJob.java +++ b/src/main/java/com/owncloud/android/jobs/AccountRemovalJob.java @@ -34,12 +34,19 @@ import com.owncloud.android.MainApp; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.ArbitraryDataProvider; import com.owncloud.android.datamodel.FileDataStorageManager; +import com.owncloud.android.datamodel.FilesystemDataProvider; +import com.owncloud.android.datamodel.SyncedFolder; +import com.owncloud.android.datamodel.SyncedFolderProvider; +import com.owncloud.android.datamodel.UploadsStorageManager; import com.owncloud.android.ui.events.AccountRemovedEvent; import com.owncloud.android.utils.FileStorageUtils; +import com.owncloud.android.utils.FilesSyncHelper; import org.greenrobot.eventbus.EventBus; import java.io.File; +import java.util.ArrayList; +import java.util.List; import static android.content.Context.ACCOUNT_SERVICE; import static com.owncloud.android.ui.activity.ManageAccountsActivity.PENDING_FOR_REMOVAL; @@ -78,6 +85,32 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback syncedFolders = syncedFolderProvider.getSyncedFolders(); + + List syncedFolderIds = new ArrayList<>(); + + for (SyncedFolder syncedFolder : syncedFolders) { + if (syncedFolder.getAccount().equals(account.name)) { + arbitraryDataProvider.deleteKeyForAccount(FilesSyncHelper.GLOBAL, + FilesSyncHelper.SYNCEDFOLDERINITIATED + syncedFolder.getId()); + syncedFolderIds.add(syncedFolder.getId()); + } + } + + syncedFolderProvider.deleteSyncFoldersForAccount(account); + + UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), + context); + uploadsStorageManager.removeAccountUploads(account); + + FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(context.getContentResolver()); + + for (long syncedFolderId : syncedFolderIds) { + filesystemDataProvider.deleteAllEntriesForSyncedFolder(Long.toString(syncedFolderId)); + } + return Result.SUCCESS; } else { return Result.FAILURE; diff --git a/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java b/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java index bb098bc8d0..f9fa8eb178 100644 --- a/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/UserInfoActivity.java @@ -62,7 +62,6 @@ 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.lib.common.UserInfo; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -408,10 +407,6 @@ public class UserInfoActivity extends FileActivity { ContactsPreferenceActivity.cancelContactBackupJobForAccount(getActivity(), account); ContentResolver contentResolver = getActivity().getContentResolver(); - // delete all synced folder for an account - SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider( - contentResolver); - syncedFolderProvider.deleteSyncFoldersForAccount(account); // disable daily backup ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider( @@ -421,7 +416,6 @@ public class UserInfoActivity extends FileActivity { ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP, "false"); - String arbitraryDataPushString; if (!TextUtils.isEmpty(arbitraryDataPushString = arbitraryDataProvider.getValue(