Skip to content

Fix updater stuck on 'Downloading…' — complete download → verify → installer flow - #20

Merged
Lav-developer merged 3 commits into
android-appfrom
arena/01a09504-pyq
Sep 13, 2026
Merged

Lav-developer merged 3 commits into
android-appfrom
arena/01a09504-pyq

Conversation

@arena-ai-coding-agent

Copy link
Copy Markdown
Contributor

Summary

Fixes the in-app updater bug where the v1.4.2 APK downloaded fully ("5.70 MB / 5.70 MB") but the system installer never appeared and the button stayed on "Downloading…" forever. Updater scope only — update detection, the Worker /api/app-update endpoint, releases, and all other app features are untouched.

Root cause (3 compounding post-download defects)

  1. REQUEST_INSTALL_PACKAGES missing from the manifest — on Android 8+ the system package installer cannot resolve ACTION_VIEW intents for application/vnd.android.package-archive at all without it. The download finished, the installer launch failed silently.
  2. catch (Exception) only in downloadAndInstall — any Throwable after download left the Capacitor PluginCall unanswered, so the JS await never settled.
  3. No JS success handler — even a successful native resolve left the button on "Downloading…".

What changed

  • DsmnruAppPlugin.java — downloadAndInstall rewritten as a phased pipeline: download (.part file, real byte-progress events, manual per-hop redirect re-validation, timeouts, UA, streams/connections closed) → verify (exists → plausible/exact size → ZIP magic → PackageManager.getPackageArchiveInfo parse → exact expectedVersionCode) → atomic .part → .apk rename → install (FileProvider content:// URI + FLAG_GRANT_READ_URI_PERMISSION, launched on the main thread with a latch so the real outcome is known) → plugin call resolved/rejected exactly once on every terminal path (AtomicBoolean + catch (Throwable)). Invalid/partial files are deleted; a verified APK is kept so retry after granting the install permission skips straight to the installer. Unknown-app-sources is detected via canRequestPackageInstalls() and the exact settings screen is opened (UPDATE_INSTALL_PERMISSION_REQUIRED) instead of failing opaquely.
  • UpdateUrlPolicy.java (new) — pure-JDK security policy: HTTPS-only github.com / objects.githubusercontent.com initial URLs, *.githubusercontent.com redirect targets only, no embedded credentials, bounded redirects, APK size floor/ceiling, .apk filename sanitizing, ZIP-magic sniff. No android.* imports → unit-testable on the JVM.
  • AndroidManifest.xml — adds REQUEST_INSTALL_PACKAGES (required for sideload installs; per-user "Install unknown apps" toggle still fully in the user's control).
  • www/js/update.js — same dialog design; real MB progress, "Verifying…", "Starting installer…", retry + toast on every failure (download and post-download), 90 s watchdog, "Open installer" success state; Later/mandatory behavior preserved.
  • www/js/native.js — onUpdateProgress() subscription, expectedVersionCode passthrough, bridge re-resolution on each probe.
  • build.gradle — pinned back to 1.4.1 / versionCode 12 (the merged baseline was 13/1.4.2) so the existing GitHub Release v1.4.2 (code 13) remains the update target for the on-device test.

Tests

  • android-app: 91/91 pass, including the new test/update-install.test.mjs (15 cases: trusted/untrusted URLs, redirect policy, phase separation, .part/rename/cleanup, FileProvider + Intent contract, install-permission guidance, jsdom UI state machine — success / download failure / post-download installer failure / permission / watchdog / retry / Later / mandatory, 1.4.1→v1.4.2 detection, no version bump) and new JUnit UpdateUrlPolicyTest (plain JVM).
  • worker: 139/139 pass — update detection untouched.

Version / release safety

  • versionName "1.4.1", versionCode 12 (test-enforced)
  • No new release, no release-automation changes, no Worker changes, v1.4.2 remains the update target.

…taller flow

Root cause: after the APK finished downloading, three defects prevented the
installer from ever opening and left the JS button on 'Downloading…' forever:
1. REQUEST_INSTALL_PACKAGES was missing from the manifest — Android 8+ cannot
   resolve the package installer for ACTION_VIEW apk:// intents without it;
2. the plugin caught only Exception (an Error/Throwable after download left
   the Capacitor PluginCall unanswered forever);
3. JS had no success/error state handling after the call.

Fixes (updater only — detection, Worker, releases untouched):
- DsmnruAppPlugin.downloadAndInstall: phased download → verify → install with
  real byte progress events (updateDownloadProgress), .part→.apk promotion
  only after verification (exists/size/ZIP magic/PackageManager parse/expected
  versionCode), manual per-hop redirect re-validation via new UpdateUrlPolicy
  (HTTPS github.com/objects.githubusercontent.com + *.githubusercontent.com
  CDN only), 15s/30s timeouts, proper stream/connection close, single-flight
  guard, partial-file cleanup, verified-APK reuse for instant retry, unknown
  app-sources settings hand-off (UPDATE_INSTALL_PERMISSION_REQUIRED), and the
  call answered EXACTLY ONCE on every terminal path (catch Throwable).
- Manifest: + REQUEST_INSTALL_PACKAGES (sideload installer requirement).
- update.js: same dialog; real MB progress, Verifying/Starting installer
  states, retry + toast on every failure, 90s watchdog, 'Open installer'
  success state, Later/mandatory behavior preserved.
- native.js: onUpdateProgress subscription, expectedVersionCode passthrough,
  re-resolve injected bridge on each probe.
- build.gradle: pinned back to 1.4.1 / 12 (local test build) so the existing
  GitHub v1.4.2 (code 13) is the update target.
- Tests: UpdateUrlPolicyTest (JUnit, plain JVM) + test/update-install.test.mjs
  (policy contract, FileProvider/Intent contract, jsdom UI state machine:
  success, download failure, post-download installer failure, permission
  guidance, watchdog, retry, Later/mandatory, no version bump).

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@gitguardian

gitguardian Bot commented Sep 12, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
37209929 Triggered Generic Password ff0ef91 android-app/android/app/src/test/java/com/dsmnru/pyq/UpdateUrlPolicyTest.java View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Lav-developer and others added 2 commits September 12, 2026 10:32
…ect.opt

JSONObject.get(String) throws the checked JSONException, so
downloadAndInstall failed 'assembleRelease' with 'unreported exception
JSONException' at the expectedVersionCode read. Switch to opt(String),
which returns null when absent and never throws — behavior identical:
JS/native.js still passes the Worker-reported versionCode, and verifyApk
still rejects any package whose versionCode differs. Adds a source
regression test locking the accessor choice.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…sion pins

Reproduced the 'App logic + Worker API tests' failure with versionName
1.4.2 / versionCode 13. Exactly two tests failed, both stale hard-coded
version pins (no production bug, no Worker coupling — worker tests are
pure fixtures and build.gradle is never read there):

1. test/fcm.test.mjs (pre-existing, predates PR #20): asserted
   'versionCode 12' / versionName "1.4.1" inside a Firebase-wiring test.
   Written before the repo's own bump commit d99c212, which never updated
   it — incidental coupling that breaks on every legitimate bump. Now
   asserts well-formed metadata (integer versionCode, semver versionName)
   while keeping every Firebase/identity/signing assertion.

2. test/update-install.test.mjs: 'NO version bump' pinned 1.4.1/12 for
   the temporary local-device updater test against the published v1.4.2
   release. Replaced with a well-formedness invariant; the updater logic
   tests remain fixture-driven (local 1.4.1/12 vs remote v1.4.2/13 as
   pure data, independent of build.gradle).

build.gradle is restored to the production versionCode 13 /
versionName "1.4.2" with a comment stating the release flow owns the
values. No Worker changes, no release automation changes, existing
GitHub releases untouched.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@Lav-developer
Lav-developer merged commit e5af5e7 into android-app Sep 13, 2026
3 of 4 checks 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