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..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; @@ -43,8 +42,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 +52,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, 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 74abf91ae..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
@@ -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, org.iiab.controller.system.domain.ContentType.BOOKS)) return;
JSONArray order = BooksWishlist.all(ctx);
Log.i(TAG, "books drain: " + order.length() + " in wishlist");
List 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 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, ContentType stream) {
+ if (ModuleQueueRepository.get().isRunning()
+ || MapsProvisioner.hasPending(ctx)
+ || DashboardRebuildService.isRunning()) {
+ 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.key() + " drain deferred: a content stream still has work to do");
+ return false;
+ }
+ return true;
+ }
+}
+ *
+ *
+ *