Skip to content

ADFA-7239: Apply a new APK's bundled add-ons at start-up - #2300

Draft
davidschachterADFA wants to merge 9 commits into
feature/ADFA-7238from
feature/ADFA-7239
Draft

davidschachterADFA wants to merge 9 commits into
feature/ADFA-7238from
feature/ADFA-7239

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-7239

Part of epic ADFA-3905. Stacked on #2289 (ADFA-7238), and based on its branch so this diff shows only this ticket. Draft until #2289 merges; then it will be rebased onto stage by merging the new base.

When a new APK is installed over an existing installation, its bundled add-ons replace the old bundle. This also repairs a first install that stopped before its bundle record was written.

What changes

  • BundleSync (new). When the build's bundle fingerprint differs from the record, or there is no record, it:

    Each bundled plugin replaces every other installed build of its ID, whether the user's or an older bundled one, through a new beforePluginMove hook on BundledAddonInstaller. That fixes ADFA-7238: Bundle plugins and templates and install them at first installation #2289's limitation that an older build was left beside the new one. The hook runs after the content check, so a corrupt copy never removes the installed build. A build that cannot be deleted fails the sync. A plugin whose bundled build is already the one installed is copied over in place and keeps its state (enabled or not, crash count). A template replaces one of the same name. A bundled add-on the user removed comes back, but only when the bundle changes. When any copy is rejected, nothing is removed: the rejected copy has no known ID and may be a recorded add-on that is still bundled. An I/O error leaves the old record, so the sync runs again at the next start.

  • BundleSyncAtStart (new) runs it from CredentialProtectedApplicationLoader:

    • before loadPlugins(), so the synced set loads once;
    • at most once per process;
    • only after first-time setup has put a JDK and SDK on disk (areIdeToolsInstalled(), beside isIdeSetupComplete in SetupState);
    • on a debug build whose assets-<arch>.zip is gone, not at all. It skips the sync instead of treating the bundle as empty.

    After a sync, bundled plugins that failed to load are recorded for the existing error bar. A failed sync is recorded there too.

  • MainActivity waits for the start-up check to begin and to end before reading failures. It waits up to 30 s for the check to begin, because the screen can resume first. It shows a progress bar ("Updating the plugins and templates that came with the app…") only while a sync runs.

  • ARCHITECTURE.md describes the sync.

Decisions (ADFA-7239 comment 41492):

  • A missing debug zip means no change.
  • A user's newer build of a bundled plugin stays bundled.
  • The progress bar shows only while a sync runs.

Verification

  • CI: Spotless and :app:assembleV8Debug pass on 68b04be, which merges ADFA-7238: Bundle plugins and templates and install them at first installation #2289's fea9942 (with stage) into 78fc586; the APK is on Firebase App Distribution as C-d-1123-0603 (ADFA-7239's upload at 06:22Z; ADFA-7238: Bundle plugins and templates and install them at first installation #2289's build has the same name, so pick by ticket key).
  • Independent review (Opus, on 8a9569f): no critical findings.
    • Fixed in e4f2a0e:
      • the start-up race: the screen could resume before the check began and miss the bar and the report;
      • every bundled plugin was uninstalled on every bundle change, which reset its state even when unchanged;
      • an old build that cannot be deleted;
      • a failed sync was only logged;
      • a retried start-up could run a second sync.
    • Done in ADFA-7238: Bundle plugins and templates and install them at first installation #2289 (eb8f522, its code) and merged here: a content-based fingerprint from a build-time index of SHA-256s, which also lists the bundle without inflating any add-on.
    • Kept by decision: a user's own build of a bundled plugin is removed when a later APK drops it.
  • Unit tests, run locally on 78fc586 because CI runs no app unit tests: :app:testV8DebugUnitTest passes 1853 of 1853, including BundleSyncTest's 20 cases, and :plugin-manager:testV8DebugUnitTest passes 210 of 210.
  • Each rule of BundleSync was broken on its own (on 90731e8, the same code), and the tests named for it failed at their assertions: an unchanged build uninstalled anyway; removals despite a rejected copy; no check that the old build is gone; the index hash not passed to the copy; absent bundled add-ons not removed; other builds never removed; the fingerprint ignored; no sync without a record; the record written before the copies; old failures kept.
  • Not yet done: device tests, per the ticket's Steps to QA, and the progress bar at font scale 1.0 and 2.0.

