fix vpn notification, add more logs under debug flag

This commit is contained in:
kulikov0 committed 2026-07-25 12:23:41 +02:00
1 parent d66be97922
commit 2dbc6ea1eb
17 files changed
+90 -27

No files matched your search

@@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
@@ -1,10 +1,13 @@
package bypass.whitelist
import android.Manifest
import android.animation.ArgbEvaluator
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Intent
import android.content.pm.PackageManager
import android.net.VpnService
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
@@ -16,6 +19,7 @@ import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
@@ -101,11 +105,19 @@ class MainActivity :
else appendLog("VPN permission denied")
}
private val notificationPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { granted ->
if (!granted) appendLog("Notification permission denied")
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
requestNotificationPermissionIfNeeded()
bottomNav = findViewById(R.id.bottomNav)
navMain = findViewById(R.id.navMain)
navSettings = findViewById(R.id.navSettings)
@@ -473,6 +485,16 @@ class MainActivity :
if (intent != null) vpnLauncher.launch(intent) else startVpnService()
}
private fun requestNotificationPermissionIfNeeded() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return
val granted = ContextCompat.checkSelfPermission(
this,
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
if (granted) return
notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
private fun handleIntent(intent: Intent?) {
if (intent?.action != ACTION_AUTO_START) return
intent.action = null
+6 -2
View File
@@ -379,7 +379,9 @@ func (b *Bridge) handleMessage(raw []byte) {
}
if ud, ok := msg["updateDescription"]; ok {
log.Printf("[tm-ws] <- updateDescription %s", tmapi.BriefJSON(ud))
if common.Debug {
log.Printf("[tm-ws] <- updateDescription %s", tmapi.BriefJSON(ud))
}
udMap, _ := ud.(map[string]interface{})
descs, _ := udMap["description"].([]interface{})
b.applyDescriptionSnapshot(descs)
@@ -440,7 +442,9 @@ func (b *Bridge) handleMessage(raw []byte) {
}
if sc, ok := msg["slotsConfig"]; ok {
log.Printf("[tm-ws] <- slotsConfig %s", tmapi.BriefJSON(sc))
if common.Debug {
log.Printf("[tm-ws] <- slotsConfig %s", tmapi.BriefJSON(sc))
}
needRebind := false
presentPids := make(map[string]bool)
for _, ev := range tmapi.SlotsConfigBindings(sc) {
+1 -1
View File
@@ -271,7 +271,7 @@ func (r *SFURelay) readTrack(track *webrtc.TrackRemote) {
continue
}
recvCount++
if recvCount <= 3 || recvCount%200 == 0 {
if common.Debug && (recvCount <= 3 || recvCount%200 == 0) {
log.Printf("[video] recv vp8 frame #%d %d bytes", recvCount, len(frameBuf))
}
+7 -3
View File
@@ -106,14 +106,18 @@ func (u *TunnelRelay) Init(iceServers []webrtc.ICEServer) error {
if err == nil {
dcNotif.OnOpen(func() { log.Println("[relay] producerNotification DC opened") })
dcNotif.OnMessage(func(msg webrtc.DataChannelMessage) {
log.Printf("[relay] producerNotification msg len=%d", len(msg.Data))
if common.Debug {
log.Printf("[relay] producerNotification msg len=%d", len(msg.Data))
}
})
}
dcCmd, err := pc.CreateDataChannel("producerCommand", &webrtc.DataChannelInit{Ordered: &ordered})
if err == nil {
dcCmd.OnOpen(func() { log.Println("[relay] producerCommand DC opened") })
dcCmd.OnMessage(func(msg webrtc.DataChannelMessage) {
log.Printf("[relay] producerCommand msg len=%d", len(msg.Data))
if common.Debug {
log.Printf("[relay] producerCommand msg len=%d", len(msg.Data))
}
})
}
producerScreen, psErr := pc.CreateDataChannel("producerScreenShare", &webrtc.DataChannelInit{Ordered: &ordered})
@@ -459,7 +463,7 @@ func (u *TunnelRelay) readTrack(track *webrtc.TrackRemote) {
continue
}
recvCount++
if recvCount <= 3 || recvCount%200 == 0 {
if common.Debug && (recvCount <= 3 || recvCount%200 == 0) {
log.Printf("[video] recv vp8 frame #%d %d bytes", recvCount, len(frameBuf))
}
+4 -1
View File
@@ -13,6 +13,7 @@ import (
"github.com/pion/rtp/codecs"
"github.com/pion/webrtc/v4"
"whitelist-bypass/relay/common"
"whitelist-bypass/relay/tunnel"
)
@@ -500,7 +501,9 @@ func (c *Call) handleSpeakerCamStateChanged(params SpeakerCamStateChangedParams)
c.peersByID[params.SessionID] = &PeerEntry{SessionID: params.SessionID, CamState: params.CamState, JoinedAt: time.Now()}
}
c.peersMu.Unlock()
c.cfg.LogFn("[call] speaker_cam_state_changed session_id=%s cam=%v", params.SessionID, params.CamState)
if common.Debug {
c.cfg.LogFn("[call] speaker_cam_state_changed session_id=%s cam=%v", params.SessionID, params.CamState)
}
if params.CamState {
c.subscribeIfNeeded(params.SessionID)
}
+8 -2
View File
@@ -13,6 +13,8 @@ import (
"time"
"github.com/gorilla/websocket"
"whitelist-bypass/relay/common"
)
const (
@@ -549,11 +551,15 @@ func (c *SignalingClient) ReadLoop() error {
}
var frame Frame
if err := json.Unmarshal(raw, &frame); err != nil {
c.logFn("dion: drop non-json frame: %v", err)
if common.Debug {
c.logFn("dion: drop non-json frame: %v", err)
}
continue
}
if frame.Error != nil {
c.logFn("dion: <- %s ERROR code=%d message=%q", frame.Method, frame.Error.Code, frame.Error.Message)
if common.Debug {
c.logFn("dion: <- %s ERROR code=%d message=%q", frame.Method, frame.Error.Code, frame.Error.Message)
}
}
c.dispatch(frame)
}
+4 -2
View File
@@ -367,7 +367,9 @@ func (c *Client) handleSignal(data []byte) {
c.OnParticipantUpdate(sr.Participants)
}
default:
c.logFn("[lk] <- signal kind=%d (%d bytes)", sr.Kind, len(data))
if common.Debug {
c.logFn("[lk] <- signal kind=%d (%d bytes)", sr.Kind, len(data))
}
}
}
@@ -476,7 +478,7 @@ func (c *Client) PingLoop() {
return
}
sentN++
if sentN <= 3 || sentN%12 == 0 {
if common.Debug && (sentN <= 3 || sentN%12 == 0) {
c.logFn("[lk] ping #%d sent", sentN)
}
}
@@ -741,7 +741,9 @@ func (j *TelemostHeadlessJoiner) handleMessage(raw []byte) {
}
if ud, ok := msg["updateDescription"]; ok {
j.logFn("telemost-joiner: <- updateDescription %s", tmapi.BriefJSON(ud))
if common.Debug {
j.logFn("telemost-joiner: <- updateDescription %s", tmapi.BriefJSON(ud))
}
j.ack(uid)
return
}
@@ -753,7 +755,9 @@ func (j *TelemostHeadlessJoiner) handleMessage(raw []byte) {
}
if sc, ok := msg["slotsConfig"]; ok {
j.logFn("telemost-joiner: <- slotsConfig %s", tmapi.BriefJSON(sc))
if common.Debug {
j.logFn("telemost-joiner: <- slotsConfig %s", tmapi.BriefJSON(sc))
}
needRebind := false
presentPids := make(map[string]bool)
for _, ev := range tmapi.SlotsConfigBindings(sc) {
@@ -817,7 +821,9 @@ func (j *TelemostHeadlessJoiner) handleMessage(raw []byte) {
if k == "uid" || k == "ack" {
continue
}
j.logFn("telemost-joiner: <- %s (unhandled) %s", k, tmapi.BriefJSON(v))
if common.Debug {
j.logFn("telemost-joiner: <- %s (unhandled) %s", k, tmapi.BriefJSON(v))
}
break
}
+1 -1
View File
@@ -217,7 +217,7 @@ func ReadTrack(track *webrtc.TrackRemote, handler func([]byte), logFn func(strin
continue
}
recvCount++
if recvCount <= 3 || recvCount%200 == 0 {
if common.Debug && (recvCount <= 3 || recvCount%200 == 0) {
logFn("%s: recv vp8 frame #%d %d bytes", prefix, recvCount, len(frameBuf))
}
if handler != nil {
+12 -4
View File
@@ -46,7 +46,9 @@ func (c *VKClient) handleMessage(raw []byte) {
if err := json.Unmarshal(raw, &msg); err != nil {
return
}
c.logFn("vk: >> msg type=%s id=%d", msg.Type, msg.ID)
if common.Debug {
c.logFn("vk: >> msg type=%s id=%d", msg.Type, msg.ID)
}
switch msg.Type {
case "ice-servers":
@@ -66,7 +68,9 @@ func (c *VKClient) handleMessage(raw []byte) {
case "close":
c.cleanup()
}
c.logFn("vk: << msg type=%s id=%d done", msg.Type, msg.ID)
if common.Debug {
c.logFn("vk: << msg type=%s id=%d done", msg.Type, msg.ID)
}
}
func (c *VKClient) createPC(config webrtc.Configuration) error {
@@ -96,7 +100,9 @@ func (c *VKClient) createPC(config webrtc.Configuration) error {
c.logFn("vk: producerNotification DC opened")
})
dcNotif.OnMessage(func(msg webrtc.DataChannelMessage) {
c.logFn("vk: producerNotification msg len=%d isString=%v", len(msg.Data), msg.IsString)
if common.Debug {
c.logFn("vk: producerNotification msg len=%d isString=%v", len(msg.Data), msg.IsString)
}
// Forward to Node bridge as sfu-dc-message
c.SendToHook("sfu-dc-message", map[string]interface{}{
"channel": "producerNotification",
@@ -113,7 +119,9 @@ func (c *VKClient) createPC(config webrtc.Configuration) error {
c.logFn("vk: producerCommand DC opened")
})
dcCmd.OnMessage(func(msg webrtc.DataChannelMessage) {
c.logFn("vk: producerCommand msg len=%d", len(msg.Data))
if common.Debug {
c.logFn("vk: producerCommand msg len=%d", len(msg.Data))
}
c.SendToHook("sfu-dc-message", map[string]interface{}{
"channel": "producerCommand",
"data": string(msg.Data),
+3 -1
View File
@@ -7,6 +7,8 @@ import (
"time"
kcp "github.com/xtaci/kcp-go/v5"
"whitelist-bypass/relay/common"
)
const (
@@ -383,7 +385,7 @@ func (t *MultiTrackKCPTunnel) updateLoop() {
session.update()
}
ticks++
if ticks%kcpStatsEvery == 0 && t.logFn != nil {
if common.Debug && ticks%kcpStatsEvery == 0 && t.logFn != nil {
t.logFn("kcptunnel: sessions=%d window=%d sent=%d delivered=%d out_segs=%d in_segs=%d raw_out=%d raw_in=%d dropped=%d",
len(sessions), t.currentWindow.Load(), t.sentMessages.Load(), t.deliveredMessages.Load(),
t.outputSegments.Load(), t.inputSegments.Load(),
+3
View File
@@ -15,6 +15,8 @@ import (
"whitelist-bypass/relay/common"
)
const acceptErrorRetryDelay = 100 * time.Millisecond
type creatorUDP struct {
direct *net.UDPConn
socks *common.Socks5UDPSession
@@ -549,6 +551,7 @@ func (rb *RelayBridge) ListenSOCKS(addr string) error {
return nil
}
rb.logFn("relay: accept error: %v", err)
time.Sleep(acceptErrorRetryDelay)
continue
}
go rb.handleSOCKS(conn)
+4 -2
View File
@@ -5,6 +5,8 @@ import (
"sync"
"sync/atomic"
"time"
"whitelist-bypass/relay/common"
)
const (
@@ -134,7 +136,7 @@ func (w *ScreenWriter) emit(msg []byte) {
return
}
n := w.sent.Add(1)
if n <= 5 || n%500 == 0 {
if common.Debug && (n <= 5 || n%500 == 0) {
w.logFn("[%s] sent frame #%d size=%d", w.label, n, len(msg))
}
}
@@ -252,7 +254,7 @@ func (s *SymmetricScreenTunnel) Stop() {
func (s *SymmetricScreenTunnel) HandleScreenFrame(frame []byte) {
res := s.obf.Decode(frame)
n := s.recv.Add(1)
if n <= 10 || n%500 == 0 {
if common.Debug && (n <= 10 || n%500 == 0) {
s.logFn("screen recv frame #%d in=%d hasFrame=%v keepalive=%v payload=%d", n, len(frame), res.HasFrame, res.Keepalive, len(res.Payload))
}
if !res.HasFrame || res.SelfEcho || res.Keepalive || len(res.Payload) == 0 {
+2 -2
View File
@@ -221,7 +221,7 @@ func (t *VP8DataTunnel) writerLoop() {
if isKeepalive {
t.keepaliveFrames.Add(1)
}
if n <= 5 || n%500 == 0 {
if common.Debug && (n <= 5 || n%500 == 0) {
keepalives := t.keepaliveFrames.Load()
t.logFn("vp8tunnel: sent frame #%d size=%d data=%d keepalive=%d", n, len(sample), n-keepalives, keepalives)
}
@@ -249,7 +249,7 @@ func (t *VP8DataTunnel) HandleFrame(frame []byte) {
return
}
n := t.recvFrames.Add(1)
if n <= 5 || n%500 == 0 {
if common.Debug && (n <= 5 || n%500 == 0) {
t.logFn("vp8tunnel: recv frame #%d size=%d", n, len(res.Payload))
}
if t.OnData != nil {
+2 -2
View File
@@ -198,7 +198,7 @@ func (t *VP8LegacyTunnel) writerLoop() {
continue
}
n := t.sentFrames.Add(1)
if n <= 5 || n%500 == 0 {
if common.Debug && (n <= 5 || n%500 == 0) {
t.logFn("vp8tunnel-legacy: sent frame #%d size=%d", n, len(sample))
}
}
@@ -232,7 +232,7 @@ func (t *VP8LegacyTunnel) HandleFrame(frame []byte) {
return
}
n := t.recvFrames.Add(1)
if n <= 5 || n%500 == 0 {
if common.Debug && (n <= 5 || n%500 == 0) {
t.logFn("vp8tunnel-legacy: recv frame #%d size=%d", n, len(payload))
}
if t.OnData != nil {
+1 -1
View File
@@ -628,7 +628,7 @@ func (s *Session) readVP8Track(track *webrtc.TrackRemote) {
continue
}
recvCount++
if recvCount <= 3 || recvCount%200 == 0 {
if common.Debug && (recvCount <= 3 || recvCount%200 == 0) {
s.cfg.LogFn("[lk-video] recv vp8 frame #%d %d bytes", recvCount, len(frameBuf))
}