diff options
author | Fred Quintana <fredq@google.com> | 2009-11-09 15:42:20 -0800 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-11-10 16:10:54 -0800 |
commit | 5ebbb4a6b3e16f711735ae0615b9a9ea64faad38 (patch) | |
tree | 57cd54aa0cdb48dcadc3cf236bf0947caf1a6f6e /core/java/android/accounts | |
parent | 50c548d242d637328ec6b2c4987969b02695cc7d (diff) | |
download | frameworks_base-5ebbb4a6b3e16f711735ae0615b9a9ea64faad38.zip frameworks_base-5ebbb4a6b3e16f711735ae0615b9a9ea64faad38.tar.gz frameworks_base-5ebbb4a6b3e16f711735ae0615b9a9ea64faad38.tar.bz2 |
Make the RegisteredSErvices Cache not allow the registered service for a
type to change without first uninstalling the previous service for that
type, unless the newly installed service is in the system image.
Notify the listener when a service is added or removed.
Make the AccountManagerService remove the accounts for an authenticator
when the registered authenticator changes from one uid to another.
Make the AbstractSyncableContentProvider force a sync when the database is first created.
Diffstat (limited to 'core/java/android/accounts')
3 files changed, 33 insertions, 14 deletions
diff --git a/core/java/android/accounts/AccountAuthenticatorCache.java b/core/java/android/accounts/AccountAuthenticatorCache.java index ce063a7..d6c76a2 100644 --- a/core/java/android/accounts/AccountAuthenticatorCache.java +++ b/core/java/android/accounts/AccountAuthenticatorCache.java @@ -18,10 +18,16 @@ package android.accounts; import android.content.pm.PackageManager; import android.content.pm.RegisteredServicesCache; +import android.content.pm.XmlSerializerAndParser; import android.content.res.TypedArray; import android.content.Context; import android.util.AttributeSet; import android.text.TextUtils; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlSerializer; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; /** * A cache of services that export the {@link IAccountAuthenticator} interface. This cache @@ -33,10 +39,12 @@ import android.text.TextUtils; /* package private */ class AccountAuthenticatorCache extends RegisteredServicesCache<AuthenticatorDescription> { private static final String TAG = "Account"; + private static final MySerializer sSerializer = new MySerializer(); public AccountAuthenticatorCache(Context context) { super(context, AccountManager.ACTION_AUTHENTICATOR_INTENT, - AccountManager.AUTHENTICATOR_META_DATA_NAME, AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME); + AccountManager.AUTHENTICATOR_META_DATA_NAME, + AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME, sSerializer); } public AuthenticatorDescription parseServiceAttributes(String packageName, AttributeSet attrs) { @@ -62,4 +70,16 @@ import android.text.TextUtils; sa.recycle(); } } + + private static class MySerializer implements XmlSerializerAndParser<AuthenticatorDescription> { + public void writeAsXml(AuthenticatorDescription item, XmlSerializer out) + throws IOException { + out.attribute(null, "type", item.type); + } + + public AuthenticatorDescription createFromXml(XmlPullParser parser) + throws IOException, XmlPullParserException { + return AuthenticatorDescription.newKey(parser.getAttributeValue(null, "type")); + } + } } diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java index 4f59c4e..800ad749 100644 --- a/core/java/android/accounts/AccountManagerService.java +++ b/core/java/android/accounts/AccountManagerService.java @@ -72,7 +72,7 @@ import com.android.internal.R; */ public class AccountManagerService extends IAccountManager.Stub - implements RegisteredServicesCacheListener { + implements RegisteredServicesCacheListener<AuthenticatorDescription> { private static final String GOOGLE_ACCOUNT_TYPE = "com.google"; private static final String NO_BROADCAST_FLAG = "nobroadcast"; @@ -220,34 +220,29 @@ public class AccountManagerService mMessageHandler = new MessageHandler(mMessageThread.getLooper()); mAuthenticatorCache = new AccountAuthenticatorCache(mContext); - mAuthenticatorCache.setListener(this); + mAuthenticatorCache.setListener(this, null /* Handler */); mBindHelper = new AuthenticatorBindHelper(mContext, mAuthenticatorCache, mMessageHandler, MESSAGE_CONNECTED, MESSAGE_DISCONNECTED); mSimWatcher = new SimWatcher(mContext); sThis.set(this); - - onRegisteredServicesCacheChanged(); } - public void onRegisteredServicesCacheChanged() { + public void onServiceChanged(AuthenticatorDescription desc, boolean removed) { boolean accountDeleted = false; SQLiteDatabase db = mOpenHelper.getWritableDatabase(); Cursor cursor = db.query(TABLE_ACCOUNTS, new String[]{ACCOUNTS_ID, ACCOUNTS_TYPE, ACCOUNTS_NAME}, - null, null, null, null, null); + ACCOUNTS_TYPE + "=?", new String[]{desc.type}, null, null, null); try { while (cursor.moveToNext()) { final long accountId = cursor.getLong(0); final String accountType = cursor.getString(1); final String accountName = cursor.getString(2); - if (mAuthenticatorCache.getServiceInfo(AuthenticatorDescription.newKey(accountType)) - == null) { - Log.d(TAG, "deleting account " + accountName + " because type " - + accountType + " no longer has a registered authenticator"); - db.delete(TABLE_ACCOUNTS, ACCOUNTS_ID + "=" + accountId, null); - accountDeleted= true; - } + Log.d(TAG, "deleting account " + accountName + " because type " + + accountType + " no longer has a registered authenticator"); + db.delete(TABLE_ACCOUNTS, ACCOUNTS_ID + "=" + accountId, null); + accountDeleted = true; } } finally { cursor.close(); diff --git a/core/java/android/accounts/AuthenticatorDescription.java b/core/java/android/accounts/AuthenticatorDescription.java index e642700..91c94e6 100644 --- a/core/java/android/accounts/AuthenticatorDescription.java +++ b/core/java/android/accounts/AuthenticatorDescription.java @@ -87,6 +87,10 @@ public class AuthenticatorDescription implements Parcelable { return type.equals(other.type); } + public String toString() { + return "AuthenticatorDescription {type=" + type + "}"; + } + /** @inhericDoc */ public void writeToParcel(Parcel dest, int flags) { dest.writeString(type); |