Repository navigation
fix: leave the terminal on Back - #11
Merged
Merged
Conversation
oonid
force-pushed
the
fix/terminal-back
branch
from
October 17, 2026 10:33
212a175 to
0352340
Compare
Back never reached TerminalActivity's OnBackPressedCallback, from the navigation button, the gesture, or a key event. With the keyboard up, the IME takes Back's key-down to hide itself and the activity sees a lone key-up. With it hidden, Compose takes the key-down to move focus from the terminal library's input view to the Compose root (dispatchKeyEvent: action=0 handled=true, focus=AndroidComposeView). Either way the activity never got a full press, so the terminal stayed open; leaving needed Home or the recents screen. TerminalActivity now handles Back before the view tree: a key-down followed by a key-up runs the back callback (cleanup and finish), and a lone key-up, the press the IME used to hide itself, is ignored. The first Back still hides the keyboard; the next one leaves. With a text selection active, Back clears it through termlib's SelectionController and stays, as it did before when the key reached termlib.
oonid
force-pushed
the
fix/terminal-back
branch
from
October 17, 2026 11:43
0352340 to
fc403d1
Compare
With Back working, Back ends the terminal session through the existing cleanup(); before, the key never reached the callback, so Back left the session alive. android-apk-architecture.md now lists how a session ends (Back, exit, Home, swipe-away), why nothing inside the container survives (--kill-on-exit), and the options for keeping a session after leaving its screen: Back as Home, sessions owned by an app-wide manager, and a user choice between ending and keeping. The follow-up is planned with the foreground service.
oonid
added a commit
that referenced
this pull request
Oct 17, 2026
build_proot_args_non_isolated_includes_prefix_and_mounts pointed TMPDIR at <its temp dir>/cache and then removed that temp dir. The other tests build their scratch paths with std::env::temp_dir(), which reads TMPDIR, and 25 of them do not take the env lock. One that ran in that window created its files inside the doomed tree and lost them: read_helpers_report_expected_access failed with `assertion failed: can_read_file(...)` on main's CI after #11, and in 1 of 40 local runs. Both tests that set TMPDIR now set it to the value temp_dir() already returns, so they still check that TMPDIR wins over the $APP_PREFIX/tmp fallback while no other test sees a different temp dir (build_proot_runtime_env_prefers_tmpdir_when_set used /tmp/custom-cache, where tests running in its window left directories), and they restore the caller's TMPDIR instead of removing it. 0 failures in 240 local runs with TMPDIR unset and 60 with it set.
oonid
added a commit
that referenced
this pull request
Oct 17, 2026
build_proot_args_non_isolated_includes_prefix_and_mounts pointed TMPDIR at <its temp dir>/cache and then removed that temp dir. The other tests build their scratch paths with std::env::temp_dir(), which reads TMPDIR, and 25 of them do not take the env lock. One that ran in that window created its files inside the doomed tree and lost them: read_helpers_report_expected_access failed with `assertion failed: can_read_file(...)` on main's CI after #11, and in 1 of 40 local runs. Both tests that set TMPDIR now set it to the value temp_dir() already returns, so they still check that TMPDIR wins over the $APP_PREFIX/tmp fallback while no other test sees a different temp dir (build_proot_runtime_env_prefers_tmpdir_when_set used /tmp/custom-cache, where tests running in its window left directories), and they restore the caller's TMPDIR instead of removing it. 0 failures in 240 local runs with TMPDIR unset and 60 with it set.
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.
Back never left the terminal: not the navigation button, not the gesture, not a Back key event. Leaving needed Home or the recents screen.
TerminalActivity'sOnBackPressedCallbacknever ran because the activity never saw a complete Back press:dispatchKeyEvent:code=4 action=0 handled=true focus=AndroidComposeView).TerminalActivity.dispatchKeyEventnow handles Back before the view tree: a key-down followed by a key-up runs the back callback (cleanup andfinish()), and a lone key-up (the press the IME used to hide itself) is ignored. The first Back still hides the keyboard; the next one leaves. With a text selection active (long press), Back clears it through termlib's publicSelectionController(onSelectionControllerAvailable) and stays, as main already did when the key reached termlib; the next Back leaves.docs/android-apk-architecture.mddescribes it.vendor/termlibis unchanged.Verification (Android 16, Samsung)
On main, three Back presses (adb key event) left the terminal open, with a live session and after
exit. With this change:mInputShown=false), the second returns to the distro list.exitin the shell: two presses return to the list.pr-cli test alpineandpr-cli test ubuntu55/55,pit allfrom an in-app terminal 55/55.Session lifetime (documented here, built in a follow-up)
Back now ends the session, through the existing callback (
cleanup()). Before this change the key never reached the callback, so Back left the terminal open and the session alive; an earlier lifecycle check that "survived Back" was measuring that. Because pr-cli starts proot with--kill-on-exit, nothing started inside the session outlives it (nohup,&,setsiddo not help).exitin the shellSo a long-running program such as the Hermes gateway needs Home, not Back, and still dies when Android reclaims the process. Options for keeping a session after leaving its screen, recorded in
android-apk-architecture.md("Session lifetime and Back"):moveTaskToBack): trivial, but lands on the launcher, not the distro list.This PR keeps the documented design (Back ends the session). Background sessions come in a follow-up together with the foreground service, which needs the same session manager and is what stops Android from killing the process.
The app module has no instrumented-test setup, so there is no automated test for this.