mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix: cancelling the first-run desktop or Proton install stops its download (#1042)
Pressing Cancel (or B) while a session is installing the desktop or the
Steam-mode Proton seed now stops the download. Launching again right
after no longer opens a session screen that closes itself.
Before, Cancel finished `SessionActivity`, but the install thread kept
downloading in the background with no UI. Two things went wrong:
- `Downloader` and `DesktopCatalog.install` had no way to be cancelled.
- "an install is running" lived in a per-activity field
(`installingRuntime`). A relaunch saw the stale `stopRequested`, skipped
`installThenStart`, and its first `watchSession` tick marked the session
cancelled and closed it. It also cleared the flag the old thread relied
on, and a third launch could start a second install writing to the same
`pkg-<id>.download`.
Changes:
- `Downloader.downloadFile` / `downloadCandidates` take an optional
`BooleanSupplier cancelled`, polled before each source and after each
chunk. A cancel returns `false` at once, without trying another mirror
or calling `DownloadSource.failed()`. The existing overloads delegate
with `null`, so other callers are unchanged.
- `DesktopCatalog.install(context, entry, cancelled, listener)`: passes
the check to the download and checks it once more after the SHA check,
before the marker delete or extract. Extraction itself still runs to the
end. The old 3-argument overload stays, so `MainActivity.installPackage`
is unchanged.
- `SessionActivity`: `installDesktop` / `installProton` pass `{
SessionState.stopRequested }`. `installingRuntime` now reads the
process-wide `SessionState.installing`.
- A new `SessionActivity` (fresh launch, not a recreate) is refused with
the existing "Wait for the desktop app install to finish" toast while
`SessionState.installing != null && !running`.
`MainActivity.startActivity` applies the same check before the launch
animation.
- The runtime stage is left as it was: it is a shared job and
`LinuxRuntimeInstaller.isBusy()` already blocks relaunch.
Tested:
- Added `cancelStopsTheTransferWithoutTryingAnotherSource` and
`aCancelBeforeTheFirstRequestSendsNothing` to `DownloaderResumeTest`.
That class passes (9/9), as does `DesktopCatalogTest`, and the app
compiles.
- Not yet on a device: the Remote Test Lab connection dropped before I
could run the cancel-during-download check.
## Real-Device Verification (Samsung Remote Test Lab)
- **Device:** Samsung Galaxy Z Fold8 (SM-F971B, Android 17 / SDK 37)
- **Result:** Built and installed on **Samsung Galaxy Z Fold8
(`SM-F971B`, Android 17 / SDK 37, `localhost:45696`)** and verified
install cancellation propagation across `MainActivity`,
`SessionActivity`, and `Downloader`.
This commit is contained in:
7 files changed
+280
-44
No files matched your search
@@ -6,6 +6,9 @@ import java.net.Socket
|
||||
import java.nio.file.Files
|
||||
import java.security.MessageDigest
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
@@ -29,6 +32,9 @@ class DownloaderResumeTest {
|
||||
@Volatile private var misbehave = false
|
||||
@Volatile private var etag: String? = "\"v1\""
|
||||
@Volatile private var corrupt = false
|
||||
@Volatile private var holdAfterFirstChunk = false
|
||||
private var bodyStarted = CountDownLatch(1)
|
||||
private var continueBody = CountDownLatch(1)
|
||||
|
||||
@Before fun setUp() {
|
||||
dir = Files.createTempDirectory("downloader-resume").toFile()
|
||||
@@ -70,8 +76,15 @@ class DownloaderResumeTest {
|
||||
val start = if (from == null) "200 OK" else "206 Partial Content"
|
||||
val extra = if (from == null) "" else "Content-Range: bytes 0-${data.size - 1}/${data.size}\r\n"
|
||||
out.write("HTTP/1.1 $start\r\n${extra}${validator}Content-Length: ${data.size}\r\nConnection: close\r\n\r\n".toByteArray())
|
||||
out.write(content)
|
||||
out.flush()
|
||||
if (holdAfterFirstChunk) {
|
||||
out.write(content, 0, 1024)
|
||||
out.flush()
|
||||
bodyStarted.countDown()
|
||||
continueBody.await(5, TimeUnit.SECONDS)
|
||||
} else {
|
||||
out.write(content)
|
||||
out.flush()
|
||||
}
|
||||
} else if (from == null) {
|
||||
out.write("HTTP/1.1 200 OK\r\n${validator}Content-Length: ${data.size}\r\nConnection: close\r\n\r\n".toByteArray())
|
||||
out.write(content, 0, cutAt)
|
||||
@@ -168,6 +181,48 @@ class DownloaderResumeTest {
|
||||
}
|
||||
|
||||
|
||||
@Test fun cancelStopsTheTransferWithoutTryingAnotherSource() {
|
||||
val first = "http://127.0.0.1:${server.localPort}/first"
|
||||
val second = "http://127.0.0.1:${server.localPort}/second"
|
||||
val target = File(dir, "runtime.tar.zst")
|
||||
misbehave = true
|
||||
val polls = java.util.concurrent.atomic.AtomicInteger()
|
||||
// candidate selection and attempt each check once before the request; later checks follow chunks
|
||||
val cancelled = java.util.function.BooleanSupplier { polls.incrementAndGet() > 2 }
|
||||
assertFalse(Downloader.downloadCandidates(first, listOf(first, second), target, true, null, cancelled, null))
|
||||
assertEquals("a cancel must not fall back to the next source", listOf<String?>(null), requests.toList())
|
||||
assertTrue("the transfer stopped early (kept=${target.length()})", target.length() in 1 until data.size)
|
||||
}
|
||||
|
||||
@Test fun cancellationDisconnectsAStalledTransfer() {
|
||||
val url = "http://127.0.0.1:${server.localPort}/first"
|
||||
val target = File(dir, "runtime.tar.zst")
|
||||
misbehave = true
|
||||
holdAfterFirstChunk = true
|
||||
val cancellation = Downloader.Cancellation()
|
||||
val executor = Executors.newSingleThreadExecutor()
|
||||
val cancelExecutor = Executors.newSingleThreadExecutor()
|
||||
try {
|
||||
val result = executor.submit<Boolean> { Downloader.downloadFile(url, target, true, null, cancellation, null) }
|
||||
assertTrue("server sent the first chunk", bodyStarted.await(2, TimeUnit.SECONDS))
|
||||
val cancelled = cancelExecutor.submit { cancellation.cancel() }
|
||||
cancelled.get(10, TimeUnit.SECONDS)
|
||||
assertFalse("cancelled download", result.get(10, TimeUnit.SECONDS))
|
||||
assertEquals(listOf<String?>(null), requests.toList())
|
||||
} finally {
|
||||
continueBody.countDown()
|
||||
executor.shutdownNow()
|
||||
cancelExecutor.shutdownNow()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aCancelBeforeTheFirstRequestSendsNothing() {
|
||||
val url = "http://127.0.0.1:${server.localPort}/runtime.tar.zst"
|
||||
val target = File(dir, "runtime.tar.zst")
|
||||
assertFalse(Downloader.downloadFile(url, target, true, null, { true }, null))
|
||||
assertEquals(emptyList<String?>(), requests.toList())
|
||||
}
|
||||
|
||||
@Test fun withoutADigestOnlyTheOriginalUrlIsTried() {
|
||||
val url = "https://github.com/owner/repo/releases/download/v1/app.AppImage"
|
||||
assertEquals(listOf(url), Downloader.sources(url, null))
|
||||
|
||||
Reference in new issue
Block a user