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 @@ -83,6 +83,7 @@ private enum Stage { JOIN, START }
private boolean cloneLockHeld = false; // ADFA-4956: this fragment holds EnvironmentLock(CLONE)
private boolean cloneGuardHeld = false; // ADFA-4956: a receive (destructive write) also set InstallGuard
private boolean shareAnyway = false; // ADFA-4786: user chose to share even with no library installed
private boolean systemPresent = true; // ADFA-5150: Send needs a system to send; refreshed on entry / onResume
// ADFA-4785: "Send the app" sub-screen (bootstrap a phone with no K2Go) — serves the APK over HTTP.
private boolean sendApp = false;
private ApkServer apkServer;
Expand Down Expand Up @@ -310,7 +311,18 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

private void setSide(Side sd) {
side = sd;
if (sd == Side.SEND) { stage = Stage.JOIN; setMode(Mode.HOTSPOT); return; } // ADFA-4785: enter Send at step 1
if (sd == Side.SEND) {
// ADFA-5150: Send shares this device's library — with no system there is nothing to send,
// the same dead surface as Connect. Refresh the fact; render() shows a no-system empty
// state (message + Recover) at the entry rather than an abrupt jump or a snackbar. Receive
// stays open: it is how you GET a system. Don't spin up the hotspot when there is nothing
// to serve. (This also covers "send the app" buried under Send — a deliberate simplification;
// a phone with a system is the natural source for both the app and the system.)
systemPresent = org.iiab.controller.SystemStateEvaluator.isSystemInstalled(requireContext());
stage = Stage.JOIN;
if (systemPresent) setMode(Mode.HOTSPOT); else render(); // ADFA-4785: enter Send at step 1
return;
}
rStage = RStage.JOIN; pasteExpanded = false;
incompatHostBits = -1; incompatWhyOpen = false; incompatTechOpen = false; // ADFA-4784: fresh on entry
render();
Expand Down Expand Up @@ -520,6 +532,10 @@ private void render() {
return;
}
receiveBox.setVisibility(View.GONE);
if (!systemPresent) { // ADFA-5150: empty state, like Connect — no system to send, offer Recover
renderNoSystemSend();
return;
}
if (sendApp) { // ADFA-4785: step 2 (Get app) — spine + step title + network selector, then the sub-view
netRow.setVisibility(View.VISIBLE); qr.setVisibility(View.GONE);
paintTab(tabHotspot, mode == Mode.HOTSPOT);
Expand Down Expand Up @@ -549,6 +565,35 @@ private void render() {
syncProtection();
}

/**
* ADFA-5150: no system, so nothing to send — the empty state Connect shows, at the entry to Send
* rather than three steps in at the old "share anyway" notice. A message plus a Recover action.
* Reuses {@code stop} as the button; the normal Send paths re-set stop, so this does not stick once
* a system exists. Reuses k2go_connect_no_system (both Send and Connect are "share your library").
*/
private void renderNoSystemSend() {
netRow.setVisibility(View.GONE);
steps.setVisibility(View.GONE);
if (stepTitle != null) stepTitle.setVisibility(View.GONE);
// Keep the QR placeholder box visible (null bitmap shows its card background), exactly as
// Connect's no-system state does — this is what makes the two screens read the same instead of
// Send looking bare and top-crammed.
qr.setImageBitmap(null); qr.setVisibility(View.VISIBLE);
caption.setVisibility(View.VISIBLE);
caption.setText(getString(R.string.k2go_connect_no_system));
subCaption.setVisibility(View.GONE);
setFallback(null); fallbackToggle.setVisibility(View.GONE);
shareCard.setVisibility(View.GONE);
sendAppEntry.setVisibility(View.GONE); sendAppView.setVisibility(View.GONE);
advance.setVisibility(View.GONE);
stop.setVisibility(View.VISIBLE);
stop.setText(getString(R.string.k2go_home_recover));
stop.setBackgroundResource(R.drawable.k2go_primary_bg);
stop.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_on_teal));
stop.setOnClickListener(v -> SetupLibraryActivity.recover(requireContext()));
footer.setVisibility(View.GONE);
}

