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

Commit 8b9146f0 authored by Rhed Jao's avatar Rhed Jao Committed by Android (Google) Code Review
Browse files

Merge "Enforce package visibility filtering on getAuthenticatorTypes API"

parents 8fe347b0 cc5a96ef
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -623,6 +623,9 @@ public class AccountManager {
     *
     * <p>No permission is required to call this method.
     *
     * <p>Caller targeting API level 34 and above, the results are filtered
     * by the rules of <a href="/training/basics/intents/package-visibility">package visibility</a>.
     *
     * @return An array of {@link AuthenticatorDescription} for every
     *     authenticator known to the AccountManager service.  Empty (never
     *     null) if no authenticators are known.
+8 −8
Original line number Diff line number Diff line
@@ -1649,7 +1649,7 @@ public class AccountManagerService

        final long identityToken = clearCallingIdentity();
        try {
            return getAuthenticatorTypesInternal(userId);
            return getAuthenticatorTypesInternal(userId, callingUid);

        } finally {
            restoreCallingIdentity(identityToken);
@@ -1659,19 +1659,19 @@ public class AccountManagerService
    /**
     * Should only be called inside of a clearCallingIdentity block.
     */
    private AuthenticatorDescription[] getAuthenticatorTypesInternal(int userId) {
    private AuthenticatorDescription[] getAuthenticatorTypesInternal(int userId, int callingUid) {
        mAuthenticatorCache.updateServices(userId);
        Collection<AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription>>
                authenticatorCollection = mAuthenticatorCache.getAllServices(userId);
        AuthenticatorDescription[] types =
                new AuthenticatorDescription[authenticatorCollection.size()];
        int i = 0;
        final List<AuthenticatorDescription> types =
                new ArrayList<>(authenticatorCollection.size());
        for (AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticator
                : authenticatorCollection) {
            types[i] = authenticator.type;
            i++;
            if (canCallerAccessPackage(authenticator.type.packageName, callingUid, userId)) {
                types.add(authenticator.type);
            }
        return types;
        }
        return types.toArray(new AuthenticatorDescription[types.size()]);
    }

    private boolean isCrossUser(int callingUid, int userId) {