From 68584ba426f025d3ca74f8a7420eb8382c77c3ea Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Mon, 1 Jan 2024 16:10:11 -0700 Subject: [PATCH] music: fix file document path extraction Apparently on Android 14 you need to reassemble the document URI and then extract it's ID to get a path object. Really not sure why. --- .../org/oxycblt/auxio/music/fs/DocumentPathFactory.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/oxycblt/auxio/music/fs/DocumentPathFactory.kt b/app/src/main/java/org/oxycblt/auxio/music/fs/DocumentPathFactory.kt index 7643603c7..5a9ebcfeb 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/fs/DocumentPathFactory.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/fs/DocumentPathFactory.kt @@ -64,7 +64,15 @@ interface DocumentPathFactory { class DocumentPathFactoryImpl @Inject constructor(private val volumeManager: VolumeManager) : DocumentPathFactory { - override fun unpackDocumentUri(uri: Uri) = fromDocumentId(DocumentsContract.getDocumentId(uri)) + override fun unpackDocumentUri(uri: Uri): Path? { + // Abuse the document contract and extract the encoded path from the URI. + // I've seen some implementations that just use getDocumentId. That no longer seems + // to work on Android 14 onwards. But spoofing our own document URI and then decoding + // it does for some reason. + val docUri = DocumentsContract.buildDocumentUri(uri.authority, uri.pathSegments[1]) + val docId = DocumentsContract.getDocumentId(docUri) + return fromDocumentId(docId) + } override fun unpackDocumentTreeUri(uri: Uri): Path? { // Convert the document tree URI into it's relative path form, which can then be