fix tile service clash start failure

This commit is contained in:
Kr328 committed 2019-12-10 13:45:08 +08:00
1 parent 7cd52a84db
commit 7238e919c5
3 files changed
+11 -6

No files matched your search

@@ -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)
}
}
@@ -19,7 +19,7 @@ class TileService : TileService() {
when (tile.state) {
Tile.STATE_INACTIVE -> {
ServiceUtils.startProxyService(this)
ServiceUtils.startStarterService(this)
}
Tile.STATE_ACTIVE -> {
val binder =
@@ -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))
}
}