use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by LineageOS.
the class SmartDialCursorLoader method loadInBackground.
/**
* Queries the SmartDial database and loads results in background.
*
* @return Cursor of contacts that matches the SmartDial query.
*/
@Override
public Cursor loadInBackground() {
if (DEBUG) {
LogUtil.v(TAG, "Load in background " + mQuery);
}
if (!PermissionsUtil.hasContactsReadPermissions(mContext)) {
return new MatrixCursor(PhoneQuery.PROJECTION_PRIMARY);
}
/**
* Loads results from the database helper.
*/
final DialerDatabaseHelper dialerDatabaseHelper = Database.get(mContext).getDatabaseHelper(mContext);
final ArrayList<ContactNumber> allMatches = dialerDatabaseHelper.getLooseMatches(mQuery, mNameMatcher);
if (DEBUG) {
LogUtil.v(TAG, "Loaded matches " + allMatches.size());
}
/**
* Constructs a cursor for the returned array of results.
*/
final MatrixCursor cursor = new MatrixCursor(PhoneQuery.PROJECTION_PRIMARY);
Object[] row = new Object[PhoneQuery.PROJECTION_PRIMARY.length];
for (ContactNumber contact : allMatches) {
row[PhoneQuery.PHONE_ID] = contact.dataId;
row[PhoneQuery.PHONE_NUMBER] = contact.phoneNumber;
row[PhoneQuery.CONTACT_ID] = contact.id;
row[PhoneQuery.LOOKUP_KEY] = contact.lookupKey;
row[PhoneQuery.PHOTO_ID] = contact.photoId;
row[PhoneQuery.DISPLAY_NAME] = contact.displayName;
row[PhoneQuery.CARRIER_PRESENCE] = contact.carrierPresence;
cursor.addRow(row);
}
return cursor;
}
use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by MoKee.
the class SmartDialPrefixTest method testPutNumbersNANP.
// Tests special case handling for NANP numbers
public void testPutNumbersNANP() {
SmartDialPrefix.setUserInNanpRegion(true);
final SQLiteDatabase db = mTestHelper.getWritableDatabase();
final MatrixCursor nameCursor = constructNewNameCursor();
final MatrixCursor contactCursor = constructNewContactCursor();
final ContactNumber contactno1 = constructNewContactWithDummyIds(contactCursor, nameCursor, "16503337596", 0, "James");
final ContactNumber contactno2 = constructNewContactWithDummyIds(contactCursor, nameCursor, "5109921234", 1, "Michael");
final ContactNumber contactno3 = constructNewContactWithDummyIds(contactCursor, nameCursor, "(415)-123-4567", 2, "Jason");
final ContactNumber contactno4 = constructNewContactWithDummyIds(contactCursor, nameCursor, "1 510-284-9170", 3, "Mike");
final ContactNumber contactno5 = constructNewContactWithDummyIds(contactCursor, nameCursor, "1-415-123-123", 4, "Invalid");
final ContactNumber contactno6 = constructNewContactWithDummyIds(contactCursor, nameCursor, "415-123-123", 5, "Invalid2");
final ContactNumber contactno7 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+1-510-284-9170", 6, "Mike");
final ContactNumber contactno8 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+1-510-284-917", 7, "Invalid");
final ContactNumber contactno9 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+857-510-284-9170", 8, "Inv");
mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
mTestHelper.insertNamePrefixes(db, nameCursor);
nameCursor.close();
contactCursor.close();
assertTrue(getLooseMatchesFromDb("16503337596").contains(contactno1));
assertTrue(getLooseMatchesFromDb("6503337596").contains(contactno1));
assertTrue(getLooseMatchesFromDb("3337596").contains(contactno1));
assertTrue(getLooseMatchesFromDb("5109921234").contains(contactno2));
assertTrue(getLooseMatchesFromDb("9921234").contains(contactno2));
assertTrue(getLooseMatchesFromDb("4151234567").contains(contactno3));
assertTrue(getLooseMatchesFromDb("1234567").contains(contactno3));
assertTrue(getLooseMatchesFromDb("15102849170").contains(contactno4));
assertTrue(getLooseMatchesFromDb("5102849170").contains(contactno4));
assertTrue(getLooseMatchesFromDb("2849170").contains(contactno4));
assertTrue(getLooseMatchesFromDb("1415123123").contains(contactno5));
assertFalse(getLooseMatchesFromDb("415123123").contains(contactno5));
assertFalse(getLooseMatchesFromDb("123123").contains(contactno5));
assertTrue(getLooseMatchesFromDb("415123123").contains(contactno6));
assertFalse(getLooseMatchesFromDb("123123").contains(contactno6));
assertTrue(getLooseMatchesFromDb("15102849170").contains(contactno7));
assertTrue(getLooseMatchesFromDb("5102849170").contains(contactno7));
assertTrue(getLooseMatchesFromDb("2849170").contains(contactno7));
assertFalse(getLooseMatchesFromDb("849170").contains(contactno7));
assertFalse(getLooseMatchesFromDb("10849170").contains(contactno7));
assertTrue(getLooseMatchesFromDb("1510284917").contains(contactno8));
assertTrue(getLooseMatchesFromDb("510284917").contains(contactno8));
assertFalse(getLooseMatchesFromDb("2849170").contains(contactno8));
assertTrue(getLooseMatchesFromDb("8575102849170").contains(contactno9));
assertFalse(getLooseMatchesFromDb("5102849170").contains(contactno9));
assertFalse(getLooseMatchesFromDb("2849170").contains(contactno9));
// TODO(klp) Adds test for non-NANP region number matchings.
}
use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by MoKee.
the class SmartDialPrefixTest method testCheckLongToken.
public void testCheckLongToken() {
final SQLiteDatabase db = mTestHelper.getWritableDatabase();
final MatrixCursor nameCursor = constructNewNameCursor();
final MatrixCursor contactCursor = constructNewContactCursor();
final ContactNumber alphabet = constructNewContactWithDummyIds(contactCursor, nameCursor, "1", 0, " aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn" + " oooo pppp qqqq rrrr ssss tttt uuuu vvvv wwww xxxx yyyy zzzz");
final ContactNumber alphabet2 = constructNewContactWithDummyIds(contactCursor, nameCursor, "1", 1, "aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrr" + "ssssttttuuuuvvvvwwwwxxxxyyyyzzzz");
mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
mTestHelper.insertNamePrefixes(db, nameCursor);
nameCursor.close();
contactCursor.close();
assertTrue(getLooseMatchesFromDb("2222").contains(alphabet));
assertEquals(40, mTestHelper.countPrefixTableRows(db));
}
use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by MoKee.
the class SmartDialPrefixTest method testPutForNumbers.
public void testPutForNumbers() {
final SQLiteDatabase db = mTestHelper.getWritableDatabase();
final MatrixCursor nameCursor = constructNewNameCursor();
final MatrixCursor contactCursor = constructNewContactCursor();
final ContactNumber contactno1 = constructNewContactWithDummyIds(contactCursor, nameCursor, "510-527-2357", 0, "James");
final ContactNumber contactno2 = constructNewContactWithDummyIds(contactCursor, nameCursor, "77212862357", 1, "James");
final ContactNumber contactno3 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+13684976334", 2, "James");
mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
mTestHelper.insertNamePrefixes(db, nameCursor);
nameCursor.close();
contactCursor.close();
assertTrue(getLooseMatchesFromDb("510").contains(contactno1));
assertFalse(getLooseMatchesFromDb("511").contains(contactno1));
assertTrue(getLooseMatchesFromDb("77212862357").contains(contactno2));
assertFalse(getLooseMatchesFromDb("77212862356").contains(contactno2));
assertTrue(getLooseMatchesFromDb("1368").contains(contactno3));
assertFalse(getLooseMatchesFromDb("1367").contains(contactno3));
}
use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by MoKee.
the class SmartDialPrefixTest method testNumbersInName.
public void testNumbersInName() {
final SQLiteDatabase db = mTestHelper.getWritableDatabase();
final MatrixCursor nameCursor = constructNewNameCursor();
final MatrixCursor contactCursor = constructNewContactCursor();
final ContactNumber contact = constructNewContactWithDummyIds(contactCursor, nameCursor, "0", 0, "12345678");
final ContactNumber teacher = constructNewContactWithDummyIds(contactCursor, nameCursor, "0", 1, "1st Grade Teacher");
mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
mTestHelper.insertNamePrefixes(db, nameCursor);
nameCursor.close();
contactCursor.close();
assertTrue(getLooseMatchesFromDb("12345678").contains(contact));
assertTrue(getLooseMatchesFromDb("17847233").contains(teacher));
assertTrue(getLooseMatchesFromDb("14832").contains(teacher));
}
Aggregations