Skip to content

Debloat your Android TV, install apps, browse and transfer files on it, all from your phone. Just 3 MB, no tracking, no root, no PC.

Close the remote alert with Back, checked in the same call

jesse-agent-232673726ae927b
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/ConnectionPrompt.kt b/adb/src/main/kotlin/app/tellyscope/adb/ConnectionPrompt.kt
index 08e1020..388bca2 100644
--- a/adb/src/main/kotlin/app/tellyscope/adb/ConnectionPrompt.kt
+++ b/adb/src/main/kotlin/app/tellyscope/adb/ConnectionPrompt.kt
@@ -31,13 +31,15 @@ class ConnectionPrompt(private val shell: AdbShell) {
}
/**
- * Presses OK once on Amazon's alert, for the user who can't, as the remote it complains about
- * isn't connected. Only while the alert still holds focus over the prompt, checked just before:
- * once the prompt has focus, no key is ever sent, so this can't answer it. False when nothing was sent.
+ * Closes Amazon's alert with one Back, for the user who can't, as the remote it complains about
+ * isn't connected. Only while the alert holds focus over the prompt: checked with a screen dump,
+ * then again in the same shell call as the key, as the alert can close by itself meanwhile. Back,
+ * not OK, so a key that still lands on the prompt can only cancel it, never allow it.
+ * False when nothing was sent.
*/
suspend fun closeAlert(): Boolean {
if (!alertOnTop()) return false
- return shell.shell("input keyevent $KEY_OK").exitCode == 0
+ return shell.shell("dumpsys window | grep -q '$ALERT_FOCUS_SH' && input keyevent $KEY_BACK").exitCode == 0
}
/** A system prompt is up but a bare `android` window holds focus, and that window is Amazon's alert. */
@@ -76,8 +78,8 @@ class ConnectionPrompt(private val shell: AdbShell) {
companion object {
private const val DUMP = "/data/local/tmp/tellyscope-ui.xml"
- /** DPAD_CENTER: the remote's OK. */
- private const val KEY_OK = 23
+ /** The remote's Back: it closes the alert, and on the prompt it means Cancel. */
+ private const val KEY_BACK = 4
private val NODE = Regex("<node [^>]*>")
private val ATTR = Regex("([\\w-]+)=\"([^\"]*)\"")
private val BOUNDS = Regex("\\[(\\d+),(\\d+)]\\[(\\d+),(\\d+)]")
@@ -98,6 +100,8 @@ class ConnectionPrompt(private val shell: AdbShell) {
private val FOCUS = Regex("mCurrentFocus|mFocusedWindow")
/** Fire OS's alert is a window of the system itself, `android`, with no activity. */
private val ALERT_FOCUS = Regex("mCurrentFocus=Window\\{\\S+ u\\d+ android}")
+ /** [ALERT_FOCUS] for the TV's grep, in the call that sends the key. */
+ private const val ALERT_FOCUS_SH = "mCurrentFocus=Window{[^ ]* u[0-9]* android}"
/** Its OK button, the one id that says it's the remote alert and not some other system window. */
private const val ALERT_OK = "amazon.fireos:id/ok_button"
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ConnectionPromptTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ConnectionPromptTest.kt
index 7a72153..df90022 100644
--- a/adb/src/test/kotlin/app/tellyscope/adb/ConnectionPromptTest.kt
+++ b/adb/src/test/kotlin/app/tellyscope/adb/ConnectionPromptTest.kt
@@ -85,23 +85,32 @@ class ConnectionPromptTest {
assertEquals(ConnectionRequest("", canAlwaysAllow = false, behindAlert = true), ConnectionPrompt(tv(alert, alertFocus)).pending())
}
- @Test fun okIsPressedOnceAndOnlyOnTheAlert() = runTest {
+ private val back = "dumpsys window | grep -q 'mCurrentFocus=Window{[^ ]* u[0-9]* android}' && input keyevent 4"
+
+ @Test fun backIsSentOnceAndCheckedInTheSameCall() = runTest {
val sh = tv(alert, alertFocus)
assertTrue(ConnectionPrompt(sh).closeAlert())
- assertEquals(listOf("input keyevent 23"), sh.ran.filter { it.startsWith("input") })
+ assertEquals(listOf(back), sh.ran.filter { "input" in it })
}
@Test fun noKeyOnceThePromptHasFocus() = runTest {
val sh = tv(dump())
assertFalse(ConnectionPrompt(sh).closeAlert())
- assertFalse(sh.ran.any { it.startsWith("input") })
+ assertFalse(sh.ran.any { "input" in it })
+ }
+
+ @Test fun theAlertClosingDuringTheDumpSendsNothing() = runTest {
+ // The TV's grep finds no alert by the final check, so `&&` never runs the key.
+ val sh = tv(alert, alertFocus).apply { answer = { if (it == back) ShellResult("", 1) else null } }
+ assertFalse(ConnectionPrompt(sh).closeAlert())
+ assertEquals(listOf(back), sh.ran.filter { "input" in it })
}
@Test fun anotherSystemWindowIsNotTheAlert() = runTest {
val sh = tv(alert.replace("amazon.fireos:id/ok_button", "android:id/button1"), alertFocus)
assertNull(ConnectionPrompt(sh).pending())
assertFalse(ConnectionPrompt(sh).closeAlert())
- assertFalse(sh.ran.any { it.startsWith("input") })
+ assertFalse(sh.ran.any { "input" in it })
}
@Test fun theAlertAloneIsNoPrompt() = runTest {
diff --git a/app/src/main/java/app/tellyscope/ui/RequestDialog.kt b/app/src/main/java/app/tellyscope/ui/RequestDialog.kt
index cac078a..1efad70 100644
--- a/app/src/main/java/app/tellyscope/ui/RequestDialog.kt
+++ b/app/src/main/java/app/tellyscope/ui/RequestDialog.kt
@@ -81,7 +81,7 @@ fun RequestDialog(
/**
* The same dialog while the prompt is under Fire OS's alert: no fingerprint, so no Allow and no Deny.
- * Press OK on the TV sends one OK to the alert, for when the remote it complains about isn't there.
+ * Press OK on the TV closes the alert with one Back, for when the remote it complains about isn't there.
* Close answers nothing.
*/
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 486d491..d7db786 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -1446,7 +1446,7 @@ class TellyscopeViewModel(
}
/**
- * Press OK on the TV, on a prompt under Fire OS's remote alert: one OK, sent only while the alert has focus.
+ * Press OK on the TV, on a prompt under Fire OS's remote alert: one Back, sent only while the alert has focus.
* Then a fresh read, so the prompt itself, with its fingerprint, takes over without waiting for the next check.
*/
fun closeAlert() {