diff --git a/CLAUDE.md b/CLAUDE.md index 7bbb540fb..0b1e7dd60 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -334,6 +334,24 @@ One source per fact: the app ABI and the installed library's ABI (ADR-K2GO-571). (`DeepOpService`), backup identity + name (`BackupEngine`), 64-bit-only module gate (`ModuleCards.runsOn`), fresh-install arch (`SystemStateEvaluator.termuxArch`). +**Standard flow (K2GO-593): proot module install progress and download** +Maps (K2GO-394) and Forgejo use it; a new proot module follows it. + +- `install/domain/`: `ModuleDownloadProgress` (the download bar state), `DownloadHold` (hold a box + download on mobile data with no consent or with Keep offline; reuses `NetworkPolicy`), + `ForgejoBinaryPin` (the version pin of one run). Pure JVM, unit-tested. +- `install/presentation/`: `ModuleDownload` owns one dash-node download job (start, pause, resume, + cancel, hold; "who stopped it" lives only here). `ModuleDownloadRepository` is the one source of + the download bar; `ModuleQueueRepository` stays the one source of the install bar. + `InstallService.postModuleStart` is the one rule: a role with a task table starts at 0% before its + download, so both bars show. +- `redesign/ModuleProgressPanel` + `view_k2go_module_progress`: install bar over download card, the + same on every install screen; it keeps no state. +- dash-node: the download runs before `pdsm stop` (the stop also stops dash-node); the box resolves + the URL and checks the file (`sockets/forgejo-bin.exec.ts`). +- A new module with a download: a dash-node job type, a pre-download step in `InstallService`, a + task table in `assets/runrole/`, and the panel in its screen. + **Legacy (NOT yet layered)**: the redesign retired the original god classes `MainActivity` and `DeployFragment` (they no longer exist; DONE-slice seams above that still name them are pre-redesign records). The current god-tier classes, diff --git a/controller/app/src/main/assets/runrole/forgejo.txt b/controller/app/src/main/assets/runrole/forgejo.txt new file mode 100644 index 000000000..fa7d1e591 --- /dev/null +++ b/controller/app/src/main/assets/runrole/forgejo.txt @@ -0,0 +1,47 @@ +Assert that "forgejo_install is sameas true" (boolean not string etc) +Assert that "forgejo_enabled | type_debug == 'bool'" (boolean not string etc) +Install Forgejo if 'forgejo_installed' not defined, e.g. in /etc/iiab/iiab_state.yml +Assert forgejo_db_engine is a supported value ('sqlite' or 'mariadb') +Query Codeberg for the latest Forgejo release +Set forgejo_version from the latest release tag +Assert forgejo_version is a valid X.Y.Z release +Record (initial) disk space used +Stop existing Forgejo systemd service (if reinstalling, not proot) +Stop existing Forgejo via pdsm (if reinstalling, proot) +Ensure group 'forgejo' exists +Create user 'forgejo' +Create /library/forgejo directory structure +Make directories data, log, backups writable (0750) +Check whether Forgejo is already installed (app.ini present) +Detect the existing install's DB engine (engine-change guard) +Refuse an unsupported DB engine change on an existing install +Compute a backup timestamp (proot-safe, no fact dependency) +Back up Forgejo (forgejo dump) to /library/forgejo/backups before swapping the binary +Fail if we detect an unsupported CPU architecture +Verify the downloaded Forgejo binary against its GPG signature (fail closed) +Find installed Forgejo binaries in /library/forgejo/bin +mkdir /etc/forgejo (0770 root:forgejo) +Generate Forgejo secrets once (guarded by 'creates'), referenced by *_URI in app.ini +Secure the generated secret files (0640 root:forgejo) +Set 'mysql_install: True' and 'mysql_enabled: True' +MYSQL - run 'mysql' role +FAIL (STOP THE INSTALL) IF 'mysql_installed is undefined' +Create MySQL database for Forgejo: forgejo +Create MySQL username (forgejo) with password, for above database +Install /etc/forgejo/app.ini from template (0664 root:forgejo) +Install systemd unit /etc/systemd/system/forgejo.service (not proot) +Record (final) disk space used +Set 'forgejo_installed: True' +Add 'forgejo_installed: True' to /etc/iiab/iiab_state.yml +Enable/Disable Forgejo (systemd or pdsm) and NGINX +Enable & Restart 'forgejo' systemd service, if forgejo_enabled (not proot) +Disable & Stop 'forgejo' systemd service, if not forgejo_enabled (not proot) +Enable 'forgejo' via pdsm (proot) +Restart 'forgejo' via pdsm (proot) +Stop 'forgejo' via pdsm (proot) +Disable 'forgejo' via pdsm (proot) +Enable http://box/forgejo via NGINX, by installing /etc/nginx/conf.d/forgejo-nginx.conf from template +Disable http://box/forgejo via NGINX, by removing /etc/nginx/conf.d/forgejo-nginx.conf +Reload 'nginx' systemd service (not proot) +Restart 'nginx' via pdsm (proot) +Add 'forgejo' variable values to /etc/iiab/iiab.ini diff --git a/controller/app/src/main/java/org/appdevforall/k2go/dependency/domain/DashNodeRequirement.java b/controller/app/src/main/java/org/appdevforall/k2go/dependency/domain/DashNodeRequirement.java index e7ac18dfb..fca3598db 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/dependency/domain/DashNodeRequirement.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/dependency/domain/DashNodeRequirement.java @@ -7,9 +7,9 @@ * and the box read live elsewhere (redesign.DashboardVersion), so this stays a plain, * unit-testable registry with no Android or network dependency. * - * Forgejo needs the dashboard build that ships its repo status/refresh endpoints (1.3.7): - * an older dash-node makes "Install repos"/"Update repos" and the seed break silently, so - * installing Forgejo is HARD-blocked below that version. Code on the Go add-ons (K2GO-99) + * Forgejo needs the dashboard build that ships its repo status/refresh endpoints (1.3.7) + * and the forgejo-bin download job (1.6.5, K2GO-593): an older dash-node breaks the + * install, so installing Forgejo is HARD-blocked below that version. Code on the Go add-ons (K2GO-99) * needs the dashboard build that ships the /addons/refresh endpoints (1.3.8), so the gallery * can update, so it is HARD-blocked below that version too. Other modules have no hard minimum * (a soft "update the dashboard" suggestion applies to all installs, handled in the gate). @@ -25,7 +25,8 @@ private DashNodeRequirement() {} /** {major, minor, patch} minimum dash-node for {@code moduleKey}, or null when it has no hard minimum. */ @Nullable public static int[] minFor(@Nullable String moduleKey) { - if ("forgejo".equals(moduleKey)) return new int[]{1, 3, 7}; + // K2GO-593: 1.6.5 has the forgejo-bin job, which downloads the binary before the install. + if ("forgejo".equals(moduleKey)) return new int[]{1, 6, 5}; if ("code_addons".equals(moduleKey)) return new int[]{1, 3, 8}; // K2GO-99: needs /addons/refresh // K2GO-437: code_assets install (runrole) and browsing (WebView) do NOT use the dash-node // refresh endpoints; only the "Update build assets" action does, and it degrades gracefully diff --git a/controller/app/src/main/java/org/appdevforall/k2go/install/domain/DownloadHold.java b/controller/app/src/main/java/org/appdevforall/k2go/install/domain/DownloadHold.java new file mode 100644 index 000000000..96c5312e8 --- /dev/null +++ b/controller/app/src/main/java/org/appdevforall/k2go/install/domain/DownloadHold.java @@ -0,0 +1,66 @@ +/* + * ============================================================================ + * Name : DownloadHold.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : K2GO-593. When the app must stop a module download on the box + * because of the network, and when it may continue it. Pure JVM. + * ============================================================================ + */ +package org.appdevforall.k2go.install.domain; + +import org.appdevforall.k2go.networkpolicy.domain.NetworkClass; +import org.appdevforall.k2go.networkpolicy.domain.NetworkPolicy; +import org.appdevforall.k2go.networkpolicy.domain.NetworkPolicyDecision; + +/** + * The box downloads on the phone's default network, and its aria2 retry loop continues on mobile + * data after a Wi-Fi drop, with no question (seen on a Samsung A16 with 4G). The start gate + * (NetworkPolicyGate) asks only at the start. This rule is the in-flight half: hold the download while + * the network may not be used, and continue it when it may. + * + *

