File tree Expand file tree Collapse file tree
app/src/main/java/com/github/kr328/clash/util
service/src/main/java/com/github/kr328/clash/service/clash/module Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,17 +26,16 @@ fun Context.runClashService(): Intent? {
2626 } else {
2727 startForegroundServiceCompat(ClashService ::class .intent)
2828 }
29+ UiStore (this ).enableClashService = true
2930
3031 return null
3132}
3233
3334fun Context.startClashService (): Intent ? {
34- UiStore (this ).enableClashService = true
3535 return runClashService()
3636}
3737
3838fun Context.stopClashService () {
39- UiStore (this ).enableClashService = false
4039 sendBroadcastSelf(Intent (Intents .ACTION_CLASH_REQUEST_STOP ))
4140}
4241
Original file line number Diff line number Diff line change 11package com.github.kr328.clash.service.clash.module
22
33import android.app.Service
4+ import android.os.Build
45import com.github.kr328.clash.common.constants.Intents
56import com.github.kr328.clash.common.log.Log
7+ import com.github.kr328.clash.service.TunService
68
79class CloseModule (service : Service ) : Module<CloseModule.RequestClose>(service) {
810 object RequestClose
911
12+ fun isAlwaysOn (service : Service ): Boolean {
13+ return Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q && service is TunService && service.isAlwaysOn
14+ }
15+
1016 override suspend fun run () {
1117 val broadcasts = receiveBroadcast {
1218 addAction(Intents .ACTION_CLASH_REQUEST_STOP )
1319 }
1420
1521 broadcasts.receive()
1622
23+ if (isAlwaysOn(service))
24+ return
25+
1726 Log .d(" User request close" )
1827
1928 return enqueueEvent(RequestClose )
You can’t perform that action at this time.
0 commit comments