Remove Account from UploadsStorageManager

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2021-06-02 01:54:40 +01:00
parent 2dd46ea967
commit 9171fb1d1c
No known key found for this signature in database
GPG key ID: 30D28CA4CCC665C6
3 changed files with 19 additions and 24 deletions

View file

@ -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);
}
}

View file

@ -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)

View file

@ -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 {