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

Commit 1681b437 authored by Soonil Nagarkar's avatar Soonil Nagarkar Committed by Android (Google) Code Review
Browse files

Merge "Normalize user active logic across Location APIs"

parents d69fa2d1 0d108d8f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
    }

+22 −6
Original line number Diff line number Diff line
@@ -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
+24 −5
Original line number Diff line number Diff line
@@ -266,11 +266,30 @@ public abstract class GnssListenerMultiplexer<TRequest, TListener extends IInter
        CallerIdentity identity = registration.getIdentity();
        return registration.isPermitted()
                && (registration.isForeground() || isBackgroundRestrictionExempt(identity))
                && (identity.isSystem() || mUserInfoHelper.isCurrentUserId(identity.getUserId()))
                && mLocationManagerInternal.isProviderEnabledForUser(GPS_PROVIDER,
                identity.getUserId())
                && !mSettingsHelper.isLocationPackageBlacklisted(identity.getUserId(),
                identity.getPackageName());
                && isActive(identity);
    }

    private boolean isActive(CallerIdentity identity) {
        if (identity.isSystemServer()) {
            if (!mLocationManagerInternal.isProviderEnabledForUser(GPS_PROVIDER,
                    mUserInfoHelper.getCurrentUserId())) {
                return false;
            }
        } else {
            if (!mLocationManagerInternal.isProviderEnabledForUser(GPS_PROVIDER,
                    identity.getUserId())) {
                return false;
            }
            if (!mUserInfoHelper.isCurrentUserId(identity.getUserId())) {
                return false;
            }
            if (mSettingsHelper.isLocationPackageBlacklisted(identity.getUserId(),
                    identity.getPackageName())) {
                return false;
            }
        }

        return true;
    }

    private boolean isBackgroundRestrictionExempt(CallerIdentity identity) {
+15 −9
Original line number Diff line number Diff line
@@ -88,11 +88,6 @@ public class SystemUserInfoHelper extends UserInfoHelper {
        return mUserManager;
    }

    /**
     * Returns an array of running user ids. This will include all running users, and will also
     * include any profiles of the running users. The caller must never mutate the returned
     * array.
     */
    @Override
    public int[] getRunningUserIds() {
        IActivityManager activityManager = getActivityManager();
@@ -110,10 +105,6 @@ public class SystemUserInfoHelper extends UserInfoHelper {
        }
    }

    /**
     * Returns true if the given user id is either the current user or a profile of the current
     * user.
     */
    @Override
    public boolean isCurrentUserId(@UserIdInt int userId) {
        ActivityManagerInternal activityManagerInternal = getActivityManagerInternal();
@@ -129,6 +120,21 @@ public class SystemUserInfoHelper extends UserInfoHelper {
        }
    }

    @Override
    public @UserIdInt int getCurrentUserId() {
        ActivityManagerInternal activityManagerInternal = getActivityManagerInternal();
        if (activityManagerInternal != null) {
            final long identity = Binder.clearCallingIdentity();
            try {
                return activityManagerInternal.getCurrentUserId();
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        } else {
            return UserHandle.USER_NULL;
        }
    }

    @Override
    protected int[] getProfileIds(@UserIdInt int userId) {
        UserManager userManager = getUserManager();
+6 −0
Original line number Diff line number Diff line
@@ -132,6 +132,12 @@ public abstract class UserInfoHelper {
     */
    public abstract boolean isCurrentUserId(@UserIdInt int userId);

    /**
     * Returns the current user id. Where possible, prefer to use {@link #isCurrentUserId(int)}
     * instead, as that method has more flexibility.
     */
    public abstract @UserIdInt int getCurrentUserId();

    protected abstract int[] getProfileIds(@UserIdInt int userId);

    /**
Loading