Compare commits

...
3 changed files with 143 additions and 8 deletions

No files matched your search

@@ -349,7 +349,9 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl
releaseChecking = true
autoStatus = activity.getString(R.string.drivers_checking_latest)
Thread({
val problem = if (force || releasesStale()) runCatching { TurnipReleases.refresh(activity) }.exceptionOrNull()?.message else null
val failure = if (force || releasesStale()) runCatching { TurnipReleases.refresh(activity) }.exceptionOrNull() else null
val problem = failure?.message
val checkFailed = failure != null
val holdBack = !force && com.droiddeck.launcher.frontend.AutoComponents.constrained(activity)
runCatching { com.droiddeck.launcher.gpu.VulkanInfo.query() }
ui.post {
@@ -367,17 +369,23 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl
SessionPrefs.maliFallbackByAuto(activity), gpu.family.mali,
pair?.key?.let { DriverPairs.isNonAdreno(it) } == true,
)) endMaliFallback()
autoStatus = problem?.let { activity.getString(R.string.drivers_up_to_date_check_failed, it) }
?: activity.getString(R.string.upd_current_status)
autoStatus = if (checkFailed || TurnipReleases.cached(activity)?.failed?.contains(TurnipReleases.NON_ADRENO_LABEL) == true)
activity.getString(R.string.drivers_up_to_date_check_failed, problem ?: TurnipReleases.NON_ADRENO_LABEL)
else activity.getString(R.string.upd_current_status)
}
gpu.family == GpuInfo.Family.POWERVR && (pair == null || !pair.complete) &&
(checkFailed || TurnipReleases.cached(activity)?.failed?.contains(TurnipReleases.NON_ADRENO_LABEL) == true) -> {
SessionPrefs.ensurePowerVrAutoDrivers(activity)
autoStatus = activity.getString(R.string.upd_couldnt_check, problem ?: TurnipReleases.NON_ADRENO_LABEL)
refreshDrivers()
}
gpu.family == GpuInfo.Family.POWERVR && (pair == null || !pair.complete) -> {
// RADV is not published right now: the Xclipse falls back to the system route.
SessionPrefs.ensurePowerVrAutoDrivers(activity)
autoStatus = activity.getString(R.string.drivers_powervr_builtin)
refreshDrivers()
}
gpu.family.mali && (pair == null || !pair.complete) &&
(problem != null || TurnipReleases.cached(activity)?.failed?.contains(TurnipReleases.NON_ADRENO_LABEL) == true) -> {
(checkFailed || TurnipReleases.cached(activity)?.failed?.contains(TurnipReleases.NON_ADRENO_LABEL) == true) -> {
// The list could not be read: nothing is known to be missing, so a working route stays.
// With no open driver, Venus or bridge the session would run the runtime's Turnip,
// which finds no GPU on a Mali, so the stand-in goes on anyway.
@@ -2,12 +2,21 @@ package com.droiddeck.launcher
import android.app.Activity
import android.content.Context
import android.net.Uri
import android.os.Handler
import android.os.Looper
import com.droiddeck.launcher.session.QuestExperimental
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.gpu.DriverBundle
import com.droiddeck.launcher.gpu.DriverPairs
import com.droiddeck.launcher.gpu.GpuInfo
import com.droiddeck.launcher.gpu.GpuInfo.Family
import com.droiddeck.launcher.gpu.LinuxVulkanDriverManager
import com.droiddeck.launcher.gpu.TpUbwcHint
import com.droiddeck.launcher.gpu.TurnipDriver
import com.droiddeck.launcher.gpu.TurnipReleases
import com.droiddeck.launcher.session.QuestExperimental
import com.droiddeck.launcher.session.SessionPrefs
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
@@ -18,9 +27,13 @@ import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import org.robolectric.shadows.ShadowBuild
import org.robolectric.util.ReflectionHelpers
import java.io.File
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
@@ -117,4 +130,118 @@ class DriverMenusAutoTest {
menus.refreshDrivers()
assertTrue(menus.tpUbwcRestartRequired())
}
private fun library(libc: String) = ByteArray(64).also {
byteArrayOf(0x7f, 'E'.code.toByte(), 'L'.code.toByte(), 'F'.code.toByte(), 2, 1).copyInto(it)
it[18] = 0xB7.toByte()
} + libc.toByteArray() + ByteArray(1)
private fun bundleZip(context: Context): Uri {
val manifest = JSONObject()
.put("package", "PanVK Mali JM").put("version", "1.0").put("tag", "panvk-mali-jm")
.put("drivers", JSONObject()
.put("android", JSONObject().put("path", "android"))
.put("linux", JSONObject().put("path", "linux")))
val file = File.createTempFile("bundle", ".zip", context.cacheDir)
ZipOutputStream(file.outputStream()).use { z ->
fun put(name: String, data: ByteArray) { z.putNextEntry(ZipEntry(name)); z.write(data); z.closeEntry() }
put("manifest.json", manifest.toString().toByteArray())
put("android/meta.json", JSONObject().put("name", "PanVK Mali JM").put("libraryName", "libvulkan_freedreno.so").toString().toByteArray())
put("android/libvulkan_freedreno.so", library("libc.so"))
put("linux/meta.json", JSONObject().put("name", "PanVK Mali JM").toString().toByteArray())
put("linux/libvulkan_freedreno.so", library("libc.so.6"))
}
return Uri.fromFile(file)
}
private fun setCachedMaliJmPair(context: Context, assetName: String = "PanVK-JM-Pair.zip") {
val asset = JSONObject()
.put("source", TurnipReleases.NON_ADRENO_LABEL).put("tag", "panvk-mali-jm")
.put("name", assetName).put("url", "https://example/$assetName")
.put("size", 1L).put("linux", false).put("label", "Android + Linux · PanVK Mali JM")
.put("sha256", "0".repeat(64)).put("pair", DriverPairs.NAD_MALI_JM)
.put("bundle", true).put("id", 1L).put("updated_at", "2026-01-01T00:00:00Z")
val stored = JSONObject().put("assets", JSONArray().put(asset))
.put("latest", JSONArray()).put("failed", JSONArray())
.put("checkedAt", System.currentTimeMillis())
context.getSharedPreferences("turnip_releases", Context.MODE_PRIVATE)
.edit().putString("latest", stored.toString()).commit()
}
private fun prepareActiveMaliJmPair(assetName: String = "PanVK-JM-Pair.zip"): Pair<Activity, DriverMenus> {
ShadowBuild.setModel("Generic phone")
ShadowBuild.setDevice("generic")
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
val bundle = DriverBundle.install(activity, bundleZip(activity))
setCachedMaliJmPair(activity, assetName)
TurnipReleases.recordDownload(activity, TurnipReleases.cached(activity)!!.assets.first(), bundle.id)
SessionPrefs.setGpuDriverMode(activity, SessionPrefs.GPU_DRIVERS_AUTO)
SessionPrefs.setAndroidDriver(activity, TurnipDriver.AUTO)
SessionPrefs.setLinuxDriver(activity, bundle.linuxId)
val menus = DriverMenus(activity, Handler(Looper.getMainLooper()))
ReflectionHelpers.setField(menus, "gpu", GpuInfo("Mali-G78", 78, Family.MALI_JM, "", false))
menus.refreshDrivers()
return activity to menus
}
@Test fun activeRecommendedPairWithNullRefreshFailureShowsCheckFailureStatus() {
val (activity, menus) = prepareActiveMaliJmPair()
val original = TurnipReleases.fetch
TurnipReleases.fetch = { _, _, _ -> throw java.io.IOException(null as String?) }
try {
menus.ensureAuto(force = true)
for (i in 0..40) {
shadowOf(Looper.getMainLooper()).idle()
Thread.sleep(50)
shadowOf(Looper.getMainLooper()).idle()
if (!menus.releaseChecking) break
}
assertEquals(activity.getString(R.string.drivers_up_to_date_check_failed, TurnipReleases.NON_ADRENO_LABEL), menus.autoStatus)
} finally { TurnipReleases.fetch = original }
}
@Test fun activeRecommendedPairWithSuccessfulRefreshShowsCurrentStatus() {
val (activity, menus) = prepareActiveMaliJmPair()
menus.ensureAuto(force = false)
for (i in 0..40) {
shadowOf(Looper.getMainLooper()).idle()
Thread.sleep(50)
shadowOf(Looper.getMainLooper()).idle()
if (!menus.releaseChecking) break
}
assertEquals(activity.getString(R.string.upd_current_status), menus.autoStatus)
}
@Test fun activeRecommendedPairWithSuccessfulForcedRefreshShowsCurrentStatus() {
val (activity, menus) = prepareActiveMaliJmPair("PanVK-Mali-JM-Pair.zip")
val asset = TurnipReleases.cached(activity)!!.assets.single()
val releases = JSONArray().put(JSONObject()
.put("tag_name", asset.tag)
.put("assets", JSONArray().put(JSONObject()
.put("name", asset.name).put("browser_download_url", asset.url)
.put("digest", "sha256:" + asset.sha256).put("size", 1L)
.put("id", 1L).put("updated_at", "2026-01-01T00:00:00Z"))))
val original = TurnipReleases.fetch
val requests = java.util.concurrent.atomic.AtomicInteger()
TurnipReleases.fetch = { _, _, url ->
if (url.contains("droiddeck-nonadreno-drivers/releases")) {
requests.incrementAndGet()
releases.toString()
} else "[]"
}
try {
menus.ensureAuto(force = true)
for (i in 0..40) {
shadowOf(Looper.getMainLooper()).idle()
Thread.sleep(50)
shadowOf(Looper.getMainLooper()).idle()
if (!menus.releaseChecking) break
}
assertFalse(menus.releaseChecking)
assertTrue(requests.get() > 0)
assertTrue(TurnipReleases.cached(activity)!!.failed.isEmpty())
assertEquals(activity.getString(R.string.upd_current_status), menus.autoStatus)
} finally { TurnipReleases.fetch = original }
}
}