From 204641070c7516c2ae293a638a19b98a569d2927 Mon Sep 17 00:00:00 2001 From: Luis-ADFA Date: Tue, 1 Sep 2026 03:30:20 -0600 Subject: [PATCH 1/2] ADFA-5364 refactor(content): one admission rule for the REST content streams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Books, ZIM and Kolibri each carried the same deferral rule word for word — proot or a dashboard update in flight, then another stream with unfinished work — so a fourth stream would have carried a fourth copy. It now lives once, in system/data next to the PendingContent it consults, which is a package that already depends on both callers' packages: no new dependency direction. Behaviour is unchanged: same checks, same order, same reasons. The only observable difference is the log wording, unified on "deferred" (Kolibri said "blocked"), which is the accurate word — a deferred order stays in the wishlist and the next pass takes it. Not touched: the proot provisioners (maps, modules). Their gate looks similar but is a different rule for a different family — they are what this one defers to, and sharing it would make maps defer on REST work it must ignore. First slice of ADFA-5364: the gate now exists in one place, so the connection dimension lands there instead of in three copies. No behaviour to verify by test; the device check is that queueing content during a module install still defers, on all three streams. --- .../presentation/KolibriProvisioner.java | 26 ++----- .../controller/redesign/BooksProvisioner.java | 21 +----- .../controller/redesign/ZimProvisioner.java | 23 +----- .../system/data/ContentAdmission.java | 74 +++++++++++++++++++ 4 files changed, 85 insertions(+), 59 deletions(-) create mode 100644 controller/app/src/main/java/org/iiab/controller/system/data/ContentAdmission.java diff --git a/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriProvisioner.java b/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriProvisioner.java index 571ddf37f..78fac82b1 100644 --- a/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriProvisioner.java +++ b/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriProvisioner.java @@ -43,8 +43,7 @@ public static boolean hasPending(Context ctx) { } /** - * ADFA-4954: whether a drain would proceed right now, without writing - * anything. + * ADFA-4954: whether a drain would proceed right now, without writing anything. * *

