Merge pull request #9073 from nextcloud/remove-deprecated-calls-to-storage-manager-constructor

Remove deprecated calls to storage manager constructor
This commit is contained in:
Álvaro Brey 2021-11-18 14:36:03 +01:00 committed by GitHub
commit 373fec8b45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 178 additions and 167 deletions

View file

@ -366,7 +366,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
"[" + i + "/" + actionCount + "] " + "Download file: " + "[" + i + "/" + actionCount + "] " + "Download file: " +
currentFolder.getDecryptedRemotePath() + fileToDownload.getDecryptedFileName()); currentFolder.getDecryptedRemotePath() + fileToDownload.getDecryptedFileName());
assertTrue(new DownloadFileOperation(account, fileToDownload, targetContext) assertTrue(new DownloadFileOperation(user, fileToDownload, targetContext)
.execute(client) .execute(client)
.isSuccess()); .isSuccess());

View file

@ -79,7 +79,7 @@ class ContactsBackupIT : AbstractOnServerIT() {
false false
)[0] )[0]
assertTrue(DownloadFileOperation(account, backupOCFile, AbstractIT.targetContext).execute(client).isSuccess) assertTrue(DownloadFileOperation(user, backupOCFile, AbstractIT.targetContext).execute(client).isSuccess)
val backupFile = File(backupOCFile.storagePath) val backupFile = File(backupOCFile.storagePath)

View file

@ -134,7 +134,7 @@ public abstract class AbstractIT {
// color // color
String colorParameter = arguments.getString("COLOR"); String colorParameter = arguments.getString("COLOR");
if (!TextUtils.isEmpty(colorParameter)) { if (!TextUtils.isEmpty(colorParameter)) {
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account, FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user,
targetContext.getContentResolver()); targetContext.getContentResolver());
String colorHex = null; String colorHex = null;

View file

@ -92,8 +92,8 @@ public class DownloadIT extends AbstractOnServerIT {
OCFile file2 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty2.txt"); OCFile file2 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty2.txt");
verifyDownload(file1, file2); verifyDownload(file1, file2);
assertTrue(new DownloadFileOperation(account, file1, targetContext).execute(client).isSuccess()); assertTrue(new DownloadFileOperation(user, file1, targetContext).execute(client).isSuccess());
assertTrue(new DownloadFileOperation(account, file2, targetContext).execute(client).isSuccess()); assertTrue(new DownloadFileOperation(user, file2, targetContext).execute(client).isSuccess());
refreshFolder(FOLDER); refreshFolder(FOLDER);

View file

@ -28,7 +28,7 @@ public class FileDataStorageManagerContentProviderClientIT extends FileDataStora
@Override @Override
public void before() { public void before() {
sut = new FileDataStorageManager(account, sut = new FileDataStorageManager(user,
targetContext targetContext
.getContentResolver() .getContentResolver()
.acquireContentProviderClient(ProviderMeta.ProviderTableMeta.CONTENT_URI) .acquireContentProviderClient(ProviderMeta.ProviderTableMeta.CONTENT_URI)

View file

@ -217,7 +217,7 @@ abstract public class FileDataStorageManagerIT extends AbstractOnServerIT {
*/ */
@Test @Test
public void testGallerySearch() throws IOException { public void testGallerySearch() throws IOException {
sut = new FileDataStorageManager(account, sut = new FileDataStorageManager(user,
targetContext targetContext
.getContentResolver() .getContentResolver()
.acquireContentProviderClient(ProviderMeta.ProviderTableMeta.CONTENT_URI) .acquireContentProviderClient(ProviderMeta.ProviderTableMeta.CONTENT_URI)

View file

@ -38,7 +38,7 @@ class DocumentsStorageProviderIT : AbstractOnServerIT() {
private val authority = context.getString(R.string.document_provider_authority) private val authority = context.getString(R.string.document_provider_authority)
private val rootFileId = storageManager.getFileByEncryptedRemotePath(ROOT_PATH).fileId private val rootFileId = storageManager.getFileByEncryptedRemotePath(ROOT_PATH).fileId
private val documentId = "${account.hashCode()}${DOCUMENTID_SEPARATOR}$rootFileId" private val documentId = "${user.hashCode()}${DOCUMENTID_SEPARATOR}$rootFileId"
private val uri = DocumentsContract.buildTreeDocumentUri(authority, documentId) private val uri = DocumentsContract.buildTreeDocumentUri(authority, documentId)
private val rootDir get() = DocumentFile.fromTreeUri(context, uri)!! private val rootDir get() = DocumentFile.fromTreeUri(context, uri)!!

View file

@ -62,13 +62,13 @@ public class ConflictsResolveActivityIT extends AbstractIT {
OCFile newFile = new OCFile("/newFile.txt"); OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000); newFile.setFileLength(56000);
newFile.setModificationTimestamp(1522019340); newFile.setModificationTimestamp(1522019340);
newFile.setStoragePath(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt"); newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
OCFile existingFile = new OCFile("/newFile.txt"); OCFile existingFile = new OCFile("/newFile.txt");
existingFile.setFileLength(1024000); existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340); existingFile.setModificationTimestamp(1582019340);
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver()); FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
storageManager.saveNewFile(existingFile); storageManager.saveNewFile(existingFile);
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class); Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
@ -98,13 +98,13 @@ public class ConflictsResolveActivityIT extends AbstractIT {
// @Test // @Test
// @ScreenshotTest // todo run without real server // @ScreenshotTest // todo run without real server
// public void screenshotImages() throws IOException { // public void screenshotImages() throws IOException {
// FileDataStorageManager storageManager = new FileDataStorageManager(account, // FileDataStorageManager storageManager = new FileDataStorageManager(user,
// targetContext.getContentResolver()); // targetContext.getContentResolver());
// //
// OCFile newFile = new OCFile("/newFile.txt"); // OCFile newFile = new OCFile("/newFile.txt");
// newFile.setFileLength(56000); // newFile.setFileLength(56000);
// newFile.setModificationTimestamp(1522019340); // newFile.setModificationTimestamp(1522019340);
// newFile.setStoragePath(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt"); // newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
// //
// File image = getFile("image.jpg"); // File image = getFile("image.jpg");
// //
@ -118,7 +118,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
// false, // false,
// true, // true,
// storageManager, // storageManager,
// account, // user.toPlatformAccount(),
// targetContext // targetContext
// ).execute(client).isSuccess()); // ).execute(client).isSuccess());
// //
@ -153,9 +153,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
public void cancel() { public void cancel() {
returnCode = false; returnCode = false;
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt", OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt",
"/newFile.txt", "/newFile.txt",
account.name); user.getAccountName());
OCFile existingFile = new OCFile("/newFile.txt"); OCFile existingFile = new OCFile("/newFile.txt");
existingFile.setFileLength(1024000); existingFile.setFileLength(1024000);
@ -164,9 +164,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
OCFile newFile = new OCFile("/newFile.txt"); OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000); newFile.setFileLength(56000);
newFile.setModificationTimestamp(1522019340); newFile.setModificationTimestamp(1522019340);
newFile.setStoragePath(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt"); newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver()); FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
storageManager.saveNewFile(existingFile); storageManager.saveNewFile(existingFile);
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class); Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
@ -194,9 +194,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
public void keepExisting() { public void keepExisting() {
returnCode = false; returnCode = false;
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt", OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt",
"/newFile.txt", "/newFile.txt",
account.name); user.getAccountName());
OCFile existingFile = new OCFile("/newFile.txt"); OCFile existingFile = new OCFile("/newFile.txt");
existingFile.setFileLength(1024000); existingFile.setFileLength(1024000);
@ -205,9 +205,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
OCFile newFile = new OCFile("/newFile.txt"); OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000); newFile.setFileLength(56000);
newFile.setModificationTimestamp(1522019340); newFile.setModificationTimestamp(1522019340);
newFile.setStoragePath(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt"); newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver()); FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
storageManager.saveNewFile(existingFile); storageManager.saveNewFile(existingFile);
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class); Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
@ -239,9 +239,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
public void keepNew() { public void keepNew() {
returnCode = false; returnCode = false;
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt", OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt",
"/newFile.txt", "/newFile.txt",
account.name); user.getAccountName());
OCFile existingFile = new OCFile("/newFile.txt"); OCFile existingFile = new OCFile("/newFile.txt");
existingFile.setFileLength(1024000); existingFile.setFileLength(1024000);
@ -251,9 +251,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
OCFile newFile = new OCFile("/newFile.txt"); OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000); newFile.setFileLength(56000);
newFile.setModificationTimestamp(1522019340); newFile.setModificationTimestamp(1522019340);
newFile.setStoragePath(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt"); newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver()); FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
storageManager.saveNewFile(existingFile); storageManager.saveNewFile(existingFile);
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class); Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
@ -285,9 +285,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
public void keepBoth() { public void keepBoth() {
returnCode = false; returnCode = false;
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt", OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt",
"/newFile.txt", "/newFile.txt",
account.name); user.getAccountName());
OCFile existingFile = new OCFile("/newFile.txt"); OCFile existingFile = new OCFile("/newFile.txt");
existingFile.setFileLength(1024000); existingFile.setFileLength(1024000);
@ -296,9 +296,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
OCFile newFile = new OCFile("/newFile.txt"); OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000); newFile.setFileLength(56000);
newFile.setModificationTimestamp(1522019340); newFile.setModificationTimestamp(1522019340);
newFile.setStoragePath(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt"); newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver()); FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
storageManager.saveNewFile(existingFile); storageManager.saveNewFile(existingFile);
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class); Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);

View file

@ -35,6 +35,8 @@ import com.nextcloud.android.lib.resources.profile.Action;
import com.nextcloud.android.lib.resources.profile.HoverCard; import com.nextcloud.android.lib.resources.profile.HoverCard;
import com.nextcloud.client.account.RegisteredUser; import com.nextcloud.client.account.RegisteredUser;
import com.nextcloud.client.account.Server; import com.nextcloud.client.account.Server;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.device.DeviceInfo; import com.nextcloud.client.device.DeviceInfo;
import com.nextcloud.ui.ChooseAccountDialogFragment; import com.nextcloud.ui.ChooseAccountDialogFragment;
import com.owncloud.android.AbstractIT; import com.owncloud.android.AbstractIT;
@ -175,6 +177,7 @@ public class DialogFragmentIT extends AbstractIT {
@Test @Test
@ScreenshotTest @ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException { public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
UserAccountManager userAccountManager = activityRule.getActivity().getUserAccountManager();
AccountManager accountManager = AccountManager.get(targetContext); AccountManager accountManager = AccountManager.get(targetContext);
for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) { for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
accountManager.removeAccountExplicitly(account); accountManager.removeAccountExplicitly(account);
@ -185,7 +188,7 @@ public class DialogFragmentIT extends AbstractIT {
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL); accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test"); accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password"); accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
User newUser = userAccountManager.getUser(newAccount.name).orElseThrow(RuntimeException::new);
Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext)); Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount2, "password", null); accountManager.addAccountExplicitly(newAccount2, "password", null);
@ -194,8 +197,7 @@ public class DialogFragmentIT extends AbstractIT {
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0"); accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0");
accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password"); accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser,
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newAccount,
targetContext.getContentResolver()); targetContext.getContentResolver());
OCCapability capability = new OCCapability(); OCCapability capability = new OCCapability();
@ -257,7 +259,9 @@ public class DialogFragmentIT extends AbstractIT {
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test"); accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password"); accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newAccount, UserAccountManager userAccountManager = activityRule.getActivity().getUserAccountManager();
User newUser = userAccountManager.getUser(newAccount.name).get();
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser,
targetContext.getContentResolver()); targetContext.getContentResolver());
OCCapability capability = new OCCapability(); OCCapability capability = new OCCapability();

