Loading core/java/android/accounts/AccountAuthenticatorCache.java +21 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) { Loading @@ -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")); } } } core/java/android/accounts/AccountManagerService.java +8 −13 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ import com.android.internal.telephony.TelephonyIntents; */ 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"; Loading Loading @@ -221,33 +221,28 @@ public class AccountManagerService mMessageHandler = new MessageHandler(mMessageThread.getLooper()); mAuthenticatorCache = new AccountAuthenticatorCache(mContext); mAuthenticatorCache.setListener(this); mAuthenticatorCache.setListener(this, null /* Handler */); 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; } } } finally { cursor.close(); if (accountDeleted) { Loading core/java/android/accounts/AuthenticatorDescription.java +4 −0 Original line number Diff line number Diff line Loading @@ -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); Loading core/java/android/content/AbstractSyncableContentProvider.java +2 −0 Original line number Diff line number Diff line Loading @@ -135,6 +135,8 @@ public abstract class AbstractSyncableContentProvider extends SyncableContentPro public void onCreate(SQLiteDatabase db) { bootstrapDatabase(db); mSyncState.createDatabase(db); ContentResolver.requestSync(null /* all accounts */, mContentUri.getAuthority(), new Bundle()); } @Override Loading core/java/android/content/SyncAdaptersCache.java +22 −2 Original line number Diff line number Diff line Loading @@ -17,9 +17,14 @@ package android.content; import android.content.pm.RegisteredServicesCache; import android.content.pm.XmlSerializerAndParser; import android.content.res.TypedArray; import android.content.Context; import android.util.AttributeSet; 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 android.content.ISyncAdapter} interface. Loading @@ -31,9 +36,10 @@ import android.util.AttributeSet; private static final String SERVICE_INTERFACE = "android.content.SyncAdapter"; private static final String SERVICE_META_DATA = "android.content.SyncAdapter"; private static final String ATTRIBUTES_NAME = "sync-adapter"; private static final MySerializer sSerializer = new MySerializer(); SyncAdaptersCache(Context context) { super(context, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME); super(context, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME, sSerializer); } public SyncAdapterType parseServiceAttributes(String packageName, AttributeSet attrs) { Loading @@ -57,4 +63,18 @@ import android.util.AttributeSet; sa.recycle(); } } static class MySerializer implements XmlSerializerAndParser<SyncAdapterType> { public void writeAsXml(SyncAdapterType item, XmlSerializer out) throws IOException { out.attribute(null, "authority", item.authority); out.attribute(null, "accountType", item.accountType); } public SyncAdapterType createFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { final String authority = parser.getAttributeValue(null, "authority"); final String accountType = parser.getAttributeValue(null, "accountType"); return SyncAdapterType.newKey(authority, accountType); } } } No newline at end of file Loading
core/java/android/accounts/AccountAuthenticatorCache.java +21 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) { Loading @@ -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")); } } }
core/java/android/accounts/AccountManagerService.java +8 −13 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ import com.android.internal.telephony.TelephonyIntents; */ 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"; Loading Loading @@ -221,33 +221,28 @@ public class AccountManagerService mMessageHandler = new MessageHandler(mMessageThread.getLooper()); mAuthenticatorCache = new AccountAuthenticatorCache(mContext); mAuthenticatorCache.setListener(this); mAuthenticatorCache.setListener(this, null /* Handler */); 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; } } } finally { cursor.close(); if (accountDeleted) { Loading
core/java/android/accounts/AuthenticatorDescription.java +4 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
core/java/android/content/AbstractSyncableContentProvider.java +2 −0 Original line number Diff line number Diff line Loading @@ -135,6 +135,8 @@ public abstract class AbstractSyncableContentProvider extends SyncableContentPro public void onCreate(SQLiteDatabase db) { bootstrapDatabase(db); mSyncState.createDatabase(db); ContentResolver.requestSync(null /* all accounts */, mContentUri.getAuthority(), new Bundle()); } @Override Loading
core/java/android/content/SyncAdaptersCache.java +22 −2 Original line number Diff line number Diff line Loading @@ -17,9 +17,14 @@ package android.content; import android.content.pm.RegisteredServicesCache; import android.content.pm.XmlSerializerAndParser; import android.content.res.TypedArray; import android.content.Context; import android.util.AttributeSet; 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 android.content.ISyncAdapter} interface. Loading @@ -31,9 +36,10 @@ import android.util.AttributeSet; private static final String SERVICE_INTERFACE = "android.content.SyncAdapter"; private static final String SERVICE_META_DATA = "android.content.SyncAdapter"; private static final String ATTRIBUTES_NAME = "sync-adapter"; private static final MySerializer sSerializer = new MySerializer(); SyncAdaptersCache(Context context) { super(context, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME); super(context, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME, sSerializer); } public SyncAdapterType parseServiceAttributes(String packageName, AttributeSet attrs) { Loading @@ -57,4 +63,18 @@ import android.util.AttributeSet; sa.recycle(); } } static class MySerializer implements XmlSerializerAndParser<SyncAdapterType> { public void writeAsXml(SyncAdapterType item, XmlSerializer out) throws IOException { out.attribute(null, "authority", item.authority); out.attribute(null, "accountType", item.accountType); } public SyncAdapterType createFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { final String authority = parser.getAttributeValue(null, "authority"); final String accountType = parser.getAttributeValue(null, "accountType"); return SyncAdapterType.newKey(authority, accountType); } } } No newline at end of file