From b78ac7d2e9a2a480a927ab9af661bb0857b365df Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 16 Jan 2021 15:46:50 +0100 Subject: [PATCH] Fix strange behaviour when app loses access to saf download folder --- .../java/org/schabi/newpipe/download/DownloadDialog.java | 7 +++++-- .../schabi/newpipe/streams/io/StoredDirectoryHelper.java | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index d3b57631f..72dc2fdde 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -682,12 +682,15 @@ public class DownloadDialog extends DialogFragment throw new RuntimeException("No stream selected"); } - if (!askForSavePath && (mainStorage == null || (mainStorage.isDirect() - == NewPipeSettings.useStorageAccessFramework(context)))) { + if (!askForSavePath + && (mainStorage == null + || mainStorage.isDirect() == NewPipeSettings.useStorageAccessFramework(context) + || mainStorage.isInvalidSafStorage())) { // Pick new download folder if one of: // - Download folder is not set // - Download folder uses SAF while SAF is disabled // - Download folder doesn't use SAF while SAF is enabled + // - Download folder uses SAF but the user manually revoked access to it Toast.makeText(context, getString(R.string.no_dir_yet), Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/org/schabi/newpipe/streams/io/StoredDirectoryHelper.java b/app/src/main/java/org/schabi/newpipe/streams/io/StoredDirectoryHelper.java index 5bd03e624..feca89f02 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/io/StoredDirectoryHelper.java +++ b/app/src/main/java/org/schabi/newpipe/streams/io/StoredDirectoryHelper.java @@ -223,6 +223,15 @@ public class StoredDirectoryHelper { return docTree == null ? ioTree.canWrite() : docTree.canWrite(); } + /** + * @return {@code false} if the storage is direct, or the SAF storage is valid; {@code true} if + * SAF access to this SAF storage is denied (e.g. the user clicked on {@code Android settings -> + * Apps & notifications -> NewPipe -> Storage & cache -> Clear access}); + */ + public boolean isInvalidSafStorage() { + return docTree != null && docTree.getName() == null; + } + @NonNull @Override public String toString() {