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 @@ -151,8 +151,25 @@ public void startClient(Context context, ShareConfig config, String hostIp, int
mainHandler.post(() -> listener.onProgress(progress.percent, progress.speed, progress.eta, finalFile));
}
// PHASE 1 FIX: Strict match for actual rsync errors, ignoring files named "error"
else if (line.contains("@ERROR:") || line.contains("rsync error:")) {
//
// ADFA-5143: "rsync error:" is only the FINAL summary line. Every per-file failure
// rsync prints starts with a bare "rsync:" —
// rsync: [receiver] mkstemp "..." failed: Permission denied (13)
// rsync: [generator] failed to set times on "...": Operation not permitted (1)
// — so none of them matched, they all fell through to the branch below, and were
// stored as lastFile: filed as the name of the file being transferred and shown to
// the user as such. A device log of a code-23 transfer therefore ended with
// "some files/attrs were not transferred (see previous errors)" and no previous
// errors anywhere, because they had been reclassified as data.
//
// That is the difference between a benign 23 (attributes Android will not let us
// set) and a fatal one (files that did not arrive), and it is the whole reason
// nobody can tell those apart today. Logged into LogRepository as well as logcat,
// so the failure report a user can send carries them.
else if (line.contains("@ERROR:") || line.startsWith("rsync:")
|| line.startsWith("rsync warning:") || line.contains("rsync error:")) {
Log.e(TAG, "[Rsync Output Error] " + line);
org.iiab.controller.LogRepository.get().append("[Rsync] " + line);
} else if (!line.trim().isEmpty() && !line.startsWith("sending incremental file list") && !line.contains("bytes/sec")) {
lastFile = line.trim();
}
Expand All @@ -162,6 +179,17 @@ else if (line.contains("@ERROR:") || line.contains("rsync error:")) {

secretStore.deleteClientPassword();

// ADFA-5143: say the verdict out loud. The log used to show a code-23 error line and then
// a SUCCESS state with nothing in between explaining the jump, which reads like a bug in
// the app rather than a deliberate rule. RsyncOutcome.isSuccess() counts 0, 23 and 24 as
// complete on purpose — 24 (files vanished from a live source) is defensible, and 23 is
// ambiguous: attributes Android refused to set, or files that never arrived. Until the
// per-file errors above have been read on a real transfer, the rule stays as it is and
// the log states it.
Log.i(TAG, "rsync client exit " + exitCode + " → "
+ RsyncOutcome.classifyTransfer(exitCode)
+ (RsyncOutcome.isSuccess(exitCode) && exitCode != 0
? " (non-zero treated as complete — see any [Rsync Output Error] lines above)" : ""));
if (isCancelled) {
mainHandler.post(() -> listener.onError(context.getString(R.string.rsync_error_cancelled)));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
Expand All @@ -29,7 +28,8 @@
import com.journeyapps.barcodescanner.ScanOptions;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.progressindicator.LinearProgressIndicator;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
Expand Down Expand Up @@ -104,7 +104,10 @@ private enum Stage { JOIN, START }
private LinearLayout receiveBox, progressBox;
private EditText paste;
private TextView receiveStart, pStatus, pFile, pStats, cancel;
private ProgressBar pbar;
private LinearProgressIndicator pbar; // ADFA-5143: typed as itself, so setProgressCompat is available
private com.airbnb.lottie.LottieAnimationView anim; // ADFA-5143: the clone loop
// ADFA-5143: read once — renderReceive() runs on every progress tick and this is a Settings read.
private boolean reduceMotion = false;
private long lastSeq = -1L;
private LinearLayout confirmPanel, confirmSizes, confirmReplace, confirmFresh;
private TextView confirmSys, confirmContent, confirmTotal;
Expand Down Expand Up @@ -185,6 +188,20 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
progressBox = v.findViewById(R.id.k2go_clone_progress);
pStatus = v.findViewById(R.id.k2go_clone_pstatus);
pbar = v.findViewById(R.id.k2go_clone_pbar);
// ADFA-5143: the transfer state uses the same Lottie template as the backup / restore job
// screen. The animation ships without icons; the two K2Go logos are composited by the layout.
anim = v.findViewById(R.id.k2go_clone_anim);
reduceMotion = org.iiab.controller.util.Motion.reduced(getContext());
if (anim != null) {
anim.setAnimation(R.raw.k2go_clone_loop);
if (reduceMotion) {
// Reduce motion: hold one frame — the glows and a few dots still read as "in flight",
// and the screen never depends on movement to be understood.
anim.setProgress(0.5f);
} else {
anim.setRepeatCount(com.airbnb.lottie.LottieDrawable.INFINITE);
}
}
pFile = v.findViewById(R.id.k2go_clone_pfile);
pStats = v.findViewById(R.id.k2go_clone_pstats);
cancel = v.findViewById(R.id.k2go_clone_cancel);
Expand Down Expand Up @@ -305,7 +322,7 @@ private void requestMode(Mode target) {
boolean sharing = (side == Side.SEND && !sendApp && stage == Stage.START && daemonStarted);
if (target == mode || !sharing) { setMode(target); return; }
String label = (target == Mode.HOTSPOT) ? "Hotspot" : "Wi-Fi";
new AlertDialog.Builder(requireContext())
new MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.k2go_clone_switch_title, label))
.setMessage(getString(R.string.k2go_clone_switch_msg))
.setNegativeButton(getString(R.string.k2go_cancel), null)
Expand Down Expand Up @@ -757,7 +774,7 @@ private String bitsLabel(int bits) {
// nothing to copy — warn before probing rather than pulling an empty library.
private void probeOrWarnEmpty(SyncHandshakeHelper.SyncCredentials creds) {
if (!creds.hasRootfs) {
new AlertDialog.Builder(requireContext())
new MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.k2go_clone_nolib_title))
.setMessage(getString(R.string.k2go_clone_nolib_msg))
.setNegativeButton(getString(R.string.k2go_cancel), null)
Expand Down Expand Up @@ -793,10 +810,40 @@ private void onTransferState(SyncTransferState st) {
syncProtection(); // ADFA-4782: match protection to the live pull state on every transition
}

/**
* ADFA-5143: show or hide the transfer block, and let the Lottie follow it. The animation is only
* ever running while the block that contains it is on screen — one place decides both, so a hidden
* screen can't leave a loop spinning against the battery.
*/
private void showProgress(boolean visible) {
progressBox.setVisibility(visible ? View.VISIBLE : View.GONE);
if (anim == null || reduceMotion) return;
if (visible) {
if (!anim.isAnimating()) anim.playAnimation();
} else if (anim.isAnimating()) {
anim.pauseAnimation();
}
}

/**
* ADFA-5143: switch the M3 indicator between determinate and indeterminate without depending on
* whether Material allows it in place. {@code BaseProgressIndicator} guards that transition while
* the indicator is visible to the user, and this screen crosses it on every run (CONNECTING and
* CALCULATING are indeterminate, TRANSFERRING is not) — so the bar is taken off screen for the
* switch and put back. Costs nothing if the guard never fires.
*/
private void setBarIndeterminate(boolean indeterminate) {
if (pbar == null || pbar.isIndeterminate() == indeterminate) return;
int was = pbar.getVisibility();
pbar.setVisibility(View.GONE);
pbar.setIndeterminate(indeterminate);
pbar.setVisibility(was);
}

private void renderReceive() {
SyncTransferState st = SyncProgressRepository.get().current();
boolean busy = (st != null && st.isActive());
progressBox.setVisibility(busy ? View.VISIBLE : View.GONE);
showProgress(busy);
confirmPanel.setVisibility(View.GONE);
rcvIncompat.setVisibility(View.GONE); // ADFA-4784
if (busy) {
Expand All @@ -807,7 +854,7 @@ private void renderReceive() {
rcvCamNote.setVisibility(View.GONE); rcvShowPaste.setVisibility(View.GONE); pasteBlock.setVisibility(View.GONE);
SyncTransferState.Phase ph = st.phase;
if (ph == SyncTransferState.Phase.CONFIRM) {
progressBox.setVisibility(View.GONE);
showProgress(false);
// ADFA-4790: confirm as a System/Content/Total table (sizes travel in the QR) per the
// design mockup; the replace notice is static in the layout. If the sender didn't send
// sizes (older build), hide the table and just show the notice.
Expand All @@ -831,13 +878,16 @@ private void renderReceive() {
return;
}
if (ph == SyncTransferState.Phase.TRANSFERRING) {
pbar.setIndeterminate(false);
pbar.setProgress(st.percent);
setBarIndeterminate(false);
// setProgressCompat animates to the new value instead of jumping. The explicit switch
// above stays: setProgressCompat can also leave indeterminate mode on its own, but only
// after the current cycle, and that path isn't something this screen should depend on.
pbar.setProgressCompat(st.percent, true);
pStatus.setText(getString(R.string.k2go_clone_copying));
pFile.setText(st.file);
pStats.setText(st.percent + "% " + st.speed + " ETA " + st.eta);
} else {
pbar.setIndeterminate(true);
setBarIndeterminate(true);
pStatus.setText(ph == SyncTransferState.Phase.CALCULATING ? getString(R.string.k2go_clone_calculating) : getString(R.string.k2go_clone_connecting));
pFile.setText(""); pStats.setText("");
}
Expand Down Expand Up @@ -966,6 +1016,19 @@ private void startReceiveTransfer() {
}

private void showReceiveTerminal(boolean ok, String message) {
// ADFA-5143: reaching a receive terminal is itself the proof that this side owns the clone
// environment — whatever this fragment instance happens to remember. cloneLockHeld and
// cloneGuardHeld are fragment fields, so a fragment recreated mid-transfer (app closed and
// reopened, then re-attached to the running rsync) arrived here with both false and
// releaseCloneEnv() returned on its first line: the install marker stayed set, the lock was
// never dropped and the server was never booted. The next launch then read that leftover
// marker as a damaged install — of a clone that had in fact completed. Re-derive the two
// facts from disk, where they actually live, instead of trusting the fragment's memory.
Context termCtx = getContext();
if (termCtx != null) {
cloneLockHeld = true; // EnvironmentLock.release() is idempotent and self-heals a stale file
cloneGuardHeld = org.iiab.controller.InstallGuard.inProgress(termCtx);
}
releaseCloneEnv(); // ADFA-4956: boot the (possibly replaced) system, end guard, drop the lock
syncVm.releaseNetwork();
String body = (message != null) ? message : "";
Expand All @@ -974,14 +1037,33 @@ private void showReceiveTerminal(boolean ok, String message) {
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.";
}
new AlertDialog.Builder(requireContext())
new MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(ok ? R.string.k2go_clone_copy_complete : R.string.k2go_clone_copy_stopped))
.setMessage(body)
.setPositiveButton(getString(android.R.string.ok), (d, w) -> { SyncProgressRepository.get().postIdle(); renderReceive(); })
.setCancelable(false)
.show();
}

// ADFA-5143: the loop follows the screen, like the backup / restore job screen. Only the animation
// is touched here — the transfer itself is owned by the service and keeps running either way.
@Override
public void onResume() {
super.onResume();
// Re-read the setting here rather than trusting what onCreateView saw: changing it doesn't
// recreate the fragment, so a cached answer can outlive the truth. Coming back to the front is
// the only moment it can have changed behind our back, and it keeps the read off the tick path.
reduceMotion = org.iiab.controller.util.Motion.reduced(getContext());
if (anim != null && reduceMotion && anim.isAnimating()) anim.pauseAnimation();
if (progressBox != null) showProgress(progressBox.getVisibility() == View.VISIBLE);
}

@Override
public void onPause() {
super.onPause();
if (anim != null && anim.isAnimating()) anim.pauseAnimation();
}

@Override
public void onDestroyView() {
super.onDestroyView();
Expand All @@ -995,7 +1077,7 @@ public void onDestroyView() {
}

private void confirmStop() {
new AlertDialog.Builder(requireContext())
new MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.k2go_clone_stopshare_title))
.setMessage(getString(R.string.k2go_clone_stopshare_msg))
.setNegativeButton(getString(R.string.k2go_cancel), null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ public android.graphics.Typeface fetchFont(String fontFamily) {
// ADFA-4919 (2c-ii): marker set + no live installer (both install repos IDLE) means a proot
// install was killed. Enter recovery instead of quietly lifting the gate to an empty library.
recovering = !installing
// ADFA-5143 (plan B): not when the user was brought here to get a system. A killed
// clone-receive leaves the marker set, so this predicate was true again the moment
// recovery's own suggestion — Reinstall → Copy from a phone — landed on this screen:
// dialog, recovery, wizard, clone, dialog. A loop out of the exit.
//
// The extra already means "the caller knows there is no usable system and is bringing
// this person somewhere to fix it", which is exactly when a dialog announcing that the
// system is broken has nothing to add and everything to block. Leave and come back
// cold and the marker still puts them in recovery, correctly: they are no longer
// mid-attempt.
&& !broughtHereToSetUp
&& org.iiab.controller.InstallGuard.inProgress(this)
&& !InstallProgressRepository.get().current().isRunning()
&& !org.iiab.controller.install.presentation.ModuleQueueRepository.get().isRunning()
Expand Down Expand Up @@ -985,12 +996,9 @@ public void onBackPressed() {
}

private boolean reduceMotion() {
try {
return android.provider.Settings.Global.getFloat(getContentResolver(),
android.provider.Settings.Global.ANIMATOR_DURATION_SCALE, 1f) == 0f;
} catch (Exception e) {
return false;
}
// ADFA-5143: the reading moved to util/Motion so the clone screen answers this the same way
// this one does, instead of keeping a private copy of the same setting.
return org.iiab.controller.util.Motion.reduced(this);
}

/** ADFA-4837: true while a server start is actually in progress (header shows "Starting…"). */
Expand All @@ -1011,9 +1019,33 @@ public boolean canStartServer() {
&& (serverController == null || !serverController.isStopping())
&& !InstallProgressRepository.get().isRunning()
&& !org.iiab.controller.InstallGuard.inProgress(this)
// ADFA-5143: the last two align this with ServerController.handleServerLaunchClick,
// which is the guard that actually decides. This method was a PARTIAL copy of it —
// missing the module queue and the environment lock — so it said yes where the real
// guard says no, and the header offered a Retry that flickered and did nothing. The
// start was never in danger; the button was a lie about it. Two places answering "can
// I start the server?" and answering differently is the defect, not the clone.
//
// ownerHeld covers a clone on either side without knowing anything about clones:
// Owner.CLONE is in the enum and both sides acquire it (CloneFragment:354 and :936).
&& !org.iiab.controller.install.presentation.ModuleQueueRepository.get().isRunning()
&& !org.iiab.controller.env.EnvironmentLock.ownerHeld(this)
&& org.iiab.controller.SystemStateEvaluator.isSystemInstalled(this);
}

/**
* ADFA-5143: take the user to the Clone tab, where a transfer in flight actually lives.
*
* <p>The Home header offers this instead of a restart during a transfer. For the receiver it is
* the only place the progress exists; for the donor it is where the QR and Stop are — which is
* why Stop is not copied onto the header. Navigating to a control beats owning a second one.
*/
public void openCloneTab() {
currentTab = R.id.nav_clone;
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
Loading