Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1490213 authored by David Christie's avatar David Christie
Browse files

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
parent 5dc2f75f
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -187,6 +187,16 @@ flag {
    is_fixed_read_only: true
}

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"
+11 −1
Original line number Diff line number Diff line
@@ -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;