Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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());
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
* <p><b>Why this exists.</b> 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 <em>system</em> goes away, so both outlived a wipe:
*
* <ul>
* <li>a stale {@link ModuleBatch} made the install index draw a row for a module from a
* previous, unrelated install — "Books reader" appearing in a run that never asked for
* it. Worse than cosmetic: {@code SetupProgressActivity.moduleInSession()} latches on
* it, and that decides whether the index becomes a gate, whether "Run in background"
* is offered, and whether the server restart is awaited;</li>
* <li>a stale {@link ModuleWishlist} is a scheduled install that survived the box it was
* scheduled against. At best it repeats work the new tier already shipped; at worst it
* runs a runrole nobody asked for in this run.</li>
* </ul>
*
* <p>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.
*
* <p><b>Not {@code HiddenModules}</b>, 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.
*
* <p>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)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
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
Expand All @@ -140,7 +140,7 @@
// 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()
Expand Down Expand Up @@ -550,7 +550,7 @@
* on purpose (not deleted): ADFA-4842 (reactivate proot modules via module management) may want
* to generalize a "install these proot modules now" path from here — 4842 decides whether to
* reuse/generalize or delete. Deleting now could remove something module management wants. */
public void openMapsPreparing(String[] levels) {

Check warning on line 553 in controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java

View workflow job for this annotation

GitHub Actions / Lint & Compile Check

[dep-ann] deprecated item is not annotated with @deprecated

Check warning on line 553 in controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java

View workflow job for this annotation

GitHub Actions / Build & Distribute

[dep-ann*** deprecated item is not annotated with @deprecated
getSupportFragmentManager().beginTransaction()
.replace(R.id.k2go_setup_host, MapsPreparingFragment.newInstance(levels))
.addToBackStack("maps_preparing")
Expand Down Expand Up @@ -616,7 +616,7 @@
* the per-layer selection). InstallService writes the full maps_* local_vars and runs runrole
* with the shared success/failure verdict, revert-on-fail and observable progress. {@code levels}
* is aligned to the Choose groups [base, satellite, terrain, search]; null = off. */
public void startMapsInstall(String[] levels) {

Check warning on line 619 in controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java

View workflow job for this annotation

GitHub Actions / Lint & Compile Check

[dep-ann] deprecated item is not annotated with @deprecated

Check warning on line 619 in controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java

View workflow job for this annotation

GitHub Actions / Build & Distribute

[dep-ann*** deprecated item is not annotated with @deprecated
String base = levels != null && levels.length > 0 && levels[0] != null ? levels[0] : "11";
String sat = levels != null && levels.length > 1 && levels[1] != null ? levels[1] : "none";
String ter = levels != null && levels.length > 2 && levels[2] != null ? levels[2] : "0-none";
Expand All @@ -637,7 +637,7 @@
* Kept UNUSED pending ADFA-4842 (see openMapsPreparing). (ZIM uses backToGetMoreHubZim, separate.)
* ADFA-4848: "Run in background" from Preparing -> drop the whole Maps flow off the back
* stack and return to the Get More hub; the build keeps running. */
public void backToGetMoreHub() {

Check warning on line 640 in controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java

View workflow job for this annotation

GitHub Actions / Lint & Compile Check

[dep-ann] deprecated item is not annotated with @deprecated

Check warning on line 640 in controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java

View workflow job for this annotation

GitHub Actions / Build & Distribute

[dep-ann*** deprecated item is not annotated with @deprecated
getSupportFragmentManager().popBackStack("getmore_maps",
androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@
* The one place that forgets content state when the system is replaced.
*
* <p>{@link SystemReplacement} decides <em>what</em>; 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.
*
* <p><b>The name undersells it now</b> (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.
*
* <p><b>Two moments, because they have different costs.</b>
*
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
* <p><b>Why one more class rather than two calls.</b> 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:
*
* <pre>
* PendingContent.clearAll(ctx);
* ModuleInstallState.clearAll(ctx);
* </pre>
*
* <p>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.
*
* <p>So the list lives here, and both moments ask the same question.
*
* <p><b>Two moments, one reason.</b> 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.
*
* <p>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);
}
}
14 changes: 14 additions & 0 deletions controller/docs/ADR-5061-rest-vs-proot-operation-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading