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 @@ -29,9 +29,11 @@ public void onCreate() {
super.onCreate();
// ADFA-4640: wire up persistence for the server log (survives app restarts).
org.iiab.controller.LogRepository.get().init(this);
// ADFA-5343 (Phase 1): establish the app-scoped server-lifecycle reconciler. Log-only for now,
// fed by the status poll; it gains its own tick + WatchdogService promotion in a later phase.
org.iiab.controller.env.ServerLifecycleReconciler.get();
// ADFA-5343 (Phase 1): establish the app-scoped server-lifecycle reconciler.
// ADFA-5343 (Phase 4a): start its own background tick so it can bring the box up / re-drive a flap
// with NO foreground Activity. The tick stands down while an Activity is foregrounded (the Activity
// poll + bridge drive then); it only actuates OFF-UI when backgrounded.
org.iiab.controller.env.ServerLifecycleReconciler.get().startBackgroundTick(this);
// We inject Conscrypt as the app's primary security provider
try {
Security.insertProviderAt(Conscrypt.newProvider(), 1);
Expand Down
195 changes: 14 additions & 181 deletions controller/app/src/main/java/org/iiab/controller/ServerController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public class WatchdogService extends Service {
public static final String ACTION_STATE_STARTED = "org.iiab.controller.WATCHDOG_STARTED";
public static final String ACTION_STATE_STOPPED = "org.iiab.controller.WATCHDOG_STOPPED";

// ADFA-5343 (Phase 4b): process-scoped "is the watchdog protecting right now", so the reconciler —
// the one promoter — can edge-detect (start only when not running, stop only when running) without a
// reconciler-side flag. Resets to false if the process is recreated (START_STICKY re-delivers a start).
private static volatile boolean RUNNING = false;
public static boolean isRunning() { return RUNNING; }

// Hardware Locks
private PowerManager.WakeLock wakeLock;
private WifiManager.WifiLock wifiLock;
Expand All @@ -61,10 +67,16 @@ public int onStartCommand(Intent intent, int flags, int startId) {
}

private void startWatchdog() {
// 1. Start Foreground to prevent OOM (Out of Memory) kills
// 1. Start Foreground to prevent OOM (Out of Memory) kills. Called on EVERY start (idempotent) so a
// re-delivered / repeat ACTION_START still satisfies the startForeground() contract.
Notification notification = createNotification();
startForeground(NOTIFICATION_ID, notification);

// ADFA-5343 (Phase 4b): the reconciler may re-send ACTION_START; guard so a repeat does NOT
// re-acquire the hardware locks (that would leak the held ones). Acquire once per running session.
if (RUNNING) return;
RUNNING = true;

// 2. Acquire CPU WakeLock to prevent sleep during heavy operations (e.g., Tar extraction, Rsync)
acquireHardwareLocks();

Expand Down Expand Up @@ -106,6 +118,7 @@ private void releaseHardwareLocks() {

@Override
public void onDestroy() {
RUNNING = false; // ADFA-5343 (Phase 4b): protection is ending — clear the promoter's state signal
// 1. Notify the UI that protection is gone
Intent stopIntent = new Intent(ACTION_STATE_STOPPED);
stopIntent.setPackage(getPackageName());
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
* Description : ADFA-4957. Context-based quiescing of the Debian environment SERVICES (pdsm stop),
* extracted from ServerController so a foreground service (DeepOpService) can stop the
* environment off ANY Activity — the same deterministic pdsm command the UI path uses.
* stop() runs `pdsm stop`; callbacks fire on the PRootEngine worker thread. Booting is
* deliberately NOT here: the hosting Activity boots via ServerController.startEnvironment()
* (which shares createFakeSysData below, so the fake /proc data has a single copy).
* stop() runs `pdsm stop`; callbacks fire on the PRootEngine worker thread.
* ADFA-5343 (Phase 4): start() is now here too — the OFF-UI boot the app-scoped reconciler
* owner uses to bring the box up with no foreground Activity (the process-scoped owner the
* ADR §1.1 root cause needs). Both share createFakeSysData below, one copy of the fake /proc
* data. ServerController.doLaunchEnvironment keeps its own Activity-UI boot until the
* app-scoped actuator is device-verified (then it delegates here / is deleted).
* ============================================================================
*/
package org.iiab.controller.env;
Expand All @@ -29,6 +32,9 @@ public final class EnvironmentControl {
private static final String PATH_ENV =
"/usr/bin/env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin bash -lc ";
private static final String CMD_STOP = PATH_ENV + "'/usr/local/bin/pdsm stop'";
// ADFA-5343 (Phase 4): the persistent boot — the same command ServerController.doLaunchEnvironment
// uses (pdsm start, then `tail -f /dev/null` so the proot outlives the command and stays up).
private static final String CMD_START = PATH_ENV + "'/usr/local/bin/pdsm start && tail -f /dev/null'";

private EnvironmentControl() {}

Expand All @@ -54,6 +60,32 @@ public static void stop(Context ctx, final LineSink log, final Runnable onDone)
});
}

/**
* ADFA-5343 (Phase 4): the OFF-UI boot — bring the environment up in a fresh, app-scoped
* {@link PRootEngine} with no Activity, so the app-scoped reconciler owner can boot the box when no
* screen is foregrounded. Mirrors {@code ServerController.doLaunchEnvironment}'s launch
* (createFakeSysData + {@code pdsm start && tail -f /dev/null}) minus the Activity-UI callbacks
* (onStartupBegan / per-service progress / fusion pulse) — those belong to a foreground screen, and
* the UI observes the published phase instead.
*
* <p>The caller (the reconciler) HOLDS the returned engine — it is the process-scoped owner of the
* launch, which is the ADR §1.1 root-cause fix (the proot outlives any Activity). Runs the command on
* the PRootEngine worker thread; call after an idempotency decision (EnvironmentEnsure) so a live
* proot is never stacked.
*/
public static PRootEngine start(Context ctx, final LineSink log) {
File rootfsDir = rootfs(ctx);
createFakeSysData(rootfsDir);
PRootEngine engine = new PRootEngine();
engine.executeInContainer(ctx.getApplicationContext(), rootfsDir.getAbsolutePath(), CMD_START,
new PRootEngine.OutputListener() {
@Override public void onOutputLine(String line) { if (log != null) log.onLine("[Server] " + line); }
@Override public void onProcessExit(int exitCode) { if (log != null) log.onLine("[Server] engine exit " + exitCode); }
@Override public void onError(String error) { if (log != null) log.onLine("[Server] error " + error); }
});
return engine;
}

/**
* Writes the fake /proc files (uptime/version/stat/loadavg) the container expects. Extracted
* verbatim from ServerController.createFakeSysData; that method now delegates here so there is a
Expand Down
Loading