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