A pause by the user is the user's decision: a network event never continues it, and this rule + * never holds it again. No network at all is not a hold: the box reconnects on its own, and there is + * no traffic to stop. + */ +public final class DownloadHold { + + private DownloadHold() {} + + /** Who stopped the download, if somebody did. */ + public enum StoppedBy { NOBODY, USER, NETWORK } + + /** Why the download is held. */ + public enum Reason { METERED_NO_CONSENT, KEPT_OFFLINE } + + /** What the caller does now. */ + public enum Action { NONE, HOLD, CONTINUE } + + /** + * @param net cost class of the default network now + * @param meteredConsent the user allowed mobile data for this session + * @param onlineAllowed the user allows module installs to connect (online, or allowed this time) + * @param stoppedBy who stopped the download, if somebody did + */ + public static Action decide(NetworkClass net, boolean meteredConsent, boolean onlineAllowed, + StoppedBy stoppedBy) { + if (stoppedBy == StoppedBy.USER || net == NetworkClass.NONE) return Action.NONE; + boolean mayRun = reason(net, meteredConsent, onlineAllowed) == null; + if (stoppedBy == StoppedBy.NOBODY) return mayRun ? Action.NONE : Action.HOLD; + return mayRun ? Action.CONTINUE : Action.NONE; + } + + /** + * Why the network may not be used now, or null when it may. The mobile data rule is the start + * gate's own rule (NetworkPolicy), so the start and the in-flight check cannot disagree. + */ + public static Reason reason(NetworkClass net, boolean meteredConsent, boolean onlineAllowed) { + if (!onlineAllowed) return Reason.KEPT_OFFLINE; + if (POLICY.decideHeavyStart(net, meteredConsent) == NetworkPolicyDecision.NEEDS_CONSENT) { + return Reason.METERED_NO_CONSENT; + } + return null; + } + + private static final NetworkPolicy POLICY = new NetworkPolicy(); +} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/install/domain/ForgejoBinaryPin.java b/controller/app/src/main/java/org/appdevforall/k2go/install/domain/ForgejoBinaryPin.java new file mode 100644 index 000000000..0e8a6ad61 --- /dev/null +++ b/controller/app/src/main/java/org/appdevforall/k2go/install/domain/ForgejoBinaryPin.java @@ -0,0 +1,81 @@ +/* + * ============================================================================ + * Name : ForgejoBinaryPin.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : K2GO-593. The local_vars line that makes the forgejo role use + * the binary that dash-node downloaded. Pure JVM. + * ============================================================================ + */ +package org.appdevforall.k2go.install.domain; + +/** + * dash-node downloads the Forgejo binary to {@code /library/forgejo/bin/forgejo-} (job type + * {@code forgejo-bin}). The role resolves {@code forgejo_version: latest} on its own, so the app pins + * the version that dash-node got, and the role's get_url finds the file and skips its download. The + * role then still checks the GPG signature of the file. + * + *

The pin is for this one run: a later update must resolve the newest release again. So the line + * carries a marker, and {@link #UNPIN} removes only the marked line, never a pin the owner wrote. + * The version comes from the box, and it goes into a root shell command, so it is checked here first. + */ +public final class ForgejoBinaryPin { + + private ForgejoBinaryPin() {} + + /** The module that owns this download. */ + public static final String MODULE = "forgejo"; + /** The dash-node job type. */ + public static final String JOB_TYPE = "forgejo-bin"; + + private static final String MARKER = "# k2go-forgejo-bin"; + private static final String LOCAL_VARS = "/etc/iiab/local_vars.yml"; + + /** Removes the marked pin. Safe to run when there is none. */ + public static final String UNPIN = "sed -i '/" + MARKER + "$/d' " + LOCAL_VARS; + + /** The role's assert: X.Y.Z. */ + public static boolean isVersion(String v) { + return v != null && v.matches("[0-9]+\\.[0-9]+\\.[0-9]+"); + } + + /** + * The forgejo_version that the owner wrote in local_vars (a line without the marker), or null when + * there is none or it is "latest". With an owner pin the app does not download: the role + * downloads the version the owner chose, as before. + */ + public static String ownerPin(java.util.List localVarsLines) { + if (localVarsLines == null) return null; + String pin = null; + for (String raw : localVarsLines) { + if (raw == null || raw.trim().endsWith(MARKER)) continue; + java.util.regex.Matcher m = OWNER_LINE.matcher(raw); + if (m.matches()) pin = m.group(1); // the last one wins, as in YAML + } + return pin == null || "latest".equals(pin) ? null : pin; + } + + private static final java.util.regex.Pattern OWNER_LINE = java.util.regex.Pattern.compile( + "^forgejo_version[ \\t]*:[ \\t]*[\"']?([^\"'#\\s]+)[\"']?[ \\t]*(#.*)?$"); + + /** + * The batch order with Forgejo first. Its download runs before the server stop, while its row + * already runs, so a module before it in the list would look done. The others keep their order. + */ + public static String[] downloadFirst(String[] modules) { + if (modules == null) return null; + java.util.List out = new java.util.ArrayList<>(modules.length); + for (String m : modules) if (MODULE.equals(m)) out.add(m); + for (String m : modules) if (!MODULE.equals(m)) out.add(m); + return out.toArray(new String[0]); + } + + /** + * The shell command that pins {@code version}, or null when the version is not X.Y.Z. A pin that a + * killed run left is removed first, so there is never more than one marked line. + */ + public static String pinCommand(String version) { + if (!isVersion(version)) return null; + return UNPIN + " && echo 'forgejo_version: \"" + version + "\" " + MARKER + "' >> " + LOCAL_VARS; + } +} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/install/domain/ModuleDownloadProgress.java b/controller/app/src/main/java/org/appdevforall/k2go/install/domain/ModuleDownloadProgress.java new file mode 100644 index 000000000..11668d456 --- /dev/null +++ b/controller/app/src/main/java/org/appdevforall/k2go/install/domain/ModuleDownloadProgress.java @@ -0,0 +1,115 @@ +/* + * ============================================================================ + * Name : ModuleDownloadProgress.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : K2GO-394, K2GO-593. The download that a module install does + * through dash-node before its role (maps base maps, the Forgejo + * binary), as the download bar needs it. Pure JVM. + * ============================================================================ + */ +package org.appdevforall.k2go.install.domain; + +/** + * A snapshot of a module's download for the download bar. The download runs as a dash-node job, so + * this is built from the REST poll fields ({@code RestContentClient.Listener}): a phase, a percent, a + * speed token, the time left and the reconnect counter. The rule for "which phase" lives here, not in + * the UI. + */ +public final class ModuleDownloadProgress { + + /** + * The states the download bar shows. RECONNECTING is a network drop that the box rides out. HELD + * is a stop that the app made because the network may not be used now (mobile data with no + * consent, or Keep offline); it continues on Wi-Fi or after the user allows it. + */ + public enum Phase { NONE, ACTIVE, PAUSED, HELD, RECONNECTING, COMPLETE } + + public final Phase phase; + /** The module key that owns the download ("maps", "forgejo"), or null for NONE. */ + public final String module; + /** 0..100, or -1 when not known yet. */ + public final int percent; + /** Display token for the rate WITHOUT the per-second suffix (e.g. "3.4 MB"); the UI appends "/s". */ + public final String speed; + /** Seconds left, or -1 when not known. */ + public final long etaSeconds; + /** Reconnect counter for "Reconnecting n of N"; both 0 when not reconnecting. */ + public final int reconnectAttempt; + public final int reconnectTotal; + /** Why the download is HELD; null in the other phases. */ + public final DownloadHold.Reason holdReason; + + private ModuleDownloadProgress(Phase phase, String module, int percent, String speed, long eta, + int attempt, int total, DownloadHold.Reason holdReason) { + this.phase = phase; + this.module = module; + this.percent = percent < 0 ? -1 : Math.min(100, percent); + this.speed = speed != null ? speed : ""; + this.etaSeconds = eta < 0 ? -1 : eta; + this.reconnectAttempt = Math.max(0, attempt); + this.reconnectTotal = Math.max(0, total); + this.holdReason = holdReason; + } + + /** Nothing is downloading: before the job starts, or after it ends. */ + public static ModuleDownloadProgress none() { + return new ModuleDownloadProgress(Phase.NONE, null, -1, "", -1, 0, 0, null); + } + + /** A live download at {@code percent} moving at {@code speed} (a display token, no "/s"). */ + public static ModuleDownloadProgress active(String module, int percent, String speed, long etaSeconds) { + return new ModuleDownloadProgress(Phase.ACTIVE, module, percent, speed, etaSeconds, 0, 0, null); + } + + /** The user paused the download; the partial is kept and Resume continues from it. */ + public static ModuleDownloadProgress paused(String module, int percent) { + return new ModuleDownloadProgress(Phase.PAUSED, module, percent, "", -1, 0, 0, null); + } + + /** The app stopped the download for {@code reason}; the partial is kept. */ + public static ModuleDownloadProgress held(String module, int percent, DownloadHold.Reason reason) { + return new ModuleDownloadProgress(Phase.HELD, module, percent, "", -1, 0, 0, reason); + } + + /** The box lost the network and reconnects (attempt n of total), keeping the partial. */ + public static ModuleDownloadProgress reconnecting(String module, int attempt, int total) { + return new ModuleDownloadProgress(Phase.RECONNECTING, module, -1, "", -1, attempt, total, null); + } + + /** The download finished. */ + public static ModuleDownloadProgress complete(String module) { + return new ModuleDownloadProgress(Phase.COMPLETE, module, 100, "", 0, 0, 0, null); + } + + public boolean isActive() { + return phase == Phase.ACTIVE; + } + + public boolean isPaused() { + return phase == Phase.PAUSED; + } + + public boolean isHeld() { + return phase == Phase.HELD; + } + + public boolean isReconnecting() { + return phase == Phase.RECONNECTING; + } + + public boolean isComplete() { + return phase == Phase.COMPLETE; + } + + /** Whether there is a download to show a bar for (active, paused, held or reconnecting). */ + public boolean isRunning() { + return phase == Phase.ACTIVE || phase == Phase.PAUSED || phase == Phase.HELD + || phase == Phase.RECONNECTING; + } + + /** Whether this snapshot is the download of {@code moduleKey}. */ + public boolean isFor(String moduleKey) { + return module != null && module.equals(moduleKey); + } +} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/InstallService.java b/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/InstallService.java index a459d7177..89320f473 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/InstallService.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/InstallService.java @@ -47,6 +47,7 @@ import org.appdevforall.k2go.download.domain.DownloadRetryPolicy; import org.appdevforall.k2go.install.data.InstallStateStore; import org.appdevforall.k2go.install.domain.AnsibleRunOutcome; +import org.appdevforall.k2go.install.domain.ForgejoBinaryPin; import org.appdevforall.k2go.sync.transport.NetworkStateLiveData; import java.io.BufferedReader; @@ -206,9 +207,12 @@ public final class InstallService extends Service { private static String sRetryMapsVector, sRetryMapsSat, sRetryMapsTerrain; private static boolean sRetryMapsSearch; private boolean mapsSearchOn; - // K2GO-394: the base-map download client for the maps module (dash-node "basemaps" job). Held so - // the UI's Pause/Resume/Cancel reach the in-flight download; null when nothing is downloading. - private volatile org.appdevforall.k2go.content.RestContentClient mapsClient; + // K2GO-394, K2GO-593: the module download through dash-node (maps base maps, the Forgejo binary). + // Held so the UI's Pause/Resume/Cancel reach it; null when nothing downloads. + private volatile ModuleDownload moduleDownload; + // K2GO-593: the Forgejo version that dash-node downloaded, which the forgejo runrole pins. "" when + // the download did not give one (the role then downloads by itself); null before the download. + private volatile String forgejoPinVersion; private File iiabRootDir; // filesDir/rootfs private File debianRootfs; // filesDir/rootfs/installed-rootfs/iiab @@ -238,6 +242,9 @@ public void onCreate() { */ private void onValidatedNetworkReturned() { if (finished || cancelled) return; + // K2GO-593: a module download holds on mobile data with no consent and continues on Wi-Fi. + ModuleDownload md = moduleDownload; + if (md != null) md.evaluate(); // K2GO-394: the maps base-map download is NOT driven from here -- dash-node owns its transport // resilience (its "basemaps" job re-runs aria2 with --continue and reports "Reconnecting n/5"), // the same self-healing path as ZIMs. The app just polls it. The manual Pause/Resume button @@ -332,6 +339,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { // recreation (theme toggle / rotation) and can never launch two concurrent runroles. String[] mods = intent.getStringArrayExtra(EXTRA_MODULES); moduleQueue = new java.util.ArrayDeque<>(); + forgejoPinVersion = null; // K2GO-593: each batch downloads (or finds) the binary again if (mods != null) { for (String m : mods) if (m != null && !m.isEmpty()) moduleQueue.add(m); } @@ -865,6 +873,18 @@ private void runModuleQueue() { boolean anyRealModule = false; for (String m : moduleQueue) if (!"maps".equals(m)) { anyRealModule = true; break; } if (!anyRealModule) { installNextModule(); return; } + // K2GO-593: pdsm stop also stops dash-node, so its download must end before the stop. + if (moduleQueue.contains(ForgejoBinaryPin.MODULE) && forgejoPinVersion == null) { + String ownerPin = ForgejoBinaryPin.ownerPin(readLocalVars()); + if (ownerPin != null) { + // The owner chose a version: the role downloads that one, as before. + log("[forgejo] local_vars pins forgejo_version " + ownerPin + "; the role downloads the binary"); + forgejoPinVersion = ""; + } else { + downloadForgejoBinaryThen(this::runModuleQueue); + return; + } + } updateNotification(getString(R.string.server_shutting_down)); log("[Modules] Stopping server services before runroles (exclusive rootfs)..."); if (prootEngine == null) prootEngine = new PRootEngine(); @@ -939,18 +959,22 @@ private void installNextModule() { final long startMs = System.currentTimeMillis(); final int remainingSnapshot = moduleQueue.size(); final int[] lastPct = { Integer.MIN_VALUE }; - if (progress.hasTable()) { - ModuleQueueRepository.get().postRunning(nextModule, remainingSnapshot, 0); - } + if (progress.hasTable()) postModuleStart(nextModule, remainingSnapshot, true); // ADFA-4900: for the wizard maps flow, write the full per-layer maps_* var set before // runrole (the generic _install/_enabled echo can't express quality/off/search). - final String runroleCmd = ("maps".equals(nextModule) && hasMapsConfig) + final String plainCmd = ("maps".equals(nextModule) && hasMapsConfig) ? mapsInstallCmd() : "sed -i -E '/^[[:space:]]*" + nextModule + "_(install|enabled)[[:space:]]*:/d' /etc/iiab/local_vars.yml && " + "echo '" + nextModule + "_install: True' >> /etc/iiab/local_vars.yml && " + "echo '" + nextModule + "_enabled: True' >> /etc/iiab/local_vars.yml && " + "cd /opt/iiab/iiab && ./runrole " + roleName; + // K2GO-593: pin the version that dash-node downloaded, for this run only, so the role uses that + // file. pinCommand is null for a version that is not X.Y.Z: then the role downloads by itself. + final String pin = ForgejoBinaryPin.MODULE.equals(nextModule) + ? ForgejoBinaryPin.pinCommand(forgejoPinVersion) : null; + final String runroleCmd = pin == null ? plainCmd + : pin + " && " + plainCmd + " ; rc=$? ; " + ForgejoBinaryPin.UNPIN + " ; exit $rc"; // K2GO-464: refresh the stale rootfs apt index before the runrole, or a pinned dep 404s as the // box ages. Best-effort (short timeout, || true) so an offline/local-only install still runs. // K2GO-593: a Cancel SIGKILLs the runrole, also during dpkg; finish any interrupted dpkg first. @@ -1077,8 +1101,9 @@ private void revertModuleInLocalVars(String module, Runnable then) { String revertCmd = "sed -i -E '/^[[:space:]]*" + module + "_(install|enabled)[[:space:]]*:/d' /etc/iiab/local_vars.yml && " + "echo '" + module + "_install: False' >> /etc/iiab/local_vars.yml && " + "echo '" + module + "_enabled: False' >> /etc/iiab/local_vars.yml ; " + - // K2GO-593: a killed runrole leaves its task dirs (a partial download) behind. - "rm -rf /root/.ansible/tmp/ansible-tmp-*"; + // K2GO-593: a killed runrole leaves its task dirs (a partial download) behind, and + // the forgejo version pin of that run. + "rm -rf /root/.ansible/tmp/ansible-tmp-* ; " + ForgejoBinaryPin.UNPIN; prootEngine.executeInContainer(this, debianRootfs.getAbsolutePath(), revertCmd, new PRootEngine.OutputListener() { @Override public void onOutputLine(String line) { } @Override public void onProcessExit(int exitCode) { then.run(); } @@ -1274,35 +1299,16 @@ private void downloadMapsBasemapsThenRun(String module, Runnable onReady) { } log("[maps] downloading " + ids.size() + " base-map file(s) via dash-node: " + android.text.TextUtils.join(", ", ids)); - final org.appdevforall.k2go.content.RestContentClient client = - new org.appdevforall.k2go.content.RestContentClient("basemaps"); - mapsClient = client; - client.start(body, new org.appdevforall.k2go.content.RestContentClient.Listener() { - @Override public void onProgress(int percent, String speed) { - org.appdevforall.k2go.maps.presentation.MapsDownloadRepository.get().post( - org.appdevforall.k2go.maps.domain.MapsDownloadProgress.active(percent, speed)); - } - @Override public void onReconnecting(int attempt, int total) { - org.appdevforall.k2go.maps.presentation.MapsDownloadRepository.get().post( - org.appdevforall.k2go.maps.domain.MapsDownloadProgress.reconnecting(attempt, total)); - } - @Override public void onPaused(int percent) { - org.appdevforall.k2go.maps.presentation.MapsDownloadRepository.get().post( - org.appdevforall.k2go.maps.domain.MapsDownloadProgress.paused(percent)); - } - @Override public void onIndexing() { /* base maps have no index phase */ } - @Override public void onLog(String line) { log("[maps-dl] " + line); } - @Override public void onDone() { - mapsClient = null; - org.appdevforall.k2go.maps.presentation.MapsDownloadRepository.get().clear(); + moduleDownload = new ModuleDownload(this, module, "basemaps", body, new ModuleDownload.Callback() { + @Override public void onDone(org.json.JSONObject result) { + moduleDownload = null; if (cancelled) return; log("[maps] base-map download complete; running the role"); // Keep the runrole off the poll's main-thread callback (it reads assets / prefs). org.appdevforall.k2go.util.AppExecutors.get().io().execute(onReady); } @Override public void onError(String message) { - mapsClient = null; - org.appdevforall.k2go.maps.presentation.MapsDownloadRepository.get().clear(); + moduleDownload = null; if (cancelled) return; failedModules.add(module); log("[Install] FAILED: " + module + " base-map download (" + message + ")"); @@ -1312,7 +1318,81 @@ private void downloadMapsBasemapsThenRun(String module, Runnable onReady) { org.appdevforall.k2go.util.AppExecutors.get().io().execute( () -> revertModuleInLocalVars(module, InstallService.this::finishModuleQueue)); } - }); + }, this::log); + moduleDownload.start(); + } + + /** + * K2GO-593: the one rule for the install bar when a module starts, before its download (if it has + * one) and before its role. A role with a task table starts the bar at 0%, so the install bar and + * the download card show together (the maps pattern, K2GO-394); with no table the module runs with + * no percent. The bar then moves only from the role's task stream. + */ + private void postModuleStart(String module, int remaining, boolean hasTaskTable) { + if (hasTaskTable) ModuleQueueRepository.get().postRunning(module, remaining, 0); + else ModuleQueueRepository.get().postRunning(module, remaining); + } + + /** The lines of the box's local_vars.yml, or an empty list when it cannot be read. */ + private java.util.List readLocalVars() { + // Not java.nio.file: it is API 26, and minSdk is 24. + java.util.List lines = new java.util.ArrayList<>(); + try (BufferedReader r = new BufferedReader(new InputStreamReader(new java.io.FileInputStream( + new File(debianRootfs, "etc/iiab/local_vars.yml")), java.nio.charset.StandardCharsets.UTF_8))) { + String line; + while ((line = r.readLine()) != null) lines.add(line); + } catch (Exception e) { + return java.util.Collections.emptyList(); + } + return lines; + } + + /** + * K2GO-593: download the Forgejo binary through dash-node (job "forgejo-bin") while the server is + * still up, then run {@code then}. The box resolves the version and writes the file where the role + * looks for it; the forgejo runrole pins that version, so its get_url skips the download and its GPG + * check verifies the file. A failed download fails only Forgejo (Retry is offered) and the other + * modules of the batch still install. No local_vars edit was made yet, so nothing is reverted. + */ + private void downloadForgejoBinaryThen(Runnable then) { + final String module = ForgejoBinaryPin.MODULE; + org.json.JSONObject body; + try { + body = new org.json.JSONObject().put("ids", new org.json.JSONArray().put(module)); + } catch (org.json.JSONException e) { + throw new IllegalStateException(e); // a literal body cannot fail + } + log("[forgejo] downloading the Forgejo binary via dash-node before the install"); + // The download is part of the Forgejo install: its row runs, opens the card, and can cancel. + postModuleStart(module, Math.max(0, moduleQueue.size() - 1), + !RunroleTables.tasksFor(this, org.appdevforall.k2go.deploy.domain.RoleNames.roleFor(module)).isEmpty()); + moduleDownload = new ModuleDownload(this, module, ForgejoBinaryPin.JOB_TYPE, body, new ModuleDownload.Callback() { + @Override public void onDone(org.json.JSONObject result) { + moduleDownload = null; + if (cancelled) return; + String version = result != null ? result.optString("version", "") : ""; + if (ForgejoBinaryPin.isVersion(version)) { + log("[forgejo] binary " + version + " is ready; the role uses it"); + } else { + log("[forgejo] WARNING: no valid version from the box; the role downloads the binary"); + version = ""; + } + forgejoPinVersion = version; + org.appdevforall.k2go.util.AppExecutors.get().io().execute(then); + } + @Override public void onError(String message) { + moduleDownload = null; + if (cancelled) return; + log("[Install] FAILED: " + module + " download (" + message + ")"); + failedModules.add(module); + org.appdevforall.k2go.analytics.AnalyticsClient.with(InstallService.this).logModuleInstall(module, false); + moduleQueue.remove(module); + persistQueue(); + forgejoPinVersion = ""; + org.appdevforall.k2go.util.AppExecutors.get().io().execute(then); + } + }, this::log); + moduleDownload.start(); } /** @@ -1466,12 +1546,11 @@ private String formatEta(int bucket) { */ private void doPause() { if (finished || cancelled) return; - // K2GO-394: a maps base-map download pauses through dash-node (the "basemaps" job), not the - // rootfs aria2 the checks below govern. The poll reflects the paused state on the download bar. - org.appdevforall.k2go.content.RestContentClient pauseClient = mapsClient; - if (pauseClient != null) { - log("[maps] pause requested"); - pauseClient.pause(); + // K2GO-394, K2GO-593: a module download pauses through dash-node, not the rootfs aria2 that the + // checks below govern. + ModuleDownload pauseDownload = moduleDownload; + if (pauseDownload != null) { + pauseDownload.pause(); return; } if (!InstallProgressRepository.get().current().isRunning()) return; @@ -1645,11 +1724,10 @@ private static int softFailLine(org.appdevforall.k2go.download.domain.Aria2Exit. */ private void doResume() { if (finished || cancelled) return; - // K2GO-394: resume a maps download through dash-node (aria2 --continue picks up the partial). - org.appdevforall.k2go.content.RestContentClient resumeClient = mapsClient; - if (resumeClient != null) { - log("[maps] resume requested"); - resumeClient.resume(); + // K2GO-394, K2GO-593: resume a module download through dash-node (aria2 --continue). + ModuleDownload resumeDownload = moduleDownload; + if (resumeDownload != null) { + resumeDownload.resume(); return; } if (!InstallProgressRepository.get().current().isHeld()) return; @@ -1711,7 +1789,11 @@ private void doCancel() { // server was pdsm-stopped for the runroles) is not raced by teardown's later clear. // K2GO-593: during pdsm stop no module is current yet; the cancel stops the first one. final String running = ModuleQueueRepository.get().current().currentModule; - final String cur = running != null ? running : (moduleQueue != null ? moduleQueue.peek() : null); + // K2GO-593: a cancel during the download before the stop cancels the module that downloads. + final ModuleDownload downloading = moduleDownload; + final String cur = running != null ? running + : downloading != null ? downloading.module() + : (moduleQueue != null ? moduleQueue.peek() : null); stopModuleStallWatch(); // ADFA-4898 P4 // K2GO-593: SIGKILL, not SIGTERM. On SIGTERM proot stayed up and the runrole kept downloading. if (prootEngine != null) prootEngine.forceKill(); @@ -1842,10 +1924,10 @@ private void teardown(boolean clearMarker) { // ADFA-5119: nothing to wait for once this is over — neither the window nor a queued attempt. cancelHeldWindow(); cancelPendingRetry(); - // K2GO-394: cancel an in-flight base-map download and clear its bar. - org.appdevforall.k2go.content.RestContentClient mc = mapsClient; - if (mc != null) { mc.cancel(); mapsClient = null; } - org.appdevforall.k2go.maps.presentation.MapsDownloadRepository.get().clear(); + // K2GO-394, K2GO-593: cancel an in-flight module download (the box removes its partial). + ModuleDownload md = moduleDownload; + if (md != null) { md.cancel(); moduleDownload = null; } + ModuleDownloadRepository.get().clear(); if (clearMarker) { org.appdevforall.k2go.InstallGuard.end(this); } else { diff --git a/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/ModuleDownload.java b/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/ModuleDownload.java new file mode 100644 index 000000000..df7b14c41 --- /dev/null +++ b/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/ModuleDownload.java @@ -0,0 +1,248 @@ +/* + * ============================================================================ + * Name : ModuleDownload.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : K2GO-394, K2GO-593. One module download through a dash-node job + * (maps base maps, the Forgejo binary): start, pause, resume, + * cancel, the hold on mobile data, and the download bar state. + * ============================================================================ + */ +package org.appdevforall.k2go.install.presentation; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import org.appdevforall.k2go.content.RestContentClient; +import org.appdevforall.k2go.install.domain.DownloadHold; +import org.appdevforall.k2go.install.domain.ModuleDownloadProgress; +import org.appdevforall.k2go.networkpolicy.data.AndroidNetworkClassifier; +import org.appdevforall.k2go.networkpolicy.data.OnlineAllowance; +import org.appdevforall.k2go.networkpolicy.data.SessionMeteredConsentStore; +import org.json.JSONObject; + +/** + * Owns one dash-node download job for {@link InstallService}: the REST client, who stopped it, and the + * download bar ({@link ModuleDownloadRepository}). The box owns the transfer (aria2, resume, + * "Reconnecting n/5"); this class only adds what the box cannot know: whether the phone's network may + * be used now ({@link DownloadHold}). + * + *

"Who stopped it" is the one fact that only the app has: dash-node shows a user pause and a hold + * the same way ('paused'). It lives here, for the life of this download, and nowhere else. The process + * dies with the service that owns this object, and the next run re-attaches to the job + * (RestContentClient) and resumes a paused job that nobody here stopped. + * + *

All methods are synchronized: the poll and the network callback run on the main thread, the + * start runs on the queue thread. + */ +public final class ModuleDownload { + + interface Callback { + /** The job finished. {@code result} is the job's result, or null. Runs on the main thread. */ + void onDone(@Nullable JSONObject result); + + /** The job failed or was canceled on the box. Runs on the main thread. */ + void onError(@NonNull String message); + } + + private final Context app; + private final String module; + private final String jobType; + private final JSONObject body; + private final Callback callback; + private final LogSink logSink; + + interface LogSink { void log(String line); } + + private RestContentClient client; // null until the job starts + private DownloadHold.StoppedBy stoppedBy = DownloadHold.StoppedBy.NOBODY; + private boolean ended; + private int lastPercent = -1; + private String lastDetail; + + ModuleDownload(@NonNull Context ctx, @NonNull String module, @NonNull String jobType, + @NonNull JSONObject body, @NonNull Callback callback, @NonNull LogSink logSink) { + this.app = ctx.getApplicationContext(); + this.module = module; + this.jobType = jobType; + this.body = body; + this.callback = callback; + this.logSink = logSink; + } + + /** The OnlineAllowance kind of a module: maps is a content kind (K2GO-588), the rest are modules. */ + public static String allowanceKind(String module) { + return "maps".equals(module) + ? org.appdevforall.k2go.system.domain.ContentType.MAPS.key() + : OnlineAllowance.MODULES; + } + + String module() { + return module; + } + + /** Start the job, or hold it before the start when the network may not be used now. */ + synchronized void start() { + if (ended) return; + DownloadHold.Reason why = holdReason(); + if (why != null && AndroidNetworkClassifier.classify(app) + != org.appdevforall.k2go.networkpolicy.domain.NetworkClass.NONE) { + hold(why); + return; + } + begin(); + } + + /** The user paused. */ + synchronized void pause() { + if (ended) return; + stoppedBy = DownloadHold.StoppedBy.USER; + if (client != null) client.pause(); + ModuleDownloadRepository.get().post(ModuleDownloadProgress.paused(module, lastPercent)); + logSink.log("[" + module + "-dl] paused by the user"); + } + + /** + * The user resumed, or allowed the network on a hold. A hold that is still true stays held: the + * card shows why, and its button gives the consent. + */ + synchronized void resume() { + if (ended) return; + DownloadHold.Reason why = holdReason(); + if (why != null) { + stoppedBy = DownloadHold.StoppedBy.NETWORK; + ModuleDownloadProgress cur = ModuleDownloadRepository.get().current(); + if (!(cur.isHeld() && cur.holdReason == why)) hold(why); + return; + } + stoppedBy = DownloadHold.StoppedBy.NOBODY; + logSink.log("[" + module + "-dl] resumed"); + if (client == null) { + begin(); + } else { + client.resume(); + ModuleDownloadRepository.get().post(ModuleDownloadProgress.active(module, lastPercent, "", -1)); + } + } + + /** The network or the privacy choice changed: hold or continue as {@link DownloadHold} says. */ + synchronized void evaluate() { + if (ended) return; + DownloadHold.Action a = DownloadHold.decide(AndroidNetworkClassifier.classify(app), + SessionMeteredConsentStore.get().isGranted(), onlineAllowed(), stoppedBy); + if (a == DownloadHold.Action.HOLD) { + DownloadHold.Reason why = holdReason(); + if (why != null) hold(why); + } else if (a == DownloadHold.Action.CONTINUE) { + stoppedBy = DownloadHold.StoppedBy.NOBODY; + logSink.log("[" + module + "-dl] the network may be used again; continuing"); + if (client == null) begin(); else client.resume(); + } + } + + /** Stop the job and remove its partial (the box does that on a cancel). */ + synchronized void cancel() { + if (ended) return; + ended = true; + if (client != null) client.cancel(); + ModuleDownloadRepository.get().clear(); + } + + private void hold(DownloadHold.Reason why) { + stoppedBy = DownloadHold.StoppedBy.NETWORK; + if (client != null) client.pause(); + ModuleDownloadRepository.get().post(ModuleDownloadProgress.held(module, lastPercent, why)); + logSink.log("[" + module + "-dl] held: " + why); + } + + @Nullable + private DownloadHold.Reason holdReason() { + return DownloadHold.reason(AndroidNetworkClassifier.classify(app), + SessionMeteredConsentStore.get().isGranted(), onlineAllowed()); + } + + private boolean onlineAllowed() { + return OnlineAllowance.allows(app, allowanceKind(module)); + } + + private void begin() { + ModuleDownloadRepository.get().post(ModuleDownloadProgress.active(module, -1, "", -1)); + client = new RestContentClient(jobType); + client.start(body, new RestContentClient.Listener() { + @Override public void onProgress(int percent, String speed) { onProgress(percent, speed, -1L); } + + @Override public void onProgress(int percent, String speed, long etaSeconds) { + synchronized (ModuleDownload.this) { + if (ended) return; + lastPercent = percent; + if (stoppedBy == DownloadHold.StoppedBy.NOBODY) { + ModuleDownloadRepository.get().post( + ModuleDownloadProgress.active(module, percent, speed, etaSeconds)); + } + } + evaluate(); + } + + @Override public void onReconnecting(int attempt, int total) { + synchronized (ModuleDownload.this) { + if (ended) return; + if (stoppedBy == DownloadHold.StoppedBy.NOBODY) { + ModuleDownloadRepository.get().post( + ModuleDownloadProgress.reconnecting(module, attempt, total)); + } + } + evaluate(); + } + + @Override public void onPaused(int percent) { + synchronized (ModuleDownload.this) { + if (ended) return; + // The box's percent at the stop: the bar showed the last poll before it. + int before = lastPercent; + if (percent >= 0) lastPercent = percent; + ModuleDownloadProgress cur = ModuleDownloadRepository.get().current(); + if (stoppedBy == DownloadHold.StoppedBy.NOBODY) { + // A paused job that nobody here stopped: a job from an earlier run that this + // run re-attached to, or the poll before a resume took effect: continue. + if (holdReason() == null) client.resume(); else hold(holdReason()); + } else if (lastPercent != before && (cur.isPaused() || cur.isHeld())) { + ModuleDownloadRepository.get().post(cur.isPaused() + ? ModuleDownloadProgress.paused(module, lastPercent) + : ModuleDownloadProgress.held(module, lastPercent, cur.holdReason)); + } + } + } + + @Override public void onIndexing() { } + + @Override public void onLog(String line) { + // The poll repeats the job detail every second: log it only when it changes. + if (line.equals(lastDetail)) return; + lastDetail = line; + logSink.log("[" + module + "-dl] " + line); + } + + @Override public void onDone() { onDone(null); } + + @Override public void onDone(JSONObject result) { + synchronized (ModuleDownload.this) { + if (ended) return; + ended = true; + } + ModuleDownloadRepository.get().clear(); + callback.onDone(result); + } + + @Override public void onError(String message) { + synchronized (ModuleDownload.this) { + if (ended) return; + ended = true; + } + ModuleDownloadRepository.get().clear(); + callback.onError(message); + } + }); + } +} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/ModuleDownloadRepository.java b/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/ModuleDownloadRepository.java new file mode 100644 index 000000000..89e96ddc4 --- /dev/null +++ b/controller/app/src/main/java/org/appdevforall/k2go/install/presentation/ModuleDownloadRepository.java @@ -0,0 +1,63 @@ +/* + * ============================================================================ + * Name : ModuleDownloadRepository.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : K2GO-394, K2GO-593. The one place where the progress of a + * module's download lives, so the install screens observe it. + * ============================================================================ + */ +package org.appdevforall.k2go.install.presentation; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; + +import org.appdevforall.k2go.install.domain.ModuleDownloadProgress; + +/** + * The download bar's single source. {@link ModuleDownload} writes it from the dash-node poll; the + * install screens observe it beside {@code ModuleQueueRepository} (the phase spine). One writer, so no + * second place makes up a download percent. It is {@link ModuleDownloadProgress#none()} when no + * module downloads, so a module with no download shows only its phase. + */ +public final class ModuleDownloadRepository { + + private static final ModuleDownloadRepository INSTANCE = new ModuleDownloadRepository(); + + private final MutableLiveData state = + new MutableLiveData<>(ModuleDownloadProgress.none()); + // postValue is applied later on the main thread; current() must see the last write at once. + private volatile ModuleDownloadProgress last = ModuleDownloadProgress.none(); + + private ModuleDownloadRepository() { + } + + public static ModuleDownloadRepository get() { + return INSTANCE; + } + + public LiveData state() { + return state; + } + + public ModuleDownloadProgress current() { + return last; + } + + /** Whether {@code module} has a download in progress now (active, paused, held or reconnecting). */ + public boolean isDownloading(String module) { + ModuleDownloadProgress p = last; + return p.isRunning() && p.isFor(module); + } + + /** Post a new snapshot. postValue, because the writers run on the main and on worker threads. */ + public void post(ModuleDownloadProgress p) { + last = p != null ? p : ModuleDownloadProgress.none(); + state.postValue(last); + } + + /** Back to "nothing downloads": when the download ends, and on teardown. */ + public void clear() { + post(ModuleDownloadProgress.none()); + } +} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/maps/domain/MapsDownloadProgress.java b/controller/app/src/main/java/org/appdevforall/k2go/maps/domain/MapsDownloadProgress.java deleted file mode 100644 index ab9444775..000000000 --- a/controller/app/src/main/java/org/appdevforall/k2go/maps/domain/MapsDownloadProgress.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ============================================================================ - * Name : MapsDownloadProgress.java - * Author : AppDevForAll - * Copyright : Copyright (c) 2026 AppDevForAll - * Description : K2GO-394. One base-map download's progress, as the subordinate - * download bar needs it, built from the dash-node REST poll - * (RestContentClient). Pure JVM, no Android, no JSON framework. - * ============================================================================ - */ -package org.appdevforall.k2go.maps.domain; - -/** - * A snapshot of the base-map download for the subordinate bar. The base maps are downloaded through - * dash-node's durable job engine (the same path as ZIMs), so this is built from the REST poll fields - * ({@code RestContentClient.Listener}) -- a phase, a percent, a speed token, and the reconnect counter - * -- not from aria2's raw RPC. The rule for "which phase" lives in one testable place, not in the UI. - */ -public final class MapsDownloadProgress { - - /** The states the download bar distinguishes. RECONNECTING is a network drop the server rides out. */ - public enum Phase { NONE, ACTIVE, PAUSED, RECONNECTING, COMPLETE } - - public final Phase phase; - /** 0..100, or -1 when not known yet (queued / no percent reported). */ - public final int percent; - /** Display token for the rate WITHOUT the per-second suffix (e.g. "3.4 MB"); the UI appends "/s". */ - public final String speed; - /** Reconnect counter for "Reconnecting n of N"; both 0 when not reconnecting. */ - public final int reconnectAttempt; - public final int reconnectTotal; - - private MapsDownloadProgress(Phase phase, int percent, String speed, int attempt, int total) { - this.phase = phase; - this.percent = percent < 0 ? -1 : Math.min(100, percent); - this.speed = speed != null ? speed : ""; - this.reconnectAttempt = Math.max(0, attempt); - this.reconnectTotal = Math.max(0, total); - } - - /** Nothing is downloading right now -- before the job starts, or after it finishes/clears. */ - public static MapsDownloadProgress none() { - return new MapsDownloadProgress(Phase.NONE, -1, "", 0, 0); - } - - /** A live download at {@code percent} moving at {@code speed} (a display token, no "/s"). */ - public static MapsDownloadProgress active(int percent, String speed) { - return new MapsDownloadProgress(Phase.ACTIVE, percent, speed, 0, 0); - } - - /** The user paused the download; the partial is kept and resume continues from it. */ - public static MapsDownloadProgress paused(int percent) { - return new MapsDownloadProgress(Phase.PAUSED, percent, "", 0, 0); - } - - /** The server lost the network and is reconnecting (attempt n of total), keeping the partial. */ - public static MapsDownloadProgress reconnecting(int attempt, int total) { - return new MapsDownloadProgress(Phase.RECONNECTING, -1, "", attempt, total); - } - - /** The download finished. */ - public static MapsDownloadProgress complete() { - return new MapsDownloadProgress(Phase.COMPLETE, 100, "", 0, 0); - } - - public boolean isActive() { - return phase == Phase.ACTIVE; - } - - public boolean isPaused() { - return phase == Phase.PAUSED; - } - - public boolean isReconnecting() { - return phase == Phase.RECONNECTING; - } - - public boolean isComplete() { - return phase == Phase.COMPLETE; - } - - /** Whether there is a live download to show a bar for (active, paused, or reconnecting). */ - public boolean isRunning() { - return phase == Phase.ACTIVE || phase == Phase.PAUSED || phase == Phase.RECONNECTING; - } -} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/maps/presentation/MapsDownloadRepository.java b/controller/app/src/main/java/org/appdevforall/k2go/maps/presentation/MapsDownloadRepository.java deleted file mode 100644 index 2fe764dc9..000000000 --- a/controller/app/src/main/java/org/appdevforall/k2go/maps/presentation/MapsDownloadRepository.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * ============================================================================ - * Name : MapsDownloadRepository.java - * Author : AppDevForAll - * Copyright : Copyright (c) 2026 AppDevForAll - * Description : K2GO-394. The one place the maps download progress lives, so the - * install-progress UI observes it instead of polling aria2 itself. - * ============================================================================ - */ -package org.appdevforall.k2go.maps.presentation; - -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; - -import org.appdevforall.k2go.maps.domain.MapsDownloadProgress; - -/** - * The subordinate download bar's single source (K2GO-394). {@code InstallService} writes it from the - * dash-node poll ({@code RestContentClient.Listener} for the "basemaps" job); the progress screen - * observes it beside {@code ModuleQueueRepository} (the phase spine). One writer, so there is no - * second place inventing a download percent. - * - *

Starts and resets to {@link MapsDownloadProgress#none()} -- the honest "nothing to show", which - * is also what a non-maps module leaves it at, so the UI simply shows the phase-only Variant 3. - */ -public final class MapsDownloadRepository { - - private static final MapsDownloadRepository INSTANCE = new MapsDownloadRepository(); - - private final MutableLiveData state = - new MutableLiveData<>(MapsDownloadProgress.none()); - - private MapsDownloadRepository() { - } - - public static MapsDownloadRepository get() { - return INSTANCE; - } - - public LiveData state() { - return state; - } - - public MapsDownloadProgress current() { - MapsDownloadProgress v = state.getValue(); - return v != null ? v : MapsDownloadProgress.none(); - } - - /** - * Post a new snapshot. {@code postValue} on purpose: the poll listener delivers on the main thread - * but InstallService clears from its background install thread, so the write must be thread-safe. - */ - public void post(MapsDownloadProgress p) { - state.postValue(p != null ? p : MapsDownloadProgress.none()); - } - - /** Clear back to "nothing downloading" -- on teardown, or when the download finishes. */ - public void clear() { - state.postValue(MapsDownloadProgress.none()); - } -} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/redesign/DownloadCard.java b/controller/app/src/main/java/org/appdevforall/k2go/redesign/DownloadCard.java new file mode 100644 index 000000000..448377a67 --- /dev/null +++ b/controller/app/src/main/java/org/appdevforall/k2go/redesign/DownloadCard.java @@ -0,0 +1,145 @@ +/* + * ============================================================================ + * Name : DownloadCard.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : K2GO-394, K2GO-593. Binds the shared download card + * (view_k2go_download_card) of a module install to + * ModuleDownloadRepository: percent, speed, time left, + * Pause/Resume, "Reconnecting n of 5", and the hold on mobile data. + * ============================================================================ + */ +package org.appdevforall.k2go.redesign; + +import android.content.Context; +import android.content.Intent; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; +import androidx.lifecycle.LifecycleOwner; + +import com.google.android.material.progressindicator.LinearProgressIndicator; + +import org.appdevforall.k2go.R; +import org.appdevforall.k2go.install.domain.DownloadHold; +import org.appdevforall.k2go.install.domain.ModuleDownloadProgress; +import org.appdevforall.k2go.install.presentation.EtaText; +import org.appdevforall.k2go.install.presentation.InstallService; +import org.appdevforall.k2go.install.presentation.ModuleDownload; +import org.appdevforall.k2go.install.presentation.ModuleDownloadRepository; +import org.appdevforall.k2go.networkpolicy.data.OnlineAllowance; +import org.appdevforall.k2go.networkpolicy.data.SessionMeteredConsentStore; + +/** + * The download half of {@link ModuleProgressPanel}. It only renders {@link ModuleDownloadRepository} for + * one module and sends the user's taps to {@link InstallService}; it keeps no download state of its own. + */ +final class DownloadCard { + + private final Context ctx; + private final String module; + private final View card; + private final LinearProgressIndicator bar; + private final TextView pct, rate, note; + private final Button pause, allow; + + /** + * @param root a view that contains view_k2go_download_card + * @param module the module key whose download this card shows + * @param titleRes the card title + */ + DownloadCard(@NonNull View root, @NonNull String module, @StringRes int titleRes) { + this.ctx = root.getContext(); + this.module = module; + card = root.findViewById(R.id.k2go_dl_card); + ((TextView) root.findViewById(R.id.k2go_dl_title)).setText(titleRes); + bar = root.findViewById(R.id.k2go_dl_bar); + pct = root.findViewById(R.id.k2go_dl_pct); + rate = root.findViewById(R.id.k2go_dl_rate); + note = root.findViewById(R.id.k2go_dl_note); + pause = root.findViewById(R.id.k2go_dl_pause); + allow = root.findViewById(R.id.k2go_dl_allow); + pause.setOnClickListener(v -> send(isStopped(current()) + ? InstallService.ACTION_RESUME : InstallService.ACTION_PAUSE)); + allow.setOnClickListener(v -> allowNetwork()); + } + + /** Observe the download for the life of {@code owner}. */ + void observe(@NonNull LifecycleOwner owner) { + ModuleDownloadRepository.get().state().observe(owner, this::render); + } + + private ModuleDownloadProgress current() { + return ModuleDownloadRepository.get().current(); + } + + private static boolean isStopped(ModuleDownloadProgress p) { + return p.isPaused() || p.isHeld(); + } + + private void render(ModuleDownloadProgress p) { + boolean shown = p != null && p.isRunning() && p.isFor(module); + card.setVisibility(shown ? View.VISIBLE : View.GONE); + if (!shown) return; + + note.setVisibility(p.isHeld() ? View.VISIBLE : View.GONE); + allow.setVisibility(p.isHeld() ? View.VISIBLE : View.GONE); + pause.setVisibility(p.isHeld() ? View.GONE : View.VISIBLE); + if (p.isReconnecting()) { + // The box reconnects (aria2 --continue keeps the partial); the percent comes back after. + bar.setIndeterminate(true); + pct.setText(""); + rate.setText(ctx.getString(R.string.k2go_dl_attempt, p.reconnectAttempt, p.reconnectTotal)); + pause.setText(R.string.k2go_dl_pause); + return; + } + bar.setIndeterminate(p.percent < 0); + if (p.percent >= 0) bar.setProgressCompat(p.percent, true); + pct.setText(p.percent >= 0 ? ctx.getString(R.string.dash_format_pct, p.percent) : ""); + if (p.isHeld()) { + boolean metered = p.holdReason == DownloadHold.Reason.METERED_NO_CONSENT; + rate.setText(R.string.k2go_mod_phase_queued); + note.setText(metered ? R.string.k2go_dl_held_metered : R.string.k2go_dl_held_offline); + allow.setText(metered ? R.string.k2go_netpolicy_continue : R.string.k2go_offline_action_allow_once); + return; + } + if (p.isPaused()) { + rate.setText(R.string.k2go_dl_paused); + pause.setText(R.string.k2go_dl_resume); + return; + } + pause.setText(R.string.k2go_dl_pause); + if (p.speed.isEmpty()) { + rate.setText(""); + } else if (p.etaSeconds >= 0) { + rate.setText(ctx.getString(R.string.k2go_dl_speed_eta, p.speed, EtaText.of(ctx, p.etaSeconds))); + } else { + rate.setText(ctx.getString(R.string.k2go_dl_speed, p.speed)); + } + } + + /** + * The tap is the user's consent, for this session only, the same as the start gate gives: mobile + * data (SessionMeteredConsentStore) or, with Keep offline, this kind of install + * (OnlineAllowance). Then the service continues; if a second reason remains, the card shows it. + */ + private void allowNetwork() { + ModuleDownloadProgress p = current(); + if (!p.isHeld()) return; + if (p.holdReason == DownloadHold.Reason.METERED_NO_CONSENT) { + SessionMeteredConsentStore.get().grant(); + } else { + OnlineAllowance.allow(ModuleDownload.allowanceKind(module)); + } + send(InstallService.ACTION_RESUME); + } + + private void send(String action) { + Intent i = new Intent(ctx, InstallService.class); + i.setAction(action); + ctx.startService(i); + } +} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/redesign/MapsPreparingFragment.java b/controller/app/src/main/java/org/appdevforall/k2go/redesign/MapsPreparingFragment.java index 323aa5790..76f71c7ad 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/redesign/MapsPreparingFragment.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/redesign/MapsPreparingFragment.java @@ -58,14 +58,6 @@ public static MapsPreparingFragment newInstance(boolean fromIndex) { } private TextView status; - private View progressRow; // ADFA-5228 - private com.google.android.material.progressindicator.LinearProgressIndicator progress; - private TextView progressPct, progressEta; - // K2GO-394: subordinate download card (the in-proot aria2c's live progress + Pause/Resume). - private View downloadCard; - private com.google.android.material.progressindicator.LinearProgressIndicator dlBar; - private TextView dlBytes, dlRate; - private android.widget.Button dlPause; private boolean fromIndex = false; // ADFA-4901: hosted by the Finishing-setup index (observe only) private boolean launched = false; // ADFA-4900: guard against re-launching maps on view recreation @@ -85,28 +77,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c status = root.findViewById(R.id.k2go_prep_status); status.setText(getString(R.string.k2go_maps_phase_prepared)); - progressRow = root.findViewById(R.id.k2go_prep_progress_row); // ADFA-5228 - progress = root.findViewById(R.id.k2go_prep_progress); - progressPct = root.findViewById(R.id.k2go_prep_progress_pct); - progressEta = root.findViewById(R.id.k2go_prep_progress_eta); - // K2GO-394: the subordinate download card + its Pause/Resume, fed by MapsDownloadRepository. - downloadCard = root.findViewById(R.id.k2go_prep_download); - dlBar = root.findViewById(R.id.k2go_prep_dl_bar); - dlBytes = root.findViewById(R.id.k2go_prep_dl_bytes); - dlRate = root.findViewById(R.id.k2go_prep_dl_rate); - dlPause = root.findViewById(R.id.k2go_prep_dl_pause); - dlPause.setOnClickListener(v -> { - // Toggle by the current phase: pause an active download, resume a paused one. The service - // routes ACTION_PAUSE/RESUME to the in-proot aria2c over RPC (InstallService.doPause/doResume). - boolean paused = org.appdevforall.k2go.maps.presentation.MapsDownloadRepository.get().current().isPaused(); - android.content.Intent i = new android.content.Intent(requireContext(), - org.appdevforall.k2go.install.presentation.InstallService.class); - i.setAction(paused - ? org.appdevforall.k2go.install.presentation.InstallService.ACTION_RESUME - : org.appdevforall.k2go.install.presentation.InstallService.ACTION_PAUSE); - requireContext().startService(i); - }); - // ADFA-4919: the fromIndex=false branch below is the DEPRECATED standalone Get More route // (its own "Run in background", no index, no gate). Get More now routes through the install // index (SetupLibraryActivity.openMapsIndex), so this branch is unreachable in that flow. @@ -140,16 +110,6 @@ && getActivity() instanceof SetupLibraryActivity // terminal and always wins. ModuleQueueRepository.get().state().observe(getViewLifecycleOwner(), st -> { if (st == null) return; - // ADFA-5228: determinate bar while maps installs; hidden if maps has no table (percent < 0). - if (progressRow != null) { - boolean showBar = st.phase == ModuleQueueState.Phase.RUNNING && st.percent >= 0; - progressRow.setVisibility(showBar ? View.VISIBLE : View.GONE); - if (showBar) { - progress.setProgressCompat(st.percent, true); - progressPct.setText(st.percent + "%"); - progressEta.setText(org.appdevforall.k2go.install.presentation.EtaText.of(requireContext(), st.etaSeconds)); - } - } if (st.phase == ModuleQueueState.Phase.RUNNING) { if (logLines.isEmpty()) status.setText(getString(R.string.k2go_maps_phase_building)); } else if (st.phase == ModuleQueueState.Phase.DONE) { @@ -160,10 +120,8 @@ && getActivity() instanceof SetupLibraryActivity } }); - // K2GO-394: the subordinate download bar. Present only while a live in-proot download exists - // (the RPC feed); hidden otherwise, so a stock rootfs with no RPC shows the phase spine alone. - org.appdevforall.k2go.maps.presentation.MapsDownloadRepository.get().state() - .observe(getViewLifecycleOwner(), this::renderDownload); + // K2GO-593: the standard proot install panel (install bar + base-map download card). + new ModuleProgressPanel(root, "maps", R.string.k2go_maps_dl_title).observe(getViewLifecycleOwner()); // ADFA-4901: collapsible live log. The status line mirrors the latest line; expanding shows // the full terminal (LogRepository snapshot + live appends), auto-scrolled. @@ -187,41 +145,6 @@ && getActivity() instanceof SetupLibraryActivity return root; } - /** K2GO-394: render (or hide) the subordinate download card from the dash-node progress feed. */ - private void renderDownload(org.appdevforall.k2go.maps.domain.MapsDownloadProgress p) { - if (downloadCard == null) { - return; - } - if (p == null || !p.isRunning()) { - downloadCard.setVisibility(View.GONE); - return; - } - downloadCard.setVisibility(View.VISIBLE); - // A network drop: dash-node is re-establishing (aria2 --continue). Show the attempt counter - // and an indeterminate bar; the partial is kept, so the percent will pick back up on resume. - if (p.isReconnecting()) { - dlBar.setIndeterminate(true); - dlBytes.setText(""); - dlRate.setText(getString(R.string.k2go_dl_attempt, p.reconnectAttempt, p.reconnectTotal)); - dlPause.setText(getString(R.string.k2go_dl_pause)); - return; - } - int pct = p.percent; - dlBar.setIndeterminate(pct < 0); - if (pct >= 0) { - dlBar.setProgressCompat(pct, true); - } - dlBytes.setText(pct >= 0 ? (pct + "%") : ""); - if (p.isPaused()) { - dlRate.setText(getString(R.string.k2go_dl_paused)); - dlPause.setText(getString(R.string.k2go_dl_resume)); - } else { - // The poll gives the rate as a display token ("3.4 MB"); append the per-second suffix. - dlRate.setText(p.speed.isEmpty() ? "" : p.speed + "/s"); - dlPause.setText(getString(R.string.k2go_dl_pause)); - } - } - /** K2GO-374: seed the panel's deque from the current log snapshot when it is expanded. */ private void seedLog() { logLines.clear(); diff --git a/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleInstallFragment.java b/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleInstallFragment.java index 51fbc90da..a3b91fa87 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleInstallFragment.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleInstallFragment.java @@ -47,9 +47,6 @@ public static ModuleInstallFragment newInstance(String yamlBaseKey) { private String key; private TextView status; - private View progressRow; // ADFA-5228 - private com.google.android.material.progressindicator.LinearProgressIndicator progress; - private TextView progressPct, progressEta; private org.appdevforall.k2go.widget.LiveLogPanel logPanel; // K2GO-374: shared details panel private boolean terminalDone = false; // this module reached done/failed → stop live status private final ArrayDeque logLines = new ArrayDeque<>(); @@ -66,15 +63,17 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c title.setText(c != null ? getString(c.detailTitleRes) : (key == null ? "" : key)); status = root.findViewById(R.id.k2go_modinst_status); - progressRow = root.findViewById(R.id.k2go_modinst_progress_row); // ADFA-5228 - progress = root.findViewById(R.id.k2go_modinst_progress); - progressPct = root.findViewById(R.id.k2go_modinst_progress_pct); - progressEta = root.findViewById(R.id.k2go_modinst_progress_eta); // ADFA-5074: the key is passed so a module that earns its own art can be matched. org.appdevforall.k2go.util.ProgressVisuals.applyForModule(root, key); logPanel = root.findViewById(R.id.k2go_modinst_log_panel); logPanel.setOnExpandListener(this::seedLog); // K2GO-374: seed from the snapshot on expand + // K2GO-593: the standard proot install panel (install bar + download card). + new ModuleProgressPanel(root, key == null ? "" : key, R.string.k2go_dl_program_title) + .observe(getViewLifecycleOwner()); + org.appdevforall.k2go.install.presentation.ModuleDownloadRepository.get().state() + .observe(getViewLifecycleOwner(), p -> updateStatus()); + updateStatus(); ModuleQueueRepository.get().state().observe(getViewLifecycleOwner(), st -> updateStatus()); // ADFA-4898 P4: surface a "seems stalled" hint over the frozen status line while this module is @@ -91,7 +90,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c logListener = new LogRepository.Listener() { @Override public void onAppend(String line) { if (!isAdded() || line == null) return; - if (!terminalDone && installing()) status.setText(line); + if (!terminalDone && installing() && !downloading()) status.setText(line); if (logPanel.isExpanded()) { pushLine(line); renderLog(); } } @Override public void onCleared() { @@ -104,6 +103,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c return root; } + /** True while THIS module downloads before its role (the one source: ModuleDownloadRepository). */ + private boolean downloading() { + return org.appdevforall.k2go.install.presentation.ModuleDownloadRepository.get().isDownloading(key); + } + /** True while THIS module is the one currently running. */ private boolean installing() { ModuleQueueState mq = ModuleQueueRepository.get().current(); @@ -116,18 +120,6 @@ private void updateStatus() { if (status == null || !isAdded()) return; ModuleQueueState mq = ModuleQueueRepository.get().current(); - // ADFA-5228: determinate bar above the status line while THIS module installs; hidden when - // it isn't running or has no task table (percent < 0), leaving the animation alone. - if (progressRow != null) { - boolean showBar = installing() && mq.percent >= 0; - progressRow.setVisibility(showBar ? View.VISIBLE : View.GONE); - if (showBar) { - progress.setProgressCompat(mq.percent, true); - progressPct.setText(mq.percent + "%"); - progressEta.setText(org.appdevforall.k2go.install.presentation.EtaText.of(requireContext(), mq.etaSeconds)); - } - } - // ADFA-4898: one predicate for "did this module fail" across every surface (hub pill, detail // Retry/Back, this progress line) — ModuleQueueState.didFail(key). Was hand-rolled here as // failedModules.contains(...); routed through the shared atom so the three can't drift apart. @@ -142,6 +134,13 @@ private void updateStatus() { status.setText(getString(R.string.k2go_mod_phase_done)); return; } + if (downloading()) { + org.appdevforall.k2go.install.domain.ModuleDownloadProgress dl = + org.appdevforall.k2go.install.presentation.ModuleDownloadRepository.get().current(); + status.setText(getString(dl.isHeld() ? R.string.k2go_mod_phase_queued + : dl.isPaused() ? R.string.k2go_dl_paused : R.string.k2go_mod_phase_downloading)); + return; + } if (installing()) { // ADFA-4898: a retry from this card brought the module back to RUNNING — clear the terminal // latch so the live log resumes driving the status line (it stops again on the next terminal). diff --git a/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleProgressPanel.java b/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleProgressPanel.java new file mode 100644 index 000000000..9375d2ae8 --- /dev/null +++ b/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleProgressPanel.java @@ -0,0 +1,77 @@ +/* + * ============================================================================ + * Name : ModuleProgressPanel.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : K2GO-593. The progress panel of a proot module install + * (view_k2go_module_progress): the install bar over the download + * card, the same on every install screen. + * ============================================================================ + */ +package org.appdevforall.k2go.redesign; + +import android.content.Context; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; +import androidx.lifecycle.LifecycleOwner; + +import com.google.android.material.progressindicator.LinearProgressIndicator; + +import org.appdevforall.k2go.R; +import org.appdevforall.k2go.install.presentation.EtaText; +import org.appdevforall.k2go.install.presentation.ModuleQueueRepository; +import org.appdevforall.k2go.install.presentation.ModuleQueueState; + +/** + * The standard progress of a proot module install, started with maps (K2GO-394) and Forgejo + * (K2GO-593). Two bars, each with one source, and the panel keeps no state of its own: + *

    + *
  1. The install bar: {@link ModuleQueueRepository}. It shows while the module runs and its role + * has a task table (percent >= 0). It starts at 0% before the module's download, so both bars + * show while the module downloads.
  2. + *
  3. The download card: {@code ModuleDownloadRepository}, through {@link DownloadCard}.
  4. + *
+ * A new proot module gets both by including the layout and making one panel with its key. + */ +public final class ModuleProgressPanel { + + private final Context ctx; + private final String module; + private final View installRow; + private final LinearProgressIndicator installBar; + private final TextView installPct, installEta; + private final DownloadCard downloadCard; + + /** + * @param root a view that contains view_k2go_module_progress + * @param module the module key ("maps", "forgejo") + * @param downloadTitleRes the download card title + */ + public ModuleProgressPanel(@NonNull View root, @NonNull String module, @StringRes int downloadTitleRes) { + this.ctx = root.getContext(); + this.module = module; + installRow = root.findViewById(R.id.k2go_mp_install_row); + installBar = root.findViewById(R.id.k2go_mp_install_bar); + installPct = root.findViewById(R.id.k2go_mp_install_pct); + installEta = root.findViewById(R.id.k2go_mp_install_eta); + downloadCard = new DownloadCard(root, module, downloadTitleRes); + } + + /** Observe both sources for the life of {@code owner}. */ + public void observe(@NonNull LifecycleOwner owner) { + ModuleQueueRepository.get().state().observe(owner, this::renderInstall); + downloadCard.observe(owner); + } + + private void renderInstall(ModuleQueueState mq) { + boolean show = mq != null && mq.isInstalling(module) && mq.percent >= 0; + installRow.setVisibility(show ? View.VISIBLE : View.GONE); + if (!show) return; + installBar.setProgressCompat(mq.percent, true); + installPct.setText(ctx.getString(R.string.dash_format_pct, mq.percent)); + installEta.setText(EtaText.of(ctx, mq.etaSeconds)); + } +} diff --git a/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleProvisioner.java b/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleProvisioner.java index 56ea0dd66..fa18f56d3 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleProvisioner.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleProvisioner.java @@ -96,6 +96,8 @@ public static OperationDispatcher.Dispatch drain(Context ctx) { public static void startBatch(Context ctx, String[] modules, android.os.Bundle extras) { if (ctx == null || modules == null || modules.length == 0) return; final Context app = ctx.getApplicationContext(); + // K2GO-593: Forgejo downloads before the server stop, so it is the first row of the batch. + modules = org.appdevforall.k2go.install.domain.ForgejoBinaryPin.downloadFirst(modules); ModuleBatch.save(app, modules); // K2GO-592: every Forgejo install owes its seed (admin account, org, repos), whatever screen // scheduled it. Banked before the queue starts, so the install index sees it when the batch ends. diff --git a/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleRetry.java b/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleRetry.java index f118b6d81..95039cb54 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleRetry.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleRetry.java @@ -74,9 +74,8 @@ public static void fire(View anchor, String moduleKey, @Nullable Runnable onStar final Runnable start = () -> { // K2GO-588/593: the gate let this retry connect, also "Allow only this time" with Keep // offline; record it as the start path does, so the run's download does not ask again. - org.appdevforall.k2go.networkpolicy.data.OnlineAllowance.allow("maps".equals(moduleKey) - ? org.appdevforall.k2go.system.domain.ContentType.MAPS.key() - : org.appdevforall.k2go.networkpolicy.data.OnlineAllowance.MODULES); + org.appdevforall.k2go.networkpolicy.data.OnlineAllowance.allow( + org.appdevforall.k2go.install.presentation.ModuleDownload.allowanceKind(moduleKey)); InstallService.retryModules(ctx, Collections.singletonList(moduleKey)); if (onStarted != null) onStarted.run(); }; diff --git a/controller/app/src/main/res/layout/fragment_k2go_maps_preparing.xml b/controller/app/src/main/res/layout/fragment_k2go_maps_preparing.xml index e87cd8333..0c231f097 100644 --- a/controller/app/src/main/res/layout/fragment_k2go_maps_preparing.xml +++ b/controller/app/src/main/res/layout/fragment_k2go_maps_preparing.xml @@ -36,114 +36,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -