Skip to content

ADFA-4492 (step 3b-1) refactor(sync): concurrency + lifecycle hardening (S8/S9/S10)#98

Merged
luisguzman-adfa merged 2 commits into
mainfrom
refactor/ADFA-4492-sync-hardening
Jun 30, 2026
Merged

ADFA-4492 (step 3b-1) refactor(sync): concurrency + lifecycle hardening (S8/S9/S10)#98
luisguzman-adfa merged 2 commits into
mainfrom
refactor/ADFA-4492-sync-hardening

Conversation

@luisguzman-adfa

Copy link
Copy Markdown
Collaborator

Part of ADFA-1028 (tech-debt). Step 3b-1 of ADFA-4492 (Carve & export the Share/rsync feature, S14).

The safe, behaviour-preserving part of the SyncFragment carve: the concurrency/lifecycle hardening, without the structural ViewModel move (that is step 3b-2).

  • S8: the network-reachability probe ran on a raw Thread and showed AlertDialogs from the callback with no lifecycle guard -> a config change / leaving the screen could fire dialogs / requireContext() after onDestroyView and crash. Now runs on AppExecutors.io(); ALL five transport callbacks (dry-run onCalculated/onError, transfer onProgress/onComplete/onError) plus the probe callback are guarded with isAdded()/getContext(); enable/disableSystemProtection() are null-safe; onDestroyView stops the watchdog so a cut-short transfer doesn't leak it.
  • S9: three swallowed catch(Exception ignored) blocks now log at warn.
  • S10: RsyncManager.isCancelled is now volatile.

Verified on-device: changing the theme during the dry-run/probe no longer crashes (was IllegalStateException: not attached to a context). NOTE: this only stops the crash — making the transfer SURVIVE recreation (re-bind + continue) is step 3b-2 (observable repository + transport in an Activity-scoped ViewModel).

…ng (S8/S9/S10)

The safe, behaviour-preserving part of the SyncFragment carve: fixes the
concurrency/lifecycle debt without the high-churn structural move. No behaviour
change for the happy path.

- S8: the network-reachability probe ran on a raw new Thread and then showed
  AlertDialogs from the callback with no lifecycle guard -> a config change or
  leaving the screen mid-probe could fire dialogs / requireContext() after
  onDestroyView and crash. Now runs on the shared AppExecutors.io(), the UI
  callback is guarded (isAdded() && getActivity() != null) and bails early if the
  view is gone.
- S9: three swallowed catch (Exception ignored) blocks (reachability probe, ppk
  value parse, native-arch detection) now log at warn instead of hiding failures.
- S10: RsyncManager.isCancelled is now volatile (written on the UI/stop thread,
  read on the transfer worker thread).

Deferred to step 3b-2 (the structural carve): moving SyncFragment session state +
orchestration into a SyncViewModel / thin fragment. Done right that also wants the
InstallService-style observable owner so a transfer survives recreation, so it is a
focused follow-up rather than a blind ~50-site field migration here. NOT built locally yet.
…backs against detach (S8)

Fixes a crash found on-device: changing the theme during the dry-run/transfer
recreates the fragment -> onDestroyView stops the rsync process -> its
DryRunListener/SyncListener callback fires on the main thread after the fragment
detached and calls requireContext() -> IllegalStateException (not attached to a
context). The previous 3b-1 commit only guarded the reachability probe, not these
RsyncManager callbacks.

- Guard all five transport callbacks (dry-run onCalculated/onError, transfer
  onProgress/onComplete/onError) with `if (!isAdded() || getContext() == null) return;`
  so they no longer touch the UI / requireContext() once detached.
- Make enable/disableSystemProtection() null-safe (use getContext(), no-op if gone).
- onDestroyView now also calls disableSystemProtection(), so a transfer cut short by
  leaving/recreation does not leak the watchdog foreground service.

No happy-path behaviour change. NOT built locally yet.
@luisguzman-adfa luisguzman-adfa marked this pull request as ready for review June 30, 2026 01:08
@luisguzman-adfa luisguzman-adfa merged commit e131e58 into main Jun 30, 2026
1 check passed
@luisguzman-adfa luisguzman-adfa deleted the refactor/ADFA-4492-sync-hardening branch June 30, 2026 01:52
luisguzman-adfa added a commit that referenced this pull request Jun 30, 2026
…ess against detach

Theme toggle during the pre-transfer probing phase detached SyncFragment
while showArchCompatibilitySuccess() and its 1.5s postDelayed runnable
still called requireContext()/requireView() -> IllegalStateException
"Fragment not attached to a context" (crash at SyncFragment:849).

Same S8 lifecycle-guard pattern already applied to the dry-run callbacks
in #98, but this success/animation path ran just before the dry-run and
was left unguarded. Now: bail early if detached, use getContext() instead
of requireContext(), skip the requireView() snackbar when the view is
gone, and re-check isAdded()/getContext() inside the delayed runnable
before touching any view.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant