Skip QD1A.190821.011 in stage-aosp-master
Bug: 141248619
Change-Id: Ia3ddfe73a2fa32723e809f74bb83ff43d2c11df9
diff --git a/Android.bp b/Android.bp
index b6bddce..8991628 100644
--- a/Android.bp
+++ b/Android.bp
@@ -6,8 +6,7 @@
"src/com/android/providers/contacts/EventLogTags.logtags",
],
libs: [
- "ext",
- "telephony-common",
+ "ext"
],
static_libs: [
"android-common",
diff --git a/src/com/android/providers/contacts/CallLogProvider.java b/src/com/android/providers/contacts/CallLogProvider.java
index ff3e65c..022b61e 100644
--- a/src/com/android/providers/contacts/CallLogProvider.java
+++ b/src/com/android/providers/contacts/CallLogProvider.java
@@ -183,6 +183,7 @@
private CallLogDatabaseHelper mDbHelper;
private DatabaseUtils.InsertHelper mCallsInserter;
private boolean mUseStrictPhoneNumberComparation;
+ private int mMinMatch;
private VoicemailPermissions mVoicemailPermissions;
private CallLogInsertionHelper mCallLogInsertionHelper;
@@ -214,6 +215,9 @@
mUseStrictPhoneNumberComparation =
context.getResources().getBoolean(
com.android.internal.R.bool.config_use_strict_phone_number_comparation);
+ mMinMatch =
+ context.getResources().getInteger(
+ com.android.internal.R.integer.config_phonenumber_compare_min_match);
mVoicemailPermissions = new VoicemailPermissions(context);
mCallLogInsertionHelper = createCallLogInsertionHelper(context);
@@ -239,6 +243,16 @@
return DefaultCallLogInsertionHelper.getInstance(context);
}
+ @VisibleForTesting
+ public void setMinMatchForTest(int minMatch) {
+ mMinMatch = minMatch;
+ }
+
+ @VisibleForTesting
+ public int getMinMatchForTest() {
+ return mMinMatch;
+ }
+
protected CallLogDatabaseHelper getDatabaseHelper(final Context context) {
return CallLogDatabaseHelper.getInstance(context);
}
@@ -331,7 +345,8 @@
if (!TextUtils.isEmpty(phoneNumber)) {
qb.appendWhere("PHONE_NUMBERS_EQUAL(number, ");
qb.appendWhereEscapeString(phoneNumber);
- qb.appendWhere(mUseStrictPhoneNumberComparation ? ", 1)" : ", 0)");
+ qb.appendWhere(mUseStrictPhoneNumberComparation ? ", 1)"
+ : ", 0, " + mMinMatch + ")");
} else {
qb.appendWhere(Calls.NUMBER_PRESENTATION + "!="
+ Calls.PRESENTATION_ALLOWED);
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index 4c521f4..91a2a91 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -982,6 +982,7 @@
private boolean mUseStrictPhoneNumberComparisonBase;
private boolean mUseStrictPhoneNumberComparisonForRussia;
private boolean mUseStrictPhoneNumberComparisonForKazakhstan;
+ private int mMinMatch;
private String[] mSelectionArgs1 = new String[1];
private NameSplitter.Name mName = new NameSplitter.Name();
@@ -1071,6 +1072,9 @@
} else {
mUseStrictPhoneNumberComparison = mUseStrictPhoneNumberComparisonBase;
}
+
+ mMinMatch = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_phonenumber_compare_min_match);
}
private boolean getConfig(String configKey, int defaultResId) {
@@ -4239,7 +4243,7 @@
sb.setLength(0);
sb.append("PHONE_NUMBERS_EQUAL(" + Tables.DATA + "." + Phone.NUMBER + ", ");
DatabaseUtils.appendEscapedSQLString(sb, number);
- sb.append(mUseStrictPhoneNumberComparison ? ", 1)" : ", 0)");
+ sb.append(mUseStrictPhoneNumberComparison ? ", 1)" : ", 0, " + mMinMatch + ")");
qb.appendWhere(sb.toString());
}
@@ -4336,6 +4340,10 @@
return mUseStrictPhoneNumberComparison ? "1" : "0";
}
+ public String getMinMatchParameter() {
+ return String.valueOf(mMinMatch);
+ }
+
/**
* Loads common nickname mappings into the database.
*/
@@ -4954,6 +4962,16 @@
return mUseStrictPhoneNumberComparison;
}
+ @VisibleForTesting
+ public void setMinMatchForTest(int minMatch) {
+ mMinMatch = minMatch;
+ }
+
+ @VisibleForTesting
+ public int getMinMatchForTest() {
+ return mMinMatch;
+ }
+
@NeededForTesting
/* package */ String querySearchIndexContentForTest(long contactId) {
return DatabaseUtils.stringForQuery(getReadableDatabase(),
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 02c8bf0..dbf6bea 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -9828,7 +9828,7 @@
* @return the currently active {@link ContactsDatabaseHelper} for the current thread.
*/
@NeededForTesting
- protected ContactsDatabaseHelper getThreadActiveDatabaseHelperForTest() {
+ public ContactsDatabaseHelper getThreadActiveDatabaseHelperForTest() {
return mDbHelper.get();
}
diff --git a/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java b/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java
index 965780e..82e35f1 100644
--- a/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java
+++ b/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java
@@ -174,6 +174,7 @@
protected String[] mSelectionArgs1 = new String[1];
protected String[] mSelectionArgs2 = new String[2];
+ protected String[] mSelectionArgs3 = new String[3];
protected long mMimeTypeIdIdentity;
protected long mMimeTypeIdEmail;
@@ -794,8 +795,8 @@
" AND d1." + Data.RAW_CONTACT_ID + " IN (" + rawContactIdSet1 + ")" +
" AND d2." + Data.RAW_CONTACT_ID + " IN (" + rawContactIdSet2 + ")" +
" AND PHONE_NUMBERS_EQUAL(d1." + Phone.NUMBER + ",d2." + Phone.NUMBER + "," +
- String.valueOf(mDbHelper.getUseStrictPhoneNumberComparisonParameter()) +
- ")";
+ (mDbHelper.getUseStrictPhoneNumberComparisonParameter().equals("1") ? "1)"
+ : "0," + mDbHelper.getMinMatchParameter() + ")");
return (countOnly) ? RawContactMatchingSelectionStatement.SELECT_COUNT + sql :
RawContactMatchingSelectionStatement.SELECT_ID + sql;
}
@@ -1195,6 +1196,12 @@
+ " AND " + RawContactsColumns.AGGREGATION_NEEDED + "=0"
+ " AND " + RawContacts.CONTACT_ID + " IN " + Tables.DEFAULT_DIRECTORY;
+ String SELECTION_MIN_MATCH = "dataA." + Data.RAW_CONTACT_ID + "=?"
+ + " AND PHONE_NUMBERS_EQUAL(dataA." + Phone.NUMBER + ", "
+ + "dataB." + Phone.NUMBER + ",?,?)"
+ + " AND " + RawContactsColumns.AGGREGATION_NEEDED + "=0"
+ + " AND " + RawContacts.CONTACT_ID + " IN " + Tables.DEFAULT_DIRECTORY;
+
String[] COLUMNS = new String[] {
Tables.RAW_CONTACTS + "." + RawContacts._ID,
RawContacts.CONTACT_ID,
diff --git a/src/com/android/providers/contacts/aggregation/ContactAggregator.java b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
index e5bd2ea..a104339 100644
--- a/src/com/android/providers/contacts/aggregation/ContactAggregator.java
+++ b/src/com/android/providers/contacts/aggregation/ContactAggregator.java
@@ -800,11 +800,25 @@
private void updateMatchScoresBasedOnPhoneMatches(SQLiteDatabase db, long rawContactId,
ContactMatcher matcher) {
- mSelectionArgs2[0] = String.valueOf(rawContactId);
- mSelectionArgs2[1] = mDbHelper.getUseStrictPhoneNumberComparisonParameter();
- Cursor c = db.query(PhoneLookupQuery.TABLE, PhoneLookupQuery.COLUMNS,
+ Cursor c;
+ String useStrictPhoneNumberComparison =
+ mDbHelper.getUseStrictPhoneNumberComparisonParameter();
+
+ if (useStrictPhoneNumberComparison.equals("1")) {
+ mSelectionArgs2[0] = String.valueOf(rawContactId);
+ mSelectionArgs2[1] = useStrictPhoneNumberComparison;
+ c = db.query(PhoneLookupQuery.TABLE, PhoneLookupQuery.COLUMNS,
PhoneLookupQuery.SELECTION,
mSelectionArgs2, null, null, null, SECONDARY_HIT_LIMIT_STRING);
+ } else {
+ mSelectionArgs3[0] = String.valueOf(rawContactId);
+ mSelectionArgs3[1] = useStrictPhoneNumberComparison;
+ mSelectionArgs3[2] = mDbHelper.getMinMatchParameter();
+ c = db.query(PhoneLookupQuery.TABLE, PhoneLookupQuery.COLUMNS,
+ PhoneLookupQuery.SELECTION_MIN_MATCH,
+ mSelectionArgs3, null, null, null, SECONDARY_HIT_LIMIT_STRING);
+ }
+
try {
while (c.moveToNext()) {
long contactId = c.getLong(PhoneLookupQuery.CONTACT_ID);
diff --git a/src/com/android/providers/contacts/aggregation/ContactAggregator2.java b/src/com/android/providers/contacts/aggregation/ContactAggregator2.java
index e0bc3bb..6b1424c 100644
--- a/src/com/android/providers/contacts/aggregation/ContactAggregator2.java
+++ b/src/com/android/providers/contacts/aggregation/ContactAggregator2.java
@@ -665,11 +665,25 @@
private void updateMatchScoresBasedOnPhoneMatches(SQLiteDatabase db, long rawContactId,
RawContactMatcher matcher) {
- mSelectionArgs2[0] = String.valueOf(rawContactId);
- mSelectionArgs2[1] = mDbHelper.getUseStrictPhoneNumberComparisonParameter();
- Cursor c = db.query(PhoneLookupQuery.TABLE, PhoneLookupQuery.COLUMNS,
+ Cursor c;
+ String useStrictPhoneNumberComparison =
+ mDbHelper.getUseStrictPhoneNumberComparisonParameter();
+
+ if (useStrictPhoneNumberComparison.equals("1")) {
+ mSelectionArgs2[0] = String.valueOf(rawContactId);
+ mSelectionArgs2[1] = useStrictPhoneNumberComparison;
+ c = db.query(PhoneLookupQuery.TABLE, PhoneLookupQuery.COLUMNS,
PhoneLookupQuery.SELECTION,
mSelectionArgs2, null, null, null, SECONDARY_HIT_LIMIT_STRING);
+ } else {
+ mSelectionArgs3[0] = String.valueOf(rawContactId);
+ mSelectionArgs3[1] = useStrictPhoneNumberComparison;
+ mSelectionArgs3[2] = mDbHelper.getMinMatchParameter();
+ c = db.query(PhoneLookupQuery.TABLE, PhoneLookupQuery.COLUMNS,
+ PhoneLookupQuery.SELECTION_MIN_MATCH,
+ mSelectionArgs3, null, null, null, SECONDARY_HIT_LIMIT_STRING);
+ }
+
try {
while (c.moveToNext()) {
long rId = c.getLong(PhoneLookupQuery.RAW_CONTACT_ID);
@@ -1029,6 +1043,11 @@
+ "dataB." + Phone.NUMBER + ",?)"
+ " AND " + RawContacts.CONTACT_ID + " IN " + Tables.DEFAULT_DIRECTORY;
+ String SELECTION_MIN_MATCH = "dataA." + Data.RAW_CONTACT_ID + "=?"
+ + " AND PHONE_NUMBERS_EQUAL(dataA." + Phone.NUMBER + ", "
+ + "dataB." + Phone.NUMBER + ",?,?)"
+ + " AND " + RawContacts.CONTACT_ID + " IN " + Tables.DEFAULT_DIRECTORY;
+
String[] COLUMNS = new String[] {
Tables.RAW_CONTACTS + "." + RawContacts._ID,
RawContacts.CONTACT_ID,
diff --git a/tests/src/com/android/providers/contacts/CallLogProviderTest.java b/tests/src/com/android/providers/contacts/CallLogProviderTest.java
index 93806e0..247da7d 100644
--- a/tests/src/com/android/providers/contacts/CallLogProviderTest.java
+++ b/tests/src/com/android/providers/contacts/CallLogProviderTest.java
@@ -63,6 +63,10 @@
/** Total number of columns exposed by call_log provider. */
private static final int NUM_CALLLOG_FIELDS = 34;
+ private static final int MIN_MATCH = 7;
+
+ private int mOldMinMatch;
+
private CallLogProviderTestable mCallLogProvider;
@Override
@@ -79,6 +83,8 @@
protected void setUp() throws Exception {
super.setUp();
mCallLogProvider = addProvider(CallLogProviderTestable.class, CallLog.AUTHORITY);
+ mOldMinMatch = mCallLogProvider.getMinMatchForTest();
+ mCallLogProvider.setMinMatchForTest(MIN_MATCH);
}
@Override
@@ -86,6 +92,7 @@
setUpWithVoicemailPermissions();
mResolver.delete(Calls.CONTENT_URI_WITH_VOICEMAIL, null, null);
setTimeForTest(null);
+ mCallLogProvider.setMinMatchForTest(mOldMinMatch);
super.tearDown();
}
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
index 32a0306..6421c8f 100644
--- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
@@ -70,6 +70,7 @@
import android.provider.ContactsContract.StreamItemPhotos;
import android.provider.ContactsContract.StreamItems;
import android.provider.OpenableColumns;
+import android.telephony.PhoneNumberUtils;
import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
@@ -129,6 +130,31 @@
private static final String TAG = ContactsProvider2Test.class.getSimpleName();
+ private static final int MIN_MATCH = 7;
+
+ private int mOldMinMatch1;
+ private int mOldMinMatch2;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ final ContactsProvider2 cp = (ContactsProvider2) getProvider();
+ final ContactsDatabaseHelper dbHelper = cp.getThreadActiveDatabaseHelperForTest();
+ mOldMinMatch1 = PhoneNumberUtils.getMinMatchForTest();
+ mOldMinMatch2 = dbHelper.getMinMatchForTest();
+ PhoneNumberUtils.setMinMatchForTest(MIN_MATCH);
+ dbHelper.setMinMatchForTest(MIN_MATCH);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ final ContactsProvider2 cp = (ContactsProvider2) getProvider();
+ final ContactsDatabaseHelper dbHelper = cp.getThreadActiveDatabaseHelperForTest();
+ PhoneNumberUtils.setMinMatchForTest(mOldMinMatch1);
+ dbHelper.setMinMatchForTest(mOldMinMatch2);
+ super.tearDown();
+ }
+
public void testConvertEnterpriseUriWithEnterpriseDirectoryToLocalUri() {
String phoneNumber = "886";
String directory = String.valueOf(Directory.ENTERPRISE_DEFAULT);
diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java
index 927b215..b19a10f 100644
--- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java
+++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregator2Test.java
@@ -34,10 +34,12 @@
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.StatusUpdates;
+import android.telephony.PhoneNumberUtils;
import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.MediumTest;
import com.android.providers.contacts.BaseContactsProvider2Test;
+import com.android.providers.contacts.ContactsDatabaseHelper;
import com.android.providers.contacts.ContactsProvider2;
import com.android.providers.contacts.TestUtils;
import com.android.providers.contacts.tests.R;
@@ -69,11 +71,32 @@
AggregationExceptions.RAW_CONTACT_ID2
};
+ private static final int MIN_MATCH = 7;
+
+ private static int mOldMinMatch1;
+ private static int mOldMinMatch2;
+
+ @Override
protected void setUp() throws Exception {
super.setUp();
// Enable new aggregator.
final ContactsProvider2 cp = (ContactsProvider2) getProvider();
cp.setNewAggregatorForTest(true);
+
+ final ContactsDatabaseHelper dbHelper = cp.getThreadActiveDatabaseHelperForTest();
+ mOldMinMatch1 = PhoneNumberUtils.getMinMatchForTest();
+ mOldMinMatch2 = dbHelper.getMinMatchForTest();
+ PhoneNumberUtils.setMinMatchForTest(MIN_MATCH);
+ dbHelper.setMinMatchForTest(MIN_MATCH);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ final ContactsProvider2 cp = (ContactsProvider2) getProvider();
+ final ContactsDatabaseHelper dbHelper = cp.getThreadActiveDatabaseHelperForTest();
+ PhoneNumberUtils.setMinMatchForTest(mOldMinMatch1);
+ dbHelper.setMinMatchForTest(mOldMinMatch2);
+ super.tearDown();
}
public void testCrudAggregationExceptions() throws Exception {
diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
index fb4f930..56f0883 100644
--- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
+++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
@@ -34,10 +34,12 @@
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.StatusUpdates;
+import android.telephony.PhoneNumberUtils;
import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.MediumTest;
import com.android.providers.contacts.BaseContactsProvider2Test;
+import com.android.providers.contacts.ContactsDatabaseHelper;
import com.android.providers.contacts.ContactsProvider2;
import com.android.providers.contacts.TestUtils;
import com.android.providers.contacts.tests.R;
@@ -63,17 +65,38 @@
private static final Account ACCOUNT_2 = new Account("account_name_2", "account_type_2");
private static final Account ACCOUNT_3 = new Account("account_name_3", "account_type_3");
+ private static final int MIN_MATCH = 7;
+
+ private int mOldMinMatch1;
+ private int mOldMinMatch2;
+
private static final String[] AGGREGATION_EXCEPTION_PROJECTION = new String[] {
AggregationExceptions.TYPE,
AggregationExceptions.RAW_CONTACT_ID1,
AggregationExceptions.RAW_CONTACT_ID2
};
+ @Override
protected void setUp() throws Exception {
super.setUp();
final ContactsProvider2 cp = (ContactsProvider2) getProvider();
// Make sure to use ContactAggregator.java class
cp.setNewAggregatorForTest(false);
+
+ final ContactsDatabaseHelper dbHelper = cp.getThreadActiveDatabaseHelperForTest();
+ mOldMinMatch1 = PhoneNumberUtils.getMinMatchForTest();
+ mOldMinMatch2 = dbHelper.getMinMatchForTest();
+ PhoneNumberUtils.setMinMatchForTest(MIN_MATCH);
+ dbHelper.setMinMatchForTest(MIN_MATCH);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ final ContactsProvider2 cp = (ContactsProvider2) getProvider();
+ final ContactsDatabaseHelper dbHelper = cp.getThreadActiveDatabaseHelperForTest();
+ PhoneNumberUtils.setMinMatchForTest(mOldMinMatch1);
+ dbHelper.setMinMatchForTest(mOldMinMatch2);
+ super.tearDown();
}
public void testCrudAggregationExceptions() throws Exception {