Skip to content

Android: Hex Preview's update download survives leaving the app; setup says Hex Preview - #2552

Merged
R44VC0RP merged 2 commits into
devfrom
android-preview-uidt
Nov 23, 2026
Merged

R44VC0RP merged 2 commits into
devfrom
android-preview-uidt

Conversation

@R44VC0RP

Copy link
Copy Markdown
Collaborator

Two commits, both under android/app/src/preview/ only (Play builds and src/main unchanged). Not for merge by the author. Both reach people as Hex Preview's first update through the app.

1. f84143a: setup names "Hex Preview", as Android's lists do. Found on a first run of published build 2305 from the real link: Hex Preview's setup said "Set up Hex", "choose Hex as your keyboard", "Turn on Hex in Settings", "Choose Hex in the list", while Android's Turn on list, keyboard picker and microphone prompt say "Hex Preview" (and, with the Play app installed, the picker offers both "Hex" and "Hex Preview"). Preview-only overrides (English and Simplified Chinese) of setup_title, setup_detail, setup_microphone_detail, setup_keyboard, setup_keyboard_enabled, setup_keyboard_off, setup_choose_hex, keyboard_hint_microphone, and setup_welcome_detail, which also stops claiming the internet is used only for the speech model (it now names the GitHub update check). "The Hex key" stays.

2. 4e90199: the update download keeps going when the person leaves the app (Android 14+). On Android 16 the in-process download was cut off about 5 s after leaving Hex Preview. The tap on Update now schedules a user-initiated data transfer job (UpdateJob) running the unchanged Channel.download and Channel.verify. If the app is in front when it finishes, it installs as before; if not, nothing installs from the background: the verified file stays and the Home card shows Install, which re-checks size, SHA-256 and signing key before the installer runs. Below Android 14 nothing changes.

  • New in the preview manifest only: android.permission.RUN_USER_INITIATED_JOBS and the UpdateJob service (BIND_JOB_SERVICE, not exported). No POST_NOTIFICATIONS.
  • What the person sees: the Home card's progress, then Install if they were away; Android's running-apps list shows Hex Preview while the job runs. The job's notification ("Downloading Hex Preview 0.2.x", then "… is downloaded. Open Hex Preview to install it.") is not shown: without POST_NOTIFICATIONS declared, Android's settings say "This app does not send notifications" and can't turn it on.

Verified on an Android 16 emulator with this branch built as build 2300 (preview key), updating to the real channel's published 2305 (nothing published, test fork untouched):

  • setup shows the new wording; the keyboard picker match ("Choose Hex Preview in the list" / "Hex Preview");
  • Update, then Home 0.7 s later: the job ran 8.7 s entirely in the background, the APK downloaded and verified, version stayed 2300; on return the card showed Install; Install updated to 2305 with no system dialog, keyboard still selected, cache emptied on next open;
  • Update in front: downloaded and installed as before;
  • job stopped by Android (cmd jobscheduler timeout): partial file deleted, card says "The download stopped…" with Try again, which then completed;
  • ./gradlew :app:testDebugUnitTest passes; APK signed with the preview certificate, badging and permissions checked.

Not verified: a slow connection long enough to exceed the old cut-off by minutes (the emulator's network couldn't be throttled; the background run was ~8 s against the observed ~5 s cut-off), Android 14/15, and real phones.

Hex Preview's first run said "Set up Hex", "choose Hex as your keyboard", a
"Hex keyboard" row with "Turn on Hex in Settings" / "Choose Hex in the list",
and "Choose Hex keyboard", while Android's keyboard list, keyboard picker and
microphone prompt say "Hex Preview" (and list both "Hex" and "Hex Preview"
for anyone who also has the Play app), so a person could turn on or pick the
wrong keyboard. Its welcome also said Hex uses the internet only for the
speech model, which isn't true for Hex Preview: it also asks GitHub for
updates.