View file

@ -139,7 +139,7 @@ class AppModule {
@Provides @Provides
FileDataStorageManager fileDataStorageManager(CurrentAccountProvider currentAccountProvider, FileDataStorageManager fileDataStorageManager(CurrentAccountProvider currentAccountProvider,
Context context) { Context context) {
return new FileDataStorageManager(currentAccountProvider.getCurrentAccount(), context.getContentResolver()); return new FileDataStorageManager(currentAccountProvider.getUser(), context.getContentResolver());
} }
@Provides @Provides

View file

@ -63,7 +63,7 @@ class DownloadTask(
} }
fun download(request: DownloadRequest, progress: (Int) -> Unit, isCancelled: IsCancelled): Result { fun download(request: DownloadRequest, progress: (Int) -> Unit, isCancelled: IsCancelled): Result {
val op = DownloadFileOperation(request.user.toPlatformAccount(), request.file, context) val op = DownloadFileOperation(request.user, request.file, context)
val client = clientProvider.invoke() val client = clientProvider.invoke()
val result = op.execute(client) val result = op.execute(client)
if (result.isSuccess) { if (result.isSuccess) {

View file

@ -65,7 +65,7 @@ class SessionMixin constructor(
} }
currentAccount?.let { currentAccount?.let {
val storageManager = FileDataStorageManager(currentAccount, contentResolver) val storageManager = FileDataStorageManager(getUser().get(), contentResolver)
this.storageManager = storageManager this.storageManager = storageManager
this.capabilities = storageManager.getCapability(it.name) this.capabilities = storageManager.getCapability(it.name)
} }

View file

@ -85,28 +85,18 @@ public class FileDataStorageManager {
private ContentResolver contentResolver; private ContentResolver contentResolver;
private ContentProviderClient contentProviderClient; private ContentProviderClient contentProviderClient;
private Account account; private User user;
@Deprecated
public FileDataStorageManager(Account account, ContentResolver contentResolver) {
this.contentProviderClient = null;
this.contentResolver = contentResolver;
this.account = account;
}
public FileDataStorageManager(User user, ContentResolver contentResolver) { public FileDataStorageManager(User user, ContentResolver contentResolver) {
this(user.toPlatformAccount(), contentResolver); this.contentProviderClient = null;
} this.contentResolver = contentResolver;
this.user = user;
@Deprecated
public FileDataStorageManager(Account account, ContentProviderClient contentProviderClient) {
this.contentProviderClient = contentProviderClient;
this.contentResolver = null;
this.account = account;
} }
public FileDataStorageManager(User user, ContentProviderClient contentProviderClient) { public FileDataStorageManager(User user, ContentProviderClient contentProviderClient) {
this(user.toPlatformAccount(), contentProviderClient); this.contentProviderClient = contentProviderClient;
this.contentResolver = null;
this.user = user;
} }
/** /**
@ -236,7 +226,7 @@ public class FileDataStorageManager {
if (!ocFile.isFolder()) { if (!ocFile.isFolder()) {
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, ocFile.getStoragePath()); cv.put(ProviderTableMeta.FILE_STORAGE_PATH, ocFile.getStoragePath());
} }
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, account.name); cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, ocFile.getLastSyncDateForProperties()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, ocFile.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, ocFile.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, ocFile.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_ETAG, ocFile.getEtag()); cv.put(ProviderTableMeta.FILE_ETAG, ocFile.getEtag());
@ -403,7 +393,7 @@ public class FileDataStorageManager {
// prepare operations to remove files in the given folder // prepare operations to remove files in the given folder
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " = ?"; String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " = ?";
String[] whereArgs = new String[2]; String[] whereArgs = new String[2];
whereArgs[0] = account.name; whereArgs[0] = user.getAccountName();
for (OCFile ocFile : filesToRemove) { for (OCFile ocFile : filesToRemove) {
if (ocFile.getParentId() == folder.getFileId()) { if (ocFile.getParentId() == folder.getFileId()) {
whereArgs[1] = ocFile.getRemotePath(); whereArgs[1] = ocFile.getRemotePath();
@ -412,7 +402,7 @@ public class FileDataStorageManager {
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, ocFile.getFileId())) ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, ocFile.getFileId()))
.withSelection(where, whereArgs).build()); .withSelection(where, whereArgs).build());
File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(account.name, ocFile)); File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile));
if (localFolder.exists()) { if (localFolder.exists()) {
removeLocalFolder(localFolder); removeLocalFolder(localFolder);
} }
@ -490,7 +480,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId()); cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId());
cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath()); cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath());
cv.put(ProviderTableMeta.FILE_PATH_DECRYPTED, folder.getDecryptedRemotePath()); cv.put(ProviderTableMeta.FILE_PATH_DECRYPTED, folder.getDecryptedRemotePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, account.name); cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, folder.getLastSyncDateForProperties()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, folder.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag()); cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag());
@ -524,7 +514,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath()); cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
cv.put(ProviderTableMeta.FILE_PATH_DECRYPTED, file.getDecryptedRemotePath()); cv.put(ProviderTableMeta.FILE_PATH_DECRYPTED, file.getDecryptedRemotePath());
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, account.name); cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag()); cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
@ -563,7 +553,7 @@ public class FileDataStorageManager {
// ""+file.getFileId()); // ""+file.getFileId());
Uri file_uri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, ocFile.getFileId()); Uri file_uri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, ocFile.getFileId());
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?"; String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?";
String[] whereArgs = new String[]{account.name, ocFile.getRemotePath()}; String[] whereArgs = new String[]{user.getAccountName(), ocFile.getRemotePath()};
int deleted = 0; int deleted = 0;
if (getContentProviderClient() != null) { if (getContentProviderClient() != null) {
try { try {
@ -620,7 +610,7 @@ public class FileDataStorageManager {
Uri folderUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, String.valueOf(folder.getFileId())); Uri folderUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, String.valueOf(folder.getFileId()));
// for recursive deletion // for recursive deletion
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?"; String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?";
String[] whereArgs = new String[]{account.name, folder.getRemotePath()}; String[] whereArgs = new String[]{user.getAccountName(), folder.getRemotePath()};
int deleted = 0; int deleted = 0;
if (getContentProviderClient() != null) { if (getContentProviderClient() != null) {
try { try {
@ -636,7 +626,7 @@ public class FileDataStorageManager {
private boolean removeLocalFolder(OCFile folder) { private boolean removeLocalFolder(OCFile folder) {
boolean success = true; boolean success = true;
String localFolderPath = FileStorageUtils.getDefaultSavePathFor(account.name, folder); String localFolderPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), folder);
File localFolder = new File(localFolderPath); File localFolder = new File(localFolderPath);
if (localFolder.exists()) { if (localFolder.exists()) {
@ -705,7 +695,7 @@ public class FileDataStorageManager {
ProviderTableMeta.CONTENT_URI, ProviderTableMeta.CONTENT_URI,
null, null,
ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " LIKE ? ", ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " LIKE ? ",
new String[]{account.name, ocFile.getRemotePath() + "%"}, new String[]{user.getAccountName(), ocFile.getRemotePath() + "%"},
ProviderTableMeta.FILE_PATH + " ASC " ProviderTableMeta.FILE_PATH + " ASC "
); );
} catch (RemoteException e) { } catch (RemoteException e) {
@ -717,14 +707,14 @@ public class FileDataStorageManager {
ProviderTableMeta.CONTENT_URI, ProviderTableMeta.CONTENT_URI,
null, null,
ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " LIKE ? ", ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " LIKE ? ",
new String[]{account.name, ocFile.getRemotePath() + "%"}, new String[]{user.getAccountName(), ocFile.getRemotePath() + "%"},
ProviderTableMeta.FILE_PATH + " ASC " ProviderTableMeta.FILE_PATH + " ASC "
); );
} }
/// 2. prepare a batch of update operations to change all the descendants /// 2. prepare a batch of update operations to change all the descendants
ArrayList<ContentProviderOperation> operations = new ArrayList<>(cursor.getCount()); ArrayList<ContentProviderOperation> operations = new ArrayList<>(cursor.getCount());
String defaultSavePath = FileStorageUtils.getSavePath(account.name); String defaultSavePath = FileStorageUtils.getSavePath(user.getAccountName());
List<String> originalPathsToTriggerMediaScan = new ArrayList<>(); List<String> originalPathsToTriggerMediaScan = new ArrayList<>();
List<String> newPathsToTriggerMediaScan = new ArrayList<>(); List<String> newPathsToTriggerMediaScan = new ArrayList<>();
@ -780,7 +770,7 @@ public class FileDataStorageManager {
} }
/// 4. move in local file system /// 4. move in local file system
String originalLocalPath = FileStorageUtils.getDefaultSavePathFor(account.name, ocFile); String originalLocalPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile);
String targetLocalPath = defaultSavePath + targetPath; String targetLocalPath = defaultSavePath + targetPath;
File localFile = new File(originalLocalPath); File localFile = new File(originalLocalPath);
boolean renamed = false; boolean renamed = false;
@ -812,10 +802,10 @@ public class FileDataStorageManager {
public void copyLocalFile(OCFile ocFile, String targetPath) { public void copyLocalFile(OCFile ocFile, String targetPath) {
if (ocFile.fileExists() && !OCFile.ROOT_PATH.equals(ocFile.getFileName())) { if (ocFile.fileExists() && !OCFile.ROOT_PATH.equals(ocFile.getFileName())) {
String localPath = FileStorageUtils.getDefaultSavePathFor(account.name, ocFile); String localPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile);
File localFile = new File(localPath); File localFile = new File(localPath);
boolean copied = false; boolean copied = false;
String defaultSavePath = FileStorageUtils.getSavePath(account.name); String defaultSavePath = FileStorageUtils.getSavePath(user.getAccountName());
if (localFile.exists()) { if (localFile.exists()) {
File targetFile = new File(defaultSavePath + targetPath); File targetFile = new File(defaultSavePath + targetPath);
File targetFolder = targetFile.getParentFile(); File targetFolder = targetFile.getParentFile();
@ -828,6 +818,10 @@ public class FileDataStorageManager {
} }
} }
/**
* This method does not require {@link FileDataStorageManager} being initialized
* with any specific user. Migration can be performed with {@link com.nextcloud.client.account.AnonymousUser}.
*/
public void migrateStoredFiles(String sourcePath, String destinationPath) public void migrateStoredFiles(String sourcePath, String destinationPath)
throws RemoteException, OperationApplicationException { throws RemoteException, OperationApplicationException {
Cursor cursor; Cursor cursor;
@ -962,14 +956,14 @@ public class FileDataStorageManager {
key + AND key + AND
+ ProviderTableMeta.FILE_ACCOUNT_OWNER + ProviderTableMeta.FILE_ACCOUNT_OWNER
+ "=?", + "=?",
new String[]{value, account.name}, null); new String[]{value, user.getAccountName()}, null);
} else { } else {
try { try {
cursor = getContentProviderClient().query( cursor = getContentProviderClient().query(
ProviderTableMeta.CONTENT_URI, ProviderTableMeta.CONTENT_URI,
null, null,
key + AND + ProviderTableMeta.FILE_ACCOUNT_OWNER key + AND + ProviderTableMeta.FILE_ACCOUNT_OWNER
+ "=?", new String[]{value, account.name}, + "=?", new String[]{value, user.getAccountName()},
null); null);
} catch (RemoteException e) { } catch (RemoteException e) {
Log_OC.e(TAG, "Could not get file details: " + e.getMessage(), e); Log_OC.e(TAG, "Could not get file details: " + e.getMessage(), e);
@ -999,7 +993,7 @@ public class FileDataStorageManager {
// try to find existing file and bind it with current account; // try to find existing file and bind it with current account;
// with the current update of SynchronizeFolderOperation, this won't be // with the current update of SynchronizeFolderOperation, this won't be
// necessary anymore after a full synchronization of the account // necessary anymore after a full synchronization of the account
File file = new File(FileStorageUtils.getDefaultSavePathFor(account.name, ocFile)); File file = new File(FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile));
if (file.exists()) { if (file.exists()) {
ocFile.setStoragePath(file.getAbsolutePath()); ocFile.setStoragePath(file.getAbsolutePath());
ocFile.setLastSyncDateForData(file.lastModified()); ocFile.setLastSyncDateForData(file.lastModified());
@ -1160,7 +1154,7 @@ public class FileDataStorageManager {
null, null,
key + AND key + AND
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?", + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
new String[]{value, account.name}, new String[]{value, user.getAccountName()},
null null
); );
} else { } else {
@ -1169,7 +1163,7 @@ public class FileDataStorageManager {
ProviderTableMeta.CONTENT_URI_SHARE, ProviderTableMeta.CONTENT_URI_SHARE,
null, null,
key + AND + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?", key + AND + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
new String[]{value, account.name}, new String[]{value, user.getAccountName()},
null null
); );
} catch (RemoteException e) { } catch (RemoteException e) {
@ -1205,21 +1199,21 @@ public class FileDataStorageManager {
selectionArgs = new String[]{ selectionArgs = new String[]{
path, path,
Integer.toString(type.getValue()), Integer.toString(type.getValue()),
account.name user.getAccountName()
}; };
} else { } else {
if (shareWith == null) { if (shareWith == null) {
selectionArgs = new String[]{ selectionArgs = new String[]{
path, path,
Integer.toString(type.getValue()), Integer.toString(type.getValue()),
account.name, user.getAccountName(),
"" ""
}; };
} else { } else {
selectionArgs = new String[]{ selectionArgs = new String[]{
path, path,
Integer.toString(type.getValue()), Integer.toString(type.getValue()),
account.name, user.getAccountName(),
shareWith shareWith
}; };
} }
@ -1274,7 +1268,7 @@ public class FileDataStorageManager {
contentValues.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0); contentValues.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
contentValues.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId()); contentValues.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
contentValues.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId()); contentValues.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
contentValues.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, account.name); contentValues.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, user.getAccountName());
contentValues.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0); contentValues.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0);
contentValues.put(ProviderTableMeta.OCSHARES_NOTE, share.getNote()); contentValues.put(ProviderTableMeta.OCSHARES_NOTE, share.getNote());
contentValues.put(ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD, share.isHideFileDownload()); contentValues.put(ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD, share.isHideFileDownload());
@ -1313,7 +1307,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE); cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?"; String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
String[] whereArgs = new String[]{account.name}; String[] whereArgs = new String[]{user.getAccountName()};
if (getContentResolver() != null) { if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs); getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
@ -1332,7 +1326,7 @@ public class FileDataStorageManager {
contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE); contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
contentValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE); contentValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PARENT + " = ?"; String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PARENT + " = ?";
String[] whereArgs = new String[]{account.name, String.valueOf(folder.getFileId())}; String[] whereArgs = new String[]{user.getAccountName(), String.valueOf(folder.getFileId())};
if (getContentResolver() != null) { if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI, contentValues, where, whereArgs); getContentResolver().update(ProviderTableMeta.CONTENT_URI, contentValues, where, whereArgs);
@ -1351,7 +1345,7 @@ public class FileDataStorageManager {
contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE); contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
contentValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE); contentValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " = ?"; String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " = ?";
String[] whereArgs = new String[]{account.name, filePath}; String[] whereArgs = new String[]{user.getAccountName(), filePath};
if (getContentResolver() != null) { if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI, contentValues, where, whereArgs); getContentResolver().update(ProviderTableMeta.CONTENT_URI, contentValues, where, whereArgs);
@ -1368,7 +1362,7 @@ public class FileDataStorageManager {
@VisibleForTesting @VisibleForTesting
public void cleanShares() { public void cleanShares() {
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"; String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
String[] whereArgs = new String[]{account.name}; String[] whereArgs = new String[]{user.getAccountName()};
if (getContentResolver() != null) { if (getContentResolver() != null) {
getContentResolver().delete(ProviderTableMeta.CONTENT_URI_SHARE, where, whereArgs); getContentResolver().delete(ProviderTableMeta.CONTENT_URI_SHARE, where, whereArgs);
@ -1451,7 +1445,7 @@ public class FileDataStorageManager {
if (!file.isFolder()) { if (!file.isFolder()) {
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
} }
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, account.name); cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
cv.put( cv.put(
ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA,
@ -1512,7 +1506,7 @@ public class FileDataStorageManager {
Uri contentUriShare = ProviderTableMeta.CONTENT_URI_SHARE; Uri contentUriShare = ProviderTableMeta.CONTENT_URI_SHARE;
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND + String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND +
ProviderTableMeta._ID + " = ?"; ProviderTableMeta._ID + " = ?";
String[] whereArgs = {account.name, Long.toString(share.getId())}; String[] whereArgs = {user.getAccountName(), Long.toString(share.getId())};
if (getContentProviderClient() != null) { if (getContentProviderClient() != null) {
try { try {
@ -1635,7 +1629,7 @@ public class FileDataStorageManager {
if (folder != null) { if (folder != null) {
String where = ProviderTableMeta.OCSHARES_PATH + AND String where = ProviderTableMeta.OCSHARES_PATH + AND
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"; + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
String[] whereArgs = new String[]{"", account.name}; String[] whereArgs = new String[]{"", user.getAccountName()};
List<OCFile> files = getFolderContent(folder, false); List<OCFile> files = getFolderContent(folder, false);
@ -1656,7 +1650,7 @@ public class FileDataStorageManager {
String where = ProviderTableMeta.OCSHARES_PATH + AND String where = ProviderTableMeta.OCSHARES_PATH + AND
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " = ?"; + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " = ?";
String[] whereArgs = new String[]{filePath, account.name}; String[] whereArgs = new String[]{filePath, user.getAccountName()};
preparedOperations.add( preparedOperations.add(
ContentProviderOperation ContentProviderOperation
@ -1889,7 +1883,7 @@ public class FileDataStorageManager {
ProviderTableMeta.CONTENT_URI_FILE, ProviderTableMeta.CONTENT_URI_FILE,
projection, projection,
whereForDescencentsInConflict, whereForDescencentsInConflict,
new String[]{account.name, parentPath + "%"}, new String[]{user.getAccountName(), parentPath + "%"},
null null
); );
} else { } else {
@ -1898,7 +1892,7 @@ public class FileDataStorageManager {
ProviderTableMeta.CONTENT_URI_FILE, ProviderTableMeta.CONTENT_URI_FILE,
projection, projection,
whereForDescencentsInConflict, whereForDescencentsInConflict,
new String[]{account.name, parentPath + "%"}, new String[]{user.getAccountName(), parentPath + "%"},
null null
); );
} catch (RemoteException e) { } catch (RemoteException e) {
@ -1914,7 +1908,7 @@ public class FileDataStorageManager {
cv, cv,
ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_ACCOUNT_OWNER + AND +
ProviderTableMeta.FILE_PATH + "=?", ProviderTableMeta.FILE_PATH + "=?",
new String[]{account.name, parentPath} new String[]{user.getAccountName(), parentPath}
); );
} else { } else {
try { try {
@ -1923,7 +1917,7 @@ public class FileDataStorageManager {
cv, cv,
ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_ACCOUNT_OWNER + AND +
ProviderTableMeta.FILE_PATH + "=?" ProviderTableMeta.FILE_PATH + "=?"
, new String[]{account.name, parentPath} , new String[]{user.getAccountName(), parentPath}
); );
} catch (RemoteException e) { } catch (RemoteException e) {
Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage(), e); Log_OC.e(TAG, "Failed saving conflict in database " + e.getMessage(), e);
@ -1948,18 +1942,18 @@ public class FileDataStorageManager {
public void saveCapabilities(OCCapability capability) { public void saveCapabilities(OCCapability capability) {
// Prepare capabilities data // Prepare capabilities data
ContentValues contentValues = createContentValues(account.name, capability); ContentValues contentValues = createContentValues(user.getAccountName(), capability);
if (capabilityExists(account.name)) { if (capabilityExists(user.getAccountName())) {
if (getContentResolver() != null) { if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES, contentValues, getContentResolver().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES, contentValues,
ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?", ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?",
new String[]{account.name}); new String[]{user.getAccountName()});
} else { } else {
try { try {
getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES, getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES,
contentValues, ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?", contentValues, ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?",
new String[]{account.name}); new String[]{user.getAccountName()});
} catch (RemoteException e) { } catch (RemoteException e) {
Log_OC.e(TAG, FAILED_TO_INSERT_MSG + e.getMessage(), e); Log_OC.e(TAG, FAILED_TO_INSERT_MSG + e.getMessage(), e);
} }
@ -1981,7 +1975,7 @@ public class FileDataStorageManager {
long new_id = Long.parseLong(result_uri.getPathSegments() long new_id = Long.parseLong(result_uri.getPathSegments()
.get(1)); .get(1));
capability.setId(new_id); capability.setId(new_id);
capability.setAccountName(account.name); capability.setAccountName(user.getAccountName());
} }
} }
} }
@ -2341,7 +2335,7 @@ public class FileDataStorageManager {
public void deleteAllFiles() { public void deleteAllFiles() {
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "= ? AND " + String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "= ? AND " +
ProviderTableMeta.FILE_PATH + "= ?"; ProviderTableMeta.FILE_PATH + "= ?";
String[] whereArgs = new String[]{account.name, OCFile.ROOT_PATH}; String[] whereArgs = new String[]{user.getAccountName(), OCFile.ROOT_PATH};
if (getContentResolver() != null) { if (getContentResolver() != null) {
getContentResolver().delete(ProviderTableMeta.CONTENT_URI_DIR, where, whereArgs); getContentResolver().delete(ProviderTableMeta.CONTENT_URI_DIR, where, whereArgs);
@ -2349,14 +2343,14 @@ public class FileDataStorageManager {
try { try {
getContentProviderClient().delete(ProviderTableMeta.CONTENT_URI_DIR, where, whereArgs); getContentProviderClient().delete(ProviderTableMeta.CONTENT_URI_DIR, where, whereArgs);
} catch (RemoteException e) { } catch (RemoteException e) {
Log_OC.e(TAG, "Exception in deleteAllFiles for account " + account.name + ": " + e.getMessage(), e); Log_OC.e(TAG, "Exception in deleteAllFiles for account " + user.getAccountName() + ": " + e.getMessage(), e);
} }
} }
} }
public List<OCFile> getAllFiles() { public List<OCFile> getAllFiles() {
String selection = ProviderTableMeta.FILE_ACCOUNT_OWNER + "= ? "; String selection = ProviderTableMeta.FILE_ACCOUNT_OWNER + "= ? ";
String[] selectionArgs = new String[]{account.name}; String[] selectionArgs = new String[]{user.getAccountName()};
List<OCFile> folderContent = new ArrayList<>(); List<OCFile> folderContent = new ArrayList<>();
@ -2410,7 +2404,8 @@ public class FileDataStorageManager {
return this.contentProviderClient; return this.contentProviderClient;
} }
@Deprecated
public Account getAccount() { public Account getAccount() {
return this.account; return this.user.toPlatformAccount();
} }
} }

View file

@ -41,6 +41,7 @@ import android.util.Pair;
import com.nextcloud.client.account.User; import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.files.downloader.DownloadTask; import com.nextcloud.client.files.downloader.DownloadTask;
import com.nextcloud.java.util.Optional;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager;
@ -104,7 +105,7 @@ public class FileDownloader extends Service
private ServiceHandler mServiceHandler; private ServiceHandler mServiceHandler;
private IBinder mBinder; private IBinder mBinder;
private OwnCloudClient mDownloadClient; private OwnCloudClient mDownloadClient;
private Account mCurrentAccount; private Optional<User> currentUser;
private FileDataStorageManager mStorageManager; private FileDataStorageManager mStorageManager;
private IndexedForest<DownloadFileOperation> mPendingDownloads = new IndexedForest<>(); private IndexedForest<DownloadFileOperation> mPendingDownloads = new IndexedForest<>();
@ -210,7 +211,7 @@ public class FileDownloader extends Service
conflictUploadId = intent.getLongExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, -1); conflictUploadId = intent.getLongExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, -1);
AbstractList<String> requestedDownloads = new Vector<String>(); AbstractList<String> requestedDownloads = new Vector<String>();
try { try {
DownloadFileOperation newDownload = new DownloadFileOperation(user.toPlatformAccount(), DownloadFileOperation newDownload = new DownloadFileOperation(user,
file, file,
behaviour, behaviour,
activityName, activityName,
@ -303,9 +304,9 @@ public class FileDownloader extends Service
if (download != null) { if (download != null) {
download.cancel(); download.cancel();
} else { } else {
if (mCurrentDownload != null && mCurrentAccount != null && if (mCurrentDownload != null && currentUser.isPresent() &&
mCurrentDownload.getRemotePath().startsWith(file.getRemotePath()) && mCurrentDownload.getRemotePath().startsWith(file.getRemotePath()) &&
account.name.equals(mCurrentAccount.name)) { account.name.equals(currentUser.get().getAccountName())) {
mCurrentDownload.cancel(); mCurrentDownload.cancel();
} }
} }
@ -456,18 +457,16 @@ public class FileDownloader extends Service
RemoteOperationResult downloadResult = null; RemoteOperationResult downloadResult = null;
try { try {
/// prepare client object to send the request to the ownCloud server /// prepare client object to send the request to the ownCloud server
if (mCurrentAccount == null || Account currentDownloadAccount = mCurrentDownload.getAccount();
!mCurrentAccount.equals(mCurrentDownload.getAccount())) { Optional<User> currentDownloadUser = accountManager.getUser(currentDownloadAccount.name);
mCurrentAccount = mCurrentDownload.getAccount(); if (!currentUser.equals(currentDownloadUser)) {
mStorageManager = new FileDataStorageManager( currentUser = currentDownloadUser;
mCurrentAccount, mStorageManager = new FileDataStorageManager(currentUser.get(), getContentResolver());
getContentResolver()
);
} // else, reuse storage manager from previous operation } // else, reuse storage manager from previous operation
// always get client from client manager, to get fresh credentials in case // always get client from client manager, to get fresh credentials in case
// of update // of update
OwnCloudAccount ocAccount = new OwnCloudAccount(mCurrentAccount, this); OwnCloudAccount ocAccount = currentDownloadUser.get().toOwnCloudAccount();
mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton(). mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, this); getClientFor(ocAccount, this);
@ -484,7 +483,7 @@ public class FileDownloader extends Service
} finally { } finally {
Pair<DownloadFileOperation, String> removeResult = mPendingDownloads.removePayload( Pair<DownloadFileOperation, String> removeResult = mPendingDownloads.removePayload(
mCurrentAccount.name, mCurrentDownload.getRemotePath()); currentUser.get().getAccountName(), mCurrentDownload.getRemotePath());
if (downloadResult == null) { if (downloadResult == null) {
downloadResult = new RemoteOperationResult(new RuntimeException("Error downloading…")); downloadResult = new RemoteOperationResult(new RuntimeException("Error downloading…"));

View file

@ -491,7 +491,7 @@ public class FileUploader extends Service
onWifiOnly, onWifiOnly,
whileChargingOnly, whileChargingOnly,
disableRetries, disableRetries,
new FileDataStorageManager(user.toPlatformAccount(), getContentResolver()) new FileDataStorageManager(user, getContentResolver())
); );
newUpload.setCreatedBy(createdBy); newUpload.setCreatedBy(createdBy);
if (isCreateRemoteFolder) { if (isCreateRemoteFolder) {
@ -541,7 +541,7 @@ public class FileUploader extends Service
onWifiOnly, onWifiOnly,
whileChargingOnly, whileChargingOnly,
true, true,
new FileDataStorageManager(user.toPlatformAccount(), getContentResolver()) new FileDataStorageManager(user, getContentResolver())
); );
newUpload.addDataTransferProgressListener(this); newUpload.addDataTransferProgressListener(this);
@ -623,7 +623,7 @@ public class FileUploader extends Service
/// prepare client object to send the request to the ownCloud server /// prepare client object to send the request to the ownCloud server
if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentUpload.getAccount())) { if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentUpload.getAccount())) {
mCurrentAccount = mCurrentUpload.getAccount(); mCurrentAccount = mCurrentUpload.getAccount();
mStorageManager = new FileDataStorageManager(mCurrentAccount, getContentResolver()); mStorageManager = new FileDataStorageManager(getCurrentUser().get(), getContentResolver());
} // else, reuse storage manager from previous operation } // else, reuse storage manager from previous operation
// always get client from client manager, to get fresh credentials in case of update // always get client from client manager, to get fresh credentials in case of update

View file

@ -26,6 +26,7 @@ import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import com.nextcloud.client.account.User;
import com.owncloud.android.datamodel.DecryptedFolderMetadata; import com.owncloud.android.datamodel.DecryptedFolderMetadata;
import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
@ -52,7 +53,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class DownloadFileOperation extends RemoteOperation { public class DownloadFileOperation extends RemoteOperation {
private static final String TAG = DownloadFileOperation.class.getSimpleName(); private static final String TAG = DownloadFileOperation.class.getSimpleName();
private Account account; private User user;
private OCFile file; private OCFile file;
private String behaviour; private String behaviour;
private String etag = ""; private String etag = "";
@ -66,10 +67,10 @@ public class DownloadFileOperation extends RemoteOperation {
private final AtomicBoolean cancellationRequested = new AtomicBoolean(false); private final AtomicBoolean cancellationRequested = new AtomicBoolean(false);
public DownloadFileOperation(Account account, OCFile file, String behaviour, String activityName, public DownloadFileOperation(User user, OCFile file, String behaviour, String activityName,
String packageName, Context context) { String packageName, Context context) {
if (account == null) { if (user == null) {
throw new IllegalArgumentException("Illegal null account in DownloadFileOperation " + throw new IllegalArgumentException("Illegal null user in DownloadFileOperation " +
"creation"); "creation");
} }
if (file == null) { if (file == null) {
@ -77,7 +78,7 @@ public class DownloadFileOperation extends RemoteOperation {
"creation"); "creation");
} }
this.account = account; this.user = user;
this.file = file; this.file = file;
this.behaviour = behaviour; this.behaviour = behaviour;
this.activityName = activityName; this.activityName = activityName;
@ -85,8 +86,8 @@ public class DownloadFileOperation extends RemoteOperation {
this.context = context; this.context = context;
} }
public DownloadFileOperation(Account account, OCFile file, Context context) { public DownloadFileOperation(User user, OCFile file, Context context) {
this(account, file, null, null, null, context); this(user, file, null, null, null, context);
} }
public String getSavePath() { public String getSavePath() {
@ -100,15 +101,15 @@ public class DownloadFileOperation extends RemoteOperation {
return path.getAbsolutePath(); return path.getAbsolutePath();
} }
} }
return FileStorageUtils.getDefaultSavePathFor(account.name, file); return FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), file);
} }
public String getTmpPath() { public String getTmpPath() {
return FileStorageUtils.getTemporalPath(account.name) + file.getRemotePath(); return FileStorageUtils.getTemporalPath(user.getAccountName()) + file.getRemotePath();
} }
public String getTmpFolder() { public String getTmpFolder() {
return FileStorageUtils.getTemporalPath(account.name); return FileStorageUtils.getTemporalPath(user.getAccountName());
} }
public String getRemotePath() { public String getRemotePath() {
@ -177,11 +178,14 @@ public class DownloadFileOperation extends RemoteOperation {
// decrypt file // decrypt file
if (file.isEncrypted()) { if (file.isEncrypted()) {
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account, context.getContentResolver()); FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user, context.getContentResolver());
OCFile parent = fileDataStorageManager.getFileByPath(file.getParentRemotePath()); OCFile parent = fileDataStorageManager.getFileByPath(file.getParentRemotePath());
DecryptedFolderMetadata metadata = EncryptionUtils.downloadFolderMetadata(parent, client, context, account); DecryptedFolderMetadata metadata = EncryptionUtils.downloadFolderMetadata(parent,
client,
context,
user.toPlatformAccount());
if (metadata == null) { if (metadata == null) {
return new RemoteOperationResult(RemoteOperationResult.ResultCode.METADATA_NOT_FOUND); return new RemoteOperationResult(RemoteOperationResult.ResultCode.METADATA_NOT_FOUND);
@ -235,8 +239,13 @@ public class DownloadFileOperation extends RemoteOperation {
} }
} }
@Deprecated
public Account getAccount() { public Account getAccount() {
return this.account; return this.user.toPlatformAccount();
}
public User getUser() {
return this.user;
} }
public OCFile getFile() { public OCFile getFile() {

View file

@ -198,6 +198,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
OCFile ocFile = document.getFile(); OCFile ocFile = document.getFile();
Account account = document.getAccount(); Account account = document.getAccount();
User user = accountManager.getUser(account.name).orElseGet(accountManager::getAnonymousUser);
int accessMode = ParcelFileDescriptor.parseMode(mode); int accessMode = ParcelFileDescriptor.parseMode(mode);
boolean writeOnly = (accessMode & MODE_WRITE_ONLY) != 0; boolean writeOnly = (accessMode & MODE_WRITE_ONLY) != 0;
@ -208,7 +209,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
// TODO show a conflict notification with a pending intent that shows a ConflictResolveDialog // TODO show a conflict notification with a pending intent that shows a ConflictResolveDialog
Log_OC.w(TAG, "Conflict found!"); Log_OC.w(TAG, "Conflict found!");
} else { } else {
DownloadFileOperation downloadFileOperation = new DownloadFileOperation(account, ocFile, context); DownloadFileOperation downloadFileOperation = new DownloadFileOperation(user, ocFile, context);
RemoteOperationResult result = downloadFileOperation.execute(document.getClient()); RemoteOperationResult result = downloadFileOperation.execute(document.getClient());
if (!result.isSuccess()) { if (!result.isSuccess()) {
if (ocFile.isDown()) { if (ocFile.isDown()) {
@ -674,9 +675,9 @@ public class DocumentsStorageProvider extends DocumentsProvider {
ContentResolver contentResolver = getContext().getContentResolver(); ContentResolver contentResolver = getContext().getContentResolver();
for (Account account : accountManager.getAccounts()) { for (User user : accountManager.getAllUsers()) {
final FileDataStorageManager storageManager = new FileDataStorageManager(account, contentResolver); final FileDataStorageManager storageManager = new FileDataStorageManager(user, contentResolver);
rootIdToStorageManager.put(account.hashCode(), storageManager); rootIdToStorageManager.put(user.hashCode(), storageManager);
} }
} }

View file

@ -160,7 +160,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
this.setAccount(account); this.setAccount(account);
this.setContentProviderClient(providerClient); this.setContentProviderClient(providerClient);
this.setStorageManager(new FileDataStorageManager(account, providerClient)); this.setStorageManager(new FileDataStorageManager(getUser(), providerClient));
try { try {
this.initClientForCurrentAccount(); this.initClientForCurrentAccount();
@ -480,7 +480,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
/// includes a pending intent in the notification showing a more detailed explanation /// includes a pending intent in the notification showing a more detailed explanation
Intent explanationIntent = new Intent(getContext(), ErrorsWhileCopyingHandlerActivity.class); Intent explanationIntent = new Intent(getContext(), ErrorsWhileCopyingHandlerActivity.class);
explanationIntent.putExtra(ErrorsWhileCopyingHandlerActivity.EXTRA_ACCOUNT, getAccount()); explanationIntent.putExtra(ErrorsWhileCopyingHandlerActivity.EXTRA_USER, getUser());
ArrayList<String> remotePaths = new ArrayList<String>(); ArrayList<String> remotePaths = new ArrayList<String>();
ArrayList<String> localPaths = new ArrayList<String>(); ArrayList<String> localPaths = new ArrayList<String>();
remotePaths.addAll(mForgottenLocalFiles.keySet()); remotePaths.addAll(mForgottenLocalFiles.keySet());

View file

@ -20,7 +20,6 @@
package com.owncloud.android.ui.activity; package com.owncloud.android.ui.activity;
import android.accounts.Account;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
@ -36,6 +35,7 @@ import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.nextcloud.client.account.User;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
@ -65,7 +65,7 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
private static final String TAG = ErrorsWhileCopyingHandlerActivity.class.getSimpleName(); private static final String TAG = ErrorsWhileCopyingHandlerActivity.class.getSimpleName();
public static final String EXTRA_ACCOUNT = public static final String EXTRA_USER =
ErrorsWhileCopyingHandlerActivity.class.getCanonicalName() + ".EXTRA_ACCOUNT"; ErrorsWhileCopyingHandlerActivity.class.getCanonicalName() + ".EXTRA_ACCOUNT";
public static final String EXTRA_LOCAL_PATHS = public static final String EXTRA_LOCAL_PATHS =
ErrorsWhileCopyingHandlerActivity.class.getCanonicalName() + ".EXTRA_LOCAL_PATHS"; ErrorsWhileCopyingHandlerActivity.class.getCanonicalName() + ".EXTRA_LOCAL_PATHS";
@ -74,7 +74,7 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
private static final String WAIT_DIALOG_TAG = "WAIT_DIALOG"; private static final String WAIT_DIALOG_TAG = "WAIT_DIALOG";
protected Account mAccount; protected User user;
protected FileDataStorageManager mStorageManager; protected FileDataStorageManager mStorageManager;
protected List<String> mLocalPaths; protected List<String> mLocalPaths;
protected List<String> mRemotePaths; protected List<String> mRemotePaths;
@ -91,10 +91,10 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
/// read extra parameters in intent /// read extra parameters in intent
Intent intent = getIntent(); Intent intent = getIntent();
mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT); user = intent.getParcelableExtra(EXTRA_USER);
mRemotePaths = intent.getStringArrayListExtra(EXTRA_REMOTE_PATHS); mRemotePaths = intent.getStringArrayListExtra(EXTRA_REMOTE_PATHS);
mLocalPaths = intent.getStringArrayListExtra(EXTRA_LOCAL_PATHS); mLocalPaths = intent.getStringArrayListExtra(EXTRA_LOCAL_PATHS);
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); mStorageManager = new FileDataStorageManager(user, getContentResolver());
mHandler = new Handler(); mHandler = new Handler();
if (mCurrentDialog != null) { if (mCurrentDialog != null) {
mCurrentDialog.dismiss(); mCurrentDialog.dismiss();
@ -108,7 +108,7 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
TextView textView = findViewById(R.id.message); TextView textView = findViewById(R.id.message);
String appName = getString(R.string.app_name); String appName = getString(R.string.app_name);
String message = String.format(getString(R.string.sync_foreign_files_forgotten_explanation), String message = String.format(getString(R.string.sync_foreign_files_forgotten_explanation),
appName, appName, appName, appName, mAccount.name); appName, appName, appName, appName, user.getAccountName());
textView.setText(message); textView.setText(message);
textView.setMovementMethod(new ScrollingMovementMethod()); textView.setMovementMethod(new ScrollingMovementMethod());
@ -230,7 +230,7 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
while (!mLocalPaths.isEmpty()) { while (!mLocalPaths.isEmpty()) {
String currentPath = mLocalPaths.get(0); String currentPath = mLocalPaths.get(0);
File currentFile = new File(currentPath); File currentFile = new File(currentPath);
String expectedPath = FileStorageUtils.getSavePath(mAccount.name) + mRemotePaths.get(0); String expectedPath = FileStorageUtils.getSavePath(user.getAccountName()) + mRemotePaths.get(0);
File expectedFile = new File(expectedPath); File expectedFile = new File(expectedPath);
if (expectedFile.equals(currentFile) || currentFile.renameTo(expectedFile)) { if (expectedFile.equals(currentFile) || currentFile.renameTo(expectedFile)) {

View file

@ -695,8 +695,7 @@ public class SettingsActivity extends ThemedPreferenceActivity
if (storagePath.equals(newPath)) { if (storagePath.equals(newPath)) {
return true; return true;
} }
StorageMigration storageMigration = new StorageMigration(this, user, storagePath, newPath);
StorageMigration storageMigration = new StorageMigration(this, storagePath, newPath);
storageMigration.setStorageMigrationProgressListener(this); storageMigration.setStorageMigrationProgressListener(this);
storageMigration.migrate(); storageMigration.migrate();

View file

@ -30,6 +30,7 @@ import android.content.DialogInterface.OnClickListener;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.view.View; import android.view.View;
import com.nextcloud.client.account.User;
import com.owncloud.android.MainApp; import com.owncloud.android.MainApp;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager;
@ -48,6 +49,7 @@ public class StorageMigration {
private static final String TAG = StorageMigration.class.getName(); private static final String TAG = StorageMigration.class.getName();
private Context mContext; private Context mContext;
private User user;
private String mSourceStoragePath; private String mSourceStoragePath;
private String mTargetStoragePath; private String mTargetStoragePath;
@ -58,8 +60,9 @@ public class StorageMigration {
void onCancelMigration(); void onCancelMigration();
} }
public StorageMigration(Context context, String sourcePath, String targetPath) { public StorageMigration(Context context, User user, String sourcePath, String targetPath) {
mContext = context; mContext = context;
this.user = user;
mSourceStoragePath = sourcePath; mSourceStoragePath = sourcePath;
mTargetStoragePath = targetPath; mTargetStoragePath = targetPath;
} }
@ -76,6 +79,7 @@ public class StorageMigration {
progressDialog.show(); progressDialog.show();
new FileMigrationTask( new FileMigrationTask(
mContext, mContext,
user,
mSourceStoragePath, mSourceStoragePath,
mTargetStoragePath, mTargetStoragePath,
progressDialog, progressDialog,
@ -118,6 +122,7 @@ public class StorageMigration {
progressDialog.show(); progressDialog.show();
new StoragePathSwitchTask( new StoragePathSwitchTask(
mContext, mContext,
user,
mSourceStoragePath, mSourceStoragePath,
mTargetStoragePath, mTargetStoragePath,
progressDialog, progressDialog,
@ -134,6 +139,7 @@ public class StorageMigration {
progressDialog.show(); progressDialog.show();
new FileMigrationTask( new FileMigrationTask(
mContext, mContext,
user,
mSourceStoragePath, mSourceStoragePath,
mTargetStoragePath, mTargetStoragePath,
progressDialog, progressDialog,
@ -167,6 +173,7 @@ public class StorageMigration {
protected String mStorageSource; protected String mStorageSource;
protected String mStorageTarget; protected String mStorageTarget;
protected Context mContext; protected Context mContext;
protected User user;
protected ProgressDialog mProgressDialog; protected ProgressDialog mProgressDialog;
protected StorageMigrationProgressListener mListener; protected StorageMigrationProgressListener mListener;
@ -174,11 +181,13 @@ public class StorageMigration {
protected Account[] mOcAccounts; protected Account[] mOcAccounts;
public FileMigrationTaskBase(Context context, public FileMigrationTaskBase(Context context,
User user,
String source, String source,
String target, String target,
ProgressDialog progressDialog, ProgressDialog progressDialog,
StorageMigrationProgressListener listener) throws SecurityException { StorageMigrationProgressListener listener) throws SecurityException {
mContext = context; mContext = context;
this.user = user;
mStorageSource = source; mStorageSource = source;
mStorageTarget = target; mStorageTarget = target;
mProgressDialog = progressDialog; mProgressDialog = progressDialog;
@ -290,11 +299,12 @@ public class StorageMigration {
static private class StoragePathSwitchTask extends FileMigrationTaskBase { static private class StoragePathSwitchTask extends FileMigrationTaskBase {
public StoragePathSwitchTask(Context context, public StoragePathSwitchTask(Context context,
User user,
String source, String source,
String target, String target,
ProgressDialog progressDialog, ProgressDialog progressDialog,
StorageMigrationProgressListener listener) { StorageMigrationProgressListener listener) {
super(context, source, target, progressDialog, listener); super(context, user, source, target, progressDialog, listener);
} }
@Override @Override
@ -337,11 +347,12 @@ public class StorageMigration {
} }
public FileMigrationTask(Context context, public FileMigrationTask(Context context,
User user,
String source, String source,
String target, String target,
ProgressDialog progressDialog, ProgressDialog progressDialog,
StorageMigrationProgressListener listener) { StorageMigrationProgressListener listener) {
super(context, source, target, progressDialog, listener); super(context, user, source, target, progressDialog, listener);
} }
@Override @Override
@ -436,8 +447,7 @@ public class StorageMigration {
} }
private void updateIndex(Context context) throws MigrationException { private void updateIndex(Context context) throws MigrationException {
final Account nullAccount = null; FileDataStorageManager manager = new FileDataStorageManager(user, context.getContentResolver());
FileDataStorageManager manager = new FileDataStorageManager(nullAccount, context.getContentResolver());
try { try {
manager.migrateStoredFiles(mStorageSource, mStorageTarget); manager.migrateStoredFiles(mStorageSource, mStorageTarget);

View file

@ -22,9 +22,9 @@
*/ */
package com.owncloud.android.utils.theme; package com.owncloud.android.utils.theme;
import android.accounts.Account;
import android.content.Context; import android.content.Context;
import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManagerImpl; import com.nextcloud.client.account.UserAccountManagerImpl;
import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.lib.resources.status.OCCapability;
@ -34,22 +34,15 @@ import com.owncloud.android.lib.resources.status.OCCapability;
*/ */
public final class CapabilityUtils { public final class CapabilityUtils {
public static OCCapability getCapability(Context context) { public static OCCapability getCapability(Context context) {
return getCapability(null, context); User user = null;
} if (context != null) {
private static OCCapability getCapability(Account acc, Context context) {
Account account = null;
if (acc != null) {
account = acc;
} else if (context != null) {
// TODO: refactor when dark theme work is completed // TODO: refactor when dark theme work is completed
account = UserAccountManagerImpl.fromContext(context).getCurrentAccount(); user = UserAccountManagerImpl.fromContext(context).getUser();
} }
if (account != null) { if (user != null) {
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver()); FileDataStorageManager storageManager = new FileDataStorageManager(user, context.getContentResolver());
return storageManager.getCapability(account.name); return storageManager.getCapability(user.getAccountName());
} else { } else {
return new OCCapability(); return new OCCapability();
} }

View file

@ -29,6 +29,7 @@ import android.graphics.Color;
import com.nextcloud.client.account.User; import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManagerImpl; import com.nextcloud.client.account.UserAccountManagerImpl;
import com.nextcloud.java.util.Optional;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.lib.resources.status.OCCapability;
@ -290,18 +291,18 @@ public final class ThemeColorUtils {
} }
private static OCCapability getCapability(Account acc, Context context) { private static OCCapability getCapability(Account acc, Context context) {
Account account = null; Optional<User> user = Optional.empty();
if (acc != null) { if (acc != null) {
account = acc; user = UserAccountManagerImpl.fromContext(context).getUser(acc.name);
} else if (context != null) { } else if (context != null) {
// TODO: refactor when dark theme work is completed // TODO: refactor when dark theme work is completed
account = UserAccountManagerImpl.fromContext(context).getCurrentAccount(); user = Optional.of(UserAccountManagerImpl.fromContext(context).getUser());
} }
if (account != null) { if (user.isPresent()) {
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver()); FileDataStorageManager storageManager = new FileDataStorageManager(user.get(), context.getContentResolver());
return storageManager.getCapability(account.name); return storageManager.getCapability(user.get().getAccountName());
} else { } else {
return new OCCapability(); return new OCCapability();
} }