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.
Wait for a running job before the next app action
jesse-agent-232d96654f9ea5c
diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex e9ba277..8fcf353 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -38,6 +38,7 @@ import androidx.compose.material3.OutlinedTextFieldimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.remember@@ -351,7 +352,7 @@ internal fun homeLabel(apps: List<AppInfo>, app: AppInfo): String? =/** Uninstall has no undo, so it asks in a dialog that names the app, not inline. */@Composable-fun UninstallDialog(app: AppInfo, onUninstall: () -> Unit, onDismiss: () -> Unit) {+fun UninstallDialog(app: AppInfo, onUninstall: () -> Unit, onDismiss: () -> Unit, enabled: Boolean = true) {AlertDialog(onDismissRequest = onDismiss,title = { Text(Copy.uninstallTitle(app.label)) },@@ -359,6 +360,7 @@ fun UninstallDialog(app: AppInfo, onUninstall: () -> Unit, onDismiss: () -> UnitconfirmButton = {Button(onClick = onUninstall,+ enabled = enabled,colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.error, contentColor = MaterialTheme.colorScheme.onError),) { Text(Copy.confirm(Action.Uninstall)) }},@@ -376,6 +378,8 @@ internal fun AppRow(actions: DeviceActions,/** The current home screen's name, when this app can replace it. */homeLabel: String? = null,+ /** Something else is running on this TV: every button waits for it, like the tweaks do. */+ locked: Boolean = false,) {var open by rememberSaveable(app.packageName) { mutableStateOf(false) }// A launcher can be protected by its name and still be offered as the new home screen.@@ -402,22 +406,26 @@ internal fun AppRow(}if (busy) androidx.compose.material3.LoadingIndicator(Modifier.size(32.dp))}- val proposed = pending?.takeIf { it.first == app.packageName }?.second+ val asked = pending?.takeIf { it.first == app.packageName }?.second+ // A launcher switch whose target went away meanwhile (turned off in Debloat, say) has nothing left to explain.+ val orphaned = (asked == Action.Home && home == null) || (asked == Action.HomeBack && back == null)+ if (orphaned) LaunchedEffect(app.packageName) { actions.cancel() }+ val proposed = asked.takeUnless { orphaned }AnimatedVisibility((open || proposed != null) && changeable) {Column(Modifier.padding(start = 52.dp, top = 8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {// The label is whatever the app calls itself; the package id is what an action touches.Text(app.packageName, style = SmallNumber, color = MaterialTheme.colorScheme.onSurfaceVariant)if (proposed == null) {if (app.protectedReason == null) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- if (app.enabled && ram > 0) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Stop) }) { Text(Copy.button(Action.Stop)) }- if (app.enabled) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Disable) }) { Text(Copy.button(Action.Disable)) }- else FilledTonalButton(onClick = { actions.propose(app.packageName, Action.Enable) }) { Text(Copy.button(Action.Enable)) }- if (app.removable) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Uninstall) }) { Text(Copy.button(Action.Uninstall)) }+ if (app.enabled && ram > 0) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Stop) }, enabled = !locked) { Text(Copy.button(Action.Stop)) }+ if (app.enabled) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Disable) }, enabled = !locked) { Text(Copy.button(Action.Disable)) }+ else FilledTonalButton(onClick = { actions.propose(app.packageName, Action.Enable) }, enabled = !locked) { Text(Copy.button(Action.Enable)) }+ if (app.removable) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Uninstall) }, enabled = !locked) { Text(Copy.button(Action.Uninstall)) }}- if (home != null) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Home) }) { Text(Copy.MAKE_HOME) }- if (back != null) OutlinedButton(onClick = { actions.propose(app.packageName, Action.HomeBack) }) { Text(Copy.homeBack(back)) }+ if (home != null) OutlinedButton(onClick = { actions.propose(app.packageName, Action.Home) }, enabled = !locked) { Text(Copy.MAKE_HOME) }+ if (back != null) OutlinedButton(onClick = { actions.propose(app.packageName, Action.HomeBack) }, enabled = !locked) { Text(Copy.homeBack(back)) }} else if (proposed == Action.Uninstall) {- UninstallDialog(app, onUninstall = actions.confirm, onDismiss = actions.cancel)+ UninstallDialog(app, onUninstall = actions.confirm, onDismiss = actions.cancel, enabled = !locked)} else {Text(when {@@ -429,7 +437,7 @@ internal fun AppRow(style = MaterialTheme.typography.bodyMedium,)Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- Button(onClick = actions.confirm) { Text(Copy.confirm(proposed)) }+ Button(onClick = actions.confirm, enabled = !locked) { Text(Copy.confirm(proposed)) }TextButton(onClick = actions.cancel) { Text("Cancel") }}}@@ -445,6 +453,8 @@ internal fun HistoryList(onUndo: (HistoryEntry) -> Unit,restoring: Boolean = false,onRestoreAll: () -> Unit = {},+ /** Something is running on this TV, a restore included: Undo and Restore wait for it. */+ busy: Boolean = restoring,) {var confirming by rememberSaveable { mutableStateOf(false) }val off = HistoryBook.leftDisabled(history).size@@ -454,7 +464,7 @@ internal fun HistoryList(UndoDisableDialog(h, onDisable = { disabling = null; onUndo(h) }, onDismiss = { disabling = null })}if (off > 0) {- OutlinedButton(onClick = { confirming = true }, enabled = !restoring) {+ OutlinedButton(onClick = { confirming = true }, enabled = !busy) {Text(if (restoring) "Turning apps back on…" else "Restore everything ($off)")}}@@ -483,7 +493,7 @@ internal fun HistoryList(Spacer(Modifier.width(4.dp))Text("Undone")}- h.undo != null -> TextButton(onClick = { if (h.undo == Action.Disable) disabling = h else onUndo(h) }) { Text(Copy.undo(h.undo)) }+ h.undo != null -> TextButton(onClick = { if (h.undo == Action.Disable) disabling = h else onUndo(h) }, enabled = !busy) { Text(Copy.undo(h.undo)) }}}}diff --git a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt b/app/src/main/java/app/tellyscope/ui/DeviceTabs.ktindex 675762f..e86b332 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceTabs.kt@@ -282,7 +282,7 @@ fun DeviceTabsScreen(TvTab.Apps -> {val procs = snap?.procs.orEmpty()fun rows(apps: List<AppInfo>) = items(apps, key = { it.packageName }) { app ->- AppRow(app, procs, ui.pending, ui.busy == app.packageName, actions, homeLabel(ui.apps, app))+ AppRow(app, procs, ui.pending, ui.busy == app.packageName, actions, homeLabel(ui.apps, app), locked = ui.busy != null)}if (searching) {// One flat list of every matching app, whichever button it sits under; each row says@@ -338,7 +338,7 @@ fun DeviceTabsScreen(else item { Panel(Copy.TWEAKS) { TweaksBlock(ui, actions) } }item {Panel("Recent changes") {- HistoryList(ui.history, state.now, actions.undo, restoring = ui.busy == RESTORING, onRestoreAll = actions.restoreAll)+ HistoryList(ui.history, state.now, actions.undo, restoring = ui.busy == RESTORING, onRestoreAll = actions.restoreAll, busy = ui.busy != null)}}}diff --git a/app/src/test/java/app/tellyscope/BusyGatingTest.kt b/app/src/test/java/app/tellyscope/BusyGatingTest.ktnew file mode 100644index 0000000..b0de004--- /dev/null+++ b/app/src/test/java/app/tellyscope/BusyGatingTest.kt@@ -0,0 +1,82 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.junit4.v2.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import app.tellyscope.data.Action+import app.tellyscope.data.AppInfo+import app.tellyscope.data.HistoryEntry+import app.tellyscope.ui.AppRow+import app.tellyscope.ui.Copy+import app.tellyscope.ui.DeviceActions+import app.tellyscope.ui.HistoryList+import org.junit.Assert.assertEquals+import org.junit.Rule+import org.junit.Test+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config++@RunWith(RobolectricTestRunner::class)+@Config(sdk = [35])+class BusyGatingTest {+ @get:Rule val compose = createComposeRule()++ private val pkg = "com.example"+ private val app = AppInfo(pkg, "Example", null, false, true, null, "1.0", removable = true)++ @Test fun appButtonsWaitWhileTheTvIsBusy() {+ compose.setContent { AppRow(app, emptyList(), null, busy = false, actions = DeviceActions(), locked = true) }+ compose.onNodeWithText("Example").performClick()+ compose.onNodeWithText(Copy.button(Action.Disable)).assertIsNotEnabled()+ compose.onNodeWithText(Copy.button(Action.Uninstall)).assertIsNotEnabled()+ }++ @Test fun confirmWaitsWhileTheTvIsBusy() {+ // Proposed before a restore started: the explanation stays, its button waits.+ compose.setContent { AppRow(app, emptyList(), pkg to Action.Disable, busy = false, actions = DeviceActions(), locked = true) }+ compose.onNodeWithText(Copy.confirm(Action.Disable)).assertIsNotEnabled()+ }++ @Test fun undoAndRestoreWaitWhileTheTvIsBusy() {+ val history = listOf(HistoryEntry(1, "tv", 0L, Action.Disable, pkg, "Example", Action.Enable, null))+ compose.setContent { HistoryList(history, 0L, onUndo = {}, busy = true) }+ compose.onNodeWithText(Copy.undo(Action.Enable)).assertIsNotEnabled()+ compose.onNodeWithText("Restore everything (1)").assertIsNotEnabled()+ }++ @Test fun restoreKeepsItsOwnLabel() {+ val history = listOf(HistoryEntry(1, "tv", 0L, Action.Disable, pkg, "Example", Action.Enable, null))+ compose.setContent { HistoryList(history, 0L, onUndo = {}, restoring = true) }+ compose.onNodeWithText("Turning apps back on…").assertIsNotEnabled()+ compose.onNodeWithText(Copy.undo(Action.Enable)).assertIsNotEnabled()+ }++ @Test fun idleUndoStillWorks() {+ val history = listOf(HistoryEntry(1, "tv", 0L, Action.Disable, pkg, "Example", Action.Enable, null))+ compose.setContent { HistoryList(history, 0L, onUndo = {}) }+ compose.onNodeWithText(Copy.undo(Action.Enable)).assertIsEnabled()+ }++ @Test fun launcherSwitchWithItsTargetGoneIsCancelled() {+ // "Set as default launcher" was asked, then the launcher was turned off in Debloat.+ var cancels = 0+ val off = app.copy(enabled = false, homeInstead = "com.stock.home")+ compose.setContent { AppRow(off, emptyList(), pkg to Action.Home, busy = false, actions = DeviceActions(cancel = { cancels++ }), homeLabel = "Stock") }+ compose.waitForIdle()+ assertEquals(1, cancels)+ compose.onNodeWithText(Copy.confirm(Action.Home)).assertDoesNotExist()+ }++ @Test fun switchBackWithItsTargetGoneIsCancelled() {+ var cancels = 0+ val off = app.copy(enabled = false, homeBack = "Stock")+ compose.setContent { AppRow(off, emptyList(), pkg to Action.HomeBack, busy = false, actions = DeviceActions(cancel = { cancels++ })) }+ compose.waitForIdle()+ assertEquals(1, cancels)+ }+}