From 8de7a125a894912231d669d61ea6d763f52e61ca Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sat, 17 Jan 2026 08:52:38 -0700 Subject: [PATCH] Revert "musikr.fs: prototype arbitrary saf locations" This reverts commit c730091637a4afe77b0651f7215faa66a7f54b75. --- .../org/oxycblt/auxio/music/MusicSettings.kt | 4 ++-- .../auxio/music/locations/LocationsDialog.kt | 7 ++++--- app/src/main/res/values/strings.xml | 1 - .../main/java/org/oxycblt/musikr/fs/Location.kt | 10 +++------- .../src/main/java/org/oxycblt/musikr/fs/Path.kt | 10 +++------- .../musikr/fs/path/DocumentPathFactory.kt | 17 +++++++++++++++++ .../musikr/fs/path/MediaStorePathInterpreter.kt | 9 --------- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/music/MusicSettings.kt b/app/src/main/java/org/oxycblt/auxio/music/MusicSettings.kt index c5fd7f21a..372630dcb 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/MusicSettings.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/MusicSettings.kt @@ -247,10 +247,10 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont private fun String.toOpenedLocations(): List = splitEscaped { it == ';' } - .mapNotNull { Location.Unopened.from(context, it.toUri()).open(context) } + .mapNotNull { Location.Unopened.from(context, it.toUri())?.open(context) } private fun String.toUnopenedLocations(): List = - splitEscaped { it == ';' }.map { Location.Unopened.from(context, it.toUri()) } + splitEscaped { it == ';' }.mapNotNull { Location.Unopened.from(context, it.toUri()) } private inline fun String.splitEscaped(selector: (Char) -> Boolean): List { val split = mutableListOf() diff --git a/app/src/main/java/org/oxycblt/auxio/music/locations/LocationsDialog.kt b/app/src/main/java/org/oxycblt/auxio/music/locations/LocationsDialog.kt index 2161d7088..775c300c5 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/locations/LocationsDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/locations/LocationsDialog.kt @@ -303,10 +303,11 @@ class LocationsDialog : ViewBindingMaterialDialogFragmentNo app found that can handle this task This folder is not supported - Warning: This folder is managed by a 3rd-party No folders diff --git a/musikr/src/main/java/org/oxycblt/musikr/fs/Location.kt b/musikr/src/main/java/org/oxycblt/musikr/fs/Location.kt index b37cd51d9..083290436 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/fs/Location.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/fs/Location.kt @@ -60,15 +60,11 @@ sealed class Location(val uri: Uri, val path: Path) { } companion object { - fun from(context: Context, uri: Uri): Unopened { - val path = getDocumentTreePath(context, uri) ?: Path(null, Components.root()) - return Unopened(uri, path) - } - - private fun getDocumentTreePath(context: Context, uri: Uri): Path? { + fun from(context: Context, uri: Uri): Unopened? { if (!DocumentsContract.isTreeUri(uri)) return null val documentPathFactory = DocumentPathFactory.from(context) - return documentPathFactory.unpackDocumentTreeUri(uri) + val path = documentPathFactory.unpackDocumentTreeUri(uri) ?: return null + return Unopened(uri, path) } } } diff --git a/musikr/src/main/java/org/oxycblt/musikr/fs/Path.kt b/musikr/src/main/java/org/oxycblt/musikr/fs/Path.kt index 9568ba647..c5cba4ca5 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/fs/Path.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/fs/Path.kt @@ -24,11 +24,10 @@ import java.io.File /** * An abstraction of an android file system path, including the volume and relative path. * - * @param volume The volume that the path is on. Might be null if the Path is not associated with a - * standard SAF document URI. + * @param volume The volume that the path is on. * @param components The components of the path of the file, relative to the root of the volume. */ -data class Path(val volume: Volume?, val components: Components) { +data class Path(val volume: Volume, val components: Components) { /** The name of the file/directory. */ val name: String? get() = components.name @@ -52,8 +51,7 @@ data class Path(val volume: Volume?, val components: Components) { * * @param context [Context] required to obtain human-readable strings. */ - fun resolve(context: Context) = - volume?.let { "${volume.resolveName(context)}/$components" } ?: components.toString() + fun resolve(context: Context) = "${volume.resolveName(context)}/$components" } sealed interface Volume { @@ -172,8 +170,6 @@ value class Components private constructor(val components: List) { fun parseWindows(path: String) = Components(path.trimSlashes().split('\\').filter { it.isNotEmpty() }) - fun root() = Components(emptyList()) - private fun String.trimSlashes() = trimStart(File.separatorChar).trimEnd(File.separatorChar) } } diff --git a/musikr/src/main/java/org/oxycblt/musikr/fs/path/DocumentPathFactory.kt b/musikr/src/main/java/org/oxycblt/musikr/fs/path/DocumentPathFactory.kt index 1c04ba7c3..aeeb5bb81 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/fs/path/DocumentPathFactory.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/fs/path/DocumentPathFactory.kt @@ -51,6 +51,14 @@ internal interface DocumentPathFactory { */ fun unpackDocumentTreeUri(uri: Uri): Path? + /** + * Serializes a [Path] instance into a document tree URI format path. + * + * @param path The [Path] instance to serialize. + * @return The serialized path. + */ + fun toDocumentId(path: Path): String + /** * Deserializes a document tree URI format path into a [Path] instance. * @@ -114,6 +122,15 @@ private class DocumentPathFactoryImpl( return fromDocumentId(treeUri) } + override fun toDocumentId(path: Path): String = + when (val volume = path.volume) { + // The primary storage has a volume prefix of "primary", regardless + // of if it's internal or not. + is Volume.Internal -> "$DOCUMENT_URI_PRIMARY_NAME:${path.components}" + // Document tree URIs consist of a prefixed volume name followed by a relative path. + is Volume.External -> "${volume.id}:${path.components}" + } + override fun fromDocumentId(path: String): Path? { // Document tree URIs consist of a prefixed volume name followed by a relative path, // delimited with a colon. diff --git a/musikr/src/main/java/org/oxycblt/musikr/fs/path/MediaStorePathInterpreter.kt b/musikr/src/main/java/org/oxycblt/musikr/fs/path/MediaStorePathInterpreter.kt index ebe145da5..6ec3cd42d 100644 --- a/musikr/src/main/java/org/oxycblt/musikr/fs/path/MediaStorePathInterpreter.kt +++ b/musikr/src/main/java/org/oxycblt/musikr/fs/path/MediaStorePathInterpreter.kt @@ -136,10 +136,6 @@ private constructor(private val cursor: Cursor, volumeManager: VolumeManager) : var template = "" for (i in paths.indices) { val path = paths[i] - if (path.volume == null) { - // FIXME: This means we are silently ignoring third-party storage volumes - continue - } val volume = path.volume.components ?: continue template += if (args.isEmpty()) { @@ -220,11 +216,6 @@ private constructor(private val cursor: Cursor, volumeManager: VolumeManager) : var template = "" for (i in paths.indices) { val path = paths[i] - if (path.volume == null) { - // FIXME: This means we are silently ignoring third-party storage volumes - // in MediaStore. - continue - } template += if (args.isEmpty()) { "(${MediaStore.Audio.AudioColumns.VOLUME_NAME} LIKE ? " +