From e998c73c3380f525b218cd95a3d3f575935c5222 Mon Sep 17 00:00:00 2001 From: Svet Ganov Date: Fri, 10 Jun 2016 00:12:38 -0700 Subject: [PATCH] Blame only location observers that actually receive updates The location manager service keeps update records for all apps registered to receive location updates. If an app does not have the location permission then its update record is skipped when dispatching location updates. However, the battery blame is spread across all apps requesting location updates even if they don't receive such because of lacking permission. bug:28804546 Change-Id: Iee96fd6f304c7a49f9c70484e52abc0ed1538a29 --- .../java/com/android/server/LocationManagerService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index e0b49603ac4fd..36ec2eb9a192f 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -1431,6 +1431,13 @@ public class LocationManagerService extends ILocationManager.Stub { for (UpdateRecord record : records) { if (isCurrentProfile(UserHandle.getUserId(record.mReceiver.mUid))) { LocationRequest locationRequest = record.mRequest; + + // Don't assign battery blame for update records whose + // client has no permission to receive location data. + if (!providerRequest.locationRequests.contains(locationRequest)) { + continue; + } + if (locationRequest.getInterval() <= thresholdInterval) { if (record.mReceiver.mWorkSource != null && record.mReceiver.mWorkSource.size() > 0