Repository navigation
Android: model download resumes instead of failing in the background - #2300
Merged
Merged
Conversation
…ckground Setup starts the 190 MB Whisper small download and then sends the person to Android's Settings. On Android 15+ (seen on API 36) the system closes a backgrounded app's sockets about 5 s later, so the plain HttpsURLConnection failed, setup said the download stopped and Try again started from 0. ModelStore now: - keeps the partial file (whisper-small-<sha256>.part) and continues with an HTTP Range request; it re-hashes the kept bytes so the final SHA-256 and byte-count check is unchanged. A 200 reply (range ignored), a 206 for the wrong range or a 416 for an incomplete file falls back to a clean restart. A resumed file that fails the checksum is deleted and fetched once more from 0; a fresh one that fails reports a failure. - treats a connection error while Hex was in the background (or left the foreground during the attempt) as a pause, not an error: the progress stays and the download continues as soon as a Hex activity starts again (ActivityLifecycleCallbacks registered from refresh()). The same hook picks up a partial file after the app is swiped away or the phone restarts. - reports real failures by cause. State.Retry is now a data class carrying a Problem (Connection, Server, Space); modelStatus() maps them to the new model_no_connection / model_no_space strings and the existing model_stopped, and modelAction() offers Try again, which now resumes. - the old restart-every-time path (part.delete() in finally) is removed. No new permissions (still only RECORD_AUDIO and INTERNET), no foreground service, no new dependencies. Verified on API 36 and API 31 emulators with the debug build, rebased on #2291's setup flow (Turn on, Hex switched on in Settings, the picker that opens on return, Hex picked): Settings for 10/30/90 s, swipe from recents, airplane mode in the foreground (shows "No connection", Try again resumes) and in the background (continues on return), reboot, and 16 corrupted bytes in the partial file (detected, re-fetched, final SHA-256 matches). Every run finished with the right hash; dictation from Home used the installed small model on both. Signed release build: Settings 30 s on API 36 finished, DEX has no android.util.Log references, permissions are RECORD_AUDIO and INTERNET only. Baseline on API 36: interrupted ~5 s after Settings, 234.5 MB fetched; now 190.1 MB and no error. ./gradlew test passes (64 tests); lintDebug's only error is the existing LogTagMismatch in MicCapture.kt (same on origin/dev), plus one UsableSpace warning from the extra check.
#2295 added values-zh-rCN while this branch was open. This adds model_no_connection and model_no_space there in the same style as model_stopped. Verified: assembleDebug, test and lintDebug pass on the rebased branch (lint now has no errors).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Setup's Get started starts the 190 MB Whisper small download and then sends the person to Android's Settings. On Android 15+ the system closes a backgrounded app's sockets about 5 s later, so setup said the download stopped and Try again started from 0.
Now: the partial file is kept and the download continues with an HTTP Range request. A connection that drops while Hex is in the background counts as a pause, not an error. The download picks up again as soon as a Hex screen is in front, including after a swipe from recents or a reboot. Real failures say what went wrong: "No connection", "Not enough storage" or "Download stopped" (server or checksum), each with Try again, which also resumes.
ModelStorekeepswhisper-small-<sha256>.partand re-hashes the kept bytes, so the final byte count and SHA-256 check is unchanged. If the server ignores the range (200), sends the wrong range (206) or answers 416 for an incomplete file, the download restarts from 0. A resumed file that fails the checksum is deleted and fetched once more from 0.ActivityLifecycleCallbacks, registered fromModelStore.refresh().MainActivity's lifecycle is unchanged.State.Retryis nowRetry(problem). Setup-screen lines touched:modelStatus()andmodelAction()inMainActivity.kt(about 5 lines), plus 2 strings each invaluesandvalues-zh-rCN.Verified on API 36 and API 31 emulators with the debug build, on top of #2291's flow (Turn on, Hex switched on in Settings, picker on return, Hex picked). Every run finished with the right SHA-256:
On API 36 today's build got interrupted about 5 s after leaving for Settings and fetched 234.5 MB in total. With this change it fetches 190.1 MB and shows no error. The signed release build also finished the 30 s Settings case on API 36. Its DEX has no
android.util.Logreferences. Dictation from Home used the installed small model../gradlew test lintDebugpasses.