aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-09-20 17:31:57 -0700
committerYorke Lee <yorkelee@google.com>2013-09-22 18:04:50 -0700
commitd820edb03bd5caffc0dff19096552efa817dec59 (patch)
tree163fd1b0ab5ab41d343c7e471879bcb878a91ecd
parent60bc1537f541bb78814da7d7ffe159beadb2c42d (diff)
downloadContactsProvider-d820edb03bd5caffc0dff19096552efa817dec59.tar.gz
Change frequents algorithm to return contacts in a different order
Bucketing thresholds - 3 days - 7 days - 14 days - 30 days - Any contacts older than this are not shown Change-Id: I4940920c4eb8ad4f5d130adc0b2acd30a4d7aff6
-rw-r--r--src/com/android/providers/contacts/ContactsProvider2.java29
-rw-r--r--tests/src/com/android/providers/contacts/ContactsProvider2Test.java65
2 files changed, 68 insertions, 26 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index b71892cc..ff13dcd1 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -518,21 +518,31 @@ public class ContactsProvider2 extends AbstractContactsProvider
" WHERE " + RawContacts.CONTACT_ID + " = ?1 AND " + Contacts.PINNED + " <= " +
PinnedPositions.DEMOTED;
- // Current contacts - those contacted within the last 3 days (in seconds)
- private static final long LAST_TIME_USED_CURRENT_SEC = 3 * 24 * 60 * 60;
+ // Contacts contacted within the last 3 days (in seconds)
+ private static final long LAST_TIME_USED_3_DAYS_SEC = 3L * 24 * 60 * 60;
- // Recent contacts - those contacted within the last 30 days (in seconds)
- private static final long LAST_TIME_USED_RECENT_SEC = 30 * 24 * 60 * 60;
+ // Contacts contacted within the last 7 days (in seconds)
+ private static final long LAST_TIME_USED_7_DAYS_SEC = 7L * 24 * 60 * 60;
+
+ // Contacts contacted within the last 14 days (in seconds)
+ private static final long LAST_TIME_USED_14_DAYS_SEC = 14L * 24 * 60 * 60;
+
+ // Contacts contacted within the last 30 days (in seconds)
+ private static final long LAST_TIME_USED_30_DAYS_SEC = 30L * 24 * 60 * 60;
private static final String TIME_SINCE_LAST_USED_SEC =
"(strftime('%s', 'now') - " + DataUsageStatColumns.LAST_TIME_USED + "/1000)";
private static final String SORT_BY_DATA_USAGE =
- "(CASE WHEN " + TIME_SINCE_LAST_USED_SEC + " < " + LAST_TIME_USED_CURRENT_SEC +
+ "(CASE WHEN " + TIME_SINCE_LAST_USED_SEC + " < " + LAST_TIME_USED_3_DAYS_SEC +
" THEN 0 " +
- " WHEN " + TIME_SINCE_LAST_USED_SEC + " < " + LAST_TIME_USED_RECENT_SEC +
+ " WHEN " + TIME_SINCE_LAST_USED_SEC + " < " + LAST_TIME_USED_7_DAYS_SEC +
" THEN 1 " +
- " ELSE 2 END), " +
+ " WHEN " + TIME_SINCE_LAST_USED_SEC + " < " + LAST_TIME_USED_14_DAYS_SEC +
+ " THEN 2 " +
+ " WHEN " + TIME_SINCE_LAST_USED_SEC + " < " + LAST_TIME_USED_30_DAYS_SEC +
+ " THEN 3 " +
+ " ELSE 4 END), " +
DataUsageStatColumns.TIMES_USED + " DESC";
/*
@@ -5427,7 +5437,10 @@ public class ContactsProvider2 extends AbstractContactsProvider
// We need to wrap the inner queries in an extra select, because they contain
// their own SORT and LIMIT
- final String frequentQuery = "SELECT * FROM (" + frequentInnerQuery + ")";
+
+ // Phone numbers that were used more than 30 days ago are dropped from frequents
+ final String frequentQuery = "SELECT * FROM (" + frequentInnerQuery + ") WHERE " +
+ TIME_SINCE_LAST_USED_SEC + "<" + LAST_TIME_USED_30_DAYS_SEC;
final String starredQuery = "SELECT * FROM (" + starredInnerQuery + ")";
// Put them together
diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
index f9b13a58..867d935e 100644
--- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
+++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java
@@ -2401,15 +2401,23 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
final long rid6 = RawContactUtil.createRawContact(mResolver);
final long did6 = ContentUris.parseId(insertPhoneNumber(rid6, "6"));
+ final long rid7 = RawContactUtil.createRawContact(mResolver);
+ final long did7 = ContentUris.parseId(insertPhoneNumber(rid7, "7"));
+
+ final long rid8 = RawContactUtil.createRawContact(mResolver);
+ final long did8 = ContentUris.parseId(insertPhoneNumber(rid8, "8"));
+
final long cid1 = queryContactId(rid1);
final long cid2 = queryContactId(rid2);
final long cid3 = queryContactId(rid3);
final long cid4 = queryContactId(rid4);
final long cid5 = queryContactId(rid5);
final long cid6 = queryContactId(rid6);
+ final long cid7 = queryContactId(rid7);
+ final long cid8 = queryContactId(rid8);
// Make sure they aren't aggregated.
- EvenMoreAsserts.assertUnique(cid1, cid2, cid3, cid4, cid5, cid6);
+ EvenMoreAsserts.assertUnique(cid1, cid2, cid3, cid4, cid5, cid6, cid7, cid8);
// Prepare the clock
sMockClock.install();
@@ -2418,24 +2426,27 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
// use the actual (roughly) time.
final long nowInMillis = System.currentTimeMillis();
- final long yesterdayInMillis = (nowInMillis - 24 * 60 * 60 * 1000);
- final long sevenDaysAgoInMillis = (nowInMillis - 7 * 24 * 60 * 60 * 1000);
- final long oneYearAgoInMillis = (nowInMillis - 365L * 24 * 60 * 60 * 1000);
+ final long oneDayAgoInMillis = (nowInMillis - 24L * 60 * 60 * 1000);
+ final long fourDaysAgoInMillis = (nowInMillis - 4L * 24 * 60 * 60 * 1000);
+ final long eightDaysAgoInMillis = (nowInMillis - 8L * 24 * 60 * 60 * 1000);
+ final long fifteenDaysAgoInMillis = (nowInMillis - 15L * 24 * 60 * 60 * 1000);
+ // All contacts older than 30 days will not be included in frequents
+ final long thirtyOneDaysAgoInMillis = (nowInMillis - 31L * 24 * 60 * 60 * 1000);
- // A year ago...
- sMockClock.setCurrentTimeMillis(oneYearAgoInMillis);
+ // Contacts in this bucket are considered more than 30 days old
+ sMockClock.setCurrentTimeMillis(thirtyOneDaysAgoInMillis);
updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did1, did2);
updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did1);
- // 7 days ago...
- sMockClock.setCurrentTimeMillis(sevenDaysAgoInMillis);
+ // Contacts in this bucket are considered more than 14 days old
+ sMockClock.setCurrentTimeMillis(fifteenDaysAgoInMillis);
updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did3, did4);
updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did3);
- // Yesterday...
- sMockClock.setCurrentTimeMillis(yesterdayInMillis);
+ // Contacts in this bucket are considered more than 7 days old
+ sMockClock.setCurrentTimeMillis(eightDaysAgoInMillis);
updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did5, did6);
updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did5);
@@ -2443,28 +2454,46 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
// Contact cid1 again, but it's an email, not a phone call.
updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_LONG_TEXT, did1e);
+ // Contacts in this bucket are considered more than 3 days old
+ sMockClock.setCurrentTimeMillis(fourDaysAgoInMillis);
+
+ updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did7);
+ updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did7);
+
+
+ // Contacts in this bucket are considered less than 3 days old
+ sMockClock.setCurrentTimeMillis(oneDayAgoInMillis);
+
+ updateDataUsageFeedback(DataUsageFeedback.USAGE_TYPE_CALL, did8);
+
+ sMockClock.setCurrentTimeMillis(nowInMillis);
+
// Check the order -- The regular frequent, which is contact based.
- // Note because we contacted cid1 yesterday, it's been contacted 3 times, so it comes
- // first.
+ // Note because we contacted cid1 8 days ago, it's been contacted 3 times, so it comes
+ // before cid5 and cid6, which were contacted at the same time.
+ // cid2 will not show up because it was contacted more than 30 days ago
+
assertStoredValuesOrderly(Contacts.CONTENT_STREQUENT_URI,
+ cv(Contacts._ID, cid8),
+ cv(Contacts._ID, cid7),
cv(Contacts._ID, cid1),
cv(Contacts._ID, cid5),
cv(Contacts._ID, cid6),
cv(Contacts._ID, cid3),
- cv(Contacts._ID, cid4),
- cv(Contacts._ID, cid2));
+ cv(Contacts._ID, cid4));
// Check the order -- phone only frequent, which is data based.
// Note this is based on data, and only looks at phone numbers, so the order is different
// now.
+ // did1, did2 will not show up because they were used to make calls more than 30 days ago.
assertStoredValuesOrderly(Contacts.CONTENT_STREQUENT_URI.buildUpon()
.appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "1").build(),
+ cv(Data._ID, did8),
+ cv(Data._ID, did7),
cv(Data._ID, did5),
cv(Data._ID, did6),
cv(Data._ID, did3),
- cv(Data._ID, did4),
- cv(Data._ID, did1),
- cv(Data._ID, did2));
+ cv(Data._ID, did4));
}
/**
@@ -7287,7 +7316,7 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test {
public void testDataUsageFeedbackAndDelete() {
sMockClock.install();
-
+ sMockClock.setCurrentTimeMillis(System.currentTimeMillis());
final long startTime = sMockClock.currentTimeMillis();
final long rid1 = RawContactUtil.createRawContactWithName(mResolver, "contact", "a");