Compare commits

..
4 changed files with 42 additions and 2 deletions

No files matched your search

@@ -192,6 +192,7 @@ object DeviceReport {
val fs = StatFs(Environment.getExternalStorageDirectory().path) val fs = StatFs(Environment.getExternalStorageDirectory().path)
k("Shared storage free", FileUtils.sizeToString(fs.availableBlocksLong * fs.blockSizeLong)) k("Shared storage free", FileUtils.sizeToString(fs.availableBlocksLong * fs.blockSizeLong))
} }
k("All files access", runCatching { com.droiddeck.launcher.files.AllFilesAccess.state() }.getOrNull())
h("GPU") h("GPU")
k("KGSL gpu_model", readSys("/sys/class/kgsl/kgsl-3d0/gpu_model")) k("KGSL gpu_model", readSys("/sys/class/kgsl/kgsl-3d0/gpu_model"))
@@ -14,6 +14,15 @@ object AllFilesAccess {
fun missing(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean = fun missing(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean =
sdk >= Build.VERSION_CODES.R && !granted() sdk >= Build.VERSION_CODES.R && !granted()
fun state(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): String = when {
sdk < Build.VERSION_CODES.R -> "not needed"
granted() -> "granted"
else -> "missing"
}
fun mayHideFilesIn(path: String, sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean =
covers(path) && missing(sdk, granted)
/** Whether reading [path] takes all-files access: shared storage, outside the per-app folders directly under a volume's root, which Android always lets the app use. */ /** Whether reading [path] takes all-files access: shared storage, outside the per-app folders directly under a volume's root, which Android always lets the app use. */
fun covers(path: String): Boolean { fun covers(path: String): Boolean {
val inside = VOLUME.matchEntire(path)?.groupValues?.get(2) ?: return false val inside = VOLUME.matchEntire(path)?.groupValues?.get(2) ?: return false
@@ -1355,10 +1355,17 @@ class SessionService : Service() {
if (controllersOn) components.add(RumbleComponent().also { it.attach(this) }) if (controllersOn) components.add(RumbleComponent().also { it.attach(this) })
val home = File(LinuxRuntime.rootDir(this), "root") val home = File(LinuxRuntime.rootDir(this), "root")
File(home, "Storage").mkdirs() File(home, "Storage").mkdirs()
val addedExeFolders = com.droiddeck.launcher.frontend.AddedExes.list(this).map { File(it.folder) }.distinctBy { it.path }
val addedGameRoots = com.droiddeck.launcher.frontend.AddedGames.roots(this)
val addedFolders = (addedExeFolders + addedGameRoots.map { it.host }).distinctBy { it.path }
for (folder in addedFolders) {
if (com.droiddeck.launcher.files.AllFilesAccess.mayHideFilesIn(folder.path))
Log.w(TAG, "added games: Android may hide .exe files in $folder because All files access is missing")
}
if (sharedStorage != null) { if (sharedStorage != null) {
binds.add(sharedStorage.path + ":/root/Storage") binds.add(sharedStorage.path + ":/root/Storage")
} else { } else {
for (folder in com.droiddeck.launcher.frontend.AddedExes.list(this).map { File(it.folder) }.distinctBy { it.path }) { for (folder in addedExeFolders) {
val guest = com.droiddeck.launcher.frontend.AddedGames.guestPath(this, folder) ?: continue val guest = com.droiddeck.launcher.frontend.AddedGames.guestPath(this, folder) ?: continue
if (!guest.startsWith("/root/Storage/") || !folder.isDirectory) continue if (!guest.startsWith("/root/Storage/") || !folder.isDirectory) continue
File(LinuxRuntime.rootDir(this), guest.removePrefix("/")).mkdirs() File(LinuxRuntime.rootDir(this), guest.removePrefix("/")).mkdirs()
@@ -1409,7 +1416,7 @@ class SessionService : Service() {
Log.w(TAG, "storage diagnostics: selected library could not be identified; metadata snapshot only") Log.w(TAG, "storage diagnostics: selected library could not be identified; metadata snapshot only")
} }
} }
for (root in com.droiddeck.launcher.frontend.AddedGames.roots(this)) { for (root in addedGameRoots) {
if (root.host.isDirectory && root.host.canRead()) { if (root.host.isDirectory && root.host.canRead()) {
File(LinuxRuntime.rootDir(this), root.guest.removePrefix("/")).mkdirs() File(LinuxRuntime.rootDir(this), root.guest.removePrefix("/")).mkdirs()
binds.add(root.host.path + ":" + root.guest) binds.add(root.host.path + ":" + root.guest)
@@ -1,5 +1,6 @@
package com.droiddeck.launcher.files package com.droiddeck.launcher.files
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Test import org.junit.Test
@@ -37,4 +38,26 @@ class AllFilesAccessTest {
assertFalse(AllFilesAccess.covers("/storage/1A2B-3C4D/Android/obb/com.droiddeck.launcher")) assertFalse(AllFilesAccess.covers("/storage/1A2B-3C4D/Android/obb/com.droiddeck.launcher"))
assertFalse(AllFilesAccess.covers("/data/user/0/com.droiddeck.launcher/files")) assertFalse(AllFilesAccess.covers("/data/user/0/com.droiddeck.launcher/files"))
} }
@Test
fun stateNamesWhatTheReportShows() {
assertEquals("not needed", AllFilesAccess.state(sdk = 29) { false })
assertEquals("missing", AllFilesAccess.state(sdk = 34) { false })
assertEquals("granted", AllFilesAccess.state(sdk = 34) { true })
}
@Test
fun sharedStorageMayHideFilesOnlyWithoutAccess() {
assertTrue(AllFilesAccess.mayHideFilesIn("/storage/emulated/0", sdk = 34) { false })
assertTrue(AllFilesAccess.mayHideFilesIn("/storage/1A2B-3C4D/Games", sdk = 34) { false })
assertFalse(AllFilesAccess.mayHideFilesIn("/storage/emulated/0", sdk = 34) { true })
assertFalse(AllFilesAccess.mayHideFilesIn("/storage/emulated/0", sdk = 29) { false })
}
@Test
fun appFoldersAndPrivateStorageNeverHideFiles() {
assertFalse(AllFilesAccess.mayHideFilesIn("/storage/emulated/0/Android/data/com.droiddeck.launcher/files", sdk = 34) { false })
assertFalse(AllFilesAccess.mayHideFilesIn("/data/user/0/com.droiddeck.launcher/files/Games", sdk = 34) { false })
assertFalse(AllFilesAccess.mayHideFilesIn("/mnt/media_rw/1A2B-3C4D", sdk = 34) { false })
}
} }