From a95459f9ccb54f6b694810cf7396ffdefde11d45 Mon Sep 17 00:00:00 2001 From: mdooley Date: Mon, 2 Oct 2017 16:12:34 -0700 Subject: Adjust the location update frequency for emergency calls Sometimes takes many seconds to get an accurate location during an emergency call. With this cl we use a high frequency update rate (5 seconds) until we get an accurate location, and then we decrease the update rate (30 seconds) to save power. Bug: 67317743 Test: manual PiperOrigin-RevId: 170770361 Change-Id: Ib6415145f6a62125f4b458e242ebe23409f9d406 --- .../incallui/calllocation/impl/LocationHelper.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'java') diff --git a/java/com/android/incallui/calllocation/impl/LocationHelper.java b/java/com/android/incallui/calllocation/impl/LocationHelper.java index 48baa020a..7fbd60d04 100644 --- a/java/com/android/incallui/calllocation/impl/LocationHelper.java +++ b/java/com/android/incallui/calllocation/impl/LocationHelper.java @@ -39,7 +39,8 @@ import java.util.List; /** Uses the Fused location service to get location and pass updates on to listeners. */ public class LocationHelper { - private static final int MIN_UPDATE_INTERVAL_MS = 20 * 1000; + private static final int FAST_MIN_UPDATE_INTERVAL_MS = 5 * 1000; + private static final int SLOW_MIN_UPDATE_INTERVAL_MS = 30 * 1000; private static final int LAST_UPDATE_THRESHOLD_MS = 60 * 1000; private static final int LOCATION_ACCURACY_THRESHOLD_METERS = 100; @@ -159,6 +160,7 @@ public class LocationHelper { private final FusedLocationProviderClient locationClient; private final ConnectivityManager connectivityManager; private final Handler mainThreadHandler = new Handler(); + private boolean gotGoodLocation; @MainThread LocationHelperInternal(Context context) { @@ -178,11 +180,12 @@ public class LocationHelper { private void requestUpdates() { LogUtil.enterBlock("LocationHelperInternal.requestUpdates"); + int interval = gotGoodLocation ? SLOW_MIN_UPDATE_INTERVAL_MS : FAST_MIN_UPDATE_INTERVAL_MS; LocationRequest locationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) - .setInterval(MIN_UPDATE_INTERVAL_MS) - .setFastestInterval(MIN_UPDATE_INTERVAL_MS); + .setInterval(interval) + .setFastestInterval(interval); locationClient .requestLocationUpdates(locationRequest, this) @@ -202,6 +205,7 @@ public class LocationHelper { LogUtil.i("LocationHelperInternal.getLocation", "onSuccess"); Assert.isMainThread(); LocationHelper.this.onLocationChanged(location, isConnected()); + maybeAdjustUpdateInterval(location); }) .addOnFailureListener( e -> LogUtil.e("LocationHelperInternal.getLocation", "onFailure", e)); @@ -215,10 +219,19 @@ public class LocationHelper { @Override public void run() { LocationHelper.this.onLocationChanged(location, isConnected()); + maybeAdjustUpdateInterval(location); } }); } + private void maybeAdjustUpdateInterval(Location location) { + if (!gotGoodLocation && checkLocation(location) == LOCATION_STATUS_OK) { + LogUtil.i("LocationHelperInternal.maybeAdjustUpdateInterval", "got good location"); + gotGoodLocation = true; + requestUpdates(); + } + } + /** @return Whether the phone is connected to data. */ private boolean isConnected() { if (connectivityManager == null) { -- cgit v1.2.3