Fix WIFI state permission again

This commit is contained in:
世界
2024-02-16 14:35:11 +08:00
parent 4504447a2c
commit f8ebfaabe2
5 changed files with 89 additions and 38 deletions

View File

@@ -5,6 +5,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.os.Build
import android.os.IBinder
import android.os.ParcelFileDescriptor
@@ -169,6 +170,23 @@ class BoxService(
}
newService.start()
if (newService.needWIFIState()) {
val wifiPermission = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
android.Manifest.permission.ACCESS_FINE_LOCATION
} else {
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
}
if (ContextCompat.checkSelfPermission(
service, wifiPermission
) != PackageManager.PERMISSION_GRANTED
) {
newService.close()
stopAndAlert(Alert.RequestLocationPermission)
return
}
}
boxService = newService
commandServer?.setService(boxService)
status.postValue(Status.Started)