AbstractAccountAuthenticatorpublic abstract class AbstractAccountAuthenticator extends Object Abstract base class for creating AccountAuthenticators.
In order to be an authenticator one must extend this class, provider implementations for the
abstract methods and write a service that returns the result of {@link #getIBinder()}
in the service's {@link android.app.Service#onBind(android.content.Intent)} when invoked
with an intent with action {@link AccountManager#ACTION_AUTHENTICATOR_INTENT}. This service
must specify the following intent filter and metadata tags in its AndroidManifest.xml file
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
The android:resource attribute must point to a resource that looks like:
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="typeOfAuthenticator"
android:icon="@drawable/icon"
android:smallIcon="@drawable/miniIcon"
android:label="@string/label"
android:accountPreferences="@xml/account_preferences"
/>
Replace the icons and labels with your own resources. The android:accountType
attribute must be a string that uniquely identifies your authenticator and will be the same
string that user will use when making calls on the {@link AccountManager} and it also
corresponds to {@link Account#type} for your accounts. One user of the android:icon is the
"Account & Sync" settings page and one user of the android:smallIcon is the Contact Application's
tab panels.
The preferences attribute points to a PreferenceScreen xml hierarchy that contains
a list of PreferenceScreens that can be invoked to manage the authenticator. An example is:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/title_fmt" />
<PreferenceScreen
android:key="key1"
android:title="@string/key1_action"
android:summary="@string/key1_summary">
<intent
android:action="key1.ACTION"
android:targetPackage="key1.package"
android:targetClass="key1.class" />
</PreferenceScreen>
</PreferenceScreen>
The standard pattern for implementing any of the abstract methods is the following:
The following descriptions of each of the abstract authenticator methods will not describe the
possible asynchronous nature of the request handling and will instead just describe the input
parameters and the expected result.
When writing an activity to satisfy these requests one must pass in the AccountManagerResponse
and return the result via that response when the activity finishes (or whenever else the
activity author deems it is the correct time to respond).
The {@link AccountAuthenticatorActivity} handles this, so one may wish to extend that when
writing activities to handle these requests. |
Fields Summary |
---|
private static final String | TAG | private final android.content.Context | mContext | private Transport | mTransport |
Methods Summary |
---|
public abstract android.os.Bundle | addAccount(AccountAuthenticatorResponse response, java.lang.String accountType, java.lang.String authTokenType, java.lang.String[] requiredFeatures, android.os.Bundle options)Adds an account of the specified accountType.
| public android.os.Bundle | addAccountFromCredentials(AccountAuthenticatorResponse response, Account account, android.os.Bundle accountCredentials)Creates an account based on credentials provided by the authenticator instance of another
user on the device, who has chosen to share the account with this user.
new Thread(new Runnable() {
public void run() {
Bundle result = new Bundle();
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
response.onResult(result);
}
}).start();
return null;
| private void | checkBinderPermission()
final int uid = Binder.getCallingUid();
final String perm = Manifest.permission.ACCOUNT_MANAGER;
if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("caller uid " + uid + " lacks " + perm);
}
| public abstract android.os.Bundle | confirmCredentials(AccountAuthenticatorResponse response, Account account, android.os.Bundle options)Checks that the user knows the credentials of an account.
| public abstract android.os.Bundle | editProperties(AccountAuthenticatorResponse response, java.lang.String accountType)Returns a Bundle that contains the Intent of the activity that can be used to edit the
properties. In order to indicate success the activity should call response.setResult()
with a non-null Bundle.
| public android.os.Bundle | getAccountCredentialsForCloning(AccountAuthenticatorResponse response, Account account)Returns a Bundle that contains whatever is required to clone the account on a different
user. The Bundle is passed to the authenticator instance in the target user via
{@link #addAccountFromCredentials(AccountAuthenticatorResponse, Account, Bundle)}.
The default implementation returns null, indicating that cloning is not supported.
new Thread(new Runnable() {
public void run() {
Bundle result = new Bundle();
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
response.onResult(result);
}
}).start();
return null;
| public android.os.Bundle | getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account)Checks if the removal of this account is allowed.
final Bundle result = new Bundle();
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
return result;
| public abstract android.os.Bundle | getAuthToken(AccountAuthenticatorResponse response, Account account, java.lang.String authTokenType, android.os.Bundle options)Gets the authtoken for an account.
| public abstract java.lang.String | getAuthTokenLabel(java.lang.String authTokenType)Ask the authenticator for a localized label for the given authTokenType.
| public final android.os.IBinder | getIBinder()
return mTransport.asBinder();
| private void | handleException(IAccountAuthenticatorResponse response, java.lang.String method, java.lang.String data, java.lang.Exception e)
if (e instanceof NetworkErrorException) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, method + "(" + data + ")", e);
}
response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
} else if (e instanceof UnsupportedOperationException) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, method + "(" + data + ")", e);
}
response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
method + " not supported");
} else if (e instanceof IllegalArgumentException) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, method + "(" + data + ")", e);
}
response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
method + " not supported");
} else {
Log.w(TAG, method + "(" + data + ")", e);
response.onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION,
method + " failed");
}
| public abstract android.os.Bundle | hasFeatures(AccountAuthenticatorResponse response, Account account, java.lang.String[] features)Checks if the account supports all the specified authenticator specific features.
| public abstract android.os.Bundle | updateCredentials(AccountAuthenticatorResponse response, Account account, java.lang.String authTokenType, android.os.Bundle options)Update the locally stored credentials for an account.
|
|