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 @@ -732,6 +732,13 @@ class TerminalBridge {
}
connecting = true

// A reconnect replaces the transport, and the one it replaces must end first. A
// tab-atelier session that is still redialling keeps its own relay reading into this
// emulator, so the new relay would write the same replay at a second offset. Closing
// it ends that relay's read. Only tab-atelier is closed here: SSH defers its close
// during a network grace period, and that deferral belongs to SSH.
(transport as? TabAtelier)?.close()

transport = newTransport
newTransport.bridge = this
newTransport.manager = manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,12 @@ class TerminalManager :
*/
fun requestReconnect(bridge: TerminalBridge) {
synchronized(pendingReconnect) {
pendingReconnect.add(WeakReference(bridge))
// Each tap on Reconnect asks again for the same session. Queuing it every time
// made reconnectPending start that session once per tap, so a bridge opened
// several transports, each with a relay writing into the same emulator.
if (pendingReconnect.none { it.get() === bridge }) {
pendingReconnect.add(WeakReference(bridge))
}
if (!bridge.isUsingNetwork() ||
connectivityMonitor.getCurrentNetworkInfo()?.isConnected == true
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.mockito.Mockito.doReturn
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.robolectric.RobolectricTestRunner
Expand Down Expand Up @@ -124,6 +125,38 @@ class TerminalManagerBellTest {
verify(manager).playBeep()
}

/**
* Pressing Reconnect repeatedly while the network is down must reconnect the bridge once.
*
* Each press used to queue the bridge again, so when the network came back it started
* the session once per press. Every extra transport had its own relay writing into the
* same emulator at a different offset, which showed as the output repeating in pieces.
*/
@Test
fun reconnectingWhileOfflineStartsTheSessionOnce() {
val bridge = bridge(hostA)
`when`(bridge.isUsingNetwork()).thenReturn(true)
val monitor = mock(ConnectivityMonitor::class.java)
`when`(monitor.getCurrentNetworkInfo()).thenReturn(null)
manager.connectivityMonitor = monitor

manager.requestReconnect(bridge)
manager.requestReconnect(bridge)
manager.requestReconnect(bridge)
verify(bridge, never()).startConnection()

val online = ConnectivityMonitor.NetworkInfo(
isConnected = true,
ipAddresses = emptySet(),
networkId = "wifi",
networkType = 1,
)
`when`(monitor.getCurrentNetworkInfo()).thenReturn(online)
manager.requestReconnect(bridge)

verify(bridge, times(1)).startConnection()
}

private fun bridge(host: Host): TerminalBridge {
val bridge = mock(TerminalBridge::class.java)
`when`(bridge.host).thenReturn(host)
Expand Down
37 changes: 37 additions & 0 deletions docs/upstream/01-shift-tab-modifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 01 — Shift, Ctrl and Alt were dropped from the Tab and Esc keys

**Upstreamable: yes, as a standalone fix. This does not depend on tab-atelier.**

## What was wrong

In `service/TerminalKeyListener.kt`, the keys bar's Esc and Tab sent their key with a
modifier value of `0`, then cleared the modifier state. Every other key on the bar honoured
the latched modifier. So a latched Shift was eaten by the key after it: Shift then Tab sent a
plain Tab. Ctrl and Alt behaved the same way.

## The change

Both calls pass the modifier state the rest of the bar already uses:

```kotlin
- keyDispatcher.dispatchKey(0, VTermKey.ESCAPE)
+ keyDispatcher.dispatchKey(modifiersForTerminal, VTermKey.ESCAPE)
- keyDispatcher.dispatchKey(0, VTermKey.TAB)
+ keyDispatcher.dispatchKey(modifiersForTerminal, VTermKey.TAB)
```

Two comment lines were added with a `Changed for Tab Atelier Remote` marker. Remove the marker
when offering the change upstream; keep the reasoning comment, which says why the value matters.

## How to upstream it

1. Branch from upstream `HEAD` (not from this fork).
2. Apply the two-line change and the comment, without the fork marker.
3. Add a regression test beside `TerminalKeyListenerTest.kt`: latch Shift, send Tab, and assert
the dispatched modifier includes Shift. Send Ctrl and Alt the same way.
4. Run upstream's own checks (`ci-build.yml`) before opening the pull request.

## Upstream churn

`TerminalKeyListener.kt` changed upstream once since the base. Read that upstream commit before
porting, since it may already touch the same two calls.
41 changes: 41 additions & 0 deletions docs/upstream/02-reconnect-single-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 02 — Reconnect started one session per press

**Upstreamable: in part.** The queue fix is generic and can go upstream. The transport close is
specific to tab-atelier and must stay here.

## What was wrong

Two things combined, and both are visible in the output as the same text written again at
different positions, which Ctrl+L hides until more output arrives.

1. `TerminalManager.requestReconnect` added the bridge to `pendingReconnect` on every call.
While the network was down, each press of Reconnect queued the bridge again. When the
network returned, `reconnectPending` started the bridge once per queued entry.
2. `TerminalBridge.startConnection` replaced `transport` without ending the previous one. A
tab-atelier session still redialling kept its relay reading into the same emulator, so the
new relay wrote a second copy of the replay.

## The change

- `TerminalManager.requestReconnect`: queue a bridge only if it is not already queued.
- `TerminalBridge.startConnection`: before replacing the transport, close it if it is a
tab-atelier transport: `(transport as? TabAtelier)?.close()`.
- Regression test `TerminalManagerBellTest.reconnectingWhileOfflineStartsTheSessionOnce`.

## How to upstream it

**The queue fix (`requestReconnect`):** offer it as its own pull request. The guard
`pendingReconnect.none { it.get() === bridge }` is generic. Write the test in
`TerminalManager`'s own test class rather than the bell test this fork uses. Upstream's
`TerminalManager` has changed since the base (8 commits), so check that the function still
looks the same before porting.

**The close (`startConnection`):** do not offer it. Upstream's SSH transport defers `close()`
during a network grace period, so ending the previous transport generically would change SSH
behaviour. If upstream wants a generic version, the first step is an `AbsTransport` method
that says whether closing a replaced transport is safe, with SSH answering no.

## Upstream churn

`TerminalBridge.kt` changed upstream 15 times since the base, and `TerminalManager.kt` 8 times.
Both need a hand merge in a sync, and the reconnect code is the part most likely to conflict.
43 changes: 43 additions & 0 deletions docs/upstream/03-tab-atelier-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 03 — The tab-atelier protocol

**Upstreamable: no.** This is a new transport for a server this project runs. It stays in
this fork. This document lists the pieces so a sync knows what to keep.

## What it is

A tab-atelier host is a server that serves terminal tabs over HTTP and a WebSocket. The app
attaches to one tab and replays its output. It is a viewer: the tab keeps running on the
server, and a dropped connection redials.

## The pieces

| Area | Files |
|---|---|
| Transport | `transport/TabAtelier.kt` (new), `transport/Transport.kt` (a `TabAtelier` object) |
| Client and addresses | `tabatelier/TabAtelierClient.kt`, `tabatelier/TabAtelierAddresses.kt`, `tabatelier/TabAtelierTab.kt` |
| Connection state and progress | `service/ConnectionState.kt`, `service/TabAtelierConnectionPolicy.kt`, `tabatelier/ConnectionProgress.kt`, `tabatelier/ConnectionEventListener.kt` |
| Tab selection | `tabatelier/SessionTabKeys.kt`, `service/TerminalManager.kt` (`switchTab`, tab keys), `ui/navigation/NavGraph.kt` (optional tab argument), `ui/MainActivity.kt` (pending tab) |
| Host data | `data/entity/Host.kt` (`tabAtelierUrl`, `tabAtelierUrls`), `data/ConnectBotDatabase.kt` and schemas 12 and 13 (migrations) |
| Editor and list | `ui/screens/hosteditor/*`, `ui/screens/hostlist/*`, `ui/screens/console/*` |
| Strings | `res/values/strings_tabatelier.xml`, `res/values-fr/strings_tabatelier.xml` |

## Why it cannot be upstreamed

A protocol is a product decision for the upstream maintainers, and this one only makes sense
against a server that is not part of ConnectBot. Offering it would put a dependency on
tab-atelier into an app that does not use it.

## What a sync must keep

- The database migrations (12 and 13). They are versioned after upstream's last schema, so an
upstream migration with the same number would collide. Renumber them when upstream adds one.
- `Host.kt` fields. The fork's schema JSON in `app/schemas` must be regenerated after a sync.
- The strings file is a separate resource, because upstream's `strings.xml` changes often
(26 upstream commits since the base). Keep new strings in `strings_tabatelier.xml`, not in
upstream's file.

## Notes on the editor

`HostEditorScreen` and `HostEditorViewModel` were changed in several places, and both are
among the most-changed upstream files (8 and 5 upstream commits). A sync should merge the
fields and the validation separately from the layout.
27 changes: 27 additions & 0 deletions docs/upstream/04-branding-and-removals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 04 — Branding, removed screens and strings

**Upstreamable: no.** These are the changes that make this a different app.

## The changes

- **Name:** `res/values/notrans.xml` sets `app_name` to `Tab Atelier Remote`.
- **Removed screen:** `ui/screens/contact/` (the upstream Contact screen) and its test
`ContactScreenTest.kt`. The route and the navigation to it are removed in `NavGraph.kt`.
- **Help screen:** `ui/screens/help/HelpScreen.kt` carries `Changed for Tab Atelier Remote`
markers at two places. The change is to upstream's text and links there.
- **Deep links:** `AndroidManifest.xml` adds the `tabatelier` scheme to two intent filters.
- **Strings:** upstream strings that name ConnectBot or link to its community were rewritten in
`res/values/strings.xml`. Strings the fork adds live in `strings_tabatelier.xml`.

## Why none of it goes upstream

Upstream's identity, its community links and its contact route are upstream's decisions. The
licence (Apache-2.0, section 4(b)) requires these changes to be marked, which is why each has a
`Changed for Tab Atelier Remote` comment. Keep the markers, so a sync can find them.

## What a sync must watch

`res/values/strings.xml` changed 26 times upstream since the base, and every localised
`values-*/strings.xml` changed too. A rewritten string is an edit in the middle of upstream's
file, so each one is a likely conflict. The fork's rule is to keep rewritten strings few, and
to prefer adding a new string in `strings_tabatelier.xml` over editing an upstream one.
30 changes: 30 additions & 0 deletions docs/upstream/05-build-and-versioning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 05 — Build, versioning and networking configuration

**Upstreamable: no**, with one exception that should be revisited rather than offered.

## The changes

- **Versioning.** `app/build.gradle.kts` removes upstream's `app-versioning` plugin, which
derives the version code and name from git tags. The fork sets the version from Gradle
properties and its own CI counter (`scripts/build-apk.sh`, `android-apk.yml`). The plugin
is still declared in `gradle/libs.versions.toml`; only its use in `app/build.gradle.kts` is
removed, so the catalogue entry is dead and can be dropped in a sync.
- **OkHttp.** `gradle/libs.versions.toml` adds `okhttp` 5.5.0. The tab-atelier client uses it
for HTTP and WebSocket. Upstream has no HTTP client in the app module, so this is a new
dependency, not a change to one of theirs.
- **Cleartext traffic.** `AndroidManifest.xml` sets `android:usesCleartextTraffic="true"`.

## Cleartext traffic needs revisiting

Enabling cleartext lets the app use `http://` on any host. Tab-atelier needs it because a LAN
daemon is often plain HTTP, but the setting is application-wide, so it also permits cleartext to
hosts the user never configured. The narrower option is a `network_security_config` that
permits cleartext only for the LAN ranges, or only for hosts the user has marked local. Upstream
would reject the global form, so it must not be offered upstream in its current shape.

## What a sync must watch

`app/build.gradle.kts` changed 25 times upstream and `gradle/libs.versions.toml` 55 times since
the base, so these are the first files a sync touches. Re-apply the versioning removal and the
OkHttp entry on top of upstream's current catalogue, and check the Gradle wrapper and AGP
versions in the same pass.
Loading
Loading