summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Christie <dnchrist@google.com> 2025-03-11 14:18:16 -0700
committer David Christie <dnchrist@google.com> 2025-03-11 20:22:06 -0700
commite1490213801cc9eeb442aeb7260b6033b179a2ea (patch)
treefb262103346444db789a15d82d287ebe618069e8
parent5dc2f75fc5fae44c0723e4d54f9f6832cd6ea5d4 (diff)
Update logic in default fused location provider to avoid excessive power drain
GPS should only be used for high power requests at relatively fast intervals Flag: android.location.flags.limit_fused_gps Bug: 401885179 Test: manual modified: location/java/android/location/flags/location.aconfig modified: packages/FusedLocation/src/com/android/location/fused/FusedLocationProvider.java Change-Id: Ic6a6ee54b60054dfef6a4b04b18d3b3a9d128bd8
-rw-r--r--location/java/android/location/flags/location.aconfig10
-rw-r--r--packages/FusedLocation/src/com/android/location/fused/FusedLocationProvider.java12
2 files changed, 21 insertions, 1 deletions
diff --git a/location/java/android/location/flags/location.aconfig b/location/java/android/location/flags/location.aconfig
index 496ba501e49c..109d9e83d444 100644
--- a/location/java/android/location/flags/location.aconfig
+++ b/location/java/android/location/flags/location.aconfig
@@ -188,6 +188,16 @@ flag {
}
flag {
+ name: "limit_fused_gps"
+ namespace: "location"
+ description: "Limits when GPS can be used for fused location requests"
+ bug: "401885179"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
+
+flag {
name: "gnss_assistance_interface_jni"
namespace: "location"
description: "Flag for GNSS assistance interface JNI"
diff --git a/packages/FusedLocation/src/com/android/location/fused/FusedLocationProvider.java b/packages/FusedLocation/src/com/android/location/fused/FusedLocationProvider.java
index 8e52a00fe545..a0e008c9437f 100644
--- a/packages/FusedLocation/src/com/android/location/fused/FusedLocationProvider.java
+++ b/packages/FusedLocation/src/com/android/location/fused/FusedLocationProvider.java
@@ -19,6 +19,7 @@ package com.android.location.fused;
import static android.content.Intent.ACTION_USER_SWITCHED;
import static android.location.LocationManager.GPS_PROVIDER;
import static android.location.LocationManager.NETWORK_PROVIDER;
+import static android.location.LocationRequest.QUALITY_HIGH_ACCURACY;
import static android.location.LocationRequest.QUALITY_LOW_POWER;
import static android.location.provider.ProviderProperties.ACCURACY_FINE;
import static android.location.provider.ProviderProperties.POWER_USAGE_LOW;
@@ -34,6 +35,7 @@ import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationRequest;
+import android.location.flags.Flags;
import android.location.provider.LocationProviderBase;
import android.location.provider.ProviderProperties;
import android.location.provider.ProviderRequest;
@@ -61,6 +63,9 @@ public class FusedLocationProvider extends LocationProviderBase {
.build();
private static final long MAX_LOCATION_COMPARISON_NS = 11 * 1000000000L; // 11 seconds
+ // Maximum request interval at which we will activate GPS (because GPS sometimes consumes
+ // excessive power with large intervals).
+ private static final long MAX_GPS_INTERVAL_MS = 5 * 1000; // 5 seconds
private final Object mLock = new Object();
@@ -165,8 +170,13 @@ public class FusedLocationProvider extends LocationProviderBase {
mNlpPresent = mLocationManager.hasProvider(NETWORK_PROVIDER);
}
+ boolean requestAllowsGps =
+ Flags.limitFusedGps()
+ ? mRequest.getQuality() == QUALITY_HIGH_ACCURACY
+ && mRequest.getIntervalMillis() <= MAX_GPS_INTERVAL_MS
+ : !mNlpPresent || mRequest.getQuality() < QUALITY_LOW_POWER;
long gpsInterval =
- mGpsPresent && (!mNlpPresent || mRequest.getQuality() < QUALITY_LOW_POWER)
+ mGpsPresent && requestAllowsGps
? mRequest.getIntervalMillis() : INTERVAL_DISABLED;
long networkInterval = mNlpPresent ? mRequest.getIntervalMillis() : INTERVAL_DISABLED;