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

Commit 31957f1b authored by Fred Quintana's avatar Fred Quintana
Browse files

- add javadoc for the account manager

- add some checks to the AccountManagerService to keep it from crashing when a null is passed in
- cleaned up the API a bit
parent 04104665
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -13804,6 +13804,8 @@
</parameter>
<parameter name="options" type="android.os.Bundle">
</parameter>
<exception name="NetworkErrorException" type="android.accounts.NetworkErrorException">
</exception>
</method>
<method name="editProperties"
 return="android.os.Bundle"
@@ -13853,7 +13855,7 @@
</parameter>
<parameter name="authTokenType" type="java.lang.String">
</parameter>
<parameter name="loginOptions" type="android.os.Bundle">
<parameter name="options" type="android.os.Bundle">
</parameter>
<exception name="NetworkErrorException" type="android.accounts.NetworkErrorException">
</exception>
@@ -13917,8 +13919,10 @@
</parameter>
<parameter name="authTokenType" type="java.lang.String">
</parameter>
<parameter name="loginOptions" type="android.os.Bundle">
<parameter name="options" type="android.os.Bundle">
</parameter>
<exception name="NetworkErrorException" type="android.accounts.NetworkErrorException">
</exception>
</method>
</class>
<class name="Account"
@@ -14183,7 +14187,7 @@
</parameter>
<parameter name="password" type="java.lang.String">
</parameter>
<parameter name="extras" type="android.os.Bundle">
<parameter name="userdata" type="android.os.Bundle">
</parameter>
</method>
<method name="addOnAccountsUpdatedListener"
@@ -14349,7 +14353,7 @@
</parameter>
<parameter name="authTokenType" type="java.lang.String">
</parameter>
<parameter name="loginOptions" type="android.os.Bundle">
<parameter name="options" type="android.os.Bundle">
</parameter>
<parameter name="activity" type="android.app.Activity">
</parameter>
@@ -14399,7 +14403,7 @@
</parameter>
<parameter name="addAccountOptions" type="android.os.Bundle">
</parameter>
<parameter name="loginOptions" type="android.os.Bundle">
<parameter name="getAuthTokenOptions" type="android.os.Bundle">
</parameter>
<parameter name="callback" type="android.accounts.AccountManagerCallback&lt;android.os.Bundle&gt;">
</parameter>
@@ -14568,7 +14572,7 @@
</parameter>
<parameter name="authTokenType" type="java.lang.String">
</parameter>
<parameter name="loginOptions" type="android.os.Bundle">
<parameter name="options" type="android.os.Bundle">
</parameter>
<parameter name="activity" type="android.app.Activity">
</parameter>
+37 −59
Original line number Diff line number Diff line
@@ -87,6 +87,9 @@ import android.Manifest;
 * the {@link AccountAuthenticatorResponse} as {@link AccountManager#KEY_ACCOUNT_MANAGER_RESPONSE}.
 * The activity must then call {@link AccountAuthenticatorResponse#onResult} or
 * {@link AccountAuthenticatorResponse#onError} when it is complete.
 * <li> If the authenticator cannot synchronously process the request and return a result then it
 * may choose to return null and then use the {@link AccountManagerResponse} to send the result
 * when it has completed the request.
 * </ul>
 * <p>
 * The following descriptions of each of the abstract authenticator methods will not describe the
@@ -111,44 +114,35 @@ public abstract class AbstractAccountAuthenticator {
                String authTokenType, String[] requiredFeatures, Bundle options)
                throws RemoteException {
            checkBinderPermission();
            final Bundle result;
            try {
                result = AbstractAccountAuthenticator.this.addAccount(
                final Bundle result = AbstractAccountAuthenticator.this.addAccount(
                    new AccountAuthenticatorResponse(response),
                        accountType, authTokenType, requiredFeatures, options);
                if (result != null) {
                    response.onResult(result);
                }
            } catch (NetworkErrorException e) {
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
                return;
            } catch (UnsupportedOperationException e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "addAccount not supported");
                return;
            }
            if (result != null) {
                response.onResult(result);
            } else {
                response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE,
                        "no response from the authenticator");
            }
        }

        public void confirmCredentials(IAccountAuthenticatorResponse response,
                Account account, Bundle options) throws RemoteException {
            checkBinderPermission();
            final Bundle result;
            try {
                result = AbstractAccountAuthenticator.this.confirmCredentials(
                final Bundle result = AbstractAccountAuthenticator.this.confirmCredentials(
                    new AccountAuthenticatorResponse(response), account, options);
                if (result != null) {
                    response.onResult(result);
                }
            } catch (NetworkErrorException e) {
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
            } catch (UnsupportedOperationException e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "confirmCredentials not supported");
                return;
            }
            if (result != null) {
                response.onResult(result);
            } else {
                response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE,
                        "no response from the authenticator");
            }
        }

@@ -180,9 +174,6 @@ public abstract class AbstractAccountAuthenticator {
                        authTokenType, loginOptions);
                if (result != null) {
                    response.onResult(result);
                } else {
                    response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE,
                            "no response from the authenticator");
                }
            } catch (UnsupportedOperationException e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
@@ -195,64 +186,50 @@ public abstract class AbstractAccountAuthenticator {
        public void updateCredentials(IAccountAuthenticatorResponse response, Account account,
                String authTokenType, Bundle loginOptions) throws RemoteException {
            checkBinderPermission();
            final Bundle result;
            try {
                result = AbstractAccountAuthenticator.this.updateCredentials(
                final Bundle result = AbstractAccountAuthenticator.this.updateCredentials(
                    new AccountAuthenticatorResponse(response), account,
                        authTokenType, loginOptions);
                if (result != null) {
                    response.onResult(result);
                }
            } catch (NetworkErrorException e) {
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
            } catch (UnsupportedOperationException e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "updateCredentials not supported");
                return;
            }
            if (result != null) {
                response.onResult(result);
            } else {
                response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE,
                        "no response from the authenticator");
            }
        }

        public void editProperties(IAccountAuthenticatorResponse response,
                String accountType) throws RemoteException {
            checkBinderPermission();
            final Bundle result;
            try {
                result = AbstractAccountAuthenticator.this.editProperties(
                final Bundle result = AbstractAccountAuthenticator.this.editProperties(
                    new AccountAuthenticatorResponse(response), accountType);
                if (result != null) {
                    response.onResult(result);
                }
            } catch (UnsupportedOperationException e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "editProperties not supported");
                return;
            }
            if (result != null) {
                response.onResult(result);
            } else {
                response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE,
                        "no response from the authenticator");
            }
        }

        public void hasFeatures(IAccountAuthenticatorResponse response,
                Account account, String[] features) throws RemoteException {
            checkBinderPermission();
            final Bundle result;
            try {
                result = AbstractAccountAuthenticator.this.hasFeatures(
                final Bundle result = AbstractAccountAuthenticator.this.hasFeatures(
                    new AccountAuthenticatorResponse(response), account, features);
                if (result != null) {
                    response.onResult(result);
                }
            } catch (UnsupportedOperationException e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "hasFeatures not supported");
                return;
            } catch (NetworkErrorException e) {
                response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
                return;
            }
            if (result != null) {
                response.onResult(result);
            } else {
                response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE,
                        "no response from the authenticator");
            }
        }

