Self-update: install via PackageInstaller and clean up installer files #13

Merged
nezumi merged 1 commit from fix/self-update into dev 2026-11-21 13:36:41 +00:00
Owner

Summary

Reworks the in-app self-update so that, after the user taps Update, the app downloads and installs the new version on its own where Android allows it, then removes the installer file and any leftovers.

  • Install via PackageInstaller session instead of ACTION_VIEW + FileProvider. On Android 12+ it sets USER_ACTION_NOT_REQUIRED, so the update is silent once KaraTV is its own installer of record. The first update after an adb/file-manager sideload, and every update on Android ≤ 11, still shows the system confirmation.
  • Auto-install when safe: runs only while the app is in the foreground and not in the middle of a song. After the user grants "install unknown apps", the install continues on resume, without reopening settings in a loop.
  • Cleanup:
    • The APK is deleted as soon as it is written into the session.
    • cache/updates is cleared on app start and on MY_PACKAGE_REPLACED.
    • Leftover sessions are abandoned on start.
    • Partial downloads (.apk.part) are removed on failure.
  • Integrity: the downloaded size is checked against the release asset size.
  • Fixes:
    • Crash on API 24/25: canRequestPackageInstalls() and ACTION_MANAGE_UNKNOWN_APP_SOURCES are API 26+.
    • A release check can no longer overwrite a running download or install.
  • UI:
    • New Installing state and chip.
    • The error dialog has a Retry button.
    • The "Khởi động lại" button now reads "Cài đặt".
  • Removes the now-unused FileProvider and res/xml/file_paths.xml.

Testing

  • ./gradlew :app:compileDebugKotlin :app:testDebugUnitTest :app:lintDebug pass; lint reports no NewApi findings.
  • Manual run on the Android TV emulator (API 36) against a mock releases/latest server:
    • A newer version was detected.
    • The download verified the size, then the unknown-sources grant led to an auto install.
    • Cancel at the confirmation returned to "update available".
    • The retry installed 9.9.9 silently, with the installer of record now com.karatv.app.
    • cache/updates was removed afterwards.
  • Not tested on a real device, or on Android ≤ 11 / API 24–25.

Known limitations

  • After a successful update the app is not reopened automatically. Android 10+ blocks background activity starts, and this was confirmed on the emulator, so the TV returns to the launcher.
  • If the confirmation is needed while the app is in the background, the system blocks it. The chip stays on "Installing…" until the next app start, which then cleans up and allows a retry.
## Summary Reworks the in-app self-update so that, after the user taps **Update**, the app downloads and installs the new version on its own where Android allows it, then removes the installer file and any leftovers. - **Install via `PackageInstaller` session** instead of `ACTION_VIEW` + FileProvider. On Android 12+ it sets `USER_ACTION_NOT_REQUIRED`, so the update is silent once KaraTV is its own installer of record. The first update after an adb/file-manager sideload, and every update on Android ≤ 11, still shows the system confirmation. - **Auto-install when safe**: runs only while the app is in the foreground and not in the middle of a song. After the user grants "install unknown apps", the install continues on resume, without reopening settings in a loop. - **Cleanup**: - The APK is deleted as soon as it is written into the session. - `cache/updates` is cleared on app start and on `MY_PACKAGE_REPLACED`. - Leftover sessions are abandoned on start. - Partial downloads (`.apk.part`) are removed on failure. - **Integrity**: the downloaded size is checked against the release asset `size`. - **Fixes**: - Crash on API 24/25: `canRequestPackageInstalls()` and `ACTION_MANAGE_UNKNOWN_APP_SOURCES` are API 26+. - A release check can no longer overwrite a running download or install. - **UI**: - New `Installing` state and chip. - The error dialog has a **Retry** button. - The "Khởi động lại" button now reads "Cài đặt". - Removes the now-unused FileProvider and `res/xml/file_paths.xml`. ## Testing - `./gradlew :app:compileDebugKotlin :app:testDebugUnitTest :app:lintDebug` pass; lint reports no NewApi findings. - Manual run on the Android TV emulator (API 36) against a mock `releases/latest` server: - A newer version was detected. - The download verified the size, then the unknown-sources grant led to an auto install. - Cancel at the confirmation returned to "update available". - The retry installed 9.9.9 silently, with the installer of record now `com.karatv.app`. - `cache/updates` was removed afterwards. - Not tested on a real device, or on Android ≤ 11 / API 24–25. ## Known limitations - After a successful update the app is not reopened automatically. Android 10+ blocks background activity starts, and this was confirmed on the emulator, so the TV returns to the launcher. - If the confirmation is needed while the app is in the background, the system blocks it. The chip stays on "Installing…" until the next app start, which then cleans up and allows a retry.
Self-update: install via PackageInstaller and clean up installer files
All checks were successful
CI / build (pull_request) Successful in 2m4s
332e678845
- Install through a PackageInstaller session instead of ACTION_VIEW; on
  Android 12+ the update is silent once the app is its own installer.
- Auto-install after the user taps update, only in the foreground and
  never in the middle of a song; resume after the unknown-sources grant.
- Delete the APK once it is written into the session; clear leftovers on
  start and on MY_PACKAGE_REPLACED; drop partial downloads.
- Verify the downloaded size against the release asset.
- Fix crash on API 24/25 (canRequestPackageInstalls is API 26+).
- Never let a check overwrite a running download/install; add Installing
  state and a retry button on errors.
- Remove the now-unused FileProvider.
nezumi deleted branch fix/self-update 2026-11-21 13:36:41 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nezumi/kara-tv-app!13
No description provided.