Fix start loop on MIUI

This commit is contained in:
世界 2023-12-11 18:59:40 +08:00
parent 96e369e829
commit c0d2f57ec0
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -184,13 +184,14 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
fun startService() { fun startService(skipRequestFineLocation: Boolean = false) {
if (!ServiceNotification.checkPermission()) { if (!ServiceNotification.checkPermission()) {
notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
return return
} }
if (ContextCompat.checkSelfPermission( // MIUI always return false for shouldShowRequestPermissionRationale
if (!skipRequestFineLocation && ContextCompat.checkSelfPermission(
this, Manifest.permission.ACCESS_FINE_LOCATION this, Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED ) != PackageManager.PERMISSION_GRANTED
) { ) {
@ -204,7 +205,6 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
} }
} }
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
if (Settings.rebuildServiceMode()) { if (Settings.rebuildServiceMode()) {
reconnect() reconnect()
@ -234,7 +234,7 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
private val fineLocationPermissionLauncher = registerForActivityResult( private val fineLocationPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission() ActivityResultContracts.RequestPermission()
) { ) {
startService() startService(true)
} }
private val prepareLauncher = registerForActivityResult(PrepareService()) { private val prepareLauncher = registerForActivityResult(PrepareService()) {