Now only {@link #drain} asks. It used to be public API for the live door, which * checked before writing so it could refuse with "Another download is running" rather @@ -54,27 +53,12 @@ public static boolean hasPending(Context ctx) { * and visible ("Queued" on its row). The door banks and lets this defer; a queue is a * better answer than a refusal, and the honest one now that something drains it. * - *

The rule stays here rather than being restated at the call site — that is - * how the four {@code *Wizard} booleans went wrong. + *

The rule itself moved to {@link org.iiab.controller.system.data.ContentAdmission}: Books + * and ZIM carried the same one, word for word. It stays out of the call site for the reason + * this javadoc always gave — that is how the four {@code *Wizard} booleans went wrong. */ static boolean canDrainNow(Context ctx) { - if (org.iiab.controller.install.presentation.ModuleQueueRepository.get().isRunning() - || MapsProvisioner.hasPending(ctx) - || org.iiab.controller.redesign.DashboardRebuildService.isRunning()) { // ADFA-5333 - Log.d(TAG, "kolibri drain blocked: proot (runrole) or dashboard-update work is in flight"); - return false; - } - // ADFA-5074: unfinished work only. This read a merely registered session, so a - // download that had already completed and was waiting to be dismissed refused the - // next one with "something else is downloading" while nothing was — and the only - // way out was force-stopping the app, because these are process statics. - // Serialising exists because each stream measures free space at its own moment; - // one that has finished has already been absorbed by the disk. - if (org.iiab.controller.system.data.PendingContent.anyUnfinished(ctx)) { - Log.d(TAG, "kolibri drain blocked: a content stream still has work to do"); - return false; - } - return true; + return org.iiab.controller.system.data.ContentAdmission.canStart(ctx, "kolibri"); } /** diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/BooksProvisioner.java b/controller/app/src/main/java/org/iiab/controller/redesign/BooksProvisioner.java index 74abf91ae..c7685431d 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/BooksProvisioner.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/BooksProvisioner.java @@ -37,24 +37,9 @@ public static boolean hasPending(Context ctx) { /** Hand the wishlist to BooksDownloadService (requires the server to be up) and clear it. * No-op if empty or a session is already running. */ public static void drain(Context ctx) { - // ADFA-4900: proot (runrole) and REST downloads must not run at the same time — Ansible forks - // background processes and concurrent REST work is a recipe for corruption. Defer REST while a - // module-queue (proot) job is pending or running; a later drain pass picks it up once idle. - if (org.iiab.controller.install.presentation.ModuleQueueRepository.get().isRunning() - || MapsProvisioner.hasPending(ctx) - || DashboardRebuildService.isRunning()) { // ADFA-5333: a live dashboard update restarts dash-node - Log.d(TAG, "books drain deferred: proot (runrole) or dashboard-update work is in flight"); - return; - } - // ADFA-4954 (ADR-4954 D8): the live REST streams also serialize against each other. - // Each measures free space independently and at a different moment, so all of them can - // pass their own check and jointly fill the disk. A Kolibri channel runs to tens of GB. - // ADFA-5074: asked in one place, and about unfinished work rather than a registered - // session — see ZimProvisioner for why. - if (org.iiab.controller.system.data.PendingContent.anyUnfinished(ctx)) { - Log.d(TAG, "books drain deferred: a content stream still has work to do"); - return; - } + // The deferral rule (proot in flight, another stream unfinished) is one source, shared with + // ZIM and Kolibri — see ContentAdmission for why each check is there. + if (!org.iiab.controller.system.data.ContentAdmission.canStart(ctx, "books")) return; JSONArray order = BooksWishlist.all(ctx); Log.i(TAG, "books drain: " + order.length() + " in wishlist"); List ids = new ArrayList<>(), titles = new ArrayList<>(), urls = new ArrayList<>(); diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ZimProvisioner.java b/controller/app/src/main/java/org/iiab/controller/redesign/ZimProvisioner.java index 4fcc48bd3..27094f1b4 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/ZimProvisioner.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ZimProvisioner.java @@ -38,26 +38,9 @@ public static boolean hasPending(Context ctx) { /** Resolve the wishlist against the offline catalog and hand it to ZimDownloadService. * No-op if empty or a session is already running. Requires the server to be up. */ public static void drain(Context ctx) { - // ADFA-4900: proot (runrole) and REST downloads must not run concurrently (Ansible forks - // background processes; concurrent REST work risks corruption). Defer ZIM while a module-queue - // (proot) job is pending or running; a later drain pass runs it once proot is idle. - if (org.iiab.controller.install.presentation.ModuleQueueRepository.get().isRunning() - || MapsProvisioner.hasPending(ctx) - || DashboardRebuildService.isRunning()) { // ADFA-5333: a live dashboard update restarts dash-node - Log.d(TAG, "zim drain deferred: proot (runrole) or dashboard-update work is in flight"); - return; - } - // ADFA-4954 (ADR-4954 D8): the live REST streams also serialize against each other. - // Each measures free space independently and at a different moment, so all of them can - // pass their own check and jointly fill the disk. A Kolibri channel runs to tens of GB. - // ADFA-5074: asked in one place, and about unfinished work rather than a registered - // session — a finished stream has already been absorbed by the disk, and blocking on - // it refused downloads with nothing running. Also means a fourth content type is one - // line in ContentType instead of an edit here. - if (org.iiab.controller.system.data.PendingContent.anyUnfinished(ctx)) { - Log.d(TAG, "zim drain deferred: a content stream still has work to do"); - return; - } + // The deferral rule (proot in flight, another stream unfinished) is one source, shared with + // Books and Kolibri — see ContentAdmission for why each check is there. + if (!org.iiab.controller.system.data.ContentAdmission.canStart(ctx, "zim")) return; if (ZimWishlist.size(ctx) == 0) return; final Context app = ctx.getApplicationContext(); Log.i(TAG, "zim drain: " + ZimWishlist.size(app) + " in wishlist; loading catalog"); diff --git a/controller/app/src/main/java/org/iiab/controller/system/data/ContentAdmission.java b/controller/app/src/main/java/org/iiab/controller/system/data/ContentAdmission.java new file mode 100644 index 000000000..89dd396c9 --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/system/data/ContentAdmission.java @@ -0,0 +1,74 @@ +/* + * ============================================================================ + * Name : ContentAdmission.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : The one answer to "may a REST content stream start right now?". Books, ZIM and + * Kolibri each carried an identical copy of this rule; a fourth stream would have + * carried a fourth. Behaviour is unchanged — the checks, their order and the reasons + * are the ones the three copies already applied. + * ============================================================================ + */ +package org.iiab.controller.system.data; + +import android.content.Context; +import android.util.Log; + +import org.iiab.controller.install.presentation.ModuleQueueRepository; +import org.iiab.controller.redesign.DashboardRebuildService; +import org.iiab.controller.redesign.MapsProvisioner; + +/** + * Admission for the live REST content streams (Books, ZIM, Kolibri channels). + * + *

The rule lives here rather than being restated at each call site — that is how the four + * {@code *Wizard} booleans went wrong. It answers for the streams that the box downloads over REST; + * the proot operations (a module runrole, maps) have their own, different gate, and deliberately do + * not share this one: they are what this rule defers to. + * + *

Two deferrals, for different reasons: + *

+ * + *

ADFA-5074: the second check asks about unfinished work, not about a registered + * session. Reading a merely registered session refused the next download while nothing was running + * — a stream that had already completed and was waiting to be dismissed still said no, and the only + * way out was force-stopping the app, because these are process statics. A finished stream has + * already been absorbed by the disk. It also means a fourth content type is one line in + * {@code ContentType} instead of an edit here. + * + *

Deferred is not a failure: callers leave the order banked and the next pass picks it up. + */ +public final class ContentAdmission { + + private static final String TAG = "K2Go-Provision"; + + private ContentAdmission() {} + + /** + * True when a REST content stream may start now. + * + * @param stream the caller's own name ("books", "zim", "kolibri"), used only so the deferral + * reads in logcat the way it did when each provisioner logged for itself + */ + public static boolean canStart(Context ctx, String stream) { + if (ModuleQueueRepository.get().isRunning() + || MapsProvisioner.hasPending(ctx) + || DashboardRebuildService.isRunning()) { + Log.d(TAG, stream + " drain deferred: proot (runrole) or dashboard-update work is in flight"); + return false; + } + if (PendingContent.anyUnfinished(ctx)) { + Log.d(TAG, stream + " drain deferred: a content stream still has work to do"); + return false; + } + return true; + } +} From ff83f151a3c1f8a45eefaacaac96ce55e819885f Mon Sep 17 00:00:00 2001 From: Luis-ADFA Date: Tue, 1 Sep 2026 04:09:12 -0600 Subject: [PATCH 2/2] ADFA-5364 refactor(content): the admission gate asks by ContentType, not by name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review follow-up on the collapse. The shared rule took the stream's name as a free string, so the three callers carried three literals of an identity that system/domain/ContentType already owns — the same drift its own javadoc was written about. It now takes the type: the log output is byte-identical (key() is "books" / "zim" / "kolibri"), the signature carries the execution class that says which types this gate is even about (MAPS is STOPPED — not a caller here but one of the things this rule defers to), and a fifth content type needs no edit in this class. Also drops the MapsProvisioner import KolibriProvisioner no longer uses — it only ever served the rule that moved out, and an unused import is a lint warning, not an error, so it would have landed. --- .../kolibri/presentation/KolibriProvisioner.java | 3 +-- .../iiab/controller/redesign/BooksProvisioner.java | 2 +- .../iiab/controller/redesign/ZimProvisioner.java | 2 +- .../controller/system/data/ContentAdmission.java | 14 +++++++++----- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriProvisioner.java b/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriProvisioner.java index 78fac82b1..569c161c9 100644 --- a/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriProvisioner.java +++ b/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriProvisioner.java @@ -16,7 +16,6 @@ import android.util.Log; import org.iiab.controller.kolibri.data.KolibriWishlist; -import org.iiab.controller.redesign.MapsProvisioner; import org.json.JSONArray; import org.json.JSONObject; @@ -58,7 +57,7 @@ public static boolean hasPending(Context ctx) { * this javadoc always gave — that is how the four {@code *Wizard} booleans went wrong. */ static boolean canDrainNow(Context ctx) { - return org.iiab.controller.system.data.ContentAdmission.canStart(ctx, "kolibri"); + return org.iiab.controller.system.data.ContentAdmission.canStart(ctx, org.iiab.controller.system.domain.ContentType.COURSES); } /** diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/BooksProvisioner.java b/controller/app/src/main/java/org/iiab/controller/redesign/BooksProvisioner.java index c7685431d..878c51e19 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/BooksProvisioner.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/BooksProvisioner.java @@ -39,7 +39,7 @@ public static boolean hasPending(Context ctx) { public static void drain(Context ctx) { // The deferral rule (proot in flight, another stream unfinished) is one source, shared with // ZIM and Kolibri — see ContentAdmission for why each check is there. - if (!org.iiab.controller.system.data.ContentAdmission.canStart(ctx, "books")) return; + if (!org.iiab.controller.system.data.ContentAdmission.canStart(ctx, org.iiab.controller.system.domain.ContentType.BOOKS)) return; JSONArray order = BooksWishlist.all(ctx); Log.i(TAG, "books drain: " + order.length() + " in wishlist"); List ids = new ArrayList<>(), titles = new ArrayList<>(), urls = new ArrayList<>(); diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ZimProvisioner.java b/controller/app/src/main/java/org/iiab/controller/redesign/ZimProvisioner.java index 27094f1b4..ca7c40557 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/ZimProvisioner.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ZimProvisioner.java @@ -40,7 +40,7 @@ public static boolean hasPending(Context ctx) { public static void drain(Context ctx) { // The deferral rule (proot in flight, another stream unfinished) is one source, shared with // Books and Kolibri — see ContentAdmission for why each check is there. - if (!org.iiab.controller.system.data.ContentAdmission.canStart(ctx, "zim")) return; + if (!org.iiab.controller.system.data.ContentAdmission.canStart(ctx, org.iiab.controller.system.domain.ContentType.ZIM)) return; if (ZimWishlist.size(ctx) == 0) return; final Context app = ctx.getApplicationContext(); Log.i(TAG, "zim drain: " + ZimWishlist.size(app) + " in wishlist; loading catalog"); diff --git a/controller/app/src/main/java/org/iiab/controller/system/data/ContentAdmission.java b/controller/app/src/main/java/org/iiab/controller/system/data/ContentAdmission.java index 89dd396c9..be49ab6a0 100644 --- a/controller/app/src/main/java/org/iiab/controller/system/data/ContentAdmission.java +++ b/controller/app/src/main/java/org/iiab/controller/system/data/ContentAdmission.java @@ -17,6 +17,7 @@ import org.iiab.controller.install.presentation.ModuleQueueRepository; import org.iiab.controller.redesign.DashboardRebuildService; import org.iiab.controller.redesign.MapsProvisioner; +import org.iiab.controller.system.domain.ContentType; /** * Admission for the live REST content streams (Books, ZIM, Kolibri channels). @@ -55,18 +56,21 @@ private ContentAdmission() {} /** * True when a REST content stream may start now. * - * @param stream the caller's own name ("books", "zim", "kolibri"), used only so the deferral - * reads in logcat the way it did when each provisioner logged for itself + * @param stream the asking stream. A {@link ContentType} rather than its name: the type already + * owns that identity ({@code key()} is what the logs, the progress rows and the + * operations all use), and it carries the execution class that says which types + * this gate is even about — {@code MAPS} is {@code STOPPED}, so it is not a caller + * here but one of the things this rule defers to. */ - public static boolean canStart(Context ctx, String stream) { + public static boolean canStart(Context ctx, ContentType stream) { if (ModuleQueueRepository.get().isRunning() || MapsProvisioner.hasPending(ctx) || DashboardRebuildService.isRunning()) { - Log.d(TAG, stream + " drain deferred: proot (runrole) or dashboard-update work is in flight"); + Log.d(TAG, stream.key() + " drain deferred: proot (runrole) or dashboard-update work is in flight"); return false; } if (PendingContent.anyUnfinished(ctx)) { - Log.d(TAG, stream + " drain deferred: a content stream still has work to do"); + Log.d(TAG, stream.key() + " drain deferred: a content stream still has work to do"); return false; } return true;