Only use MediaStore APIs on Android 11+

Fix #3428
This commit is contained in:
topjohnwu 2020-11-13 02:53:30 -08:00
parent 58a5d52b78
commit 9241246de6
3 changed files with 7 additions and 7 deletions

View File

@ -7,7 +7,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" /> android:maxSdkVersion="29" />
<application <application
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"

View File

@ -1,6 +1,6 @@
package com.topjohnwu.magisk.core.base package com.topjohnwu.magisk.core.base
import android.Manifest import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.content.ActivityNotFoundException import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -40,8 +40,8 @@ abstract class BaseActivity : AppCompatActivity() {
fun withPermission(permission: String, builder: PermissionRequestBuilder.() -> Unit) { fun withPermission(permission: String, builder: PermissionRequestBuilder.() -> Unit) {
val request = PermissionRequestBuilder().apply(builder).build() val request = PermissionRequestBuilder().apply(builder).build()
if (permission == Manifest.permission.WRITE_EXTERNAL_STORAGE && Build.VERSION.SDK_INT >= 29) { if (permission == WRITE_EXTERNAL_STORAGE && Build.VERSION.SDK_INT >= 30) {
// We do not need external rw on 29+ // We do not need external rw on 30+
request.onSuccess() request.onSuccess()
return return
} }
@ -64,7 +64,7 @@ abstract class BaseActivity : AppCompatActivity() {
} }
fun withExternalRW(builder: PermissionRequestBuilder.() -> Unit) { fun withExternalRW(builder: PermissionRequestBuilder.() -> Unit) {
withPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, builder = builder) withPermission(WRITE_EXTERNAL_STORAGE, builder = builder)
} }
override fun onRequestPermissionsResult( override fun onRequestPermissionsResult(

View File

@ -66,8 +66,8 @@ object MediaStoreUtils {
} }
private fun queryFile(displayName: String): UriFile? { private fun queryFile(displayName: String): UriFile? {
if (Build.VERSION.SDK_INT < 29) { if (Build.VERSION.SDK_INT < 30) {
// Before official general purpose MediaStore API exists, fallback to file based I/O // Fallback to file based I/O pre Android 11
val parent = File(Environment.getExternalStorageDirectory(), relativePath) val parent = File(Environment.getExternalStorageDirectory(), relativePath)
parent.mkdirs() parent.mkdirs()
return LegacyUriFile(File(parent, displayName)) return LegacyUriFile(File(parent, displayName))