|
@@ -4,7 +4,7 @@
|
|
* @author Bartosz Przybylski
|
|
* @author Bartosz Przybylski
|
|
* @author Chris Narkiewicz
|
|
* @author Chris Narkiewicz
|
|
* Copyright (C) 2016 Bartosz Przybylski <bart.p.pl@gmail.com>
|
|
* Copyright (C) 2016 Bartosz Przybylski <bart.p.pl@gmail.com>
|
|
- * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
|
|
|
|
|
|
+ * Copyright (C) 2021 Chris Narkiewicz <hello@ezaquarii.com>
|
|
*
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2,
|
|
* it under the terms of the GNU General Public License version 2,
|
|
@@ -44,7 +44,6 @@ import android.util.Log;
|
|
import android.util.SparseArray;
|
|
import android.util.SparseArray;
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
-import com.nextcloud.client.account.AnonymousUser;
|
|
|
|
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.account.UserAccountManagerImpl;
|
|
import com.nextcloud.client.account.UserAccountManagerImpl;
|
|
@@ -62,7 +61,6 @@ import com.owncloud.android.files.services.NameCollisionPolicy;
|
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
|
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
|
-import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
|
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
import com.owncloud.android.lib.resources.files.CheckEtagRemoteOperation;
|
|
import com.owncloud.android.lib.resources.files.CheckEtagRemoteOperation;
|
|
@@ -93,7 +91,6 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.annotation.VisibleForTesting;
|
|
-import dagger.android.AndroidInjection;
|
|
|
|
|
|
|
|
import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
|
|
import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
|
|
import static android.os.ParcelFileDescriptor.MODE_WRITE_ONLY;
|
|
import static android.os.ParcelFileDescriptor.MODE_WRITE_ONLY;
|
|
@@ -197,8 +194,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
Context context = getNonNullContext();
|
|
Context context = getNonNullContext();
|
|
|
|
|
|
OCFile ocFile = document.getFile();
|
|
OCFile ocFile = document.getFile();
|
|
- Account account = document.getAccount();
|
|
|
|
- User user = accountManager.getUser(account.name).orElseGet(accountManager::getAnonymousUser);
|
|
|
|
|
|
+ User user = document.getUser();
|
|
|
|
|
|
int accessMode = ParcelFileDescriptor.parseMode(mode);
|
|
int accessMode = ParcelFileDescriptor.parseMode(mode);
|
|
boolean writeOnly = (accessMode & MODE_WRITE_ONLY) != 0;
|
|
boolean writeOnly = (accessMode & MODE_WRITE_ONLY) != 0;
|
|
@@ -245,7 +241,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
// upload file with FileUploader service (off main thread)
|
|
// upload file with FileUploader service (off main thread)
|
|
FileUploader.uploadUpdateFile(
|
|
FileUploader.uploadUpdateFile(
|
|
context,
|
|
context,
|
|
- account,
|
|
|
|
|
|
+ user.toPlatformAccount(),
|
|
ocFile,
|
|
ocFile,
|
|
LOCAL_BEHAVIOUR_DELETE,
|
|
LOCAL_BEHAVIOUR_DELETE,
|
|
NameCollisionPolicy.OVERWRITE,
|
|
NameCollisionPolicy.OVERWRITE,
|
|
@@ -266,7 +262,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
Context context = getNonNullContext();
|
|
Context context = getNonNullContext();
|
|
OCFile ocFile = document.getFile();
|
|
OCFile ocFile = document.getFile();
|
|
RemoteOperationResult result = new CheckEtagRemoteOperation(ocFile.getRemotePath(), ocFile.getEtag())
|
|
RemoteOperationResult result = new CheckEtagRemoteOperation(ocFile.getRemotePath(), ocFile.getEtag())
|
|
- .execute(document.getAccount(), context);
|
|
|
|
|
|
+ .execute(document.getUser().toPlatformAccount(), context);
|
|
switch (result.getCode()) {
|
|
switch (result.getCode()) {
|
|
case ETAG_CHANGED:
|
|
case ETAG_CHANGED:
|
|
return true;
|
|
return true;
|
|
@@ -328,7 +324,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
boolean exists = ThumbnailsCacheManager.containsBitmap(ThumbnailsCacheManager.PREFIX_THUMBNAIL
|
|
boolean exists = ThumbnailsCacheManager.containsBitmap(ThumbnailsCacheManager.PREFIX_THUMBNAIL
|
|
+ file.getRemoteId());
|
|
+ file.getRemoteId());
|
|
if (!exists) {
|
|
if (!exists) {
|
|
- ThumbnailsCacheManager.generateThumbnailFromOCFile(file, document.getAccount(), getContext());
|
|
|
|
|
|
+ ThumbnailsCacheManager.generateThumbnailFromOCFile(file, document.getUser(), getContext());
|
|
}
|
|
}
|
|
|
|
|
|
return new AssetFileDescriptor(DiskLruImageCacheFileProvider.getParcelFileDescriptorForOCFile(file),
|
|
return new AssetFileDescriptor(DiskLruImageCacheFileProvider.getParcelFileDescriptorForOCFile(file),
|
|
@@ -592,7 +588,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
OCFile file = document.getStorageManager().getFileByPath(document.getRemotePath());
|
|
OCFile file = document.getStorageManager().getFileByPath(document.getRemotePath());
|
|
RemoteOperationResult result = new RemoveFileOperation(file,
|
|
RemoteOperationResult result = new RemoveFileOperation(file,
|
|
false,
|
|
false,
|
|
- document.getAccount(),
|
|
|
|
|
|
+ document.getUser().toPlatformAccount(),
|
|
true,
|
|
true,
|
|
context,
|
|
context,
|
|
document.getStorageManager())
|
|
document.getStorageManager())
|
|
@@ -643,7 +639,9 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
// The solution below uses paths and is faster by a factor of 2-10 depending on the nesting level of child.
|
|
// The solution below uses paths and is faster by a factor of 2-10 depending on the nesting level of child.
|
|
// So far, the same document with its unique ID can never be in two places at once.
|
|
// So far, the same document with its unique ID can never be in two places at once.
|
|
// If this assumption ever changes, this code would need to be adapted.
|
|
// If this assumption ever changes, this code would need to be adapted.
|
|
- return parentDocument.getAccount() == currentDocument.getAccount() && childPath.startsWith(parentPath);
|
|
|
|
|
|
+ User parentDocumentOwner = parentDocument.getUser();
|
|
|
|
+ User currentDocumentOwner = currentDocument.getUser();
|
|
|
|
+ return parentDocumentOwner.nameEquals(currentDocumentOwner) && childPath.startsWith(parentPath);
|
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
Log.e(TAG, "failed to check for child document", e);
|
|
Log.e(TAG, "failed to check for child document", e);
|
|
@@ -661,7 +659,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
private FileDataStorageManager getStorageManager(String rootId) {
|
|
private FileDataStorageManager getStorageManager(String rootId) {
|
|
for(int i = 0; i < rootIdToStorageManager.size(); i++) {
|
|
for(int i = 0; i < rootIdToStorageManager.size(); i++) {
|
|
FileDataStorageManager storageManager = rootIdToStorageManager.valueAt(i);
|
|
FileDataStorageManager storageManager = rootIdToStorageManager.valueAt(i);
|
|
- if (storageManager.getAccount().name.equals(rootId)) {
|
|
|
|
|
|
+ if (storageManager.getUser().nameEquals(rootId)) {
|
|
return storageManager;
|
|
return storageManager;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -796,13 +794,8 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
return storageManager;
|
|
return storageManager;
|
|
}
|
|
}
|
|
|
|
|
|
- public Account getAccount() {
|
|
|
|
- return getStorageManager().getAccount();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public User getUser() {
|
|
public User getUser() {
|
|
- Account account = getAccount();
|
|
|
|
- return accountManager.getUser(account.name).orElseGet(accountManager::getAnonymousUser);
|
|
|
|
|
|
+ return getStorageManager().getUser();
|
|
}
|
|
}
|
|
|
|
|
|
public OCFile getFile() {
|
|
public OCFile getFile() {
|
|
@@ -815,9 +808,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
|
|
|
|
OwnCloudClient getClient() {
|
|
OwnCloudClient getClient() {
|
|
try {
|
|
try {
|
|
- OwnCloudAccount ocAccount = new OwnCloudAccount(getAccount(), MainApp.getAppContext());
|
|
|
|
|
|
+
|
|
|
|
+ OwnCloudAccount ocAccount = getUser().toOwnCloudAccount();
|
|
return OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, getContext());
|
|
return OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, getContext());
|
|
- } catch (OperationCanceledException | IOException | AuthenticatorException | AccountNotFoundException e) {
|
|
|
|
|
|
+ } catch (OperationCanceledException | IOException | AuthenticatorException e) {
|
|
Log_OC.e(TAG, "Failed to set client", e);
|
|
Log_OC.e(TAG, "Failed to set client", e);
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|