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

Commit b1d615d6 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Properly battery blame throttled location requests

Bug: 37552457
Fixes: 37552457
Test: manual

Change-Id: Iba980eb885b5a6465bafc12c9ee35831b7a4ff31
(cherry picked from commit d4def0c6)
parent d3d1c558
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -1727,7 +1727,7 @@ public class LocationManagerService extends ILocationManager.Stub {
                            record.mReceiver.mIdentity.mUid,
                            record.mReceiver.mIdentity.mPackageName,
                            record.mReceiver.mAllowedResolutionLevel)) {
                        LocationRequest locationRequest = record.mRequest;
                        LocationRequest locationRequest = record.mRealRequest;
                        long interval = locationRequest.getInterval();

                        if (!isThrottlingExemptLocked(record.mReceiver.mIdentity)) {
@@ -1740,6 +1740,7 @@ public class LocationManagerService extends ILocationManager.Stub {
                            }
                        }

                        record.mRequest = locationRequest;
                        providerRequest.locationRequests.add(locationRequest);
                        if (interval < providerRequest.interval) {
                            providerRequest.reportLocation = true;
@@ -1832,7 +1833,8 @@ public class LocationManagerService extends ILocationManager.Stub {

    private class UpdateRecord {
        final String mProvider;
        final LocationRequest mRequest;
        final LocationRequest mRealRequest;  // original request from client
        LocationRequest mRequest;  // possibly throttled version of the request
        final Receiver mReceiver;
        boolean mIsForegroundUid;
        Location mLastFixBroadcast;
@@ -1843,6 +1845,7 @@ public class LocationManagerService extends ILocationManager.Stub {
         */
        UpdateRecord(String provider, LocationRequest request, Receiver receiver) {
            mProvider = provider;
            mRealRequest = request;
            mRequest = request;
            mReceiver = receiver;
            mIsForegroundUid = isImportanceForeground(
@@ -1892,7 +1895,7 @@ public class LocationManagerService extends ILocationManager.Stub {
        public String toString() {
            return "UpdateRecord[" + mProvider + " " + mReceiver.mIdentity.mPackageName
                    + "(" + mReceiver.mIdentity.mUid + (mIsForegroundUid ? " foreground" : " background")
                    + ")" + " " + mRequest + "]";
                    + ")" + " " + mRealRequest + "]";
        }
    }

@@ -2533,7 +2536,7 @@ public class LocationManagerService extends ILocationManager.Stub {
        }

        // Check whether sufficient time has passed
        long minTime = record.mRequest.getFastestInterval();
        long minTime = record.mRealRequest.getFastestInterval();
        long delta = (loc.getElapsedRealtimeNanos() - lastLoc.getElapsedRealtimeNanos())
                / NANOS_PER_MILLI;
        if (delta < minTime - MAX_PROVIDER_SCHEDULING_JITTER_MS) {
@@ -2541,7 +2544,7 @@ public class LocationManagerService extends ILocationManager.Stub {
        }

        // Check whether sufficient distance has been traveled
        double minDistance = record.mRequest.getSmallestDisplacement();
        double minDistance = record.mRealRequest.getSmallestDisplacement();
        if (minDistance > 0.0) {
            if (loc.distanceTo(lastLoc) <= minDistance) {
                return false;
@@ -2549,12 +2552,12 @@ public class LocationManagerService extends ILocationManager.Stub {
        }

        // Check whether sufficient number of udpates is left
        if (record.mRequest.getNumUpdates() <= 0) {
        if (record.mRealRequest.getNumUpdates() <= 0) {
            return false;
        }

        // Check whether the expiry date has passed
        return record.mRequest.getExpireAt() >= now;
        return record.mRealRequest.getExpireAt() >= now;
    }

    private void handleLocationChangedLocked(Location location, boolean passive) {
@@ -2672,7 +2675,7 @@ public class LocationManagerService extends ILocationManager.Stub {
                        Slog.w(TAG, "RemoteException calling onLocationChanged on " + receiver);
                        receiverDead = true;
                    }
                    r.mRequest.decrementNumUpdates();
                    r.mRealRequest.decrementNumUpdates();
                }
            }

@@ -2688,7 +2691,7 @@ public class LocationManagerService extends ILocationManager.Stub {
            }

            // track expired records
            if (r.mRequest.getNumUpdates() <= 0 || r.mRequest.getExpireAt() < now) {
            if (r.mRealRequest.getNumUpdates() <= 0 || r.mRealRequest.getExpireAt() < now) {
                if (deadUpdateRecords == null) {
                    deadUpdateRecords = new ArrayList<>();
                }