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:
Daniel Shokouhi 2022-07-21 17:41:08 -07:00 committed by GitHub
parent d072b90843
commit 33f6673e61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -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())

View file

@ -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