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 @@ -84,6 +84,12 @@ private enum Stage { JOIN, START }
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
private boolean receiveExiting = false; // ADFA-5151: success confirmation is showing; hold it, then go to Library
private static final long RECEIVE_SUCCESS_REDIRECT_MS = 3000L; // ADFA-5151: like the install index's REDIRECT_MS
// ADFA-5151: once a receive is accepted (running), Back is confined — first press warns, the next
// backgrounds the app (the copy keeps running under CloneShareService; the notification returns).
private androidx.activity.OnBackPressedCallback receiveBackGate;
private boolean leaveWarned = false;
// 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 @@ -287,6 +293,22 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
v.findViewById(R.id.k2go_clone_fork_send).setOnClickListener(x -> enterSide(Side.SEND));
v.findViewById(R.id.k2go_clone_fork_receive).setOnClickListener(x -> enterSide(Side.RECEIVE));
backHeader.setOnClickListener(x -> goToFork());
// ADFA-5151: the receive confinement, mirroring BackupJobFragment's backGate. Enabled only once
// the transfer is accepted (running, past CONFIRM) via updateBackGuard(); before that Back is
// free. First Back warns; the next backgrounds the app rather than landing on a systemless Home.
receiveBackGate = new androidx.activity.OnBackPressedCallback(false) {
@Override public void handleOnBackPressed() {
if (!leaveWarned) {
leaveWarned = true;
org.iiab.controller.util.Snackbars.make(
requireActivity().findViewById(android.R.id.content),
R.string.k2go_clone_back_running).show();
} else {
requireActivity().moveTaskToBack(true); // leave; the copy survives, the notification returns
}
}
};
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), receiveBackGate);
// ADFA-4960: re-bind to a live SEND session. Its rsync daemon is still up in this process (kept
// alive by CloneShareService), so a recreated Fragment must land on the share screen — not the
// fork. Restore the state the share screen redraws from; daemonStarted=true makes ensureDaemon's
Expand All @@ -312,6 +334,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
cloneLockHeld = true;
Context rebindCtx = getContext();
cloneGuardHeld = rebindCtx != null && org.iiab.controller.InstallGuard.inProgress(rebindCtx);
} else if (!org.iiab.controller.SystemStateEvaluator.isSystemInstalled(requireContext())) {
// ADFA-5151: no system → skip the Send/Receive fork and land on receive step 1. Send is
// blocked anyway (ADFA-5150), so Receive is the only real move; going straight to it is the
// funnel Recover feeds. Free until the transfer is accepted — the back guard bites only once
// it is running.
atFork = false; side = Side.RECEIVE; rStage = RStage.JOIN;
}
render();
return v;
Expand Down Expand Up @@ -490,6 +518,7 @@ private void releaseCloneEnv() {

private void render() {
if (!isAdded() || caption == null) return;
updateBackGuard(); // ADFA-5151: keep the Back confinement in step with side + transfer state
if (showcode != null) { showcode.setVisibility(View.GONE); codeblock.setVisibility(View.GONE); }
if (stepTitle != null) { stepTitle.setVisibility(View.GONE); skipApp.setVisibility(View.GONE); shareWifi.setVisibility(View.GONE); }
paintTab(tabSend, side == Side.SEND);
Expand Down Expand Up @@ -863,7 +892,10 @@ private void onTransferState(SyncTransferState st) {
if (st.phase == SyncTransferState.Phase.SUCCESS) { lastSeq = st.seq; showReceiveTerminal(true, st.message); }
else if (st.phase == SyncTransferState.Phase.FAILED || st.phase == SyncTransferState.Phase.ABORTED) { lastSeq = st.seq; showReceiveTerminal(false, st.message); }
}
if (side == Side.RECEIVE) renderReceive();
// ADFA-5151: while the success confirmation is holding before the redirect to Library, don't let
// renderReceive() tear the progress screen down (SUCCESS is not active, so it would).
if (side == Side.RECEIVE && !receiveExiting) renderReceive();
updateBackGuard(); // ADFA-5151: CONFIRM -> running (accepted) flips the Back confinement on
syncProtection(); // ADFA-4782: match protection to the live pull state on every transition
}

Expand Down Expand Up @@ -897,6 +929,20 @@ private void setBarIndeterminate(boolean indeterminate) {
pbar.setVisibility(was);
}

/**
* ADFA-5151: enable the Back confinement only once the receive is accepted (running, past CONFIRM).
* Before acceptance (JOIN / CONFIRM) Back is free; the user is still deciding. Reset the one-time
* warning whenever it is off, so each accepted transfer warns once before backgrounding.
*/
private void updateBackGuard() {
if (receiveBackGate == null) return;
SyncTransferState st = SyncProgressRepository.get().current();
boolean accepted = side == Side.RECEIVE && st != null && st.isActive()
&& st.phase != SyncTransferState.Phase.CONFIRM;
receiveBackGate.setEnabled(accepted);
if (!accepted) leaveWarned = false;
}

private void renderReceive() {
SyncTransferState st = SyncProgressRepository.get().current();
boolean busy = (st != null && st.isActive());
Expand Down Expand Up @@ -1088,16 +1134,51 @@ private void showReceiveTerminal(boolean ok, String message) {
}
releaseCloneEnv(); // ADFA-4956: boot the (possibly replaced) system, end guard, drop the lock
syncVm.releaseNetwork();

if (ok) {
// ADFA-5151: success exit. Do not strand the user on the receive step — confirm briefly on
// the progress screen, then go to the Library, exactly as the install index does. A system
// now exists (releaseCloneEnv booted it), so LibraryHomeFragment refreshes onto it. Shared
// terminal, so a normal receive (with a system) gets the same courtesy.
receiveExiting = true;
if (progressBox != null) progressBox.setVisibility(View.VISIBLE);
setBarIndeterminate(false);
if (pbar != null) pbar.setProgressCompat(100, true);
if (pStatus != null) pStatus.setText(getString(R.string.k2go_clone_copy_complete));
if (pFile != null) pFile.setText("");
if (pStats != null) pStats.setText("");
if (cancel != null) cancel.setVisibility(View.GONE); // nothing to cancel on a finished copy
View host = (progressBox != null) ? progressBox : getView();
if (host != null) host.postDelayed(() -> {
if (!isAdded()) return;
// ADFA-5151 (review): clear the flag here — its owner and lifetime. Navigation destroys
// this fragment, so it normally dies with it; resetting means that even if navigation
// ever no-ops, renderReceive is not left permanently muted. A marker with a clear-path.
receiveExiting = false;
SyncProgressRepository.get().postIdle();
if (getActivity() instanceof LibraryActivity) ((LibraryActivity) getActivity()).openLibraryTab();
}, RECEIVE_SUCCESS_REDIRECT_MS);
return;
}

String body = (message != null) ? message : "";
// ADFA-4782: if rsync was SIGKILLed (exit 137, phantom-process killer), guide the user.
if (!ok && body.contains("137")) {
if (body.contains("137")) {
body += "\n\nThe copy was stopped by the system. Keep this screen on and the app in the "
+ "foreground during a transfer, then scan again to resume.";
}
// ADFA-5151: fail -> the user chooses, never stranded and never dropped onto a systemless Home.
// Retry re-scans (rsync resumes from the half-written tree — the maravilla Luis relies on);
// Recover goes to the hub (restore / install over internet / clone again). The Back guard has
// already turned off (FAILED is not active), so leaving the app is free too.
new MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(ok ? R.string.k2go_clone_copy_complete : R.string.k2go_clone_copy_stopped))
.setTitle(getString(R.string.k2go_clone_copy_stopped))
.setMessage(body)
.setPositiveButton(getString(android.R.string.ok), (d, w) -> { SyncProgressRepository.get().postIdle(); renderReceive(); })
.setPositiveButton(getString(R.string.k2go_home_retry), (d, w) -> { SyncProgressRepository.get().postIdle(); renderReceive(); })
.setNegativeButton(getString(R.string.k2go_home_recover), (d, w) -> {
SyncProgressRepository.get().postIdle();
SetupLibraryActivity.recover(requireContext());
})
.setCancelable(false)
.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,15 @@ public void openCloneTab() {
syncSelection(currentTab);
}

/** ADFA-5151: land on Home/Library — the success exit of a clone-receive (a system now exists),
* mirroring the install index's goHome. The server was booted by CloneFragment.releaseCloneEnv,
* so LibraryHomeFragment refreshes onto the new system. */
public void openLibraryTab() {
currentTab = R.id.nav_library;
showTab(currentTab);
syncSelection(currentTab);
}

/** ADFA-4837: header "Couldn't start — tap to retry" action. Safe no-op unless truly idle. */
public void startServer() {
if (!canStartServer()) return;
Expand Down
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 @@ -183,6 +183,7 @@
<string name="k2go_bj_wait_body">أبقِ K2Go مفتوحًا. يمكنك المغادرة — يستمر في العمل في الخلفية، ويعيدك الإشعار.</string>
<string name="k2go_bj_returning">تم — جارٍ العودة إلى الشاشة الرئيسية…</string>
<string name="k2go_br_leave_backup">النسخ الاحتياطي قيد التشغيل — يمكنك المغادرة؛ سيستمر وسيكون جاهزًا عند عودتك.</string>
<string name="k2go_clone_back_running">النسخ قيد التشغيل — يمكنك المغادرة؛ يستمر، والإشعار يعيدك إليه.</string>
<string name="k2go_br_leave_restore">الاستعادة قيد التشغيل — يمكنك المغادرة؛ ستستمر وستكون جاهزة عند عودتك.</string>
<string name="k2go_settings_sec_developer">المطوّر</string>
<string name="k2go_settings_network_dns">الشبكة وDNS</string>
Expand Down
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 @@ -183,6 +183,7 @@
<string name="k2go_bj_wait_body">K2Go-nu açıq saxlayın. Tərk edə bilərsiniz — arxa planda işləməyə davam edir və bildiriş sizi geri gətirir.</string>
<string name="k2go_bj_returning">Hazır — Evə qayıdılır…</string>
<string name="k2go_br_leave_backup">Ehtiyat nüsxə işləyir — tərk edə bilərsiniz; davam edir və qayıtdıqda hazır olacaq.</string>
<string name="k2go_clone_back_running">Kopyalama işləyir — tərk edə bilərsiniz; davam edir və bildiriş sizi geri qaytarır.</string>
<string name="k2go_br_leave_restore">Bərpa işləyir — tərk edə bilərsiniz; davam edir və qayıtdıqda hazır olacaq.</string>
<string name="k2go_settings_sec_developer">TƏRTİBATÇI</string>
<string name="k2go_settings_network_dns">Şəbəkə &amp; DNS</string>
Expand Down
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 @@ -183,6 +183,7 @@
<string name="k2go_bj_wait_body">Оставете K2Go отворено. Можете да го напуснете — то продължава да работи във фонов режим, а известието ще ви върне обратно.</string>
<string name="k2go_bj_returning">Готово — връщане към Начало…</string>
<string name="k2go_br_leave_backup">Резервното копие се изпълнява — можете да напуснете; продължава и ще е готово, когато се върнете.</string>
<string name="k2go_clone_back_running">Копирането се изпълнява — можете да напуснете; продължава и известието ви връща обратно.</string>
<string name="k2go_br_leave_restore">Възстановяването се изпълнява — можете да напуснете; продължава и ще е готово, когато се върнете.</string>
<string name="k2go_settings_sec_developer">РАЗРАБОТЧИК</string>
<string name="k2go_settings_network_dns">Мрежа и DNS</string>
Expand Down
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 @@ -183,6 +183,7 @@
<string name="k2go_bj_wait_body">K2Go খোলা রাখুন। আপনি চলে যেতে পারেন — এটি ব্যাকগ্রাউন্ডে চালু থাকে, এবং বিজ্ঞপ্তি আপনাকে ফিরিয়ে আনে।</string>
<string name="k2go_bj_returning">সম্পন্ন — হোমে ফিরে যাচ্ছে…</string>
<string name="k2go_br_leave_backup">ব্যাকআপ চলছে — আপনি চলে যেতে পারেন; এটি চলতে থাকবে এবং আপনি ফিরে এলে প্রস্তুত থাকবে।</string>
<string name="k2go_clone_back_running">কপি চলছে — আপনি চলে যেতে পারেন; এটি চলতে থাকবে এবং নোটিফিকেশন আপনাকে ফিরিয়ে আনবে।</string>
<string name="k2go_br_leave_restore">পুনরুদ্ধার চলছে — আপনি চলে যেতে পারেন; এটি চলতে থাকবে এবং আপনি ফিরে এলে প্রস্তুত থাকবে।</string>
<string name="k2go_settings_sec_developer">ডেভেলপার</string>
<string name="k2go_settings_network_dns">নেটওয়ার্ক ও DNS</string>
Expand Down
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 @@ -183,6 +183,7 @@
<string name="k2go_bj_wait_body">Nechte K2Go otevřené. Můžete odejít — běží dál na pozadí a oznámení vás vrátí zpět.</string>
<string name="k2go_bj_returning">Hotovo — návrat na Domů…</string>
<string name="k2go_br_leave_backup">Záloha probíhá — můžete odejít; pokračuje dál a bude hotová, až se vrátíte.</string>
<string name="k2go_clone_back_running">Kopírování probíhá — můžete odejít; pokračuje dál a oznámení vás vrátí zpět.</string>
<string name="k2go_br_leave_restore">Obnova probíhá — můžete odejít; pokračuje dál a bude hotová, až se vrátíte.</string>
<string name="k2go_settings_sec_developer">PRO VÝVOJÁŘE</string>
<string name="k2go_settings_network_dns">Síť &amp; DNS</string>
Expand Down
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 @@ -184,6 +184,7 @@
<string name="k2go_bj_wait_body">Lass K2Go geöffnet. Du kannst weggehen — es läuft im Hintergrund weiter, und die Benachrichtigung bringt dich zurück.</string>
<string name="k2go_bj_returning">Fertig — zurück zum Start…</string>
<string name="k2go_br_leave_backup">Das Backup läuft — du kannst weggehen; es läuft weiter und ist fertig, wenn du zurückkommst.</string>
<string name="k2go_clone_back_running">Das Kopieren läuft — du kannst weggehen; es läuft weiter und die Benachrichtigung bringt dich zurück.</string>
<string name="k2go_br_leave_restore">Die Wiederherstellung läuft — du kannst weggehen; sie läuft weiter und ist fertig, wenn du zurückkommst.</string>
<string name="k2go_settings_sec_developer">ENTWICKLER</string>
<string name="k2go_settings_network_dns">Netzwerk &amp; DNS</string>
Expand Down
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 @@ -184,6 +184,7 @@
<string name="k2go_bj_wait_body">Κρατήστε το K2Go ανοιχτό. Μπορείτε να φύγετε — συνεχίζει να εκτελείται στο παρασκήνιο και η ειδοποίηση σας επαναφέρει.</string>
<string name="k2go_bj_returning">Ολοκληρώθηκε — επιστροφή στην Αρχική…</string>
<string name="k2go_br_leave_backup">Το αντίγραφο ασφαλείας εκτελείται — μπορείτε να φύγετε· συνεχίζεται και θα είναι έτοιμο όταν επιστρέψετε.</string>
<string name="k2go_clone_back_running">Η αντιγραφή εκτελείται — μπορείτε να φύγετε· συνεχίζεται και η ειδοποίηση σας επαναφέρει.</string>
<string name="k2go_br_leave_restore">Η επαναφορά εκτελείται — μπορείτε να φύγετε· συνεχίζεται και θα είναι έτοιμη όταν επιστρέψετε.</string>
<string name="k2go_settings_sec_developer">ΠΡΟΓΡΑΜΜΑΤΙΣΤΗΣ</string>
<string name="k2go_settings_network_dns">Δίκτυο &amp; DNS</string>
Expand Down
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 @@ -183,6 +183,7 @@
<string name="k2go_bj_wait_body">Mantén K2Go abierto. Puedes salir — sigue ejecutándose en segundo plano, y la notificación te trae de vuelta.</string>
<string name="k2go_bj_returning">Listo — volviendo a Inicio…</string>
<string name="k2go_br_leave_backup">La copia está en marcha — puedes salir; sigue funcionando y estará lista cuando vuelvas.</string>
<string name="k2go_clone_back_running">La copia está en marcha — puedes salir; sigue funcionando y la notificación te trae de vuelta.</string>
<string name="k2go_br_leave_restore">La restauración está en marcha — puedes salir; sigue funcionando y estará lista cuando vuelvas.</string>
<string name="k2go_settings_sec_developer">DESARROLLADOR</string>
<string name="k2go_settings_network_dns">Red y DNS</string>
Expand Down
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 @@ -183,6 +183,7 @@
<string name="k2go_bj_wait_body">K2Go را باز نگه دارید. می‌توانید خارج شوید — در پس‌زمینه اجرا می‌ماند و اعلان شما را برمی‌گرداند.</string>
<string name="k2go_bj_returning">انجام شد — در حال بازگشت به خانه…</string>
<string name="k2go_br_leave_backup">پشتیبان‌گیری در حال اجراست — می‌توانید خارج شوید؛ ادامه می‌یابد و هنگام بازگشت آماده خواهد بود.</string>
<string name="k2go_clone_back_running">کپی در حال اجراست — می‌توانید خارج شوید؛ ادامه می‌یابد و اعلان شما را بازمی‌گرداند.</string>
<string name="k2go_br_leave_restore">بازیابی در حال اجراست — می‌توانید خارج شوید؛ ادامه می‌یابد و هنگام بازگشت آماده خواهد بود.</string>
<string name="k2go_settings_sec_developer">توسعه‌دهنده</string>
<string name="k2go_settings_network_dns">شبکه و DNS</string>
Expand Down
Loading
Loading