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.

Fire TV: install Projectivy as one screen; Who has access shows the TV's prompt

jesse-agent-23205cf1cdc885e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2addb04..0b300b6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,15 @@ until this file has a section for its version.
## Unreleased
+- **New:** Who has access shows the TV's Allow prompt, and answers it from the phone. [#253](../../pull/253)
+ - A computer waiting on that prompt shows as Waiting, not as connected.
+ - Keys allowed while Tellyscope wasn't watching are marked New.
+- **Improved:** On Fire TV, installing Projectivy is one screen, step by step. [#253](../../pull/253)
+ - When the download fails, pick the file you downloaded yourself; it's checked the same way.
+ - Stopping a download asks first; the TV can't be left half installed.
+- **Improved:** Install apps and Projectivy's file picker open in Downloads, showing only apps. [#253](../../pull/253)
+- **Fixed:** Projectivy's download works when GitHub limits lookups from your network. [#253](../../pull/253)
+
## 0.13.0 — 2026-10-29
- **New:** Remote buttons open Netflix, YouTube, Plex and 20 more streaming apps. [#224](../../pull/224)
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index 2bb541f..42418ac 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -8,6 +8,7 @@ import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
+import android.provider.DocumentsContract
import android.provider.Settings
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
@@ -209,8 +210,8 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
var rejoinId by rememberSaveable { mutableStateOf<String?>(null) }
var rejoinSince by rememberSaveable { mutableStateOf(0L) }
- // "*/*": file managers label .apks and .xapk bundles inconsistently, so a narrower type would grey them out.
- val pickApp = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { vm.pickedApp(it) }
+ val pickApp = rememberLauncherForActivityResult(InDownloads.Multiple()) { vm.pickedApp(it) }
+ val pickProjectivy = rememberLauncherForActivityResult(InDownloads.One()) { uri -> uri?.let(vm::pickedProjectivy) }
val pickFile = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri -> uri?.let(vm::push) }
val saveFile = rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("application/octet-stream"), vm::saveTo)
val saveScreenshot = rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("image/png"), vm::screenshotTo)
@@ -345,6 +346,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
fireCheck = vm::checkProjectivy,
fireInstall = vm::installProjectivy,
fireDismiss = vm::dismissProjectivy,
+ firePick = { pickProjectivy.launch(arrayOf(InDownloads.APK)) },
),
snackbar = snackbar,
direct = vm.directDownload,
@@ -392,7 +394,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
forget = vm::forget,
rename = vm::rename,
restoreAll = vm::restoreAll,
- pickApp = { pickApp.launch(arrayOf("*/*")) },
+ pickApp = { pickApp.launch(InDownloads.APPS) },
allowDowngrade = vm::allowDowngrade,
install = vm::install,
closeSideload = vm::closeSideload,
@@ -513,6 +515,11 @@ private fun Context.openWifiSettings() {
private fun accessActions(vm: TellyscopeViewModel, back: () -> Unit) = AccessActions(
back = back,
markMine = vm::markMine,
+ markKeyMine = vm::markKeyMine,
+ showRequest = vm::showRequest,
+ answerRequest = vm::answerRequest,
+ dismissRequest = vm::dismissRequest,
+ closeAlert = vm::closeAlert,
askRemove = vm::askRemoveAccess,
close = vm::closeRemoval,
remove = vm::removeAccess,
@@ -523,3 +530,29 @@ private fun accessActions(vm: TellyscopeViewModel, back: () -> Unit) = AccessAct
checkAgain = vm::checkAgain,
restart = vm::restartToRemove,
)
+
+/**
+ * The system file picker, opened in Downloads, where a browser saves what it downloads. Most pickers
+ * start there; some ignore it. It can't be kept there, or searched for the user.
+ */
+private object InDownloads {
+ const val APK = "application/vnd.android.package-archive"
+
+ /**
+ * Apps and the bundle types file managers give .apks and .xapk files, which vary: zip, unknown
+ * ("octet-stream"), or a type of their own. Photos, videos and documents are greyed out.
+ */
+ val APPS = arrayOf(APK, "application/zip", "application/x-zip-compressed", "application/octet-stream", "application/xapk-package-archive")
+
+ private val DOWNLOADS: Uri = DocumentsContract.buildDocumentUri("com.android.providers.downloads.documents", "downloads")
+
+ class One : ActivityResultContracts.OpenDocument() {
+ override fun createIntent(context: Context, input: Array<String>): Intent =
+ super.createIntent(context, input).putExtra(DocumentsContract.EXTRA_INITIAL_URI, DOWNLOADS)
+ }
+
+ class Multiple : ActivityResultContracts.OpenMultipleDocuments() {
+ override fun createIntent(context: Context, input: Array<String>): Intent =
+ super.createIntent(context, input).putExtra(DocumentsContract.EXTRA_INITIAL_URI, DOWNLOADS)
+ }
+}
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
index 782ce7d..a397125 100644
--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt
@@ -101,6 +101,10 @@ class AdbDeviceSource(context: Context) : DeviceSource {
/** TVs whose Apps tab got Not now on the card about a better home screen. */
private val launcherCards = FoldBook(File(appContext.filesDir, "launcher-card.properties"))
private val mine = MineBook(File(appContext.filesDir, "mine.tsv"))
+ /** The keys each TV was seen to allow, so one allowed behind Tellyscope's back shows as new. */
+ private val knownKeys = MineBook(File(appContext.filesDir, "known-keys.tsv"))
+ /** Per TV, fingerprints seen on its prompt in this launch: allowed while the user watched, so not new. */
+ private val watchedKeys = ConcurrentHashMap<String, Set<String>>()
private val networkNames = NetworkNames()
/** Last label seen per package, so history entries read like the app list. */
private val labels = ConcurrentHashMap<String, String>()
@@ -966,7 +970,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {
override suspend fun screenshot(deviceId: String, sink: Sink) = Tweaks(session(deviceId)).screenshot(sink)
- override suspend fun connectionRequest(deviceId: String) = ConnectionPrompt(session(deviceId)).pending()
+ override suspend fun connectionRequest(deviceId: String) = ConnectionPrompt(session(deviceId)).pending()?.also { watch(deviceId, it.fingerprint) }
override suspend fun answerRequest(deviceId: String, request: ConnectionRequest, allow: Boolean, always: Boolean) =
ConnectionPrompt(session(deviceId)).answer(request, allow, always)
@@ -978,7 +982,13 @@ class AdbDeviceSource(context: Context) : DeviceSource {
override suspend fun access(deviceId: String): TvAccess {
val a = Access(session(deviceId))
val port = links[deviceId]?.port ?: Access.CLASSIC_PORT
- val access = TvAccess.of(a.clients(port), a.keys(), phoneAddresses(), deviceId, mine[key(deviceId)], phoneFingerprint())
+ val pending = runCatching { connectionRequest(deviceId)?.fingerprint }.getOrNull()
+ val tv = key(deviceId)
+ val access = TvAccess.of(
+ a.clients(port), a.keys(), phoneAddresses(), deviceId, mine[tv], phoneFingerprint(),
+ pending = pending, known = knownKeys[tv].takeIf { knownKeys.has(tv) }, watched = watchedKeys[deviceId].orEmpty(),
+ )
+ access.allowed?.let { keys -> knownKeys.set(tv, knownKeys[tv] + keys.filterNot { it.new }.map { it.fingerprint }) }
// Other computers only: this phone and apps on the TV itself need no name.
val lookup = access.connected.orEmpty().filter { it.who == AccessClient.Who.Other || it.who == AccessClient.Who.Mine }
return access.named(networkNames.of(lookup.map { it.address }))
@@ -989,9 +999,22 @@ class AdbDeviceSource(context: Context) : DeviceSource {
mine.add(key(deviceId), address)
}
+ /** A prompt the app showed: the key on it, once allowed, isn't new. */
+ private fun watch(deviceId: String, fingerprint: String) {
+ if (fingerprint.isNotEmpty()) watchedKeys.merge(deviceId, setOf(fingerprint), Set<String>::plus)
+ }
+
+ override suspend fun markKeyMine(deviceId: String, fingerprint: String) {
+ restored.await()
+ knownKeys.add(key(deviceId), fingerprint)
+ }
+
override suspend fun peripherals(deviceId: String) = Peripherals(session(deviceId)).read()
- override suspend fun revokeAll(deviceId: String) = Access(session(deviceId)).revokeAll()
+ /** Every key goes, so none counts as known after: a computer allowed again later shows as new. */
+ override suspend fun revokeAll(deviceId: String) = Access(session(deviceId)).revokeAll().also { ok ->
+ if (ok) knownKeys.set(key(deviceId), setOfNotNull(phoneFingerprint()))
+ }
override suspend fun openDeveloperOptions(deviceId: String) = Access(session(deviceId)).openDeveloperOptions()
@@ -1027,6 +1050,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {
names.rekey(deviceId, key)
docks.rekey(deviceId, key)
mine.rekey(deviceId, key)
+ knownKeys.rekey(deviceId, key)
remember(deviceId)
}
return key
diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
index 027836a..f5f0da6 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt
@@ -226,6 +226,9 @@ interface DeviceSource {
/** "It's mine": connections from [address] stop counting toward the warning on this TV. */
suspend fun markMine(deviceId: String, address: String) {}
+ /** "It's mine" on a new allowed computer: [fingerprint] counts as known on this TV from now on. */
+ suspend fun markKeyMine(deviceId: String, fingerprint: String) {}
+
/** Bluetooth, input, USB storage, HDMI-CEC and audio, for the Connected devices card. */
suspend fun peripherals(deviceId: String): List<Peripheral> = emptyList()
diff --git a/app/src/main/java/app/tellyscope/data/LauncherDownload.kt b/app/src/main/java/app/tellyscope/data/LauncherDownload.kt
index 33285d1..31b2ada 100644
--- a/app/src/main/java/app/tellyscope/data/LauncherDownload.kt
+++ b/app/src/main/java/app/tellyscope/data/LauncherDownload.kt
@@ -4,6 +4,7 @@ package app.tellyscope.data
import android.content.Context
import android.content.pm.PackageManager
+import android.net.Uri
import android.os.Build
import androidx.core.content.pm.PackageInfoCompat
import app.tellyscope.adb.ApkInfo
@@ -48,13 +49,31 @@ fun parseRelease(json: String): LauncherRelease? = runCatching {
val url = apk?.getString("browser_download_url")
val size = apk?.getLong("size") ?: 0L
LauncherRelease(tag, r.getString("html_url"), url.orEmpty(), size).takeIf {
- !r.optBoolean("draft") && !r.optBoolean("prerelease") &&
- it.page == "$PROJECTIVY_RELEASES/tag/$tag" &&
- it.apk.startsWith("$PROJECTIVY_RELEASES/download/$tag/") &&
- size in 1..MAX_APK_BYTES
+ !r.optBoolean("draft") && !r.optBoolean("prerelease") && it.valid()
}
}.getOrNull()
+/** On Projectivy's own repo, its one APK served from that release, and about the right size. */
+private fun LauncherRelease.valid() =
+ page == "$PROJECTIVY_RELEASES/tag/$version" && apk.startsWith("$PROJECTIVY_RELEASES/download/$version/") && size in 1..MAX_APK_BYTES
+
+/** The tag github.com's `releases/latest` redirects to, from its Location; null for anywhere else. */
+fun latestTag(location: String?): String? =
+ location?.removePrefix("$PROJECTIVY_RELEASES/tag/")?.takeIf { it != location && it.isNotEmpty() && '/' !in it && '?' !in it }
+
+/** The release page's one APK, from its asset list's links: the full URL, or null unless there is exactly one. */
+fun pageApk(html: String, tag: String): String? {
+ val path = PROJECTIVY_RELEASES.removePrefix("https://github.com") + "/download/$tag/"
+ return Regex("href=\"(${Regex.escape(path)}[^\"/?#]+\\.apk)\"").findAll(html).map { it.groupValues[1] }.distinct()
+ .singleOrNull()?.let { "https://github.com$it" }
+}
+
+/**
+ * GitHub's API turned the lookup down: it allows 60 an hour per network without a login. [until] is
+ * when it takes them again, epoch millis, when it said.
+ */
+class RateLimited(val until: Long?) : IOException("rate-limited")
+
/** Projectivy, signed only by its developer: [signers] are the SHA-256s of the APK's certificates. */
fun isProjectivy(packageName: String, signers: Set<String>) =
packageName == PROJECTIVY && signers.isNotEmpty() && PROJECTIVY_SIGNERS.containsAll(signers)
@@ -69,14 +88,67 @@ interface LauncherDownload {
/** Downloads [release]'s APK and checks it. Throws [NotProjectivy], or IOException on a failed download. */
suspend fun fetch(release: LauncherRelease, onProgress: (Progress) -> Unit): PickedApp
+
+ /** A file the user downloaded and picked, checked the same way. Throws [NotProjectivy], or IOException when it can't be read. */
+ suspend fun open(uri: Uri): PickedApp
}
class AndroidLauncherDownload(context: Context) : LauncherDownload {
private val ctx = context.applicationContext
private val dir get() = File(ctx.cacheDir, "launcher")
- override suspend fun latest(): LauncherRelease =
- parseRelease(download(PROJECTIVY_LATEST).decodeToString()) ?: throw IOException("no Projectivy release")
+ /**
+ * From GitHub's API, or, when that is rate-limited, from the release page it links to, which isn't.
+ * Throws [RateLimited] only when the page didn't answer either.
+ */
+ override suspend fun latest(): LauncherRelease = withContext(Dispatchers.IO) {
+ val limited = try {
+ return@withContext parseRelease(api()) ?: throw IOException("no Projectivy release")
+ } catch (e: RateLimited) {
+ e
+ }
+ runCatching { fromPage() }.getOrNull() ?: throw limited
+ }
+
+ private fun api(): String {
+ val c = URL(PROJECTIVY_LATEST).openConnection() as HttpURLConnection
+ c.connectTimeout = 10_000
+ c.readTimeout = 10_000
+ try {
+ val code = c.responseCode
+ if ((code == 403 || code == 429) && c.getHeaderField("x-ratelimit-remaining") == "0") {
+ throw RateLimited(c.getHeaderField("x-ratelimit-reset")?.toLongOrNull()?.times(1000))
+ }
+ if (code != 200) throw IOException("HTTP $code")
+ return c.inputStream.use { it.readBytes() }.decodeToString()
+ } finally {
+ c.disconnect()
+ }
+ }
+
+ /** `releases/latest` redirects to the tag, whose asset list names the APK; its size comes from the download's own length. */
+ private suspend fun fromPage(): LauncherRelease? {
+ val c = URL("$PROJECTIVY_RELEASES/latest").openConnection() as HttpURLConnection
+ c.instanceFollowRedirects = false
+ c.connectTimeout = 10_000
+ c.readTimeout = 10_000
+ val tag = try {
+ latestTag(c.takeIf { it.responseCode in 301..302 }?.getHeaderField("Location"))
+ } finally {
+ c.disconnect()
+ } ?: return null
+ val apk = pageApk(download("$PROJECTIVY_RELEASES/expanded_assets/$tag").decodeToString(), tag) ?: return null
+ val head = URL(apk).openConnection() as HttpURLConnection
+ head.requestMethod = "HEAD"
+ head.connectTimeout = 10_000
+ head.readTimeout = 10_000
+ val size = try {
+ head.contentLengthLong.takeIf { head.responseCode == 200 } ?: return null
+ } finally {
+ head.disconnect()
+ }
+ return LauncherRelease(tag, "$PROJECTIVY_RELEASES/tag/$tag", apk, size).takeIf { it.valid() }
+ }
override suspend fun fetch(release: LauncherRelease, onProgress: (Progress) -> Unit): PickedApp = withContext(Dispatchers.IO) {
dir.deleteRecursively()
@@ -108,6 +180,28 @@ class AndroidLauncherDownload(context: Context) : LauncherDownload {
read(file)
}
+ override suspend fun open(uri: Uri): PickedApp = withContext(Dispatchers.IO) {
+ dir.deleteRecursively()
+ dir.mkdirs()
+ val file = File(dir, "projectivy.apk")
+ val input = ctx.contentResolver.openInputStream(uri) ?: throw IOException("can't read $uri")
+ input.use { s ->
+ file.outputStream().use { out ->
+ val buf = ByteArray(64 * 1024)
+ var done = 0L
+ while (true) {
+ ensureActive()
+ val n = s.read(buf).takeIf { it >= 0 } ?: break
+ done += n
+ // Far past Projectivy's size: some other file, never read whole.
+ if (done > MAX_APK_BYTES) throw NotProjectivy()
+ out.write(buf, 0, n)
+ }
+ }
+ }
+ read(file)
+ }
+
/** The package manager checks the APK's signature while it reads the certificates. */
private fun read(file: File): PickedApp {
val pm = ctx.packageManager
diff --git a/app/src/main/java/app/tellyscope/data/TvAccess.kt b/app/src/main/java/app/tellyscope/data/TvAccess.kt
index b9d0afb..10ef508 100644
--- a/app/src/main/java/app/tellyscope/data/TvAccess.kt
+++ b/app/src/main/java/app/tellyscope/data/TvAccess.kt
@@ -15,7 +15,10 @@ data class TvAccess(
val connected: List<AccessClient>? = null,
val allowed: List<AccessKey>? = null,
) {
- /** Connections the warning is about: neither this phone nor an address the user said is theirs. */
+ /**
+ * Connections the warning is about: neither this phone nor an address the user said is theirs.
+ * One [AccessClient.Who.Waiting] isn't in yet, so it doesn't count.
+ */
val others: List<AccessClient> get() = connected.orEmpty().filter { it.who == AccessClient.Who.Other || it.who == AccessClient.Who.OnTv }
val warning: Boolean get() = others.isNotEmpty()
@@ -32,6 +35,14 @@ data class TvAccess(
* Sorts the TV's open connections into this phone, the user's own and the rest. A
* loopback connection is this phone only when Tellyscope itself reaches the TV over
* loopback ([tvHost], as through an emulator's forward); otherwise it is an app on the TV.
+ *
+ * [pending]: the fingerprint on the TV's "Allow debugging?" prompt now, empty when the prompt
+ * can't be read, null when there is none. A prompt for a key that isn't allowed means a
+ * connection is waiting on it; with exactly one other connection, that one is
+ * [AccessClient.Who.Waiting]. With more, nothing says which, so none is.
+ *
+ * [known]: the keys this TV was seen to allow before, null on the first read, when every key
+ * counts as known. A key that isn't, and wasn't seen on a prompt ([watched]), is [AccessKey.new].
*/
fun of(
clients: List<AdbClient>?,
@@ -40,6 +51,9 @@ data class TvAccess(
tvHost: String,
mine: Set<String>,
phoneFingerprint: String?,
+ pending: String? = null,
+ known: Set<String>? = null,
+ watched: Set<String> = emptySet(),
): TvAccess {
val tvLoopback = tvHost == "localhost" || AdbClient(tvHost, 0).loopback
val connected = clients?.groupBy { it.address }?.map { (address, rows) ->
@@ -52,9 +66,14 @@ data class TvAccess(
else -> AccessClient.Who.Other
}
AccessClient(address, rows.size, who)
+ }?.let { list ->
+ val waiting = pending != null && keys?.none { it.fingerprint == pending } != false && list.count { it.who == AccessClient.Who.Other } == 1
+ if (waiting) list.map { if (it.who == AccessClient.Who.Other) it.copy(who = AccessClient.Who.Waiting) else it } else list
}?.sortedBy { it.who.ordinal }
- val allowed = keys?.map { AccessKey(it.fingerprint, it.name, it.lastSeen, phone = it.fingerprint == phoneFingerprint) }
- ?.sortedByDescending { it.phone }
+ val allowed = keys?.map { k ->
+ val phone = k.fingerprint == phoneFingerprint
+ AccessKey(k.fingerprint, k.name, k.lastSeen, phone, new = !phone && known != null && k.fingerprint !in known && k.fingerprint !in watched)
+ }?.sortedWith(compareByDescending<AccessKey> { it.phone }.thenByDescending { it.new })
return TvAccess(connected, allowed)
}
}
@@ -65,15 +84,19 @@ data class TvAccess(
* describes the address only, never which key is behind it.
*/
data class AccessClient(val address: String, val connections: Int, val who: Who, val name: String? = null) {
- enum class Who { Phone, Mine, Other, OnTv }
+ /** [Waiting]: its "Allow debugging?" prompt is on the TV, so it can't do anything yet. */
+ enum class Who { Phone, Mine, Waiting, Other, OnTv }
}
-/** An allowed computer. [lastSeen] is rough: the TV stamps keys, not sessions. */
-data class AccessKey(val fingerprint: String, val name: String?, val lastSeen: Long?, val phone: Boolean = false)
+/**
+ * An allowed computer. [lastSeen] is rough: the TV stamps keys, not sessions. [new]: allowed while
+ * Tellyscope wasn't watching, until the user says it's theirs.
+ */
+data class AccessKey(val fingerprint: String, val name: String?, val lastSeen: Long?, val phone: Boolean = false, val new: Boolean = false)
/**
- * Addresses the user marked "It's mine" on each TV, keyed like [NameBook]. `key \t address` per
- * line; null file keeps it in memory (tests, the fake source).
+ * A set of strings per TV, keyed like [NameBook]: the addresses the user marked "It's mine", or the
+ * keys a TV was seen to allow. `key \t value` per line; null file keeps it in memory (tests, the fake source).
*/
class MineBook(private val file: File? = null) {
private val mine = linkedMapOf<String, Set<String>>()
@@ -90,6 +113,16 @@ class MineBook(private val file: File? = null) {
@Synchronized
operator fun get(key: String): Set<String> = mine[key].orEmpty()
+ /** Whether [key] has a set at all, even one that was never added to since. */
+ @Synchronized
+ fun has(key: String): Boolean = key in mine
+
+ @Synchronized
+ fun set(key: String, values: Set<String>) {
+ mine[key] = values.filter { it.isNotBlank() && '\t' !in it && '\n' !in it }.toSet()
+ save()
+ }
+
@Synchronized
fun add(key: String, address: String) {
val clean = address.trim().takeIf { it.isNotEmpty() && '\t' !in it && '\n' !in it } ?: return
diff --git a/app/src/main/java/app/tellyscope/ui/AccessUi.kt b/app/src/main/java/app/tellyscope/ui/AccessUi.kt
index e252198..70b991e 100644
--- a/app/src/main/java/app/tellyscope/ui/AccessUi.kt
+++ b/app/src/main/java/app/tellyscope/ui/AccessUi.kt
@@ -87,6 +87,13 @@ import app.tellyscope.data.TvAccess
data class AccessActions(
val back: () -> Unit = {},
val markMine: (String) -> Unit = {},
+ /** "It's mine" on a new allowed computer, by its fingerprint. */
+ val markKeyMine: (String) -> Unit = {},
+ /** Answer on a waiting connection: the TV's prompt, over this screen. */
+ val showRequest: () -> Unit = {},
+ val answerRequest: (allow: Boolean, always: Boolean) -> Unit = { _, _ -> },
+ val dismissRequest: () -> Unit = {},
+ val closeAlert: () -> Unit = {},
val askRemove: () -> Unit = {},
val close: () -> Unit = {},
val remove: () -> Unit = {},
@@ -334,6 +341,10 @@ fun AccessScreen(state: UiState, actions: AccessActions, snackbar: SnackbarHostS
}
}
if (removal?.step == Removal.Step.Confirm) ConfirmRemoval(actions)
+ // The TV's prompt shows here as on the TV's page, so a computer asking in is answered where it's listed.
+ else if (removal == null && device.state == DeviceState.Online) {
+ ui.request?.let { RequestDialog(it, ui.busy == ANSWERING, actions.answerRequest, actions.dismissRequest, actions.closeAlert) }
+ }
}
/** C4: the one warning before every key on the TV goes, this phone's included. */
@@ -371,7 +382,7 @@ private fun AccessList(access: TvAccess?, now: Long, online: Boolean, actions: A
when (val list = access?.allowed) {
null -> item { Muted(if (access == null) "Checking…" else Copy.CANT_CHECK_ALLOWED) }
emptyList<AccessKey>() -> item { Muted(Copy.NOBODY_ALLOWED) }
- else -> segmented(list) { AllowedRow(it, now) }
+ else -> segmented(list) { AllowedRow(it, now, actions) }
}
item {
Column(Modifier.padding(top = 16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
@@ -423,11 +434,23 @@ private fun ConnectedRow(client: AccessClient, actions: AccessActions) {
AccessClient.Who.OnTv -> Copy.ON_TV
else -> client.address
},
- chip = phone,
+ chip = when (client.who) {
+ AccessClient.Who.Phone -> Chip.Tellyscope
+ AccessClient.Who.Waiting -> Chip.Waiting
+ else -> null
+ },
) {
if (phone || client.who == AccessClient.Who.OnTv) Sub(client.address)
- Sub(Copy.connections(client.connections))
+ // Not in yet, so no connection count: it isn't using the TV.
+ if (client.who != AccessClient.Who.Waiting) Sub(Copy.connections(client.connections))
when (client.who) {
+ AccessClient.Who.Waiting -> {
+ Text(Copy.WAITING_LINE, style = MaterialTheme.typography.bodyMedium)
+ Sub(Copy.WAITING_TEXT)
+ Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.CenterEnd) {
+ FilledTonalButton(onClick = actions.showRequest) { Text(Copy.ANSWER) }
+ }
+ }
AccessClient.Who.Other, AccessClient.Who.OnTv -> {
Text(Copy.NOT_THIS_PHONE, style = MaterialTheme.typography.bodyMedium, color = c.error)
Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.CenterEnd) {
@@ -441,7 +464,7 @@ private fun ConnectedRow(client: AccessClient, actions: AccessActions) {
}
@Composable
-private fun AllowedRow(key: AccessKey, now: Long) {
+private fun AllowedRow(key: AccessKey, now: Long, actions: AccessActions) {
val name = key.name
AccessRow(
icon = when {
@@ -451,25 +474,41 @@ private fun AllowedRow(key: AccessKey, now: Long) {
else -> AccessIcons.Desktop
},
title = if (key.phone) Copy.THIS_PHONE else name ?: Copy.UNNAMED_COMPUTER,
- chip = key.phone,
+ chip = if (key.phone) Chip.Tellyscope else if (key.new) Chip.New else null,
) {
Text(Copy.shortFingerprint(key.fingerprint), style = MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace), color = MaterialTheme.colorScheme.onSurfaceVariant)
Sub(Copy.lastSeen(key.lastSeen, now))
+ if (key.new) {
+ Text(Copy.NEW_KEY_TEXT, style = MaterialTheme.typography.bodyMedium, modifier = Modifier.padding(top = 4.dp))
+ Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.CenterEnd) {
+ FilledTonalButton(onClick = { actions.markKeyMine(key.fingerprint) }) { Text(Copy.ITS_MINE) }
+ }
+ }
}
}
+/** Beside a row's title: this phone is Tellyscope, filled; Waiting and New are neutral outlines, a state and not an alarm. */
+private enum class Chip(val text: String) { Tellyscope(Copy.TELLYSCOPE), Waiting(Copy.WAITING_CHIP), New(Copy.NEW_CHIP) }
+
@Composable
-private fun AccessRow(icon: ImageVector, title: String, chip: Boolean, lines: @Composable () -> Unit) {
+private fun AccessRow(icon: ImageVector, title: String, chip: Chip?, lines: @Composable () -> Unit) {
+ val c = MaterialTheme.colorScheme
Row(Modifier.padding(16.dp)) {
- Icon(icon, contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant)
+ Icon(icon, contentDescription = null, tint = c.onSurfaceVariant)
Spacer(Modifier.width(16.dp))
Column(Modifier.weight(1f)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(title, style = MaterialTheme.typography.titleMedium)
- if (chip) {
+ if (chip != null) {
Spacer(Modifier.width(8.dp))
- Surface(shape = RoundedCornerShape(8.dp), color = MaterialTheme.colorScheme.secondaryContainer) {
- Text(Copy.TELLYSCOPE, style = MaterialTheme.typography.labelMedium, modifier = Modifier.padding(horizontal = 8.dp, vertical = 2.dp))
+ val filled = chip == Chip.Tellyscope
+ Surface(
+ shape = RoundedCornerShape(8.dp),
+ color = if (filled) c.secondaryContainer else Color.Transparent,
+ contentColor = if (filled) c.onSecondaryContainer else c.onSurfaceVariant,
+ border = if (filled) null else BorderStroke(1.dp, c.outline),
+ ) {
+ Text(chip.text, style = MaterialTheme.typography.labelMedium, modifier = Modifier.padding(horizontal = 8.dp, vertical = 2.dp))
}
}
}
diff --git a/app/src/main/java/app/tellyscope/ui/Copy.kt b/app/src/main/java/app/tellyscope/ui/Copy.kt
index 495dcb4..f203402 100644
--- a/app/src/main/java/app/tellyscope/ui/Copy.kt
+++ b/app/src/main/java/app/tellyscope/ui/Copy.kt
@@ -238,14 +238,13 @@ object Copy {
const val INSTALL_PROJECTIVY = "Install Projectivy"
const val FIRE_INSTALL_TEXT = "A home screen without ads. Tellyscope installs it on the TV for you; there's nothing to do on the TV."
- fun installProjectivyOn(tv: String) = "Install Projectivy on $tv?"
-
fun downloadsFrom(name: String) = "Tellyscope downloads $name from the developer's own release page:"
fun release(version: String, size: Long) = "Release $version · ${bytes(size)}"
+ const val WHERE_FROM = "Where it comes from"
const val SIGNED_CHECK =
- "and checks it's signed by Projectivy's developer before installing it on the TV. Tellyscope isn't affiliated with Projectivy."
+ "Tellyscope checks it's signed by Projectivy's developer before installing it on the TV. Tellyscope isn't affiliated with Projectivy."
const val DOWNLOAD_AND_INSTALL = "Download and install"
/** Download directly on a TV with the Play Store: what Tellyscope checks, what it doesn't, and the safer way. */
@@ -257,16 +256,49 @@ object Copy {
const val DOWNLOAD_ANYWAY = "Download anyway"
const val STORE_INSTEAD = "Get it from the Play Store on the TV instead."
- fun downloading(percent: Int) = "Downloading · $percent%"
+ /** Install Projectivy's steps, one panel: download (or the picked file), the check, the install. */
+ fun installing(name: String) = "Installing $name"
+ const val STEP_DOWNLOAD = "Download from GitHub"
+ const val STEP_DOWNLOADED = "Downloaded"
+ fun downloading(percent: Int, done: Long, total: Long) = "Downloading · $percent% · ${bytes(done)} of ${bytes(total)}"
+ const val STEP_PICKED = "Picked a file"
+ const val STEP_CHECK = "Check it's Projectivy"
+ const val STEP_CHECKING = "Checking it's Projectivy…"
+ const val STEP_CHECKED = "It's Projectivy"
+ const val STEP_CHECKED_TEXT = "Signed by its developer"
+ const val STEP_FAILED = "Not Projectivy"
+ const val STEP_FAILED_TEXT = "Package name or signature didn't match"
+ fun installOn(tv: String) = "Install on $tv"
fun installingOn(tv: String) = "Installing on $tv…"
+ /** X while it downloads: nothing is on the TV yet. */
+ const val STOP_TITLE = "Stop the download?"
+ const val STOP_TEXT = "Nothing is on the TV yet. You can start again any time."
+ const val STOP = "Stop"
+ const val KEEP_DOWNLOADING = "Keep downloading"
+
const val NOT_PROJECTIVY = "That download isn't Projectivy"
const val NOT_PROJECTIVY_TEXT =
"The file from GitHub didn't match Projectivy's package name or its developer's signature, so Tellyscope installed nothing on the TV."
+ const val NOT_PROJECTIVY_FILE = "That file isn't Projectivy"
+ const val NOT_PROJECTIVY_FILE_TEXT =
+ "It didn't match Projectivy's package name or its developer's signature, so Tellyscope installed nothing on the TV."
+ const val CANT_READ_FILE = "Tellyscope couldn't read that file. Pick it again, or download it again."
+ fun cantInstall(name: String) = "Couldn't install $name"
+
+ /** Couldn't download: GitHub's limit for the network ([until] is a clock time), or no way to reach it. */
const val NO_DOWNLOAD = "Couldn't download Projectivy"
- const val NO_DOWNLOAD_TEXT = "Check the phone's internet, then try again. Or download it yourself from Projectivy's release page."
- const val OPEN_DOWNLOAD_PAGE = "Open the download page"
+ const val NO_DOWNLOAD_OFFLINE = "The phone can't reach GitHub. Check its internet, then try again."
+ fun noDownloadLimited(until: String?) =
+ "GitHub is limiting downloads from your network ${if (until != null) "until $until" else "for a while"}. Try again then, or download it yourself."
+ const val OR_YOURSELF = "Or download it yourself"
+ const val YOURSELF_PAGE = "Download the app file (.apk) from the release page in your browser."
+ fun yourselfPick(file: String?) = "Come back and pick ${file ?: "it"}. Tellyscope checks it's Projectivy before installing it."
+ const val LATEST_RELEASE = "Latest release"
+ const val PICK_DOWNLOADED = "Pick the downloaded file"
+ const val PICK_ANOTHER = "Pick another file"
+ const val TRY_DOWNLOAD_AGAIN = "Try download again"
const val NOT_INSTALLED_TEXT =
"The Play Store closed on the TV before it was installed. If the Store said it isn't available for this TV, choose another launcher."
@@ -715,6 +747,12 @@ object Copy {
const val TELLYSCOPE = "Tellyscope"
const val NOT_THIS_PHONE = "Not this phone"
const val YOURS = "Yours"
+ const val WAITING_CHIP = "Waiting"
+ const val WAITING_LINE = "Waiting for you to allow it on the TV"
+ const val WAITING_TEXT = "An Allow prompt for it is on the TV now. It can't do anything until you choose Allow there. Not yours? Choose Deny."
+ const val ANSWER = "Answer"
+ const val NEW_CHIP = "New"
+ const val NEW_KEY_TEXT = "Allowed on the TV while Tellyscope wasn't watching. Not yours? Remove all other access."
const val ALLOWED_COMPUTERS = "Allowed computers"
const val UNNAMED_COMPUTER = "Unnamed computer"
const val CANT_CHECK_CONNECTED = "This TV doesn't say who is connected."
diff --git a/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt b/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt
index 393c349..9bf9ae3 100644
--- a/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt
+++ b/app/src/main/java/app/tellyscope/ui/LauncherFlowUi.kt
@@ -6,6 +6,7 @@ package app.tellyscope.ui
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
+import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -37,6 +38,7 @@ import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Icon
+import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearWavyProgressIndicator
import androidx.compose.material3.LoadingIndicator
@@ -135,10 +137,12 @@ data class LauncherActions(
val later: () -> Unit = {},
/** Fire OS: Install Projectivy, which reads the latest release for the confirm dialog. Try again does the same. */
val fireCheck: () -> Unit = {},
- /** Fire OS: Download and install in the confirm dialog. */
+ /** Fire OS: Download and install on the confirm step. */
val fireInstall: () -> Unit = {},
- /** Fire OS: Cancel, Close or OK in a dialog. */
+ /** Fire OS: X, Stop or OK on a step. */
val fireDismiss: () -> Unit = {},
+ /** Fire OS: Pick the downloaded file, after Couldn't download. */
+ val firePick: () -> Unit = {},
)
/** The Apps tab's card: a launcher without ads, from the Play Store ([fire]: Projectivy, installed by Tellyscope). Not now puts it away on this TV. */
@@ -175,7 +179,23 @@ fun LauncherScreen(
val app = apps.firstOrNull { it.packageName == if (picking) chosen else flow.pkg }
val current = app?.let { homeLabel(apps, it) }
val switch = { service: Boolean -> if (picking) actions.makeHome(chosen, service) else actions.switch(service) }
- flow.fire?.let { FireDialog(it, device, actions) }
+ // Fire OS's install, from the start; Download directly once it has read the release. The picker gives way to it.
+ val fire = when {
+ !picking -> null
+ flow.fireOs -> flow.fire ?: FireInstall()
+ else -> flow.fire?.takeIf { it.step != null && it.step != FireInstall.Step.Checking }
+ }
+ var askStop by rememberSaveable { mutableStateOf(false) }
+ if (askStop && fire?.step == FireInstall.Step.Downloading) {
+ StopDialog(onKeep = { askStop = false }, onStop = { askStop = false; actions.fireDismiss() })
+ }
+ val close: () -> Unit = {
+ when {
+ fire?.step == FireInstall.Step.Downloading -> askStop = true
+ fire != null && fire.store -> actions.fireDismiss()
+ else -> actions.close()
+ }
+ }
if (askService && app != null && current != null) {
ServiceDialog(
app.label, current,
@@ -196,7 +216,10 @@ fun LauncherScreen(
},
)
},
- navigationIcon = { IconButton(onClick = actions.close) { Icon(Icons.Default.Close, contentDescription = "Close") } },
+ // Dimmed while it installs: stopping halfway could leave the TV half done.
+ navigationIcon = {
+ IconButton(onClick = close, enabled = fire?.step != FireInstall.Step.Installing) { Icon(Icons.Default.Close, contentDescription = "Close") }
+ },
)
},
bottomBar = {
@@ -206,8 +229,8 @@ fun LauncherScreen(
verticalAlignment = Alignment.CenterVertically,
) {
when (flow.step) {
- LauncherFlow.Step.Pick -> if (flow.fireOs) {
- IconButtonText(LauncherIcons.Download, Copy.INSTALL_PROJECTIVY, enabled = flow.fire?.step == null) { actions.fireCheck() }
+ LauncherFlow.Step.Pick -> if (fire != null) {
+ FireButtons(fire, actions, Modifier.weight(1f))
} else {
val have = installedLauncher(apps, chosen)
when {
@@ -262,7 +285,7 @@ fun LauncherScreen(
}
val c = MaterialTheme.colorScheme
when (flow.step) {
- LauncherFlow.Step.Pick -> if (flow.fireOs) FirePick() else Picker(chosen, apps, direct) { chosen = it }
+ LauncherFlow.Step.Pick -> if (fire != null) FireBody(fire, device, actions.firePick) else Picker(chosen, apps, direct) { chosen = it }
LauncherFlow.Step.Waiting -> {
Hero(LauncherIcons.Download, c.secondaryContainer, c.onSecondaryContainer)
Headed(Copy.INSTALL_IT, bold(Copy.installItText(label), label, "Install"))
@@ -370,116 +393,225 @@ private fun FirePick() {
}
/**
- * Fire OS's install, one dialog per [FireInstall.Step]: where it downloads from, the source row opening that release
- * page on the phone, then the download and the install with no way out, then what went wrong. After Download
- * directly ([FireInstall.store]) the confirm is a warning, and it and a wrong signature offer the Play Store instead.
+ * Fire OS's install as steps of this one screen, per [FireInstall.Step]: where it downloads from (with the
+ * source row opening that release page on the phone), the download, the check and the install, then what
+ * went wrong. Couldn't download offers the release page and Pick the downloaded file, checked the same way.
+ * After Download directly ([FireInstall.store]) the confirm is a warning, and it and a wrong signature offer
+ * the Play Store instead.
*/
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
-private fun FireDialog(f: FireInstall, device: Device, actions: LauncherActions) {
- val step = f.step?.takeIf { it != FireInstall.Step.Checking } ?: return
+private fun FireBody(f: FireInstall, device: Device, onPick: () -> Unit) {
+ val c = MaterialTheme.colorScheme
val uri = LocalUriHandler.current
val label = launcherName(PROJECTIVY)
val release = f.release
- val failed = step == FireInstall.Step.NotProjectivy || step == FireInstall.Step.NoDownload || step == FireInstall.Step.Refused
- val warn = step == FireInstall.Step.Confirm && f.store
- val store = { actions.install(PROJECTIVY) }
- AlertDialog(
- onDismissRequest = {},
- properties = Sticky,
- icon = if (failed || warn) ({ WarningBadge() }) else null,
- title = {
- Text(
- when (step) {
- FireInstall.Step.Confirm -> if (f.store) Copy.downloadDirectly(label) else Copy.installProjectivyOn(name(device))
- FireInstall.Step.NotProjectivy -> Copy.NOT_PROJECTIVY
- FireInstall.Step.NoDownload -> Copy.NO_DOWNLOAD
- FireInstall.Step.Refused -> "Couldn't install $label"
- else -> label
- },
+ val openPage = { uri.openUri(release?.page ?: "$PROJECTIVY_RELEASES/latest") }
+ when (f.step) {
+ null, FireInstall.Step.Checking, FireInstall.Step.Confirm -> if (f.store) {
+ WarningBadge()
+ Text(Copy.downloadDirectly(label), style = MaterialTheme.typography.headlineMedium)
+ Text(Copy.downloadsFrom(label), style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant)
+ release?.let { SourceRow(it, openPage) }
+ Text(Copy.DIRECT_CHECK, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant)
+ Text(Copy.STORE_SAFER, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant)
+ } else {
+ FirePick()
+ if (release != null) {
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text(Copy.WHERE_FROM, style = MaterialTheme.typography.labelLarge, color = c.primary)
+ SourceRow(release, openPage)
+ }
+ Text(Copy.SIGNED_CHECK, style = MaterialTheme.typography.bodySmall, color = c.onSurfaceVariant)
+ }
+ }
+ FireInstall.Step.Downloading, FireInstall.Step.Reading, FireInstall.Step.Installing -> {
+ Text(Copy.installing(label), style = MaterialTheme.typography.labelLarge, color = c.primary)
+ FireSteps(f, device)
+ Text(Copy.INSTALL_KEEP_OPEN, style = MaterialTheme.typography.bodySmall, color = c.onSurfaceVariant)
+ }
+ FireInstall.Step.NotProjectivy -> {
+ Hero(LauncherIcons.ErrorOutline, c.errorContainer, c.onErrorContainer)
+ Headed(
+ if (f.picked) Copy.NOT_PROJECTIVY_FILE else Copy.NOT_PROJECTIVY,
+ AnnotatedString(if (f.picked) Copy.NOT_PROJECTIVY_FILE_TEXT else Copy.NOT_PROJECTIVY_TEXT),
)
- },
- text = {
- Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
- when (step) {
- FireInstall.Step.Confirm -> if (release != null) {
- Text(Copy.downloadsFrom(label), style = MaterialTheme.typography.bodyMedium)
- SourceRow(release) { uri.openUri(release.page) }
- if (f.store) {
- Text(Copy.DIRECT_CHECK, style = MaterialTheme.typography.bodyMedium)
- Text(Copy.STORE_SAFER, style = MaterialTheme.typography.bodyMedium)
- } else {
- Text(Copy.SIGNED_CHECK, style = MaterialTheme.typography.bodyMedium)
+ FireSteps(f, device)
+ if (f.store) Text(Copy.STORE_INSTEAD, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant)
+ }
+ FireInstall.Step.NoDownload -> {
+ Hero(LauncherIcons.ErrorOutline, c.errorContainer, c.onErrorContainer)
+ val text = if (f.until != null) Copy.noDownloadLimited(clockTime(f.until)) else Copy.NO_DOWNLOAD_OFFLINE
+ Headed(Copy.NO_DOWNLOAD, AnnotatedString(text))
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ Text(Copy.OR_YOURSELF, style = MaterialTheme.typography.labelLarge, color = c.primary)
+ Surface(shape = MaterialTheme.shapes.large, color = c.surfaceContainer, modifier = Modifier.fillMaxWidth()) {
+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
+ Numbered(1) {
+ Text(Copy.YOURSELF_PAGE, style = MaterialTheme.typography.bodyMedium)
+ SourceRow(release, openPage)
}
- }
- FireInstall.Step.Downloading, FireInstall.Step.Installing -> {
- val c = MaterialTheme.colorScheme
- Column {
- Text(PROJECTIVY, style = SmallNumber, color = c.onSurfaceVariant)
- release?.let { Text("Version ${it.version} · ${Copy.bytes(it.size)}", style = SmallNumber, color = c.onSurfaceVariant) }
- Text("from " + PROJECTIVY_SOURCE, style = SmallNumber, color = c.onSurfaceVariant)
+ Numbered(2) {
+ Text(Copy.yourselfPick(release?.apk?.substringAfterLast('/')), style = MaterialTheme.typography.bodyMedium)
+ FilledTonalButton(onClick = onPick, modifier = Modifier.fillMaxWidth()) { Text(Copy.PICK_DOWNLOADED) }
}
- val p = f.progress?.fraction
- // Past the last byte the TV is still unpacking: no bar stuck at 100%.
- if (p != null && p < 1f) LinearWavyProgressIndicator(progress = { p }, Modifier.fillMaxWidth())
- else LinearWavyProgressIndicator(Modifier.fillMaxWidth())
- Text(
- if (step == FireInstall.Step.Downloading) Copy.downloading(((p ?: 0f) * 100).toInt()) else Copy.installingOn(name(device)),
- style = MaterialTheme.typography.bodyMedium,
- )
- Text(Copy.INSTALL_KEEP_OPEN, style = MaterialTheme.typography.bodySmall, color = c.onSurfaceVariant)
}
- FireInstall.Step.NotProjectivy -> {
- Text(Copy.NOT_PROJECTIVY_TEXT, style = MaterialTheme.typography.bodyMedium)
- if (f.store) Text(Copy.STORE_INSTEAD, style = MaterialTheme.typography.bodyMedium)
- }
- FireInstall.Step.NoDownload -> Text(Copy.NO_DOWNLOAD_TEXT, style = MaterialTheme.typography.bodyMedium)
- FireInstall.Step.Refused -> Text(f.error.orEmpty(), style = MaterialTheme.typography.bodyMedium)
- FireInstall.Step.Checking -> Unit
}
}
- },
- confirmButton = {
- when (step) {
- // The safe way first and filled; the download only as the outlined second.
- FireInstall.Step.Confirm -> if (f.store) {
- Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
- IconButtonText(OpenInNew, Copy.GET_FROM_STORE, Modifier.fillMaxWidth(), onClick = store)
- OutlinedButton(onClick = actions.fireInstall, modifier = Modifier.fillMaxWidth()) { Text(Copy.DOWNLOAD_ANYWAY) }
- TextButton(onClick = actions.fireDismiss, modifier = Modifier.fillMaxWidth()) { Text("Cancel") }
+ }
+ FireInstall.Step.Refused -> {
+ Hero(LauncherIcons.ErrorOutline, c.errorContainer, c.onErrorContainer)
+ Headed(Copy.cantInstall(label), AnnotatedString(f.error.orEmpty()))
+ }
+ }
+}
+
+/** The bottom of each Fire OS step: full width, so the confirm reads the same as Download directly's. */
+@Composable
+private fun FireButtons(f: FireInstall, actions: LauncherActions, modifier: Modifier) {
+ val store = { actions.install(PROJECTIVY) }
+ Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ val wide = Modifier.fillMaxWidth()
+ when (f.step) {
+ null, FireInstall.Step.Checking -> IconButtonText(LauncherIcons.Download, Copy.INSTALL_PROJECTIVY, wide, enabled = f.step == null, onClick = actions.fireCheck)
+ // The safe way first and filled; the download only as the outlined second.
+ FireInstall.Step.Confirm -> if (f.store) {
+ IconButtonText(OpenInNew, Copy.GET_FROM_STORE, wide, onClick = store)
+ OutlinedButton(onClick = actions.fireInstall, modifier = wide) { Text(Copy.DOWNLOAD_ANYWAY) }
+ } else {
+ IconButtonText(LauncherIcons.Download, Copy.DOWNLOAD_AND_INSTALL, wide, onClick = actions.fireInstall)
+ }
+ FireInstall.Step.Downloading, FireInstall.Step.Reading, FireInstall.Step.Installing -> Unit
+ FireInstall.Step.NotProjectivy -> when {
+ f.picked -> Row(wide, horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)) {
+ TextButton(onClick = actions.firePick) { Text(Copy.PICK_ANOTHER) }
+ Button(onClick = actions.fireCheck) { Text(Copy.TRY_DOWNLOAD_AGAIN) }
+ }
+ f.store -> IconButtonText(OpenInNew, Copy.GET_FROM_STORE, wide, onClick = store)
+ else -> Button(onClick = actions.fireCheck, modifier = wide) { Text(Copy.TRY_AGAIN) }
+ }
+ FireInstall.Step.NoDownload -> Row(wide, horizontalArrangement = Arrangement.End) {
+ Button(onClick = actions.fireCheck) { Text(Copy.TRY_AGAIN) }
+ }
+ FireInstall.Step.Refused -> Row(wide, horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End)) {
+ if (f.picked) TextButton(onClick = actions.firePick) { Text(Copy.PICK_ANOTHER) }
+ Button(onClick = actions.fireDismiss) { Text("OK") }
+ }
+ }
+ }
+}
+
+/** One numbered step of Or download it yourself. */
+@Composable
+private fun Numbered(n: Int, content: @Composable () -> Unit) {
+ val c = MaterialTheme.colorScheme
+ Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
+ Box(Modifier.size(24.dp).background(c.secondaryContainer, CircleShape), contentAlignment = Alignment.Center) {
+ Text("$n", style = MaterialTheme.typography.labelMedium, color = c.onSecondaryContainer)
+ }
+ Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) { content() }
+ }
+}
+
+private enum class Mark { Todo, Active, Done, Failed }
+
+/** Download (or the picked file), the check, the install: each to do, under way, done, or failed. */
+@OptIn(ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+private fun FireSteps(f: FireInstall, device: Device) {
+ val c = MaterialTheme.colorScheme
+ val release = f.release
+ val failed = f.step == FireInstall.Step.NotProjectivy
+ val checked = f.step == FireInstall.Step.Installing
+ Surface(shape = MaterialTheme.shapes.large, color = c.surfaceContainer, modifier = Modifier.fillMaxWidth()) {
+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
+ when {
+ f.picked -> StepLine(1, Mark.Done, Copy.STEP_PICKED, f.size?.let(Copy::bytes))
+ f.step == FireInstall.Step.Downloading -> {
+ val p = f.progress
+ val total = p?.total?.takeIf { it > 0 } ?: release?.size ?: 0L
+ val fraction = p?.fraction
+ StepLine(1, Mark.Active, Copy.STEP_DOWNLOAD, Copy.downloading(((fraction ?: 0f) * 100).toInt(), p?.done ?: 0L, total)) {
+ if (fraction != null) LinearWavyProgressIndicator(progress = { fraction }, Modifier.fillMaxWidth())
+ else LinearWavyProgressIndicator(Modifier.fillMaxWidth())
}
- } else {
- Button(onClick = actions.fireInstall) { Text(Copy.DOWNLOAD_AND_INSTALL) }
}
- FireInstall.Step.NotProjectivy -> if (f.store) {
- IconButtonText(OpenInNew, Copy.GET_FROM_STORE, onClick = store)
+ else -> StepLine(1, Mark.Done, Copy.STEP_DOWNLOADED, release?.let { Copy.release(it.version, it.size) })
+ }
+ when {
+ failed -> StepLine(2, Mark.Failed, Copy.STEP_FAILED, Copy.STEP_FAILED_TEXT)
+ checked -> StepLine(2, Mark.Done, Copy.STEP_CHECKED, Copy.STEP_CHECKED_TEXT)
+ f.step == FireInstall.Step.Reading -> StepLine(2, Mark.Active, Copy.STEP_CHECKING)
+ else -> StepLine(2, Mark.Todo, Copy.STEP_CHECK)
+ }
+ if (!failed) {
+ if (checked) {
+ StepLine(3, Mark.Active, Copy.installingOn(name(device))) {
+ // Past the last byte the TV is still unpacking: no bar stuck at 100%.
+ val p = f.progress?.fraction
+ if (p != null && p < 1f) LinearWavyProgressIndicator(progress = { p }, Modifier.fillMaxWidth())
+ else LinearWavyProgressIndicator(Modifier.fillMaxWidth())
+ }
} else {
- Button(onClick = actions.fireCheck) { Text(Copy.TRY_AGAIN) }
+ StepLine(3, Mark.Todo, Copy.installOn(name(device)))
}
- FireInstall.Step.NoDownload -> Button(onClick = actions.fireCheck) { Text(Copy.TRY_AGAIN) }
- FireInstall.Step.Refused -> Button(onClick = actions.fireDismiss) { Text("OK") }
- else -> Unit
}
- },
- dismissButton = {
- when (step) {
- FireInstall.Step.Confirm -> if (!f.store) TextButton(onClick = actions.fireDismiss) { Text("Cancel") }
- FireInstall.Step.NotProjectivy -> TextButton(onClick = actions.fireDismiss) { Text("Close") }
- FireInstall.Step.NoDownload -> TextButton(onClick = { actions.fireDismiss(); uri.openUri(release?.page ?: PROJECTIVY_RELEASES) }) {
- Text(Copy.OPEN_DOWNLOAD_PAGE)
+ }
+ }
+}
+
+@OptIn(ExperimentalMaterial3ExpressiveApi::class)
+@Composable
+private fun StepLine(n: Int, mark: Mark, title: String, text: String? = null, below: @Composable () -> Unit = {}) {
+ val c = MaterialTheme.colorScheme
+ Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
+ Box(Modifier.size(24.dp), contentAlignment = Alignment.Center) {
+ when (mark) {
+ Mark.Todo -> Box(Modifier.size(22.dp).border(1.5.dp, c.outline, CircleShape), contentAlignment = Alignment.Center) {
+ Text("$n", style = MaterialTheme.typography.labelMedium, color = c.onSurfaceVariant)
+ }
+ Mark.Active -> LoadingIndicator(Modifier.size(24.dp))
+ Mark.Done -> Box(Modifier.size(24.dp).background(c.primary, CircleShape), contentAlignment = Alignment.Center) {
+ Icon(Icons.Default.Check, null, Modifier.size(16.dp), tint = c.onPrimary)
+ }
+ Mark.Failed -> Box(Modifier.size(24.dp).background(c.errorContainer, CircleShape), contentAlignment = Alignment.Center) {
+ Icon(Icons.Default.Close, null, Modifier.size(16.dp), tint = c.onErrorContainer)
}
- else -> Unit
}
- },
+ }
+ Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
+ Text(title, style = MaterialTheme.typography.bodyLarge, color = if (mark == Mark.Todo) c.onSurfaceVariant else c.onSurface)
+ text?.let { Text(it, style = MaterialTheme.typography.bodyMedium, color = c.onSurfaceVariant) }
+ below()
+ }
+ }
+}
+
+/** X while it downloads; Keep downloading is the filled one, as stopping throws the download away. */
+@Composable
+private fun StopDialog(onKeep: () -> Unit, onStop: () -> Unit) {
+ AlertDialog(
+ onDismissRequest = onKeep,
+ title = { Text(Copy.STOP_TITLE) },
+ text = { Text(Copy.STOP_TEXT) },
+ confirmButton = { Button(onClick = onKeep) { Text(Copy.KEEP_DOWNLOADING) } },
+ dismissButton = { TextButton(onClick = onStop) { Text(Copy.STOP) } },
)
}
-/** Projectivy's repo, as the source row and the progress dialog name it. */
+/** [millis] as the phone's clock shows it, like 18:44. */
+private fun clockTime(millis: Long): String =
+ java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT).format(java.util.Date(millis))
+
+/** Projectivy's repo, as the source row names it. */
private val PROJECTIVY_SOURCE = PROJECTIVY_RELEASES.removePrefix("https://").removeSuffix("/releases")
-/** Where the download comes from, as one tappable row: the repo, then the release and its size; it opens the release page. */
+/**
+ * Where the download comes from, as one tappable row: the repo, then the release and its size; it opens the
+ * release page. With no [release] read, it says the latest one and opens that.
+ */
@Composable
-private fun SourceRow(release: LauncherRelease, onOpen: () -> Unit) {
+private fun SourceRow(release: LauncherRelease?, onOpen: () -> Unit) {
val c = MaterialTheme.colorScheme
Surface(
onClick = onOpen,
@@ -492,7 +624,7 @@ private fun SourceRow(release: LauncherRelease, onOpen: () -> Unit) {
Spacer(Modifier.width(12.dp))
Column(Modifier.weight(1f)) {
Text(PROJECTIVY_SOURCE, style = MaterialTheme.typography.bodyMedium, color = c.primary, maxLines = 1, overflow = TextOverflow.Ellipsis)
- Text(Copy.release(release.version, release.size), style = MaterialTheme.typography.bodySmall, color = c.onSurfaceVariant)
+ Text(release?.let { Copy.release(it.version, it.size) } ?: Copy.LATEST_RELEASE, style = MaterialTheme.typography.bodySmall, color = c.onSurfaceVariant)
}
Spacer(Modifier.width(8.dp))
Icon(OpenInNew, null, Modifier.size(18.dp), tint = c.primary)
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index 84ff410..580f2c2 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -40,6 +40,7 @@ import app.tellyscope.data.NotProjectivy
import app.tellyscope.data.PROJECTIVY
import app.tellyscope.data.PhoneStorage
import app.tellyscope.data.PickedApp
+import app.tellyscope.data.RateLimited
import app.tellyscope.data.RemoteButtons
import app.tellyscope.data.ResetApp
import app.tellyscope.data.ResetFailure
@@ -184,9 +185,11 @@ data class LauncherFlow(val step: Step = Step.Pick, val pkg: String = RECOMMENDE
* Install Projectivy on Fire OS ([fireInstall]), on [LauncherFlow.Step.Pick] in place of the picker: there's no
* Play Store, so Tellyscope reads the latest release ([Step.Checking]), asks ([Step.Confirm]), downloads and
* checks it ([Step.Downloading]), installs it over adb ([Step.Installing]), then moves to [LauncherFlow.Step.Installed].
- * A null [step] is the screen with no dialog. [error] is the TV's refusal, for [Step.Refused].
- * [store]: Download directly on a TV with the Play Store, from the picker ([downloadable]); its dialogs offer the
+ * A null [step] is the picker with nothing started. [error] is the TV's refusal, for [Step.Refused].
+ * [store]: Download directly on a TV with the Play Store, from the picker ([downloadable]); its steps offer the
* Store instead, and closing one goes back to the picker.
+ * After [Step.NoDownload] the user can download it themselves and pick the file ([picked]): [Step.Reading] checks
+ * it, then it installs the same way. [until]: GitHub refused the lookup until then, epoch millis, not the network.
*/
data class FireInstall(
val step: Step? = null,
@@ -194,8 +197,12 @@ data class FireInstall(
val progress: Progress? = null,
val error: String? = null,
val store: Boolean = false,
+ val picked: Boolean = false,
+ val until: Long? = null,
+ /** The APK's size once it's downloaded or picked, for the steps' first line. */
+ val size: Long? = null,
) {
- enum class Step { Checking, Confirm, Downloading, Installing, NotProjectivy, NoDownload, Refused }
+ enum class Step { Checking, Confirm, Downloading, Reading, Installing, NotProjectivy, NoDownload, Refused }
}
/**
@@ -897,6 +904,8 @@ class TellyscopeViewModel(
download.latest()
} catch (e: CancellationException) {
throw e
+ } catch (e: RateLimited) {
+ return@launch setFire(id) { FireInstall(FireInstall.Step.NoDownload, store = store, until = e.until) }
} catch (_: Exception) {
return@launch setFire(id) { FireInstall(FireInstall.Step.NoDownload, store = store) }
}
@@ -913,7 +922,7 @@ class TellyscopeViewModel(
val download = launcherDownload ?: return
val release = _state.value.device.launcher?.fire?.takeIf { it.step == FireInstall.Step.Confirm }?.release ?: return
launcherJob?.cancel()
- setFire(id) { it.copy(step = FireInstall.Step.Downloading, progress = null) }
+ setFire(id) { it.copy(step = FireInstall.Step.Downloading, progress = null, picked = false, size = null, until = null) }
launcherJob = viewModelScope.launch {
val app = try {
download.fetch(release) { p -> setFire(id) { it.copy(progress = p) } }
@@ -924,27 +933,56 @@ class TellyscopeViewModel(
} catch (_: Exception) {
return@launch setFire(id) { it.copy(step = FireInstall.Step.NoDownload) }
}
- setFire(id) { it.copy(step = FireInstall.Step.Installing, progress = null) }
- val result = try {
- source.install(id, app.files, app.info, allowDowngrade = false) { p -> setFire(id) { it.copy(progress = p) } }
+ installFetched(id, app)
+ }
+ }
+
+ /**
+ * Pick the downloaded file, after Couldn't download: the file the user picked, checked like the download,
+ * then installed the same way. Nothing reaches the TV unless it's Projectivy signed by its developer.
+ */
+ fun pickedProjectivy(uri: Uri) {
+ val id = _state.value.selectedId ?: return
+ val download = launcherDownload ?: return
+ if (_state.value.device.launcher?.fire == null) return
+ launcherJob?.cancel()
+ setFire(id) { it.copy(step = FireInstall.Step.Reading, picked = true, progress = null, size = null) }
+ launcherJob = viewModelScope.launch {
+ val app = try {
+ download.open(uri)
} catch (e: CancellationException) {
throw e
+ } catch (_: NotProjectivy) {
+ return@launch setFire(id) { it.copy(step = FireInstall.Step.NotProjectivy) }
} catch (_: Exception) {
- return@launch setFire(id) { it.copy(step = FireInstall.Step.Refused, error = Copy.SIDELOAD_LOST) }
+ return@launch setFire(id) { it.copy(step = FireInstall.Step.Refused, error = Copy.CANT_READ_FILE) }
}
- when (result) {
- // The install dialog closes with it: Installing would keep it up, and Close and Cancel wait on that.
- InstallResult.Done -> launcherInstalled(id, PROJECTIVY) { step ->
- updateDevice(id) { it.copy(launcher = it.launcher?.let { l -> l.copy(step = step, fire = if (l.fire?.store == true) null else FireInstall()) }) }
- }
- is InstallResult.Refused -> setFire(id) {
- it.copy(step = FireInstall.Step.Refused, error = Copy.installRefused(result.reason, launcherName(PROJECTIVY)))
- }
+ installFetched(id, app)
+ }
+ }
+
+ /** Projectivy, downloaded or picked and checked, onto the TV over adb like any sideload. */
+ private suspend fun installFetched(id: String, app: PickedApp) {
+ setFire(id) { it.copy(step = FireInstall.Step.Installing, progress = null, size = app.sizeBytes) }
+ val result = try {
+ source.install(id, app.files, app.info, allowDowngrade = false) { p -> setFire(id) { it.copy(progress = p) } }
+ } catch (e: CancellationException) {
+ throw e
+ } catch (_: Exception) {
+ return setFire(id) { it.copy(step = FireInstall.Step.Refused, error = Copy.SIDELOAD_LOST) }
+ }
+ when (result) {
+ // The steps close with it: Installing would keep them up, and Close waits on that.
+ InstallResult.Done -> launcherInstalled(id, PROJECTIVY) { step ->
+ updateDevice(id) { it.copy(launcher = it.launcher?.let { l -> l.copy(step = step, fire = if (l.fire?.store == true) null else FireInstall()) }) }
+ }
+ is InstallResult.Refused -> setFire(id) {
+ it.copy(step = FireInstall.Step.Refused, error = Copy.installRefused(result.reason, launcherName(PROJECTIVY)))
}
}
}
- /** Cancel, Close or OK on a Fire OS dialog: back to the screen, or to the picker after Download directly. Not while the install runs. */
+ /** X or Stop on a Fire OS step: back to the start, or to the picker after Download directly. Not while the install runs. */
fun dismissProjectivy() {
val id = _state.value.selectedId ?: return
if (_state.value.device.launcher?.fire?.step == FireInstall.Step.Installing) return
@@ -1544,6 +1582,22 @@ class TellyscopeViewModel(
}
}
+ /** "It's mine" on a new allowed computer: it stops showing as new on this TV. */
+ fun markKeyMine(fingerprint: String) {
+ val id = _state.value.selectedId ?: return
+ viewModelScope.launch {
+ source.markKeyMine(id, fingerprint)
+ readAccess(id)
+ }
+ }
+
+ /** Answer on a waiting connection: the TV's prompt again, even after it was dismissed. */
+ fun showRequest() {
+ val id = _state.value.selectedId ?: return
+ dismissedRequest = null
+ viewModelScope.launch { readRequest(id) }
+ }
+
private fun setRemoval(id: String, removal: Removal?) = updateDevice(id) { it.copy(removal = removal) }
/** "Remove all other access…": asks first. */
diff --git a/app/src/test/java/app/tellyscope/FireOsTest.kt b/app/src/test/java/app/tellyscope/FireOsTest.kt
index 57307ee..2d3471c 100644
--- a/app/src/test/java/app/tellyscope/FireOsTest.kt
+++ b/app/src/test/java/app/tellyscope/FireOsTest.kt
@@ -2,6 +2,7 @@
package app.tellyscope
+import android.net.Uri
import androidx.lifecycle.viewModelScope
import app.tellyscope.adb.ApkInfo
import app.tellyscope.adb.InstallResult
@@ -25,6 +26,8 @@ import app.tellyscope.data.Snapshot
import app.tellyscope.data.Suggestions
import app.tellyscope.data.isFireOs
import app.tellyscope.data.isProjectivy
+import app.tellyscope.data.latestTag
+import app.tellyscope.data.pageApk
import app.tellyscope.data.parseRelease
import app.tellyscope.ui.FireInstall
import app.tellyscope.ui.LauncherFlow
@@ -112,6 +115,10 @@ private class FakeDownload(var signedByDeveloper: Boolean = true) : LauncherDown
if (!signedByDeveloper) throw NotProjectivy()
return PickedApp(listOf(File("projectivy.apk")), ApkInfo(PROJECTIVY, 97, release.version), "Projectivy Launcher")
}
+ override suspend fun open(uri: Uri): PickedApp {
+ if (!signedByDeveloper) throw NotProjectivy()
+ return PickedApp(listOf(File("projectivy.apk")), ApkInfo(PROJECTIVY, 97, "4.72"), "Projectivy Launcher")
+ }
}
/** Install a home screen on Fire OS: who gets it, the release and signature checks, and the install. */
@@ -256,4 +263,33 @@ class FireOsTest {
assertNull(v.state.value.device.launcher?.fire)
assertEquals(0, download.fetched)
}
+
+ @Test fun whenTheApiIsLimitedTheReleasePageGivesTheTagAndItsOneApk() {
+ assertEquals(TAG, latestTag(PAGE))
+ assertNull(latestTag("https://github.com/someone/miproja1/releases/tag/$TAG"))
+ assertNull(latestTag(null))
+ val link = APK.removePrefix("https://github.com")
+ assertEquals(APK, pageApk("""<a href="$link" rel="nofollow">x</a><a href="$link">x</a>""", TAG))
+ assertNull(pageApk("""<a href="$link">a</a><a href="${link.replace(".apk", "-b.apk")}">b</a>""", TAG))
+ assertNull(pageApk("""<a href="${link.replace("/$TAG/", "/4.70/")}">old</a>""", TAG))
+ }
+
+ @Test fun aPickedFileIsCheckedThenInstalled() = with(test) {
+ val v = opened()
+ v.pickedProjectivy(Uri.parse("content://downloads/1"))
+ runCurrent()
+ assertEquals(listOf(PROJECTIVY), source.installs.map { it.packageName })
+ assertEquals(LauncherFlow.Step.Installed, v.state.value.device.launcher?.step)
+ }
+
+ @Test fun aPickedFileThatIsntProjectivyInstallsNothing() = with(test) {
+ download.signedByDeveloper = false
+ val v = opened()
+ v.pickedProjectivy(Uri.parse("content://downloads/1"))
+ runCurrent()
+ assertTrue(source.installs.isEmpty())
+ val fire = v.state.value.device.launcher?.fire
+ assertEquals(FireInstall.Step.NotProjectivy, fire?.step)
+ assertEquals(true, fire?.picked)
+ }
}
diff --git a/app/src/test/java/app/tellyscope/TvAccessTest.kt b/app/src/test/java/app/tellyscope/TvAccessTest.kt
index 3d12282..5884d13 100644
--- a/app/src/test/java/app/tellyscope/TvAccessTest.kt
+++ b/app/src/test/java/app/tellyscope/TvAccessTest.kt
@@ -92,4 +92,27 @@ class TvAccessTest {
assertEquals(setOf(other), book["serial-1"])
assertTrue(book["192.0.2.20"].isEmpty())
}
+
+ @Test fun aConnectionWhoseAllowPromptIsUpIsWaitingNotAWarning() {
+ val a = TvAccess.of(listOf(AdbClient(phone, 1), AdbClient(other, 2)), listOf(phoneKey), setOf(phone), "192.0.2.20", emptySet(), "AA", pending = "CC")
+ assertEquals(Who.Waiting, a.connected!!.first { it.address == other }.who)
+ assertFalse(a.warning)
+ }
+
+ @Test fun anAllowedKeyOrASecondComputerIsNeverHiddenAsWaiting() {
+ val allowed = TvAccess.of(listOf(AdbClient(other, 2)), listOf(phoneKey, laptop), setOf(phone), "192.0.2.20", emptySet(), "AA", pending = "BB")
+ assertTrue(allowed.warning)
+ val two = TvAccess.of(listOf(AdbClient(other, 2), AdbClient("192.0.2.99", 3)), listOf(phoneKey), setOf(phone), "192.0.2.20", emptySet(), "AA", pending = "CC")
+ assertEquals(2, two.others.size)
+ }
+
+ @Test fun aKeyAllowedWhileTellyscopeWasntWatchingIsNew() {
+ fun keys(known: Set<String>?, watched: Set<String> = emptySet()) =
+ TvAccess.of(emptyList(), listOf(phoneKey, laptop), setOf(phone), "192.0.2.20", emptySet(), "AA", known = known, watched = watched).allowed!!
+ assertTrue(keys(known = setOf("AA")).single { it.fingerprint == "BB" }.new)
+ // First look at this TV: what's there is known. Allowed from Tellyscope's own prompt: known too.
+ assertTrue(keys(known = null).none { it.new })
+ assertTrue(keys(known = setOf("AA"), watched = setOf("BB")).none { it.new })
+ assertTrue(keys(known = emptySet()).none { it.phone && it.new })
+ }
}