summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFred Quintana <fredq@google.com>2009-10-21 13:43:10 -0700
committerFred Quintana <fredq@google.com>2009-10-28 16:29:21 -0700
commit31957f1badbb900bbfe211317e1ea992d650a72d (patch)
tree2ffcdd542dff8e4e621b14ffb11db3cf4106c000 /core
parent04104665271248719cb3659e42938fa4bec0261e (diff)
downloadframeworks_base-31957f1badbb900bbfe211317e1ea992d650a72d.zip
frameworks_base-31957f1badbb900bbfe211317e1ea992d650a72d.tar.gz
frameworks_base-31957f1badbb900bbfe211317e1ea992d650a72d.tar.bz2
- 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
Diffstat (limited to 'core')
-rw-r--r--core/java/android/accounts/AbstractAccountAuthenticator.java96
-rw-r--r--core/java/android/accounts/AccountAuthenticatorActivity.java23
-rw-r--r--core/java/android/accounts/AccountManager.java45
-rw-r--r--core/java/android/accounts/AccountManagerService.java119
4 files changed, 176 insertions, 107 deletions
diff --git a/core/java/android/accounts/AbstractAccountAuthenticator.java b/core/java/android/accounts/AbstractAccountAuthenticator.java
index ee6d748..0efeb1d 100644
--- a/core/java/android/accounts/AbstractAccountAuthenticator.java
+++ b/core/java/android/accounts/AbstractAccountAuthenticator.java
@@ -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.
diff --git a/core/java/android/accounts/AccountAuthenticatorActivity.java b/core/java/android/accounts/AccountAuthenticatorActivity.java
index 3d7be48..5cce6da 100644
--- a/core/java/android/accounts/AccountAuthenticatorActivity.java
+++ b/core/java/android/accounts/AccountAuthenticatorActivity.java
@@ -56,14 +56,8 @@ 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();
@@ -71,16 +65,6 @@ public class AccountAuthenticatorActivity extends Activity {
}
/**
- * 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.
*/
public void finish() {
@@ -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;
}
diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java
index 153d95f..46dc895 100644
--- a/core/java/android/accounts/AccountManager.java
+++ b/core/java/android/accounts/AccountManager.java
@@ -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;
}
diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java
index 3a11cb3..9c60141 100644
--- a/core/java/android/accounts/AccountManagerService.java
+++ b/core/java/android/accounts/AccountManagerService.java
@@ -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 {