mLastLocation.clear();
for (LocationProviderInterface p : mProviders) {
updateProviderListenersLocked(p.getName(), false, mCurrentUserId);
- if (!LocationManager.FUSED_PROVIDER.equals(p.getName())) {
- p.switchUser(userId);
- }
+ p.switchUser(userId);
}
mCurrentUserId = userId;
updateProvidersLocked();
mProvidersByName.remove(provider.getName());
}
- /**
- * Returns true if the specified UID is SYSTEM_UID or matches the current user.
- *
- * @param uid the uid
- * @return true if uid is SYSTEM_UID or matches the current user
- */
- private boolean isCurrentUserOrSystemLocked(int uid) {
- return uid == Process.SYSTEM_UID || UserHandle.getUserId(uid) == mCurrentUserId;
- }
-
- /**
- * Returns the first UID in the current user's range.
- *
- * @return the first UID in the current user's range
- */
- private int getCurrentUidBaseLocked() {
- return UserHandle.getUid(mCurrentUserId, 0);
- }
- private boolean isAllowedBySettingsLocked(String provider, int uid) {
- if (!isCurrentUserOrSystemLocked(uid)) {
+ private boolean isAllowedBySettingsLocked(String provider, int userId) {
+ if (userId != mCurrentUserId) {
return false;
}
if (mEnabledProviders.contains(provider)) {
if (mDisabledProviders.contains(provider)) {
return false;
}
- if (uid == Process.SYSTEM_UID) {
- return true;
- }
-
// Use system settings
ContentResolver resolver = mContext.getContentResolver();
public List<String> getProviders(Criteria criteria, boolean enabledOnly) {
int allowedResolutionLevel = getCallerAllowedResolutionLevel();
ArrayList<String> out;
- final int callingUid = Binder.getCallingUid();
- final long identity = Binder.clearCallingIdentity();
+ int callingUserId = UserHandle.getCallingUserId();
+ long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
out = new ArrayList<String>(mProviders.size());
continue;
}
if (allowedResolutionLevel >= getMinimumResolutionLevelForProviderUse(name)) {
- if (enabledOnly && !isAllowedBySettingsLocked(name, callingUid)) {
+ if (enabledOnly && !isAllowedBySettingsLocked(name, callingUserId)) {
continue;
}
if (criteria != null && !LocationProvider.propertiesMeetCriteria(
LocationProviderInterface p = mProviders.get(i);
boolean isEnabled = p.isEnabled();
String name = p.getName();
- boolean shouldBeEnabled = isAllowedBySettingsLocked(name, getCurrentUidBaseLocked());
+ boolean shouldBeEnabled = isAllowedBySettingsLocked(name, mCurrentUserId);
if (isEnabled && !shouldBeEnabled) {
updateProviderListenersLocked(name, false, mCurrentUserId);
changesMade = true;
final int N = records.size();
for (int i = 0; i < N; i++) {
UpdateRecord record = records.get(i);
- if (isCurrentUserOrSystemLocked(record.mReceiver.mUid)) {
+ if (UserHandle.getUserId(record.mReceiver.mUid) == userId) {
// Sends a notification message to the receiver
if (!record.mReceiver.callProviderEnabledLocked(provider, enabled)) {
if (deadReceivers == null) {
if (records != null) {
for (UpdateRecord record : records) {
- if (isCurrentUserOrSystemLocked(record.mReceiver.mUid)) {
+ if (UserHandle.getUserId(record.mReceiver.mUid) == mCurrentUserId) {
LocationRequest locationRequest = record.mRequest;
providerRequest.locationRequests.add(locationRequest);
if (locationRequest.getInterval() < providerRequest.interval) {
// under that threshold.
long thresholdInterval = (providerRequest.interval + 1000) * 3 / 2;
for (UpdateRecord record : records) {
- if (isCurrentUserOrSystemLocked(record.mReceiver.mUid)) {
+ if (UserHandle.getUserId(record.mReceiver.mUid) == mCurrentUserId) {
LocationRequest locationRequest = record.mRequest;
if (locationRequest.getInterval() <= thresholdInterval) {
worksource.add(record.mReceiver.mUid);
oldRecord.disposeLocked(false);
}
- boolean isProviderEnabled = isAllowedBySettingsLocked(name, uid);
+ boolean isProviderEnabled = isAllowedBySettingsLocked(name, UserHandle.getUserId(uid));
if (isProviderEnabled) {
applyRequirementsLocked(name);
} else {
}
// update provider
- int currentUidBase = getCurrentUidBaseLocked();
for (String provider : providers) {
// If provider is already disabled, don't need to do anything
- if (!isAllowedBySettingsLocked(provider, currentUidBase)) {
+ if (!isAllowedBySettingsLocked(provider, mCurrentUserId)) {
continue;
}
request.getProvider());
// no need to sanitize this request, as only the provider name is used
- final int callingUid = Binder.getCallingUid();
- final long identity = Binder.clearCallingIdentity();
+ long identity = Binder.clearCallingIdentity();
try {
if (mBlacklist.isBlacklisted(packageName)) {
if (D) Log.d(TAG, "not returning last loc for blacklisted app: " +
LocationProviderInterface provider = mProvidersByName.get(name);
if (provider == null) return null;
- if (!isAllowedBySettingsLocked(name, callingUid)) {
- return null;
- }
+ if (!isAllowedBySettingsLocked(name, mCurrentUserId)) return null;
Location location = mLastLocation.get(name);
if (location == null) {
provider);
if (LocationManager.FUSED_PROVIDER.equals(provider)) return false;
- final int callingUid = Binder.getCallingUid();
- final long identity = Binder.clearCallingIdentity();
+ long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
LocationProviderInterface p = mProvidersByName.get(provider);
if (p == null) return false;
- return isAllowedBySettingsLocked(provider, callingUid);
+ return isAllowedBySettingsLocked(provider, mCurrentUserId);
}
} finally {
Binder.restoreCallingIdentity(identity);
Receiver receiver = r.mReceiver;
boolean receiverDead = false;
- final int receiverUid = receiver.mUid;
- if (!isCurrentUserOrSystemLocked(receiverUid)) {
+ int receiverUserId = UserHandle.getUserId(receiver.mUid);
+ if (receiverUserId != mCurrentUserId) {
if (D) {
- Log.d(TAG, "skipping loc update for background uid " + receiverUid +
+ Log.d(TAG, "skipping loc update for background user " + receiverUserId +
" (current user: " + mCurrentUserId + ", app: " +
receiver.mPackageName + ")");
}
}
synchronized (mLock) {
- if (isAllowedBySettingsLocked(provider, getCurrentUidBaseLocked())) {
+ if (isAllowedBySettingsLocked(provider, mCurrentUserId)) {
handleLocationChangedLocked(location, passive);
}
}