mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 05:05:31 +03:00
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:
commit
373fec8b45
23 changed files with 178 additions and 167 deletions
|
@ -366,7 +366,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
|
|||
"[" + i + "/" + actionCount + "] " + "Download file: " +
|
||||
currentFolder.getDecryptedRemotePath() + fileToDownload.getDecryptedFileName());
|
||||
|
||||
assertTrue(new DownloadFileOperation(account, fileToDownload, targetContext)
|
||||
assertTrue(new DownloadFileOperation(user, fileToDownload, targetContext)
|
||||
.execute(client)
|
||||
.isSuccess());
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class ContactsBackupIT : AbstractOnServerIT() {
|
|||
false
|
||||
)[0]
|
||||
|
||||
assertTrue(DownloadFileOperation(account, backupOCFile, AbstractIT.targetContext).execute(client).isSuccess)
|
||||
assertTrue(DownloadFileOperation(user, backupOCFile, AbstractIT.targetContext).execute(client).isSuccess)
|
||||
|
||||
val backupFile = File(backupOCFile.storagePath)
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ public abstract class AbstractIT {
|
|||
// color
|
||||
String colorParameter = arguments.getString("COLOR");
|
||||
if (!TextUtils.isEmpty(colorParameter)) {
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account,
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user,
|
||||
targetContext.getContentResolver());
|
||||
|
||||
String colorHex = null;
|
||||
|
|
|
@ -92,8 +92,8 @@ public class DownloadIT extends AbstractOnServerIT {
|
|||
OCFile file2 = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty2.txt");
|
||||
verifyDownload(file1, file2);
|
||||
|
||||
assertTrue(new DownloadFileOperation(account, file1, targetContext).execute(client).isSuccess());
|
||||
assertTrue(new DownloadFileOperation(account, file2, targetContext).execute(client).isSuccess());
|
||||
assertTrue(new DownloadFileOperation(user, file1, targetContext).execute(client).isSuccess());
|
||||
assertTrue(new DownloadFileOperation(user, file2, targetContext).execute(client).isSuccess());
|
||||
|
||||
refreshFolder(FOLDER);
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public class FileDataStorageManagerContentProviderClientIT extends FileDataStora
|
|||
|
||||
@Override
|
||||
public void before() {
|
||||
sut = new FileDataStorageManager(account,
|
||||
sut = new FileDataStorageManager(user,
|
||||
targetContext
|
||||
.getContentResolver()
|
||||
.acquireContentProviderClient(ProviderMeta.ProviderTableMeta.CONTENT_URI)
|
||||
|
|
|
@ -217,7 +217,7 @@ abstract public class FileDataStorageManagerIT extends AbstractOnServerIT {
|
|||
*/
|
||||
@Test
|
||||
public void testGallerySearch() throws IOException {
|
||||
sut = new FileDataStorageManager(account,
|
||||
sut = new FileDataStorageManager(user,
|
||||
targetContext
|
||||
.getContentResolver()
|
||||
.acquireContentProviderClient(ProviderMeta.ProviderTableMeta.CONTENT_URI)
|
||||
|
|
|
@ -38,7 +38,7 @@ class DocumentsStorageProviderIT : AbstractOnServerIT() {
|
|||
private val authority = context.getString(R.string.document_provider_authority)
|
||||
|
||||
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 rootDir get() = DocumentFile.fromTreeUri(context, uri)!!
|
||||
|
||||
|
|
|
@ -62,13 +62,13 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
OCFile newFile = new OCFile("/newFile.txt");
|
||||
newFile.setFileLength(56000);
|
||||
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");
|
||||
existingFile.setFileLength(1024000);
|
||||
existingFile.setModificationTimestamp(1582019340);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, targetContext.getContentResolver());
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
|
||||
storageManager.saveNewFile(existingFile);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
|
@ -98,13 +98,13 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
// @Test
|
||||
// @ScreenshotTest // todo run without real server
|
||||
// public void screenshotImages() throws IOException {
|
||||
// FileDataStorageManager storageManager = new FileDataStorageManager(account,
|
||||
// FileDataStorageManager storageManager = new FileDataStorageManager(user,
|
||||
// targetContext.getContentResolver());
|
||||
//
|
||||
// OCFile newFile = new OCFile("/newFile.txt");
|
||||
// newFile.setFileLength(56000);
|
||||
// newFile.setModificationTimestamp(1522019340);
|
||||
// newFile.setStoragePath(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt");
|
||||
// newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
|
||||
//
|
||||
// File image = getFile("image.jpg");
|
||||
//
|
||||
|
@ -118,7 +118,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
// false,
|
||||
// true,
|
||||
// storageManager,
|
||||
// account,
|
||||
// user.toPlatformAccount(),
|
||||
// targetContext
|
||||
// ).execute(client).isSuccess());
|
||||
//
|
||||
|
@ -153,9 +153,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
public void cancel() {
|
||||
returnCode = false;
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
user.getAccountName());
|
||||
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
|
@ -164,9 +164,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
OCFile newFile = new OCFile("/newFile.txt");
|
||||
newFile.setFileLength(56000);
|
||||
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);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
|
@ -194,9 +194,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
public void keepExisting() {
|
||||
returnCode = false;
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
user.getAccountName());
|
||||
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
|
@ -205,9 +205,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
OCFile newFile = new OCFile("/newFile.txt");
|
||||
newFile.setFileLength(56000);
|
||||
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);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
|
@ -239,9 +239,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
public void keepNew() {
|
||||
returnCode = false;
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
user.getAccountName());
|
||||
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
|
@ -251,9 +251,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
OCFile newFile = new OCFile("/newFile.txt");
|
||||
newFile.setFileLength(56000);
|
||||
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);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
|
@ -285,9 +285,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
public void keepBoth() {
|
||||
returnCode = false;
|
||||
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt",
|
||||
"/newFile.txt",
|
||||
account.name);
|
||||
user.getAccountName());
|
||||
|
||||
OCFile existingFile = new OCFile("/newFile.txt");
|
||||
existingFile.setFileLength(1024000);
|
||||
|
@ -296,9 +296,9 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
|||
OCFile newFile = new OCFile("/newFile.txt");
|
||||
newFile.setFileLength(56000);
|
||||
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);
|
||||
|
||||
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
|
||||
|
|
|
@ -35,6 +35,8 @@ import com.nextcloud.android.lib.resources.profile.Action;
|
|||
import com.nextcloud.android.lib.resources.profile.HoverCard;
|
||||
import com.nextcloud.client.account.RegisteredUser;
|
||||
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.ui.ChooseAccountDialogFragment;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
|
@ -175,6 +177,7 @@ public class DialogFragmentIT extends AbstractIT {
|
|||
@Test
|
||||
@ScreenshotTest
|
||||
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
|
||||
UserAccountManager userAccountManager = activityRule.getActivity().getUserAccountManager();
|
||||
AccountManager accountManager = AccountManager.get(targetContext);
|
||||
for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
|
||||
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_USER_ID, "test");
|
||||
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));
|
||||
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.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
|
||||
|
||||
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newAccount,
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser,
|
||||
targetContext.getContentResolver());
|
||||
|
||||
OCCapability capability = new OCCapability();
|
||||
|
@ -257,7 +259,9 @@ public class DialogFragmentIT extends AbstractIT {
|
|||
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
|
||||
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());
|
||||
|
||||
OCCapability capability = new OCCapability();
|
||||
|
|
|
@ -139,7 +139,7 @@ class AppModule {
|
|||
@Provides
|
||||
FileDataStorageManager fileDataStorageManager(CurrentAccountProvider currentAccountProvider,
|
||||
Context context) {
|
||||
return new FileDataStorageManager(currentAccountProvider.getCurrentAccount(), context.getContentResolver());
|
||||
return new FileDataStorageManager(currentAccountProvider.getUser(), context.getContentResolver());
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -63,7 +63,7 @@ class DownloadTask(
|
|||
}
|
||||
|
||||
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 result = op.execute(client)
|
||||
if (result.isSuccess) {
|
||||
|
|
|
@ -65,7 +65,7 @@ class SessionMixin constructor(
|
|||
}
|
||||
|
||||
currentAccount?.let {
|
||||
val storageManager = FileDataStorageManager(currentAccount, contentResolver)
|
||||
val storageManager = FileDataStorageManager(getUser().get(), contentResolver)
|
||||
this.storageManager = storageManager
|
||||
this.capabilities = storageManager.getCapability(it.name)
|
||||
}
|
||||
|
|
|
@ -85,28 +85,18 @@ public class FileDataStorageManager {
|
|||
|
||||
private ContentResolver contentResolver;
|
||||
private ContentProviderClient contentProviderClient;
|
||||
private Account account;
|
||||
|
||||
@Deprecated
|
||||
public FileDataStorageManager(Account account, ContentResolver contentResolver) {
|
||||
this.contentProviderClient = null;
|
||||
this.contentResolver = contentResolver;
|
||||
this.account = account;
|
||||
}
|
||||
private User user;
|
||||
|
||||
public FileDataStorageManager(User user, ContentResolver contentResolver) {
|
||||
this(user.toPlatformAccount(), contentResolver);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FileDataStorageManager(Account account, ContentProviderClient contentProviderClient) {
|
||||
this.contentProviderClient = contentProviderClient;
|
||||
this.contentResolver = null;
|
||||
this.account = account;
|
||||
this.contentProviderClient = null;
|
||||
this.contentResolver = contentResolver;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
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()) {
|
||||
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_FOR_DATA, ocFile.getLastSyncDateForData());
|
||||
cv.put(ProviderTableMeta.FILE_ETAG, ocFile.getEtag());
|
||||
|
@ -403,7 +393,7 @@ public class FileDataStorageManager {
|
|||
// prepare operations to remove files in the given folder
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + " = ?";
|
||||
String[] whereArgs = new String[2];
|
||||
whereArgs[0] = account.name;
|
||||
whereArgs[0] = user.getAccountName();
|
||||
for (OCFile ocFile : filesToRemove) {
|
||||
if (ocFile.getParentId() == folder.getFileId()) {
|
||||
whereArgs[1] = ocFile.getRemotePath();
|
||||
|
@ -412,7 +402,7 @@ public class FileDataStorageManager {
|
|||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, ocFile.getFileId()))
|
||||
.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()) {
|
||||
removeLocalFolder(localFolder);
|
||||
}
|
||||
|
@ -490,7 +480,7 @@ public class FileDataStorageManager {
|
|||
cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId());
|
||||
cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath());
|
||||
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_FOR_DATA, folder.getLastSyncDateForData());
|
||||
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_DECRYPTED, file.getDecryptedRemotePath());
|
||||
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_FOR_DATA, file.getLastSyncDateForData());
|
||||
cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
|
||||
|
@ -563,7 +553,7 @@ public class FileDataStorageManager {
|
|||
// ""+file.getFileId());
|
||||
Uri file_uri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, ocFile.getFileId());
|
||||
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;
|
||||
if (getContentProviderClient() != null) {
|
||||
try {
|
||||
|
@ -620,7 +610,7 @@ public class FileDataStorageManager {
|
|||
Uri folderUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, String.valueOf(folder.getFileId()));
|
||||
// for recursive deletion
|
||||
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;
|
||||
if (getContentProviderClient() != null) {
|
||||
try {
|
||||
|
@ -636,7 +626,7 @@ public class FileDataStorageManager {
|
|||
|
||||
private boolean removeLocalFolder(OCFile folder) {
|
||||
boolean success = true;
|
||||
String localFolderPath = FileStorageUtils.getDefaultSavePathFor(account.name, folder);
|
||||
String localFolderPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), folder);
|
||||
File localFolder = new File(localFolderPath);
|
||||
|
||||
if (localFolder.exists()) {
|
||||
|
@ -705,7 +695,7 @@ public class FileDataStorageManager {
|
|||
ProviderTableMeta.CONTENT_URI,
|
||||
null,
|
||||
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 "
|
||||
);
|
||||
} catch (RemoteException e) {
|
||||
|
@ -717,14 +707,14 @@ public class FileDataStorageManager {
|
|||
ProviderTableMeta.CONTENT_URI,
|
||||
null,
|
||||
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 "
|
||||
);
|
||||
}
|
||||
|
||||
/// 2. prepare a batch of update operations to change all the descendants
|
||||
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> newPathsToTriggerMediaScan = new ArrayList<>();
|
||||
|
||||
|
@ -780,7 +770,7 @@ public class FileDataStorageManager {
|
|||
}
|
||||
|
||||
/// 4. move in local file system
|
||||
String originalLocalPath = FileStorageUtils.getDefaultSavePathFor(account.name, ocFile);
|
||||
String originalLocalPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile);
|
||||
String targetLocalPath = defaultSavePath + targetPath;
|
||||
File localFile = new File(originalLocalPath);
|
||||
boolean renamed = false;
|
||||
|
@ -812,10 +802,10 @@ public class FileDataStorageManager {
|
|||
|
||||
public void copyLocalFile(OCFile ocFile, String targetPath) {
|
||||
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);
|
||||
boolean copied = false;
|
||||
String defaultSavePath = FileStorageUtils.getSavePath(account.name);
|
||||
String defaultSavePath = FileStorageUtils.getSavePath(user.getAccountName());
|
||||
if (localFile.exists()) {
|
||||
File targetFile = new File(defaultSavePath + targetPath);
|
||||
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)
|
||||
throws RemoteException, OperationApplicationException {
|
||||
Cursor cursor;
|
||||
|
@ -962,14 +956,14 @@ public class FileDataStorageManager {
|
|||
key + AND
|
||||
+ ProviderTableMeta.FILE_ACCOUNT_OWNER
|
||||
+ "=?",
|
||||
new String[]{value, account.name}, null);
|
||||
new String[]{value, user.getAccountName()}, null);
|
||||
} else {
|
||||
try {
|
||||
cursor = getContentProviderClient().query(
|
||||
ProviderTableMeta.CONTENT_URI,
|
||||
null,
|
||||
key + AND + ProviderTableMeta.FILE_ACCOUNT_OWNER
|
||||
+ "=?", new String[]{value, account.name},
|
||||
+ "=?", new String[]{value, user.getAccountName()},
|
||||
null);
|
||||
} catch (RemoteException 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;
|
||||
// with the current update of SynchronizeFolderOperation, this won't be
|
||||
// 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()) {
|
||||
ocFile.setStoragePath(file.getAbsolutePath());
|
||||
ocFile.setLastSyncDateForData(file.lastModified());
|
||||
|
@ -1160,7 +1154,7 @@ public class FileDataStorageManager {
|
|||
null,
|
||||
key + AND
|
||||
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
|
||||
new String[]{value, account.name},
|
||||
new String[]{value, user.getAccountName()},
|
||||
null
|
||||
);
|
||||
} else {
|
||||
|
@ -1169,7 +1163,7 @@ public class FileDataStorageManager {
|
|||
ProviderTableMeta.CONTENT_URI_SHARE,
|
||||
null,
|
||||
key + AND + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
|
||||
new String[]{value, account.name},
|
||||
new String[]{value, user.getAccountName()},
|
||||
null
|
||||
);
|
||||
} catch (RemoteException e) {
|
||||
|
@ -1205,21 +1199,21 @@ public class FileDataStorageManager {
|
|||
selectionArgs = new String[]{
|
||||
path,
|
||||
Integer.toString(type.getValue()),
|
||||
account.name
|
||||
user.getAccountName()
|
||||
};
|
||||
} else {
|
||||
if (shareWith == null) {
|
||||
selectionArgs = new String[]{
|
||||
path,
|
||||
Integer.toString(type.getValue()),
|
||||
account.name,
|
||||
user.getAccountName(),
|
||||
""
|
||||
};
|
||||
} else {
|
||||
selectionArgs = new String[]{
|
||||
path,
|
||||
Integer.toString(type.getValue()),
|
||||
account.name,
|
||||
user.getAccountName(),
|
||||
shareWith
|
||||
};
|
||||
}
|
||||
|
@ -1274,7 +1268,7 @@ public class FileDataStorageManager {
|
|||
contentValues.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
|
||||
contentValues.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
|
||||
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_NOTE, share.getNote());
|
||||
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_WITH_SHAREE, Boolean.FALSE);
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgs = new String[]{account.name};
|
||||
String[] whereArgs = new String[]{user.getAccountName()};
|
||||
|
||||
if (getContentResolver() != null) {
|
||||
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_WITH_SHAREE, Boolean.FALSE);
|
||||
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) {
|
||||
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_WITH_SHAREE, Boolean.FALSE);
|
||||
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) {
|
||||
getContentResolver().update(ProviderTableMeta.CONTENT_URI, contentValues, where, whereArgs);
|
||||
|
@ -1368,7 +1362,7 @@ public class FileDataStorageManager {
|
|||
@VisibleForTesting
|
||||
public void cleanShares() {
|
||||
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgs = new String[]{account.name};
|
||||
String[] whereArgs = new String[]{user.getAccountName()};
|
||||
|
||||
if (getContentResolver() != null) {
|
||||
getContentResolver().delete(ProviderTableMeta.CONTENT_URI_SHARE, where, whereArgs);
|
||||
|
@ -1451,7 +1445,7 @@ public class FileDataStorageManager {
|
|||
if (!file.isFolder()) {
|
||||
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_FOR_DATA,
|
||||
|
@ -1512,7 +1506,7 @@ public class FileDataStorageManager {
|
|||
Uri contentUriShare = ProviderTableMeta.CONTENT_URI_SHARE;
|
||||
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND +
|
||||
ProviderTableMeta._ID + " = ?";
|
||||
String[] whereArgs = {account.name, Long.toString(share.getId())};
|
||||
String[] whereArgs = {user.getAccountName(), Long.toString(share.getId())};
|
||||
|
||||
if (getContentProviderClient() != null) {
|
||||
try {
|
||||
|
@ -1635,7 +1629,7 @@ public class FileDataStorageManager {
|
|||
if (folder != null) {
|
||||
String where = ProviderTableMeta.OCSHARES_PATH + AND
|
||||
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgs = new String[]{"", account.name};
|
||||
String[] whereArgs = new String[]{"", user.getAccountName()};
|
||||
|
||||
List<OCFile> files = getFolderContent(folder, false);
|
||||
|
||||
|
@ -1656,7 +1650,7 @@ public class FileDataStorageManager {
|
|||
|
||||
String where = ProviderTableMeta.OCSHARES_PATH + AND
|
||||
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " = ?";
|
||||
String[] whereArgs = new String[]{filePath, account.name};
|
||||
String[] whereArgs = new String[]{filePath, user.getAccountName()};
|
||||
|
||||
preparedOperations.add(
|
||||
ContentProviderOperation
|
||||
|
@ -1889,7 +1883,7 @@ public class FileDataStorageManager {
|
|||
ProviderTableMeta.CONTENT_URI_FILE,
|
||||
projection,
|
||||
whereForDescencentsInConflict,
|
||||
new String[]{account.name, parentPath + "%"},
|
||||
new String[]{user.getAccountName(), parentPath + "%"},
|
||||
null
|
||||
);
|
||||
} else {
|
||||
|
@ -1898,7 +1892,7 @@ public class FileDataStorageManager {
|
|||
ProviderTableMeta.CONTENT_URI_FILE,
|
||||
projection,
|
||||
whereForDescencentsInConflict,
|
||||
new String[]{account.name, parentPath + "%"},
|
||||
new String[]{user.getAccountName(), parentPath + "%"},
|
||||
null
|
||||
);
|
||||
} catch (RemoteException e) {
|
||||
|
@ -1914,7 +1908,7 @@ public class FileDataStorageManager {
|
|||
cv,
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + AND +
|
||||
ProviderTableMeta.FILE_PATH + "=?",
|
||||
new String[]{account.name, parentPath}
|
||||
new String[]{user.getAccountName(), parentPath}
|
||||
);
|
||||
} else {
|
||||
try {
|
||||
|
@ -1923,7 +1917,7 @@ public class FileDataStorageManager {
|
|||
cv,
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + AND +
|
||||
ProviderTableMeta.FILE_PATH + "=?"
|
||||
, new String[]{account.name, parentPath}
|
||||
, new String[]{user.getAccountName(), parentPath}
|
||||
);
|
||||
} catch (RemoteException 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) {
|
||||
// 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) {
|
||||
getContentResolver().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES, contentValues,
|
||||
ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?",
|
||||
new String[]{account.name});
|
||||
new String[]{user.getAccountName()});
|
||||
} else {
|
||||
try {
|
||||
getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES,
|
||||
contentValues, ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?",
|
||||
new String[]{account.name});
|
||||
new String[]{user.getAccountName()});
|
||||
} catch (RemoteException 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()
|
||||
.get(1));
|
||||
capability.setId(new_id);
|
||||
capability.setAccountName(account.name);
|
||||
capability.setAccountName(user.getAccountName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2341,7 +2335,7 @@ public class FileDataStorageManager {
|
|||
public void deleteAllFiles() {
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "= ? AND " +
|
||||
ProviderTableMeta.FILE_PATH + "= ?";
|
||||
String[] whereArgs = new String[]{account.name, OCFile.ROOT_PATH};
|
||||
String[] whereArgs = new String[]{user.getAccountName(), OCFile.ROOT_PATH};
|
||||
|
||||
if (getContentResolver() != null) {
|
||||
getContentResolver().delete(ProviderTableMeta.CONTENT_URI_DIR, where, whereArgs);
|
||||
|
@ -2349,14 +2343,14 @@ public class FileDataStorageManager {
|
|||
try {
|
||||
getContentProviderClient().delete(ProviderTableMeta.CONTENT_URI_DIR, where, whereArgs);
|
||||
} 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() {
|
||||
String selection = ProviderTableMeta.FILE_ACCOUNT_OWNER + "= ? ";
|
||||
String[] selectionArgs = new String[]{account.name};
|
||||
String[] selectionArgs = new String[]{user.getAccountName()};
|
||||
|
||||
List<OCFile> folderContent = new ArrayList<>();
|
||||
|
||||
|
@ -2410,7 +2404,8 @@ public class FileDataStorageManager {
|
|||
return this.contentProviderClient;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Account getAccount() {
|
||||
return this.account;
|
||||
return this.user.toPlatformAccount();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import android.util.Pair;
|
|||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.files.downloader.DownloadTask;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
|
@ -104,7 +105,7 @@ public class FileDownloader extends Service
|
|||
private ServiceHandler mServiceHandler;
|
||||
private IBinder mBinder;
|
||||
private OwnCloudClient mDownloadClient;
|
||||
private Account mCurrentAccount;
|
||||
private Optional<User> currentUser;
|
||||
private FileDataStorageManager mStorageManager;
|
||||
|
||||
private IndexedForest<DownloadFileOperation> mPendingDownloads = new IndexedForest<>();
|
||||
|
@ -210,7 +211,7 @@ public class FileDownloader extends Service
|
|||
conflictUploadId = intent.getLongExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, -1);
|
||||
AbstractList<String> requestedDownloads = new Vector<String>();
|
||||
try {
|
||||
DownloadFileOperation newDownload = new DownloadFileOperation(user.toPlatformAccount(),
|
||||
DownloadFileOperation newDownload = new DownloadFileOperation(user,
|
||||
file,
|
||||
behaviour,
|
||||
activityName,
|
||||
|
@ -303,9 +304,9 @@ public class FileDownloader extends Service
|
|||
if (download != null) {
|
||||
download.cancel();
|
||||
} else {
|
||||
if (mCurrentDownload != null && mCurrentAccount != null &&
|
||||
if (mCurrentDownload != null && currentUser.isPresent() &&
|
||||
mCurrentDownload.getRemotePath().startsWith(file.getRemotePath()) &&
|
||||
account.name.equals(mCurrentAccount.name)) {
|
||||
account.name.equals(currentUser.get().getAccountName())) {
|
||||
mCurrentDownload.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -456,18 +457,16 @@ public class FileDownloader extends Service
|
|||
RemoteOperationResult downloadResult = null;
|
||||
try {
|
||||
/// prepare client object to send the request to the ownCloud server
|
||||
if (mCurrentAccount == null ||
|
||||
!mCurrentAccount.equals(mCurrentDownload.getAccount())) {
|
||||
mCurrentAccount = mCurrentDownload.getAccount();
|
||||
mStorageManager = new FileDataStorageManager(
|
||||
mCurrentAccount,
|
||||
getContentResolver()
|
||||
);
|
||||
Account currentDownloadAccount = mCurrentDownload.getAccount();
|
||||
Optional<User> currentDownloadUser = accountManager.getUser(currentDownloadAccount.name);
|
||||
if (!currentUser.equals(currentDownloadUser)) {
|
||||
currentUser = currentDownloadUser;
|
||||
mStorageManager = new FileDataStorageManager(currentUser.get(), getContentResolver());
|
||||
} // else, reuse storage manager from previous operation
|
||||
|
||||
// always get client from client manager, to get fresh credentials in case
|
||||
// of update
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(mCurrentAccount, this);
|
||||
OwnCloudAccount ocAccount = currentDownloadUser.get().toOwnCloudAccount();
|
||||
mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, this);
|
||||
|
||||
|
@ -484,7 +483,7 @@ public class FileDownloader extends Service
|
|||
|
||||
} finally {
|
||||
Pair<DownloadFileOperation, String> removeResult = mPendingDownloads.removePayload(
|
||||
mCurrentAccount.name, mCurrentDownload.getRemotePath());
|
||||
currentUser.get().getAccountName(), mCurrentDownload.getRemotePath());
|
||||
|
||||
if (downloadResult == null) {
|
||||
downloadResult = new RemoteOperationResult(new RuntimeException("Error downloading…"));
|
||||
|
|
|
@ -491,7 +491,7 @@ public class FileUploader extends Service
|
|||
onWifiOnly,
|
||||
whileChargingOnly,
|
||||
disableRetries,
|
||||
new FileDataStorageManager(user.toPlatformAccount(), getContentResolver())
|
||||
new FileDataStorageManager(user, getContentResolver())
|
||||
);
|
||||
newUpload.setCreatedBy(createdBy);
|
||||
if (isCreateRemoteFolder) {
|
||||
|
@ -541,7 +541,7 @@ public class FileUploader extends Service
|
|||
onWifiOnly,
|
||||
whileChargingOnly,
|
||||
true,
|
||||
new FileDataStorageManager(user.toPlatformAccount(), getContentResolver())
|
||||
new FileDataStorageManager(user, getContentResolver())
|
||||
);
|
||||
|
||||
newUpload.addDataTransferProgressListener(this);
|
||||
|
@ -623,7 +623,7 @@ public class FileUploader extends Service
|
|||
/// prepare client object to send the request to the ownCloud server
|
||||
if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentUpload.getAccount())) {
|
||||
mCurrentAccount = mCurrentUpload.getAccount();
|
||||
mStorageManager = new FileDataStorageManager(mCurrentAccount, getContentResolver());
|
||||
mStorageManager = new FileDataStorageManager(getCurrentUser().get(), getContentResolver());
|
||||
} // else, reuse storage manager from previous operation
|
||||
|
||||
// always get client from client manager, to get fresh credentials in case of update
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.content.Context;
|
|||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.datamodel.DecryptedFolderMetadata;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
@ -52,7 +53,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
public class DownloadFileOperation extends RemoteOperation {
|
||||
private static final String TAG = DownloadFileOperation.class.getSimpleName();
|
||||
|
||||
private Account account;
|
||||
private User user;
|
||||
private OCFile file;
|
||||
private String behaviour;
|
||||
private String etag = "";
|
||||
|
@ -66,10 +67,10 @@ public class DownloadFileOperation extends RemoteOperation {
|
|||
|
||||
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) {
|
||||
if (account == null) {
|
||||
throw new IllegalArgumentException("Illegal null account in DownloadFileOperation " +
|
||||
if (user == null) {
|
||||
throw new IllegalArgumentException("Illegal null user in DownloadFileOperation " +
|
||||
"creation");
|
||||
}
|
||||
if (file == null) {
|
||||
|
@ -77,7 +78,7 @@ public class DownloadFileOperation extends RemoteOperation {
|
|||
"creation");
|
||||
}
|
||||
|
||||
this.account = account;
|
||||
this.user = user;
|
||||
this.file = file;
|
||||
this.behaviour = behaviour;
|
||||
this.activityName = activityName;
|
||||
|
@ -85,8 +86,8 @@ public class DownloadFileOperation extends RemoteOperation {
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
public DownloadFileOperation(Account account, OCFile file, Context context) {
|
||||
this(account, file, null, null, null, context);
|
||||
public DownloadFileOperation(User user, OCFile file, Context context) {
|
||||
this(user, file, null, null, null, context);
|
||||
}
|
||||
|
||||
public String getSavePath() {
|
||||
|
@ -100,15 +101,15 @@ public class DownloadFileOperation extends RemoteOperation {
|
|||
return path.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
return FileStorageUtils.getDefaultSavePathFor(account.name, file);
|
||||
return FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), file);
|
||||
}
|
||||
|
||||
public String getTmpPath() {
|
||||
return FileStorageUtils.getTemporalPath(account.name) + file.getRemotePath();
|
||||
return FileStorageUtils.getTemporalPath(user.getAccountName()) + file.getRemotePath();
|
||||
}
|
||||
|
||||
public String getTmpFolder() {
|
||||
return FileStorageUtils.getTemporalPath(account.name);
|
||||
return FileStorageUtils.getTemporalPath(user.getAccountName());
|
||||
}
|
||||
|
||||
public String getRemotePath() {
|
||||
|
@ -177,11 +178,14 @@ public class DownloadFileOperation extends RemoteOperation {
|
|||
|
||||
// decrypt file
|
||||
if (file.isEncrypted()) {
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account, context.getContentResolver());
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user, context.getContentResolver());
|
||||
|
||||
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) {
|
||||
return new RemoteOperationResult(RemoteOperationResult.ResultCode.METADATA_NOT_FOUND);
|
||||
|
@ -235,8 +239,13 @@ public class DownloadFileOperation extends RemoteOperation {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Account getAccount() {
|
||||
return this.account;
|
||||
return this.user.toPlatformAccount();
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public OCFile getFile() {
|
||||
|
|
|
@ -198,6 +198,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|||
|
||||
OCFile ocFile = document.getFile();
|
||||
Account account = document.getAccount();
|
||||
User user = accountManager.getUser(account.name).orElseGet(accountManager::getAnonymousUser);
|
||||
|
||||
int accessMode = ParcelFileDescriptor.parseMode(mode);
|
||||
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
|
||||
Log_OC.w(TAG, "Conflict found!");
|
||||
} else {
|
||||
DownloadFileOperation downloadFileOperation = new DownloadFileOperation(account, ocFile, context);
|
||||
DownloadFileOperation downloadFileOperation = new DownloadFileOperation(user, ocFile, context);
|
||||
RemoteOperationResult result = downloadFileOperation.execute(document.getClient());
|
||||
if (!result.isSuccess()) {
|
||||
if (ocFile.isDown()) {
|
||||
|
@ -674,9 +675,9 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|||
|
||||
ContentResolver contentResolver = getContext().getContentResolver();
|
||||
|
||||
for (Account account : accountManager.getAccounts()) {
|
||||
final FileDataStorageManager storageManager = new FileDataStorageManager(account, contentResolver);
|
||||
rootIdToStorageManager.put(account.hashCode(), storageManager);
|
||||
for (User user : accountManager.getAllUsers()) {
|
||||
final FileDataStorageManager storageManager = new FileDataStorageManager(user, contentResolver);
|
||||
rootIdToStorageManager.put(user.hashCode(), storageManager);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
|
|||
|
||||
this.setAccount(account);
|
||||
this.setContentProviderClient(providerClient);
|
||||
this.setStorageManager(new FileDataStorageManager(account, providerClient));
|
||||
this.setStorageManager(new FileDataStorageManager(getUser(), providerClient));
|
||||
|
||||
try {
|
||||
this.initClientForCurrentAccount();
|
||||
|
@ -480,7 +480,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
|
|||
|
||||
/// includes a pending intent in the notification showing a more detailed explanation
|
||||
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> localPaths = new ArrayList<String>();
|
||||
remotePaths.addAll(mForgottenLocalFiles.keySet());
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
|
@ -36,6 +35,7 @@ import android.widget.Button;
|
|||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
@ -65,8 +65,8 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
|
|||
|
||||
private static final String TAG = ErrorsWhileCopyingHandlerActivity.class.getSimpleName();
|
||||
|
||||
public static final String EXTRA_ACCOUNT =
|
||||
ErrorsWhileCopyingHandlerActivity.class.getCanonicalName() + ".EXTRA_ACCOUNT";
|
||||
public static final String EXTRA_USER =
|
||||
ErrorsWhileCopyingHandlerActivity.class.getCanonicalName() + ".EXTRA_ACCOUNT";
|
||||
public static final String EXTRA_LOCAL_PATHS =
|
||||
ErrorsWhileCopyingHandlerActivity.class.getCanonicalName() + ".EXTRA_LOCAL_PATHS";
|
||||
public static final String EXTRA_REMOTE_PATHS =
|
||||
|
@ -74,7 +74,7 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
|
|||
|
||||
private static final String WAIT_DIALOG_TAG = "WAIT_DIALOG";
|
||||
|
||||
protected Account mAccount;
|
||||
protected User user;
|
||||
protected FileDataStorageManager mStorageManager;
|
||||
protected List<String> mLocalPaths;
|
||||
protected List<String> mRemotePaths;
|
||||
|
@ -91,10 +91,10 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
|
|||
|
||||
/// read extra parameters in intent
|
||||
Intent intent = getIntent();
|
||||
mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);
|
||||
user = intent.getParcelableExtra(EXTRA_USER);
|
||||
mRemotePaths = intent.getStringArrayListExtra(EXTRA_REMOTE_PATHS);
|
||||
mLocalPaths = intent.getStringArrayListExtra(EXTRA_LOCAL_PATHS);
|
||||
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
|
||||
mStorageManager = new FileDataStorageManager(user, getContentResolver());
|
||||
mHandler = new Handler();
|
||||
if (mCurrentDialog != null) {
|
||||
mCurrentDialog.dismiss();
|
||||
|
@ -108,7 +108,7 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
|
|||
TextView textView = findViewById(R.id.message);
|
||||
String appName = getString(R.string.app_name);
|
||||
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.setMovementMethod(new ScrollingMovementMethod());
|
||||
|
||||
|
@ -230,7 +230,7 @@ public class ErrorsWhileCopyingHandlerActivity extends AppCompatActivity implem
|
|||
while (!mLocalPaths.isEmpty()) {
|
||||
String currentPath = mLocalPaths.get(0);
|
||||
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);
|
||||
|
||||
if (expectedFile.equals(currentFile) || currentFile.renameTo(expectedFile)) {
|
||||
|
|
|
@ -695,8 +695,7 @@ public class SettingsActivity extends ThemedPreferenceActivity
|
|||
if (storagePath.equals(newPath)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
StorageMigration storageMigration = new StorageMigration(this, storagePath, newPath);
|
||||
StorageMigration storageMigration = new StorageMigration(this, user, storagePath, newPath);
|
||||
storageMigration.setStorageMigrationProgressListener(this);
|
||||
storageMigration.migrate();
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import android.content.DialogInterface.OnClickListener;
|
|||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
|
@ -48,6 +49,7 @@ public class StorageMigration {
|
|||
private static final String TAG = StorageMigration.class.getName();
|
||||
|
||||
private Context mContext;
|
||||
private User user;
|
||||
private String mSourceStoragePath;
|
||||
private String mTargetStoragePath;
|
||||
|
||||
|
@ -58,8 +60,9 @@ public class StorageMigration {
|
|||
void onCancelMigration();
|
||||
}
|
||||
|
||||
public StorageMigration(Context context, String sourcePath, String targetPath) {
|
||||
public StorageMigration(Context context, User user, String sourcePath, String targetPath) {
|
||||
mContext = context;
|
||||
this.user = user;
|
||||
mSourceStoragePath = sourcePath;
|
||||
mTargetStoragePath = targetPath;
|
||||
}
|
||||
|
@ -76,6 +79,7 @@ public class StorageMigration {
|
|||
progressDialog.show();
|
||||
new FileMigrationTask(
|
||||
mContext,
|
||||
user,
|
||||
mSourceStoragePath,
|
||||
mTargetStoragePath,
|
||||
progressDialog,
|
||||
|
@ -118,6 +122,7 @@ public class StorageMigration {
|
|||
progressDialog.show();
|
||||
new StoragePathSwitchTask(
|
||||
mContext,
|
||||
user,
|
||||
mSourceStoragePath,
|
||||
mTargetStoragePath,
|
||||
progressDialog,
|
||||
|
@ -134,6 +139,7 @@ public class StorageMigration {
|
|||
progressDialog.show();
|
||||
new FileMigrationTask(
|
||||
mContext,
|
||||
user,
|
||||
mSourceStoragePath,
|
||||
mTargetStoragePath,
|
||||
progressDialog,
|
||||
|
@ -167,6 +173,7 @@ public class StorageMigration {
|
|||
protected String mStorageSource;
|
||||
protected String mStorageTarget;
|
||||
protected Context mContext;
|
||||
protected User user;
|
||||
protected ProgressDialog mProgressDialog;
|
||||
protected StorageMigrationProgressListener mListener;
|
||||
|
||||
|
@ -174,11 +181,13 @@ public class StorageMigration {
|
|||
protected Account[] mOcAccounts;
|
||||
|
||||
public FileMigrationTaskBase(Context context,
|
||||
User user,
|
||||
String source,
|
||||
String target,
|
||||
ProgressDialog progressDialog,
|
||||
StorageMigrationProgressListener listener) throws SecurityException {
|
||||
mContext = context;
|
||||
this.user = user;
|
||||
mStorageSource = source;
|
||||
mStorageTarget = target;
|
||||
mProgressDialog = progressDialog;
|
||||
|
@ -290,11 +299,12 @@ public class StorageMigration {
|
|||
static private class StoragePathSwitchTask extends FileMigrationTaskBase {
|
||||
|
||||
public StoragePathSwitchTask(Context context,
|
||||
User user,
|
||||
String source,
|
||||
String target,
|
||||
ProgressDialog progressDialog,
|
||||
StorageMigrationProgressListener listener) {
|
||||
super(context, source, target, progressDialog, listener);
|
||||
super(context, user, source, target, progressDialog, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -337,11 +347,12 @@ public class StorageMigration {
|
|||
}
|
||||
|
||||
public FileMigrationTask(Context context,
|
||||
User user,
|
||||
String source,
|
||||
String target,
|
||||
ProgressDialog progressDialog,
|
||||
StorageMigrationProgressListener listener) {
|
||||
super(context, source, target, progressDialog, listener);
|
||||
super(context, user, source, target, progressDialog, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -436,8 +447,7 @@ public class StorageMigration {
|
|||
}
|
||||
|
||||
private void updateIndex(Context context) throws MigrationException {
|
||||
final Account nullAccount = null;
|
||||
FileDataStorageManager manager = new FileDataStorageManager(nullAccount, context.getContentResolver());
|
||||
FileDataStorageManager manager = new FileDataStorageManager(user, context.getContentResolver());
|
||||
|
||||
try {
|
||||
manager.migrateStoredFiles(mStorageSource, mStorageTarget);
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
*/
|
||||
package com.owncloud.android.utils.theme;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
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 static OCCapability getCapability(Context context) {
|
||||
return getCapability(null, context);
|
||||
}
|
||||
|
||||
private static OCCapability getCapability(Account acc, Context context) {
|
||||
Account account = null;
|
||||
|
||||
if (acc != null) {
|
||||
account = acc;
|
||||
} else if (context != null) {
|
||||
User user = null;
|
||||
if (context != null) {
|
||||
// TODO: refactor when dark theme work is completed
|
||||
account = UserAccountManagerImpl.fromContext(context).getCurrentAccount();
|
||||
user = UserAccountManagerImpl.fromContext(context).getUser();
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
|
||||
return storageManager.getCapability(account.name);
|
||||
if (user != null) {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(user, context.getContentResolver());
|
||||
return storageManager.getCapability(user.getAccountName());
|
||||
} else {
|
||||
return new OCCapability();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import android.graphics.Color;
|
|||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.lib.resources.status.OCCapability;
|
||||
|
@ -290,18 +291,18 @@ public final class ThemeColorUtils {
|
|||
}
|
||||
|
||||
private static OCCapability getCapability(Account acc, Context context) {
|
||||
Account account = null;
|
||||
Optional<User> user = Optional.empty();
|
||||
|
||||
if (acc != null) {
|
||||
account = acc;
|
||||
user = UserAccountManagerImpl.fromContext(context).getUser(acc.name);
|
||||
} else if (context != null) {
|
||||
// TODO: refactor when dark theme work is completed
|
||||
account = UserAccountManagerImpl.fromContext(context).getCurrentAccount();
|
||||
user = Optional.of(UserAccountManagerImpl.fromContext(context).getUser());
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
|
||||
return storageManager.getCapability(account.name);
|
||||
if (user.isPresent()) {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.get(), context.getContentResolver());
|
||||
return storageManager.getCapability(user.get().getAccountName());
|
||||
} else {
|
||||
return new OCCapability();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue