Bug 897924 - Intermittent test_contacts_basics.html | No contacts after clear - got 124 (or 84), expected 0. r=cpeterson

This commit is contained in:
Chris Peterson 2013-08-16 15:49:18 -07:00
parent ae382f0b99
commit 9e70a3b067
2 changed files with 34 additions and 26 deletions

View File

@ -240,7 +240,8 @@ function removeAndroidDefaultCategory(category) {
}
for (var i = 0; i < category.length; i++) {
if (category[i] == "My Contacts") {
// Some devices may return the full group name (prefixed with "System Group: ")
if (category[i] == "My Contacts" || category[i] == "System Group: My Contacts") {
category.splice(i, 1);
}
}

View File

@ -27,8 +27,8 @@ import android.content.DialogInterface;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
import android.os.Build;
import android.os.RemoteException;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.BaseTypes;
import android.provider.ContactsContract.CommonDataKinds.Email;
@ -921,8 +921,8 @@ public class ContactService implements GeckoEventListener {
}
private boolean deleteContact(String rawContactId) {
ContentProviderOperation deleteOptions = ContentProviderOperation.newDelete(Data.CONTENT_URI)
.withSelection(Data.RAW_CONTACT_ID + "=?",
ContentProviderOperation deleteOptions = ContentProviderOperation.newDelete(RawContacts.CONTENT_URI)
.withSelection(RawContacts._ID + "=?",
new String[] {rawContactId})
.build();
@ -1482,7 +1482,9 @@ public class ContactService implements GeckoEventListener {
}
private void getContactsCount(final String requestID) {
Integer numContacts = getAllRawContactIds().length;
Cursor cursor = getAllRawContactIdsCursor();
Integer numContacts = Integer.valueOf(cursor.getCount());
cursor.close();
sendCallbackToJavascript("Android:Contacts:Count", requestID, new String[] {"count"},
new Object[] {numContacts});
@ -1730,33 +1732,38 @@ public class ContactService implements GeckoEventListener {
}
private long[] getAllRawContactIds() {
// Only get contacts from the selected account
String selection = null;
String[] selectionArgs = null;
if (mAccountName != null) {
selection = RawContacts.ACCOUNT_NAME + "=? AND " + RawContacts.ACCOUNT_TYPE + "=?";
selectionArgs = new String[] {mAccountName, mAccountType};
}
Cursor cursor = getAllRawContactIdsCursor();
// Get the ID's of all the contacts and use the number of contact ID's as
// the total number of contacts
Cursor cursor = mContentResolver.query(Data.CONTENT_URI,
new String[] {Data.RAW_CONTACT_ID},
selection, selectionArgs, null);
List<Long> ids = new ArrayList<Long>();
// Filter out any duplicate IDs
// Put the ids into an array
long[] ids = new long[cursor.getCount()];
int index = 0;
cursor.moveToPosition(-1);
while(cursor.moveToNext()) {
Long id = Long.valueOf(cursor.getLong(cursor.getColumnIndex(Data.RAW_CONTACT_ID)));
if (!ids.contains(id)) {
ids.add(id);
}
ids[index] = cursor.getLong(cursor.getColumnIndex(RawContacts._ID));
index++;
}
cursor.close();
return convertLongListToArray(ids);
return ids;
}
private Cursor getAllRawContactIdsCursor() {
// When a contact is deleted, it actually just sets the deleted field to 1 until the
// sync adapter actually deletes the contact later so ignore any contacts with the deleted
// flag set
String selection = RawContacts.DELETED + "=0";
String[] selectionArgs = null;
// Only get contacts from the selected account
if (mAccountName != null) {
selection += " AND " + RawContacts.ACCOUNT_NAME + "=? AND " + RawContacts.ACCOUNT_TYPE + "=?";
selectionArgs = new String[] {mAccountName, mAccountType};
}
// Get the ID's of all contacts and use the number of contact ID's as
// the total number of contacts
return mContentResolver.query(RawContacts.CONTENT_URI, new String[] {RawContacts._ID},
selection, selectionArgs, null);
}
private static Long getRawContactIdFromContentProviderResults(ContentProviderResult[] results) throws NumberFormatException {