Merge pull request #8290 from grote/saf-optimization

Optimize writing out files to Nextcloud via SAF
This commit is contained in:
Andy Scherzinger 2021-05-29 20:02:16 +02:00 committed by GitHub
commit be29f9aa9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -90,9 +90,11 @@ import java.util.concurrent.TimeUnit;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import static android.os.ParcelFileDescriptor.MODE_READ_ONLY;
import static android.os.ParcelFileDescriptor.MODE_WRITE_ONLY;
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR; import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH; import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
import static com.owncloud.android.files.services.FileUploader.LOCAL_BEHAVIOUR_MOVE; import static com.owncloud.android.files.services.FileUploader.LOCAL_BEHAVIOUR_DELETE;
public class DocumentsStorageProvider extends DocumentsProvider { public class DocumentsStorageProvider extends DocumentsProvider {
@ -192,7 +194,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
OCFile ocFile = document.getFile(); OCFile ocFile = document.getFile();
Account account = document.getAccount(); Account account = document.getAccount();
boolean needsDownload = !ocFile.isDown() || hasServerChange(document); int accessMode = ParcelFileDescriptor.parseMode(mode);
boolean writeOnly = (accessMode & MODE_WRITE_ONLY) != 0;
boolean wasNotYetStored = ocFile.getStoragePath() == null;
boolean needsDownload = (!writeOnly || wasNotYetStored) && (!ocFile.isDown() || hasServerChange(document));
if (needsDownload) { if (needsDownload) {
if (ocFile.getLocalModificationTimestamp() > ocFile.getLastSyncDateForData()) { if (ocFile.getLocalModificationTimestamp() > ocFile.getLastSyncDateForData()) {
// 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
@ -210,8 +215,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
File file = new File(ocFile.getStoragePath()); File file = new File(ocFile.getStoragePath());
int accessMode = ParcelFileDescriptor.parseMode(mode); if (accessMode != MODE_READ_ONLY) {
if (accessMode != ParcelFileDescriptor.MODE_READ_ONLY) {
// The calling thread is not guaranteed to have a Looper, so we can't block it with the OnCloseListener. // The calling thread is not guaranteed to have a Looper, so we can't block it with the OnCloseListener.
// Thus, we are unable to do a synchronous upload and have to start an asynchronous one. // Thus, we are unable to do a synchronous upload and have to start an asynchronous one.
Handler handler = new Handler(context.getMainLooper()); Handler handler = new Handler(context.getMainLooper());
@ -229,7 +233,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
context, context,
account, account,
ocFile, ocFile,
LOCAL_BEHAVIOUR_MOVE, LOCAL_BEHAVIOUR_DELETE,
NameCollisionPolicy.OVERWRITE, NameCollisionPolicy.OVERWRITE,
false); false);
} else { // error, no upload needed } else { // error, no upload needed