Merge pull request #6654 from vector-im/feature/mna/update-sending-period-lls

[Location share] Update minimum sending period to 5 seconds for a live
This commit is contained in:
Maxime NATUREL 2022-08-04 14:17:00 +02:00 committed by GitHub
commit dd69b254f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 11 deletions

1
changelog.d/6653.misc Normal file
View File

@ -0,0 +1 @@
[Location share] Update minimum sending period to 5 seconds for a live

View File

@ -22,5 +22,3 @@ const val DEFAULT_PIN_ID = "DEFAULT_PIN_ID"
const val INITIAL_MAP_ZOOM_IN_PREVIEW = 15.0
const val INITIAL_MAP_ZOOM_IN_TIMELINE = 17.0
const val MIN_TIME_TO_UPDATE_LOCATION_MILLIS = 2 * 1_000L // every 2 seconds
const val MIN_DISTANCE_TO_UPDATE_LOCATION_METERS = 10f

View File

@ -36,6 +36,10 @@ import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.time.Duration.Companion.seconds
@VisibleForTesting
const val MIN_DISTANCE_TO_UPDATE_LOCATION_METERS = 10f
@Singleton
class LocationTracker @Inject constructor(
@ -62,14 +66,25 @@ class LocationTracker @Inject constructor(
@VisibleForTesting
var hasLocationFromGPSProvider = false
private var firstLocationHandled = false
private val _locations = MutableSharedFlow<Location>(replay = 1)
@VisibleForTesting
val minDurationToUpdateLocationMillis = 5.seconds.inWholeMilliseconds
/**
* SharedFlow to collect location updates.
*/
val locations = _locations.asSharedFlow()
.onEach { Timber.d("new location emitted") }
.debounce(MIN_TIME_TO_UPDATE_LOCATION_MILLIS)
.debounce {
if (firstLocationHandled) {
minDurationToUpdateLocationMillis
} else {
firstLocationHandled = true
0
}
}
.onEach { Timber.d("new location emitted after debounce") }
.map { it.toLocationData() }
@ -96,7 +111,7 @@ class LocationTracker @Inject constructor(
locationManager.requestLocationUpdates(
provider,
MIN_TIME_TO_UPDATE_LOCATION_MILLIS,
minDurationToUpdateLocationMillis,
MIN_DISTANCE_TO_UPDATE_LOCATION_METERS,
this
)

View File

@ -76,19 +76,19 @@ class LocationTrackerTest {
verifyOrder {
fakeLocationManager.instance.requestLocationUpdates(
LocationManager.FUSED_PROVIDER,
MIN_TIME_TO_UPDATE_LOCATION_MILLIS,
locationTracker.minDurationToUpdateLocationMillis,
MIN_DISTANCE_TO_UPDATE_LOCATION_METERS,
locationTracker
)
fakeLocationManager.instance.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_TO_UPDATE_LOCATION_MILLIS,
locationTracker.minDurationToUpdateLocationMillis,
MIN_DISTANCE_TO_UPDATE_LOCATION_METERS,
locationTracker
)
fakeLocationManager.instance.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_TO_UPDATE_LOCATION_MILLIS,
locationTracker.minDurationToUpdateLocationMillis,
MIN_DISTANCE_TO_UPDATE_LOCATION_METERS,
locationTracker
)
@ -155,7 +155,7 @@ class LocationTrackerTest {
locationTracker.onLocationChanged(fusedLocation)
locationTracker.onLocationChanged(gpsLocation)
locationTracker.onLocationChanged(networkLocation)
advanceTimeBy(MIN_TIME_TO_UPDATE_LOCATION_MILLIS + 1)
advanceTimeBy(locationTracker.minDurationToUpdateLocationMillis + 1)
val expectedLocationData = LocationData(
latitude = 1.0,
@ -189,7 +189,7 @@ class LocationTrackerTest {
locationTracker.onLocationChanged(gpsLocation)
locationTracker.onLocationChanged(networkLocation)
advanceTimeBy(MIN_TIME_TO_UPDATE_LOCATION_MILLIS + 1)
advanceTimeBy(locationTracker.minDurationToUpdateLocationMillis + 1)
val expectedLocationData = LocationData(
latitude = 1.0,
@ -218,7 +218,7 @@ class LocationTrackerTest {
val resultUpdates = locationTracker.locations.test(this)
locationTracker.onLocationChanged(networkLocation)
advanceTimeBy(MIN_TIME_TO_UPDATE_LOCATION_MILLIS + 1)
advanceTimeBy(locationTracker.minDurationToUpdateLocationMillis + 1)
val expectedLocationData = LocationData(
latitude = 1.0,
@ -244,7 +244,7 @@ class LocationTrackerTest {
val resultUpdates = locationTracker.locations.test(this)
locationTracker.requestLastKnownLocation()
advanceTimeBy(MIN_TIME_TO_UPDATE_LOCATION_MILLIS + 1)
advanceTimeBy(locationTracker.minDurationToUpdateLocationMillis + 1)
val expectedLocationData = LocationData(
latitude = A_LATITUDE,