fix startVpn crashes

This commit is contained in:
egor-white
2025-07-06 12:34:39 +03:00
parent ba2cf523bd
commit 8dcb4d1997
2 changed files with 7 additions and 5 deletions

View File

@@ -37,9 +37,9 @@ class ByeDpiVpnService : VpnService() {
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
return when (intent?.action) { return when (intent?.action) {
"START_VPN" -> { "START_VPN" -> {
startForeground(NOTIFICATION_ID, createNotification())
setupProxy() setupProxy()
START_STICKY START_STICKY
} }
@@ -51,6 +51,8 @@ class ByeDpiVpnService : VpnService() {
else -> { else -> {
START_NOT_STICKY START_NOT_STICKY
} }
}.also { result ->
super.onStartCommand(intent, flags, startId)
} }
} }
@@ -99,7 +101,6 @@ class ByeDpiVpnService : VpnService() {
private fun setupProxy() { private fun setupProxy() {
if (getActiveStrategy(sharedPreferences).isNotEmpty()) { if (getActiveStrategy(sharedPreferences).isNotEmpty()) {
startForeground(NOTIFICATION_ID, createNotification())
try { try {
startSocksProxy() startSocksProxy()
startByeDpi() startByeDpi()
@@ -107,14 +108,15 @@ class ByeDpiVpnService : VpnService() {
} catch (e: Exception) { } catch (e: Exception) {
Log.e("proxy", "Failed to start") Log.e("proxy", "Failed to start")
status = ServiceStatus.Failed status = ServiceStatus.Failed
stopSelf()
} }
} } else {
else {
Toast.makeText( Toast.makeText(
this@ByeDpiVpnService, this@ByeDpiVpnService,
getString(R.string.toast_no_strategy_selected), getString(R.string.toast_no_strategy_selected),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
stopSelf()
} }
} }