From 0d108d8f4c71c80b825206ac50f2033f58597b5b Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Thu, 19 Nov 2020 10:57:16 -0800 Subject: [PATCH] Normalize user active logic across Location APIs Adds additional logic for location requests coming from the system server, such that those requests may allowed so long as location is on for the current user, even if the system user has location disabled. Even though the system server runs under the system user, it may need to service requests from or on behalf of other users. Test: presubmits + manual Change-Id: Ic9d7762e75fc930b7d26f1d1bf20b272d562939c --- .../util/identity/CallerIdentity.java | 4 +- .../location/geofence/GeofenceManager.java | 28 +++++++--- .../gnss/GnssListenerMultiplexer.java | 29 ++++++++-- .../injector/SystemUserInfoHelper.java | 24 +++++---- .../location/injector/UserInfoHelper.java | 6 +++ .../provider/LocationProviderManager.java | 53 +++++++++++-------- .../location/injector/FakeUserInfoHelper.java | 5 ++ 7 files changed, 106 insertions(+), 43 deletions(-) diff --git a/location/java/android/location/util/identity/CallerIdentity.java b/location/java/android/location/util/identity/CallerIdentity.java index e023aa1dcd224..9dbdedeb8a030 100644 --- a/location/java/android/location/util/identity/CallerIdentity.java +++ b/location/java/android/location/util/identity/CallerIdentity.java @@ -150,8 +150,8 @@ public final class CallerIdentity { return mListenerId; } - /** Returns true if this represents a system identity. */ - public boolean isSystem() { + /** Returns true if this represents a system server identity. */ + public boolean isSystemServer() { return mUid == Process.SYSTEM_UID; } diff --git a/services/core/java/com/android/server/location/geofence/GeofenceManager.java b/services/core/java/com/android/server/location/geofence/GeofenceManager.java index 4a8534292eaf0..5a90fa7a271cd 100644 --- a/services/core/java/com/android/server/location/geofence/GeofenceManager.java +++ b/services/core/java/com/android/server/location/geofence/GeofenceManager.java @@ -322,12 +322,28 @@ public class GeofenceManager extends @Override protected boolean isActive(GeofenceRegistration registration) { - CallerIdentity identity = registration.getIdentity(); - return registration.isPermitted() - && (identity.isSystem() || mUserInfoHelper.isCurrentUserId(identity.getUserId())) - && mSettingsHelper.isLocationEnabled(identity.getUserId()) - && !mSettingsHelper.isLocationPackageBlacklisted(identity.getUserId(), - identity.getPackageName()); + return registration.isPermitted() && isActive(registration.getIdentity()); + } + + private boolean isActive(CallerIdentity identity) { + if (identity.isSystemServer()) { + if (!mSettingsHelper.isLocationEnabled(mUserInfoHelper.getCurrentUserId())) { + return false; + } + } else { + if (!mSettingsHelper.isLocationEnabled(identity.getUserId())) { + return false; + } + if (!mUserInfoHelper.isCurrentUserId(identity.getUserId())) { + return false; + } + if (mSettingsHelper.isLocationPackageBlacklisted(identity.getUserId(), + identity.getPackageName())) { + return false; + } + } + + return true; } @Override diff --git a/services/core/java/com/android/server/location/gnss/GnssListenerMultiplexer.java b/services/core/java/com/android/server/location/gnss/GnssListenerMultiplexer.java index e68f595c3c43e..7e848e03c3a0f 100644 --- a/services/core/java/com/android/server/location/gnss/GnssListenerMultiplexer.java +++ b/services/core/java/com/android/server/location/gnss/GnssListenerMultiplexer.java @@ -266,11 +266,30 @@ public abstract class GnssListenerMultiplexer