package org.meshbay.client.shell import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.net.Uri import android.view.Gravity import android.view.View import android.widget.Button import android.widget.LinearLayout import android.widget.TextView import androidx.webkit.WebViewCompat import androidx.webkit.WebViewFeature /** * The engine floor, checked before the page is loaded (design O6: verified, * not assumed). * * The WebView updates through the store independently of Android, so the floor * is a Chromium version, not an API level. What binds it: Ed25519 and X25519 in * WebCrypto (the handshake, chat and the group envelope) — Chromium 137 — and * the two androidx.webkit features the bridge is built on. Measured present on * WebView 145 (spike S-1); the floor itself still has to be confirmed on the * oldest real device to be supported. */ object EngineCheck { const val MIN_CHROMIUM = 137 fun problem(context: Context): String? { if (!WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER) || !WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) { return "This device's Android System WebView is too old for MeshBay." } val version = WebViewCompat.getCurrentWebViewPackage(context)?.versionName ?: return null val major = version.substringBefore('.').toIntOrNull() ?: return null return if (major < MIN_CHROMIUM) { "MeshBay needs Android System WebView $MIN_CHROMIUM or newer; this device has $version." } else null } fun screen(context: Context, problem: String): View = LinearLayout(context).apply { orientation = LinearLayout.VERTICAL gravity = Gravity.CENTER setPadding(48, 48, 48, 48) addView(TextView(context).apply { text = problem; textSize = 18f; gravity = Gravity.CENTER }) addView(Button(context).apply { text = "Update Android System WebView" setOnClickListener { val id = "com.google.android.webview" try { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$id"))) } catch (e: ActivityNotFoundException) { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$id"))) } } }) } }