fix: use startForegroundService instead of startService

This commit is contained in:
kaajjo 2024-08-08 02:48:07 +03:00
parent 989156d3dd
commit 1494eadf9a

View File

@ -3,6 +3,7 @@ package io.github.dovecoteescapee.byedpi.services
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.util.Log import android.util.Log
import androidx.core.content.ContextCompat
import io.github.dovecoteescapee.byedpi.data.Mode import io.github.dovecoteescapee.byedpi.data.Mode
import io.github.dovecoteescapee.byedpi.data.START_ACTION import io.github.dovecoteescapee.byedpi.data.START_ACTION
import io.github.dovecoteescapee.byedpi.data.STOP_ACTION import io.github.dovecoteescapee.byedpi.data.STOP_ACTION
@ -16,14 +17,14 @@ object ServiceManager {
Log.i(TAG, "Starting VPN") Log.i(TAG, "Starting VPN")
val intent = Intent(context, ByeDpiVpnService::class.java) val intent = Intent(context, ByeDpiVpnService::class.java)
intent.action = START_ACTION intent.action = START_ACTION
context.startService(intent) ContextCompat.startForegroundService(context, intent)
} }
Mode.Proxy -> { Mode.Proxy -> {
Log.i(TAG, "Starting proxy") Log.i(TAG, "Starting proxy")
val intent = Intent(context, ByeDpiProxyService::class.java) val intent = Intent(context, ByeDpiProxyService::class.java)
intent.action = START_ACTION intent.action = START_ACTION
context.startService(intent) ContextCompat.startForegroundService(context, intent)
} }
} }
} }
@ -35,14 +36,14 @@ object ServiceManager {
Log.i(TAG, "Stopping VPN") Log.i(TAG, "Stopping VPN")
val intent = Intent(context, ByeDpiVpnService::class.java) val intent = Intent(context, ByeDpiVpnService::class.java)
intent.action = STOP_ACTION intent.action = STOP_ACTION
context.startService(intent) ContextCompat.startForegroundService(context, intent)
} }
Mode.Proxy -> { Mode.Proxy -> {
Log.i(TAG, "Stopping proxy") Log.i(TAG, "Stopping proxy")
val intent = Intent(context, ByeDpiProxyService::class.java) val intent = Intent(context, ByeDpiProxyService::class.java)
intent.action = STOP_ACTION intent.action = STOP_ACTION
context.startService(intent) ContextCompat.startForegroundService(context, intent)
} }
} }
} }