Limitations accepted

  • A real change of build uses PluginManager.uninstallPlugin, which clears the plugin's saved state, as an install from the Add-ons Manager does.
  • The sync's uninstalls are not serialized with a loadPlugins() started elsewhere. They run at start-up, before any screen can trigger a load.
  • After a sync with a rejected copy, the recorded add-ons it did not remove are no longer in the record. They stay installed as if the user had added them, and a later APK does not remove them.
  • An older debug zip without the bundle index is still fingerprinted by names and sizes, as ADFA-7238: Bundle plugins and templates and install them at first installation #2289 describes.
  • Templates can change while the main screen is usable during a sync. A project created from one at that moment can fail.
  • BundleSyncAtStart imports the on-disk setup check from activities, and repeats the installers' choice of bundle source.
  • The sync's "setup finished" check (JDK and SDK on disk) is looser than onboarding's validated JDK. On a partly extracted bootstrap, the sync can run although setup will rerun. The copies are atomic and the record is synchronized, so this is harmless.
  • The progress string is English only, like msg_bundled_plugins_failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw


Code Reviewer: Code Reviewer couldn't review this pull request
The pull request author does not have access to AI for the associated Atlassian organization.

claude and others added 6 commits November 22, 2026 20:22
When the build's bundle fingerprint differs from the record, or there is no
record (a first install cut short), install the whole bundle before plugins
load, remove recorded add-ons the new bundle lacks, keep other user add-ons,
and rewrite the record last.

- BundleSync: the sync. Each bundled plugin replaces every installed build of
  its ID (a user's or an older bundled one), through a new beforePluginMove
  hook on BundledAddonInstaller; a template replaces one of the same name; a
  removed bundled add-on comes back. An I/O error leaves the old record, so the
  sync runs again at the next start.
- BundleSyncAtStart: runs it from CredentialProtectedApplicationLoader before
  loadPlugins(), only once setup has put a JDK and SDK on disk
  (areIdeToolsInstalled, from SetupState). A debug build whose assets zip is
  gone skips the sync rather than treat the bundle as empty. Bundled plugins
  that fail to load after a sync are recorded for the error bar.
- MainActivity waits for the start-up check before reporting failures, and
  shows a progress bar only while a sync runs.
- ARCHITECTURE.md describes the sync.

Decisions (ADFA-7239 comment 41492): a missing debug zip is no change; a user's
newer build of a bundled plugin stays bundled; the bar shows only while a sync
runs.

Not compiled or tested in this environment (no Android SDK); BundleSyncTest
needs a run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw
`synced && manager != null`: synced is only true when manager is non-null, so
the compiler flags the second test (CredentialProtectedApplicationLoader:393).
Check the manager once around the sync, load and failure recording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw
- Keep an unchanged bundled plugin's state: a plugin whose bundled build is
  already the only one installed for its ID is copied over in place, and
  uninstallPlugin (which clears the enabled flag, crash count and caches) runs
  only for a real change of build. The hook now gets the target file name, and
  BundleSync builds the installer itself.
- Fail the sync, keeping the old record, when an older build of a bundled ID
  cannot be deleted, so two builds never load together.
- Close the start-up race: the state starts at NOT_STARTED, which the main
  screen waits through (up to 30 s) as well as CHECKING, so a screen that
  resumes before the plugin system starts still shows the bar and the report.
  A plugin system that fails to start ends the wait.
- Sync at most once per process, even if a failed start-up is retried.
- Record a failed sync for the error bar instead of only logging it.
- Tests: an unchanged plugin is not uninstalled; a changed build goes through
  uninstall; an undeletable old build fails the sync and keeps the record; a
  sync cut short converges; a missing record removes no user add-on; a debug
  build without its zip does not sync; a release build reads the APK assets.
- ARCHITECTURE.md updated.

Not compiled or tested in this environment (no Android SDK).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw
Brings in eb8f522: bundled-addons.tsv with each add-on's size and SHA-256,
listed and fingerprinted without opening an add-on, and copies checked
against their SHA-256.

Conflicts, both additive:
- strings.xml: ADFA-7238's reworded msg_bundled_plugins_failed, plus
  ADFA-7239's msg_updating_bundled_addons.
- ARCHITECTURE.md: ADFA-7238's paragraph, then ADFA-7239's sync sentences.

Also, in BundleSync: pass each entry's SHA-256 to the installer, so a sync
checks copies against the index as the first install does. The check runs
before beforePluginMove, so a corrupt copy never removes the installed build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw
A copy rejected for its content or manifest is not known by plugin ID, so it
may be a recorded add-on the new bundle still contains. Removing recorded IDs
the new set lacks would then uninstall the user's working build of it. When
any copy is rejected, skip the removals; the rejection is reported, and the
next bundle change removes what is left over.

Test: a rejected copy keeps the old bundled add-ons.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw
…ld build

A sync passes each entry's SHA-256 to the installer (0a5e4f0); this pins it:
a copy whose content does not match is reported, the installed build stays,
and nothing of that ID is uninstalled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw
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.

2 participants