diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/GetMoreHubFragment.java b/controller/app/src/main/java/org/iiab/controller/redesign/GetMoreHubFragment.java index 1a4713f41..90dbe5d0c 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/GetMoreHubFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/GetMoreHubFragment.java @@ -50,20 +50,26 @@ public class GetMoreHubFragment extends Fragment { /** One content type on the hub. {@code key} is what SetupLibraryActivity routes on; * {@code endpoint} is the server path probed to decide whether the module is installed - * (so the card shows); {@code note} is the second (bold) line, {@code amber} tints it. */ + * (so the card shows); {@code note} is the second (bold) line. + * + *

ADFA-5074: there was an {@code amber} flag here that tinted the note as a warning. + * Courses was the only card using it, to mark "In-app: TBD" as not ready. The card now + * names what it offers, so the tint had stopped meaning "unfinished" and started meaning + * "something is wrong with this one". A future not-ready card should reintroduce the flag + * deliberately rather than inherit a colour nobody chose. */ private static final class Item { final String key; final String endpoint; final int icon; - final int title; final int desc; final int note; final boolean amber; - Item(String k, String e, int i, int t, int d, int n, boolean a) { - key = k; endpoint = e; icon = i; title = t; desc = d; note = n; amber = a; + final int title; final int desc; final int note; + Item(String k, String e, int i, int t, int d, int n) { + key = k; endpoint = e; icon = i; title = t; desc = d; note = n; } } private static final Item[] ITEMS = { - new Item("wikipedia", "kiwix", R.drawable.ic_card_wikipedia, R.string.k2go_gm_wikipedia_title, R.string.k2go_gm_wikipedia_desc, R.string.k2go_gm_wikipedia_note, false), - new Item("books", "books", R.drawable.ic_card_book, R.string.k2go_gm_books_title, R.string.k2go_gm_books_desc, R.string.k2go_gm_books_note, false), - new Item("maps", "maps", R.drawable.ic_card_maps, R.string.k2go_gm_maps_title, R.string.k2go_gm_maps_desc, R.string.k2go_gm_maps_note, false), - new Item("courses", "kolibri", R.drawable.ic_card_courses, R.string.k2go_gm_courses_title, R.string.k2go_gm_courses_desc, R.string.k2go_gm_courses_note, true), + new Item("wikipedia", "kiwix", R.drawable.ic_card_wikipedia, R.string.k2go_gm_wikipedia_title, R.string.k2go_gm_wikipedia_desc, R.string.k2go_gm_wikipedia_note), + new Item("books", "books", R.drawable.ic_card_book, R.string.k2go_gm_books_title, R.string.k2go_gm_books_desc, R.string.k2go_gm_books_note), + new Item("maps", "maps", R.drawable.ic_card_maps, R.string.k2go_gm_maps_title, R.string.k2go_gm_maps_desc, R.string.k2go_gm_maps_note), + new Item("courses", "kolibri", R.drawable.ic_card_courses, R.string.k2go_gm_courses_title, R.string.k2go_gm_courses_desc, R.string.k2go_gm_courses_note), }; private final Handler main = new Handler(Looper.getMainLooper()); @@ -293,8 +299,8 @@ private void buildCards() { ((TextView) card.findViewById(R.id.k2go_gm_card_desc)).setText(it.desc); TextView note = card.findViewById(R.id.k2go_gm_card_note); note.setText(it.note); - note.setTextColor(androidx.core.content.ContextCompat.getColor(requireContext(), - it.amber ? R.color.k2go_amber_text : R.color.k2go_muted)); + note.setTextColor(androidx.core.content.ContextCompat.getColor( + requireContext(), R.color.k2go_muted)); card.setOnClickListener(v -> { if (!(getActivity() instanceof SetupLibraryActivity)) return; SetupLibraryActivity a = (SetupLibraryActivity) getActivity(); diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ModuleInstallState.java b/controller/app/src/main/java/org/iiab/controller/redesign/ModuleInstallState.java new file mode 100644 index 000000000..690a6c080 --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ModuleInstallState.java @@ -0,0 +1,92 @@ +/* + * ============================================================================ + * Name : ModuleInstallState.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : The module-install flow's two stores, discarded together + * (ADFA-5074). + * ============================================================================ + */ +package org.iiab.controller.redesign; + +import android.content.Context; +import android.util.Log; + +import org.iiab.controller.install.presentation.ModuleQueueRepository; + +/** + * Everything the module-install flow remembers between screens, in one place to forget. + * + *

Why this exists. The flow keeps two stores and each was only cleared at the + * moment it happened to be finished with: {@link ModuleWishlist} when the batch is handed + * to the engine, {@link ModuleBatch} when the install index reaches the library. Neither is + * cleared when the system goes away, so both outlived a wipe: + * + *

+ * + *

The content side already had this — four wishlists behind {@code PendingContent} — and + * these two were simply not in that enumeration, because a module install is not content. + * Rather than teach two more call sites to list them, they are cleared together here, and + * both facades sit behind {@code PendingWork} so no caller enumerates anything. + * + *

Not {@code HiddenModules}, which also persists module keys. That one records which + * modules the user chose not to see on Home — a preference about the app, not work arranged + * against a system — so it is meant to outlive a wipe. Named here because it looks like a + * third store to anyone grepping for module keys, and the next person should not have to work + * out why it was left alone. + */ +public final class ModuleInstallState { + + private static final String TAG = "K2Go-ModuleState"; + + private ModuleInstallState() { + } + + /** Whether either persisted store still holds something. */ + public static boolean any(Context ctx) { + return ctx != null && (ModuleWishlist.has(ctx) || ModuleBatch.has(ctx)); + } + + /** + * Forgets both: what was scheduled, and what a previous run was installing. + * + *

Called where the content wishlists are dropped — a fresh wizard run, and a completed + * system replacement — because it is the same event for the same reason: the work was + * arranged against a system that no longer exists. + */ + public static void clearAll(Context ctx) { + if (ctx == null) { + return; + } + Context app = ctx.getApplicationContext(); + // Unconditional: asking first cost two SharedPreferences reads purely to decide + // whether to log, and one caller is the wizard's onCreate — main-thread disk for a + // message. Both clears are idempotent, so there is nothing to guard. + ModuleWishlist.clear(app); + ModuleBatch.clear(app); + + // ADFA-5074: and the queue's own verdict, which is held in memory for the life of the + // process. A finished install leaves it on DONE, and the install index reads that phase + // to decide whether a row is complete — so a new run drew a green check over a maps + // install that had not started, and only corrected itself when the real runrole + // published RUNNING. The row was trusting a verdict without asking whose it was. + // + // Never over a live one: a runrole in flight owns this state, and posting idle under it + // would replace a true report with a false one. On a replacement the queue has already + // been stopped; on a fresh wizard run there is nothing to stop. + ModuleQueueRepository queue = ModuleQueueRepository.get(); + if (!queue.isRunning()) { + queue.postIdle(); + } + Log.i(TAG, "module install state discarded (scheduled list, batch, queue verdict)"); + } +} diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java b/controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java index 1e7ea0506..39e8d7faa 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java @@ -130,7 +130,7 @@ protected void onCreate(Bundle savedInstanceState) { first = new GetMoreHubFragment(); // ADFA-4848: Get More opens the content hub } else if (reinstallMode) { // ADFA-5023: reinstall = the normal first-run wizard, but the final install wipes first. - org.iiab.controller.system.data.PendingContent.clearAll(this); + org.iiab.controller.system.data.PendingWork.clearAll(this); first = new Step1SystemFragment(); } else { // ADFA-4874: a fresh wizard run — drop any wishlist left by an aborted first-run so @@ -140,7 +140,7 @@ protected void onCreate(Bundle savedInstanceState) { // others were, so an abandoned run's map selection survived into the next one. // The maps selector reached from Home takes the mapsSetup branch above and is // unaffected. - org.iiab.controller.system.data.PendingContent.clearAll(this); + org.iiab.controller.system.data.PendingWork.clearAll(this); first = new Step1SystemFragment(); } getSupportFragmentManager().beginTransaction() diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/SetupProgressActivity.java b/controller/app/src/main/java/org/iiab/controller/redesign/SetupProgressActivity.java index 5e09c3315..3c042acd4 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/SetupProgressActivity.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/SetupProgressActivity.java @@ -659,7 +659,14 @@ private void render() { show(redirect, false); show(cancel, false); } else { // starting or running cancelRedirect(); - show(runBgBtn, !prootActive); // ADFA-4919: no "Run in background" while a proot module runs — the index is the gate + // ADFA-4919: no "Run in background" while a proot module runs — the index is the gate. + // ADFA-5074: and not before the run's shape is known either. prootActive() reads a latch + // that only engages once the proot work registers — launched, batched, or reported by the + // queue — so on entry it is false even for a run that is about to install a module, and + // the screen offered an escape it was going to withdraw. Waiting for servicesReady costs + // nothing: until the engine answers there is no live work to leave running anyway, and + // the header already says "Starting services…". + show(runBgBtn, servicesReady && !prootActive); show(finishBtn, false); show(finishNote, false); show(redirect, false); show(cancel, false); } } diff --git a/controller/app/src/main/java/org/iiab/controller/system/data/ContentStateInvalidator.java b/controller/app/src/main/java/org/iiab/controller/system/data/ContentStateInvalidator.java index be4248d75..01476b783 100644 --- a/controller/app/src/main/java/org/iiab/controller/system/data/ContentStateInvalidator.java +++ b/controller/app/src/main/java/org/iiab/controller/system/data/ContentStateInvalidator.java @@ -25,9 +25,16 @@ * The one place that forgets content state when the system is replaced. * *

{@link SystemReplacement} decides what; this carries it out against - * the seven stores that actually hold it — three in-memory download sessions (ZIM, - * Books, Kolibri) and four on-disk orders (those three plus Maps). Maps has no - * session of its own: it keeps no download progress in the app, only a wishlist. + * the nine stores that actually hold it — three in-memory download sessions (ZIM, + * Books, Kolibri), four on-disk orders (those three plus Maps), and the module-install + * flow's own two, behind {@code ModuleInstallState}. Maps has no session of its own: it + * keeps no download progress in the app, only a wishlist. + * + *

The name undersells it now (ADFA-5074). It began as content only, and the + * module stores were added when a stale batch was found drawing a row for a module from an + * unrelated install. Renaming it would touch every destructive route for no behavioural + * gain, so the name stays and this note carries the truth: what it forgets is state that + * described the system that went away, whether or not that state is content. * *

Two moments, because they have different costs. * @@ -117,7 +124,10 @@ public static void replacementSucceeded(Context ctx, SystemReplacement.Cause cau Context app = ctx.getApplicationContext(); int discarded = PendingContent.read(app).bankedCount(); - PendingContent.clearAll(app); + // ADFA-5074: through PendingWork, so this and the wizard's own clear-on-open ask the + // same question. Listing the facades here as well would put the enumeration back in + // two places, which is how the module stores came to be missing from it. + PendingWork.clearAll(app); Log.i(TAG, "after " + cause + ": " + discarded + " pending order(s) discarded"); } diff --git a/controller/app/src/main/java/org/iiab/controller/system/data/PendingWork.java b/controller/app/src/main/java/org/iiab/controller/system/data/PendingWork.java new file mode 100644 index 000000000..3eb2d4804 --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/system/data/PendingWork.java @@ -0,0 +1,58 @@ +/* + * ============================================================================ + * Name : PendingWork.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : One door for forgetting everything arranged against a system + * that is gone (ADFA-5074). + * ============================================================================ + */ +package org.iiab.controller.system.data; + +import android.content.Context; + +/** + * Discards every order the user placed against a system that no longer exists. + * + *

Why one more class rather than two calls. There are two families of pending + * work — content orders behind {@link PendingContent}, and the module-install flow's own two + * stores behind {@code ModuleInstallState} — and for a while both call sites listed them in + * a pair: + * + *

+ *     PendingContent.clearAll(ctx);
+ *     ModuleInstallState.clearAll(ctx);
+ * 
+ * + *

That is the same mistake as before, one level up. It began as six stores enumerated by + * hand in five screens; consolidating them into two facades left three places enumerating + * the two facades. A seventh store tomorrow would need adding in all of them, and the one + * that got missed would be the one nobody tested — which is precisely how a stale module + * batch ended up drawing a row for an install that never happened. + * + *

So the list lives here, and both moments ask the same question. + * + *

Two moments, one reason. A fresh wizard run drops whatever an abandoned earlier + * run left behind, and a completed system replacement drops the orders placed against the box + * that was wiped. They arrive by different routes but they are the same event: the work was + * arranged against a system that is no longer there. + * + *

Touches SharedPreferences, so prefer calling it off the main thread. The wizard path + * calls it during {@code onCreate} because that is where the decision is made; the writes are + * {@code apply()} and asynchronous. + */ +public final class PendingWork { + + private PendingWork() { + } + + /** Everything: content orders, and the module flow's scheduled list and batch. */ + public static void clearAll(Context ctx) { + if (ctx == null) { + return; + } + Context app = ctx.getApplicationContext(); + PendingContent.clearAll(app); + org.iiab.controller.redesign.ModuleInstallState.clearAll(app); + } +} diff --git a/controller/docs/ADR-5061-rest-vs-proot-operation-model.md b/controller/docs/ADR-5061-rest-vs-proot-operation-model.md index 21e38f77e..4fec80ca4 100644 --- a/controller/docs/ADR-5061-rest-vs-proot-operation-model.md +++ b/controller/docs/ADR-5061-rest-vs-proot-operation-model.md @@ -353,6 +353,20 @@ most expensive by the third platform. A is B done safely over time. The point of the indirection is that changing it later is one line, and that a module which turns out to need its own can have it without anyone touching a layout. + **Serialising is not the net it looks like** (noted, not blocking). The three live + streams are meant to run one at a time, which was the poor man's stand-in for a disk + budget: if only one runs, each selector's free-space reading is roughly valid. + `ZimProvisioner.drain` starts asynchronously, though — it fetches the Kiwix catalogue + first and only starts the service from the callback — so within one + `orchestrateStep` pass Books and Courses look at a ZIM that has no session yet and + start too. Three at once, observed on device. + + Not urgent and deliberately not part of ADFA-5074: the fix would have the guard count + an order already handed to a drain, not just a session in flight, and that changes + serialisation semantics with a real risk of two flows waiting on each other. And it + would still only be a stand-in — the honest answer is the run-level budget above. + Recorded so it is not rediscovered as a surprise. + Also decide **which lifetime each piece of state gets**. Three mechanisms are in use and nothing says which is for what: a `ViewModel` (survives a configuration change only), a `SavedStateHandle` (also survives a process death, riding the task's instance state), and diff --git a/controller/docs/content-execution-order.svg b/controller/docs/content-execution-order.svg index 6ef5c2704..bc81261e0 100644 --- a/controller/docs/content-execution-order.svg +++ b/controller/docs/content-execution-order.svg @@ -1,4 +1,4 @@ - + Content installation — mechanism and order How the four content types install: which mechanism each uses, why they are serialised, where the server is stopped, and what is still unsolved. Companion to operation-model-roadmap.svg, which tracks ticket state rather than behaviour. Update when the behaviour changes, not when a ticket moves. @@ -30,7 +30,7 @@ - + Content installation — mechanism and order Four content types, two mechanisms. What runs when, what waits for what, and why. @@ -91,26 +91,29 @@ InstallService.runModuleQueue():704 - + OPEN No run-level disk budget Each selector does block: it compares its own total against StatFs at the moment it is opened. But a banked order is not on disk yet, so two selections can each fit and jointly overflow — and the one that drains second dies mid-download with tens of GB already written. The wizard DOES show the running total ("Your picks 9.4 GB"); what none of them does is subtract it before deciding. The sum informs, it does not guard. -ZimConfirmFragment:94 · MapsChooseFragment:270 · KolibriConfirmFragment:211 — three readings, three moments, no total +And serialising is not the safety net it looks like: ZimProvisioner.drain starts asynchronously (catalogue fetch first), so in the +same orchestrateStep pass Books and Courses see no session yet and start too. Observed on device: three streams at once. +ZimConfirmFragment:94 · MapsChooseFragment:270 · KolibriConfirmFragment:211 — three readings, three moments, no total +Noted, not blocking: nice-to-have, and the real answer is the budget rather than tighter serialising. Do not let it displace the ticket. - - -OPEN -Five landings for one kind of work — owned by ADFA-5074 -Wizard, all four types: the order is banked and the user returns to the hub. No progress surface at all until after the install. -Get More: ZIM → ZimPreparingFragment inside SetupLibraryActivity · Books → the index, with a hint that jumps straight to the detail · -Maps → the index list · Courses → KolibriSeedingFragment inside SetupLibraryActivity. -The screens are NOT duplicated: SetupProgressActivity.openDetail() hosts those same fragments, with a fromIndex flag for the chrome. -What differs is the host, so Back still walks out of a live download and a notification returns you to a different screen than you left. -Closed already: the Home header opens the index (PR 1) · a finished session no longer gates anything (PR 2). Hosting is what remains. + + +OPEN +Five landings for one kind of work — owned by ADFA-5074 +Wizard, all four types: the order is banked and the user returns to the hub. No progress surface at all until after the install. +Get More: ZIM → ZimPreparingFragment inside SetupLibraryActivity · Books → the index, with a hint that jumps straight to the detail · +Maps → the index list · Courses → KolibriSeedingFragment inside SetupLibraryActivity. +The screens are NOT duplicated: SetupProgressActivity.openDetail() hosts those same fragments, with a fromIndex flag for the chrome. +What differs is the host, so Back still walks out of a live download and a notification returns you to a different screen than you left. +Closed already: the Home header opens the index (PR 1) · a finished session no longer gates anything (PR 2). Hosting is what remains.