music: switch to new storage perms

Switch to the new READ_AUDIO_STORAGE permission for Android 13.
This commit is contained in:
Alexander Capehart 2022-08-16 12:31:36 -06:00
parent f5f28b891a
commit 3cef088d12
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 13 additions and 5 deletions

View file

@ -2,7 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Android 13 uses READ_MEDIA_AUDIO instead of READ_EXTERNAL_STORAGE -->
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

View file

@ -17,7 +17,6 @@
package org.oxycblt.auxio.home
import android.Manifest
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
@ -325,8 +324,7 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
visibility = View.VISIBLE
text = context.getString(R.string.lbl_grant)
setOnClickListener {
storagePermissionLauncher.launch(
Manifest.permission.READ_EXTERNAL_STORAGE)
storagePermissionLauncher.launch(Indexer.PERMISSION_READ_AUDIO)
}
}
}

View file

@ -132,7 +132,7 @@ class Indexer {
val handle = guard.newHandle()
val notGranted =
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) ==
ContextCompat.checkSelfPermission(context, PERMISSION_READ_AUDIO) ==
PackageManager.PERMISSION_DENIED
if (notGranted) {
@ -462,6 +462,14 @@ class Indexer {
companion object {
@Volatile private var INSTANCE: Indexer? = null
val PERMISSION_READ_AUDIO =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// READ_EXTERNAL_STORAGE was superseded by READ_MEDIA_AUDIO in Android 13
Manifest.permission.READ_MEDIA_AUDIO
} else {
Manifest.permission.READ_EXTERNAL_STORAGE
}
/** Get the process-level instance of [Indexer]. */
fun getInstance(): Indexer {
val currentInstance = INSTANCE