mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Add experimental Xbox and PC Game Pass store support (#1156)
This commit is contained in:
1 parent
8e02904a04
commit
a63f3b1fbc
56 files changed
+3720
-47
No files matched your search
@@ -112,6 +112,25 @@ class StoreAccountsCipherTest {
|
||||
assertEquals(creds.toString(), StoreAccounts.read(app, Store.EPIC).toString())
|
||||
}
|
||||
|
||||
@Test fun xboxNeverFallsBackToPlaintextWhenKeystoreFails() {
|
||||
StoreAccounts.keys = broken
|
||||
org.junit.Assert.assertThrows(IllegalStateException::class.java) {
|
||||
StoreAccounts.write(app, Store.XBOX, JSONObject().put("username", "test@example.test").put("slots", JSONObject().put("user-tokens", "synthetic-secret")))
|
||||
}
|
||||
assertFalse(file(Store.XBOX).exists())
|
||||
StoreAccounts.keys = fake
|
||||
StoreAccounts.write(app, Store.XBOX, creds)
|
||||
assertTrue(CredentialCipher.isEnvelope(JSONObject(file(Store.XBOX).readText())))
|
||||
}
|
||||
|
||||
@Test fun xboxUsernameAndBackendSlotsAreEncryptedTogether() {
|
||||
val xbox = JSONObject().put("username", "test@example.test").put("slots", JSONObject().put("user-tokens", "synthetic-secret"))
|
||||
StoreAccounts.write(app, Store.XBOX, xbox)
|
||||
assertFalse(file(Store.XBOX).readText().contains("synthetic-secret"))
|
||||
assertFalse(file(Store.XBOX).readText().contains("test@example.test"))
|
||||
assertEquals("test@example.test", StoreAccounts.signedInAs(app, Store.XBOX))
|
||||
}
|
||||
|
||||
@Test fun signOutRemovesTheFile() {
|
||||
StoreAccounts.write(app, Store.GOG, creds)
|
||||
StoreAccounts.clear(app, Store.GOG)
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.droiddeck.launcher.stores
|
||||
|
||||
import android.app.Application
|
||||
import com.droiddeck.launcher.frontend.AddedGames
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33], application = Application::class)
|
||||
class StoreLaunchTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
private fun install(state: String = StoreGameSidecar.STATE_INSTALLED): File {
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
val folder = File(StoreInstallRoot.storeDir(StoreInstallRoot.installRoot(app), Store.XBOX), "Deep Rock Galactic")
|
||||
File(folder, "FSD/Binaries/WinGDK/FSD.exe").apply { parentFile!!.mkdirs(); writeText("licensed image") }
|
||||
StoreGameSidecar(Store.XBOX, "9NHFVWX1V7QJ", "Deep Rock Galactic", "FSD/Binaries/WinGDK/FSD.exe", state = state).write(folder)
|
||||
return folder
|
||||
}
|
||||
|
||||
@Test fun aCompletedInstallCanLaunchBeforeTheFrontendLibraryRefreshes() {
|
||||
val folder = install()
|
||||
val game = StoreLaunch.installedGame(app, Store.XBOX, "9NHFVWX1V7QJ")!!
|
||||
val added = AddedGames.single(app, folder.path)!!
|
||||
assertEquals("xbox", game.source)
|
||||
assertEquals("9NHFVWX1V7QJ", game.storeId)
|
||||
assertEquals(folder, game.gameFiles)
|
||||
assertEquals(added.gameId, game.gameId)
|
||||
assertTrue(added.guestExe.endsWith("/FSD/Binaries/WinGDK/FSD.exe"))
|
||||
}
|
||||
|
||||
@Test fun unfinishedPackagesCannotBecomePlayableThroughTheFallback() {
|
||||
for (state in listOf(StoreGameSidecar.STATE_INSTALLING, StoreGameSidecar.STATE_UPDATING)) {
|
||||
install(state)
|
||||
assertNull(StoreLaunch.installedGame(app, Store.XBOX, "9NHFVWX1V7QJ"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun anotherStoreOrProductCannotUseTheXboxInstall() {
|
||||
install()
|
||||
assertNull(StoreLaunch.installedGame(app, Store.GOG, "9NHFVWX1V7QJ"))
|
||||
assertNull(StoreLaunch.installedGame(app, Store.XBOX, "OTHERPRODUCT"))
|
||||
}
|
||||
|
||||
@Test fun aMissingExecutableDoesNotBecomeALaunchTarget() {
|
||||
val folder = install()
|
||||
File(folder, "FSD/Binaries/WinGDK/FSD.exe").delete()
|
||||
assertNull(StoreLaunch.installedGame(app, Store.XBOX, "9NHFVWX1V7QJ"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.droiddeck.launcher.stores.xbox
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class XboxCatalogTest {
|
||||
private val now = Instant.parse("2026-10-19T12:00:00Z")
|
||||
private val game = "9AAAAAAAAAAA"
|
||||
private val parent = "9BBBBBBBBBBB"
|
||||
private val plan = "CFQ7TTC0KGQ8"
|
||||
private fun row(id: String, parent: String? = null) = JSONObject().put("productId", id).put("status", "Active")
|
||||
.put("isTrial", false).put("special", false).put("sharingSource", "None")
|
||||
.put("endDate", "2099-01-01T00:00:00Z").put("satisfiedByProductId", parent ?: JSONObject.NULL)
|
||||
private fun envelope(vararg rows: JSONObject) = JSONObject().put("schema", 1).put("account", "test@example.test")
|
||||
.put("market", "US").put("checkedAt", now.toString()).put("entitlements", JSONArray(rows.toList()))
|
||||
private fun access(vararg rows: JSONObject) = XboxCatalog.access(envelope(*rows), "test@example.test", "US", now)
|
||||
|
||||
@Test fun purchasedAndSubscriptionAccessRemainDistinct() {
|
||||
assertEquals(mapOf(game to "owned", parent to "gamepass"), access(row(game), row(parent, plan)))
|
||||
assertFalse(access(row(plan)).containsKey(plan))
|
||||
}
|
||||
|
||||
@Test fun backendRfc3339OffsetsAndNanosecondsAreAccepted() {
|
||||
val checked = "2026-10-19T19:02:38.173609086+00:00"
|
||||
val response = envelope(row(game).put("endDate", "2099-01-01T01:00:00.000000001+01:00"))
|
||||
.put("checkedAt", checked)
|
||||
assertEquals(mapOf(game to "owned"), XboxCatalog.access(response, "test@example.test", "US",
|
||||
Instant.parse("2026-10-19T19:02:39Z")))
|
||||
}
|
||||
|
||||
@Test fun expiredTrialSharedAndUnknownFlagsDoNotGrantAccess() {
|
||||
for ((key, value) in listOf("status" to "Expired", "isTrial" to true, "special" to true,
|
||||
"sharingSource" to "Family", "endDate" to "2020-01-01T00:00:00Z")) {
|
||||
assertTrue(access(row(game).put(key, value)).isEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun malformedAndConflictingParentsCannotGrantDependentAccess() {
|
||||
assertTrue(access(row(game, parent), row(parent).put("isTrial", JSONObject.NULL)).isEmpty())
|
||||
assertTrue(access(row(game, plan), row(plan).put("endDate", "invalid")).isEmpty())
|
||||
assertTrue(access(row(game), row(game, plan)).isEmpty())
|
||||
assertTrue(access(row(game, parent), row(parent, game)).isEmpty())
|
||||
}
|
||||
|
||||
@Test fun mismatchedAccountAndStaleResultsAreRejected() {
|
||||
for (json in listOf(envelope(row(game)).put("account", "other@example.test"),
|
||||
envelope(row(game)).put("checkedAt", "2020-01-01T00:00:00Z"))) {
|
||||
assertThrows(IllegalArgumentException::class.java) { XboxCatalog.access(json, "test@example.test", "US", now) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun installedSubscriptionDoesNotBecomeOwnershipWithoutACachedLibrary() {
|
||||
val sidecar = com.droiddeck.launcher.stores.StoreGameSidecar(com.droiddeck.launcher.stores.Store.XBOX,
|
||||
game, "A game", "Game.exe", extra = mapOf("access" to "gamepass"))
|
||||
val card = com.droiddeck.launcher.stores.installedCards(com.droiddeck.launcher.stores.Store.XBOX,
|
||||
listOf(com.droiddeck.launcher.stores.InstalledStoreGame(sidecar, java.io.File("/synthetic-game"))), emptyList()).single()
|
||||
assertFalse(card.owned); assertTrue(card.subscription)
|
||||
}
|
||||
|
||||
@Test fun consoleAndUwpOffersAreFilteredOut() {
|
||||
fun product(platform: String, format: String) = JSONObject().put("ProductId", game).put("ProductType", "Game")
|
||||
.put("LocalizedProperties", JSONArray().put(JSONObject().put("ProductTitle", "A PC game")))
|
||||
.put("DisplaySkuAvailabilities", JSONArray().put(JSONObject().put("Sku", JSONObject().put("Properties", JSONObject()
|
||||
.put("Packages", JSONArray().put(JSONObject().put("PackageFormat", format).put("PlatformDependencies",
|
||||
JSONArray().put(JSONObject().put("PlatformName", platform)))))))))
|
||||
assertNull(XboxCatalog.product(product("Xbox.One", "MSIXVC"), mapOf(game to "owned")))
|
||||
assertNull(XboxCatalog.product(product("Windows.Desktop", "APPX"), mapOf(game to "owned")))
|
||||
val pc = XboxCatalog.product(product("Windows.Desktop", "MSIXVC"), mapOf(game to "gamepass"))!!
|
||||
assertEquals(game, XboxCatalog.product(product("Windows.Desktop", "MSIXVC").put("ProductId", game.lowercase()), mapOf(game to "owned"))!!.id)
|
||||
assertTrue(pc.accessible); assertTrue(pc.subscription); assertFalse(pc.owned)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.droiddeck.launcher.stores.xbox
|
||||
|
||||
import com.droiddeck.launcher.stores.CatalogItem
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class XboxLibraryCacheTest {
|
||||
private val account = "test@example.test"
|
||||
private val now = 1_792_440_000_000L
|
||||
private fun game(id: String, subscription: Boolean) = CatalogItem(Store.XBOX, id, "A game", "https://example.test/hero",
|
||||
tallImageUrl = "https://example.test/poster", description = "Description", developer = "Developer", publisher = "Publisher",
|
||||
sizeBytes = 12345, owned = !subscription, subscription = subscription, storeUrl = "https://www.xbox.com/games/store/$id",
|
||||
extra = mapOf("market" to "US", "access" to if (subscription) "gamepass" else "owned"))
|
||||
|
||||
@Test fun restartRestoresMetadataWithoutTurningSubscriptionsIntoPurchases() {
|
||||
val games = listOf(game("9AAAAAAAAAAA", false), game("9BBBBBBBBBBB", true))
|
||||
val text = XboxLibraryCache.encode(account, "US", games, now)
|
||||
val cached = XboxLibraryCache.decode(text, account, "US", now)!!
|
||||
assertEquals(games, cached.games)
|
||||
assertFalse(cached.games[1].owned)
|
||||
assertTrue(cached.games[1].subscription)
|
||||
}
|
||||
|
||||
@Test fun anotherAccountMarketOrInvalidEnvelopeCannotRestoreTheLibrary() {
|
||||
val text = XboxLibraryCache.encode(account, "US", listOf(game("9AAAAAAAAAAA", false)), now)
|
||||
assertNull(XboxLibraryCache.decode(text, "other@example.test", "US", now))
|
||||
assertNull(XboxLibraryCache.decode(text, account, "GB", now))
|
||||
assertNull(XboxLibraryCache.decode(text.replace("\"schema\":1", "\"schema\":2"), account, "US", now))
|
||||
assertNull(XboxLibraryCache.decode("invalid", account, "US", now))
|
||||
assertNull(XboxLibraryCache.decode(text, account, "US", now - 120_000))
|
||||
}
|
||||
|
||||
@Test fun freshCacheAvoidsNetworkAndForceOrStalenessRequestsARefresh() {
|
||||
val cached = XboxLibraryCache.Snapshot(emptyList(), now)
|
||||
assertFalse(cached.needsRefresh(false, now + 899_999))
|
||||
assertTrue(cached.needsRefresh(false, now + 900_000))
|
||||
assertTrue(cached.needsRefresh(true, now))
|
||||
val old = XboxLibraryCache.decode(XboxLibraryCache.encode(account, "US", emptyList(), now), account, "US", now + 86_400_000)!!
|
||||
assertTrue(old.needsRefresh(false, now + 86_400_000))
|
||||
assertTrue(old.games.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun clearingTheCacheRemovesThePersistedAccountLibrary() {
|
||||
val app = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
XboxLibraryCache.write(app, account, "US", listOf(game("9AAAAAAAAAAA", false)))
|
||||
assertNotNull(XboxLibraryCache.read(app, account, "US"))
|
||||
XboxLibraryCache.clear(app)
|
||||
assertNull(XboxLibraryCache.read(app, account, "US"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.droiddeck.launcher.stores.xbox
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
@org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class)
|
||||
@org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class)
|
||||
class XboxManifestTest {
|
||||
@get:Rule val temporary = TemporaryFolder()
|
||||
@Test fun resolvesTheManifestExecutableWithWindowsLetterCasing() {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "Bin").mkdir()
|
||||
java.io.File(root, "Bin/Game.exe").writeText("encrypted")
|
||||
java.io.File(root, "MicrosoftGame.Config").writeText("<Game><ExecutableList><Executable Name=\"bin\\GAME.EXE\" TargetDeviceFamily=\"PC\"/></ExecutableList></Game>")
|
||||
assertEquals("Bin/Game.exe", XboxInstaller.executable(root))
|
||||
}
|
||||
@Test fun rejectsTraversalAndExternalEntities() {
|
||||
for (xml in listOf("<Game><Executable Name=\"../escape.exe\"/></Game>",
|
||||
"<!DOCTYPE Game [<!ENTITY external SYSTEM 'file:///etc/passwd'>]><Game>&external;</Game>",
|
||||
"<!DOCTYPE Game SYSTEM 'https://example.test/manifest.dtd'><Game/>",
|
||||
"<!DOCTYPE Game [<!ENTITY internal 'test'>]><Game/>")) {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "MicrosoftGame.config").writeText(xml)
|
||||
assertThrows(Exception::class.java) { XboxInstaller.executable(root) }
|
||||
}
|
||||
}
|
||||
@Test fun androidManifestParserPreservesIdentityAndSelectsTheRetailPcExecutable() {
|
||||
val root = temporary.newFolder()
|
||||
java.io.File(root, "Retail.exe").writeText("encrypted")
|
||||
java.io.File(root, "MicrosoftGame.Config").writeText("""<?xml version="1.0" encoding="utf-8"?>
|
||||
<Game configVersion="1"><!-- package comment -->
|
||||
<Identity Name="Test.Game" Publisher="CN=A & B" Version="1.2.3.0"/>
|
||||
<ExecutableList><Executable Name="Console.exe" TargetDeviceFamily="XboxOne"/>
|
||||
<Executable Name="Dev.exe" TargetDeviceFamily="PC" IsDevOnly="true"/>
|
||||
<Executable Name="Retail.exe" TargetDeviceFamily="PC" IsDevOnly="false"/></ExecutableList>
|
||||
<StoreId>9AAAAAAAAAAA</StoreId><RelatedProduct>9BBBBBBBBBBB</RelatedProduct>
|
||||
<MainPackageDependency Name="Test.Base"/></Game>""")
|
||||
val info = XboxManifest.read(root)
|
||||
assertEquals("9AAAAAAAAAAA", info.storeId)
|
||||
assertEquals("Test.Game", info.name)
|
||||
assertEquals("CN=A & B", info.publisher)
|
||||
assertEquals("1.2.3.0", info.version)
|
||||
assertEquals("Test.Base", info.dependency)
|
||||
assertEquals(listOf("9BBBBBBBBBBB"), info.related)
|
||||
assertEquals(listOf("Retail.exe"), info.executables)
|
||||
assertEquals("Retail.exe", XboxManifest.executable(root))
|
||||
}
|
||||
@Test fun signInBridgeRejectsUntrustedAndNonHttpsOrigins() {
|
||||
assertTrue(XboxLoginActivity.trusted("https://login.live.com/ppsecure/InlineLogin.srf"))
|
||||
for (url in listOf("http://login.live.com/", "https://login.live.com.evil.test/", "https://evil.test@login.live.com/", "https://login.live.com:8443/"))
|
||||
assertFalse(XboxLoginActivity.trusted(url))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user