ADFA-4492 (step 3b-1) refactor(sync): concurrency + lifecycle hardening (S8/S9/S10)#98
Merged
Merged
Conversation
…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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).
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).