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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,47 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
if (lic != null) licView.setText(getString(R.string.k2go_mod_license_fmt, lic));
else licView.setVisibility(View.GONE);

// ADFA-5104: the detail offered Install now and Schedule on a module that is already
// installed. The hub stopped doing that; this screen is one tap behind it, and it is the
// louder of the two — a full-width button reads as an invitation in a way a checkbox does
// not. Both actions go, and a chip says why.
//
// Read off the main thread and applied when it returns: the buttons start hidden rather
// than start visible, because showing them and then taking them away is how a user ends
// up tapping one in the gap.
final Button installNowBtn = root.findViewById(R.id.k2go_moddet_install_now);
final ViewGroup chipRow = chips;
installNowBtn.setVisibility(View.GONE);

Button schedule = root.findViewById(R.id.k2go_moddet_schedule);
schedule.setVisibility(View.GONE);

final android.content.Context appCtx = requireContext().getApplicationContext();
org.iiab.controller.util.AppExecutors.get().io().execute(() -> {
final java.util.Set<String> onDisk =
org.iiab.controller.system.data.InstalledModulesReader.installedKeys(appCtx);
// Null is "could not read", not "nothing installed" — same distinction the hub keeps.
final boolean isInstalled = onDisk != null && onDisk.contains(c.key());
final boolean unknown = onDisk == null;
// root, not requireView(): inside onCreateView the fragment's view is not set yet,
// so requireView() would throw. root is already inflated and its handler is the
// main looper's.
root.post(() -> {
if (!isAdded()) return;
if (isInstalled) {
chipRow.addView(chip(getString(R.string.k2go_mod_phase_done), R.color.k2go_leaf));
return; // nothing to offer: a module cannot be uninstalled or reinstalled here
}
if (unknown) {
chipRow.addView(chip(getString(R.string.k2go_state_no_answer),
R.color.k2go_amber_text));
return; // no grounds to offer work either way
}
installNowBtn.setVisibility(View.VISIBLE);
if (!c.hasSelector) schedule.setVisibility(View.VISIBLE);
});
});

boolean scheduled = ModuleWishlist.contains(requireContext(), c.key());
schedule.setText(getString(scheduled ? R.string.k2go_mod_unschedule : R.string.k2go_mod_schedule));
schedule.setOnClickListener(v -> {
Expand All @@ -99,9 +139,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
requireActivity().getOnBackPressedDispatcher().onBackPressed(); // back to the hub (shows ✓)
});

if (c.hasSelector) schedule.setVisibility(View.GONE); // ADFA-4958: maps schedules via its selector, not here
// ADFA-4958: maps schedules via its selector, not here — folded into the callback above,
// which is now the only thing that makes either button visible.

Button installNow = root.findViewById(R.id.k2go_moddet_install_now);
Button installNow = installNowBtn;
installNow.setOnClickListener(v -> {
if (org.iiab.controller.env.EnvironmentLock.isHeld(requireContext())) { Snackbars.make(v, R.string.k2go_install_busy).show(); return; }
if (getActivity() instanceof SetupLibraryActivity) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* ============================================================================
* Name : InstalledModulesReader.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : ADFA-5104. Reads the installer's flags off the rootfs, with the
* box up or down. No proot, no network.
* ============================================================================
*/
package org.iiab.controller.system.data;

import android.content.Context;
import android.util.Log;

import org.iiab.controller.ModuleRegistry;
import org.iiab.controller.SystemStateEvaluator;
import org.iiab.controller.system.domain.InstalledModules;
import org.iiab.controller.system.domain.PlatformPresence;
import org.iiab.controller.util.LocalVarsYamlParser;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Set;

/**
* What is installed, read from the rootfs instead of asked over HTTP.
*
* <p>{@code etc/iiab/local_vars.yml} is a plain file inside the rootfs directory, so this is an
* ordinary file read on the host filesystem — no proot is entered and no service needs to be
* running. That is the whole reason this exists: the screens that ask "what is installed" must
* keep working with the box stopped, and until now they asked a probe, which cannot.
*
* <p><b>Invalidation is free.</b> The file lives inside the rootfs, so a reset, restore, clone or
* reinstall replaces or removes it along with everything else. There is no cache to clear and no
* destructive route that can be forgotten — the failure mode that a SharedPreferences copy of the
* same fact would have had, and does have: {@code installed_tier} is written once and cleared by
* nobody.
*
* <p><b>Not free of I/O.</b> Small file, but a file: call this off the main thread. It is cheap
* enough to call per screen and too expensive to call per row.
*/
public final class InstalledModulesReader {

private static final String TAG = "K2Go-Modules";
private static final String LOCAL_VARS = "etc/iiab/local_vars.yml";

/** Refuse to read anything absurd for this file; a real one is a few KB. */
private static final long MAX_BYTES = 512L * 1024L;

private InstalledModulesReader() {
}

/**
* The installer's flags, or {@code null} when they cannot be read.
*
* <p>Null is a distinct answer and callers must keep it distinct: no system, a system being
* laid down right now, or a rootfs we cannot read. None of those mean "nothing is installed".
*/
public static JSONObject readFlags(Context ctx) {
if (ctx == null) {
return null;
}
File file = new File(SystemStateEvaluator.rootfsDir(ctx), LOCAL_VARS);
try {
if (!file.isFile() || !file.canRead()) {
return null;
}
if (file.length() > MAX_BYTES) {
Log.w(TAG, "local_vars.yml is " + file.length() + " bytes; refusing to parse");
return null;
}
return LocalVarsYamlParser.parseToJson(readUtf8(file));
} catch (Exception e) {
// Vanished mid-read, permissions, a wipe in flight. All of them are "not established".
Log.w(TAG, "could not read local_vars.yml", e);
return null;
}
}

/**
* The file as text.
*
* <p>Plain streams rather than {@code Files.readAllBytes}: {@code java.nio.file} is API 26 and
* this app ships to 24 with no desugaring, so the tidier call would crash on the oldest
* devices we support — which are exactly the ones this product exists for.
*/
private static String readUtf8(File file) throws Exception {
try (FileInputStream in = new FileInputStream(file)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[8192];
int read;
while ((read = in.read(buf)) != -1) {
out.write(buf, 0, read);
}
return new String(out.toByteArray(), StandardCharsets.UTF_8);
}
}

/**
* Which presentable modules the flags claim are installed, or {@code null} when the flags
* could not be read at all.
*
* <p>Null rather than an empty set, and the difference is the whole point. "Nothing is
* installed" and "I could not look" are different answers, and a caller that receives the
* empty set for both will offer to install what is already there the moment the file is
* missing, unreadable or half-written — which is the defect this class exists to remove,
* reappearing one layer down. An earlier version of this method did exactly that.
*/
public static Set<String> installedKeys(Context ctx) {
JSONObject flags = readFlags(ctx);
if (flags == null) {
return null;
}
return InstalledModules.from(flags, ModuleRegistry.validYamlKeys());
}

/**
* Disk evidence for one module, ready to be weighed against a probe.
*
* <p>Disk wins where the two disagree, and the reason is in the asymmetry rather than in a
* preference: a readable file that does not carry the flag is a statement by the installer,
* while a probe that does not answer is usually a statement about the network. The probe's
* job here is to correct the one window disk cannot see — the flag is written before the
* runrole and reverted if it fails, so a process death in between leaves a claim that never
* came true.
*/
public static PlatformPresence.Evidence evidenceFor(Context ctx, String yamlBaseKey) {
return InstalledModules.evidenceFor(readFlags(ctx), yamlBaseKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* ============================================================================
* Name : InstalledModules.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : ADFA-5104. What the installer's own flags say is installed.
* Pure JVM, no Android, no I/O.
* ============================================================================
*/
package org.iiab.controller.system.domain;

import org.json.JSONObject;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
* Reads "what is installed" out of the installer's own flags, rather than out of who answers.
*
* <p><b>Why the flags and not a probe.</b> A probe answers "is this platform serving right now",
* which is a different question and a worse one for this purpose: it needs the box up, it needs
* the network stack, and it turns every kind of silence into "absent". The flags are written by
* the thing that does the installing, they live on disk, and they can be read with the box
* stopped.
*
* <p><b>Why this is allowed to be remembered.</b> A module install only ever adds. There is no
* uninstall today, so within one system's life the set can grow and cannot shrink — which is
* what makes a stored answer safe, where a stored answer about a *running* service would not be.
* The exit from that is a system replacement (reset, restore, clone, reinstall), and the flags
* handle it for free: they live inside the rootfs, so a replacement takes them with it. Nothing
* has to remember to invalidate anything.
*
* <p><b>What this is not.</b> Intention, not result — {@code InstallService} writes
* {@code <key>_install: True} before the runrole and reverts it if the run fails, so a process
* death between the two leaves a flag claiming an install that never finished. That window is
* narrow and it is why a live probe still gets to confirm or correct this. It is not a reason to
* prefer the probe: a flag that is wrong for minutes beats a probe that is wrong whenever the box
* is off.
*/
public final class InstalledModules {

/** The suffix the installer appends to a module's yaml base key. */
private static final String INSTALL_SUFFIX = "_install";

private InstalledModules() {
}

/**
* Whether the flags claim this module is installed.
*
* <p>{@code <key>_install} only. The installer also writes {@code <key>_enabled}, but that is
* a different statement — a module can be installed and switched off — and reading both would
* make "installed" mean "installed and running", which is the conflation this ticket exists to
* undo.
*
* @param flags parsed {@code local_vars.yml} flags, as {@code LocalVarsYamlParser}
* produces them; null is treated as "nothing known"
* @param yamlBaseKey the module's key in {@code local_vars.yml}, e.g. {@code calibreweb}
*/
public static boolean isInstalled(JSONObject flags, String yamlBaseKey) {
if (flags == null || yamlBaseKey == null || yamlBaseKey.isEmpty()) {
return false;
}
return flags.optBoolean(yamlBaseKey + INSTALL_SUFFIX, false);
}

/**
* The subset of {@code knownKeys} the flags claim is installed.
*
* <p>Restricted to the roster on purpose: {@code local_vars.yml} carries a flag for every
* IIAB role that exists, most of which this app does not present and cannot install. Reading
* them all would put names on screen that no card can render.
*/
public static Set<String> from(JSONObject flags, Collection<String> knownKeys) {
if (flags == null || knownKeys == null) {
return Collections.emptySet();
}
Set<String> installed = new HashSet<>();
for (String key : knownKeys) {
if (isInstalled(flags, key)) {
installed.add(key);
}
}
return installed;
}

/**
* What the flags amount to as evidence about one module.
*
* <p>The asymmetry matters and is the reason this returns {@link PlatformPresence.Evidence}
* rather than a boolean. A readable file that does not claim the module is a real
* {@code ABSENT} — the installer would have written the flag — and that is stronger than a
* 404, which only says nothing is serving that path right now. An unreadable file is
* {@code NONE}: no rootfs, or no system yet, and the caller must not read that as absence.
*
* @param flags null when the file could not be read at all
*/
public static PlatformPresence.Evidence evidenceFor(JSONObject flags, String yamlBaseKey) {
if (flags == null) {
return PlatformPresence.Evidence.NONE;
}
return isInstalled(flags, yamlBaseKey)
? PlatformPresence.Evidence.PRESENT
: PlatformPresence.Evidence.ABSENT;
}
}
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-ar/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">افتراضي</string>
<string name="k2go_auth_chip_custom">مخصص</string>
<string name="k2go_auth_chip_notinstalled">غير مثبَّت</string>
<string name="k2go_mod_needs_system">تُثبَّت الوحدات داخل نظام، ولا يوجد نظام بعد. ثبِّت نظامًا أولًا.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-az/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">Standart</string>
<string name="k2go_auth_chip_custom">Fərdi</string>
<string name="k2go_auth_chip_notinstalled">Quraşdırılmayıb</string>
<string name="k2go_mod_needs_system">Modullar sistemin içinə quraşdırılır, sistem isə hələ yoxdur. Əvvəlcə sistem quraşdırın.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-bg/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">По подразбиране</string>
<string name="k2go_auth_chip_custom">Персонализиран</string>
<string name="k2go_auth_chip_notinstalled">Не е инсталирано</string>
<string name="k2go_mod_needs_system">Модулите се инсталират в система, а такава още няма. Първо инсталирайте система.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-bn/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">ডিফল্ট</string>
<string name="k2go_auth_chip_custom">কাস্টম</string>
<string name="k2go_auth_chip_notinstalled">ইনস্টল করা নেই</string>
<string name="k2go_mod_needs_system">মডিউলগুলি একটি সিস্টেমের ভেতরে ইনস্টল হয়, আর এখনো কোনো সিস্টেম নেই। আগে একটি সিস্টেম ইনস্টল করুন।</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-cs/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">Výchozí</string>
<string name="k2go_auth_chip_custom">Vlastní</string>
<string name="k2go_auth_chip_notinstalled">Nenainstalováno</string>
<string name="k2go_mod_needs_system">Moduly se instalují do systému a ten zatím neexistuje. Nejprve nainstalujte systém.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-de/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -772,4 +772,5 @@
<string name="k2go_auth_chip_default">Standard</string>
<string name="k2go_auth_chip_custom">Eigene</string>
<string name="k2go_auth_chip_notinstalled">Nicht installiert</string>
<string name="k2go_mod_needs_system">Module werden in ein System installiert, und es gibt noch keines. Installieren Sie zuerst ein System.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-el/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -772,4 +772,5 @@
<string name="k2go_auth_chip_default">Προεπιλογή</string>
<string name="k2go_auth_chip_custom">Προσαρμοσμένο</string>
<string name="k2go_auth_chip_notinstalled">Δεν έχει εγκατασταθεί</string>
<string name="k2go_mod_needs_system">Τα αρθρώματα εγκαθίστανται μέσα σε ένα σύστημα, και δεν υπάρχει ακόμη. Εγκαταστήστε πρώτα ένα σύστημα.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-es/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">Predeterminado</string>
<string name="k2go_auth_chip_custom">Personalizado</string>
<string name="k2go_auth_chip_notinstalled">No instalado</string>
<string name="k2go_mod_needs_system">Los módulos se instalan dentro de un sistema, y todavía no hay uno. Instala primero un sistema.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-fa/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">پیش‌فرض</string>
<string name="k2go_auth_chip_custom">سفارشی</string>
<string name="k2go_auth_chip_notinstalled">نصب‌نشده</string>
<string name="k2go_mod_needs_system">ماژول‌ها درون یک سیستم نصب می‌شوند و هنوز سیستمی وجود ندارد. ابتدا یک سیستم نصب کنید.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-fr/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -781,4 +781,5 @@
<string name="k2go_auth_chip_default">Par défaut</string>
<string name="k2go_auth_chip_custom">Personnalisé</string>
<string name="k2go_auth_chip_notinstalled">Non installé</string>
<string name="k2go_mod_needs_system">Les modules s\'installent dans un système, et il n\'y en a pas encore. Installez d\'abord un système.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-gu/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">ડિફૉલ્ટ</string>
<string name="k2go_auth_chip_custom">કસ્ટમ</string>
<string name="k2go_auth_chip_notinstalled">ઇન્સ્ટૉલ થયેલ નથી</string>
<string name="k2go_mod_needs_system">મોડ્યુલ સિસ્ટમની અંદર ઇન્સ્ટોલ થાય છે, અને હજી કોઈ સિસ્ટમ નથી. પહેલાં સિસ્ટમ ઇન્સ્ટોલ કરો.</string>
</resources>
1 change: 1 addition & 0 deletions controller/app/src/main/res/values-hi/strings_k2go.xml
Original file line number Diff line number Diff line change
Expand Up @@ -771,4 +771,5 @@
<string name="k2go_auth_chip_default">डिफ़ॉल्ट</string>
<string name="k2go_auth_chip_custom">कस्टम</string>
<string name="k2go_auth_chip_notinstalled">इंस्टॉल नहीं है</string>
<string name="k2go_mod_needs_system">मॉड्यूल किसी सिस्टम के भीतर इंस्टॉल होते हैं, और अभी कोई सिस्टम नहीं है। पहले एक सिस्टम इंस्टॉल करें।</string>
</resources>
Loading
Loading