@@ -264,9 +241,6 @@ public abstract class AbstractAccountAuthenticator {
                    new AccountAuthenticatorResponse(response), account);
                if (result != null) {
                    response.onResult(result);
                } else {
                    response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE,
                            "no response from the authenticator");
                }
            } catch (UnsupportedOperationException e) {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
@@ -347,16 +321,18 @@ public abstract class AbstractAccountAuthenticator {
     * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
     * indicate an error
     * </ul>
     * @throws NetworkErrorException if the authenticator could not honor the request due to a
     * network error
     */
    public abstract Bundle confirmCredentials(AccountAuthenticatorResponse response,
            Account account, Bundle options);

            Account account, Bundle options)
            throws NetworkErrorException;
    /**
     * Gets the authtoken for an account.
     * @param response to send the result back to the AccountManager, will never be null
     * @param account the account whose credentials are to be retrieved, will never be null
     * @param authTokenType the type of auth token to retrieve, will never be null
     * @param loginOptions a Bundle of authenticator-specific options, may be null
     * @param options a Bundle of authenticator-specific options, may be null
     * @return a Bundle result or null if the result is to be returned via the response. The result
     * will contain either:
     * <ul>
@@ -370,7 +346,7 @@ public abstract class AbstractAccountAuthenticator {
     * network error
     */
    public abstract Bundle getAuthToken(AccountAuthenticatorResponse response,
            Account account, String authTokenType, Bundle loginOptions)
            Account account, String authTokenType, Bundle options)
            throws NetworkErrorException;

    /**
@@ -386,7 +362,7 @@ public abstract class AbstractAccountAuthenticator {
     * @param account the account whose credentials are to be updated, will never be null
     * @param authTokenType the type of auth token to retrieve after updating the credentials,
     * may be null
     * @param loginOptions a Bundle of authenticator-specific options, may be null
     * @param options a Bundle of authenticator-specific options, may be null
     * @return a Bundle result or null if the result is to be returned via the response. The result
     * will contain either:
     * <ul>
@@ -397,9 +373,11 @@ public abstract class AbstractAccountAuthenticator {
     * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
     * indicate an error
     * </ul>
     * @throws NetworkErrorException if the authenticator could not honor the request due to a
     * network error
     */
    public abstract Bundle updateCredentials(AccountAuthenticatorResponse response,
            Account account, String authTokenType, Bundle loginOptions);
            Account account, String authTokenType, Bundle options) throws NetworkErrorException;
    
    /**
     * Checks if the account supports all the specified authenticator specific features.
+4 −19
Original line number Diff line number Diff line
@@ -56,30 +56,14 @@ public class AccountAuthenticatorActivity extends Activity {
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        if (icicle == null) {
            Intent intent = getIntent();
        mAccountAuthenticatorResponse =
                    intent.getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
        } else {
            mAccountAuthenticatorResponse =
                    icicle.getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
        }
                getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);

        if (mAccountAuthenticatorResponse != null) {
            mAccountAuthenticatorResponse.onRequestContinued();
        }
    }

    /**
     * Saves the AccountAuthenticatorResponse in the instance state.
     * @param outState where to store any instance data
     */
    protected void onSaveInstanceState(Bundle outState) {
        outState.putParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,
                mAccountAuthenticatorResponse);
        super.onSaveInstanceState(outState);
    }

    /**
     * Sends the result or a Constants.ERROR_CODE_CANCELED error if a result isn't present.
     */
