Loading src/com/android/contacts/model/AccountTypeManager.java +20 −22 Original line number Diff line number Diff line Loading @@ -405,9 +405,8 @@ class AccountTypeManagerImpl extends AccountTypeManager ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this); if (Flags.getInstance().getBoolean(Experiments.CP2_DEVICE_ACCOUNT_DETECTION_ENABLED)) { // Observe changes to RAW_CONTACTS so that we will update the list of "Device" accounts // if a new device contact is added. // if a new device contact is added or removed. mContext.getContentResolver().registerContentObserver( ContactsContract.RawContacts.CONTENT_URI, /* notifyDescendents */ true, new ContentObserver(mMainThreadHandler) { Loading @@ -426,7 +425,6 @@ class AccountTypeManagerImpl extends AccountTypeManager reloadLocalAccounts(); } }); } loadAccountTypes(); } Loading src/com/android/contacts/model/DeviceLocalAccountLocator.java +11 −7 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.contacts.model; import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import android.database.Cursor; import android.provider.ContactsContract; import com.android.contacts.Experiments; import com.android.contacts.model.account.AccountWithDataSet; Loading Loading @@ -69,23 +71,25 @@ public abstract class DeviceLocalAccountLocator { return new Cp2DeviceLocalAccountLocator(context.getContentResolver(), ObjectFactory.getDeviceLocalAccountTypeFactory(context), knownTypes); } else { return new NexusDeviceAccountLocator(accountManager); return new NexusDeviceAccountLocator(context, accountManager); } } /** * On Nexus the "device" account uses "null" values for the account name and type columns * * <p>However, the focus sync adapter automatically migrates contacts from this null * account to a Google account if one exists. Hence, the device account should be returned * only when there is no Google Account added * <p>However, the focus sync adapter migrates contacts from this null account to a Google * account if one exists. Hence, the device account should be returned only when there is no * Google Account added or when there already exists contacts in the null account. * </p> */ public static class NexusDeviceAccountLocator extends DeviceLocalAccountLocator { private final Context mContext; private final AccountManager mAccountManager; public NexusDeviceAccountLocator(AccountManager accountManager) { public NexusDeviceAccountLocator(Context context, AccountManager accountManager) { mContext = context; mAccountManager = accountManager; } Loading @@ -95,7 +99,7 @@ public abstract class DeviceLocalAccountLocator { final Account[] accounts = mAccountManager .getAccountsByType(GoogleAccountType.ACCOUNT_TYPE); if (accounts.length > 0) { if (accounts.length > 0 && !AccountWithDataSet.getNullAccount().hasData(mContext)) { return Collections.emptyList(); } else { return Collections.singletonList(AccountWithDataSet.getNullAccount()); Loading Loading
src/com/android/contacts/model/AccountTypeManager.java +20 −22 Original line number Diff line number Diff line Loading @@ -405,9 +405,8 @@ class AccountTypeManagerImpl extends AccountTypeManager ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this); if (Flags.getInstance().getBoolean(Experiments.CP2_DEVICE_ACCOUNT_DETECTION_ENABLED)) { // Observe changes to RAW_CONTACTS so that we will update the list of "Device" accounts // if a new device contact is added. // if a new device contact is added or removed. mContext.getContentResolver().registerContentObserver( ContactsContract.RawContacts.CONTENT_URI, /* notifyDescendents */ true, new ContentObserver(mMainThreadHandler) { Loading @@ -426,7 +425,6 @@ class AccountTypeManagerImpl extends AccountTypeManager reloadLocalAccounts(); } }); } loadAccountTypes(); } Loading
src/com/android/contacts/model/DeviceLocalAccountLocator.java +11 −7 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.contacts.model; import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import android.database.Cursor; import android.provider.ContactsContract; import com.android.contacts.Experiments; import com.android.contacts.model.account.AccountWithDataSet; Loading Loading @@ -69,23 +71,25 @@ public abstract class DeviceLocalAccountLocator { return new Cp2DeviceLocalAccountLocator(context.getContentResolver(), ObjectFactory.getDeviceLocalAccountTypeFactory(context), knownTypes); } else { return new NexusDeviceAccountLocator(accountManager); return new NexusDeviceAccountLocator(context, accountManager); } } /** * On Nexus the "device" account uses "null" values for the account name and type columns * * <p>However, the focus sync adapter automatically migrates contacts from this null * account to a Google account if one exists. Hence, the device account should be returned * only when there is no Google Account added * <p>However, the focus sync adapter migrates contacts from this null account to a Google * account if one exists. Hence, the device account should be returned only when there is no * Google Account added or when there already exists contacts in the null account. * </p> */ public static class NexusDeviceAccountLocator extends DeviceLocalAccountLocator { private final Context mContext; private final AccountManager mAccountManager; public NexusDeviceAccountLocator(AccountManager accountManager) { public NexusDeviceAccountLocator(Context context, AccountManager accountManager) { mContext = context; mAccountManager = accountManager; } Loading @@ -95,7 +99,7 @@ public abstract class DeviceLocalAccountLocator { final Account[] accounts = mAccountManager .getAccountsByType(GoogleAccountType.ACCOUNT_TYPE); if (accounts.length > 0) { if (accounts.length > 0 && !AccountWithDataSet.getNullAccount().hasData(mContext)) { return Collections.emptyList(); } else { return Collections.singletonList(AccountWithDataSet.getNullAccount()); Loading