mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: remove BACKGROUND_LOCATION permission
This commit is contained in:
parent
b4cdbf0617
commit
3a97e6dbcb
6 changed files with 19 additions and 56 deletions
|
|
@ -138,24 +138,16 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
|
||||
private fun initCommonUI() {
|
||||
|
||||
val requestBackgroundAndCheckLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
|
||||
if (permissions.entries.any { !it.value }) {
|
||||
debug("User denied background permission")
|
||||
model.showSnackbar(getString(R.string.why_background_required))
|
||||
}
|
||||
}
|
||||
|
||||
val requestLocationAndBackgroundLauncher =
|
||||
val requestLocationPermissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
|
||||
if (permissions.entries.all { it.value }) {
|
||||
// Older versions of android only need Location permission
|
||||
if (!requireContext().hasBackgroundPermission())
|
||||
requestBackgroundAndCheckLauncher.launch(requireContext().getBackgroundPermissions())
|
||||
model.provideLocation.value = true
|
||||
model.meshService?.startProvideLocation()
|
||||
} else {
|
||||
debug("User denied location permission")
|
||||
model.showSnackbar(getString(R.string.why_background_required))
|
||||
}
|
||||
bluetoothViewModel.permissionsUpdated()
|
||||
}
|
||||
|
||||
// init our region spinner
|
||||
|
|
@ -240,7 +232,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
|
||||
binding.provideLocationCheckbox.setOnCheckedChangeListener { view, isChecked ->
|
||||
// Don't check the box until the system setting changes
|
||||
view.isChecked = isChecked && requireContext().hasBackgroundPermission()
|
||||
view.isChecked = isChecked && requireContext().hasLocationPermission()
|
||||
|
||||
if (view.isPressed) { // We want to ignore changes caused by code (as opposed to the user)
|
||||
debug("User changed location tracking to $isChecked")
|
||||
|
|
@ -255,9 +247,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
.setPositiveButton(getString(R.string.accept)) { _, _ ->
|
||||
// Make sure we have location permission (prerequisite)
|
||||
if (!requireContext().hasLocationPermission()) {
|
||||
requestLocationAndBackgroundLauncher.launch(requireContext().getLocationPermissions())
|
||||
} else {
|
||||
requestBackgroundAndCheckLauncher.launch(requireContext().getBackgroundPermissions())
|
||||
requestLocationPermissionLauncher.launch(requireContext().getLocationPermissions())
|
||||
}
|
||||
}
|
||||
.show()
|
||||
|
|
|
|||
|
|
@ -182,21 +182,6 @@ fun MapView(
|
|||
if (permissions.entries.all { it.value }) map.toggleMyLocation()
|
||||
}
|
||||
|
||||
fun requestPermissionAndToggle() {
|
||||
// Google rejects releases claiming this requires BACKGROUND_LOCATION prominent
|
||||
// disclosure. Adding to comply even though it does not use background location.
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(R.string.background_required)
|
||||
.setMessage(R.string.why_background_required)
|
||||
.setNeutralButton(R.string.cancel) { _, _ ->
|
||||
debug("User denied location permission")
|
||||
}
|
||||
.setPositiveButton(R.string.accept) { _, _ ->
|
||||
requestPermissionAndToggleLauncher.launch(context.getLocationPermissions())
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
val nodes by model.nodeList.collectAsStateWithLifecycle()
|
||||
val waypoints by model.waypoints.collectAsStateWithLifecycle(emptyMap())
|
||||
|
||||
|
|
@ -667,7 +652,7 @@ fun MapView(
|
|||
IconButton(
|
||||
onClick = {
|
||||
if (context.hasLocationPermission()) map.toggleMyLocation()
|
||||
else requestPermissionAndToggle()
|
||||
else requestPermissionAndToggleLauncher.launch(context.getLocationPermissions())
|
||||
},
|
||||
enabled = hasGps,
|
||||
drawableRes = if (myLocationOverlay == null) R.drawable.ic_twotone_my_location_24
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue