Skip to content

1.4.6: find the server on any network, follow it to a new IP, Quick Settings tile, custom cursor colour - #83

Merged
anasvhora284 merged 23 commits into
masterfrom
release/1.4.6
Nov 17, 2026
Merged

anasvhora284 merged 23 commits into
masterfrom
release/1.4.6

Conversation

@anasvhora284

@anasvhora284 anasvhora284 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Stable 1.4.6 (versionCode 16): finding the server on any network, following it when its address changes, a Quick Settings tile, a custom cursor colour, and a few input fixes.

Finding the server

  • Search every network, not just one. A phone on Wi-Fi that also shares a hotspot for the PC (wlan0 + wlan1 on OnePlus) only swept the first network's subnet, so a server reachable only over the hotspot never showed up. The scan now covers one address per /24 from every Wi-Fi, hotspot or private non-cellular interface, in parallel.
  • Follow the server to a new IP. With Auto-connect on launch on, the saved IP goes stale after a PC reboot, a hotspot restart or airplane mode. If it doesn't answer, the launch scan looks for the server presenting the same TLS certificate the user already trusted, moves the saved server (fingerprint, name, star, transport) to the new IP and connects there. It reuses the launch scan and stops at the first match (about 4 s after launch instead of about 8 s). Servers without a saved fingerprint (plain connections) keep the old behaviour. Hostname lookup was ruled out: Android doesn't resolve .local names and Deskflow advertises no mDNS service.

