mirror of
https://github.com/home-assistant/android
synced 2024-09-06 17:23:32 +00:00
Minor location update fixes (#2670)
* Minor location update fixes * Remove delay and use a new location intent for high accuracy updates to avoid a conflict
This commit is contained in:
parent
d072b90843
commit
33f6673e61
|
@ -18,6 +18,7 @@ import androidx.core.app.NotificationManagerCompat
|
|||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.google.android.gms.location.LocationRequest
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.google.android.gms.location.Priority
|
||||
import io.homeassistant.companion.android.common.util.highAccuracyChannel
|
||||
import io.homeassistant.companion.android.sensors.LocationSensorManager
|
||||
import io.homeassistant.companion.android.util.ForegroundServiceLauncher
|
||||
|
@ -182,18 +183,18 @@ class HighAccuracyLocationService : Service() {
|
|||
|
||||
private fun getLocationUpdateIntent(): PendingIntent {
|
||||
val intent = Intent(this, LocationSensorManager::class.java)
|
||||
intent.action = LocationSensorManager.ACTION_PROCESS_LOCATION
|
||||
intent.action = LocationSensorManager.ACTION_PROCESS_HIGH_ACCURACY_LOCATION
|
||||
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun requestLocationUpdates(intervalInSeconds: Int) {
|
||||
val request = LocationRequest()
|
||||
val request = LocationRequest.create()
|
||||
|
||||
val intervalInMS = (intervalInSeconds * 1000).toLong()
|
||||
request.interval = intervalInMS
|
||||
request.fastestInterval = intervalInMS / 2
|
||||
request.priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
||||
request.priority = Priority.PRIORITY_HIGH_ACCURACY
|
||||
|
||||
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
|
||||
fusedLocationProviderClient?.requestLocationUpdates(request, getLocationUpdateIntent())
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.google.android.gms.location.LocationCallback
|
|||
import com.google.android.gms.location.LocationRequest
|
||||
import com.google.android.gms.location.LocationResult
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.google.android.gms.location.Priority
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import io.homeassistant.companion.android.common.bluetooth.BluetoothUtils
|
||||
import io.homeassistant.companion.android.common.data.integration.Entity
|
||||
|
@ -65,6 +66,8 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
"io.homeassistant.companion.android.background.REQUEST_ACCURATE_UPDATE"
|
||||
const val ACTION_PROCESS_LOCATION =
|
||||
"io.homeassistant.companion.android.background.PROCESS_UPDATES"
|
||||
const val ACTION_PROCESS_HIGH_ACCURACY_LOCATION =
|
||||
"io.homeassistant.companion.android.background.PROCESS_HIGH_ACCURACY_UPDATES"
|
||||
const val ACTION_PROCESS_GEO =
|
||||
"io.homeassistant.companion.android.background.PROCESS_GEOFENCE"
|
||||
const val ACTION_FORCE_HIGH_ACCURACY =
|
||||
|
@ -166,7 +169,8 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
when (intent.action) {
|
||||
Intent.ACTION_BOOT_COMPLETED,
|
||||
ACTION_REQUEST_LOCATION_UPDATES -> setupLocationTracking()
|
||||
ACTION_PROCESS_LOCATION -> handleLocationUpdate(intent)
|
||||
ACTION_PROCESS_LOCATION,
|
||||
ACTION_PROCESS_HIGH_ACCURACY_LOCATION -> handleLocationUpdate(intent)
|
||||
ACTION_PROCESS_GEO -> handleGeoUpdate(intent)
|
||||
ACTION_REQUEST_ACCURATE_LOCATION_UPDATE -> requestSingleAccurateLocation()
|
||||
ACTION_FORCE_HIGH_ACCURACY -> {
|
||||
|
@ -764,13 +768,13 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
}
|
||||
|
||||
private fun createLocationRequest(): LocationRequest {
|
||||
val locationRequest = LocationRequest()
|
||||
val locationRequest = LocationRequest.create()
|
||||
|
||||
locationRequest.interval = 60000 // Every 60 seconds
|
||||
locationRequest.fastestInterval = 30000 // Every 30 seconds
|
||||
locationRequest.maxWaitTime = 200000 // Every 5 minutes
|
||||
|
||||
locationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
|
||||
locationRequest.priority = Priority.PRIORITY_BALANCED_POWER_ACCURACY
|
||||
|
||||
return locationRequest
|
||||
}
|
||||
|
@ -900,7 +904,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
|
|||
|
||||
val maxRetries = 5
|
||||
val request = createLocationRequest().apply {
|
||||
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
|
||||
priority = Priority.PRIORITY_HIGH_ACCURACY
|
||||
numUpdates = maxRetries
|
||||
interval = 10000
|
||||
fastestInterval = 5000
|
||||
|
|
Loading…
Reference in a new issue