Avoid being killed by SELinux when retrieving volume path

This commit is contained in:
Matéo Duparc 2024-02-11 17:55:24 +01:00
parent c26ab661c2
commit 6f43bc7417
Signed by untrusted user: hardcoresushi
GPG Key ID: AFE384344A45E13A

View File

@ -3,6 +3,7 @@ package sushi.hardcore.droidfs.util
import android.content.ActivityNotFoundException
import android.content.Context
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.storage.StorageManager
import android.provider.DocumentsContract
@ -111,6 +112,8 @@ object PathUtils {
}
}
Log.d(PATH_RESOLVER_TAG, "getExternalFilesDirs failed")
// Don't risk to be killed by SELinux on newer Android versions
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
try {
val process = ProcessBuilder("mount").redirectErrorStream(true).start().apply { waitFor() }
process.inputStream.readBytes().decodeToString().split("\n").forEach { line ->
@ -129,6 +132,7 @@ object PathUtils {
e.printStackTrace()
}
Log.d(PATH_RESOLVER_TAG, "mount processing failed")
}
return null
}