mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
Deprecate FileDataStorageManager constructors depending on legacy Account
This commit deprecates constructors using legacy platform Account type and wraps them using new API accepting User model. All calls to FileDataStorageManager constructors that were trivially portable without are updated as well. Places where passing new type requires more risku work were left out for now. FileDataStorageManager still uses Account internally - modifying this requires getting rid of all legacy constructors first. Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
parent
302c927bec
commit
ee4808213b
24 changed files with 39 additions and 31 deletions
|
@ -88,7 +88,7 @@ public abstract class AbstractIT {
|
||||||
protected Activity currentActivity;
|
protected Activity currentActivity;
|
||||||
|
|
||||||
protected FileDataStorageManager fileDataStorageManager =
|
protected FileDataStorageManager fileDataStorageManager =
|
||||||
new FileDataStorageManager(account, targetContext.getContentResolver());
|
new FileDataStorageManager(user, targetContext.getContentResolver());
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeAll() {
|
public static void beforeAll() {
|
||||||
|
|
|
@ -25,7 +25,7 @@ package com.owncloud.android.datamodel;
|
||||||
public class FileDataStorageManagerContentResolverIT extends FileDataStorageManagerIT {
|
public class FileDataStorageManagerContentResolverIT extends FileDataStorageManagerIT {
|
||||||
@Override
|
@Override
|
||||||
public void before() {
|
public void before() {
|
||||||
sut = new FileDataStorageManager(account, targetContext.getContentResolver());
|
sut = new FileDataStorageManager(user, targetContext.getContentResolver());
|
||||||
|
|
||||||
super.before();
|
super.before();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.junit.Test
|
||||||
class OCCapabilityIT : AbstractIT() {
|
class OCCapabilityIT : AbstractIT() {
|
||||||
@Test
|
@Test
|
||||||
fun saveCapability() {
|
fun saveCapability() {
|
||||||
val fileDataStorageManager = FileDataStorageManager(account, targetContext.contentResolver)
|
val fileDataStorageManager = FileDataStorageManager(user, targetContext.contentResolver)
|
||||||
|
|
||||||
val capability = OCCapability()
|
val capability = OCCapability()
|
||||||
capability.etag = "123"
|
capability.etag = "123"
|
||||||
|
@ -40,7 +40,7 @@ class OCCapabilityIT : AbstractIT() {
|
||||||
|
|
||||||
fileDataStorageManager.saveCapabilities(capability)
|
fileDataStorageManager.saveCapabilities(capability)
|
||||||
|
|
||||||
val newCapability = fileDataStorageManager.getCapability(account.name)
|
val newCapability = fileDataStorageManager.getCapability(user.accountName)
|
||||||
|
|
||||||
assertEquals(capability.etag, newCapability.etag)
|
assertEquals(capability.etag, newCapability.etag)
|
||||||
assertEquals(capability.userStatus, newCapability.userStatus)
|
assertEquals(capability.userStatus, newCapability.userStatus)
|
||||||
|
|
|
@ -25,6 +25,8 @@ import android.accounts.Account;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import com.nextcloud.client.account.MockUser;
|
||||||
|
import com.nextcloud.client.account.User;
|
||||||
import com.owncloud.android.MainApp;
|
import com.owncloud.android.MainApp;
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
|
@ -49,17 +51,17 @@ public class ErrorMessageAdapterIT {
|
||||||
@Test
|
@Test
|
||||||
public void getErrorCauseMessageForForbiddenRemoval() {
|
public void getErrorCauseMessageForForbiddenRemoval() {
|
||||||
Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
|
Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
|
||||||
Account account = new Account("name", ACCOUNT_TYPE);
|
User user = new MockUser("name", ACCOUNT_TYPE);
|
||||||
Context context = MainApp.getAppContext();
|
Context context = MainApp.getAppContext();
|
||||||
|
|
||||||
String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
|
String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
|
||||||
new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
|
new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
|
||||||
new RemoveFileOperation(new OCFile(PATH_TO_DELETE),
|
new RemoveFileOperation(new OCFile(PATH_TO_DELETE),
|
||||||
false,
|
false,
|
||||||
account,
|
user.toPlatformAccount(),
|
||||||
false,
|
false,
|
||||||
context,
|
context,
|
||||||
new FileDataStorageManager(account, context.getContentResolver())),
|
new FileDataStorageManager(user, context.getContentResolver())),
|
||||||
resources
|
resources
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ class TestActivity :
|
||||||
|
|
||||||
override fun getStorageManager(): FileDataStorageManager {
|
override fun getStorageManager(): FileDataStorageManager {
|
||||||
if (!this::storage.isInitialized) {
|
if (!this::storage.isInitialized) {
|
||||||
storage = FileDataStorageManager(account, contentResolver)
|
storage = FileDataStorageManager(user.get(), contentResolver)
|
||||||
|
|
||||||
if (!storage.capabilityExistsForAccount(account.name)) {
|
if (!storage.capabilityExistsForAccount(account.name)) {
|
||||||
val ocCapability = OCCapability()
|
val ocCapability = OCCapability()
|
||||||
|
|
|
@ -68,7 +68,7 @@ class DownloadTask(
|
||||||
val result = op.execute(client)
|
val result = op.execute(client)
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
val storageManager = FileDataStorageManager(
|
val storageManager = FileDataStorageManager(
|
||||||
request.user.toPlatformAccount(),
|
request.user,
|
||||||
contentResolver
|
contentResolver
|
||||||
)
|
)
|
||||||
val file = saveDownloadedFile(op, storageManager)
|
val file = saveDownloadedFile(op, storageManager)
|
||||||
|
|
|
@ -94,7 +94,7 @@ class AccountRemovalWork(
|
||||||
val user = optionalUser.get()
|
val user = optionalUser.get()
|
||||||
backgroundJobManager.cancelPeriodicContactsBackup(user)
|
backgroundJobManager.cancelPeriodicContactsBackup(user)
|
||||||
val userRemoved = userAccountManager.removeUser(user)
|
val userRemoved = userAccountManager.removeUser(user)
|
||||||
val storageManager = FileDataStorageManager(user.toPlatformAccount(), context.contentResolver)
|
val storageManager = FileDataStorageManager(user, context.contentResolver)
|
||||||
|
|
||||||
// disable daily backup
|
// disable daily backup
|
||||||
arbitraryDataProvider.storeOrUpdateKeyValue(
|
arbitraryDataProvider.storeOrUpdateKeyValue(
|
||||||
|
|
|
@ -179,7 +179,7 @@ class ContactsBackupWork(
|
||||||
private fun expireFiles(daysToExpire: Int, backupFolderString: String, user: User) { // -1 disables expiration
|
private fun expireFiles(daysToExpire: Int, backupFolderString: String, user: User) { // -1 disables expiration
|
||||||
if (daysToExpire > -1) {
|
if (daysToExpire > -1) {
|
||||||
val storageManager = FileDataStorageManager(
|
val storageManager = FileDataStorageManager(
|
||||||
user.toPlatformAccount(),
|
user,
|
||||||
applicationContext.getContentResolver()
|
applicationContext.getContentResolver()
|
||||||
)
|
)
|
||||||
val backupFolder: OCFile = storageManager.getFileByPath(backupFolderString)
|
val backupFolder: OCFile = storageManager.getFileByPath(backupFolderString)
|
||||||
|
|
|
@ -60,7 +60,7 @@ class OfflineSyncWork constructor(
|
||||||
if (!powerManagementService.isPowerSavingEnabled && !connectivityService.isInternetWalled) {
|
if (!powerManagementService.isPowerSavingEnabled && !connectivityService.isInternetWalled) {
|
||||||
val users = userAccountManager.allUsers
|
val users = userAccountManager.allUsers
|
||||||
for (user in users) {
|
for (user in users) {
|
||||||
val storageManager = FileDataStorageManager(user.toPlatformAccount(), contentResolver)
|
val storageManager = FileDataStorageManager(user, contentResolver)
|
||||||
val ocRoot = storageManager.getFileByPath(OCFile.ROOT_PATH)
|
val ocRoot = storageManager.getFileByPath(OCFile.ROOT_PATH)
|
||||||
if (ocRoot.storagePath == null) {
|
if (ocRoot.storagePath == null) {
|
||||||
break
|
break
|
||||||
|
|
|
@ -599,7 +599,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(), context.getContentResolver());
|
FileDataStorageManager storageManager = new FileDataStorageManager(user, context.getContentResolver());
|
||||||
|
|
||||||
String value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder));
|
String value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder));
|
||||||
OCFile prefFolder = folder;
|
OCFile prefFolder = folder;
|
||||||
|
|
|
@ -148,7 +148,7 @@ class ChooseAccountDialogFragment :
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
val capability = FileDataStorageManager(user.toPlatformAccount(), context?.contentResolver)
|
val capability = FileDataStorageManager(user, context?.contentResolver)
|
||||||
.getCapability(user)
|
.getCapability(user)
|
||||||
|
|
||||||
if (capability.userStatus.isTrue) {
|
if (capability.userStatus.isTrue) {
|
||||||
|
|
|
@ -87,18 +87,27 @@ public class FileDataStorageManager {
|
||||||
private ContentProviderClient contentProviderClient;
|
private ContentProviderClient contentProviderClient;
|
||||||
private Account account;
|
private Account account;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public FileDataStorageManager(Account account, ContentResolver contentResolver) {
|
public FileDataStorageManager(Account account, ContentResolver contentResolver) {
|
||||||
this.contentProviderClient = null;
|
this.contentProviderClient = null;
|
||||||
this.contentResolver = contentResolver;
|
this.contentResolver = contentResolver;
|
||||||
this.account = account;
|
this.account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileDataStorageManager(User user, ContentResolver contentResolver) {
|
||||||
|
this(user.toPlatformAccount(), contentResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public FileDataStorageManager(Account account, ContentProviderClient contentProviderClient) {
|
public FileDataStorageManager(Account account, ContentProviderClient contentProviderClient) {
|
||||||
this.contentProviderClient = contentProviderClient;
|
this.contentProviderClient = contentProviderClient;
|
||||||
this.contentResolver = null;
|
this.contentResolver = null;
|
||||||
this.account = account;
|
this.account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileDataStorageManager(User user, ContentProviderClient contentProviderClient) {
|
||||||
|
this(user.toPlatformAccount(), contentProviderClient);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use getFileByEncryptedRemotePath() or getFileByDecryptedRemotePath()
|
* Use getFileByEncryptedRemotePath() or getFileByDecryptedRemotePath()
|
||||||
|
@ -2403,8 +2412,4 @@ public class FileDataStorageManager {
|
||||||
public Account getAccount() {
|
public Account getAccount() {
|
||||||
return this.account;
|
return this.account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccount(Account account) {
|
|
||||||
this.account = account;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class DiskLruImageCacheFileProvider extends ContentProvider {
|
||||||
|
|
||||||
private OCFile getFile(Uri uri) {
|
private OCFile getFile(Uri uri) {
|
||||||
User user = accountManager.getUser();
|
User user = accountManager.getUser();
|
||||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user,
|
||||||
MainApp.getAppContext().getContentResolver());
|
MainApp.getAppContext().getContentResolver());
|
||||||
|
|
||||||
return fileDataStorageManager.getFileByPath(uri.getPath());
|
return fileDataStorageManager.getFileByPath(uri.getPath());
|
||||||
|
|
|
@ -234,7 +234,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
||||||
Uri emailBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_EMAIL).build();
|
Uri emailBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_EMAIL).build();
|
||||||
Uri circleBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_CIRCLE).build();
|
Uri circleBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_CIRCLE).build();
|
||||||
|
|
||||||
FileDataStorageManager manager = new FileDataStorageManager(user.toPlatformAccount(),
|
FileDataStorageManager manager = new FileDataStorageManager(user,
|
||||||
getContext().getContentResolver());
|
getContext().getContentResolver());
|
||||||
boolean federatedShareAllowed = manager.getCapability(user.getAccountName())
|
boolean federatedShareAllowed = manager.getCapability(user.getAccountName())
|
||||||
.getFilesSharingFederationOutgoing()
|
.getFilesSharingFederationOutgoing()
|
||||||
|
|
|
@ -507,7 +507,7 @@ public class OperationsService extends Service {
|
||||||
String newParentPath;
|
String newParentPath;
|
||||||
long shareId;
|
long shareId;
|
||||||
|
|
||||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account,
|
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user,
|
||||||
getContentResolver());
|
getContentResolver());
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
|
|
@ -390,7 +390,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterDrawerMenu(final Menu menu, @NonNull final User user) {
|
private void filterDrawerMenu(final Menu menu, @NonNull final User user) {
|
||||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
FileDataStorageManager storageManager = new FileDataStorageManager(user,
|
||||||
getContentResolver());
|
getContentResolver());
|
||||||
OCCapability capability = storageManager.getCapability(user.getAccountName());
|
OCCapability capability = storageManager.getCapability(user.getAccountName());
|
||||||
|
|
||||||
|
|
|
@ -2503,7 +2503,7 @@ public class FileDisplayActivity extends FileActivity
|
||||||
FileDataStorageManager storageManager = getStorageManager();
|
FileDataStorageManager storageManager = getStorageManager();
|
||||||
|
|
||||||
if (storageManager == null) {
|
if (storageManager == null) {
|
||||||
storageManager = new FileDataStorageManager(user.toPlatformAccount(), getContentResolver());
|
storageManager = new FileDataStorageManager(user, getContentResolver());
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchRemoteFileTask fetchRemoteFileTask = new FetchRemoteFileTask(user,
|
FetchRemoteFileTask fetchRemoteFileTask = new FetchRemoteFileTask(user,
|
||||||
|
|
|
@ -436,7 +436,8 @@ public class StorageMigration {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateIndex(Context context) throws MigrationException {
|
private void updateIndex(Context context) throws MigrationException {
|
||||||
FileDataStorageManager manager = new FileDataStorageManager(null, context.getContentResolver());
|
final Account nullAccount = null;
|
||||||
|
FileDataStorageManager manager = new FileDataStorageManager(nullAccount, context.getContentResolver());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
manager.migrateStoredFiles(mStorageSource, mStorageTarget);
|
manager.migrateStoredFiles(mStorageSource, mStorageTarget);
|
||||||
|
|
|
@ -857,7 +857,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mStorageManager == null) {
|
if (mStorageManager == null) {
|
||||||
mStorageManager = new FileDataStorageManager(user.toPlatformAccount(), activity.getContentResolver());
|
mStorageManager = new FileDataStorageManager(user, activity.getContentResolver());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clear) {
|
if (clear) {
|
||||||
|
|
|
@ -287,7 +287,7 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im
|
||||||
|
|
||||||
if (chooseTemplateDialogFragmentWeakReference.get() != null) {
|
if (chooseTemplateDialogFragmentWeakReference.get() != null) {
|
||||||
FileDataStorageManager storageManager = new FileDataStorageManager(
|
FileDataStorageManager storageManager = new FileDataStorageManager(
|
||||||
user.toPlatformAccount(),
|
user,
|
||||||
chooseTemplateDialogFragmentWeakReference.get().requireContext().getContentResolver());
|
chooseTemplateDialogFragmentWeakReference.get().requireContext().getContentResolver());
|
||||||
storageManager.saveFile(temp);
|
storageManager.saveFile(temp);
|
||||||
file = storageManager.getFileByPath(path);
|
file = storageManager.getFileByPath(path);
|
||||||
|
|
|
@ -332,7 +332,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
FileDataStorageManager storageManager = new FileDataStorageManager(user,
|
||||||
context.getContentResolver());
|
context.getContentResolver());
|
||||||
|
|
||||||
OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0));
|
OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0));
|
||||||
|
|
|
@ -200,7 +200,7 @@ public class ConflictsResolveDialog extends DialogFragment {
|
||||||
OCFileListAdapter.setThumbnail(existingFile,
|
OCFileListAdapter.setThumbnail(existingFile,
|
||||||
binding.existingThumbnail,
|
binding.existingThumbnail,
|
||||||
user,
|
user,
|
||||||
new FileDataStorageManager(user.toPlatformAccount(),
|
new FileDataStorageManager(user,
|
||||||
requireContext().getContentResolver()),
|
requireContext().getContentResolver()),
|
||||||
asyncTasks,
|
asyncTasks,
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupView() {
|
private void setupView() {
|
||||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
FileDataStorageManager storageManager = new FileDataStorageManager(user,
|
||||||
contentResolver);
|
contentResolver);
|
||||||
operationsHelper = ((ComponentsGetter) requireActivity()).getFileOperationsHelper();
|
operationsHelper = ((ComponentsGetter) requireActivity()).getFileOperationsHelper();
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ public class FileOperationsHelper {
|
||||||
public void startSyncForFileAndIntent(OCFile file, Intent intent) {
|
public void startSyncForFileAndIntent(OCFile file, Intent intent) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
User user = fileActivity.getUser().orElseThrow(RuntimeException::new);
|
User user = fileActivity.getUser().orElseThrow(RuntimeException::new);
|
||||||
FileDataStorageManager storageManager = new FileDataStorageManager(fileActivity.getAccount(),
|
FileDataStorageManager storageManager = new FileDataStorageManager(user,
|
||||||
fileActivity.getContentResolver());
|
fileActivity.getContentResolver());
|
||||||
|
|
||||||
// check if file is in conflict (this is known due to latest folder refresh)
|
// check if file is in conflict (this is known due to latest folder refresh)
|
||||||
|
@ -314,7 +314,7 @@ public class FileOperationsHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
User user = currentAccount.getUser();
|
User user = currentAccount.getUser();
|
||||||
FileDataStorageManager storageManager =
|
FileDataStorageManager storageManager =
|
||||||
new FileDataStorageManager(user.toPlatformAccount(), fileActivity.getContentResolver());
|
new FileDataStorageManager(user, fileActivity.getContentResolver());
|
||||||
// a fresh object is needed; many things could have occurred to the file
|
// a fresh object is needed; many things could have occurred to the file
|
||||||
// since it was registered to observe again, assuming that local files
|
// since it was registered to observe again, assuming that local files
|
||||||
// are linked to a remote file AT MOST, SOMETHING TO BE DONE;
|
// are linked to a remote file AT MOST, SOMETHING TO BE DONE;
|
||||||
|
|
Loading…
Reference in a new issue