diff --git a/core/java/com/android/server/SystemConfig.java b/core/java/com/android/server/SystemConfig.java index fcb4c7b481253..3d012bf24f7a5 100644 --- a/core/java/com/android/server/SystemConfig.java +++ b/core/java/com/android/server/SystemConfig.java @@ -109,6 +109,10 @@ public class SystemConfig { // background while in data-usage save mode, as read from the configuration files. final ArraySet mAllowInDataUsageSave = new ArraySet<>(); + // These are the packages that are white-listed to be able to run background location + // without throttling, as read from the configuration files. + final ArraySet mAllowUnthrottledLocation = new ArraySet<>(); + // These are the action strings of broadcasts which are whitelisted to // be delivered anonymously even to apps which target O+. final ArraySet mAllowImplicitBroadcasts = new ArraySet<>(); @@ -182,6 +186,10 @@ public class SystemConfig { return mAllowInDataUsageSave; } + public ArraySet getAllowUnthrottledLocation() { + return mAllowUnthrottledLocation; + } + public ArraySet getLinkedApps() { return mLinkedApps; } @@ -446,6 +454,17 @@ public class SystemConfig { XmlUtils.skipCurrentTag(parser); continue; + } else if ("allow-unthrottled-location".equals(name) && allowAll) { + String pkgname = parser.getAttributeValue(null, "package"); + if (pkgname == null) { + Slog.w(TAG, " without package in " + + permFile + " at " + parser.getPositionDescription()); + } else { + mAllowUnthrottledLocation.add(pkgname); + } + XmlUtils.skipCurrentTag(parser); + continue; + } else if ("allow-implicit-broadcast".equals(name) && allowAll) { String action = parser.getAttributeValue(null, "action"); if (action == null) { diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index 42eb958bba0b6..ef7780c79126f 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -19,6 +19,7 @@ package com.android.server; import android.app.ActivityManager; import android.annotation.NonNull; import android.content.pm.PackageManagerInternal; +import android.util.ArraySet; import com.android.internal.content.PackageMonitor; import com.android.internal.location.ProviderProperties; import com.android.internal.location.ProviderRequest; @@ -135,8 +136,6 @@ public class LocationManagerService extends ILocationManager.Stub { private static final String FUSED_LOCATION_SERVICE_ACTION = "com.android.location.service.FusedLocationProvider"; - private static final String GMSCORE_PACKAGE = "com.android.google.gms"; - private static final int MSG_LOCATION_CHANGED = 1; private static final long NANOS_PER_MILLI = 1000000L; @@ -224,7 +223,7 @@ public class LocationManagerService extends ILocationManager.Stub { private final ArrayList mProxyProviders = new ArrayList<>(); - private String[] mBackgroundThrottlePackageWhitelist = new String[]{}; + private final ArraySet mBackgroundThrottlePackageWhitelist = new ArraySet<>(); // current active user on the device - other users are denied location data private int mCurrentUserId = UserHandle.USER_SYSTEM; @@ -345,6 +344,8 @@ public class LocationManagerService extends ILocationManager.Stub { mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); updateUserProfiles(mCurrentUserId); + updateThrottlingWhitelistLocked(); + // prepare providers loadProvidersLocked(); updateProvidersLocked(); @@ -380,14 +381,7 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public void onChange(boolean selfChange) { synchronized (mLock) { - String setting = Settings.Global.getString( - mContext.getContentResolver(), - Settings.Global.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST); - if (setting == null) { - setting = ""; - } - - mBackgroundThrottlePackageWhitelist = setting.split(","); + updateThrottlingWhitelistLocked(); updateProvidersLocked(); } } @@ -1747,12 +1741,27 @@ public class LocationManagerService extends ILocationManager.Stub { p.setRequest(providerRequest, worksource); } + private void updateThrottlingWhitelistLocked() { + String setting = Settings.Global.getString( + mContext.getContentResolver(), + Settings.Global.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST); + if (setting == null) { + setting = ""; + } + + mBackgroundThrottlePackageWhitelist.clear(); + mBackgroundThrottlePackageWhitelist.addAll( + SystemConfig.getInstance().getAllowUnthrottledLocation()); + mBackgroundThrottlePackageWhitelist.addAll( + Arrays.asList(setting.split(","))); + } + private boolean isThrottlingExemptLocked(Receiver receiver) { if (receiver.mUid == Process.SYSTEM_UID) { return true; } - if (receiver.mPackageName.equals(GMSCORE_PACKAGE)) { + if (mBackgroundThrottlePackageWhitelist.contains(receiver.mPackageName)) { return true; } @@ -1762,12 +1771,6 @@ public class LocationManagerService extends ILocationManager.Stub { } } - for (String whitelistedPackage : mBackgroundThrottlePackageWhitelist) { - if (receiver.mPackageName.equals(whitelistedPackage)) { - return true; - } - } - return false; } @@ -2999,6 +3002,13 @@ public class LocationManagerService extends ILocationManager.Stub { } } + if (!mBackgroundThrottlePackageWhitelist.isEmpty()) { + pw.println(" Throttling Whitelisted Packages:"); + for (String packageName : mBackgroundThrottlePackageWhitelist) { + pw.println(" " + packageName); + } + } + pw.append(" fudger: "); mLocationFudger.dump(fd, pw, args);