Make linter happy

This commit is contained in:
世界
2024-03-16 21:34:19 +08:00
parent 78dd252b78
commit 75a35d3c97
23 changed files with 53 additions and 34 deletions

View File

@@ -15,10 +15,10 @@ class AppChangeReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.d(TAG, "onReceive: ${intent.action}")
checkUpdate(context, intent)
checkUpdate(intent)
}
private fun checkUpdate(context: Context, intent: Intent) {
private fun checkUpdate(intent: Intent) {
if (!Settings.perAppProxyEnabled) {
Log.d(TAG, "per app proxy disabled")
return

View File

@@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import io.nekohasekai.sfa.database.Settings
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@@ -11,6 +12,7 @@ import kotlinx.coroutines.withContext
class BootReceiver : BroadcastReceiver() {
@OptIn(DelicateCoroutinesApi::class)
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED -> {

View File

@@ -27,6 +27,7 @@ import io.nekohasekai.sfa.constant.Status
import io.nekohasekai.sfa.database.ProfileManager
import io.nekohasekai.sfa.database.Settings
import io.nekohasekai.sfa.ktx.hasPermission
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
@@ -243,6 +244,7 @@ class BoxService(
}
}
@OptIn(DelicateCoroutinesApi::class)
private fun stopService() {
if (status.value != Status.Started) return
status.value = Status.Stopping
@@ -298,7 +300,9 @@ class BoxService(
}
}
fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@OptIn(DelicateCoroutinesApi::class)
@Suppress("SameReturnValue")
internal fun onStartCommand(): Int {
if (status.value != Status.Stopped) return Service.START_NOT_STICKY
status.value = Status.Starting
@@ -327,19 +331,19 @@ class BoxService(
return Service.START_NOT_STICKY
}
fun onBind(intent: Intent): IBinder {
internal fun onBind(): IBinder {
return binder
}
fun onDestroy() {
internal fun onDestroy() {
binder.close()
}
fun onRevoke() {
internal fun onRevoke() {
stopService()
}
fun writeLog(message: String) {
internal fun writeLog(message: String) {
binder.broadcast {
it.onServiceWriteLog(message)
}

View File

@@ -30,8 +30,10 @@ import android.os.Handler
import android.os.Looper
import io.nekohasekai.sfa.Application
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.runBlocking
@@ -49,6 +51,7 @@ object DefaultNetworkListener {
class Lost(val network: Network) : NetworkMessage()
}
@OptIn(DelicateCoroutinesApi::class, ObsoleteCoroutinesApi::class)
private val networkActor = GlobalScope.actor<NetworkMessage>(Dispatchers.Unconfined) {
val listeners = mutableMapOf<Any, (Network?) -> Unit>()
var network: Network? = null

View File

@@ -103,6 +103,7 @@ interface PlatformInterfaceWrapper : PlatformInterface {
}
override fun readWIFIState(): WIFIState? {
@Suppress("DEPRECATION")
val wifiInfo = Application.wifiManager.connectionInfo ?: return null
var ssid = wifiInfo.ssid
if (ssid.startsWith("\"") && ssid.endsWith("\"")) {

View File

@@ -8,9 +8,9 @@ class ProxyService : Service(), PlatformInterfaceWrapper {
private val service = BoxService(this, this)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int) =
service.onStartCommand(intent, flags, startId)
service.onStartCommand()
override fun onBind(intent: Intent) = service.onBind(intent)
override fun onBind(intent: Intent) = service.onBind()
override fun onDestroy() = service.onDestroy()
override fun writeLog(message: String) = service.writeLog(message)

View File

@@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
import io.nekohasekai.sfa.aidl.IService
import io.nekohasekai.sfa.aidl.IServiceCallback
import io.nekohasekai.sfa.constant.Status
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@@ -23,6 +24,7 @@ class ServiceBinder(private val status: MutableLiveData<Status>) : IService.Stub
}
}
@OptIn(DelicateCoroutinesApi::class)
fun broadcast(work: (IServiceCallback) -> Unit) {
GlobalScope.launch(Dispatchers.Main) {
broadcastLock.withLock {

View File

@@ -22,6 +22,7 @@ import io.nekohasekai.sfa.constant.Status
import io.nekohasekai.sfa.database.Settings
import io.nekohasekai.sfa.ui.MainActivity
import io.nekohasekai.sfa.utils.CommandClient
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.withContext
@@ -43,6 +44,7 @@ class ServiceNotification(
}
}
@OptIn(DelicateCoroutinesApi::class)
private val commandClient =
CommandClient(GlobalScope, CommandClient.ConnectionType.Status, this)
private var receiverRegistered = false

View File

@@ -22,14 +22,14 @@ class VPNService : VpnService(), PlatformInterfaceWrapper {
private val service = BoxService(this, this)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int) =
service.onStartCommand(intent, flags, startId)
service.onStartCommand()
override fun onBind(intent: Intent): IBinder {
val binder = super.onBind(intent)
if (binder != null) {
return binder
}
return service.onBind(intent)
return service.onBind()
}
override fun onDestroy() {