mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat: auto driver picks come from a Drivers-CI manifest with per-GPU fallbacks (#977)
This commit is contained in:
1 parent
632f13d1b2
commit
1fbe103ffe
7 files changed
+162
-10
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package com.droiddeck.launcher.gpu
|
||||
|
||||
import com.droiddeck.launcher.gpu.GpuInfo.Family
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
object AutoPicks {
|
||||
const val URL = "https://raw.githubusercontent.com/Droid-Deck/Drivers-CI/main/auto-drivers.json"
|
||||
const val SCHEMA = 1
|
||||
const val NEWEST_DD_TURNIP = DriverPairs.DD_TURNIP
|
||||
|
||||
class Rule(
|
||||
val families: Set<Family>,
|
||||
val models: Set<Int> = emptySet(),
|
||||
val oneUi8Gen2: Boolean? = null,
|
||||
val minSdk: Int = 0,
|
||||
val blobMin: Int = 0,
|
||||
val blobMax: Int = Int.MAX_VALUE,
|
||||
val prefer: List<String>,
|
||||
) {
|
||||
fun matches(gpu: GpuInfo, sdk: Int, blob: Int?): Boolean =
|
||||
gpu.family in families &&
|
||||
(models.isEmpty() || gpu.model in models) &&
|
||||
(oneUi8Gen2 == null || gpu.oneUi8Gen2 == oneUi8Gen2) &&
|
||||
sdk >= minSdk &&
|
||||
(blobMin == 0 && blobMax == Int.MAX_VALUE || blob != null && blob in blobMin..blobMax)
|
||||
}
|
||||
|
||||
val BUILT_IN = listOf(
|
||||
Rule(setOf(Family.A8XX), models = setOf(840), prefer = listOf(NEWEST_DD_TURNIP, DriverPairs.WN_BALANCED)),
|
||||
Rule(setOf(Family.A8XX), prefer = listOf(DriverPairs.WN_BALANCED)),
|
||||
Rule(setOf(Family.A7XX_LOW), prefer = listOf(DriverPairs.BANNER_710)),
|
||||
Rule(setOf(Family.A7XX), oneUi8Gen2 = true, prefer = listOf(DriverPairs.BANNER_ONEUI)),
|
||||
Rule(setOf(Family.A7XX, Family.A6XX), prefer = listOf(DriverPairs.BANNER)),
|
||||
Rule(setOf(Family.ADRENO_UNKNOWN), minSdk = 36, prefer = listOf(DriverPairs.WN_BALANCED)),
|
||||
Rule(setOf(Family.ADRENO_UNKNOWN), prefer = listOf(DriverPairs.BANNER)),
|
||||
)
|
||||
|
||||
fun parse(text: String?): List<Rule>? = runCatching {
|
||||
val json = JSONObject(text ?: return null)
|
||||
if (json.optInt("schemaVersion") != SCHEMA) return null
|
||||
val rules = json.getJSONArray("rules")
|
||||
(0 until rules.length()).mapNotNull { i -> rule(rules.getJSONObject(i)) }.takeIf { it.isNotEmpty() }
|
||||
}.getOrNull()
|
||||
|
||||
private fun rule(o: JSONObject): Rule? {
|
||||
val families = strings(o.optJSONArray("families")).mapNotNull { name -> Family.values().firstOrNull { it.name == name } }.toSet()
|
||||
val prefer = strings(o.optJSONArray("prefer"))
|
||||
if (families.isEmpty() || prefer.isEmpty()) return null
|
||||
val models = o.optJSONArray("models")?.let { a -> (0 until a.length()).map { a.getInt(it) }.toSet() } ?: emptySet()
|
||||
return Rule(
|
||||
families, models,
|
||||
if (o.has("oneUi8Gen2")) o.getBoolean("oneUi8Gen2") else null,
|
||||
o.optInt("minSdk", 0), o.optInt("blobMin", 0), o.optInt("blobMax", Int.MAX_VALUE), prefer,
|
||||
)
|
||||
}
|
||||
|
||||
private fun strings(a: JSONArray?): List<String> = a?.let { (0 until it.length()).map { i -> it.getString(i) } }.orEmpty()
|
||||
|
||||
fun preferences(gpu: GpuInfo, rules: List<Rule>, sdk: Int, blob: Int?): List<String> =
|
||||
rules.firstOrNull { it.matches(gpu, sdk, blob) }?.prefer.orEmpty()
|
||||
|
||||
fun blobVersion(driverVersion: String?): Int? = driverVersion?.split('.')?.getOrNull(1)?.toIntOrNull()
|
||||
}
|
||||
@@ -61,13 +61,17 @@ object DriverPairs {
|
||||
}
|
||||
}
|
||||
|
||||
fun recommendedKey(gpu: GpuInfo, pairs: List<DriverPair>): String? = when (gpu.family) {
|
||||
Family.NOT_ADRENO -> null
|
||||
Family.A8XX -> if (gpu.model == 840) newestDdTurnip(pairs) ?: WN_BALANCED else WN_BALANCED
|
||||
Family.A7XX_LOW -> BANNER_710
|
||||
Family.A7XX -> if (gpu.oneUi8Gen2) BANNER_ONEUI else BANNER
|
||||
Family.A6XX -> BANNER
|
||||
Family.ADRENO_UNKNOWN -> if (android.os.Build.VERSION.SDK_INT >= 36) WN_BALANCED else BANNER
|
||||
fun recommendedKey(
|
||||
gpu: GpuInfo, pairs: List<DriverPair>,
|
||||
rules: List<AutoPicks.Rule> = AutoPicks.BUILT_IN, bad: Set<String> = emptySet(),
|
||||
sdk: Int = android.os.Build.VERSION.SDK_INT, blob: Int? = null,
|
||||
): String? {
|
||||
if (gpu.family == Family.NOT_ADRENO) return null
|
||||
val keys = AutoPicks.preferences(gpu, rules, sdk, blob)
|
||||
.ifEmpty { AutoPicks.preferences(gpu, AutoPicks.BUILT_IN, sdk, blob) }
|
||||
.mapNotNull { if (it == AutoPicks.NEWEST_DD_TURNIP) newestDdTurnip(pairs) else it }
|
||||
return keys.firstOrNull { key -> pairs.any { it.key == key && it.complete && AutoDriverTrial.release(it) !in bad } }
|
||||
?: keys.firstOrNull()
|
||||
}
|
||||
|
||||
fun newestDdTurnip(pairs: List<DriverPair>): String? = pairs
|
||||
|
||||
@@ -19,6 +19,7 @@ object TurnipReleases {
|
||||
private const val PREFS = "turnip_releases"
|
||||
private const val KEY_RELEASE = "latest"
|
||||
private const val KEY_DOWNLOADS = "downloads"
|
||||
private const val KEY_PICKS = "autoPicks"
|
||||
|
||||
class Asset(val source: String, val tag: String, val name: String, val url: String, val size: Long, val linux: Boolean, val label: String,
|
||||
val sha256: String = "", val pair: String = "", val bundle: Boolean = false)
|
||||
@@ -57,6 +58,9 @@ object TurnipReleases {
|
||||
},
|
||||
)
|
||||
|
||||
fun autoPicks(context: Context): List<AutoPicks.Rule> =
|
||||
AutoPicks.parse(prefs(context).getString(KEY_PICKS, null)) ?: AutoPicks.BUILT_IN
|
||||
|
||||
fun cached(context: Context): Check? {
|
||||
val raw = prefs(context).getString(KEY_RELEASE, null) ?: return null
|
||||
return runCatching { parse(JSONObject(raw)) }.getOrNull()
|
||||
@@ -100,6 +104,10 @@ object TurnipReleases {
|
||||
}
|
||||
}
|
||||
if (failed.size == SOURCES.size) throw lastError ?: IOException("no source answered")
|
||||
runCatching { get(context, AutoPicks.URL, AutoPicks.URL) }
|
||||
.onFailure { Log.i(TAG, "auto picks: ${it.message}") }
|
||||
.getOrNull()?.takeIf { AutoPicks.parse(it) != null }
|
||||
?.let { prefs(context).edit().putString(KEY_PICKS, it).apply() }
|
||||
val stored = JSONObject().put("assets", assets).put("latest", latest)
|
||||
.put("failed", JSONArray(failed)).put("checkedAt", System.currentTimeMillis())
|
||||
prefs(context).edit().putString(KEY_RELEASE, stored.toString()).apply()
|
||||
|
||||
Reference in new issue
Block a user