mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 14:15:44 +03:00
Remove Account from UploadsStorageManager
Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
parent
2dd46ea967
commit
9171fb1d1c
3 changed files with 19 additions and 24 deletions
|
@ -7,6 +7,7 @@ import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||||
|
import com.nextcloud.client.account.User;
|
||||||
import com.nextcloud.client.account.UserAccountManager;
|
import com.nextcloud.client.account.UserAccountManager;
|
||||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||||
import com.owncloud.android.AbstractIT;
|
import com.owncloud.android.AbstractIT;
|
||||||
|
@ -47,17 +48,18 @@ import static org.junit.Assert.assertTrue;
|
||||||
public class UploadStorageManagerTest extends AbstractIT {
|
public class UploadStorageManagerTest extends AbstractIT {
|
||||||
private UploadsStorageManager uploadsStorageManager;
|
private UploadsStorageManager uploadsStorageManager;
|
||||||
private CurrentAccountProvider currentAccountProvider = () -> null;
|
private CurrentAccountProvider currentAccountProvider = () -> null;
|
||||||
private Account account2;
|
private UserAccountManager userAccountManager;
|
||||||
|
private User user2;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Context instrumentationCtx = ApplicationProvider.getApplicationContext();
|
Context instrumentationCtx = ApplicationProvider.getApplicationContext();
|
||||||
ContentResolver contentResolver = instrumentationCtx.getContentResolver();
|
ContentResolver contentResolver = instrumentationCtx.getContentResolver();
|
||||||
uploadsStorageManager = new UploadsStorageManager(currentAccountProvider, contentResolver);
|
uploadsStorageManager = new UploadsStorageManager(currentAccountProvider, contentResolver);
|
||||||
|
userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
|
||||||
|
|
||||||
Account temp = new Account("test2@test.com", MainApp.getAccountType(targetContext));
|
Account temp = new Account("test2@test.com", MainApp.getAccountType(targetContext));
|
||||||
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
|
if (!userAccountManager.exists(temp)) {
|
||||||
if (!accountManager.exists(temp)) {
|
|
||||||
AccountManager platformAccountManager = AccountManager.get(targetContext);
|
AccountManager platformAccountManager = AccountManager.get(targetContext);
|
||||||
platformAccountManager.addAccountExplicitly(temp, "testPassword", null);
|
platformAccountManager.addAccountExplicitly(temp, "testPassword", null);
|
||||||
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION,
|
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION,
|
||||||
|
@ -68,27 +70,23 @@ public class UploadStorageManagerTest extends AbstractIT {
|
||||||
}
|
}
|
||||||
|
|
||||||
final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
|
final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
|
||||||
account2 = userAccountManager.getAccountByName("test2@test.com");
|
user2 = userAccountManager.getUser("test2@test.com").orElseThrow(ActivityNotFoundException::new);
|
||||||
|
|
||||||
if (account2 == null) {
|
|
||||||
throw new ActivityNotFoundException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteAllUploads() {
|
public void testDeleteAllUploads() {
|
||||||
// Clean
|
// Clean
|
||||||
for (Account account : getAllAccounts()) {
|
for (User user : userAccountManager.getAllUsers()) {
|
||||||
uploadsStorageManager.removeAccountUploads(account);
|
uploadsStorageManager.removeUserUploads(user);
|
||||||
}
|
}
|
||||||
int accountRowsA = 3;
|
int accountRowsA = 3;
|
||||||
int accountRowsB = 4;
|
int accountRowsB = 4;
|
||||||
insertUploads(account, accountRowsA);
|
insertUploads(account, accountRowsA);
|
||||||
insertUploads(account2, accountRowsB);
|
insertUploads(user2.toPlatformAccount(), accountRowsB);
|
||||||
|
|
||||||
assertEquals("Expected 4 removed uploads files",
|
assertEquals("Expected 4 removed uploads files",
|
||||||
4,
|
4,
|
||||||
uploadsStorageManager.removeAccountUploads(account2));
|
uploadsStorageManager.removeUserUploads(user2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -212,8 +210,6 @@ public class UploadStorageManagerTest extends AbstractIT {
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
deleteAllUploads();
|
deleteAllUploads();
|
||||||
|
userAccountManager.removeUser(user2);
|
||||||
AccountManager platformAccountManager = AccountManager.get(targetContext);
|
|
||||||
platformAccountManager.removeAccountExplicitly(account2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ class AccountRemovalWork(
|
||||||
remoceSyncedFolders(context, user.toPlatformAccount(), clock)
|
remoceSyncedFolders(context, user.toPlatformAccount(), clock)
|
||||||
|
|
||||||
// delete all uploads for account
|
// delete all uploads for account
|
||||||
uploadsStorageManager.removeAccountUploads(user.toPlatformAccount())
|
uploadsStorageManager.removeUserUploads(user)
|
||||||
|
|
||||||
// delete stored E2E keys and mnemonic
|
// delete stored E2E keys and mnemonic
|
||||||
arbitraryDataProvider.deleteKeyForAccount(user.accountName, EncryptionUtils.PRIVATE_KEY)
|
arbitraryDataProvider.deleteKeyForAccount(user.accountName, EncryptionUtils.PRIVATE_KEY)
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package com.owncloud.android.datamodel;
|
package com.owncloud.android.datamodel;
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
@ -59,8 +58,8 @@ public class UploadsStorageManager extends Observable {
|
||||||
private static final String AND = " AND ";
|
private static final String AND = " AND ";
|
||||||
private static final int SINGLE_RESULT = 1;
|
private static final int SINGLE_RESULT = 1;
|
||||||
|
|
||||||
private ContentResolver mContentResolver;
|
private final ContentResolver contentResolver;
|
||||||
private CurrentAccountProvider currentAccountProvider;
|
private final CurrentAccountProvider currentAccountProvider;
|
||||||
|
|
||||||
public UploadsStorageManager(
|
public UploadsStorageManager(
|
||||||
CurrentAccountProvider currentAccountProvider,
|
CurrentAccountProvider currentAccountProvider,
|
||||||
|
@ -69,7 +68,7 @@ public class UploadsStorageManager extends Observable {
|
||||||
if (contentResolver == null) {
|
if (contentResolver == null) {
|
||||||
throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver");
|
throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver");
|
||||||
}
|
}
|
||||||
mContentResolver = contentResolver;
|
this.contentResolver = contentResolver;
|
||||||
this.currentAccountProvider = currentAccountProvider;
|
this.currentAccountProvider = currentAccountProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,7 +510,7 @@ public class UploadsStorageManager extends Observable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContentResolver getDB() {
|
private ContentResolver getDB() {
|
||||||
return mContentResolver;
|
return contentResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long clearFailedButNotDelayedUploads() {
|
public long clearFailedButNotDelayedUploads() {
|
||||||
|
@ -647,12 +646,12 @@ public class UploadsStorageManager extends Observable {
|
||||||
new String[]{});
|
new String[]{});
|
||||||
}
|
}
|
||||||
|
|
||||||
public int removeAccountUploads(Account account) {
|
public int removeUserUploads(User user) {
|
||||||
Log_OC.v(TAG, "Delete all uploads for account " + account.name);
|
Log_OC.v(TAG, "Delete all uploads for account " + user.getAccountName());
|
||||||
return getDB().delete(
|
return getDB().delete(
|
||||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
|
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
|
||||||
new String[]{account.name});
|
new String[]{user.getAccountName()});
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum UploadStatus {
|
public enum UploadStatus {
|
||||||
|
|
Loading…
Reference in a new issue