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.
This commit is contained in:
Alexander Capehart 2024-01-01 16:10:11 -07:00
parent bf9667f545
commit 68584ba426
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -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