- 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
This commit is contained in:
@@ -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<android.os.Bundle>">
|
||||
</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>
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
mAccountAuthenticatorResponse =
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -154,6 +154,7 @@ public class AccountManagerService
|
||||
private static final boolean isDebuggableMonkeyBuild =
|
||||
SystemProperties.getBoolean("ro.monkey", false)
|
||||
&& SystemProperties.getBoolean("ro.debuggable", false);
|
||||
private static final Account[] EMPTY_ACCOUNT_ARRAY = new Account[]{};
|
||||
|
||||
static {
|
||||
ACCOUNTS_CHANGED_INTENT = new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION);
|
||||
@@ -268,6 +269,10 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
private String readPasswordFromDatabase(Account account) {
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
|
||||
Cursor cursor = db.query(TABLE_ACCOUNTS, new String[]{ACCOUNTS_PASSWORD},
|
||||
ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
|
||||
@@ -293,6 +298,10 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
private String readUserDataFromDatabase(Account account, String key) {
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
|
||||
Cursor cursor = db.query(TABLE_EXTRAS, new String[]{EXTRAS_VALUE},
|
||||
EXTRAS_ACCOUNTS_ID
|
||||
@@ -364,6 +373,9 @@ public class AccountManagerService
|
||||
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
try {
|
||||
if (account == null) {
|
||||
return false;
|
||||
}
|
||||
boolean noBroadcast = false;
|
||||
if (account.type.equals(GOOGLE_ACCOUNT_TYPE)) {
|
||||
// Look for the 'nobroadcast' flag and remove it since we don't want it to persist
|
||||
@@ -417,6 +429,14 @@ public class AccountManagerService
|
||||
checkManageAccountsPermission();
|
||||
long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
if (account == null) {
|
||||
try {
|
||||
response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, "null account");
|
||||
} catch (RemoteException e) {
|
||||
// it doesn't matter if we are unable to deliver this error
|
||||
}
|
||||
return;
|
||||
}
|
||||
new RemoveAccountSession(response, account).bind();
|
||||
} finally {
|
||||
restoreCallingIdentity(identityToken);
|
||||
@@ -513,6 +533,9 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
private boolean saveAuthTokenToDatabase(Account account, String type, String authToken) {
|
||||
if (account == null || type == null) {
|
||||
return false;
|
||||
}
|
||||
cancelNotification(getSigninRequiredNotificationId(account));
|
||||
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
@@ -539,6 +562,9 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
public String readAuthTokenFromDatabase(Account account, String authTokenType) {
|
||||
if (account == null || authTokenType == null) {
|
||||
return null;
|
||||
}
|
||||
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
|
||||
Cursor cursor = db.query(TABLE_AUTHTOKENS, new String[]{AUTHTOKENS_AUTHTOKEN},
|
||||
AUTHTOKENS_ACCOUNTS_ID + "=(select _id FROM accounts WHERE name=? AND type=?) AND "
|
||||
@@ -586,6 +612,9 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
private void setPasswordInDB(Account account, String password) {
|
||||
if (account == null) {
|
||||
return;
|
||||
}
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ACCOUNTS_PASSWORD, password);
|
||||
mOpenHelper.getWritableDatabase().update(TABLE_ACCOUNTS, values,
|
||||
@@ -608,23 +637,12 @@ public class AccountManagerService
|
||||
}
|
||||
}
|
||||
|
||||
private void sendResult(IAccountManagerResponse response, Bundle bundle) {
|
||||
if (response != null) {
|
||||
try {
|
||||
response.onResult(bundle);
|
||||
} catch (RemoteException e) {
|
||||
// if the caller is dead then there is no one to care about remote
|
||||
// exceptions
|
||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||
Log.v(TAG, "failure while notifying response", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUserData(Account account, String key, String value) {
|
||||
checkAuthenticateAccountsPermission(account);
|
||||
long identityToken = clearCallingIdentity();
|
||||
if (account == null) {
|
||||
return;
|
||||
}
|
||||
if (account.type.equals(GOOGLE_ACCOUNT_TYPE) && key.equals("broadcast")) {
|
||||
sendAccountsChangedBroadcast();
|
||||
return;
|
||||
@@ -637,6 +655,9 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
private void writeUserdataIntoDatabase(Account account, String key, String value) {
|
||||
if (account == null || key == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
try {
|
||||
@@ -685,6 +706,22 @@ public class AccountManagerService
|
||||
|
||||
long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
try {
|
||||
if (account == null) {
|
||||
response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
|
||||
"account is null");
|
||||
return;
|
||||
}
|
||||
if (authTokenType == null) {
|
||||
response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
|
||||
"authTokenType is null");
|
||||
return;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// it doesn't matter if we can't deliver this error
|
||||
return;
|
||||
}
|
||||
|
||||
// if the caller has permission, do the peek. otherwise go the more expensive
|
||||
// route of starting a Session
|
||||
if (permissionGranted) {
|
||||
@@ -850,6 +887,16 @@ public class AccountManagerService
|
||||
checkManageAccountsPermission();
|
||||
long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
try {
|
||||
if (authTokenType == null) {
|
||||
response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
|
||||
"authTokenType is null");
|
||||
return;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// it doesn't matter if we can't deliver this error
|
||||
return;
|
||||
}
|
||||
new Session(response, accountType, expectActivityLaunch) {
|
||||
public void run() throws RemoteException {
|
||||
mAuthenticator.addAccount(this, mAccountType, authTokenType, requiredFeatures,
|
||||
@@ -875,6 +922,16 @@ public class AccountManagerService
|
||||
checkManageAccountsPermission();
|
||||
long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
try {
|
||||
if (account == null) {
|
||||
response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
|
||||
"account is null");
|
||||
return;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// it doesn't matter if we can't deliver this error
|
||||
return;
|
||||
}
|
||||
new Session(response, account.type, expectActivityLaunch) {
|
||||
public void run() throws RemoteException {
|
||||
mAuthenticator.confirmCredentials(this, account, options);
|
||||
@@ -895,6 +952,16 @@ public class AccountManagerService
|
||||
checkManageAccountsPermission();
|
||||
long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
try {
|
||||
if (account == null) {
|
||||
response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
|
||||
"account is null");
|
||||
return;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// it doesn't matter if we can't deliver this error
|
||||
return;
|
||||
}
|
||||
new Session(response, account.type, expectActivityLaunch) {
|
||||
public void run() throws RemoteException {
|
||||
mAuthenticator.updateCredentials(this, account, authTokenType, loginOptions);
|
||||
@@ -917,6 +984,16 @@ public class AccountManagerService
|
||||
checkManageAccountsPermission();
|
||||
long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
try {
|
||||
if (accountType == null) {
|
||||
response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
|
||||
"accountType is null");
|
||||
return;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
// it doesn't matter if we can't deliver this error
|
||||
return;
|
||||
}
|
||||
new Session(response, accountType, expectActivityLaunch) {
|
||||
public void run() throws RemoteException {
|
||||
mAuthenticator.editProperties(this, mAccountType);
|
||||
@@ -1565,8 +1642,10 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
private boolean permissionIsGranted(Account account, String authTokenType, int callerUid) {
|
||||
final boolean fromAuthenticator = hasAuthenticatorUid(account.type, callerUid);
|
||||
final boolean hasExplicitGrants = hasExplicitlyGrantedPermission(account, authTokenType);
|
||||
final boolean fromAuthenticator = account != null
|
||||
&& hasAuthenticatorUid(account.type, callerUid);
|
||||
final boolean hasExplicitGrants = account != null
|
||||
&& hasExplicitlyGrantedPermission(account, authTokenType);
|
||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||
Log.v(TAG, "checkGrantsOrCallingUidAgainstAuthenticator: caller uid "
|
||||
+ callerUid + ", account " + account
|
||||
@@ -1610,7 +1689,7 @@ public class AccountManagerService
|
||||
|
||||
private void checkCallingUidAgainstAuthenticator(Account account) {
|
||||
final int uid = Binder.getCallingUid();
|
||||
if (!hasAuthenticatorUid(account.type, uid)) {
|
||||
if (account == null || !hasAuthenticatorUid(account.type, uid)) {
|
||||
String msg = "caller uid " + uid + " is different than the authenticator's uid";
|
||||
Log.w(TAG, msg);
|
||||
throw new SecurityException(msg);
|
||||
@@ -1641,6 +1720,9 @@ public class AccountManagerService
|
||||
* @hide
|
||||
*/
|
||||
public void grantAppPermission(Account account, String authTokenType, int uid) {
|
||||
if (account == null || authTokenType == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
try {
|
||||
@@ -1668,6 +1750,9 @@ public class AccountManagerService
|
||||
* @hide
|
||||
*/
|
||||
public void revokeAppPermission(Account account, String authTokenType, int uid) {
|
||||
if (account == null || authTokenType == null) {
|
||||
return;
|
||||
}
|
||||
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user