From dbf87c9551357d23542a00556ccee9f9fbd42fdc Mon Sep 17 00:00:00 2001 From: quantum-byte Date: Tue, 14 Mar 2023 12:49:49 +0100 Subject: [PATCH 1/2] Implemented a fix to support non "primary" external storage document provider uris like "home:" for the "documents" folder --- .../lolhens/resticui/util/ASFUriHelper.java | 25 ++++++++++++++++++- build.gradle | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/lolhens/resticui/util/ASFUriHelper.java b/app/src/main/java/de/lolhens/resticui/util/ASFUriHelper.java index d90fcc1..0edfee2 100644 --- a/app/src/main/java/de/lolhens/resticui/util/ASFUriHelper.java +++ b/app/src/main/java/de/lolhens/resticui/util/ASFUriHelper.java @@ -7,9 +7,17 @@ import android.os.Environment; import android.provider.DocumentsContract; import android.provider.MediaStore; +import androidx.documentfile.provider.DocumentFile; + +import java.io.File; +import java.util.Arrays; +import java.util.List; // https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper public class ASFUriHelper { + + private static final List documentUriTypes = Arrays.asList(Environment.DIRECTORY_MUSIC, Environment.DIRECTORY_PODCASTS, Environment.DIRECTORY_RINGTONES, Environment.DIRECTORY_ALARMS, Environment.DIRECTORY_NOTIFICATIONS, Environment.DIRECTORY_PICTURES, Environment.DIRECTORY_MOVIES, Environment.DIRECTORY_DOWNLOADS, Environment.DIRECTORY_DCIM, Environment.DIRECTORY_DOCUMENTS); + public static String getPath(final Context context, final Uri uri) { if (DocumentsContract.isDocumentUri(context, uri)) { // DocumentProvider if (isExternalStorageDocument(uri)) { // ExternalStorageProvider @@ -23,9 +31,24 @@ public static String getPath(final Context context, final Uri uri) { } else { return Environment.getExternalStorageDirectory() + "/"; } + } else { + final DocumentFile documentUriRoot = DocumentFile.fromTreeUri(context, DocumentsContract.buildTreeDocumentUri( + uri.getAuthority(), type + ":")); + if (documentUriRoot != null && documentUriRoot.exists() && ASFUriHelper.documentUriTypes.contains(documentUriRoot.getName())) { + final String basePath = Environment.getExternalStoragePublicDirectory(documentUriRoot.getName()).getAbsolutePath(); + final String fullPath; + if (split.length > 1) + fullPath = basePath + "/" + split[1]; + else { + fullPath = basePath + "/"; + } + if (new File(fullPath).exists()) { + return fullPath; + } + } + } - // TODO handle non-primary volumes } else if (isDownloadsDocument(uri)) { // DownloadsProvider try { final Uri contentUri = ContentUris.withAppendedId( diff --git a/build.gradle b/build.gradle index 2bb4f3c..0113a22 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.4.2' + classpath 'com.android.tools.build:gradle:7.4.0-beta02' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong From 2066bb48223ad28a037ad71858cd5ff5a16303ee Mon Sep 17 00:00:00 2001 From: Pierre Kisters <1524059+lhns@users.noreply.github.com> Date: Tue, 14 Mar 2023 19:34:41 +0100 Subject: [PATCH 2/2] keep com.android.tools.build:gradle at v7.4.2 Android Studio complained --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 0113a22..c23431c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.4.0-beta02' + classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong @@ -23,4 +23,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} \ No newline at end of file +}