diff options
author | Isaac Katzenelson <isaack@android.com> | 2011-08-15 16:38:28 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-08-15 16:38:28 -0700 |
commit | a473a987518f696c3480b022f5e1d13e3cbff5d2 (patch) | |
tree | f9cafff266bb588c36e99f5f5649e98ad52dde72 | |
parent | 73ea28535cb77f9a874eefcc1b009e59881d4be0 (diff) | |
parent | 3e6cd1fbafd09bf9b6ec35a19a55b48a271727df (diff) | |
download | packages_providers_ContactsProvider-a473a987518f696c3480b022f5e1d13e3cbff5d2.zip packages_providers_ContactsProvider-a473a987518f696c3480b022f5e1d13e3cbff5d2.tar.gz packages_providers_ContactsProvider-a473a987518f696c3480b022f5e1d13e3cbff5d2.tar.bz2 |
Merge "Fix provider empty state status"
-rw-r--r-- | src/com/android/providers/contacts/ContactsProvider2.java | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index edcd201..17c9201 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -1595,10 +1595,43 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun return; } - if (mContactsAccountCount == 0 - && DatabaseUtils.queryNumEntries(mDbHelper.getReadableDatabase(), - Tables.CONTACTS, null) == 0) { - setProviderStatus(ProviderStatus.STATUS_NO_ACCOUNTS_NO_CONTACTS); + // No accounts/no contacts status is true if there are no account and + // there are + // no contacts or one profile contact + if (mContactsAccountCount == 0) { + long contactsNum = DatabaseUtils.queryNumEntries(mDbHelper.getReadableDatabase(), + Tables.CONTACTS, null); + if (contactsNum == 0) { + setProviderStatus(ProviderStatus.STATUS_NO_ACCOUNTS_NO_CONTACTS); + } else if (contactsNum == 1) { + // if we have one contact, need to make sure it is the local + // profile + // so need to get the raw_contact id from the account table and + // then + // make sure the raw_contacts exists and it is not deleted + long rawId = DatabaseUtils.longForQuery( + mDbHelper.getReadableDatabase(), + "SELECT " + AccountsColumns.PROFILE_RAW_CONTACT_ID + + " FROM " + Tables.ACCOUNTS + , null); + if (rawId == 0) { + setProviderStatus(ProviderStatus.STATUS_NORMAL); + return; + } + boolean deleted = DatabaseUtils.longForQuery( + mDbHelper.getReadableDatabase(), + "SELECT " + RawContacts.DELETED + + " FROM " + Tables.RAW_CONTACTS + + " WHERE " + RawContacts._ID + "=" + String.valueOf(rawId), + null) == 1; + if (deleted) { + setProviderStatus(ProviderStatus.STATUS_NORMAL); + return; + } + setProviderStatus(ProviderStatus.STATUS_NO_ACCOUNTS_NO_CONTACTS); + } else { + setProviderStatus(ProviderStatus.STATUS_NORMAL); + } } else { setProviderStatus(ProviderStatus.STATUS_NORMAL); } |