v1.6.3: fix Android notification SOCKS5 port mismatch (#211)

buildNotif() hardcoded `proxyPort + 1` for the SOCKS5 line, ignoring
cfg.socks5Port entirely. With the default Android config
(listenPort=8080, socks5Port=1081) the foreground notification read
"Routing via SOCKS5 127.0.0.1:8081" but the real listener was on 1081 —
so users configuring per-app SOCKS5 (Telegram, etc.) against the
notification value silently failed.

Use the same `cfg.socks5Port ?: (cfg.listenPort + 1)` elvis fallback the
real listener uses, and surface both ports in the notification:
  HTTP 127.0.0.1:8080  ·  SOCKS5 127.0.0.1:1081

Reported by vpnineh and l3est (with netstat screenshots showing the
exact mismatch).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
therealaleph
2026-04-26 00:28:46 +03:00
parent 3f014b003b
commit 2c8fcc75aa
5 changed files with 21 additions and 7 deletions
@@ -91,7 +91,17 @@ class MhrvVpnService : VpnService() {
// path below MUST therefore happen after a `startForeground()`
// call — otherwise the user-visible symptom is "the app crashes
// the instant I tap Start". See issue #73.
startForeground(NOTIF_ID, buildNotif(cfg.listenPort))
// Issue #211: notification used to display
// `127.0.0.1:${listenPort + 1}` for the SOCKS5 port, which is
// wrong whenever socks5Port doesn't equal listenPort+1. With the
// default Android config (listenPort=8080, socks5Port=1081)
// users saw "Routing via SOCKS5 127.0.0.1:8081" but the real
// listener was on 1081 — so per-app SOCKS5 setup against the
// notification value silently failed. Pass the actual socks5Port
// (after the same elvis fallback used elsewhere) so the
// notification matches reality.
val notifSocks5Port = cfg.socks5Port ?: (cfg.listenPort + 1)
startForeground(NOTIF_ID, buildNotif(cfg.listenPort, notifSocks5Port))
// Deployment ID + auth key are required for apps_script and full
// modes — both talk to Apps Script. Only google_only (bootstrap)
@@ -424,7 +434,7 @@ class MhrvVpnService : VpnService() {
Log.i(TAG, "onDestroy done")
}
private fun buildNotif(proxyPort: Int): Notification {
private fun buildNotif(httpPort: Int, socks5Port: Int): Notification {
val mgr = getSystemService(NotificationManager::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val ch = NotificationChannel(
@@ -451,7 +461,7 @@ class MhrvVpnService : VpnService() {
)
return NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("mhrv-rs VPN is active")
.setContentText("Routing via SOCKS5 127.0.0.1:${proxyPort + 1}")
.setContentText("HTTP 127.0.0.1:$httpPort · SOCKS5 127.0.0.1:$socks5Port")
.setSmallIcon(android.R.drawable.presence_online)
.setContentIntent(openIntent)
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Stop", stopIntent)