summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authormdooley <mdooley@google.com>2017-10-02 16:12:34 -0700
committerEric Erfanian <erfanian@google.com>2017-10-03 10:42:46 -0700
commita95459f9ccb54f6b694810cf7396ffdefde11d45 (patch)
treef094ae078807e0486617bc958b984cc9521d5fd9 /java
parentdf3893d3ea8206a2d21c2a271a7f2ea2da681775 (diff)
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
Diffstat (limited to 'java')
-rw-r--r--java/com/android/incallui/calllocation/impl/LocationHelper.java19
1 files changed, 16 insertions, 3 deletions
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) {