Quick Settings tile (#81)

  • Tapped while connected it disconnects from the shade, with no app. Tapped while not connected it opens the app, which connects to the last server and goes back to the background. (The connection setup lives in the app, not the service, so a fully headless connect would need a larger refactor.)
  • The tile has its own leaf-pointer icon. A framework drawable can't be used as a tile icon: the system hid the tile.

Cursor colour (#81)

  • Settings → Cursor style → Colour has a Custom swatch that opens a colour picker (hue, saturation, brightness bars with a live preview). The six presets still work and clear the custom colour.

Input fixes

Notification

  • A stale notification with a Disconnect button was left behind after disconnecting: the state watcher re-posted it after the service removed it. The watcher now stays quiet from a disconnect until the next connect.
  • The Disconnect button only shows while connected or connecting, and a connection that fails for good or is rejected takes the notification down.

Checks

Refs #73, #74, #81, #82

Summary by Sourcery

Release version 1.4.6 with resilient multi-network server discovery, Quick Settings connectivity controls, customizable cursor colours, input fixes, and F-Droid distribution support.

New Features:

  • Add Quick Settings controls for connecting to the last server or disconnecting an active connection.
  • Allow users to choose a custom Accessibility cursor colour with a colour picker.
  • Search all eligible local networks and automatically follow trusted TLS servers when their IP address changes.

Bug Fixes:

  • Fix keypad digits and decimal input, Esc and Alt+Left Back handling, and Android TV app-menu activation.
  • Prevent stale or misleading connection notifications after disconnects and terminal connection failures.

Enhancements:

  • Prepare the 1.4.6 release with optimized resource shrinking and improved F-Droid compatibility, including universal unsigned builds and package metadata.

Build:

  • Update the application to version 1.4.6, remove the unused device-names dependency, and support reproducible F-Droid builds without the private signing key.

Documentation:

  • Add F-Droid build and submission documentation plus release store metadata and assets.

Tests:

  • Expand coverage for multi-network discovery, certificate-based server relocation, input handling, cursor colours, preferences, TV navigation, and F-Droid update behavior.

A phone on Wi-Fi that also hosts a hotspot for the PC (wlan0 + wlan1 on
OnePlus) only swept wlan0's subnet, so a server reachable only over the
hotspot never showed up. Return one address per /24 from every Wi-Fi,
hotspot or private non-cellular interface and sweep them in parallel.
With auto-connect on, the saved server's IP goes stale after a PC
reboot, a hotspot restart or airplane mode. If it doesn't answer at
launch, search the local networks for the server presenting the same
trusted certificate, move the saved server (fingerprint, name, star,
transport) to its new IP and connect there. Servers without a saved
fingerprint keep the old behaviour.
Check the servers the launch scan finds as they arrive and stop at the
first certificate match, instead of waiting out a second full sweep of
every network. Also give up on the old IP after 0.7 s, not 1.5 s.
Finding the moved server dropped from ~8 s to ~4 s after launch.
…Deskflow

Input Leap and Deskflow send function keys as 0xEFxx; the Back check
only compared 0xFFxx, so it never matched (#73).
The menu is drawn upside down there, so Open is the last row, not the
first; accept either as the pre-selected row (#74).
Android's virtual keyboard starts with Num Lock off, so keypad digits
read as Home/End/arrows. The server only sends KP digits while its Num
Lock is on, so type the character in both the Shizuku/root and
Accessibility paths (#82).
A Custom swatch next to the six presets opens a hex-code field (#81).
Presets still work and clear the custom colour.
Tapped while connected it disconnects from the shade. Tapped while not
connected it opens the app, which connects to the last server (following
it to a new IP) and returns to the background (#81).
What's new covers the multi-network scan, following the PC to a new IP,
the Quick Settings tile, custom cursor colour, keypad digits and the
Back-key and TV launcher fixes.
Hue, saturation and brightness bars with a live preview replace the hex
field (#81).
…on moves

Black has no hue, so starting from the default black cursor made the first
two bars do nothing visible and look like they reset brightness.
Moving hue or saturation no longer changes brightness.
The drag handlers kept the first-composition lambdas, so every drag wrote
back the initial values of the other two bars. Read the current state.
The system can't load a framework drawable for a tile and hid it. The new
icon is a pointer with a leaf (#81).
A rounded leaf head with one connected vein, a stick tail like a pointer
and two waves, centred on the tile (#81).
The state watcher fired after disconnect() removed the foreground
notification and posted it again, leaving a stale Disconnect button with
nothing connected. Stay quiet from the disconnect until the next connect.
The notification kept a Disconnect action when nothing was connected. It
now shows only while connected or connecting, and a connection that fails
for good or is rejected takes the notification down.
@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Data structures

Review the persisted cursor-colour preference and server-migration logic that moves saved servers, favourites, names, fingerprints, transport settings, and the last-server address to a new IP.

  • app/src/main/java/com/inputleaf/android/storage/AppPreferences.kt L293-313 (+3 small edits)

Review the cursor-look model and hex conversion helpers that define how custom colours are represented and formatted.

  • app/src/main/java/com/inputleaf/android/service/CursorLook.kt L14-18, L24-32

API

Review the network-address selection API and TLS fingerprint probe used to find a moved, previously trusted server.

  • app/src/main/java/com/inputleaf/android/network/NetworkUtils.kt L12-35, L40-63 (+2 small edits)
  • app/src/main/java/com/inputleaf/android/network/ServerScanner.kt L97-126

Review the keypad-text resolution and Back-key policy interfaces that callers use for the updated input behavior.

  • app/src/main/java/com/inputleaf/android/inject/AccessibilityMousePolicy.kt L50-58
  • app/src/main/java/com/inputleaf/android/inject/KeysymResolver.kt L18-32, L39-41

Review the tile action and service declaration that expose Quick Settings connect and disconnect behavior.

  • app/src/main/AndroidManifest.xml L39-48
  • app/src/main/java/com/inputleaf/android/service/QuickConnectTileService.kt L1-104

Uses of the API

Review the keypad injection callers to ensure keypad characters bypass raw HID injection in both Shizuku and root paths.

  • app/src/main/java/com/inputleaf/android/shizuku/ShizukuInputInjector.kt L683, L727, L762-766

Review launch auto-connect and network scanning callers, including reuse of the scan to match a trusted certificate and migrate the server address.

  • app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt L48-56, L584-681 (+4 small edits)

Review how MainActivity handles tile launches, connects to the last server, and returns the task to the background after connection.

  • app/src/main/java/com/inputleaf/android/ui/MainActivity.kt L4-8, L51, L87-107

Implementation

Review foreground-service shutdown and notification watcher coordination for user disconnects, rejected connections, and terminal failures.

  • app/src/main/java/com/inputleaf/android/service/ConnectionService.kt L189-198, L676-688 (+4 small edits)
  • app/src/main/java/com/inputleaf/android/service/NotificationHelper.kt L44-49

Review cursor rendering to confirm the custom fill colour is applied while the outline and leaf cursor remain unchanged.

  • app/src/main/java/com/inputleaf/android/service/CursorOverlayView.kt L26-31

Review the TV launcher menu selection rule for menus opened above the app tile.

  • app/src/main/java/com/inputleaf/android/inject/TvLauncherMenu.kt L23-26

Review F-Droid update detection and the release version metadata kept in the update service.

  • app/src/main/java/com/inputleaf/android/update/UpdateService.kt L73-81 (+3 small edits)

UI

Review the Settings cursor-colour swatch, custom-colour dialog integration, and picker controls and preview.

  • app/src/main/java/com/inputleaf/android/ui/SettingsScreen.kt L714-726, L749-760 (+5 small edits)
  • app/src/main/java/com/inputleaf/android/ui/components/ColorPickerDialog.kt L1-149

Review the app-owned Quick Settings tile icon used to make the tile visible in the system shade.

  • app/src/main/res/drawable/ic_tile_connect.xml L1-17

Configuration

Review release versioning, optional signing, shrinking, native-library packaging, dependency metadata, ABI split controls, and removal of the unused device-names dependency.

  • app/build.gradle.kts L31-41, L49-56, L73-88 (+2 small edits)
  • app/proguard-rules.pro L1-18
  • gradle/libs.versions.toml L15 (removed lines), L48 (removed lines)

Review the F-Droid build recipe and fastlane store metadata added for the 1.4.6 release.

  • docs/fdroid/com.inputleaf.android.yml L1-30
  • fastlane/metadata/android/en-US/changelogs/16.txt L1-8
  • fastlane/metadata/android/en-US/full_description.txt L1-23
  • fastlane/metadata/android/en-US/short_description.txt L1
  • fastlane/metadata/android/en-US/title.txt L1
  • fastlane/metadata/android/en-US/images/featureGraphic.png
  • fastlane/metadata/android/en-US/images/icon.png
  • fastlane/metadata/android/en-US/images/phoneScreenshots/1.jpg
  • fastlane/metadata/android/en-US/images/phoneScreenshots/2.jpg
  • fastlane/metadata/android/en-US/images/phoneScreenshots/3.jpg
  • fastlane/metadata/android/en-US/images/phoneScreenshots/4.jpg
  • fastlane/metadata/android/en-US/images/phoneScreenshots/5.jpg
  • fastlane/metadata/android/en-US/images/phoneScreenshots/6.jpg

Documentation

Review the F-Droid maintainer guide for submission, build, signing, and local verification instructions.

  • docs/FDROID.md L1-25

Tests

Review tests covering keypad resolution, Back-key variants, and TV launcher menu selection.

  • app/src/test/java/com/inputleaf/android/inject/AccessibilityMousePolicyTest.kt L67-70
  • app/src/test/java/com/inputleaf/android/inject/KeysymResolverTest.kt L169-186
  • app/src/test/java/com/inputleaf/android/inject/TvLauncherMenuTest.kt L30-37, L68-69

Review tests for network interface selection, WifiManager fallback, and TLS fingerprint probing.

  • app/src/test/java/com/inputleaf/android/network/NetworkUtilsFallbackTest.kt L1-36
  • app/src/test/java/com/inputleaf/android/network/NetworkUtilsTest.kt L39-74
  • app/src/test/java/com/inputleaf/android/network/ServerScannerTest.kt L208-240
  • app/src/test/java/com/inputleaf/android/util/NetworkUtilsLocalIpTest.kt L17-20

Review tests for cursor colour parsing and persistence, server-address migration, and F-Droid update behavior.

  • app/src/test/java/com/inputleaf/android/service/CursorLookTest.kt L31-44
  • app/src/test/java/com/inputleaf/android/storage/AppPreferencesTest.kt L9-10, L40-73
  • app/src/test/java/com/inputleaf/android/update/UpdateServiceTest.kt L101, L341-351

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 10 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="app/src/main/java/com/inputleaf/android/ui/MainActivity.kt" line_range="98-101" />
<code_context>
+     * the user was doing once it's up. On failure the app stays so the error is visible.
+     */
+    private fun handleQuickConnect(intent: Intent?) {
+        if (intent?.action != ACTION_QUICK_CONNECT) return
+        intent.action = null
+        lifecycleScope.launch {
+            if (!viewModel.connectToLastServer()) return@launch
+            withTimeoutOrNull(30_000) {
+                viewModel.connectionState.first { it is ConnectionState.Idle || it is ConnectionState.Active }
</code_context>
<issue_to_address>
**Forged intent reconnects saved server**

When another installed app explicitly launches the exported activity with `ACTION_QUICK_CONNECT` while a last server is saved and the connection is disconnected, `MainActivity` accepts the action without checking its caller, then `connectToLastServer()` launches `autoConnect()` for the saved IP; a previously trusted server reconnects without a Quick Settings tile tap and can resume sending remote input.

Require an unforgeable tile-origin authorization for this action, or route the tile through a non-exported entry point that performs the connect.
</issue_to_address>

### Comment 2
<location path="app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt" line_range="671" />
<code_context>
+            .firstOrNull()
+            ?: return@withContext lastIp
+        Log.i("InputLeaf", "Last server moved from $lastIp to ${match.ip} (same certificate)")
+        prefs.moveServer(lastIp, match.ip)
+        match.ip
+    }
</code_context>
<issue_to_address>
**Removed server is re-added**

When the user removes the old server entry while auto-connect is searching for its new address, the auto-connect job does not check whether the user removed the saved server while certificate discovery was running. It can move the entry to the new IP and then call `connect`, whose `saveLastServer` write remembers that IP again, undoing the user's removal and reconnecting to the server.

Cancel or invalidate the in-flight auto-connect when the user removes that server, and recheck the user's current saved/last-server choice before moving or reconnecting it.

Also at `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt:642`.
</issue_to_address>

### Comment 3
<location path="app/src/main/java/com/inputleaf/android/service/QuickConnectTileService.kt" line_range="56" />
<code_context>
+
+    override fun onStartListening() {
+        // No BIND_AUTO_CREATE: a tile must not start the service just to read its state.
+        bound = bindService(Intent(this, ConnectionService::class.java), connection, 0)
+        if (!bound) state = ConnectionState.Disconnected
+        render()
</code_context>
<issue_to_address>
**Active connection stays connected**

When the tile is tapped before the asynchronous service binding delivers the active state, `onStartListening` renders the initial `Disconnected` state, and `onClick` opens the app instead of sending `ACTION_DISCONNECT`; the active connection remains connected.

Avoid treating the initial state as authoritative while binding is pending, and disconnect when the bound service reports an active connection.

Also at `app/src/main/java/com/inputleaf/android/service/QuickConnectTileService.kt:73-74`.
</issue_to_address>

### Comment 4
<location path="app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt" line_range="654" />
<code_context>
+     * fingerprint (plain connection) there's nothing safe to match on, so keep [lastIp].
+     */
+    private suspend fun autoConnectAddress(lastIp: String): String = withContext(Dispatchers.IO) {
+        if (isReachable(lastIp)) return@withContext lastIp
+        val trusted = prefs.fingerprintFor(lastIp).first()?.replace(":", "")?.lowercase()
+            ?: return@withContext lastIp
</code_context>
<issue_to_address>
**Occupied old address blocks recovery**

When the old IP has been reassigned to a different host that accepts TCP connections on the default server port, `isReachable` treats any TCP listener on the default port as the saved server, so auto-connect skips the certificate search when another host has taken the old address. `connect` then targets that host instead of finding the trusted server at its new IP, and the user cannot reconnect through the recovery path.

Before skipping recovery, verify that the old endpoint presents the saved fingerprint rather than treating an open TCP port as proof of identity.
</issue_to_address>

### Comment 5
<location path="app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt" line_range="605" />
<code_context>
-                if (ip != null) {
-                    scanner.scan(ip) { server ->
-                        if (server.name.isNotBlank() && server.name != server.ip) {
-                            viewModelScope.launch { prefs.saveServerName(server.ip, server.name) }
-                        }
-                        _discoveredServers.update { currentServers ->
</code_context>
<issue_to_address>
**Stale server entry returns**

When a scan callback for the old IP is still pending when relocation commits, `saveServerName` calls `rememberServer`, so a pending name save after `moveServer` adds the old IP back to saved servers; the user sees both the relocated server and its stale entry.

Prevent a pending name save for the old IP from re-adding it after relocation.

Also at `app/src/main/java/com/inputleaf/android/storage/AppPreferences.kt:298`, `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt:672`.
</issue_to_address>

### Comment 6
<location path="app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt" line_range="631" />
<code_context>
+        if (state !is ConnectionState.Disconnected) return true
+        userRequestedDisconnect = false
+        // The connect itself needs the bound service; the tile can beat the binding.
+        withTimeoutOrNull(3000) { while (service == null) delay(50) }
+        autoConnect(lastIp)
+        return true
</code_context>
<issue_to_address>
**Tile connect is lost on slow binding**

When the service binding takes longer than three seconds and auto-connect is disabled, `connectToLastServer` continues after its 3-second wait expires, so `autoConnect` can reach `connect` while `service` is still null. `connect` then reports that the service is not ready and returns; with auto-connect disabled, the later service bind does not retry, so the tile tap never connects.

Do not report the tile request as handled until the service is available; retry the requested connection after binding or surface a definitive failure to the caller.
</issue_to_address>

### Comment 7
<location path="app/src/main/java/com/inputleaf/android/network/NetworkUtils.kt" line_range="25" />
<code_context>
-                }
+            val candidates = interfaces
+                .filter { it.isUp && !it.isLoopback }
+                .map { iface -> iface.name to listOfNotNull(getIPv4FromInterface(iface)) }
+            candidates.filter { it.second.isNotEmpty() }
+                .forEach { (name, addrs) -> Log.d(TAG, "Interface $name: $addrs") }
</code_context>
<issue_to_address>
**Servers on secondary subnets are missed**

When an eligible interface has IPv4 addresses on more than one subnet, `getIPv4FromInterface` returns only the first IPv4 address, and the caller passes that single address to `scanAddresses`; servers reachable through the interface's other subnet are never discovered.

Collect and pass every IPv4 address on each eligible interface to `scanAddresses`.
</issue_to_address>

### Comment 8
<location path="app/src/main/java/com/inputleaf/android/network/NetworkUtils.kt" line_range="25-58" />
<code_context>
+                .map { iface -> iface.name to listOfNotNull(getIPv4FromInterface(iface)) }
</code_context>
<issue_to_address>
**Servers on overlapping networks are missed**

When separate interfaces use the same /24 prefix but reach different networks, `distinctBy` keeps only one address for that /24, so the scanner does not probe the other interface's network and misses servers reachable only there.

Deduplicate scan addresses without collapsing addresses from separate interfaces that share a /24 prefix.
</issue_to_address>

### Comment 9
<location path="app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt" line_range="663" />
<code_context>
+        val checked = mutableSetOf(lastIp)
+        val match = combine(_discoveredServers, _isScanning, ::Pair)
+            .transformWhile { (servers, scanning) ->
+                val hit = servers.filter { checked.add(it.ip) }
+                    .firstOrNull { scanner.fingerprintOf(it.ip) == trusted }
+                if (hit != null) emit(hit)
</code_context>
<issue_to_address>
**Stale discovery moves the saved server**

When a rescan follows an earlier scan and an old discovered address still presents the saved certificate, `autoConnectAddress` checks every address already in `_discoveredServers` before the new scan has refreshed it. A stale entry presenting the trusted certificate is accepted and passed to `moveServer`, so the saved server is moved to an address that no longer hosts it.

Clear or generation-tag discovered results when starting a scan, and only match addresses reported by that scan.
</issue_to_address>

### Comment 10
<location path="app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt" line_range="663-664" />
<code_context>
+        val checked = mutableSetOf(lastIp)
+        val match = combine(_discoveredServers, _isScanning, ::Pair)
+            .transformWhile { (servers, scanning) ->
+                val hit = servers.filter { checked.add(it.ip) }
+                    .firstOrNull { scanner.fingerprintOf(it.ip) == trusted }
+                if (hit != null) emit(hit)
+                hit == null && scanning
</code_context>
<issue_to_address>
**Moved server can be skipped**

When multiple servers are discovered while a fingerprint check is in progress and the trusted server is not the first candidate in the next conflated emission, `filter` adds every newly observed server IP to `checked` before `firstOrNull` tests only the first candidate. If `StateFlow` conflates scan updates while a fingerprint check is blocking, later candidates in that emission are marked checked without being tested, so relocation can miss the trusted server and fall back to the stale IP.

Mark each address checked only as it is actually fingerprint-tested, and continue testing every candidate in each emission until a match is found.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +98 to +101
if (intent?.action != ACTION_QUICK_CONNECT) return
intent.action = null
lifecycleScope.launch {
if (!viewModel.connectToLastServer()) return@launch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Forged intent reconnects saved server

When another installed app explicitly launches the exported activity with ACTION_QUICK_CONNECT while a last server is saved and the connection is disconnected, MainActivity accepts the action without checking its caller, then connectToLastServer() launches autoConnect() for the saved IP; a previously trusted server reconnects without a Quick Settings tile tap and can resume sending remote input.

Require an unforgeable tile-origin authorization for this action, or route the tile through a non-exported entry point that performs the connect.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/ui/MainActivity.kt` at lines 98-101:

**Forged intent reconnects saved server**

When another installed app explicitly launches the exported activity with `ACTION_QUICK_CONNECT` while a last server is saved and the connection is disconnected, `MainActivity` accepts the action without checking its caller, then `connectToLastServer()` launches `autoConnect()` for the saved IP; a previously trusted server reconnects without a Quick Settings tile tap and can resume sending remote input.

Require an unforgeable tile-origin authorization for this action, or route the tile through a non-exported entry point that performs the connect.

.firstOrNull()
?: return@withContext lastIp
Log.i("InputLeaf", "Last server moved from $lastIp to ${match.ip} (same certificate)")
prefs.moveServer(lastIp, match.ip)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Removed server is re-added

When the user removes the old server entry while auto-connect is searching for its new address, the auto-connect job does not check whether the user removed the saved server while certificate discovery was running. It can move the entry to the new IP and then call connect, whose saveLastServer write remembers that IP again, undoing the user's removal and reconnecting to the server.

Cancel or invalidate the in-flight auto-connect when the user removes that server, and recheck the user's current saved/last-server choice before moving or reconnecting it.

Also at app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt:642.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt` at line 671:

**Removed server is re-added**

When the user removes the old server entry while auto-connect is searching for its new address, the auto-connect job does not check whether the user removed the saved server while certificate discovery was running. It can move the entry to the new IP and then call `connect`, whose `saveLastServer` write remembers that IP again, undoing the user's removal and reconnecting to the server.

Cancel or invalidate the in-flight auto-connect when the user removes that server, and recheck the user's current saved/last-server choice before moving or reconnecting it.

Also at `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt:642`.


override fun onStartListening() {
// No BIND_AUTO_CREATE: a tile must not start the service just to read its state.
bound = bindService(Intent(this, ConnectionService::class.java), connection, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Active connection stays connected

When the tile is tapped before the asynchronous service binding delivers the active state, onStartListening renders the initial Disconnected state, and onClick opens the app instead of sending ACTION_DISCONNECT; the active connection remains connected.

Avoid treating the initial state as authoritative while binding is pending, and disconnect when the bound service reports an active connection.

Also at app/src/main/java/com/inputleaf/android/service/QuickConnectTileService.kt:73-74.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/service/QuickConnectTileService.kt` at line 56:

**Active connection stays connected**

When the tile is tapped before the asynchronous service binding delivers the active state, `onStartListening` renders the initial `Disconnected` state, and `onClick` opens the app instead of sending `ACTION_DISCONNECT`; the active connection remains connected.

Avoid treating the initial state as authoritative while binding is pending, and disconnect when the bound service reports an active connection.

Also at `app/src/main/java/com/inputleaf/android/service/QuickConnectTileService.kt:73-74`.

* fingerprint (plain connection) there's nothing safe to match on, so keep [lastIp].
*/
private suspend fun autoConnectAddress(lastIp: String): String = withContext(Dispatchers.IO) {
if (isReachable(lastIp)) return@withContext lastIp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Occupied old address blocks recovery

When the old IP has been reassigned to a different host that accepts TCP connections on the default server port, isReachable treats any TCP listener on the default port as the saved server, so auto-connect skips the certificate search when another host has taken the old address. connect then targets that host instead of finding the trusted server at its new IP, and the user cannot reconnect through the recovery path.

Before skipping recovery, verify that the old endpoint presents the saved fingerprint rather than treating an open TCP port as proof of identity.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt` at line 654:

**Occupied old address blocks recovery**

When the old IP has been reassigned to a different host that accepts TCP connections on the default server port, `isReachable` treats any TCP listener on the default port as the saved server, so auto-connect skips the certificate search when another host has taken the old address. `connect` then targets that host instead of finding the trusted server at its new IP, and the user cannot reconnect through the recovery path.

Before skipping recovery, verify that the old endpoint presents the saved fingerprint rather than treating an open TCP port as proof of identity.

async {
scanner.scan(ip) { server ->
if (server.name.isNotBlank() && server.name != server.ip) {
viewModelScope.launch { prefs.saveServerName(server.ip, server.name) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Stale server entry returns

When a scan callback for the old IP is still pending when relocation commits, saveServerName calls rememberServer, so a pending name save after moveServer adds the old IP back to saved servers; the user sees both the relocated server and its stale entry.

Prevent a pending name save for the old IP from re-adding it after relocation.

Also at app/src/main/java/com/inputleaf/android/storage/AppPreferences.kt:298, app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt:672.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt` at line 605:

**Stale server entry returns**

When a scan callback for the old IP is still pending when relocation commits, `saveServerName` calls `rememberServer`, so a pending name save after `moveServer` adds the old IP back to saved servers; the user sees both the relocated server and its stale entry.

Prevent a pending name save for the old IP from re-adding it after relocation.

Also at `app/src/main/java/com/inputleaf/android/storage/AppPreferences.kt:298`, `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt:672`.

if (state !is ConnectionState.Disconnected) return true
userRequestedDisconnect = false
// The connect itself needs the bound service; the tile can beat the binding.
withTimeoutOrNull(3000) { while (service == null) delay(50) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Tile connect is lost on slow binding

When the service binding takes longer than three seconds and auto-connect is disabled, connectToLastServer continues after its 3-second wait expires, so autoConnect can reach connect while service is still null. connect then reports that the service is not ready and returns; with auto-connect disabled, the later service bind does not retry, so the tile tap never connects.

Do not report the tile request as handled until the service is available; retry the requested connection after binding or surface a definitive failure to the caller.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt` at line 631:

**Tile connect is lost on slow binding**

When the service binding takes longer than three seconds and auto-connect is disabled, `connectToLastServer` continues after its 3-second wait expires, so `autoConnect` can reach `connect` while `service` is still null. `connect` then reports that the service is not ready and returns; with auto-connect disabled, the later service bind does not retry, so the tile tap never connects.

Do not report the tile request as handled until the service is available; retry the requested connection after binding or surface a definitive failure to the caller.

}
val candidates = interfaces
.filter { it.isUp && !it.isLoopback }
.map { iface -> iface.name to listOfNotNull(getIPv4FromInterface(iface)) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Servers on secondary subnets are missed

When an eligible interface has IPv4 addresses on more than one subnet, getIPv4FromInterface returns only the first IPv4 address, and the caller passes that single address to scanAddresses; servers reachable through the interface's other subnet are never discovered.

Collect and pass every IPv4 address on each eligible interface to scanAddresses.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/network/NetworkUtils.kt` at line 25:

**Servers on secondary subnets are missed**

When an eligible interface has IPv4 addresses on more than one subnet, `getIPv4FromInterface` returns only the first IPv4 address, and the caller passes that single address to `scanAddresses`; servers reachable through the interface's other subnet are never discovered.

Collect and pass every IPv4 address on each eligible interface to `scanAddresses`.

Comment on lines +25 to +58
.map { iface -> iface.name to listOfNotNull(getIPv4FromInterface(iface)) }
candidates.filter { it.second.isNotEmpty() }
.forEach { (name, addrs) -> Log.d(TAG, "Interface $name: $addrs") }
val ips = scanAddresses(candidates)
if (ips.isNotEmpty()) {
Log.d(TAG, "Scanning from $ips")
return ips
}
} catch (e: Exception) {
Log.e(TAG, "Error getting IP address: ${e.message}", e)
}


// WifiManager fallback for older Android or edge cases
val wifiIp = getWifiManagerIp(app)
if (wifiIp != null && wifiIp != "0.0.0.0") {
Log.d(TAG, "Using WifiManager IP: $wifiIp")
return listOf(wifiIp)
}
Log.e(TAG, "Could not determine local IP address")
return null
return emptyList()
}


/**
* Picks the addresses to scan from (interface name, IPv4 addresses) pairs: known
* Wi-Fi/hotspot interfaces first and with any address, other non-cellular
* interfaces only with a private one. One address per /24, since that's what
* [ServerScanner] sweeps.
*/
internal fun scanAddresses(interfaces: List<Pair<String, List<String>>>): List<String> =
interfaces
.filterNot { (name, _) -> CELLULAR_PREFIXES.any { name.startsWith(it) } }
.sortedBy { (name, _) -> WIFI_INTERFACE_NAMES.indexOf(name).let { if (it < 0) Int.MAX_VALUE else it } }
.flatMap { (name, addrs) -> addrs.filter { name in WIFI_INTERFACE_NAMES || isPrivateIP(it) } }
.distinctBy { it.substringBeforeLast('.') }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Servers on overlapping networks are missed

When separate interfaces use the same /24 prefix but reach different networks, distinctBy keeps only one address for that /24, so the scanner does not probe the other interface's network and misses servers reachable only there.

Deduplicate scan addresses without collapsing addresses from separate interfaces that share a /24 prefix.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/network/NetworkUtils.kt` at lines 25-58:

**Servers on overlapping networks are missed**

When separate interfaces use the same /24 prefix but reach different networks, `distinctBy` keeps only one address for that /24, so the scanner does not probe the other interface's network and misses servers reachable only there.

Deduplicate scan addresses without collapsing addresses from separate interfaces that share a /24 prefix.

val checked = mutableSetOf(lastIp)
val match = combine(_discoveredServers, _isScanning, ::Pair)
.transformWhile { (servers, scanning) ->
val hit = servers.filter { checked.add(it.ip) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Stale discovery moves the saved server

When a rescan follows an earlier scan and an old discovered address still presents the saved certificate, autoConnectAddress checks every address already in _discoveredServers before the new scan has refreshed it. A stale entry presenting the trusted certificate is accepted and passed to moveServer, so the saved server is moved to an address that no longer hosts it.

Clear or generation-tag discovered results when starting a scan, and only match addresses reported by that scan.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt` at line 663:

**Stale discovery moves the saved server**

When a rescan follows an earlier scan and an old discovered address still presents the saved certificate, `autoConnectAddress` checks every address already in `_discoveredServers` before the new scan has refreshed it. A stale entry presenting the trusted certificate is accepted and passed to `moveServer`, so the saved server is moved to an address that no longer hosts it.

Clear or generation-tag discovered results when starting a scan, and only match addresses reported by that scan.

Comment on lines +663 to +664
val hit = servers.filter { checked.add(it.ip) }
.firstOrNull { scanner.fingerprintOf(it.ip) == trusted }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Moved server can be skipped

When multiple servers are discovered while a fingerprint check is in progress and the trusted server is not the first candidate in the next conflated emission, filter adds every newly observed server IP to checked before firstOrNull tests only the first candidate. If StateFlow conflates scan updates while a fingerprint check is blocking, later candidates in that emission are marked checked without being tested, so relocation can miss the trusted server and fall back to the stale IP.

Mark each address checked only as it is actually fingerprint-tested, and continue testing every candidate in each emission until a match is found.

Prompt for AI agents
In `app/src/main/java/com/inputleaf/android/ui/MainViewModel.kt` at lines 663-664:

**Moved server can be skipped**

When multiple servers are discovered while a fingerprint check is in progress and the trusted server is not the first candidate in the next conflated emission, `filter` adds every newly observed server IP to `checked` before `firstOrNull` tests only the first candidate. If `StateFlow` conflates scan updates while a fingerprint check is blocking, later candidates in that emission are marked checked without being tested, so relocation can miss the trusted server and fall back to the stale IP.

Mark each address checked only as it is actually fingerprint-tested, and continue testing every candidate in each emission until a match is found.

Sign only when the gitignored keystore exists, leave Google's dependency
list out of the APK, and build one universal APK under -PnoAbiSplits
(F-Droid wants one APK per versionCode). The normal release build is
unchanged: same five APKs, same signing certificate.
F-Droid delivers its own updates, so the in-app check now stops at the
install source instead of querying the GitHub API.
Title, descriptions, icon, feature graphic, screenshots and the 1.4.6
changelog under fastlane/, plus the fdroiddata recipe and a maintainer
note. fdroid lint passes on the recipe.
F-Droid asked for R8. Release builds now minify and shrink resources: the
universal APK goes from 15.8 MB to 2.7 MB.

proguard-rules.pro was never applied (no proguardFiles) and kept every class,
so it is replaced by rules for what is only reached by name: the app_process
entry points, the Shizuku UserService and libsu RootService constructors, the
private Shizuku.newProcess, and libsu's RootServerMain, which its root
launcher loads by its literal name.

Native libraries are kept unstripped so the APK is the same on any build
machine (F-Droid patches this in for 1.4.6), and the unused
android-device-names library, which shipped a 1.4 MB database, is dropped.
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…be defaults

Codecov flagged 7 uncovered lines on #83. getLocalIpAddresses takes the interface
list so a test can reach the WifiManager fallback, which now looks WifiManager up
by WIFI_SERVICE (Robolectric can't resolve getSystemService(Class) on Application).
@anasvhora284
anasvhora284 merged commit 2524520 into master Nov 17, 2026
5 checks passed
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