diff --git a/app/src/main/java/com/jihe/punchnet/PunchnetService.kt b/app/src/main/java/com/jihe/punchnet/PunchnetService.kt index f36af04..9b9e430 100644 --- a/app/src/main/java/com/jihe/punchnet/PunchnetService.kt +++ b/app/src/main/java/com/jihe/punchnet/PunchnetService.kt @@ -40,7 +40,7 @@ import java.io.FileOutputStream class PunchnetService : VpnService() , IfaceTun { private val TAG = "PunchnetService" - private val scope = CoroutineScope(Dispatchers.IO) + private var scope = CoroutineScope(Dispatchers.IO) private val routes: MutableList = mutableListOf() @@ -50,7 +50,7 @@ class PunchnetService : VpnService() , IfaceTun { var input: FileInputStream? = null var output: FileOutputStream? = null - override val arpTable = ARPTable(scope) + override var arpTable = ARPTable(scope) override val arpWaitList = ARPWaitList() var config: DeviceConfig = DeviceConfig(1400) @@ -126,11 +126,13 @@ class PunchnetService : VpnService() , IfaceTun { private fun disconnect() { Toast.makeText(this, "stop vpn called", Toast.LENGTH_LONG).show() + stopForeground(STOP_FOREGROUND_REMOVE) input?.close() output?.close() vpnDescriptor?.close() - stopForeground(true) + vpnDescriptor = null + stopSelf() } @@ -180,8 +182,11 @@ class PunchnetService : VpnService() , IfaceTun { return if (intent?.action == ACTION_DISCONNECT) { scope.cancel() + scope = CoroutineScope(Dispatchers.IO) + arpTable = ARPTable(scope) + disconnect() - START_STICKY + START_NOT_STICKY } else { val argument = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { intent?.getParcelableExtra("argument", PunchnetServiceArgument::class.java) @@ -215,6 +220,8 @@ class PunchnetService : VpnService() , IfaceTun { override fun onDestroy() { // scope.cancel() // disconnect() + scope.cancel() + stopForeground(STOP_FOREGROUND_REMOVE) super.onDestroy() } } \ No newline at end of file diff --git a/app/src/main/java/com/jihe/punchnet/sdlan/network/libs.kt b/app/src/main/java/com/jihe/punchnet/sdlan/network/libs.kt index 8e5ddad..a3350ab 100644 --- a/app/src/main/java/com/jihe/punchnet/sdlan/network/libs.kt +++ b/app/src/main/java/com/jihe/punchnet/sdlan/network/libs.kt @@ -440,7 +440,7 @@ suspend fun initTCPConn( } connectingChan?.send(ConnectingState.Connecting) - TerminalLogger.debugf {"try connecting..."} + TerminalLogger.debugf {"try connecting tcp..."} val socket: Socket try {