Первоначальный запуск службы работает должным образом, но как только я останавливаю свою службу и вызываю функцию Disconnect() для очистки, а затем запускаю ее снова, Vpn не будет маршрутизироваться. трафик, как это было при начальном запуске службы, и я получаю этот журнал:
Код: Выделить всё
[693172588] app/proxyman/outbound: failed to process outbound traffic > proxy/vmess/outbound: failed to find an available destination > common/retry: [transport/internet/grpc: failed to dial gRPC > transport/internet/grpc: Cannot dial gRPC > rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: read tcp 26.26.26.1:38964->173.245.58.154:2087: i/o timeout" transport/internet/grpc: failed to dial gRPC > transport/internet/grpc: Cannot dial gRPC > rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: read tcp 26.26.26.1:42536->173.245.58.154:2087: i/o timeout"] > common/retry: all retry attempts failed
Код: Выделить всё
private fun disconnect() {
Log.d("debug", "Disconnect method called")
isRunning = false
// Unregister network callback if the SDK version supports it
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
try {
connectivity.unregisterNetworkCallback(defaultNetworkCallback)
Log.d("debug", "Network callback unregistered")
} catch (e: Exception) {
Log.e("debug", "Failed to unregister network callback: ${e.message}")
}
}
// Stop V2Ray if it is running
if (v2rayPoint.isRunning) {
try {
v2rayPoint.stopLoop() // Stop the V2Ray loop
Log.d("debug", "V2Ray point stopped successfully")
} catch (e: Exception) {
Log.e("debug", "Failed to stop V2Ray point: ${e.message}")
}
}
// Stop the foreground service and clean up
serviceControl?.get()?.getService()?.stopForeground(true) // Stop the foreground notification
Log.d("debug", "Foreground notification stopped")
// Destroy the tun2socks process
try {
if (::process.isInitialized && process.isAlive) {
Log.d(packageName, "Destroying tun2socks process")
process.destroy()
}
} catch (e: Exception) {
Log.e(packageName, "Failed to destroy process: ${e.message}")
}
// Close the VPN interface if it exists
try {
if (::mInterface.isInitialized) {
mInterface.close() // Safely close the interface
Log.d("debug", "VPN interface closed")
}
} catch (ignored: Exception) {
Log.e("debug", "Failed to close VPN interface: ${ignored.message}")
}
stopSelf() // Stop the service after cleanup
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -in-kotlin