From 9171fb1d1ced338120cdd03a181edb2e16139979 Mon Sep 17 00:00:00 2001 From: Chris Narkiewicz Date: Wed, 2 Jun 2021 01:54:40 +0100 Subject: [PATCH] Remove Account from UploadsStorageManager Signed-off-by: Chris Narkiewicz --- .../datamodel/UploadStorageManagerTest.java | 26 ++++++++----------- .../client/jobs/AccountRemovalWork.kt | 2 +- .../datamodel/UploadsStorageManager.java | 15 +++++------ 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/androidTest/java/com/owncloud/android/datamodel/UploadStorageManagerTest.java b/src/androidTest/java/com/owncloud/android/datamodel/UploadStorageManagerTest.java index 17e9530e69..dc1d50099f 100644 --- a/src/androidTest/java/com/owncloud/android/datamodel/UploadStorageManagerTest.java +++ b/src/androidTest/java/com/owncloud/android/datamodel/UploadStorageManagerTest.java @@ -7,6 +7,7 @@ import android.content.ContentResolver; import android.content.Context; import com.nextcloud.client.account.CurrentAccountProvider; +import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.account.UserAccountManagerImpl; import com.owncloud.android.AbstractIT; @@ -47,17 +48,18 @@ import static org.junit.Assert.assertTrue; public class UploadStorageManagerTest extends AbstractIT { private UploadsStorageManager uploadsStorageManager; private CurrentAccountProvider currentAccountProvider = () -> null; - private Account account2; + private UserAccountManager userAccountManager; + private User user2; @Before public void setUp() { Context instrumentationCtx = ApplicationProvider.getApplicationContext(); ContentResolver contentResolver = instrumentationCtx.getContentResolver(); uploadsStorageManager = new UploadsStorageManager(currentAccountProvider, contentResolver); + userAccountManager = UserAccountManagerImpl.fromContext(targetContext); Account temp = new Account("test2@test.com", MainApp.getAccountType(targetContext)); - UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext); - if (!accountManager.exists(temp)) { + if (!userAccountManager.exists(temp)) { AccountManager platformAccountManager = AccountManager.get(targetContext); platformAccountManager.addAccountExplicitly(temp, "testPassword", null); platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION, @@ -68,27 +70,23 @@ public class UploadStorageManagerTest extends AbstractIT { } final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext); - account2 = userAccountManager.getAccountByName("test2@test.com"); - - if (account2 == null) { - throw new ActivityNotFoundException(); - } + user2 = userAccountManager.getUser("test2@test.com").orElseThrow(ActivityNotFoundException::new); } @Test public void testDeleteAllUploads() { // Clean - for (Account account : getAllAccounts()) { - uploadsStorageManager.removeAccountUploads(account); + for (User user : userAccountManager.getAllUsers()) { + uploadsStorageManager.removeUserUploads(user); } int accountRowsA = 3; int accountRowsB = 4; insertUploads(account, accountRowsA); - insertUploads(account2, accountRowsB); + insertUploads(user2.toPlatformAccount(), accountRowsB); assertEquals("Expected 4 removed uploads files", 4, - uploadsStorageManager.removeAccountUploads(account2)); + uploadsStorageManager.removeUserUploads(user2)); } @Test @@ -212,8 +210,6 @@ public class UploadStorageManagerTest extends AbstractIT { @After public void tearDown() { deleteAllUploads(); - - AccountManager platformAccountManager = AccountManager.get(targetContext); - platformAccountManager.removeAccountExplicitly(account2); + userAccountManager.removeUser(user2); } } diff --git a/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt b/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt index 4595a1e946..7488b324ca 100644 --- a/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt +++ b/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt @@ -110,7 +110,7 @@ class AccountRemovalWork( remoceSyncedFolders(context, user.toPlatformAccount(), clock) // delete all uploads for account - uploadsStorageManager.removeAccountUploads(user.toPlatformAccount()) + uploadsStorageManager.removeUserUploads(user) // delete stored E2E keys and mnemonic arbitraryDataProvider.deleteKeyForAccount(user.accountName, EncryptionUtils.PRIVATE_KEY) diff --git a/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java b/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java index 75ba020fa3..affcbd8ead 100644 --- a/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java +++ b/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java @@ -23,7 +23,6 @@ */ package com.owncloud.android.datamodel; -import android.accounts.Account; import android.content.ContentResolver; import android.content.ContentValues; import android.database.Cursor; @@ -59,8 +58,8 @@ public class UploadsStorageManager extends Observable { private static final String AND = " AND "; private static final int SINGLE_RESULT = 1; - private ContentResolver mContentResolver; - private CurrentAccountProvider currentAccountProvider; + private final ContentResolver contentResolver; + private final CurrentAccountProvider currentAccountProvider; public UploadsStorageManager( CurrentAccountProvider currentAccountProvider, @@ -69,7 +68,7 @@ public class UploadsStorageManager extends Observable { if (contentResolver == null) { throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver"); } - mContentResolver = contentResolver; + this.contentResolver = contentResolver; this.currentAccountProvider = currentAccountProvider; } @@ -511,7 +510,7 @@ public class UploadsStorageManager extends Observable { } private ContentResolver getDB() { - return mContentResolver; + return contentResolver; } public long clearFailedButNotDelayedUploads() { @@ -647,12 +646,12 @@ public class UploadsStorageManager extends Observable { new String[]{}); } - public int removeAccountUploads(Account account) { - Log_OC.v(TAG, "Delete all uploads for account " + account.name); + public int removeUserUploads(User user) { + Log_OC.v(TAG, "Delete all uploads for account " + user.getAccountName()); return getDB().delete( ProviderTableMeta.CONTENT_URI_UPLOADS, ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?", - new String[]{account.name}); + new String[]{user.getAccountName()}); } public enum UploadStatus {