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.
Send and install wait out a link dropped behind the file picker
jesse-agent-821f1817590c542
diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex f3651fa..03a77a9 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -50,10 +50,12 @@ import kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.Jobimport kotlinx.coroutines.SupervisorJob+import kotlinx.coroutines.TimeoutCancellationExceptionimport kotlinx.coroutines.asyncimport kotlinx.coroutines.awaitAllimport kotlinx.coroutines.channels.awaitCloseimport kotlinx.coroutines.coroutineScope+import kotlinx.coroutines.delayimport kotlinx.coroutines.flow.Flowimport kotlinx.coroutines.flow.callbackFlowimport kotlinx.coroutines.flow.combine@@ -61,12 +63,15 @@ import kotlinx.coroutines.flow.flowimport kotlinx.coroutines.flow.mapimport kotlinx.coroutines.flow.transformWhileimport kotlinx.coroutines.launch+import kotlinx.coroutines.withTimeout+import kotlinx.coroutines.withTimeoutOrNullimport okio.Sinkimport okio.Sourceimport java.io.Fileimport java.net.Inet4Addressimport java.net.NetworkInterfaceimport java.util.concurrent.ConcurrentHashMap+import kotlin.time.Duration.Companion.secondsimport app.tellyscope.adb.Action as AdbActionimport app.tellyscope.adb.ConnectResult as AdbConnectResultimport app.tellyscope.adb.DeviceState as AdbState@@ -1112,12 +1117,17 @@ class AdbDeviceSource(context: Context) : DeviceSource {apk: ApkInfo,allowDowngrade: Boolean,onProgress: (Progress) -> Unit,- ): InstallResult = busy(deviceId, reread = true) { Sideload(session(deviceId)).install(apks, apk, allowDowngrade, onProgress) }+ ): InstallResult {+ val session = liveSession(deviceId)+ return busy(deviceId, reread = true) { Sideload(session).install(apks, apk, allowDowngrade, onProgress) }+ }override suspend fun files(deviceId: String, folder: TvFolder) = Files(session(deviceId)).list(folder)- override suspend fun push(deviceId: String, folder: TvFolder, name: String, size: Long?, source: Source, onProgress: (Progress) -> Unit) =- busy(deviceId, reread = true) { Files(session(deviceId)).push(source, size, name, folder, onProgress) }+ override suspend fun push(deviceId: String, folder: TvFolder, name: String, size: Long?, source: Source, onProgress: (Progress) -> Unit): String {+ val session = liveSession(deviceId)+ return busy(deviceId, reread = true) { Files(session).push(source, size, name, folder, onProgress) }+ }override suspend fun pull(deviceId: String, folder: TvFolder, file: TvFile, sink: Sink, onProgress: (Progress) -> Unit) =busy(deviceId) { Files(session(deviceId)).pull(folder, file, sink, onProgress) }@@ -1125,6 +1135,40 @@ class AdbDeviceSource(context: Context) : DeviceSource {private fun session(deviceId: String) =links[deviceId]?.session ?: throw UiTextException(UiText(R.string.data_offline, deviceId))+ /**+ * The session for a file the user just picked. While the system picker is up the app is in the+ * background, where Android cuts its network after a few seconds and no stats read notices: back+ * in the app, the old session is dead (#290, #296). A quick shell call tells; a dead link starts+ * over and the transfer waits for the new session.+ */+ private suspend fun liveSession(deviceId: String): AdbSession {+ val link = links[deviceId] ?: return session(deviceId)+ val old = link.session+ if (old != null && alive(old)) return old+ // Another caller may have started over already; its new session is the one to wait for.+ if (old != null && link.session === old) link.connect()+ // Polled: a reconnect from ONLINE stays ONLINE, so the state never says when the new session is in.+ return withTimeoutOrNull(RECONNECT_WAIT) {+ var next = link.session+ while (next == null || next === old) {+ delay(250)+ next = link.session+ }+ next+ } ?: session(deviceId)+ }++ private suspend fun alive(s: AdbSession) = try {+ withTimeout(PROBE_WAIT) { s.shell("echo") }+ true+ } catch (_: TimeoutCancellationException) {+ false+ } catch (e: CancellationException) {+ throw e+ } catch (_: Exception) {+ false+ }+private fun device(id: String): Device {val link = links[id]val stats = link?.stats?.value@@ -1321,6 +1365,12 @@ internal suspend fun undoHomeSwitch(actions: Actions, switch: HistoryEntry): Booreturn back != false}+/** How long a picked file's session gets to answer before it counts as dropped. */+private val PROBE_WAIT = 3.seconds++/** How long a picked file waits for a dropped link to come back: one retry interval plus a connect. */+private val RECONNECT_WAIT = 20.seconds+/** The package name a reset's History entries carry: it changes the TV, not one app. */internal const val RESET = "reset"