- changed removeAccount() to be handled by the AccountAuthenticator and to return a boolean

- changed the IAccountManager API to use oneway IPCs
- changed the AccountManager to not have to start a thread for any of the calls (versus every call)
This commit is contained in:
Fred Quintana
2009-08-13 14:55:02 -07:00
parent 7eacaa6454
commit 3710f39096
26 changed files with 872 additions and 1286 deletions

View File

@@ -188,6 +188,25 @@ public abstract class AbstractAccountAuthenticator {
response.onResult(result);
}
}
public void getAccountRemovalAllowed(IAccountAuthenticatorResponse response,
Account account) throws RemoteException {
checkBinderPermission();
try {
final Bundle result = AbstractAccountAuthenticator.this.getAccountRemovalAllowed(
new AccountAuthenticatorResponse(response), account);
if (result != null) {
response.onResult(result);
}
} catch (UnsupportedOperationException e) {
response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
"getAccountRemovalAllowed not supported");
return;
} catch (NetworkErrorException e) {
response.onError(Constants.ERROR_CODE_NETWORK_ERROR, e.getMessage());
return;
}
}
}
private void checkBinderPermission() {
@@ -238,4 +257,10 @@ public abstract class AbstractAccountAuthenticator {
Account account, String authTokenType, Bundle loginOptions);
public abstract Bundle hasFeatures(AccountAuthenticatorResponse response,
Account account, String[] features) throws NetworkErrorException;
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response,
Account account) throws NetworkErrorException {
final Bundle result = new Bundle();
result.putBoolean(Constants.BOOLEAN_RESULT_KEY, true);
return result;
}
}

View File

