fix(service): handle missing service reference and notify UI on shutdown

This commit is contained in:
zarazaex69
2026-04-11 13:03:00 +03:00
parent 0c32ddc642
commit 732d7248af
2 changed files with 7 additions and 0 deletions
@@ -96,6 +96,11 @@ object V2RayServiceManager {
}
try {
if (serviceControl?.get() == null) {
Log.w(AppConfig.TAG, "StartCore-Manager: Service not running, resetting UI state")
MessageUtil.sendMsg2UI(context, AppConfig.MSG_STATE_STOP_SUCCESS, "")
return
}
MessageUtil.sendMsg2Service(context, AppConfig.MSG_STATE_STOP, "")
} finally {
synchronized(operationLock) {
@@ -25,6 +25,7 @@ import xyz.zarazaex.olc.handler.MmkvManager
import xyz.zarazaex.olc.handler.NotificationManager
import xyz.zarazaex.olc.handler.SettingsManager
import xyz.zarazaex.olc.handler.V2RayServiceManager
import xyz.zarazaex.olc.util.MessageUtil
import xyz.zarazaex.olc.util.MyContextWrapper
import xyz.zarazaex.olc.util.Utils
import java.lang.ref.SoftReference
@@ -94,6 +95,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
super.onDestroy()
Log.i(AppConfig.TAG, "StartCore-VPN: Service destroyed")
NotificationManager.cancelNotification()
MessageUtil.sendMsg2UI(this, AppConfig.MSG_STATE_STOP_SUCCESS, "")
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {