mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-30 18:15:42 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54ca518553 |
No files matched your search
@@ -186,7 +186,6 @@ object DeviceReport {
|
||||
val fs = StatFs(Environment.getExternalStorageDirectory().path)
|
||||
k("Shared storage free", FileUtils.sizeToString(fs.availableBlocksLong * fs.blockSizeLong))
|
||||
}
|
||||
k("All files access", runCatching { com.droiddeck.launcher.files.AllFilesAccess.state() }.getOrNull())
|
||||
|
||||
h("GPU")
|
||||
k("KGSL gpu_model", readSys("/sys/class/kgsl/kgsl-3d0/gpu_model"))
|
||||
|
||||
@@ -14,15 +14,6 @@ object AllFilesAccess {
|
||||
fun missing(sdk: Int = Build.VERSION.SDK_INT, granted: () -> Boolean = { Environment.isExternalStorageManager() }): Boolean =
|
||||
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 hidesFilesIn(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. */
|
||||
fun covers(path: String): Boolean {
|
||||
val inside = VOLUME.matchEntire(path)?.groupValues?.get(2) ?: return false
|
||||
|
||||
@@ -59,13 +59,18 @@ object GameStorage {
|
||||
return when {
|
||||
pref == SessionPrefs.GAME_STORAGE_OFF -> null
|
||||
pref.isEmpty() -> options(context).firstOrNull()?.let { Option(it.name, it.path) }
|
||||
else -> Option(SessionPrefs.gameStorageLabel(context), pref).takeIf { attached(File(pref)) }
|
||||
else -> reachable(pref).let { path -> Option(SessionPrefs.gameStorageLabel(context), path).takeIf { attached(File(path)) } }
|
||||
}
|
||||
}
|
||||
|
||||
fun disconnected(context: Context): Boolean {
|
||||
val pref = SessionPrefs.gameStorage(context)
|
||||
return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(pref))
|
||||
return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(reachable(pref)))
|
||||
}
|
||||
|
||||
internal fun reachable(path: String, usable: (File) -> Boolean = { it.isDirectory && it.canWrite() }): String {
|
||||
val alias = UsbLink.storagePath(path)
|
||||
return if (alias != path && !usable(File(path)) && usable(File(alias))) alias else path
|
||||
}
|
||||
|
||||
internal fun attached(
|
||||
|
||||
@@ -46,7 +46,16 @@ object SecondaryLibrary {
|
||||
}
|
||||
|
||||
fun privateRoot(files: File, library: File): File {
|
||||
val digest = MessageDigest.getInstance("SHA-256").digest(library.canonicalPath.toByteArray())
|
||||
val own = privateDir(files, library.canonicalPath)
|
||||
if (own.exists()) return own
|
||||
val raw = UsbLink.rawPath(library.absolutePath)
|
||||
val alias = if (raw != library.absolutePath) raw else UsbLink.storagePath(library.absolutePath)
|
||||
if (alias == library.absolutePath) return own
|
||||
return privateDir(files, runCatching { File(alias).canonicalPath }.getOrDefault(alias)).takeIf { it.exists() } ?: own
|
||||
}
|
||||
|
||||
private fun privateDir(files: File, path: String): File {
|
||||
val digest = MessageDigest.getInstance("SHA-256").digest(path.toByteArray())
|
||||
.joinToString("") { "%02x".format(it.toInt() and 255) }
|
||||
return File(files, "steam-libraries/$digest")
|
||||
}
|
||||
|
||||
@@ -1361,8 +1361,6 @@ class SessionService : Service() {
|
||||
File(LinuxRuntime.rootDir(this), root.guest.removePrefix("/")).mkdirs()
|
||||
binds.add(root.host.path + ":" + root.guest)
|
||||
Log.i(TAG, "added games: ${root.host} -> ${root.guest}")
|
||||
if (com.droiddeck.launcher.files.AllFilesAccess.hidesFilesIn(root.host.path))
|
||||
Log.w(TAG, "added games: ${root.host} needs All files access; without it Android hides its .exe files from the session")
|
||||
} else {
|
||||
Log.w(TAG, "added games: ${root.host} is not a readable folder this session")
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.AddedGames
|
||||
import com.droiddeck.launcher.runtime.BattleNet
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.session.GameStorage
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.InstalledStoreGame
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
@@ -130,13 +131,13 @@ object BattleNetClient {
|
||||
StoresState.post { opener?.invoke(args) }
|
||||
}
|
||||
|
||||
fun library(context: Context, root: File = preferred(context)): List<String> =
|
||||
AddedGames.guestPath(context, StoreInstallRoot.storeDir(root, Store.BATTLENET))?.let { listOf("--library", it) }.orEmpty()
|
||||
fun library(context: Context, root: File? = preferred(context)): List<String> =
|
||||
root?.let { AddedGames.guestPath(context, StoreInstallRoot.storeDir(it, Store.BATTLENET)) }?.let { listOf("--library", it) }.orEmpty()
|
||||
|
||||
internal fun preferred(context: Context): File {
|
||||
internal fun preferred(context: Context): File? {
|
||||
val second = StoreInstallRoot.libraryRoot(context)?.absolutePath
|
||||
return StoreInstallRoot.targets(context).firstOrNull { it.root.absolutePath == second && (it.root.isDirectory || it.root.mkdirs()) }?.root
|
||||
?: StoreInstallRoot.internalRoot(context)
|
||||
?: StoreInstallRoot.internalRoot(context).takeIf { second == null && !GameStorage.disconnected(context) }
|
||||
}
|
||||
|
||||
fun installGame(context: Context, uid: String, root: File) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.droiddeck.launcher.files
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
@@ -38,26 +37,4 @@ class AllFilesAccessTest {
|
||||
assertFalse(AllFilesAccess.covers("/storage/1A2B-3C4D/Android/obb/com.droiddeck.launcher"))
|
||||
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 sharedStorageHidesFilesOnlyWithoutAccess() {
|
||||
assertTrue(AllFilesAccess.hidesFilesIn("/storage/emulated/0", sdk = 34) { false })
|
||||
assertTrue(AllFilesAccess.hidesFilesIn("/storage/1A2B-3C4D/Games", sdk = 34) { false })
|
||||
assertFalse(AllFilesAccess.hidesFilesIn("/storage/emulated/0", sdk = 34) { true })
|
||||
assertFalse(AllFilesAccess.hidesFilesIn("/storage/emulated/0", sdk = 29) { false })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appFoldersAndPrivateStorageNeverHideFiles() {
|
||||
assertFalse(AllFilesAccess.hidesFilesIn("/storage/emulated/0/Android/data/com.droiddeck.launcher/files", sdk = 34) { false })
|
||||
assertFalse(AllFilesAccess.hidesFilesIn("/data/user/0/com.droiddeck.launcher/files/Games", sdk = 34) { false })
|
||||
assertFalse(AllFilesAccess.hidesFilesIn("/mnt/media_rw/1A2B-3C4D", sdk = 34) { false })
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,19 @@ class GameStorageTest {
|
||||
assertFalse(GameStorage.disconnected(app))
|
||||
}
|
||||
|
||||
@Test fun aRawCardPathTheProcessCannotUseFallsBackToItsStoragePath() {
|
||||
val usable = setOf("/storage/A042-9B16/Games")
|
||||
assertEquals("/storage/A042-9B16/Games", GameStorage.reachable("/mnt/media_rw/A042-9B16/Games") { it.path in usable })
|
||||
}
|
||||
|
||||
@Test fun aUsableRawPathAndOtherPathsAreKept() {
|
||||
assertEquals("/mnt/media_rw/A042-9B16/Games", GameStorage.reachable("/mnt/media_rw/A042-9B16/Games") { true })
|
||||
assertEquals("/mnt/media_rw/0000-0000/Games", GameStorage.reachable("/mnt/media_rw/0000-0000/Games") { false })
|
||||
assertEquals("/storage/A042-9B16/Games", GameStorage.reachable("/storage/A042-9B16/Games") { false })
|
||||
val folder = tmp.newFolder("library").path
|
||||
assertEquals(folder, GameStorage.reachable(folder) { false })
|
||||
}
|
||||
|
||||
@Test fun onlyAVfatMountCountsAsFat32() {
|
||||
val mounts = """
|
||||
/dev/fuse /storage/emulated fuse rw 0 0
|
||||
|
||||
@@ -21,6 +21,24 @@ class SecondaryLibraryTest {
|
||||
assertFalse(SecondaryLibrary.privateRoot(files, content).exists())
|
||||
}
|
||||
|
||||
@Test fun aCardReachedThroughItsOtherPathKeepsItsPrivateDirectories() {
|
||||
val files = tmp.newFolder("files")
|
||||
val raw = SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/A042-9B16/Games")).apply { mkdirs() }
|
||||
assertEquals(raw, SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")))
|
||||
val storage = SecondaryLibrary.privateRoot(files, File("/storage/B2BD-BCFC/Games")).apply { mkdirs() }
|
||||
assertEquals(storage, SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/B2BD-BCFC/Games")))
|
||||
}
|
||||
|
||||
@Test fun aLibraryWithItsOwnPrivateDirectoriesKeepsThem() {
|
||||
val files = tmp.newFolder("files")
|
||||
val own = SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")).apply { mkdirs() }
|
||||
val raw = File(own.parentFile, SecondaryLibrary.privateRoot(tmp.newFolder("other"), File("/mnt/media_rw/A042-9B16/Games")).name)
|
||||
raw.mkdirs()
|
||||
assertEquals(own, SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")))
|
||||
assertEquals(raw, SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/A042-9B16/Games")))
|
||||
assertFalse(SecondaryLibrary.privateRoot(files, File("/storage/emulated/0/Games")).exists())
|
||||
}
|
||||
|
||||
@Test fun aWritableAliasIsSelectedAndItsProbeIsRemoved() {
|
||||
val library = tmp.newFolder("shared")
|
||||
val candidate = File(tmp.root, "direct")
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.droiddeck.launcher.stores.battlenet
|
||||
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class BattleNetLibraryTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
@Test fun aMissingLibraryLeavesBattleNetsInstallFolderAlone() {
|
||||
SessionPrefs.setGameStorage(app, "/storage/0000-0000/Games", "SD card")
|
||||
assertTrue(BattleNetClient.library(app).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun anAttachedLibraryIsHandedToBattleNet() {
|
||||
SessionPrefs.setGameStorage(app, tmp.newFolder("card").path, "SD card")
|
||||
assertEquals("--library", BattleNetClient.library(app).firstOrNull())
|
||||
}
|
||||
|
||||
@Test fun internalStorageIsHandedToBattleNetWhenItIsTheChoice() {
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
assertEquals("--library", BattleNetClient.library(app).firstOrNull())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user