diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt index 508a9979e875..178761ef8475 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt @@ -24,7 +24,6 @@ package com.nextcloud.client.files.downloader import android.accounts.Account import android.accounts.AccountManager import android.accounts.OnAccountsUpdateListener -import android.annotation.SuppressLint import android.app.PendingIntent import android.content.Context import androidx.core.util.component1 @@ -66,7 +65,6 @@ class FileDownloadWorker( companion object { private val TAG = FileDownloadWorker::class.java.simpleName - @SuppressLint("StaticFieldLeak") private var currentDownload: DownloadFileOperation? = null const val FILES_SEPARATOR = "," diff --git a/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java b/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java index d00ab8b6a12b..1aaca764934c 100644 --- a/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java @@ -43,6 +43,7 @@ import java.io.File; import java.io.FileOutputStream; +import java.lang.ref.WeakReference; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -62,7 +63,7 @@ public class DownloadFileOperation extends RemoteOperation { private String packageName; private DownloadType downloadType; - private Context context; + private final WeakReference context; private Set dataTransferListeners = new HashSet<>(); private long modificationTimestamp; private DownloadFileRemoteOperation downloadOperation; @@ -90,7 +91,7 @@ public DownloadFileOperation(User user, this.behaviour = behaviour; this.activityName = activityName; this.packageName = packageName; - this.context = context; + this.context = new WeakReference<>(context); this.downloadType = downloadType; } @@ -203,13 +204,13 @@ protected RemoteOperationResult run(OwnCloudClient client) { // decrypt file if (file.isEncrypted()) { - FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user, context.getContentResolver()); + FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user, context.get().getContentResolver()); OCFile parent = fileDataStorageManager.getFileByPath(file.getParentRemotePath()); DecryptedFolderMetadata metadata = EncryptionUtils.downloadFolderMetadata(parent, client, - context, + context.get(), user); if (metadata == null) { @@ -227,7 +228,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { key, iv, authenticationTag, - new ArbitraryDataProviderImpl(context), + new ArbitraryDataProviderImpl(context.get()), user); try (FileOutputStream fileOutputStream = new FileOutputStream(tmpFile)) { @@ -247,7 +248,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { } else if (downloadType == DownloadType.EXPORT) { new FileExportUtils().exportFile(file.getFileName(), file.getMimeType(), - context.getContentResolver(), + context.get().getContentResolver(), null, tmpFile); if (!tmpFile.delete()) {