Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c4e7776 authored by Jordan Hayes's avatar Jordan Hayes Committed by Android (Google) Code Review
Browse files

Merge "Support Null device account"

parents 5b524519 ef4b1889
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -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) {
@@ -426,7 +425,6 @@ class AccountTypeManagerImpl extends AccountTypeManager
                        reloadLocalAccounts();
                    }
                });
        }
        loadAccountTypes();
    }

+11 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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;
        }

@@ -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());