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

Commit 2785c7f6 authored by Costin Manolache's avatar Costin Manolache Committed by Android (Google) Code Review
Browse files

Merge "Add a new attribute to auth descriptors to indicate custom handling of...

Merge "Add a new attribute to auth descriptors to indicate custom handling of permission and token caching"
parents b23a82cc a40c6304
Loading
Loading
Loading
Loading
+67 −2
Original line number Diff line number Diff line
@@ -3265,6 +3265,17 @@
 visibility="public"
>
</field>
<field name="customTokens"
 type="int"
 transient="false"
 volatile="false"
 value="16843593"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="cycles"
 type="int"
 transient="false"
@@ -18308,6 +18319,28 @@
 visibility="public"
>
</field>
<field name="KEY_CALLER_PID"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;callerPid&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="KEY_CALLER_UID"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;callerUid&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="KEY_ERROR_CODE"
 type="java.lang.String"
 transient="false"
@@ -18555,6 +18588,28 @@
</parameter>
<parameter name="prefId" type="int">
</parameter>
<parameter name="customTokens" type="boolean">
</parameter>
</constructor>
<constructor name="AuthenticatorDescription"
 type="android.accounts.AuthenticatorDescription"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="type" type="java.lang.String">
</parameter>
<parameter name="packageName" type="java.lang.String">
</parameter>
<parameter name="labelId" type="int">
</parameter>
<parameter name="iconId" type="int">
</parameter>
<parameter name="smallIconId" type="int">
</parameter>
<parameter name="prefId" type="int">
</parameter>
</constructor>
<method name="describeContents"
 return="int"
@@ -18615,6 +18670,16 @@
 visibility="public"
>
</field>
<field name="customTokens"
 type="boolean"
 transient="false"
 volatile="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="iconId"
 type="int"
 transient="false"
@@ -223231,7 +223296,7 @@
 abstract="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<constructor name="CacheManager"
@@ -223322,7 +223387,7 @@
 abstract="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
<constructor name="CacheManager.CacheResult"
+5 −3
Original line number Diff line number Diff line
@@ -64,11 +64,13 @@ import java.io.IOException;
                    com.android.internal.R.styleable.AccountAuthenticator_smallIcon, 0);
            final int prefId = sa.getResourceId(
                    com.android.internal.R.styleable.AccountAuthenticator_accountPreferences, 0);
            final boolean customTokens = sa.getBoolean(
                    com.android.internal.R.styleable.AccountAuthenticator_customTokens, false);
            if (TextUtils.isEmpty(accountType)) {
                return null;
            }
            return new AuthenticatorDescription(accountType, packageName, labelId, iconId,
                    smallIconId, prefId);
                    smallIconId, prefId, customTokens);
        } finally {
            sa.recycle();
        }
+6 −0
Original line number Diff line number Diff line
@@ -188,6 +188,12 @@ public class AccountManager {
    public static final String KEY_ERROR_CODE = "errorCode";
    public static final String KEY_ERROR_MESSAGE = "errorMessage";
    public static final String KEY_USERDATA = "userdata";
    /**
     * Authenticators using 'customTokens' option will also get the UID of the
     * caller
     */
    public static final String KEY_CALLER_UID = "callerUid";
    public static final String KEY_CALLER_PID = "callerPid";

    public static final String ACTION_AUTHENTICATOR_INTENT =
            "android.accounts.AccountAuthenticator";
+22 −4
Original line number Diff line number Diff line
@@ -893,13 +893,29 @@ public class AccountManagerService
        if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
        checkBinderPermission(Manifest.permission.USE_CREDENTIALS);
        final int callerUid = Binder.getCallingUid();
        final boolean permissionGranted = permissionIsGranted(account, authTokenType, callerUid);
        final int callerPid = Binder.getCallingPid();

        AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo =
            mAuthenticatorCache.getServiceInfo(
                    AuthenticatorDescription.newKey(account.type));
        final boolean customTokens =
            authenticatorInfo != null && authenticatorInfo.type.customTokens;

        // skip the check if customTokens
        final boolean permissionGranted = customTokens ||
            permissionIsGranted(account, authTokenType, callerUid);

        if (customTokens) {
            // let authenticator know the identity of the caller
            loginOptions.putInt(AccountManager.KEY_CALLER_UID, callerUid);
            loginOptions.putInt(AccountManager.KEY_CALLER_PID, callerPid);
        }

        long identityToken = clearCallingIdentity();
        try {
            // if the caller has permission, do the peek. otherwise go the more expensive
            // route of starting a Session
            if (permissionGranted) {
            if (!customTokens && permissionGranted) {
                String authToken = readAuthTokenFromCache(account, authTokenType);
                if (authToken != null) {
                    Bundle result = new Bundle();
@@ -953,9 +969,11 @@ public class AccountManagerService
                                        "the type and name should not be empty");
                                return;
                            }
                            if (!customTokens) {
                                saveAuthTokenToDatabase(new Account(name, type),
                                        authTokenType, authToken);
                            }
                        }

                        Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
                        if (intent != null && notifyOnAuthFailure) {
+13 −1
Original line number Diff line number Diff line
@@ -44,9 +44,12 @@ public class AuthenticatorDescription implements Parcelable {
    /** The package name that can be used to lookup the resources from above. */
    final public String packageName;

    /** Authenticator handles its own token caching and permission screen */
    final public boolean customTokens;

    /** A constructor for a full AuthenticatorDescription */
    public AuthenticatorDescription(String type, String packageName, int labelId, int iconId,
            int smallIconId, int prefId) {
            int smallIconId, int prefId, boolean customTokens) {
        if (type == null) throw new IllegalArgumentException("type cannot be null");
        if (packageName == null) throw new IllegalArgumentException("packageName cannot be null");
        this.type = type;
@@ -55,6 +58,12 @@ public class AuthenticatorDescription implements Parcelable {
        this.iconId = iconId;
        this.smallIconId = smallIconId;
        this.accountPreferencesId = prefId;
        this.customTokens = customTokens;
    }

    public AuthenticatorDescription(String type, String packageName, int labelId, int iconId,
            int smallIconId, int prefId) {
        this(type, packageName, labelId, iconId, smallIconId, prefId, false);
    }

    /**
@@ -74,6 +83,7 @@ public class AuthenticatorDescription implements Parcelable {
        this.iconId = 0;
        this.smallIconId = 0;
        this.accountPreferencesId = 0;
        this.customTokens = false;
    }

    private AuthenticatorDescription(Parcel source) {
@@ -83,6 +93,7 @@ public class AuthenticatorDescription implements Parcelable {
        this.iconId = source.readInt();
        this.smallIconId = source.readInt();
        this.accountPreferencesId = source.readInt();
        this.customTokens = source.readByte() == 1;
    }

    /** @inheritDoc */
@@ -115,6 +126,7 @@ public class AuthenticatorDescription implements Parcelable {
        dest.writeInt(iconId);
        dest.writeInt(smallIconId);
        dest.writeInt(accountPreferencesId);
        dest.writeByte((byte) (customTokens ? 1 : 0));
    }

    /** Used to create the object from a parcel. */
Loading