What changed (preview build type only, src/preview/res, English and Simplified
Chinese; src/main and the Play builds are unchanged):
- setup_title, setup_detail, setup_microphone_detail, setup_keyboard,
  setup_keyboard_enabled, setup_keyboard_off, setup_choose_hex now name
  "Hex Preview".
- keyboard_hint_microphone ("Allow the microphone in Hex Preview"): the
  keyboard's hint tells the person which app to open; MicCapture's sentinel
  sentence still maps to this resource, so no code changed.
- setup_welcome_detail: "Hex Preview uses the internet only to download its
  speech model (190 MB) and to check GitHub for updates. Your voice and words
  stay on this device."
"The Hex key", "Hex menu", "Hex dictation" and the keyboard's TalkBack pane
name stay as they are: they name the key and the keyboard's own parts, not
something to find in Android's lists.

Verified on the Mac Studio (with the next commit): :app:testDebugUnitTest
passes; :app:assemblePreview -PhexPreviewBuild=2300 builds, and aapt2 dump
strings shows the new English and Chinese strings in app-preview.apk.
…aves the app

On Android 16 (API 36) the update download, a plain HTTPS read on the
updater's own thread, was cut off about 5 s after the person left Hex
Preview, and the Home card then said "The download stopped..." with Try
again. API 31 was unaffected.

What changed (src/preview only; the Play builds and src/main are unchanged):
- Android 14+ (API 34): the tap on Update (or Download after the mobile-data
  note, or Try again) schedules a user-initiated data transfer job
  (UpdateJob: setUserInitiated, NETWORK_TYPE_ANY, the APK's size as its
  estimated bytes, the release in its extras). The job posts its
  notification first thing, then runs the same download and checks as
  before on the updater's worker (Channel.download's host allow-list, size
  and SHA-256, then Channel.verify's package, build and signing-key checks,
  untouched), updating the Home card and the notification's progress.
  onStopJob ends the download at its next read, which deletes the partial
  file and shows the same "download stopped" card; it is not rescheduled.
  With no network at all, or if Android refuses the job, the download runs
  in-process as before.
- When the job's download is checked: if Hex Preview's window shows, it
  installs exactly as before. If not, nothing installs from the background:
  the verified file stays, a notification says "Hex Preview <version> is
  downloaded" / "Open Hex Preview to install it.", and the Home card shows
  Install (kept across a restart of the process while the file is still
  there). Install checks the file's size, SHA-256 and signing key again
  before the installer session; if Android cleared it from the cache, it
  downloads again (asking first on mobile data). Nothing installs without
  the person's tap.
- Below Android 14 the in-process download is unchanged (the same code,
  moved into Updates.fetch, which both paths share).

New permission (preview manifest only): android.permission.RUN_USER_INITIATED_JOBS,
plus the UpdateJob service guarded by BIND_JOB_SERVICE (not exported). No
POST_NOTIFICATIONS is declared or asked for, so there is no new prompt.

What the person sees: the Home card's progress as before, and Android's
running-apps list (Task Manager) shows Hex Preview while the job runs. The
notification ("Downloading Hex Preview <version>" with progress, in a
low-importance "Updates" channel; tapping opens Hex Preview) appears in the
notification shade only where Hex Preview may post notifications, which by
default it can't on Android 13+.

Verified on the Mac Studio: :app:testDebugUnitTest passes;
:app:assemblePreview -PhexPreviewBuild=2300 builds (lintVital included);
aapt2 dump badging shows ly.anoma.hex.preview, versionCode 2300, label
"Hex Preview"; aapt2 dump permissions lists RUN_USER_INITIATED_JOBS; the
manifest has the UpdateJob service with BIND_JOB_SERVICE; apksigner verify
passes with certificate SHA-256 133568f6...35d98e. Not yet run on a phone
or emulator.
@R44VC0RP
R44VC0RP merged commit 81d058f into dev Nov 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant