summaryrefslogtreecommitdiff
path: root/java/com/android/incallui/calllocation/impl/LocationHelper.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-10-03 19:29:34 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-10-03 19:29:34 +0000
commit40a59d307038709ed489f0ed61ba94b224416743 (patch)
treef094ae078807e0486617bc958b984cc9521d5fd9 /java/com/android/incallui/calllocation/impl/LocationHelper.java
parent4fd9c153b6f3059bd9204051fb0c27596d2bc72d (diff)
parenta95459f9ccb54f6b694810cf7396ffdefde11d45 (diff)
Merge changes Ib6415145,Ifde98a8c
* changes: Adjust the location update frequency for emergency calls Fix issue that the connection icon is placed a little left from center
Diffstat (limited to 'java/com/android/incallui/calllocation/impl/LocationHelper.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) {