From 7238e919c51285d0175a2d4637fe5e0d9146784d Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Tue, 10 Dec 2019 13:45:08 +0800 Subject: [PATCH] fix tile service clash start failure --- .../java/com/github/kr328/clash/BootCompleteReceiver.kt | 7 ++----- app/src/main/java/com/github/kr328/clash/TileService.kt | 2 +- .../java/com/github/kr328/clash/utils/ServiceUtils.kt | 8 ++++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/kr328/clash/BootCompleteReceiver.kt b/app/src/main/java/com/github/kr328/clash/BootCompleteReceiver.kt index bc334bc..7c66681 100644 --- a/app/src/main/java/com/github/kr328/clash/BootCompleteReceiver.kt +++ b/app/src/main/java/com/github/kr328/clash/BootCompleteReceiver.kt @@ -4,16 +4,13 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.os.Build +import com.github.kr328.clash.utils.ServiceUtils class BootCompleteReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { if (Intent.ACTION_BOOT_COMPLETED != intent?.action || context == null) return - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - context.startForegroundService(Intent(context, ClashStartService::class.java)) - } else { - context.startService(Intent(context, ClashStartService::class.java)) - } + ServiceUtils.startStarterService(context) } } \ No newline at end of file diff --git a/app/src/main/java/com/github/kr328/clash/TileService.kt b/app/src/main/java/com/github/kr328/clash/TileService.kt index bc967ed..b46dbb2 100644 --- a/app/src/main/java/com/github/kr328/clash/TileService.kt +++ b/app/src/main/java/com/github/kr328/clash/TileService.kt @@ -19,7 +19,7 @@ class TileService : TileService() { when (tile.state) { Tile.STATE_INACTIVE -> { - ServiceUtils.startProxyService(this) + ServiceUtils.startStarterService(this) } Tile.STATE_ACTIVE -> { val binder = diff --git a/app/src/main/java/com/github/kr328/clash/utils/ServiceUtils.kt b/app/src/main/java/com/github/kr328/clash/utils/ServiceUtils.kt index 20a9f83..9e68f1a 100644 --- a/app/src/main/java/com/github/kr328/clash/utils/ServiceUtils.kt +++ b/app/src/main/java/com/github/kr328/clash/utils/ServiceUtils.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.net.VpnService import android.os.Build +import com.github.kr328.clash.ClashStartService import com.github.kr328.clash.MainApplication import com.github.kr328.clash.service.ClashService import com.github.kr328.clash.service.TunService @@ -35,4 +36,11 @@ object ServiceUtils { return null } } + + fun startStarterService(context: Context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + context.startForegroundService(Intent(context, ClashStartService::class.java)) + else + context.startService(Intent(context, ClashStartService::class.java)) + } } \ No newline at end of file