@@ -89,7 +73,8 @@ public class AccountAuthenticatorActivity extends Activity {
            if (mResultBundle != null) {
                mAccountAuthenticatorResponse.onResult(mResultBundle);
            } else {
                mAccountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
                mAccountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED,
                        "canceled");
            }
            mAccountAuthenticatorResponse = null;
        }
+33 −12
Original line number Diff line number Diff line
@@ -237,13 +237,13 @@ public class AccountManager {
     * with the same UID as the Authenticator for the account.
     * @param account The account to add
     * @param password The password to associate with the account. May be null.
     * @param extras A bundle of key/value pairs to set as the account's userdata. May be null.
     * @param userdata A bundle of key/value pairs to set as the account's userdata. May be null.
     * @return true if the account was sucessfully added, false otherwise, for example,
     * if the account already exists or if the account is null
     */
    public boolean addAccountExplicitly(Account account, String password, Bundle extras) {
    public boolean addAccountExplicitly(Account account, String password, Bundle userdata) {
        try {
            return mService.addAccount(account, password, extras);
            return mService.addAccount(account, password, userdata);
        } catch (RemoteException e) {
            // won't ever happen
            throw new RuntimeException(e);
@@ -320,6 +320,12 @@ public class AccountManager {
     * AccountManager, null otherwise.
     */
    public String peekAuthToken(final Account account, final String authTokenType) {
        if (account == null) {
            throw new IllegalArgumentException("the account must not be null");
        }
        if (authTokenType == null) {
            return null;
        }
        try {
            return mService.peekAuthToken(account, authTokenType);
        } catch (RemoteException e) {
@@ -339,6 +345,9 @@ public class AccountManager {
     * @param password the password to set for the account. May be null.
     */
    public void setPassword(final Account account, final String password) {
        if (account == null) {
            throw new IllegalArgumentException("the account must not be null");
        }
        try {
            mService.setPassword(account, password);
        } catch (RemoteException e) {
@@ -355,6 +364,9 @@ public class AccountManager {
     * @param account the account whose password is to be cleared. Must not be null.
     */
    public void clearPassword(final Account account) {
        if (account == null) {
            throw new IllegalArgumentException("the account must not be null");
        }
        try {
            mService.clearPassword(account);
        } catch (RemoteException e) {
@@ -375,6 +387,12 @@ public class AccountManager {
     * @param value the value to set. May be null.
     */
    public void setUserData(final Account account, final String key, final String value) {
        if (account == null) {
            throw new IllegalArgumentException("the account must not be null");
        }
        if (key == null) {
            throw new IllegalArgumentException("the key must not be null");
        }
        try {
            mService.setUserData(account, key, value);
        } catch (RemoteException e) {
@@ -458,7 +476,7 @@ public class AccountManager {
     * @param account The account whose credentials are to be updated.
     * @param authTokenType the auth token to retrieve as part of updating the credentials.
     * May be null.
     * @param loginOptions authenticator specific options for the request
     * @param options authenticator specific options for the request
     * @param activity If the authenticator returns a {@link #KEY_INTENT} in the result then
     * the intent will be started with this activity. If activity is null then the result will
     * be returned as-is.
@@ -474,7 +492,7 @@ public class AccountManager {
     * If the user presses "back" then the request will be canceled.
     */
    public AccountManagerFuture<Bundle> getAuthToken(
            final Account account, final String authTokenType, final Bundle loginOptions,
            final Account account, final String authTokenType, final Bundle options,
            final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
        if (activity == null) throw new IllegalArgumentException("activity is null");
        if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
@@ -482,7 +500,7 @@ public class AccountManager {
            public void doWork() throws RemoteException {
                mService.getAuthToken(mResponse, account, authTokenType,
                        false /* notifyOnAuthFailure */, true /* expectActivityLaunch */,
                        loginOptions);
                        options);
            }
        }.start();
    }
@@ -584,6 +602,9 @@ public class AccountManager {
            final String authTokenType, final String[] requiredFeatures,
            final Bundle addAccountOptions,
            final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
        if (accountType == null) {
            throw new IllegalArgumentException();
        }
        return new AmsTask(activity, handler, callback) {
            public void doWork() throws RemoteException {
                mService.addAcount(mResponse, accountType, authTokenType,
@@ -683,7 +704,7 @@ public class AccountManager {
     * @param account The account whose credentials are to be updated.
     * @param authTokenType the auth token to retrieve as part of updating the credentials.
     * May be null.
     * @param loginOptions authenticator specific options for the request
     * @param options authenticator specific options for the request
     * @param activity If the authenticator returns a {@link #KEY_INTENT} in the result then
     * the intent will be started with this activity. If activity is null then the result will
     * be returned as-is.
@@ -702,13 +723,13 @@ public class AccountManager {
     */
    public AccountManagerFuture<Bundle> updateCredentials(final Account account,
            final String authTokenType,
            final Bundle loginOptions, final Activity activity,
            final Bundle options, final Activity activity,
            final AccountManagerCallback<Bundle> callback,
            final Handler handler) {
        return new AmsTask(activity, handler, callback) {
            public void doWork() throws RemoteException {
                mService.updateCredentials(mResponse, account, authTokenType, activity != null,
                        loginOptions);
                        options);
            }
        }.start();
    }
@@ -1214,7 +1235,7 @@ public class AccountManager {
     * @param activityForPrompting The activity used to start any account management
     * activities that are required to fulfill this request. This may be null.
     * @param addAccountOptions authenticator-specific options used if an account needs to be added
     * @param loginOptions authenticator-specific options passed to getAuthToken
     * @param getAuthTokenOptions authenticator-specific options passed to getAuthToken
     * @param callback A callback to invoke when the request completes. If null then
     * no callback is invoked.
     * @param handler The {@link Handler} to use to invoke the callback. If null then the
@@ -1232,13 +1253,13 @@ public class AccountManager {
    public AccountManagerFuture<Bundle> getAuthTokenByFeatures(
            final String accountType, final String authTokenType, final String[] features,
            final Activity activityForPrompting, final Bundle addAccountOptions,
            final Bundle loginOptions,
            final Bundle getAuthTokenOptions,
            final AccountManagerCallback<Bundle> callback, final Handler handler) {
        if (accountType == null) throw new IllegalArgumentException("account type is null");
        if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
        final GetAuthTokenByTypeAndFeaturesTask task =
                new GetAuthTokenByTypeAndFeaturesTask(accountType, authTokenType, features,
                activityForPrompting, addAccountOptions, loginOptions, callback, handler);
                activityForPrompting, addAccountOptions, getAuthTokenOptions, callback, handler);
        task.start();
        return task;
    }
+102 −17

File changed.

Preview size limit exceeded, changes collapsed.