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.

Reset TV: put a TV back to how it shipped, from ⋮, with one Undo

jesse-agent-2327ce11235b74a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 599be74..f1bd1c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,9 @@ until this file has a section for its version.
## Unreleased
- **New:** Share Tellyscope, in ⋮ and in Settings, sends a friend the GitHub link. [#191](../../pull/191)
+- **New:** Reset TV, in ⋮: turn your TV back to how it shipped, with one Undo. [#192](../../pull/192)
+ - Turns preinstalled apps back on and brings back uninstalled ones; apps the maker shipped off stay off.
+ - Makes the TV's own launcher Home again; launchers you installed stay installed.
## 0.11.0 — 2026-10-27
diff --git a/adb/src/main/kotlin/app/tellyscope/adb/Reset.kt b/adb/src/main/kotlin/app/tellyscope/adb/Reset.kt
new file mode 100644
index 0000000..6180067
--- /dev/null
+++ b/adb/src/main/kotlin/app/tellyscope/adb/Reset.kt
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-3.0-only
+package app.tellyscope.adb
+
+/**
+ * What Reset TV would change on the TV's own apps. [turnOn]: preinstalled apps someone turned off
+ * by hand, from Settings, a phone or a tool; Android marks those "disabled by the user". [bringBack]:
+ * preinstalled apps uninstalled for this user, which are still on the TV. [shippedOff]: preinstalled
+ * apps the maker shipped switched off; Reset leaves them off.
+ */
+data class ResetScan(val turnOn: List<String>, val bringBack: List<String>, val shippedOff: List<String>)
+
+/**
+ * Reset TV's reads and changes, on preinstalled apps only. App data and sign-ins stay throughout:
+ * nothing here clears data.
+ */
+class Reset(private val shell: AdbShell) {
+
+ suspend fun scan(): ResetScan {
+ val system = names("pm list packages -s")
+ val off = names("pm list packages -s -d")
+ val gone = names("pm list packages -s -u") - system
+ val state = states((off + gone).sorted())
+ return ResetScan(
+ turnOn = off.filter { state[it]?.enabled == DISABLED_USER }.sorted(),
+ // Android 10+ leaves some apps out for a type of user on purpose; those never shipped on.
+ bringBack = gone.filter { state[it]?.let { s -> !s.installed && s.uninstallReason != USER_TYPE } == true }.sorted(),
+ shippedOff = off.filter { state[it]?.enabled.let { e -> e != null && e != DISABLED_USER } }.sorted(),
+ )
+ }
+
+ /** Turns [pkg] back on. Throws with the TV's answer when it refuses. */
+ suspend fun turnOn(pkg: String) = exec("pm enable --user 0 ${checked(pkg)}") { "enabled" in it }
+
+ /** Turns [pkg] off again, for Undo. */
+ suspend fun turnOff(pkg: String) = exec("pm disable-user --user 0 ${checked(pkg)}") { "disabled-user" in it }
+
+ /** Installs [pkg] again for this user from the copy still on the TV. */
+ suspend fun bringBack(pkg: String) = exec("pm install-existing --user 0 ${checked(pkg)}") { "installed for user" in it }
+
+ /**
+ * Uninstalls [pkg] for this user again, keeping its data, for Undo of [bringBack]. The only
+ * `--user 0` uninstall Tellyscope runs, and only on apps Reset itself brought back.
+ */
+ suspend fun remove(pkg: String) = exec("pm uninstall -k --user 0 ${checked(pkg)}") { "Success" in it }
+
+ private suspend fun names(command: String) = Parsers.packages(shell.shell(command).output).map { it.name }.toSet()
+
+ /** Each package's state for user 0, in one call: whether it's installed, how it's enabled, and why it was uninstalled. */
+ private suspend fun states(pkgs: List<String>): Map<String, UserState> {
+ val safe = pkgs.filter { Actions.PACKAGE.matches(it) }
+ if (safe.isEmpty()) return emptyMap()
+ val out = shell.shell(
+ "for p in ${safe.joinToString(" ")}; do echo \"@@\$p\"; dumpsys package \"\$p\" | grep -E '^ *User 0:|uninstallReason='; done",
+ ).output
+ return out.split("@@").drop(1).mapNotNull { block ->
+ val lines = block.lines()
+ val pkg = lines.first().trim()
+ // An updated system app lists itself twice; the first is the one that counts.
+ val user = lines.firstOrNull { it.trim().startsWith("User 0:") } ?: return@mapNotNull null
+ val reason = lines.dropWhile { it !== user }.firstNotNullOfOrNull { Regex("uninstallReason=(\\d+)").find(it) }
+ pkg to UserState(
+ installed = Regex("installed=(\\w+)").find(user)?.groupValues?.get(1) != "false",
+ enabled = Regex("enabled=(\\d+)").find(user)?.groupValues?.get(1)?.toIntOrNull(),
+ uninstallReason = reason?.groupValues?.get(1)?.toIntOrNull(),
+ )
+ }.toMap()
+ }
+
+ private suspend fun exec(command: String, ok: (String) -> Boolean) {
+ val r = shell.shell("$command 2>&1")
+ if (r.exitCode != 0 || !ok(r.output)) throw IllegalStateException(r.output.trim().ifEmpty { "the TV refused" })
+ }
+
+ private fun checked(pkg: String) = pkg.also { require(Actions.PACKAGE.matches(it)) { "not a package name: $it" } } // it goes into a shell line
+
+ private data class UserState(val installed: Boolean, val enabled: Int?, val uninstallReason: Int?)
+
+ private companion object {
+ /** PackageManager's COMPONENT_ENABLED_STATE_DISABLED_USER: what `pm disable-user` and Settings' Disable set. */
+ const val DISABLED_USER = 3
+ /** PackageManager's UNINSTALL_REASON_USER_TYPE: never installed for this kind of user. */
+ const val USER_TYPE = 1
+ }
+}
diff --git a/adb/src/test/kotlin/app/tellyscope/adb/ResetTest.kt b/adb/src/test/kotlin/app/tellyscope/adb/ResetTest.kt
new file mode 100644
index 0000000..94e6f18
--- /dev/null
+++ b/adb/src/test/kotlin/app/tellyscope/adb/ResetTest.kt
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-3.0-only
+package app.tellyscope.adb
+
+import kotlinx.coroutines.test.runTest
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
+import kotlin.test.assertTrue
+
+class ResetTest {
+ private fun tv(states: String) = FakeShell(
+ mapOf(
+ "pm list packages -s -d" to ok("package:com.google.android.tvlauncher\npackage:com.netflix.ninja\npackage:com.maker.factorytest\npackage:com.maker.demo\n"),
+ "pm list packages -s -u" to ok("package:com.google.android.tvlauncher\npackage:com.netflix.ninja\npackage:com.google.android.youtube.tvkids\npackage:com.maker.kiosk\npackage:com.android.settings\n"),
+ "pm list packages -s" to ok("package:com.google.android.tvlauncher\npackage:com.netflix.ninja\npackage:com.android.settings\n"),
+ "for p in" to ok(states),
+ ),
+ )
+
+ private val states = """
+ @@com.google.android.tvlauncher
+ User 0: ceDataInode=1 installed=true hidden=false suspended=false stopped=false notLaunched=false enabled=3 instant=false
+ uninstallReason=0
+ @@com.google.android.youtube.tvkids
+ User 0: ceDataInode=0 installed=false hidden=false suspended=false stopped=true notLaunched=true enabled=0 instant=false
+ uninstallReason=0
+ @@com.maker.demo
+ User 0: installed=true hidden=false stopped=false notLaunched=false enabled=4
+ @@com.maker.factorytest
+ User 0: ceDataInode=3 installed=true hidden=false enabled=2 instant=false
+ uninstallReason=0
+ @@com.maker.kiosk
+ User 0: ceDataInode=0 installed=false hidden=false enabled=0 instant=false
+ uninstallReason=1
+ @@com.netflix.ninja
+ User 0: ceDataInode=4 installed=true hidden=false enabled=3 instant=false
+ uninstallReason=0
+ User 0: ceDataInode=4 installed=true hidden=false enabled=0 instant=false
+ """.trimIndent()
+
+ @Test fun findsWhatWasTurnedOffOrUninstalledByHand() = runTest {
+ val scan = Reset(tv(states)).scan()
+ assertEquals(listOf("com.google.android.tvlauncher", "com.netflix.ninja"), scan.turnOn)
+ // Left out for this kind of user by Android itself: it never shipped on.
+ assertEquals(listOf("com.google.android.youtube.tvkids"), scan.bringBack)
+ assertEquals(listOf("com.maker.demo", "com.maker.factorytest"), scan.shippedOff)
+ }
+
+ @Test fun anAppWhoseStateTheTvDidntSayIsLeftAlone() = runTest {
+ val scan = Reset(tv("")).scan()
+ assertEquals(ResetScan(emptyList(), emptyList(), emptyList()), scan)
+ }
+
+ @Test fun readsEveryCandidateInOneCall() = runTest {
+ val sh = tv(states)
+ Reset(sh).scan()
+ assertEquals(1, sh.ran.count { it.startsWith("for p in") })
+ assertTrue(sh.ran.none { it.startsWith("dumpsys") })
+ }
+
+ @Test fun changesRunPerUserAndKeepData() = runTest {
+ val sh = FakeShell(
+ mapOf(
+ "pm enable" to ok("Package com.netflix.ninja new state: enabled\n"),
+ "pm disable-user" to ok("Package com.netflix.ninja new state: disabled-user\n"),
+ "pm install-existing" to ok("Package com.google.android.youtube.tvkids installed for user: 0\n"),
+ "pm uninstall" to ok("Success\n"),
+ ),
+ )
+ val r = Reset(sh)
+ r.turnOn("com.netflix.ninja")
+ r.turnOff("com.netflix.ninja")
+ r.bringBack("com.google.android.youtube.tvkids")
+ r.remove("com.google.android.youtube.tvkids")
+ assertEquals(
+ listOf(
+ "pm enable --user 0 com.netflix.ninja 2>&1",
+ "pm disable-user --user 0 com.netflix.ninja 2>&1",
+ "pm install-existing --user 0 com.google.android.youtube.tvkids 2>&1",
+ "pm uninstall -k --user 0 com.google.android.youtube.tvkids 2>&1",
+ ),
+ sh.ran,
+ )
+ }
+
+ @Test fun aRefusalThrowsWithTheTvsAnswer() = runTest {
+ val sh = FakeShell(mapOf("pm enable" to ShellResult("Error: java.lang.SecurityException: Shell cannot change component state", 255)))
+ val e = assertFailsWith<IllegalStateException> { Reset(sh).turnOn("com.netflix.ninja") }
+ assertTrue(e.message!!.contains("Shell cannot change"))
+ }
+
+ @Test fun refusesAnythingButAPackageName() = runTest {
+ assertFailsWith<IllegalArgumentException> { Reset(FakeShell()).turnOn("com.foo; reboot") }
+ }
+}
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index 8a55c87..55c974f 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -60,6 +60,8 @@ import app.tellyscope.ui.DeviceActions
import app.tellyscope.ui.DeviceTabsScreen
import app.tellyscope.ui.Done
import app.tellyscope.ui.HistoryScreen
+import app.tellyscope.ui.ResetActions
+import app.tellyscope.ui.ResetScreen
import app.tellyscope.ui.LauncherActions
import app.tellyscope.ui.LauncherScreen
import app.tellyscope.ui.LocalNow
@@ -194,6 +196,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
var remote by rememberSaveable { mutableStateOf(false) }
var advanced by rememberSaveable { mutableStateOf(false) }
var history by rememberSaveable { mutableStateOf(false) }
+ var resetting by rememberSaveable { mutableStateOf(false) }
// The TV's page comes back on the tab it was left on, from History or any screen its menu opens.
var tvTab by rememberSaveable { mutableStateOf(TvTab.Overview) }
var debloat by rememberSaveable { mutableStateOf(false) }
@@ -223,10 +226,10 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
LoggedOutSnackbars(snackbar, { state.devices }, { state.selectedId }, onView = vm::select)
// A newly connected TV becomes the selection; leave the add flow then, not on tap.
- LaunchedEffect(state.selectedId) { adding = false; remote = false; advanced = false; history = false; debloat = false; settings = false; access = false; rejoinId = null }
+ LaunchedEffect(state.selectedId) { adding = false; remote = false; advanced = false; history = false; resetting = false; debloat = false; settings = false; access = false; rejoinId = null }
// Logged out mid-screen: the page takes over, and the TV comes back on Overview once allowed again.
val loggedOutAt = state.selected?.loggedOutAt
- LaunchedEffect(loggedOutAt) { if (loggedOutAt != null) { remote = false; advanced = false; history = false; debloat = false; settings = false; access = false } }
+ LaunchedEffect(loggedOutAt) { if (loggedOutAt != null) { remote = false; advanced = false; history = false; resetting = false; debloat = false; settings = false; access = false } }
// The Allow screen while the TV is asked; allowed lands on Overview, a Deny there is a plain refusal (its card).
val rejoining = state.selected?.takeIf { it.id == rejoinId && it.state == DeviceState.Waiting }
LaunchedEffect(state.selected?.state, loggedOutAt) {
@@ -316,6 +319,14 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
onDispose { vm.historyOpened() }
}
HistoryScreen(state, onUndo = vm::undo, onRestoreAll = vm::restoreAll, back = { history = false }, snackbar = snackbar)
+ } else if (resetting && state.device.reset != null) {
+ val close = { vm.closeReset(); resetting = false }
+ // Leaving mid-run only closes the screen; the run goes on, and History has it when done.
+ BackHandler(onBack = close)
+ ResetScreen(
+ state,
+ ResetActions(reset = { vm.runReset() }, retry = { vm.runReset(retry = true) }, reload = vm::openReset, back = close),
+ )
} else if (access || state.device.removal != null) {
// A removal started from the warning opens this screen too, and back steps out of it first.
BackHandler { if (state.device.removal != null) vm.closeRemoval() else access = false }
@@ -403,6 +414,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
debloat = { debloat = true },
advanced = { advanced = true },
history = { history = true },
+ reset = { vm.openReset(); resetting = true },
checkUpdates = vm::checkUpdates,
setDns = vm::setDns,
setFastAnimations = vm::setFastAnimations,
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index 9004642..d0c1ed1 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -36,6 +36,7 @@ import app.tellyscope.adb.Protected
import app.tellyscope.adb.ProtectedReason
import app.tellyscope.adb.Remote
import app.tellyscope.adb.RemoteKey
+import app.tellyscope.adb.Reset as TvReset
import app.tellyscope.adb.Stats
import app.tellyscope.adb.StatsProfile
import app.tellyscope.adb.PairResult
@@ -504,6 +505,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {
return switchHome(deviceId, packageName, undoing, again ?: service)
}
if (action == Action.HomeBack) return homeBack(deviceId, packageName, undoing)
+ if (action == Action.Reset) return undoReset(deviceId, undoing ?: throw IllegalStateException("there's no reset to undo"))
undoing?.let { id -> book.entries(key).firstOrNull { it.id == id } }?.firstHomeService
?.let { return firstHomeServiceOff(deviceId, packageName, it, undoing) }
if (action == Action.Uninstall && Actions(shell).homeOptions()?.current == packageName) return uninstallHome(deviceId, packageName)
@@ -641,6 +643,136 @@ class AdbDeviceSource(context: Context) : DeviceSource {
}
}
+ override suspend fun resetPlan(deviceId: String): ResetPlan = busy(deviceId) {
+ val shell = session(deviceId)
+ val scan = TvReset(shell).scan()
+ val options = Actions(shell).homeOptions()
+ val system = Parsers.packages(shell.shell("pm list packages -s").output).map { it.name }.toSet()
+ val disabled = Parsers.packages(shell.shell("pm list packages -d").output).map { it.name }.toSet()
+ val own = options?.let { builtIns(system, disabled, it) }.orEmpty()
+ // Home is a launcher the user added: the TV's own takes it back, the one a switch replaced first.
+ val added = options?.takeIf { it.default }?.current?.takeIf { it !in system }
+ val to = added?.let { homeBackTarget(it, book.entries(key(deviceId)), own) }?.pkg?.takeIf { it in system } ?: own.firstOrNull()
+ ResetPlan(
+ turnOn = scan.turnOn.map { ResetApp(it, labelOf(it)) },
+ bringBack = scan.bringBack.map { ResetApp(it, labelOf(it)) },
+ home = if (added != null && to != null) ResetHome(added, labelOf(added), to, labelOf(to), service = added in serviceLaunchers) else null,
+ shippedOff = scan.shippedOff.size,
+ ownHome = (options?.current?.takeIf { it in system } ?: to ?: own.firstOrNull())?.let(::labelOf),
+ )
+ }
+
+ override suspend fun reset(deviceId: String, plan: ResetPlan, into: Long?, onProgress: (ResetProgress) -> Unit): Pair<Long?, List<ResetFailure>> = busy(deviceId) {
+ fireHomes -= deviceId
+ val key = key(deviceId)
+ // Like any first change: what was off before stays out of Restore everything.
+ if (!book.hasBaseline(key)) book.setBaseline(key, disabledPackages(deviceId))
+ val shell = session(deviceId)
+ val tv = TvReset(shell)
+ val failed = mutableListOf<ResetFailure>()
+ suspend fun each(part: ResetPart, apps: List<ResetApp>, change: suspend (String) -> Unit) = apps.mapIndexedNotNull { i, app ->
+ onProgress(ResetProgress(part, i, apps.size))
+ try {
+ change(app.packageName)
+ app.packageName
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ // A step that fails doesn't stop the rest: each one stands alone.
+ failed += ResetFailure(part, app, e.message ?: "the TV refused")
+ null
+ }
+ }
+ val on = each(ResetPart.TurnOn, plan.turnOn, tv::turnOn)
+ val back = each(ResetPart.BringBack, plan.bringBack, tv::bringBack)
+ val home = plan.home?.let { h ->
+ onProgress(ResetProgress(ResetPart.Home, 0, 1))
+ try {
+ resetHome(Actions(shell), h)
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ failed += ResetFailure(ResetPart.Home, null, e.message ?: "the TV refused")
+ null
+ }
+ }
+ val old = into?.let { id -> book.entries(key).firstOrNull { it.id == id && it.undoneAt == null } }
+ if (on.isEmpty() && back.isEmpty() && home == null) return@busy old?.id to failed
+ fun merge(k: String, new: List<String>) = k to (ResetRecord.list(old?.previous, k) + new).distinct().joinToString(",")
+ val previous = mapOf(merge(ResetRecord.ON, on), merge(ResetRecord.BACK, back)) + home.orEmpty()
+ val label = ResetRecord.label(ResetRecord.changes(old?.previous.orEmpty() + previous))
+ val id = if (old != null) old.id.also { book.amend(it, previous, label) }
+ else book.record(key, System.currentTimeMillis(), Action.Reset, RESET, label, undo = Action.Reset, previous = previous).id
+ id to failed
+ }
+
+ /**
+ * Home back to [home]'s TV's own launcher, the added one's accessibility service off with it:
+ * it would keep sending Home there. Returns what Undo needs; throws when Home didn't move. A
+ * service that stayed on throws too, but by then Home has moved, so that's recorded first.
+ */
+ private suspend fun resetHome(actions: Actions, home: ResetHome): Map<String, String?> =
+ when (val r = actions.homeBack(home.to)) {
+ is HomeResult.Switched -> {
+ val service = home.from.takeIf { it in serviceLaunchers }?.let { actions.homeService(it) }?.takeIf { actions.serviceOn(it) }
+ val off = service?.let { actions.setService(it, false) }
+ if (off == false) throw IllegalStateException(serviceNotOff(home.fromLabel))
+ listOfNotNull(ResetRecord.FROM to r.from, ResetRecord.TO to r.to, service?.let { ResetRecord.SERVICE to it }).toMap()
+ }
+ is HomeResult.Refused -> throw IllegalStateException(reasonText(r.reason))
+ is HomeResult.Failed -> throw IllegalStateException(r.output.ifEmpty { "the TV refused" })
+ }
+
+ /**
+ * Undo of a reset: Home back to the launcher it replaced, its service on again, then the apps
+ * it turned on go off and the ones it brought back are removed again. Goes on past a step that
+ * fails; then the entry keeps only what is left, so Undo can try those again.
+ */
+ private suspend fun undoReset(deviceId: String, id: Long): HistoryEntry {
+ val key = key(deviceId)
+ val entry = book.entries(key).firstOrNull { it.id == id && it.undoneAt == null }
+ ?: throw IllegalStateException("that reset is already undone")
+ val p = entry.previous.orEmpty()
+ val shell = session(deviceId)
+ val tv = TvReset(shell)
+ val actions = Actions(shell)
+ val errors = mutableListOf<String>()
+ var homeLeft = false
+ p[ResetRecord.TO]?.let { to ->
+ val from = p[ResetRecord.FROM]
+ val name = labelOf(from?.substringBefore('/') ?: to.substringBefore('/'))
+ // Home first: the TV's own launcher can't go off while it's still Home.
+ if (from == null || !actions.setHome(from)) {
+ homeLeft = true
+ errors += "the TV kept ${labelOf(to.substringBefore('/'))} as the home screen"
+ } else p[ResetRecord.SERVICE]?.let { if (!actions.setService(it, true)) errors += serviceNotOn(name) }
+ }
+ val ownHome = p[ResetRecord.TO]?.substringBefore('/')?.takeIf { homeLeft }
+ suspend fun each(pkgs: List<String>, change: suspend (String) -> Unit) = pkgs.filter { pkg ->
+ if (pkg == ownHome) return@filter true
+ try {
+ change(pkg)
+ false
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ errors += "${labelOf(pkg)}: ${e.message ?: "the TV refused"}"
+ true
+ }
+ }
+ val on = each(ResetRecord.list(p, ResetRecord.ON), tv::turnOff)
+ val back = each(ResetRecord.list(p, ResetRecord.BACK), tv::remove)
+ if (errors.isEmpty()) {
+ return book.record(key, System.currentTimeMillis(), Action.Change, RESET, "Put back what Reset TV changed", undo = null, undoing = id)
+ }
+ val left = mapOf(ResetRecord.ON to on.joinToString(","), ResetRecord.BACK to back.joinToString(",")) +
+ if (homeLeft) emptyMap() else mapOf(ResetRecord.FROM to null, ResetRecord.TO to null, ResetRecord.SERVICE to null)
+ val before = ResetRecord.changes(p)
+ val now = ResetRecord.changes(p + left)
+ book.amend(id, left, ResetRecord.label(now))
+ throw IllegalStateException("put back ${before - now} of $before changes. ${errors.first().replaceFirstChar(Char::uppercase)}. Undo again tries the rest")
+ }
+
override suspend fun suggestions(deviceId: String, apps: suspend () -> List<AppInfo>): Suggestions = try {
val r = resolve(deviceId)
when {
@@ -981,6 +1113,9 @@ internal suspend fun undoHomeSwitch(actions: Actions, switch: HistoryEntry): Boo
return back != false
}
+/** The package name a reset's History entries carry: it changes the TV, not one app. */
+internal const val RESET = "reset"
+
private fun serviceNotOn(app: String) =
"$app is Home now, but its accessibility service didn't turn on, so the TV's Home button may still open its own launcher"
diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
index df3f009..d8c6ed6 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
@@ -105,6 +105,16 @@ interface DeviceSource {
/** Turns back on every app Tellyscope disabled, and nothing that was off before. */
suspend fun restoreAll(deviceId: String): List<HistoryEntry>
+ /** What Reset TV would change, read from the TV itself, whoever changed it. Throws if it's gone. */
+ suspend fun resetPlan(deviceId: String): ResetPlan = ResetPlan()
+
+ /**
+ * Runs [plan], reporting each step to [onProgress], and goes on past a step that fails. All of
+ * it is one History entry; a retry ([into], that entry's id) adds to it. Returns the entry's id,
+ * null when nothing changed, and what failed.
+ */
+ suspend fun reset(deviceId: String, plan: ResetPlan, into: Long? = null, onProgress: (ResetProgress) -> Unit = {}): Pair<Long?, List<ResetFailure>> = null to emptyList()
+
/** The version of [packageName] on the TV, or null when it isn't installed. */
suspend fun installed(deviceId: String, packageName: String): InstalledVersion?
diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
index a5a67f0..117316d 100644
--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt
@@ -202,13 +202,19 @@ class FakeDeviceSource(
delay(400)
val list = appsFor(deviceId)
if (!book.hasBaseline(deviceId)) book.setBaseline(deviceId, list.filter { !it.enabled }.map { it.packageName }.toSet())
+ if (action == Action.Reset) {
+ val reset = book.entries(deviceId).first { it.id == undoing }
+ val on = ResetRecord.list(reset.previous, ResetRecord.ON)
+ list.replaceAll { if (it.packageName in on) it.copy(enabled = false) else it }
+ return book.record(deviceId, clock(), Action.Change, packageName, "Put back what Reset TV changed", null, undoing)
+ }
val i = list.indexOfFirst { it.packageName == packageName }
val app = list[i]
when (action) {
Action.Disable -> list[i] = app.copy(enabled = false)
Action.Enable -> list[i] = app.copy(enabled = true)
Action.Uninstall -> list.removeAt(i)
- Action.Stop, Action.Open, Action.Change, Action.ClearCaches, Action.Home, Action.HomeBack -> Unit
+ Action.Stop, Action.Open, Action.Change, Action.ClearCaches, Action.Home, Action.HomeBack, Action.Reset -> Unit
}
val undo = when (action) {
Action.Stop -> Action.Open
@@ -216,7 +222,7 @@ class FakeDeviceSource(
Action.Enable -> Action.Disable
Action.Home -> Action.Enable
Action.HomeBack -> Action.Home
- Action.Open, Action.Uninstall, Action.Change, Action.ClearCaches -> null
+ Action.Open, Action.Uninstall, Action.Change, Action.ClearCaches, Action.Reset -> null
}
return book.record(deviceId, clock(), action, packageName, app.label, undo, undoing)
}
@@ -230,6 +236,26 @@ class FakeDeviceSource(
}
}
+ /** The demo TV's apps that are off and came with it, as if someone had turned them off by hand. */
+ override suspend fun resetPlan(deviceId: String): ResetPlan {
+ delay(400)
+ val off = appsFor(deviceId).filter { it.system && !it.enabled }.map { ResetApp(it.packageName, it.label) }
+ return ResetPlan(turnOn = off, ownHome = "Google TV Home")
+ }
+
+ override suspend fun reset(deviceId: String, plan: ResetPlan, into: Long?, onProgress: (ResetProgress) -> Unit): Pair<Long?, List<ResetFailure>> {
+ val list = appsFor(deviceId)
+ plan.turnOn.forEachIndexed { i, app ->
+ onProgress(ResetProgress(ResetPart.TurnOn, i, plan.turnOn.size))
+ delay(300)
+ list.replaceAll { if (it.packageName == app.packageName) it.copy(enabled = true) else it }
+ }
+ if (plan.turnOn.isEmpty()) return into to emptyList()
+ val on = plan.turnOn.joinToString(",") { it.packageName }
+ val entry = book.record(deviceId, clock(), Action.Reset, "reset", ResetRecord.label(plan.changes), Action.Reset, previous = mapOf(ResetRecord.ON to on))
+ return entry.id to emptyList()
+ }
+
override suspend fun installed(deviceId: String, packageName: String): InstalledVersion? =
appsFor(deviceId).firstOrNull { it.packageName == packageName }?.let { InstalledVersion(1, it.version) }
diff --git a/app/src/main/java/app/tellyscope/data/HistoryBook.kt b/app/src/main/java/app/tellyscope/data/HistoryBook.kt
index 40f1261..7c303ca 100644
--- a/app/src/main/java/app/tellyscope/data/HistoryBook.kt
+++ b/app/src/main/java/app/tellyscope/data/HistoryBook.kt
@@ -70,11 +70,11 @@ class HistoryBook(private val file: File? = null) {
save()
}
- /** Adds [extra] to entry [id]'s saved state, for a later step of the same change. */
+ /** Adds [extra] to entry [id]'s saved state, for a later step of the same change, and gives it [label] if set. */
@Synchronized
- fun amend(id: Long, extra: Map<String, String?>) {
+ fun amend(id: Long, extra: Map<String, String?>, label: String? = null) {
val i = entries.indexOfFirst { it.id == id }.takeIf { it >= 0 } ?: return
- entries[i] = entries[i].copy(previous = entries[i].previous.orEmpty() + extra)
+ entries[i] = entries[i].copy(previous = entries[i].previous.orEmpty() + extra, label = label?.let(::clean) ?: entries[i].label)
save()
}
@@ -112,9 +112,13 @@ class HistoryBook(private val file: File? = null) {
* Packages whose last disable/enable in [history] was a disable (a home switch disables the
* old launcher); an uninstall clears it. Newest disable first: undoing a switch makes Home
* the launcher it replaced, so after L→A→B, Restore undoes A→B, then L→A, and ends on L.
+ * A reset nothing has undone counts as turning on each app it turned on.
*/
fun leftDisabled(history: List<HistoryEntry>): List<String> =
- history.filter { it.disables || it.action == Action.Enable || it.action == Action.Uninstall }
+ history.flatMap { e ->
+ if (e.action == Action.Reset && e.undoneAt == null) ResetRecord.list(e.previous, ResetRecord.ON).map { e.copy(action = Action.Enable, packageName = it) }
+ else listOf(e)
+ }.filter { it.disables || it.action == Action.Enable || it.action == Action.Uninstall }
.sortedBy { it.id }
.associate { it.packageName to it }
.filterValues { it.disables }
diff --git a/app/src/main/java/app/tellyscope/data/Model.kt b/app/src/main/java/app/tellyscope/data/Model.kt
index 5ecb513..4630a55 100644
--- a/app/src/main/java/app/tellyscope/data/Model.kt
+++ b/app/src/main/java/app/tellyscope/data/Model.kt
@@ -180,9 +180,11 @@ data class NetworkInfo(
* Its undo is [Enable], which also makes the old launcher Home again. [HomeBack] makes the
* launcher a switch replaced (or the TV's own) Home again, turning it on if it's off, and leaves
* the added one on: its entry's packageName is the added launcher, the label the one now Home.
- * Its undo is [Home], which switches to the added launcher again.
+ * Its undo is [Home], which switches to the added launcher again. [Reset] is Reset TV, one entry
+ * for all of it: [HistoryEntry.previous] holds what it changed ([ResetRecord]), and its undo, [Reset]
+ * too, puts all of that back.
*/
-enum class Action { Stop, Disable, Enable, Open, Uninstall, Change, ClearCaches, Home, HomeBack }
+enum class Action { Stop, Disable, Enable, Open, Uninstall, Change, ClearCaches, Home, HomeBack, Reset }
data class HistoryEntry(
val id: Long,
diff --git a/app/src/main/java/app/tellyscope/data/ResetPlan.kt b/app/src/main/java/app/tellyscope/data/ResetPlan.kt
new file mode 100644
index 0000000..93fab34
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/data/ResetPlan.kt
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.data
+
+/** One app Reset TV changes, with the name it shows. */
+data class ResetApp(val packageName: String, val label: String)
+
+/**
+ * Home's part of a reset: [to], the TV's own launcher, is Home again in place of [from], a launcher
+ * the user added. [service]: [from] holds Home with an accessibility service, which goes off.
+ */
+data class ResetHome(val from: String, val fromLabel: String, val to: String, val toLabel: String, val service: Boolean = false)
+
+/**
+ * What Reset TV found on the TV before anything changes: preinstalled apps to [turnOn] and to
+ * [bringBack], and the [home] change, if any. [shippedOff] apps the maker shipped switched off
+ * stay off. [ownHome] names the TV's own launcher, for "nothing to reset".
+ */
+data class ResetPlan(
+ val turnOn: List<ResetApp> = emptyList(),
+ val bringBack: List<ResetApp> = emptyList(),
+ val home: ResetHome? = null,
+ val shippedOff: Int = 0,
+ val ownHome: String? = null,
+) {
+ val changes get() = turnOn.size + bringBack.size + (if (home != null) 1 else 0)
+}
+
+/** The three parts of a reset, run in this order: apps first, so the TV's own launcher is on before it takes Home. */
+enum class ResetPart { TurnOn, BringBack, Home }
+
+/** How far a running reset is: [done] of [of] in [part]. */
+data class ResetProgress(val part: ResetPart, val done: Int, val of: Int)
+
+/** A step that didn't work: the [app] it was for (none for Home) and the TV's [reason]. */
+data class ResetFailure(val part: ResetPart, val app: ResetApp?, val reason: String)
+
+/** History's record of a reset: what Undo turns off, removes and switches back. */
+internal object ResetRecord {
+ const val ON = "on"
+ const val BACK = "back"
+ const val FROM = "from"
+ const val TO = "to"
+ const val SERVICE = "service"
+
+ fun label(changes: Int) = "Reset TV · $changes ${if (changes == 1) "change" else "changes"}"
+
+ fun list(previous: Map<String, String?>?, key: String) = previous?.get(key)?.split(',')?.filter { it.isNotEmpty() }.orEmpty()
+
+ /** How many changes [previous] holds: each app, plus Home. */
+ fun changes(previous: Map<String, String?>?) = list(previous, ON).size + list(previous, BACK).size + (if (previous?.get(TO) != null) 1 else 0)
+}
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 38a2239..cec2f17 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -9,6 +9,8 @@ import app.tellyscope.adb.TvFolder
import app.tellyscope.data.Action
import app.tellyscope.data.AppNames
import app.tellyscope.data.DeviceState
+import app.tellyscope.data.ResetPart
+import app.tellyscope.data.ResetProgress
import app.tellyscope.data.Snapshot
import app.tellyscope.data.TvSettings
import app.tellyscope.data.sourceName
@@ -32,7 +34,7 @@ object Copy {
Action.Enable -> "Turn on"
Action.Open -> "Open"
Action.Uninstall -> "Uninstall"
- Action.Change, Action.ClearCaches, Action.Home, Action.HomeBack -> error("$action has its own button")
+ Action.Change, Action.ClearCaches, Action.Home, Action.HomeBack, Action.Reset -> error("$action has its own button")
}
fun confirm(action: Action) = when (action) {
@@ -43,7 +45,7 @@ object Copy {
Action.Uninstall -> "Yes, uninstall it"
Action.Home -> "Yes, switch home screen"
Action.HomeBack -> "Yes, switch back"
- Action.Change, Action.ClearCaches -> error("$action isn't an app action")
+ Action.Change, Action.ClearCaches, Action.Reset -> error("$action isn't an app action")
}
/**
@@ -57,7 +59,7 @@ object Copy {
Action.Enable -> "Turns $who back on."
Action.Open -> "Opens $who on the TV."
Action.Uninstall -> "Removes $who and everything saved in it. This can't be undone; to get it back, install it again."
- Action.Change, Action.ClearCaches, Action.Home, Action.HomeBack -> error("$action isn't a one-app action")
+ Action.Change, Action.ClearCaches, Action.Home, Action.HomeBack, Action.Reset -> error("$action isn't a one-app action")
}
}
@@ -67,8 +69,8 @@ object Copy {
Action.Enable -> "Turned on $app"
Action.Open -> "Opened $app"
Action.Uninstall -> "Uninstalled $app"
- // A setting's label is the whole sentence: "Private DNS set to …".
- Action.Change -> app
+ // A setting's label is the whole sentence: "Private DNS set to …", as is a reset's.
+ Action.Change, Action.Reset -> app
Action.ClearCaches -> "Cleared $app"
Action.Home -> "Made $app Home"
Action.HomeBack -> "Switched home back to $app"
@@ -588,6 +590,58 @@ object Copy {
/** In the TV menu and in Settings: opens Android's share sheet with the repo link. */
const val SHARE = "Share Tellyscope"
+ /** Reset TV: its row in the TV menu, its screen, and what it says before, during and after. */
+ const val RESET_TV = "Reset TV to how it shipped"
+ const val RESET_KEEPS = "Keeps apps' data and sign-ins"
+
+ fun apps(n: Int) = if (n == 1) "1 app" else "$n apps"
+
+ fun resetFound(n: Int) = "$n ${if (n == 1) "change" else "changes"} since this TV left the factory"
+ const val RESET_FOUND_TEXT = "Your apps' data and sign-ins stay. Nothing has changed yet."
+ fun turnOnApps(n: Int) = "Turn on ${apps(n)}"
+ const val TURN_ON_TEXT = "Preinstalled apps turned off by hand, from any phone or tool"
+ fun bringBackApps(n: Int) = "Bring back ${apps(n)}"
+ const val BRING_BACK_TEXT = "Preinstalled apps that were uninstalled. They're still on the TV."
+ fun resetHome(to: String) = "Make $to the home screen"
+ fun resetHomeText(from: String, service: Boolean) =
+ "Instead of $from" + (if (service) ", with its accessibility service turned off" else "") + ". $from stays installed."
+
+ /** Under what Reset found: what it leaves alone. [maker] is the TV's brand, when known. */
+ fun resetLeaves(shippedOff: Int, maker: String?) =
+ (if (shippedOff > 0) "${apps(shippedOff)} ${maker ?: "the maker"} shipped switched off stay off. " else "") +
+ "Apps and launchers you installed stay installed."
+
+ const val NOTHING_TO_RESET = "Nothing to reset"
+ fun nothingToReset(ownHome: String?, maker: String?) =
+ "Every preinstalled app is on" + (ownHome?.let { ", and $it is the home screen" } ?: "") + ". " +
+ "Apps ${maker ?: "the maker"} shipped switched off stay off."
+
+ fun resetting(p: ResetProgress, home: String?) = when (p.part) {
+ ResetPart.TurnOn -> "Turning on apps: ${p.done} of ${p.of}."
+ ResetPart.BringBack -> "Bringing back apps: ${p.done} of ${p.of}."
+ ResetPart.Home -> "Making ${home ?: "the TV's own launcher"} the home screen."
+ } + " Keep the TV on and connected."
+ const val RESETTING = "Resetting…"
+ const val RESET_BUTTON = "Reset TV"
+
+ const val RESET_DONE = "TV reset to how it shipped"
+ const val RESET_PARTLY = "Reset partly done"
+ fun resetDoneText(apps: Int, home: String?) = listOfNotNull(
+ when (apps) {
+ 0 -> null
+ 1 -> "1 preinstalled app is back"
+ else -> "$apps preinstalled apps are back"
+ },
+ home?.let { "$it is the home screen" },
+ ).joinToString(", and ") + ". Apps' data and sign-ins stayed."
+ fun resetPartlyText(failed: Int) =
+ "${if (failed == 1) "One step" else "$failed steps"} didn't work. Everything else is back to how it shipped. Nothing was lost."
+ fun turnedOn(done: Int, of: Int) = if (done == of) "Turned on ${apps(of)}" else "Turned on $done of ${apps(of)}"
+ fun broughtBack(done: Int, of: Int) = if (done == of) "Brought back ${apps(of)}" else "Brought back $done of ${apps(of)}"
+ fun isHome(app: String) = "$app is the home screen"
+ fun stillHome(app: String) = "$app is still the home screen"
+ fun tryAgain(app: String?) = if (app != null) "Try $app again" else "Try again"
+
/** Under History in the menu, and on top of the History screen: apps Restore everything turns back on. */
fun stillOff(n: Int) = if (n == 1) "1 app still off" else "$n apps still off"
fun stillOffTitle(n: Int) = if (n == 1) "1 app Tellyscope turned off is still off" else "$n apps Tellyscope turned off are still off"
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
index 108df55..7c9e8dd 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt
@@ -111,6 +111,8 @@ data class DeviceActions(
val advanced: () -> Unit = {},
/** Opens History: every change on this TV with its Undo, and Restore everything. */
val history: () -> Unit = {},
+ /** Opens Reset TV: what it would change back to how the TV shipped, before anything changes. */
+ val reset: () -> Unit = {},
/** Opens the TV's own system update screen. */
val checkUpdates: () -> Unit = {},
/** Ad-blocking Private DNS through the given hostname; null goes back to Automatic. */
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
index 8ea1bfc..3a9b75c 100644
--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt
@@ -507,8 +507,11 @@ private fun AppMenu(state: UiState, actions: DeviceActions) {
{ MenuRow(Icons.Default.Info, "About & licences") { pick { about = true } } },
)
Spacer(Modifier.height(16.dp))
- // Apart and in red, so it isn't one slip from an everyday item.
- SheetGroup({ MenuRow(Icons.Default.Delete, "Forget this TV", tint = c.error) { pick { forgetting = true } } })
+ // Apart, and Forget in red, so neither is one slip from an everyday item.
+ SheetGroup(
+ { MenuRow(HistoryIcons.History, Copy.RESET_TV, Copy.RESET_KEEPS) { pick(actions.reset) } },
+ { MenuRow(Icons.Default.Delete, "Forget this TV", tint = c.error) { pick { forgetting = true } } },
+ )
}
}
}
diff --git a/app/src/main/java/app/tellyscope/ui/HistoryScreen.kt b/app/src/main/java/app/tellyscope/ui/HistoryScreen.kt
index d1a9966..4168992 100644
--- a/app/src/main/java/app/tellyscope/ui/HistoryScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/HistoryScreen.kt
@@ -199,6 +199,7 @@ internal object HistoryIcons {
Action.Uninstall, Action.ClearCaches -> Icons.Default.Delete
Action.Home, Action.HomeBack -> Icons.Default.Home
Action.Change -> Icons.Default.Settings
+ Action.Reset -> History
}
private fun icon(name: String, path: String, fill: PathFillType = PathFillType.NonZero) = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f)
diff --git a/app/src/main/java/app/tellyscope/ui/ResetScreen.kt b/app/src/main/java/app/tellyscope/ui/ResetScreen.kt
new file mode 100644
index 0000000..d3ac7b8
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/ui/ResetScreen.kt
@@ -0,0 +1,335 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.ui
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.itemsIndexed
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
+import androidx.compose.material.icons.filled.Check
+import androidx.compose.material.icons.filled.Home
+import androidx.compose.material.icons.filled.KeyboardArrowDown
+import androidx.compose.material.icons.filled.KeyboardArrowUp
+import androidx.compose.material.icons.filled.Warning
+import androidx.compose.material3.Button
+import androidx.compose.material3.CircularProgressIndicator
+import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.LinearProgressIndicator
+import androidx.compose.material3.LoadingIndicator
+import androidx.compose.material3.MaterialShapes
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.material3.TopAppBar
+import androidx.compose.material3.toShape
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.saveable.rememberSaveable
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.PathFillType
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.graphics.vector.PathParser
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.unit.dp
+import app.tellyscope.data.Device
+import app.tellyscope.data.ResetApp
+import app.tellyscope.data.ResetFailure
+import app.tellyscope.data.ResetPart
+import app.tellyscope.data.ResetPlan
+import app.tellyscope.data.ResetProgress
+
+/** What Reset TV's screen can do, for MainActivity to wire to the view model. */
+data class ResetActions(
+ val reset: () -> Unit = {},
+ val retry: () -> Unit = {},
+ val reload: () -> Unit = {},
+ val back: () -> Unit = {},
+)
+
+/**
+ * Reset TV to how it shipped: what it found on the TV first, with nothing changed yet, then its
+ * progress, then what changed or what didn't work. Opened from ⋮.
+ */
+@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+fun ResetScreen(state: UiState, actions: ResetActions) {
+ val device = state.selected ?: return
+ val ui = state.device.reset ?: return
+ val plan = ui.plan
+ val maker = makerOf(device)
+ Scaffold(
+ topBar = {
+ TopAppBar(
+ title = {
+ Column {
+ Text(Copy.RESET_TV)
+ Text(name(device), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ },
+ navigationIcon = {
+ IconButton(onClick = actions.back) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back to the TV's page") }
+ },
+ )
+ },
+ bottomBar = {
+ Row(Modifier.fillMaxWidth().padding(16.dp), horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)) {
+ when {
+ plan == null || (plan.changes == 0 && !ui.ran) -> Unit
+ ui.running != null -> Button(onClick = {}, enabled = false) { Text(Copy.RESETTING) }
+ ui.ran -> {
+ if (ui.failed.isEmpty()) Button(onClick = actions.back) { Text("Done") }
+ else {
+ TextButton(onClick = actions.back) { Text("Done") }
+ Button(onClick = actions.retry) { Text(Copy.tryAgain(ui.failed.singleOrNull()?.app?.label)) }
+ }
+ }
+ else -> {
+ TextButton(onClick = actions.back) { Text("Cancel") }
+ Button(onClick = actions.reset) { Text(Copy.RESET_BUTTON) }
+ }
+ }
+ }
+ },
+ ) { pad ->
+ Box(Modifier.fillMaxSize().padding(pad)) {
+ when {
+ ui.error != null -> Column(Modifier.fillMaxWidth().padding(horizontal = 24.dp), horizontalAlignment = Alignment.CenterHorizontally) {
+ EmptyState(Icons.Default.Warning, "Couldn't read the TV", ui.error)
+ TextButton(onClick = actions.reload) { Text("Try again") }
+ }
+ plan == null -> Column(Modifier.fillMaxWidth().padding(top = 96.dp), horizontalAlignment = Alignment.CenterHorizontally) {
+ LoadingIndicator(Modifier.size(48.dp))
+ Spacer(Modifier.height(16.dp))
+ Text("Reading the TV…", style = MaterialTheme.typography.titleSmall)
+ }
+ // Try again runs on this screen too, so a run in progress comes before the last run's result.
+ ui.running == null && ui.ran -> Result(plan, ui.failed)
+ plan.changes == 0 -> Box(Modifier.padding(horizontal = 24.dp)) {
+ EmptyState(Icons.Default.Check, Copy.NOTHING_TO_RESET, Copy.nothingToReset(plan.ownHome, maker))
+ }
+ else -> Found(plan, ui.running, ui.progress, maker)
+ }
+ }
+ }
+}
+
+/** What the TV has, before and while the reset runs: one section per part, then what stays. */
+@Composable
+private fun Found(plan: ResetPlan, running: ResetPlan?, progress: ResetProgress?, maker: String?) {
+ val c = MaterialTheme.colorScheme
+ val parts = ResetPart.entries.filter { count(plan, it) > 0 }
+ LazyColumn(contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = 24.dp)) {
+ item {
+ if (running == null) {
+ Surface(color = c.primaryContainer, shape = MaterialTheme.shapes.large, modifier = Modifier.fillMaxWidth().padding(bottom = 16.dp)) {
+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
+ Text(Copy.resetFound(plan.changes), style = MaterialTheme.typography.titleSmall, color = c.onPrimaryContainer)
+ Text(Copy.RESET_FOUND_TEXT, style = MaterialTheme.typography.bodyMedium, color = c.onPrimaryContainer)
+ }
+ }
+ } else {
+ val total = running.changes.coerceAtLeast(1)
+ val done = progress?.let { p -> ResetPart.entries.filter { it < p.part }.sumOf { count(running, it) } + p.done } ?: 0
+ LinearProgressIndicator(progress = { done.toFloat() / total }, modifier = Modifier.fillMaxWidth().padding(top = 8.dp))
+ Text(
+ progress?.let { Copy.resetting(it, plan.home?.toLabel) } ?: Copy.RESETTING,
+ style = MaterialTheme.typography.bodyMedium,
+ color = c.onSurfaceVariant,
+ modifier = Modifier.padding(top = 12.dp, bottom = 16.dp),
+ )
+ }
+ }
+ itemsIndexed(parts) { i, part ->
+ val status = running?.let { r -> status(part, r, progress) }
+ Surface(color = c.surfaceContainerLow, shape = groupShape(i, parts.size), modifier = Modifier.fillMaxWidth().padding(bottom = 2.dp)) {
+ Section(plan, part, status)
+ }
+ }
+ item {
+ Text(
+ Copy.resetLeaves(plan.shippedOff, maker),
+ style = MaterialTheme.typography.bodySmall,
+ color = c.onSurfaceVariant,
+ modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 16.dp),
+ )
+ }
+ }
+}
+
+private enum class Status { Waiting, Running, Done }
+
+/** Where [part] is in a run of [running]: a part with nothing to do this time counts as done. */
+private fun status(part: ResetPart, running: ResetPlan, progress: ResetProgress?): Status {
+ if (count(running, part) == 0) return Status.Done
+ val now = progress?.part ?: ResetPart.entries.first { count(running, it) > 0 }
+ return when {
+ part < now -> Status.Done
+ part == now -> Status.Running
+ else -> Status.Waiting
+ }
+}
+
+private fun count(plan: ResetPlan, part: ResetPart) = when (part) {
+ ResetPart.TurnOn -> plan.turnOn.size
+ ResetPart.BringBack -> plan.bringBack.size
+ ResetPart.Home -> if (plan.home != null) 1 else 0
+}
+
+/** One part of the reset; tapping it, before a run, lists the apps it changes. */
+@Composable
+private fun Section(plan: ResetPlan, part: ResetPart, status: Status?) {
+ val c = MaterialTheme.colorScheme
+ var open by rememberSaveable(part) { mutableStateOf(false) }
+ val (icon, title, text) = when (part) {
+ ResetPart.TurnOn -> Triple(HistoryIcons.TurnedOn, Copy.turnOnApps(plan.turnOn.size), Copy.TURN_ON_TEXT)
+ ResetPart.BringBack -> Triple(ResetIcons.BringBack, Copy.bringBackApps(plan.bringBack.size), Copy.BRING_BACK_TEXT)
+ ResetPart.Home -> plan.home!!.let { Triple(Icons.Default.Home, Copy.resetHome(it.toLabel), Copy.resetHomeText(it.fromLabel, it.service)) }
+ }
+ Column {
+ Row(
+ Modifier.fillMaxWidth().clickable(enabled = status == null) { open = !open }.padding(16.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Icon(icon, contentDescription = null, tint = c.onSurfaceVariant)
+ Spacer(Modifier.width(16.dp))
+ Column(Modifier.weight(1f)) {
+ Text(title, style = MaterialTheme.typography.bodyLarge)
+ Text(text, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant)
+ }
+ Spacer(Modifier.width(16.dp))
+ when (status) {
+ null -> Icon(if (open) Icons.Default.KeyboardArrowUp else Icons.Default.KeyboardArrowDown, contentDescription = if (open) "Hide the list" else "Show the list")
+ Status.Running -> CircularProgressIndicator(Modifier.size(20.dp), strokeWidth = 2.dp)
+ Status.Waiting -> Icon(ResetIcons.Waiting, contentDescription = "Waiting", tint = c.onSurfaceVariant)
+ Status.Done -> Icon(HistoryIcons.TurnedOn, contentDescription = "Done", tint = c.primary)
+ }
+ }
+ if (open && status == null) {
+ HorizontalDivider(Modifier.padding(horizontal = 16.dp), color = c.outlineVariant)
+ when (part) {
+ ResetPart.TurnOn -> AppList(plan.turnOn)
+ ResetPart.BringBack -> AppList(plan.bringBack)
+ ResetPart.Home -> plan.home!!.let { AppList(listOf(ResetApp(it.from, it.fromLabel), ResetApp(it.to, it.toLabel))) }
+ }
+ }
+ }
+}
+
+/** Name over package, as the confirms show them: any app can call itself anything, the package is what changes. */
+@Composable
+private fun AppList(apps: List<ResetApp>) {
+ var all by rememberSaveable { mutableStateOf(false) }
+ Column(Modifier.padding(start = 56.dp, end = 16.dp, top = 8.dp, bottom = 8.dp)) {
+ (if (all) apps else apps.take(SHOWN)).forEach { a ->
+ Column(Modifier.padding(vertical = 6.dp)) {
+ Text(a.label, style = MaterialTheme.typography.bodyLarge)
+ Text(a.packageName, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+ }
+ if (!all && apps.size > SHOWN) TextButton(onClick = { all = true }) { Text(Copy.showAll(apps.size)) }
+ }
+}
+
+private const val SHOWN = 7
+
+/** After a run: a cookie badge, what changed, and per part what worked, with the first failure's reason. */
+@Composable
+private fun Result(plan: ResetPlan, failed: List<ResetFailure>) {
+ val c = MaterialTheme.colorScheme
+ val ok = failed.isEmpty()
+ fun failures(part: ResetPart) = failed.filter { it.part == part }
+ val on = plan.turnOn.size - failures(ResetPart.TurnOn).size
+ val back = plan.bringBack.size - failures(ResetPart.BringBack).size
+ val home = plan.home?.takeIf { failures(ResetPart.Home).isEmpty() }
+ LazyColumn(contentPadding = PaddingValues(start = 16.dp, end = 16.dp, top = 32.dp, bottom = 24.dp), horizontalAlignment = Alignment.CenterHorizontally) {
+ item {
+ Box(
+ Modifier.size(96.dp).clip(MaterialShapes.Cookie9Sided.toShape()).background(if (ok) c.primaryContainer else c.errorContainer),
+ contentAlignment = Alignment.Center,
+ ) {
+ Icon(if (ok) Icons.Default.Check else Icons.Default.Warning, contentDescription = null, Modifier.size(44.dp), tint = if (ok) c.onPrimaryContainer else c.onErrorContainer)
+ }
+ Text(
+ if (ok) Copy.RESET_DONE else Copy.RESET_PARTLY,
+ style = MaterialTheme.typography.headlineSmall,
+ textAlign = TextAlign.Center,
+ modifier = Modifier.padding(top = 24.dp),
+ )
+ Text(
+ if (ok) Copy.resetDoneText(on + back, home?.toLabel) else Copy.resetPartlyText(failed.size),
+ style = MaterialTheme.typography.bodyMedium,
+ color = c.onSurfaceVariant,
+ textAlign = TextAlign.Center,
+ modifier = Modifier.padding(start = 8.dp, end = 8.dp, top = 12.dp, bottom = 24.dp),
+ )
+ }
+ val rows = ResetPart.entries.filter { count(plan, it) > 0 }
+ itemsIndexed(rows) { i, part ->
+ val miss = failures(part)
+ val line = when (part) {
+ ResetPart.TurnOn -> Copy.turnedOn(on, plan.turnOn.size)
+ ResetPart.BringBack -> Copy.broughtBack(back, plan.bringBack.size)
+ ResetPart.Home -> plan.home!!.let { if (miss.isEmpty()) Copy.isHome(it.toLabel) else Copy.stillHome(it.fromLabel) }
+ }
+ val why = miss.firstOrNull()?.let { f -> (f.app?.let { "${it.label}: " } ?: "") + f.reason.replaceFirstChar(Char::uppercase).trimEnd('.') + "." }
+ Surface(color = c.surfaceContainerLow, shape = groupShape(i, rows.size), modifier = Modifier.fillMaxWidth().padding(bottom = 2.dp)) {
+ Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
+ if (miss.isEmpty()) Icon(HistoryIcons.TurnedOn, contentDescription = null, tint = c.primary)
+ else Icon(Icons.Default.Warning, contentDescription = null, tint = c.error)
+ Spacer(Modifier.width(16.dp))
+ Column(Modifier.weight(1f)) {
+ Text(line, style = MaterialTheme.typography.bodyLarge)
+ if (why != null) Text(why, style = MaterialTheme.typography.bodyMedium, color = c.error)
+ }
+ }
+ }
+ }
+ }
+}
+
+/** The TV's brand as the footnotes name it, when known. */
+private fun makerOf(device: Device) = device.manufacturer ?: device.hit.maker
+
+internal object ResetIcons {
+ // Material's download and schedule (a ring cut out by even-odd, hands inside). Absolute commands only, as in TileIcons.
+ val BringBack = icon("BringBack", "M5 20H19V18H5ZM19 9H15V3H9V9H5L12 16Z")
+ val Waiting = icon(
+ "Waiting",
+ "M12 2A10 10 0 1 0 12 22A10 10 0 1 0 12 2ZM12 4A8 8 0 1 1 12 20A8 8 0 1 1 12 4Z" +
+ "M12.5 7H11V13L16.25 16.15L17 14.92L12.5 12.25Z",
+ )
+
+ private fun icon(name: String, path: String) = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f)
+ .addPath(
+ PathParser().parsePathString(path).toNodes(),
+ pathFillType = PathFillType.EvenOdd,
+ fill = SolidColor(Color.Black),
+ )
+ .build()
+}
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index d5925df..3355b34 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -36,6 +36,10 @@ import app.tellyscope.data.NetworkInfo
import app.tellyscope.data.NotAnApp
import app.tellyscope.data.PhoneStorage
import app.tellyscope.data.PickedApp
+import app.tellyscope.data.ResetFailure
+import app.tellyscope.data.ResetPart
+import app.tellyscope.data.ResetPlan
+import app.tellyscope.data.ResetProgress
import app.tellyscope.data.ScanEvent
import app.tellyscope.data.ScanHit
import app.tellyscope.data.ScanKind
@@ -122,6 +126,23 @@ data class DeviceUi(
val launcher: LauncherFlow? = null,
/** Not now on the Apps tab's home-screen card, for this TV. True until read, so the card never flashes. */
val launcherCardHidden: Boolean = true,
+ /** Reset TV, while its screen is open; null otherwise. */
+ val reset: ResetUi? = null,
+)
+
+/**
+ * Reset TV's screen. [plan] is what the TV said, null while it's read ([error] if that failed).
+ * While a run goes, [running] is what it's doing and [progress] how far. After one, [ran] is set
+ * and [failed] holds the steps that didn't work; Try again runs just those, into History's [entry].
+ */
+data class ResetUi(
+ val plan: ResetPlan? = null,
+ val error: String? = null,
+ val running: ResetPlan? = null,
+ val progress: ResetProgress? = null,
+ val ran: Boolean = false,
+ val failed: List<ResetFailure> = emptyList(),
+ val entry: Long? = null,
)
/**
@@ -272,6 +293,9 @@ const val RESTART_WAIT_MS = 60_000L
/** [DeviceUi.busy] value while "Restore everything" runs. */
const val RESTORING = "restore"
+/** [DeviceUi.busy] value while Reset TV runs. */
+const val RESETTING = "reset"
+
/** [DeviceUi.busy] value while the ticked suggestions are being disabled. */
const val DISABLING = "lists"
@@ -1543,6 +1567,62 @@ class TellyscopeViewModel(
viewModelScope.launch(Dispatchers.IO) { gates?.set(DEBLOAT_GATE, true) }
}
+ /** Opens Reset TV and reads what it would change. */
+ fun openReset() {
+ val id = _state.value.selectedId ?: return
+ updateDevice(id) { it.copy(reset = ResetUi()) }
+ viewModelScope.launch {
+ val ui = try {
+ ResetUi(plan = source.resetPlan(id))
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ ResetUi(error = e.message?.replaceFirstChar(Char::uppercase) ?: "The TV didn't answer.")
+ }
+ updateDevice(id) { d -> d.copy(reset = d.reset?.let { ui }) }
+ }
+ }
+
+ /** Reset TV on the selected TV: all of what it found, or with [retry] just the steps that failed. */
+ fun runReset(retry: Boolean = false) {
+ val id = _state.value.selectedId ?: return
+ val ui = _state.value.device.reset ?: return
+ val plan = ui.plan ?: return
+ if (_state.value.device.busy != null) return
+ val todo = if (!retry) plan else ResetPlan(
+ turnOn = ui.failed.filter { it.part == ResetPart.TurnOn }.mapNotNull { it.app },
+ bringBack = ui.failed.filter { it.part == ResetPart.BringBack }.mapNotNull { it.app },
+ home = plan.home?.takeIf { ui.failed.any { it.part == ResetPart.Home } },
+ )
+ updateDevice(id) { it.copy(busy = RESETTING, reset = ui.copy(running = todo, progress = null, failed = emptyList())) }
+ viewModelScope.launch {
+ val (entry, failed) = try {
+ source.reset(id, todo, ui.entry) { p -> updateDevice(id) { d -> d.copy(reset = d.reset?.copy(progress = p)) } }
+ } catch (e: CancellationException) {
+ throw e
+ } catch (e: Exception) {
+ // The TV went away before any step could say: every step it was to run failed.
+ val why = e.message ?: "the TV didn't answer"
+ ui.entry to todo.turnOn.map { ResetFailure(ResetPart.TurnOn, it, why) } +
+ todo.bringBack.map { ResetFailure(ResetPart.BringBack, it, why) } +
+ listOfNotNull(todo.home?.let { ResetFailure(ResetPart.Home, null, why) })
+ }
+ val apps = runCatching { source.apps(id) }.getOrNull()
+ val history = source.history(id)
+ updateDevice(id) { d ->
+ d.copy(
+ apps = apps ?: d.apps, history = history, busy = null,
+ reset = d.reset?.copy(running = null, progress = null, ran = true, failed = failed, entry = entry ?: ui.entry),
+ )
+ }
+ }
+ }
+
+ fun closeReset() {
+ val id = _state.value.selectedId ?: return
+ updateDevice(id) { it.copy(reset = null) }
+ }
+
/** History opened: its newest change is seen, so ⋮ loses its dot until the next one. */
fun historyOpened() {
val s = _state.value
diff --git a/app/src/test/java/app/tellyscope/HistoryBookTest.kt b/app/src/test/java/app/tellyscope/HistoryBookTest.kt
index 0a9dd72..d748eae 100644
--- a/app/src/test/java/app/tellyscope/HistoryBookTest.kt
+++ b/app/src/test/java/app/tellyscope/HistoryBookTest.kt
@@ -6,6 +6,7 @@ import app.tellyscope.data.Action
import app.tellyscope.data.FakeDeviceSource
import app.tellyscope.data.HistoryBook
import app.tellyscope.data.HistoryEntry
+import app.tellyscope.data.ResetRecord
import app.tellyscope.data.firstHomeService
import app.tellyscope.data.historyKey
import app.tellyscope.data.restoreEach
@@ -261,4 +262,26 @@ class HistoryBookTest {
}.exceptionOrNull()
assertEquals("turned 1 app back on, then stopped: connection reset", e?.message)
}
+
+ @Test fun aResetTurnsOnWhatTellyscopeLeftOffAndItsUndoPutsItBack() {
+ val book = HistoryBook()
+ book.record("tv", 0L, Action.Disable, "com.xgimi.ota", "XGIMI Updates", undo = Action.Enable)
+ val reset = book.record("tv", 1L, Action.Reset, "reset", ResetRecord.label(2), undo = Action.Reset,
+ previous = mapOf(ResetRecord.ON to "com.xgimi.ota,com.google.android.videos"))
+ assertEquals("Reset TV · 2 changes", reset.label)
+ assertEquals(emptyList<String>(), HistoryBook.leftDisabled(book.entries("tv")))
+ // Undone, the reset's Enables no longer count, so the earlier disable is Restore's again.
+ book.record("tv", 2L, Action.Change, "reset", "Put back what Reset TV changed", undo = null, undoing = reset.id)
+ assertEquals(listOf("com.xgimi.ota"), HistoryBook.leftDisabled(book.entries("tv")))
+ }
+
+ @Test fun amendRelabelsAPartlyUndoneReset() {
+ val book = HistoryBook()
+ val reset = book.record("tv", 0L, Action.Reset, "reset", ResetRecord.label(3), undo = Action.Reset,
+ previous = mapOf(ResetRecord.ON to "a.b,c.d", ResetRecord.BACK to "e.f"))
+ book.amend(reset.id, mapOf(ResetRecord.ON to "c.d", ResetRecord.BACK to null), ResetRecord.label(1))
+ val left = book.entries("tv").single()
+ assertEquals("Reset TV · 1 change", left.label)
+ assertEquals(1, ResetRecord.changes(left.previous))
+ }
}
diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
index cc9853e..2159992 100644
--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt
+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt
@@ -82,6 +82,15 @@ import app.tellyscope.ui.TvTab
import app.tellyscope.data.LastKnown
import app.tellyscope.ui.Copy
import app.tellyscope.ui.HistoryScreen
+import app.tellyscope.data.ResetApp
+import app.tellyscope.data.ResetFailure
+import app.tellyscope.data.ResetHome
+import app.tellyscope.data.ResetPart
+import app.tellyscope.data.ResetPlan
+import app.tellyscope.data.ResetProgress
+import app.tellyscope.ui.ResetActions
+import app.tellyscope.ui.ResetScreen
+import app.tellyscope.ui.ResetUi
import app.tellyscope.ui.TweaksBlock
import app.tellyscope.ui.DeviceUi
import app.tellyscope.ui.DisableDialog
@@ -583,14 +592,14 @@ class ScreenshotTest {
compose.mainClock.autoAdvance = false
compose.setContent {
TellyscopeTheme(dark = false, dynamic = false) {
- DeviceTabsScreen(tabsState(), DeviceActions(advanced = { calls += "advanced" }, settings = { calls += "settings" }, history = { calls += "history" }))
+ DeviceTabsScreen(tabsState(), DeviceActions(advanced = { calls += "advanced" }, settings = { calls += "settings" }, history = { calls += "history" }, reset = { calls += "reset" }))
}
}
compose.mainClock.advanceTimeBy(1_000)
compose.onNodeWithContentDescription("More options").performClick()
compose.mainClock.advanceTimeBy(1_000)
// Every group is there: this TV's items, the app's, then Forget. Rename, Forget and About open dialogs.
- for (i in listOf("Rename this TV", Copy.HISTORY, Copy.ADVANCED_MONITOR, "Settings", Copy.SHARE, "About & licences", "Forget this TV")) compose.onNodeWithText(i).assertHasClickAction()
+ for (i in listOf("Rename this TV", Copy.HISTORY, Copy.ADVANCED_MONITOR, "Settings", Copy.SHARE, "About & licences", Copy.RESET_TV, "Forget this TV")) compose.onNodeWithText(i).assertHasClickAction()
compose.onNodeWithText(item).performClick()
compose.mainClock.advanceTimeBy(1_000)
return calls
@@ -615,6 +624,8 @@ class ScreenshotTest {
assertTrue(SHARE_TEXT.endsWith(RELEASES.removeSuffix("/releases")))
}
+ @Test fun tabs_menuResetOpensReset() = assertEquals(listOf("reset"), pickFromMenu(Copy.RESET_TV))
+
private fun settings(opened: MutableList<String> = mutableListOf()) = @Composable {
val links = object : UriHandler { override fun openUri(uri: String) { opened += uri } }
CompositionLocalProvider(LocalUriHandler provides links) {
@@ -691,6 +702,63 @@ class ScreenshotTest {
}
@Test fun history_empty_dark() = history("48_history_empty", true) { deviceState() }
+ // Reset TV, as the frames drew it: XGIMI with 14 apps to turn on, 3 to bring back and Home to move.
+ private val resetPlan = ResetPlan(
+ turnOn = listOf(
+ "YouTube Kids" to "com.google.android.youtube.tvkids", "Google Play Movies & TV" to "com.google.android.videos",
+ "Google Play Games" to "com.google.android.play.games", "Live Channels" to "com.google.android.tv",
+ "Sports" to "com.google.android.tvrecommendations.sports", "XGIMI Assistant" to "com.xgimi.assistant",
+ "Netflix" to "com.netflix.ninja", "XGIMI Updates" to "com.xgimi.ota", "Google Play Music" to "com.google.android.music",
+ "Prime Video" to "com.amazon.amazonvideo.livingroom", "Google Play Store" to "com.android.vending",
+ "Disney+" to "com.disney.disneyplus", "XGIMI Manual" to "com.xgimi.manual", "Screensaver" to "com.google.android.backdrop",
+ ).map { (label, pkg) -> ResetApp(pkg, label) },
+ bringBack = listOf(ResetApp("com.google.android.katniss", "Google app for Android TV"), ResetApp("com.xgimi.store", "XGIMI Store"), ResetApp("com.google.android.tvrecommendations", "TV Recommendations")),
+ home = ResetHome("com.spocky.projengmenu", "Projectivy Launcher", "com.google.android.apps.tv.launcherx", "Google TV Home", service = true),
+ shippedOff = 4,
+ ownHome = "Google TV Home",
+ )
+ private fun reset(name: String, dark: Boolean, ui: ResetUi, before: () -> Unit = {}) =
+ shot(name, dark, before = before) { ResetScreen(deviceState { copy(reset = ui) }, ResetActions()) }
+ private val sportsFailed = listOf(ResetFailure(ResetPart.TurnOn, resetPlan.turnOn[4], "the TV didn't answer in time"))
+
+ @Test fun reset_found() {
+ reset("a1_reset_found", false, ResetUi(plan = resetPlan))
+ compose.onNodeWithText(Copy.resetFound(18)).assertExists()
+ compose.onNodeWithText(Copy.RESET_BUTTON).assertHasClickAction()
+ }
+ @Test fun reset_found_dark() = reset("a1_reset_found", true, ResetUi(plan = resetPlan))
+ @Test fun reset_listOpened() {
+ reset("a2_reset_list", false, ResetUi(plan = resetPlan)) { compose.onNodeWithText(Copy.turnOnApps(14)).performClick(); compose.mainClock.advanceTimeBy(1_000) }
+ // Seven of fourteen, then the rest behind Show all.
+ compose.onNodeWithText("com.netflix.ninja").assertExists()
+ compose.onNodeWithText("com.xgimi.ota").assertDoesNotExist()
+ compose.onNodeWithText(Copy.showAll(14)).assertExists()
+ }
+ @Test fun reset_listOpened_dark() = reset("a2_reset_list", true, ResetUi(plan = resetPlan)) { compose.onNodeWithText(Copy.turnOnApps(14)).performClick(); compose.mainClock.advanceTimeBy(1_000) }
+ @Test fun reset_nothing() {
+ reset("a3_reset_nothing", false, ResetUi(plan = ResetPlan(shippedOff = 4, ownHome = "Google TV Home")))
+ compose.onNodeWithText(Copy.NOTHING_TO_RESET).assertExists()
+ compose.onNodeWithText(Copy.RESET_BUTTON).assertDoesNotExist()
+ }
+ @Test fun reset_nothing_dark() = reset("a3_reset_nothing", true, ResetUi(plan = ResetPlan(shippedOff = 4, ownHome = "Google TV Home")))
+ private val running = ResetUi(plan = resetPlan, running = resetPlan, progress = ResetProgress(ResetPart.TurnOn, 6, 14))
+ @Test fun reset_running() {
+ reset("a4_reset_running", false, running)
+ compose.onNodeWithText(Copy.RESETTING).assertIsNotEnabled()
+ }
+ @Test fun reset_running_dark() = reset("a4_reset_running", true, running)
+ @Test fun reset_done() {
+ reset("a5_reset_done", false, ResetUi(plan = resetPlan, ran = true))
+ compose.onNodeWithText(Copy.RESET_DONE).assertExists()
+ }
+ @Test fun reset_done_dark() = reset("a5_reset_done", true, ResetUi(plan = resetPlan, ran = true))
+ @Test fun reset_partlyDone() {
+ reset("a6_reset_partly", false, ResetUi(plan = resetPlan, ran = true, failed = sportsFailed))
+ compose.onNodeWithText(Copy.turnedOn(13, 14)).assertExists()
+ compose.onNodeWithText(Copy.tryAgain("Sports")).assertHasClickAction()
+ }
+ @Test fun reset_partlyDone_dark() = reset("a6_reset_partly", true, ResetUi(plan = resetPlan, ran = true, failed = sportsFailed))
+
@Test fun device_overview() {
shot("04_device") { DeviceTabsScreen(deviceState(), DeviceActions()) }
// Plain words on the main page: no Details expander, no MB per app; numbers live on Advanced.