@@ -26,20 +26,20 @@ import android.text.TextUtils;
* suitable for use as the key of a {@link java.util.Map}
*/
public class Account implements Parcelable {
public final String mName;
public final String mType;
public final String name;
public final String type;
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Account)) return false;
final Account other = (Account)o;
return mName.equals(other.mName) && mType.equals(other.mType);
return name.equals(other.name) && type.equals(other.type);
}
public int hashCode() {
int result = 17;
result = 31 * result + mName.hashCode();
result = 31 * result + mType.hashCode();
result = 31 * result + name.hashCode();
result = 31 * result + type.hashCode();
return result;
}
@@ -50,13 +50,13 @@ public class Account implements Parcelable {
if (TextUtils.isEmpty(type)) {
throw new IllegalArgumentException("the type must not be empty: " + type);
}
mName = name;
mType = type;
this.name = name;
this.type = type;
}
public Account(Parcel in) {
mName = in.readString();
mType = in.readString();
this.name = in.readString();
this.type = in.readString();
}
public int describeContents() {
@@ -64,8 +64,8 @@ public class Account implements Parcelable {
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mName);
dest.writeString(mType);
dest.writeString(name);
dest.writeString(type);
}
public static final Creator<Account> CREATOR = new Creator<Account>() {
@@ -79,6 +79,6 @@ public class Account implements Parcelable {
};
public String toString() {
return "Account {name=" + mName + ", type=" + mType + "}";
return "Account {name=" + name + ", type=" + type + "}";
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -15,6 +15,6 @@
*/
package android.accounts;
public interface Future1Callback<V> {
void run(Future1<V> future);
}
public interface AccountManagerCallback<V> {
void run(AccountManagerFuture<V> future);
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.accounts;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.io.IOException;
/**
* An extension of {@link java.util.concurrent.Future} that provides wrappers for {@link #get()}
* that handle the various
* exceptions that {@link #get()} may return and rethrows them as exceptions specific to
* {@link android.accounts.AccountManager}.
*/
public interface AccountManagerFuture<V> extends Future<V> {
/**
* Wrapper for {@link java.util.concurrent.Future#get()}. If the get() throws
* {@link InterruptedException} then the
* {@link AccountManagerFuture} is canceled and
* {@link android.accounts.OperationCanceledException} is thrown.
* @return the {@link android.os.Bundle} that is returned by get()
* @throws android.accounts.OperationCanceledException if get() throws the unchecked
* CancellationException
* or if the Future was interrupted.
*/
V getResult() throws OperationCanceledException, IOException, AuthenticatorException;
/**
* Wrapper for {@link java.util.concurrent.Future#get()}. If the get() throws
* {@link InterruptedException} then the
* {@link AccountManagerFuture} is canceled and
* {@link android.accounts.OperationCanceledException} is thrown.
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
* @return the {@link android.os.Bundle} that is returned by
* {@link java.util.concurrent.Future#get()}
* @throws android.accounts.OperationCanceledException if get() throws the unchecked
* {@link java.util.concurrent.CancellationException} or if the {@link AccountManagerFuture}
* was interrupted.
*/
V getResult(long timeout, TimeUnit unit)
throws OperationCanceledException, IOException, AuthenticatorException;
@Deprecated
V get() throws InterruptedException, ExecutionException;
@Deprecated
V get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException;
}

View File

@@ -214,10 +214,48 @@ public class AccountManagerService extends IAccountManager.Stub {
long identityToken = clearCallingIdentity();
try {
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor cursor = db.query(TABLE_ACCOUNTS, new String[]{ACCOUNTS_PASSWORD},
ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
new String[]{account.mName, account.mType}, null, null, null);
return readPasswordFromDatabase(account);
} finally {
restoreCallingIdentity(identityToken);
}
}
private String readPasswordFromDatabase(Account account) {
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
Cursor cursor = db.query(TABLE_ACCOUNTS, new String[]{ACCOUNTS_PASSWORD},
ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
new String[]{account.name, account.type}, null, null, null);
try {
if (cursor.moveToNext()) {
return cursor.getString(0);
}
return null;
} finally {
cursor.close();
}
}
public String getUserData(Account account, String key) {
checkAuthenticateAccountsPermission(account);
long identityToken = clearCallingIdentity();
try {
return readUserDataFromDatabase(account, key);
} finally {
restoreCallingIdentity(identityToken);
}
}
private String readUserDataFromDatabase(Account account, String key) {
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
db.beginTransaction();
try {
long accountId = getAccountId(db, account);
if (accountId < 0) {
return null;
}
Cursor cursor = db.query(TABLE_EXTRAS, new String[]{EXTRAS_VALUE},
EXTRAS_ACCOUNTS_ID + "=" + accountId + " AND " + EXTRAS_KEY + "=?",
new String[]{key}, null, null, null);
try {
if (cursor.moveToNext()) {
return cursor.getString(0);
@@ -227,37 +265,7 @@ public class AccountManagerService extends IAccountManager.Stub {
cursor.close();
}
} finally {
restoreCallingIdentity(identityToken);
}
}
public String getUserData(Account account, String key) {
checkAuthenticateAccountsPermission(account);
long identityToken = clearCallingIdentity();
try {
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
db.beginTransaction();
try {
long accountId = getAccountId(db, account);
if (accountId < 0) {
return null;
}
Cursor cursor = db.query(TABLE_EXTRAS, new String[]{EXTRAS_VALUE},
EXTRAS_ACCOUNTS_ID + "=" + accountId + " AND " + EXTRAS_KEY + "=?",
new String[]{key}, null, null, null);
try {
if (cursor.moveToNext()) {
return cursor.getString(0);
}
return null;
} finally {
cursor.close();
}
} finally {
db.endTransaction();
}
} finally {
restoreCallingIdentity(identityToken);
db.endTransaction();
}
}
@@ -280,39 +288,23 @@ public class AccountManagerService extends IAccountManager.Stub {
}
}
public Account[] getAccounts() {
checkReadAccountsPermission();
long identityToken = clearCallingIdentity();
try {
return getAccountsByType(null);
} finally {
restoreCallingIdentity(identityToken);
}
}
public Account[] getAccountsByType(String accountType) {
checkReadAccountsPermission();
long identityToken = clearCallingIdentity();
try {
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
final String selection = accountType == null ? null : (ACCOUNTS_TYPE + "=?");
final String[] selectionArgs = accountType == null ? null : new String[]{accountType};
Cursor cursor = db.query(TABLE_ACCOUNTS, ACCOUNT_NAME_TYPE_PROJECTION,
selection, selectionArgs, null, null, null);
try {
int i = 0;
Account[] accounts = new Account[cursor.getCount()];
while (cursor.moveToNext()) {
accounts[i] = new Account(cursor.getString(1), cursor.getString(2));
i++;
}
return accounts;
} finally {
cursor.close();
final String selection = accountType == null ? null : (ACCOUNTS_TYPE + "=?");
final String[] selectionArgs = accountType == null ? null : new String[]{accountType};
Cursor cursor = db.query(TABLE_ACCOUNTS, ACCOUNT_NAME_TYPE_PROJECTION,
selection, selectionArgs, null, null, null);
try {
int i = 0;
Account[] accounts = new Account[cursor.getCount()];
while (cursor.moveToNext()) {
accounts[i] = new Account(cursor.getString(1), cursor.getString(2));
i++;
}
return accounts;
} finally {
restoreCallingIdentity(identityToken);
cursor.close();
}
}
@@ -322,43 +314,47 @@ public class AccountManagerService extends IAccountManager.Stub {
// fails if the account already exists
long identityToken = clearCallingIdentity();
try {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
long numMatches = DatabaseUtils.longForQuery(db,
"select count(*) from " + TABLE_ACCOUNTS
+ " WHERE " + ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
new String[]{account.mName, account.mType});
if (numMatches > 0) {
return false;
}
ContentValues values = new ContentValues();
values.put(ACCOUNTS_NAME, account.mName);
values.put(ACCOUNTS_TYPE, account.mType);
values.put(ACCOUNTS_PASSWORD, password);
long accountId = db.insert(TABLE_ACCOUNTS, ACCOUNTS_NAME, values);
if (accountId < 0) {
return false;
}
if (extras != null) {
for (String key : extras.keySet()) {
final String value = extras.getString(key);
if (insertExtra(db, accountId, key, value) < 0) {
return false;
}
}
}
db.setTransactionSuccessful();
sendAccountsChangedBroadcast();
return true;
} finally {
db.endTransaction();
}
return insertAccountIntoDatabase(account, password, extras);
} finally {
restoreCallingIdentity(identityToken);
}
}
private boolean insertAccountIntoDatabase(Account account, String password, Bundle extras) {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
long numMatches = DatabaseUtils.longForQuery(db,
"select count(*) from " + TABLE_ACCOUNTS
+ " WHERE " + ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
new String[]{account.name, account.type});
if (numMatches > 0) {
return false;
}
ContentValues values = new ContentValues();
values.put(ACCOUNTS_NAME, account.name);
values.put(ACCOUNTS_TYPE, account.type);
values.put(ACCOUNTS_PASSWORD, password);
long accountId = db.insert(TABLE_ACCOUNTS, ACCOUNTS_NAME, values);
if (accountId < 0) {
return false;
}
if (extras != null) {
for (String key : extras.keySet()) {
final String value = extras.getString(key);
if (insertExtra(db, accountId, key, value) < 0) {
return false;
}
}
}
db.setTransactionSuccessful();
sendAccountsChangedBroadcast();
return true;
} finally {
db.endTransaction();
}
}
private long insertExtra(SQLiteDatabase db, long accountId, String key, String value) {
ContentValues values = new ContentValues();
values.put(EXTRAS_KEY, key);
@@ -367,19 +363,61 @@ public class AccountManagerService extends IAccountManager.Stub {
return db.insert(TABLE_EXTRAS, EXTRAS_KEY, values);
}
public void removeAccount(Account account) {
public void removeAccount(IAccountManagerResponse response, Account account) {
checkManageAccountsPermission();
long identityToken = clearCallingIdentity();
try {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.delete(TABLE_ACCOUNTS, ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
new String[]{account.mName, account.mType});
sendAccountsChangedBroadcast();
new RemoveAccountSession(response, account).bind();
} finally {
restoreCallingIdentity(identityToken);
}
}
private class RemoveAccountSession extends Session {
final Account mAccount;
public RemoveAccountSession(IAccountManagerResponse response, Account account) {
super(response, account.type, false /* expectActivityLaunch */);
mAccount = account;
}
protected String toDebugString(long now) {
return super.toDebugString(now) + ", removeAccount"
+ ", account " + mAccount;
}
public void run() throws RemoteException {
mAuthenticator.getAccountRemovalAllowed(this, mAccount);
}
public void onResult(Bundle result) {
if (result != null && result.containsKey(Constants.BOOLEAN_RESULT_KEY)
&& !result.containsKey(Constants.INTENT_KEY)) {
final boolean removalAllowed = result.getBoolean(Constants.BOOLEAN_RESULT_KEY);
if (removalAllowed) {
removeAccount(mAccount);
}
IAccountManagerResponse response = getResponseAndClose();
if (response != null) {
Bundle result2 = new Bundle();
result2.putBoolean(Constants.BOOLEAN_RESULT_KEY, removalAllowed);
try {
response.onResult(result2);
} catch (RemoteException e) {
// ignore
}
}
}
super.onResult(result);
}
}
private void removeAccount(Account account) {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.delete(TABLE_ACCOUNTS, ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
new String[]{account.name, account.type});
sendAccountsChangedBroadcast();
}
public void invalidateAuthToken(String accountType, String authToken) {
checkManageAccountsPermission();
long identityToken = clearCallingIdentity();
@@ -398,6 +436,9 @@ public class AccountManagerService extends IAccountManager.Stub {
}
private void invalidateAuthToken(SQLiteDatabase db, String accountType, String authToken) {
if (authToken == null || accountType == null) {
return;
}
Cursor cursor = db.rawQuery(
"SELECT " + TABLE_AUTHTOKENS + "." + AUTHTOKENS_ID
+ ", " + TABLE_ACCOUNTS + "." + ACCOUNTS_NAME
@@ -488,7 +529,7 @@ public class AccountManagerService extends IAccountManager.Stub {
values.put(ACCOUNTS_PASSWORD, password);
mOpenHelper.getWritableDatabase().update(TABLE_ACCOUNTS, values,
ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
new String[]{account.mName, account.mType});
new String[]{account.name, account.type});
sendAccountsChangedBroadcast();
} finally {
restoreCallingIdentity(identityToken);
@@ -509,40 +550,58 @@ public class AccountManagerService extends IAccountManager.Stub {
}
}
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();
try {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
long accountId = getAccountId(db, account);
if (accountId < 0) {
return;
}
long extrasId = getExtrasId(db, accountId, key);
if (extrasId < 0 ) {
extrasId = insertExtra(db, accountId, key, value);
if (extrasId < 0) {
return;
}
} else {
ContentValues values = new ContentValues();
values.put(EXTRAS_VALUE, value);
if (1 != db.update(TABLE_EXTRAS, values, EXTRAS_ID + "=" + extrasId, null)) {
return;
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
writeUserdataIntoDatabase(account, key, value);
} finally {
restoreCallingIdentity(identityToken);
}
}
private void writeUserdataIntoDatabase(Account account, String key, String value) {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
long accountId = getAccountId(db, account);
if (accountId < 0) {
return;
}
long extrasId = getExtrasId(db, accountId, key);
if (extrasId < 0 ) {
extrasId = insertExtra(db, accountId, key, value);
if (extrasId < 0) {
return;
}
} else {
ContentValues values = new ContentValues();
values.put(EXTRAS_VALUE, value);
if (1 != db.update(TABLE_EXTRAS, values, EXTRAS_ID + "=" + extrasId, null)) {
return;
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
private void onResult(IAccountManagerResponse response, Bundle result) {
try {
response.onResult(result);
@@ -571,14 +630,14 @@ public class AccountManagerService extends IAccountManager.Stub {
if (authToken != null) {
Bundle result = new Bundle();
result.putString(Constants.AUTHTOKEN_KEY, authToken);
result.putString(Constants.ACCOUNT_NAME_KEY, account.mName);
result.putString(Constants.ACCOUNT_TYPE_KEY, account.mType);
result.putString(Constants.ACCOUNT_NAME_KEY, account.name);
result.putString(Constants.ACCOUNT_TYPE_KEY, account.type);
onResult(response, result);
return;
}
}
new Session(response, account.mType, expectActivityLaunch) {
new Session(response, account.type, expectActivityLaunch) {
protected String toDebugString(long now) {
if (loginOptions != null) loginOptions.keySet();
return super.toDebugString(now) + ", getAuthToken"
@@ -651,7 +710,7 @@ public class AccountManagerService extends IAccountManager.Stub {
mContext.getText(R.string.permission_request_notification_subtitle);
n.setLatestEventInfo(mContext,
mContext.getText(R.string.permission_request_notification_title),
String.format(subtitleFormatString.toString(), account.mName),
String.format(subtitleFormatString.toString(), account.name),
PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE))
.notify(getCredentialPermissionNotificationId(account, authTokenType, uid), n);
@@ -661,9 +720,9 @@ public class AccountManagerService extends IAccountManager.Stub {
AccountAuthenticatorResponse response, String authTokenType, String authTokenLabel) {
RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> serviceInfo =
mAuthenticatorCache.getServiceInfo(
AuthenticatorDescription.newKey(account.mType));
AuthenticatorDescription.newKey(account.type));
if (serviceInfo == null) {
throw new IllegalArgumentException("unknown account type: " + account.mType);
throw new IllegalArgumentException("unknown account type: " + account.type);
}
final Context authContext;
@@ -671,7 +730,7 @@ public class AccountManagerService extends IAccountManager.Stub {
authContext = mContext.createPackageContext(
serviceInfo.type.packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
throw new IllegalArgumentException("unknown account type: " + account.mType);
throw new IllegalArgumentException("unknown account type: " + account.type);
}
Intent intent = new Intent(mContext, GrantCredentialsPermissionActivity.class);
@@ -750,7 +809,7 @@ public class AccountManagerService extends IAccountManager.Stub {
checkManageAccountsPermission();
long identityToken = clearCallingIdentity();
try {
new Session(response, account.mType, expectActivityLaunch) {
new Session(response, account.type, expectActivityLaunch) {
public void run() throws RemoteException {
mAuthenticator.confirmCredentials(this, account);
}
@@ -769,7 +828,7 @@ public class AccountManagerService extends IAccountManager.Stub {
checkManageAccountsPermission();
long identityToken = clearCallingIdentity();
try {
new Session(response, account.mType, false /* expectActivityLaunch */) {
new Session(response, account.type, false /* expectActivityLaunch */) {
public void run() throws RemoteException {
mAuthenticator.confirmPassword(this, account, password);
}
@@ -789,7 +848,7 @@ public class AccountManagerService extends IAccountManager.Stub {
checkManageAccountsPermission();
long identityToken = clearCallingIdentity();
try {
new Session(response, account.mType, expectActivityLaunch) {
new Session(response, account.type, expectActivityLaunch) {
public void run() throws RemoteException {
mAuthenticator.updateCredentials(this, account, authTokenType, loginOptions);
}
@@ -898,10 +957,21 @@ public class AccountManagerService extends IAccountManager.Stub {
+ ", " + (mFeatures != null ? TextUtils.join(",", mFeatures) : null);
}
}
public void getAccountsByTypeAndFeatures(IAccountManagerResponse response,
public Account[] getAccounts(String type) {
checkReadAccountsPermission();
long identityToken = clearCallingIdentity();
try {
return getAccountsByType(type);
} finally {
restoreCallingIdentity(identityToken);
}
}
public void getAccountsByFeatures(IAccountManagerResponse response,
String type, String[] features) {
checkReadAccountsPermission();
if (type == null) {
if (features != null && type == null) {
if (response != null) {
try {
response.onError(Constants.ERROR_CODE_BAD_ARGUMENTS, "type is null");
@@ -913,6 +983,10 @@ public class AccountManagerService extends IAccountManager.Stub {
}
long identityToken = clearCallingIdentity();
try {
if (features == null || features.length == 0) {
getAccountsByType(type);
return;
}
new GetAccountsByTypeAndFeatureSession(response, type, features).bind();
} finally {
restoreCallingIdentity(identityToken);
@@ -925,7 +999,7 @@ public class AccountManagerService extends IAccountManager.Stub {
private long getAccountId(SQLiteDatabase db, Account account) {
Cursor cursor = db.query(TABLE_ACCOUNTS, new String[]{ACCOUNTS_ID},
"name=? AND type=?", new String[]{account.mName, account.mType}, null, null, null);
"name=? AND type=?", new String[]{account.name, account.type}, null, null, null);
try {
if (cursor.moveToNext()) {
return cursor.getLong(0);
@@ -1401,7 +1475,7 @@ public class AccountManagerService extends IAccountManager.Stub {
}
private boolean permissionIsGranted(Account account, String authTokenType, int callerUid) {
final boolean fromAuthenticator = hasAuthenticatorUid(account.mType, callerUid);
final boolean fromAuthenticator = hasAuthenticatorUid(account.type, callerUid);
final boolean hasExplicitGrants = hasExplicitlyGrantedPermission(account, authTokenType);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "checkGrantsOrCallingUidAgainstAuthenticator: caller uid "
@@ -1416,7 +1490,9 @@ public class AccountManagerService extends IAccountManager.Stub {
for (RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> serviceInfo :
mAuthenticatorCache.getAllServices()) {
if (serviceInfo.type.type.equals(accountType)) {
return serviceInfo.uid == callingUid;
return (serviceInfo.uid == callingUid) ||
(mContext.getPackageManager().checkSignatures(serviceInfo.uid, callingUid)
== PackageManager.SIGNATURE_MATCH);
}
}
return false;
@@ -1428,7 +1504,7 @@ public class AccountManagerService extends IAccountManager.Stub {
}
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
String[] args = {String.valueOf(Binder.getCallingUid()), authTokenType,
account.mName, account.mType};
account.name, account.type};
final boolean permissionGranted =
DatabaseUtils.longForQuery(db, COUNT_OF_MATCHING_GRANTS, args) != 0;
if (!permissionGranted && isDebuggableMonkeyBuild) {
@@ -1444,7 +1520,7 @@ public class AccountManagerService extends IAccountManager.Stub {
private void checkCallingUidAgainstAuthenticator(Account account) {
final int uid = Binder.getCallingUid();
if (!hasAuthenticatorUid(account.mType, uid)) {
if (!hasAuthenticatorUid(account.type, uid)) {
String msg = "caller uid " + uid + " is different than the authenticator's uid";
Log.w(TAG, msg);
throw new SecurityException(msg);

View File

@@ -45,7 +45,7 @@ public class ChooseAccountActivity extends ListActivity {
String[] mAccountNames = new String[mAccounts.length];
for (int i = 0; i < mAccounts.length; i++) {
mAccountNames[i] = ((Account) mAccounts[i]).mName;
mAccountNames[i] = ((Account) mAccounts[i]).name;
}
// Use an existing ListAdapter that will map an array
@@ -59,8 +59,8 @@ public class ChooseAccountActivity extends ListActivity {
Account account = (Account) mAccounts[position];
Log.d(TAG, "selected account " + account);
Bundle bundle = new Bundle();
bundle.putString(Constants.ACCOUNT_NAME_KEY, account.mName);
bundle.putString(Constants.ACCOUNT_TYPE_KEY, account.mType);
bundle.putString(Constants.ACCOUNT_NAME_KEY, account.name);
bundle.putString(Constants.ACCOUNT_TYPE_KEY, account.type);
mResult = bundle;
finish();
}

View File

@@ -31,6 +31,7 @@ public class Constants {
public static final String AUTHENTICATOR_TYPES_KEY = "authenticator_types";
public static final String USERDATA_KEY = "userdata";
public static final String AUTHTOKEN_KEY = "authtoken";
public static final String PASSWORD_KEY = "password";
public static final String ACCOUNT_NAME_KEY = "authAccount";
public static final String ACCOUNT_TYPE_KEY = "accountType";
public static final String ERROR_CODE_KEY = "errorCode";

View File

@@ -1,46 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.accounts;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/**
* An extension of {@link Future} that provides wrappers for {@link #get()} that handle the various
* exceptions that {@link #get()} may return and rethrows them as exceptions specific to
* {@link AccountManager}.
*/
public interface Future1<V> extends Future<V> {
/**
* Wrapper for {@link Future#get()}. If the get() throws {@link InterruptedException} then the
* {@link Future1} is canceled and {@link OperationCanceledException} is thrown.
* @return the {@link android.os.Bundle} that is returned by get()
* @throws OperationCanceledException if get() throws the unchecked CancellationException
* or if the Future was interrupted.
*/
V getResult() throws OperationCanceledException;
/**
* Wrapper for {@link Future#get()}. If the get() throws {@link InterruptedException} then the
* {@link Future1} is canceled and {@link OperationCanceledException} is thrown.
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
* @return the {@link android.os.Bundle} that is returned by {@link Future#get()}
* @throws OperationCanceledException if get() throws the unchecked
* {@link java.util.concurrent.CancellationException} or if the {@link Future1} was interrupted.
*/
V getResult(long timeout, TimeUnit unit) throws OperationCanceledException;
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.accounts;
import android.os.Bundle;
import java.io.IOException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/**
* An extension of {@link Future} that provides wrappers for {@link #get()} that handle the various
* exceptions that {@link #get()} may return and rethrows them as exceptions specific to
* {@link AccountManager}.
*/
public interface Future2 extends Future<Bundle> {
/**
* Wrapper for {@link Future#get()}. If the get() throws {@link InterruptedException} then the
* {@link Future2} is canceled and {@link OperationCanceledException} is thrown.
* @return the {@link android.os.Bundle} that is returned by {@link Future#get()}
* @throws OperationCanceledException if get() throws the unchecked
* {@link java.util.concurrent.CancellationException} or if the {@link Future2} was interrupted.
* @throws IOException if the request was unable to complete due to a network error
* @throws AuthenticatorException if there was an error communicating with the
* {@link AbstractAccountAuthenticator}.
*/
Bundle getResult()
throws OperationCanceledException, IOException, AuthenticatorException;
/**
* Wrapper for {@link Future#get()}. If the get() throws {@link InterruptedException} then the
* {@link Future2} is canceled and {@link OperationCanceledException} is thrown.
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
* @return the {@link android.os.Bundle} that is returned by {@link Future#get()}
* @throws OperationCanceledException if get() throws the unchecked
* {@link java.util.concurrent.CancellationException} or if the {@link Future2} was interrupted.
* @throws IOException if the request was unable to complete due to a network error
* @throws AuthenticatorException if there was an error communicating with the
* {@link AbstractAccountAuthenticator}.
*/
Bundle getResult(long timeout, TimeUnit unit)
throws OperationCanceledException, IOException, AuthenticatorException;
}

View File

@@ -1,20 +0,0 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.accounts;
public interface Future2Callback {
void run(Future2 future);
}

View File

@@ -63,12 +63,12 @@ public class GrantCredentialsPermissionActivity extends Activity implements View
CharSequence grantCredentialsPermissionFormat = getResources().getText(
R.string.grant_credentials_permission_message_desc);
messageView.setText(String.format(grantCredentialsPermissionFormat.toString(),
mAccount.mName, accountTypeLabel));
mAccount.name, accountTypeLabel));
} else {
CharSequence grantCredentialsPermissionFormat = getResources().getText(
R.string.grant_credentials_permission_message_with_authtokenlabel_desc);
messageView.setText(String.format(grantCredentialsPermissionFormat.toString(),
authTokenLabel, mAccount.mName, accountTypeLabel));
authTokenLabel, mAccount.name, accountTypeLabel));
}
String[] packageLabels = new String[packages.length];

View File

@@ -70,4 +70,9 @@ oneway interface IAccountAuthenticator {
*/
void hasFeatures(in IAccountAuthenticatorResponse response, in Account account,
in String[] features);
/**
* Gets whether or not the account is allowed to be removed.
*/
void getAccountRemovalAllowed(in IAccountAuthenticatorResponse response, in Account account);
}

View File

@@ -21,6 +21,7 @@ import android.accounts.Account;
import android.accounts.AuthenticatorDescription;
import android.os.Bundle;
/**
* Central application service that provides account management.
* @hide
@@ -29,10 +30,10 @@ interface IAccountManager {
String getPassword(in Account account);
String getUserData(in Account account, String key);
AuthenticatorDescription[] getAuthenticatorTypes();
Account[] getAccounts();
Account[] getAccountsByType(String accountType);
Account[] getAccounts(String accountType);
void getAccountsByFeatures(in IAccountManagerResponse response, String accountType, in String[] features);
boolean addAccount(in Account account, String password, in Bundle extras);
void removeAccount(in Account account);
void removeAccount(in IAccountManagerResponse response, in Account account);
void invalidateAuthToken(String accountType, String authToken);
String peekAuthToken(in Account account, String authTokenType);
void setAuthToken(in Account account, String authTokenType, String authToken);
@@ -52,8 +53,6 @@ interface IAccountManager {
boolean expectActivityLaunch);
void confirmCredentials(in IAccountManagerResponse response, in Account account,
boolean expectActivityLaunch);
void getAccountsByTypeAndFeatures(in IAccountManagerResponse response, String accountType,
in String[] features);
/*
* @deprecated

View File

@@ -170,7 +170,7 @@ public abstract class AbstractSyncableContentProvider extends SyncableContentPro
// AbstractGDataSyncAdapter, which will put acore into a crash loop
ArrayList<Account> gaiaAccounts = new ArrayList<Account>();
for (Account acct: accounts) {
if (acct.mType.equals("com.google.GAIA")) {
if (acct.type.equals("com.google.GAIA")) {
gaiaAccounts.add(acct);
}
}
@@ -693,7 +693,7 @@ public abstract class AbstractSyncableContentProvider extends SyncableContentPro
if (!accounts.containsKey(account)) {
int numDeleted;
numDeleted = db.delete(table, "_sync_account=? AND _sync_account_type=?",
new String[]{account.mName, account.mType});
new String[]{account.name, account.type});
if (Config.LOGV) {
Log.v(TAG, "deleted " + numDeleted
+ " records from table " + table
@@ -726,7 +726,7 @@ public abstract class AbstractSyncableContentProvider extends SyncableContentPro
// remove the data in the synced tables
for (String table : tables) {
db.delete(table, SYNC_ACCOUNT_WHERE_CLAUSE,
new String[]{account.mName, account.mType});
new String[]{account.name, account.type});
}
db.setTransactionSuccessful();
} finally {

View File

@@ -174,7 +174,7 @@ public abstract class AbstractTableMerger
Cursor diffsCursor = null;
try {
// load the local database entries, so we can merge them with the server
final String[] accountSelectionArgs = new String[]{account.mName, account.mType};
final String[] accountSelectionArgs = new String[]{account.name, account.type};
localCursor = mDb.query(mTable, syncDirtyProjection,
SELECT_MARKED, accountSelectionArgs, null, null,
mTable + "." + _SYNC_ID);
@@ -487,7 +487,7 @@ public abstract class AbstractTableMerger
try {
if (deleteBySyncId) {
selectionArgs = new String[]{diffsCursor.getString(serverSyncIdColumn),
account.mName, account.mType};
account.name, account.type};
c = mDb.query(mTable, new String[]{BaseColumns._ID}, SELECT_BY_SYNC_ID_AND_ACCOUNT,
selectionArgs, null, null, null);
} else {
@@ -534,7 +534,7 @@ public abstract class AbstractTableMerger
SyncableContentProvider clientDiffs = mergeResult.tempContentProvider;
if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "generating client updates");
final String[] accountSelectionArgs = new String[]{account.mName, account.mType};
final String[] accountSelectionArgs = new String[]{account.name, account.type};
// Generate the client updates and insertions
// Create a cursor for dirty records

View File

@@ -596,7 +596,7 @@ class SyncManager implements OnAccountsUpdatedListener {
for (String authority : syncableAuthorities) {
for (Account account : accounts) {
if (mSyncAdapters.getServiceInfo(new SyncAdapterType(authority, account.mType))
if (mSyncAdapters.getServiceInfo(new SyncAdapterType(authority, account.type))
!= null) {
scheduleSyncOperation(
new SyncOperation(account, source, authority, extras, delay));
@@ -1094,8 +1094,8 @@ class SyncManager implements OnAccountsUpdatedListener {
for (int i=0; i<N; i++) {
SyncStorageEngine.PendingOperation op = ops.get(i);
pw.print(" #"); pw.print(i); pw.print(": account=");
pw.print(op.account.mName); pw.print(":");
pw.print(op.account.mType); pw.print(" authority=");
pw.print(op.account.name); pw.print(":");
pw.print(op.account.type); pw.print(" authority=");
pw.println(op.authority);
if (op.extras != null && op.extras.size() > 0) {
sb.setLength(0);
@@ -1125,8 +1125,8 @@ class SyncManager implements OnAccountsUpdatedListener {
processedAccounts.add(curAccount);
pw.print(" Account "); pw.print(authority.account.mName);
pw.print(" "); pw.print(authority.account.mType);
pw.print(" Account "); pw.print(authority.account.name);
pw.print(" "); pw.print(authority.account.type);
pw.println(":");
for (int j=i; j<N; j++) {
status = statuses.get(j);
@@ -1248,9 +1248,9 @@ class SyncManager implements OnAccountsUpdatedListener {
= mSyncStorageEngine.getAuthority(item.authorityId);
pw.print(" #"); pw.print(i+1); pw.print(": ");
if (authority != null) {
pw.print(authority.account.mName);
pw.print(authority.account.name);
pw.print(":");
pw.print(authority.account.mType);
pw.print(authority.account.type);
pw.print(" ");
pw.print(authority.authority);
} else {
@@ -1636,7 +1636,7 @@ class SyncManager implements OnAccountsUpdatedListener {
// connect to the sync adapter
SyncAdapterType syncAdapterType = new SyncAdapterType(op.authority,
op.account.mType);
op.account.type);
RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo =
mSyncAdapters.getServiceInfo(syncAdapterType);
if (syncAdapterInfo == null) {

View File

@@ -172,7 +172,7 @@ public class SyncStateContentProviderHelper {
*/
public void copySyncState(SQLiteDatabase dbSrc, SQLiteDatabase dbDest,
Account account) {
final String[] whereArgs = new String[]{account.mName, account.mType};
final String[] whereArgs = new String[]{account.name, account.type};
Cursor c = dbSrc.query(SYNC_STATE_TABLE,
new String[]{"_sync_account", "_sync_account_type", "data"},
ACCOUNT_WHERE, whereArgs, null, null, null);
@@ -209,7 +209,7 @@ public class SyncStateContentProviderHelper {
public void discardSyncData(SQLiteDatabase db, Account account) {
if (account != null) {
db.delete(SYNC_STATE_TABLE, ACCOUNT_WHERE, new String[]{account.mName, account.mType});
db.delete(SYNC_STATE_TABLE, ACCOUNT_WHERE, new String[]{account.name, account.type});
} else {
db.delete(SYNC_STATE_TABLE, null, null);
}
@@ -220,7 +220,7 @@ public class SyncStateContentProviderHelper {
*/
public byte[] readSyncDataBytes(SQLiteDatabase db, Account account) {
Cursor c = db.query(SYNC_STATE_TABLE, null, ACCOUNT_WHERE,
new String[]{account.mName, account.mType}, null, null, null);
new String[]{account.name, account.type}, null, null, null);
try {
if (c.moveToFirst()) {
return c.getBlob(c.getColumnIndexOrThrow("data"));
@@ -238,6 +238,6 @@ public class SyncStateContentProviderHelper {
ContentValues values = new ContentValues();
values.put("data", data);
db.update(SYNC_STATE_TABLE, values, ACCOUNT_WHERE,
new String[]{account.mName, account.mType});
new String[]{account.name, account.type});
}
}

View File

@@ -1127,8 +1127,8 @@ public class SyncStorageEngine extends Handler {
AuthorityInfo authority = mAuthorities.get(i);
out.startTag(null, "authority");
out.attribute(null, "id", Integer.toString(authority.ident));
out.attribute(null, "account", authority.account.mName);
out.attribute(null, "type", authority.account.mType);
out.attribute(null, "account", authority.account.name);
out.attribute(null, "type", authority.account.type);
out.attribute(null, "authority", authority.authority);
if (!authority.enabled) {
out.attribute(null, "enabled", "false");

View File

@@ -174,7 +174,7 @@ public final class Calendar {
return Calendar.Calendars.delete(cr,
Calendar.Calendars._SYNC_ACCOUNT + "=? AND "
+ Calendar.Calendars._SYNC_ACCOUNT_TYPE + "=?",
new String[] {account.mName, account.mType});
new String[] {account.name, account.type});
}
/**

View File

@@ -119,8 +119,8 @@ public class SubscribedFeeds {
String authority, String service) {
ContentValues values = new ContentValues();
values.put(SubscribedFeeds.Feeds.FEED, feed);
values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT, account.mName);
values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE, account.mType);
values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT, account.name);
values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE, account.type);
values.put(SubscribedFeeds.Feeds.AUTHORITY, authority);
values.put(SubscribedFeeds.Feeds.SERVICE, service);
return resolver.insert(SubscribedFeeds.Feeds.CONTENT_URI, values);
@@ -134,7 +134,7 @@ public class SubscribedFeeds {
where.append(" AND " + SubscribedFeeds.Feeds.FEED + "=?");
where.append(" AND " + SubscribedFeeds.Feeds.AUTHORITY + "=?");
return resolver.delete(SubscribedFeeds.Feeds.CONTENT_URI,
where.toString(), new String[] {account.mName, account.mType, feed, authority});
where.toString(), new String[] {account.name, account.type, feed, authority});
}
public static int deleteFeeds(ContentResolver resolver,
@@ -144,7 +144,7 @@ public class SubscribedFeeds {
where.append(" AND " + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE + "=?");
where.append(" AND " + SubscribedFeeds.Feeds.AUTHORITY + "=?");
return resolver.delete(SubscribedFeeds.Feeds.CONTENT_URI,
where.toString(), new String[] {account.mName, account.mType, authority});
where.toString(), new String[] {account.name, account.type, authority});
}
/**

View File

@@ -71,7 +71,7 @@ public class SyncStateContract {
public static byte[] get(ContentProviderClient provider, Uri uri,
Account account) throws RemoteException {
Cursor c = provider.query(uri, DATA_PROJECTION, SELECT_BY_ACCOUNT,
new String[]{account.mName, account.mType}, null);
new String[]{account.name, account.type}, null);
try {
if (c.moveToNext()) {
return c.getBlob(c.getColumnIndexOrThrow(Columns.DATA));
@@ -96,8 +96,8 @@ public class SyncStateContract {
Account account, byte[] data) throws RemoteException {
ContentValues values = new ContentValues();
values.put(Columns.DATA, data);
values.put(Columns.ACCOUNT_NAME, account.mName);
values.put(Columns.ACCOUNT_TYPE, account.mType);
values.put(Columns.ACCOUNT_NAME, account.name);
values.put(Columns.ACCOUNT_TYPE, account.type);
provider.insert(uri, values);
}
@@ -116,8 +116,8 @@ public class SyncStateContract {
values.put(Columns.DATA, data);
return ContentProviderOperation
.newInsert(uri)
.withValue(Columns.ACCOUNT_NAME, account.mName)
.withValue(Columns.ACCOUNT_TYPE, account.mType)
.withValue(Columns.ACCOUNT_NAME, account.name)
.withValue(Columns.ACCOUNT_TYPE, account.type)
.withValues(values)
.build();
}