From c8dec0a8bc4285d9cf9da59ad7a663f0e28e9400 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:02:46 -0500 Subject: [PATCH] fix(stores): EA and Ubisoft libraries list only games the account can download (#2521) * fix(stores): EA and Ubisoft libraries list only games the account can download * fix(stores): keep owned games through entitlement and manifest lookup failures --- .../droiddeck/launcher/stores/ea/EaLibrary.kt | 33 ++++++- .../launcher/stores/ubisoft/UbisoftBackend.kt | 92 +++++++++---------- .../droiddeck/launcher/stores/ea/EaTest.kt | 14 +++ .../launcher/stores/ubisoft/UbisoftTest.kt | 31 +++++-- 4 files changed, 106 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/ea/EaLibrary.kt b/app/src/main/java/com/droiddeck/launcher/stores/ea/EaLibrary.kt index 2a90b2550c..37fd6269f8 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/ea/EaLibrary.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/ea/EaLibrary.kt @@ -69,8 +69,8 @@ data class EaGame( } object EaLibrary { - private const val KEY_CACHE = "library_cache" - private const val KEY_SYNCED_AT = "library_synced_at" + private const val KEY_CACHE = "library_cache_v2" + private const val KEY_SYNCED_AT = "library_synced_at_v2" private const val THROTTLE_MS = 6 * 60 * 60 * 1000L private const val ART_TTL_MS = 7 * 24 * 60 * 60 * 1000L private const val ART_THREADS = 4 @@ -137,6 +137,16 @@ object EaLibrary { }.sortedBy { it.first.name.lowercase() } } + /** + * Offers EA lists as owned whose entitlements grant no active game download: an online pass or product-key + * link such as Burnout Paradise's VALIDATED_ONLINE_ACCESS, or a Game Pass title disabled once the + * subscription lapsed. EA refuses their licence. Offers with no entitlement rows at all are left alone. + */ + internal fun withoutGameDownload(rows: List): Map> = + rows.groupBy { it.optString("productId") }.filterKeys { it.isNotEmpty() }.filterValues { offer -> + offer.none { it.optString("entitlementType").equals("ORIGIN_DOWNLOAD", true) && it.optString("status").equals("ACTIVE", true) } + } + private fun art(app: Context, token: String, slugs: Collection, gen: Int): Map { val prefs = EaPrefs.get(app) val now = System.currentTimeMillis() @@ -229,13 +239,28 @@ object EaLibrary { status(R.string.stores_sync_sign_in) val token = EaAuth.accessToken(app) ?: return problem(StoresState.notSignedInLine(store)) status(R.string.stores_sync_game_list) - val owned = withToken(app, token) { EaApi.owned(it) } + val listed = withToken(app, token) { EaApi.owned(it) } + val rows = try { + withToken(app, token) { EaApi.legacyEntitlements(it) } + } catch (e: Exception) { + if (e is EaApiException && e.status == 401) throw e + if (e !is EaApiException && e !is java.io.IOException) throw e + StoresState.logLine("ea: entitlements unavailable, keeping every owned product: ${e.message}") + emptyList() + } + val unplayable = withoutGameDownload(rows) + for ((id, held) in unplayable) if (listed.any { it.offerId == id }) StoresState.logLine( + "ea: left out $id, no game download: " + held.joinToString(",") { it.optString("entitlementTag") + "/" + it.optString("status") + "/" + it.optString("statusReasonCode") + "/" + it.optString("externalType") }) + val owned = listed.filterNot { it.offerId in unplayable } val offers = withToken(app, token) { EaApi.offers(it, owned.map { o -> o.offerId }) }.associateBy { it.offerId } val picked = pick(owned, offers) StoresState.logLine("ea: ${owned.size} owned products, ${picked.size} games") for ((o, offer) in picked) StoresState.logLine( "ea: owned ${o.offerId} content=${offer.contentId} master=${offer.masterTitleId} mp=${offer.multiplayerId} via=${o.ownership.joinToString("+")} type=${o.gameType}") - if (picked.isEmpty()) return problem(if (cache.isEmpty()) app.getString(R.string.stores_sync_no_games, store.label) else null) + if (picked.isEmpty()) { + if (owned.size < listed.size && storeCache(app, emptyList(), gen)) publish(app, emptyList(), gen) + return problem(app.getString(R.string.stores_sync_no_games, store.label).takeIf { cache.isEmpty() || owned.size < listed.size }) + } if (gen != generation.get()) return status(R.string.stores_sync_cover_art) val images = art(app, token, picked.map { it.first.slug }, gen) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/ubisoft/UbisoftBackend.kt b/app/src/main/java/com/droiddeck/launcher/stores/ubisoft/UbisoftBackend.kt index 09008e1927..8a4b253135 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/ubisoft/UbisoftBackend.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/ubisoft/UbisoftBackend.kt @@ -48,11 +48,6 @@ object UbisoftBackend : StoreBackend { override fun install(context: Context, item: CatalogItem, root: java.io.File) { val app = context.applicationContext - item.extra[STEAM_APP]?.takeIf { item.extra["productId"] == null }?.let { steam -> - StoresState.logLine("Ubisoft: ${item.title} is owned on Steam; installing Steam app $steam") - installInSteam(app, steam) - return - } if (!UbisoftNative.ready()) { StoresState.logLine(UbisoftNative.ENGINE_MISSING) StoresState.post { StoresState.problems[store] = UbisoftNative.ENGINE_MISSING } @@ -65,19 +60,6 @@ object UbisoftBackend : StoreBackend { } override fun uninstall(context: Context, game: InstalledStoreGame) {} - - const val STEAM_APP = "steamAppId" - - /** Steam asks to install a game it does not have when told to run it. */ - private fun installInSteam(app: Context, steamAppId: String) { - if (com.droiddeck.launcher.session.SessionState.running) { - if (!com.droiddeck.launcher.session.SessionService.launchGame(app, steamAppId)) StoresState.logLine("Ubisoft: Steam is busy; install Steam app $steamAppId there") - return - } - app.startActivity(Intent(app, com.droiddeck.launcher.SessionActivity::class.java) - .putExtra(com.droiddeck.launcher.session.SessionService.EXTRA_STEAM_URL, com.droiddeck.launcher.frontend.GameLaunchLink.steamUrl(steamAppId)) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) - } } internal class UbisoftLogin(override val userAgent: String) : StoreLoginActivity.Flow { @@ -134,11 +116,20 @@ object UbisoftLibrary { return items to games.optInt("totalCount", items.size) } - /** Base games with a manifest, by UbiServices space; add-ons and bundles share spaces with their game. */ + private val THIRD_PARTY = Regex("""^\s*third_party_platform:\s*\r?\n\s+name:\s*['"]?([^'"\r\n]+?)['"]?\s*$""", RegexOption.MULTILINE) + + /** The store a product's configuration says delivers it, such as Steam, when not Ubisoft itself. */ + internal fun thirdParty(configuration: String): String? = THIRD_PARTY.find(configuration)?.groupValues?.get(1)?.trim()?.takeIf { it.isNotEmpty() } + + /** + * Owned base games Ubisoft delivers itself, by UbiServices space; add-ons and bundles share spaces with their + * game. A game whose manifest Ubisoft did not send stays: the manifest only names the build to download. + */ internal fun ownedBySpace(owned: JSONObject?): Map { val list = owned?.optJSONArray("games") ?: return emptyMap() val games = (0 until list.length()).mapNotNull { list.optJSONObject(it) } - .filter { it.optString("manifest").isNotEmpty() && it.optInt("productType") == 0 && it.optBoolean("owned", true) } + .filter { it.optInt("productType") == 0 && it.optBoolean("owned", true) && thirdParty(it.optString("configuration")) == null } + .sortedByDescending { it.optString("manifest").isNotEmpty() } val out = LinkedHashMap() for (key in listOf("spaceId")) for (g in games) { val space = g.optString(key).takeIf { it.isNotEmpty() } ?: continue @@ -147,19 +138,30 @@ object UbisoftLibrary { return out } - private val STEAM_ID = Regex("""^\s*steam_app_id:\s*['"]?(\d+)""", RegexOption.MULTILINE) - private val THIRD_PARTY = Regex("""^\s*third_party_platform:\s*\r?\n\s+name:\s*['"]?Steam\b""", setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE)) + private fun download(o: JSONObject) = listOfNotNull( + "productId" to o.optLong("productId").toString(), + o.optString("manifest").takeIf { it.isNotEmpty() }?.let { "manifest" to it }, + o.optString("appId").takeIf { it.isNotEmpty() }?.let { "appId" to it }, + executable(o.optString("configuration"))?.let { "exe" to it }, + ) - /** The Steam app of a product Ubisoft says is owned and installed through Steam. */ - internal fun steamApp(configuration: String): String? = - if (THIRD_PARTY.containsMatchIn(configuration)) STEAM_ID.find(configuration)?.groupValues?.get(1) else null - - /** Owned games Ubisoft delivers through Steam, by UbiServices space. */ - internal fun steamBySpace(owned: JSONObject?): Map { - val list = owned?.optJSONArray("games") ?: return emptyMap() - return (0 until list.length()).mapNotNull { list.optJSONObject(it) } - .filter { it.optInt("productType") == 0 && it.optBoolean("owned", true) && it.optString("spaceId").isNotEmpty() } - .mapNotNull { o -> steamApp(o.optString("configuration"))?.let { o.optString("spaceId") to it } }.toMap() + /** + * Games Connect owns and delivers itself. The profile's game list also names games only played through + * Ubisoft+, free weekends or another store; without an ownership answer that list is all there is. + */ + internal fun assemble(listed: List, owned: JSONObject?): List { + val known = owned?.optJSONArray("games") != null && owned.optString("error").isEmpty() + val bySpace = ownedBySpace(owned) + val matched = listed.map { g -> bySpace[g.id]?.let { g.copy(extra = g.extra + download(it)) } ?: g } + .filter { !known || it.extra["productId"] != null } + .let { games -> games.filter { g -> g.extra["productId"] == null || games.first { it.extra["productId"] == g.extra["productId"] } === g } } + .let { games -> games.filter { g -> g.extra["productId"] != null || games.none { it !== g && it.title == g.title && it.extra["productId"] != null } } } + val products = matched.mapNotNull { it.extra["productId"] }.toSet() + val unlisted = bySpace.filterKeys { space -> listed.none { it.id == space } }.filterValues { it.optLong("productId").toString() !in products }.mapNotNull { (space, o) -> + val title = title(o.optString("configuration")) ?: return@mapNotNull null + CatalogItem(Store.UBISOFT, space, title, null, owned = true, extra = mapOf("spaceId" to space) + download(o)) + } + return (matched + unlisted).sortedBy { it.title.lowercase() } } private val RELATIVE = Regex("""relative:\s*['"]?([^'"\r\n]+?)['"]?\s*$""", RegexOption.MULTILINE) @@ -205,29 +207,19 @@ object UbisoftLibrary { } val owned = UbisoftNative.call("owned", JSONObject().put("ticket", s.ticket).put("sessionId", s.sessionId)) owned?.optString("error")?.takeIf { it.isNotEmpty() }?.let { StoresState.logLine("Ubisoft: ownership: $it") } - val bySpace = ownedBySpace(owned) owned?.takeIf { it.optInt("manifestsAsked") > 0 }?.let { StoresState.logLine("Ubisoft: latest manifests: ${it.optInt("manifestsFound")} of ${it.optInt("manifestsAsked")} ${it.optString("manifestError")}".trim()) } - fun download(o: JSONObject) = listOfNotNull( - "productId" to o.optLong("productId").toString(), - o.optString("manifest").takeIf { it.isNotEmpty() }?.let { "manifest" to it }, - o.optString("appId").takeIf { it.isNotEmpty() }?.let { "appId" to it }, - executable(o.optString("configuration"))?.let { "exe" to it }, - ) val listed = all.distinctBy { it.id } - val onSteam = steamBySpace(owned) - val matched = listed.map { g -> bySpace[g.id]?.let { g.copy(extra = g.extra + download(it)) } ?: onSteam[g.id]?.let { g.copy(extra = g.extra + (UbisoftBackend.STEAM_APP to it)) } ?: g } - .let { games -> games.filter { g -> g.extra["productId"] == null || games.first { it.extra["productId"] == g.extra["productId"] } === g } } - .let { games -> games.filter { g -> g.extra["productId"] != null || games.none { it !== g && it.title == g.title && it.extra["productId"] != null } } } - val products = matched.mapNotNull { it.extra["productId"] }.toSet() - val unlisted = bySpace.filterKeys { space -> listed.none { it.id == space } }.filterValues { it.optLong("productId").toString() !in products }.mapNotNull { (space, o) -> - val title = title(o.optString("configuration")) ?: return@mapNotNull null - CatalogItem(Store.UBISOFT, space, title, null, owned = true, extra = mapOf("spaceId" to space) + download(o)) + val games = assemble(listed, owned) + ownedBySpace(owned).values.filter { it.optString("manifest").isEmpty() }.takeIf { it.isNotEmpty() }?.let { bare -> + StoresState.logLine("Ubisoft: owned without a manifest: " + bare.joinToString(", ") { (title(it.optString("configuration")) ?: "?") + "=" + it.optLong("productId") }) } - val games = (matched + unlisted).sortedBy { it.title.lowercase() } - StoresState.logLine("Ubisoft: ${bySpace.size} downloadable products; " + + StoresState.logLine("Ubisoft: ${ownedBySpace(owned).size} owned products; " + games.filter { it.extra.containsKey("productId") }.joinToString(", ") { "${it.title}=${it.extra["productId"]}" }) + listed.filter { g -> games.none { it.id == g.id } }.takeIf { it.isNotEmpty() }?.let { left -> + StoresState.logLine("Ubisoft: left out ${left.size} games Connect does not deliver to this account: " + left.joinToString(", ") { it.title }) + } post(gen) { StoresState.status.remove(Store.UBISOFT) StoresState.problems.remove(Store.UBISOFT) @@ -235,7 +227,7 @@ object UbisoftLibrary { StoresState.shelves[Store.UBISOFT] = com.droiddeck.launcher.stores.StoreShelves( trending = games.sortedByDescending { it.extra.containsKey("productId") }, art = games.mapNotNull { it.imageUrl }) } - StoresState.logLine("Ubisoft: ${games.size} owned games; on Steam: " + games.filter { it.extra.containsKey(UbisoftBackend.STEAM_APP) }.joinToString(", ") { "${it.title}=${it.extra[UbisoftBackend.STEAM_APP]}" }) + StoresState.logLine("Ubisoft: ${games.size} owned games") } catch (e: Exception) { StoresState.logLine("Ubisoft: library sync failed: ${e.javaClass.simpleName} ${e.message.orEmpty().take(200)}") post(gen) { StoresState.status.remove(Store.UBISOFT); StoresState.problems[Store.UBISOFT] = app.getString(R.string.stores_sync_failed) } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/ea/EaTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/ea/EaTest.kt index bb8aa159a6..83c03495ae 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/ea/EaTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/ea/EaTest.kt @@ -225,6 +225,20 @@ class EaTest { assertEquals(listOf("1", "3"), picked.map { it.first.offerId }) } + @Test fun anOwnedProductWithoutAnActiveGameDownloadIsLeftOut() { + fun row(id: String, type: String, tag: String = type, status: String = "ACTIVE") = + JSONObject().put("productId", id).put("entitlementType", type).put("entitlementTag", tag).put("status", status) + val rows = listOf( + row("DR:106479900", "DEFAULT", "VALIDATED_ONLINE_ACCESS"), + row("DR:231813200", "ORIGIN_DOWNLOAD", status = "DISABLED"), + row("Origin.OFR.50.0003426", "ONLINE_ACCESS"), + row("Origin.OFR.50.0003426", "ORIGIN_DOWNLOAD"), + row("Origin.OFR.50.0005237", "ORIGIN_DOWNLOAD"), + ) + assertEquals(setOf("DR:106479900", "DR:231813200"), EaLibrary.withoutGameDownload(rows).keys) + assertTrue(EaLibrary.withoutGameDownload(emptyList()).isEmpty()) + } + @Test fun ownedPageParses() { val page = JSONObject( """{"me":{"ownedGameProducts":{"next":"100","items":[{"originOfferId":"Origin.OFR.50.0001","product":{"id":"x","name":"N","downloadable":true,"gameSlug":"titanfall-2", diff --git a/app/src/test/java/com/droiddeck/launcher/stores/ubisoft/UbisoftTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/ubisoft/UbisoftTest.kt index 58e361db81..7f163ce351 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/ubisoft/UbisoftTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/ubisoft/UbisoftTest.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.stores.ubisoft +import com.droiddeck.launcher.stores.CatalogItem import com.droiddeck.launcher.stores.Store import com.droiddeck.launcher.stores.StoreGameSidecar import com.droiddeck.launcher.stores.StoreLaunch @@ -20,18 +21,28 @@ class UbisoftTest { private val steamConfig = "version: 2.0\r\nroot:\r\n name: Assassin's Creed Syndicate\r\n start_game:\r\n steam:\r\n steam_app_id: 368500\r\n" + " third_party_platform:\r\n name: Steam\r\n override_uplayid: 1875\r\n" - @Test fun aProductUbisoftDeliversThroughSteamNamesItsSteamApp() { - assertEquals("368500", UbisoftLibrary.steamApp(steamConfig)) - assertNull(UbisoftLibrary.steamApp("root:\n start_game:\n online:\n executables:\n - path:\n relative: bin/game.exe\n")) + private fun listed(space: String, name: String) = CatalogItem(Store.UBISOFT, space, name, null, owned = true, extra = mapOf("spaceId" to space)) + + private val owned = JSONObject().put("games", JSONArray() + .put(JSONObject().put("productId", 1957).put("spaceId", "space-s").put("productType", 0).put("owned", true).put("configuration", steamConfig)) + .put(JSONObject().put("productId", 109).put("spaceId", "space-sc").put("productType", 0).put("owned", true).put("manifest", "AB").put("configuration", "root: {}")) + .put(JSONObject().put("productId", 1961).put("spaceId", "space-addon").put("productType", 1).put("owned", true).put("manifest", "CD").put("configuration", steamConfig)) + .put(JSONObject().put("productId", 720).put("spaceId", "space-plus").put("productType", 0).put("owned", false).put("manifest", "EF").put("configuration", "root: {}")) + .put(JSONObject().put("productId", 3539).put("spaceId", "space-o").put("productType", 0).put("owned", true).put("configuration", "root: {}"))) + + @Test fun onlyGamesConnectDeliversAreInTheLibrary() { + val profile = listOf(listed("space-sc", "Splinter Cell"), listed("space-s", "Syndicate"), listed("space-plus", "Ubisoft+ Game"), listed("space-gone", "Free Weekend"), listed("space-o", "Origins")) + val games = UbisoftLibrary.assemble(profile, owned) + assertEquals(listOf("space-o", "space-sc"), games.map { it.id }) + assertEquals(listOf("3539", "109"), games.map { it.extra["productId"] }) + assertEquals(null, games.first().extra["manifest"]) + assertEquals("Steam", UbisoftLibrary.thirdParty(steamConfig)) } - @Test fun steamOwnedGamesAreKeyedByTheirSpace() { - val owned = JSONObject().put("games", JSONArray() - .put(JSONObject().put("productId", 1957).put("spaceId", "space-s").put("productType", 0).put("owned", true).put("configuration", steamConfig)) - .put(JSONObject().put("productId", 109).put("spaceId", "space-sc").put("productType", 0).put("owned", true).put("manifest", "AB").put("configuration", "root: {}")) - .put(JSONObject().put("productId", 1961).put("spaceId", "space-addon").put("productType", 1).put("owned", true).put("configuration", steamConfig))) - assertEquals(mapOf("space-s" to "368500"), UbisoftLibrary.steamBySpace(owned)) - assertEquals(setOf("space-sc"), UbisoftLibrary.ownedBySpace(owned).keys) + @Test fun withoutAnOwnershipAnswerTheProfileListStays() { + val profile = listOf(listed("space-sc", "Splinter Cell"), listed("space-gone", "Free Weekend")) + assertEquals(listOf("space-gone", "space-sc"), UbisoftLibrary.assemble(profile, JSONObject().put("error", "demux closed")).map { it.id }) + assertEquals(listOf("space-gone", "space-sc"), UbisoftLibrary.assemble(profile, null).map { it.id }) } @Test fun theEntitlementNamesTheGamesApplication() {