Don't skip querying raw_contacts for device accounts.
Querying the raw_contacts is necessary for the second SIM account to be
displayed on the LG G5 when 2 SIM cards are installed.
Test:
Manual
* Put a second SIM card in an LG G5
* Verify that there are 2 SIM accounts when adding new contact with FAB
* If necessary add contacts so that there are contacts associated with both
SIM accounts
* Verify that there are 2 SIM account in the accounts section of the nav drawer
Bug 30868406
Change-Id: Ia29d50ae1a67a65562c6294e518b9b995e924366
diff --git a/src/com/android/contacts/common/model/DeviceLocalAccountLocator.java b/src/com/android/contacts/common/model/DeviceLocalAccountLocator.java
index 0efadc4..8c45c40 100644
--- a/src/com/android/contacts/common/model/DeviceLocalAccountLocator.java
+++ b/src/com/android/contacts/common/model/DeviceLocalAccountLocator.java
@@ -78,16 +78,8 @@
// Many device accounts have default groups associated with them.
addAccountsFromQuery(ContactsContract.Groups.CONTENT_URI, localAccounts);
-
addAccountsFromQuery(ContactsContract.Settings.CONTENT_URI, localAccounts);
-
- if (localAccounts.isEmpty()) {
- // It's probably safe to assume that if one of the earlier queries found a "device"
- // account then this query isn't going to find any different device accounts.
- // We skip this query because it probably is kind of expensive (relative to the other
- // queries).
- addAccountsFromQuery(ContactsContract.RawContacts.CONTENT_URI, localAccounts);
- }
+ addAccountsFromQuery(ContactsContract.RawContacts.CONTENT_URI, localAccounts);
return new ArrayList<>(localAccounts);
}
diff --git a/tests/src/com/android/contacts/common/model/DeviceLocalAccountLocatorTests.java b/tests/src/com/android/contacts/common/model/DeviceLocalAccountLocatorTests.java
index f1a2714..e8c4e2f 100644
--- a/tests/src/com/android/contacts/common/model/DeviceLocalAccountLocatorTests.java
+++ b/tests/src/com/android/contacts/common/model/DeviceLocalAccountLocatorTests.java
@@ -140,24 +140,6 @@
assertEquals(2, sut.getDeviceLocalAccounts().size());
}
- public void test_getDeviceLocalAccounts_onlyQueriesRawContactsIfNecessary() {
- final DeviceLocalAccountTypeFactory stubFactory = new FakeDeviceAccountTypeFactory()
- .withDeviceTypes(null, "vnd.sec.contact.phone")
- .withSimTypes("vnd.sec.contact.sim");
- final FakeContactsProvider contactsProvider = new FakeContactsProvider()
- .withQueryResult(ContactsContract.Groups.CONTENT_URI, queryResult(
- "phone_account", "vnd.sec.contact.phone",
- "sim_account", "vnd.sec.contact.sim"
- ));
- final DeviceLocalAccountLocator sut = new DeviceLocalAccountLocator(
- createContentResolverWithProvider(contactsProvider), stubFactory,
- Collections.<AccountWithDataSet>emptyList());
-
- sut.getDeviceLocalAccounts();
-
- assertEquals(0, contactsProvider.getQueryCountFor(RawContacts.CONTENT_URI));
- }
-
private DeviceLocalAccountLocator createWithQueryResult(
Cursor cursor) {
final DeviceLocalAccountLocator locator = new DeviceLocalAccountLocator(
@@ -194,7 +176,6 @@
private static class FakeContactsProvider extends MockContentProvider {
public Cursor mNextQueryResult;
public Map<Uri, Cursor> mNextResultMapping = new HashMap<>();
- public Map<Uri, Integer> mQueryCountMapping = new HashMap<>();
public FakeContactsProvider() {}
@@ -214,17 +195,10 @@
return query(uri, projection, selection, selectionArgs, sortOrder, null);
}
- public int getQueryCountFor(Uri uri) {
- ensureCountInitialized(uri);
- return mQueryCountMapping.get(uri);
- }
-
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder, CancellationSignal cancellationSignal) {
- incrementQueryCount(uri);
-
final Cursor result = mNextResultMapping.get(uri);
if (result == null) {
return mNextQueryResult;
@@ -232,17 +206,5 @@
return result;
}
}
-
- private void ensureCountInitialized(Uri uri) {
- if (!mQueryCountMapping.containsKey(uri)) {
- mQueryCountMapping.put(uri, 0);
- }
- }
-
- private void incrementQueryCount(Uri uri) {
- ensureCountInitialized(uri);
- final int count = mQueryCountMapping.get(uri);
- mQueryCountMapping.put(uri, count + 1);
- }
}
}