private void renderHotspot() {
LocalHotspotManager.State st = hs.state().getValue();
LocalHotspotManager.Phase phase = (st != null) ? st.phase : LocalHotspotManager.Phase.OFF;
Expand Down Expand Up @@ -1056,6 +1101,10 @@ public void onResume() {
reduceMotion = org.iiab.controller.util.Motion.reduced(getContext());
if (anim != null && reduceMotion && anim.isAnimating()) anim.pauseAnimation();
if (progressBox != null) showProgress(progressBox.getVisibility() == View.VISIBLE);
// ADFA-5150: a system may have been recovered while away (Send's Recover sends them off and
// back). Refresh so the Send empty state clears once a system exists, and redraw if on Send.
systemPresent = org.iiab.controller.SystemStateEvaluator.isSystemInstalled(requireContext());
if (!atFork && side == Side.SEND) render();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ private enum Stage { JOIN, OPEN }
private Mode mode = Mode.HOTSPOT;
private Stage stage = Stage.JOIN;
private boolean openDone = false;
// ADFA-5150: Connect shares this device's library — with no system there is nothing to serve, and
// the QR would point at a dead port. Read on onResume (a system is not gained while this is open).
private boolean systemPresent = true;

private final LocalHotspotManager hs = LocalHotspotManager.get();
private ActivityResultLauncher<String> locationPerm;

private TextView tabHotspot, tabWifi, caption, subCaption, advance, finish, fallbackToggle;
private TextView connFooter; // ADFA-5150: the static "available while open" note — hidden in the no-system state
private LinearLayout steps, fallback, fallbackValues;
private ImageView qr;
// ADFA-4815: the scan fallback (Wi-Fi/pass or URL) is hidden until tapped, so it only
Expand Down Expand Up @@ -76,6 +80,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
fallbackValues = v.findViewById(R.id.k2go_conn_fallback_values);
advance = v.findViewById(R.id.k2go_conn_advance);
finish = v.findViewById(R.id.k2go_conn_finish);
connFooter = v.findViewById(R.id.k2go_conn_footer);

tabHotspot.setOnClickListener(x -> setMode(Mode.HOTSPOT));
tabWifi.setOnClickListener(x -> setMode(Mode.WIFI));
Expand All @@ -100,6 +105,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
// turns Wi-Fi on after landing on a blank QR); render() re-reads the IP via discover().
NetworkStateLiveData.get(requireContext()).observe(getViewLifecycleOwner(), net -> render());

// ADFA-5150: seed before the first render so a systemless open never flashes the QR flow;
// onResume re-reads it.
systemPresent = org.iiab.controller.SystemStateEvaluator.isSystemInstalled(requireContext());
setMode(Mode.HOTSPOT);
return v;
}
Expand All @@ -125,14 +133,49 @@ private void ensureHotspot() {

private static String browseUrl(String ip) { return "http://" + ip + ":8085"; }

@Override
public void onResume() {
super.onResume();
// ADFA-5150: refresh the system fact on the way to the front and redraw — a system may have
// been recovered while the user was away in the Recover flow this screen sends them to.
systemPresent = org.iiab.controller.SystemStateEvaluator.isSystemInstalled(requireContext());
render();
}

private void render() {
if (!isAdded() || caption == null) return;
// ADFA-5150: advance's default action is the stage toggle; noSystemState() repurposes it as
// Recover, so reset it here every render — a system that returns must not keep the Recover tap.
advance.setOnClickListener(x -> {
if (mode == Mode.HOTSPOT) { stage = (stage == Stage.JOIN) ? Stage.OPEN : Stage.JOIN; openDone = false; fallbackOpen = false; render(); }
});
paintTab(tabHotspot, mode == Mode.HOTSPOT);
paintTab(tabWifi, mode == Mode.WIFI);
if (finish != null) finish.setVisibility(View.GONE);
if (connFooter != null) connFooter.setVisibility(View.VISIBLE); // default; the no-system state hides it
if (!systemPresent) { noSystemState(); return; }
if (mode == Mode.HOTSPOT) renderHotspot(); else renderWifi();
}

/**
* ADFA-5150: no system, so nothing to share. Instead of a QR pointing at a dead server, say so and
* offer the one move that helps — Recover (restore / internet / clone). Reuses {@code advance} as
* the action; render() resets its listener so this does not stick once a system exists.
*/
private void noSystemState() {
if (steps != null) steps.setVisibility(View.GONE);
qr.setImageBitmap(null);
caption.setText(R.string.k2go_connect_no_system);
subCaption.setText("");
setFallback(null);
if (fallbackToggle != null) fallbackToggle.setVisibility(View.GONE);
advance.setVisibility(View.VISIBLE);
advance.setText(R.string.k2go_home_recover);
styleAdvance(true);
advance.setOnClickListener(v -> SetupLibraryActivity.recover(requireContext()));
if (connFooter != null) connFooter.setVisibility(View.GONE); // ADFA-5150: no "available" note here
}

private void renderHotspot() {
LocalHotspotManager.State st = hs.state().getValue();
LocalHotspotManager.Phase phase = (st != null) ? st.phase : LocalHotspotManager.Phase.OFF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,8 @@ private void showDamagedDialog() {
.setTitle(R.string.k2go_damaged_title)
.setMessage(R.string.k2go_damaged_body)
.setPositiveButton(R.string.k2go_damaged_recover, (dlg, w) -> {
startActivity(new android.content.Intent(this, SetupLibraryActivity.class)
.putExtra(SetupLibraryActivity.EXTRA_BACKUP_RESTORE, true));
finish();
SetupLibraryActivity.recover(this); // ADFA-5150: the shared route
finish(); // the dialog closes so the user can't fall back onto the held gate
})
// ADFA-5119: report it from here, where the user is standing when it matters. The app
// knows what happened and they do not, so the description is filled from the install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
// dialog: the dialog closes so the user cannot fall back onto a held boot gate, but Home
// is now an honest surface — back out of recovery and it still says "needs repair".
if (headerState == H_DAMAGED) {
startActivity(new android.content.Intent(requireContext(), SetupLibraryActivity.class)
.putExtra(SetupLibraryActivity.EXTRA_BACKUP_RESTORE, true));
SetupLibraryActivity.recover(requireContext()); // ADFA-5150: the shared route
return;
}
// ADFA-5143: both clone states go to the Clone tab. For the receiver that is the only
Expand Down Expand Up @@ -369,9 +368,11 @@ private void openSheet(Card c) {
if (c.state == GREEN || contentInFlight(c)) s = ModuleActionSheet.State.READY;
else if (isScheduled(c)) s = ModuleActionSheet.State.SCHEDULED;
else if (!systemInstalled) {
// No system, so nothing is installed. Asked here rather than remembered: the store
// holds what a probe said, and no probe has been made.
s = ModuleActionSheet.State.NOT_INSTALLED;
// ADFA-5150: no system to install a module into. This used to be NOT_INSTALLED — About /
// Install now / Schedule — which banked an install order with nothing to drain it. The
// sheet now collapses to Recover. (A first-run phone never reaches this surface; the wizard
// runs before the tabs, so a systemless card here always means a system was lost.)
s = ModuleActionSheet.State.NO_SYSTEM;
} else if (ev != null && !PlatformPresence.resolve(ev)) {
// Known absent, and still known absent with the box off — that is the state where
// installing is exactly the right offer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ private ModuleActionSheet() {}
*/
public enum State {
READY, NOT_INSTALLED, SCHEDULED,
/**
* ADFA-5150: there is no system to install into — a killed install/clone, a deletion, anything
* that is not the first-run wizard (which runs before this surface is reachable). The sheet
* collapses to the one action that helps: Recover. No Install/Schedule over a system that is
* not there.
*/
NO_SYSTEM,
/** The platform did not answer and nothing else says why. */
UNKNOWN,
/**
Expand Down Expand Up @@ -212,6 +219,13 @@ public static void show(Activity act, String endpoint, String title, int iconRes
}));
break;
}
case NO_SYSTEM:
// ADFA-5150: nothing to install into. Collapse to Recover — restore a backup, install
// over the internet, or clone from a peer, all three live there. No About/Install/
// Schedule/Hide: a systemless card has one meaningful move, and this is it.
content.addView(row(ctx, R.drawable.ic_arrow_right, act.getString(R.string.k2go_home_recover),
Emphasis.ACCENT, null, false, v -> { dlg.dismiss(); SetupLibraryActivity.recover(act); }));
break;
case UNKNOWN:
case STOPPED:
// Nothing established, or the box is down — either way we cannot say whether this
Expand Down Expand Up @@ -253,7 +267,7 @@ public static void show(Activity act, String endpoint, String title, int iconRes
break;
}

if (state != State.SCHEDULED && key != null) { // ADFA-4958: Hide declutters Home; Restore lives in management
if (state != State.SCHEDULED && state != State.NO_SYSTEM && key != null) { // ADFA-4958: Hide declutters Home; Restore lives in management (ADFA-5150: not over a systemless card)
content.addView(row(ctx, R.drawable.ic_hide_24, act.getString(R.string.k2go_sheet_hide),
Emphasis.PLAIN, null, false, v -> {
HiddenModules.add(ctx, key);
Expand Down Expand Up @@ -333,6 +347,7 @@ private static String stateLabel(Activity act, State s) {
case SCHEDULED: return act.getString(R.string.k2go_state_scheduled);
case UNKNOWN: return act.getString(R.string.k2go_state_no_answer);
case STOPPED: return act.getString(R.string.k2go_card_stopped);
case NO_SYSTEM: return act.getString(R.string.k2go_state_no_system);
case NOT_INSTALLED:
default: return act.getString(R.string.k2go_state_not_installed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,22 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
// 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;
// ADFA-5150: read the system fact off the same IO thread (it hits the disk). A damaged
// rootfs with still-readable flags used to show Install now, guarded only by the lock —
// installing a module into a system that is not there. No system → the button is Recover.
final boolean noSystem = !org.iiab.controller.SystemStateEvaluator.isSystemInstalled(appCtx);
// 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 (noSystem) {
chipRow.addView(chip(getString(R.string.k2go_state_no_system), R.color.k2go_amber_text));
installNowBtn.setText(R.string.k2go_home_recover);
installNowBtn.setOnClickListener(v -> SetupLibraryActivity.recover(requireContext()));
installNowBtn.setVisibility(View.VISIBLE);
return; // no Install/Schedule into a system that is not there
}
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ private void buildCards() {
msg.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted));
msg.setText(R.string.k2go_mod_needs_system);
host.addView(msg);
// ADFA-5150: was a dead end — the sentence, and no way forward but Back. Give it the one
// action that helps: Recover (restore / internet / clone all live there).
com.google.android.material.button.MaterialButton recover =
new com.google.android.material.button.MaterialButton(requireContext());
recover.setText(R.string.k2go_home_recover);
recover.setOnClickListener(v -> SetupLibraryActivity.recover(requireContext()));
LinearLayout.LayoutParams rlp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
rlp.gravity = Gravity.CENTER;
host.addView(recover, rlp);
addHiddenSection();
return;
}
Expand Down
Loading