diff options
author | Mathew Inwood <mathewi@google.com> | 2012-07-04 14:16:59 +0100 |
---|---|---|
committer | The Android Automerger <android-build@android.com> | 2012-07-04 13:53:05 -0700 |
commit | 1318af9730c64ebc3d72944b33cdd688c05e1970 (patch) | |
tree | 8d00b9918aeea49a482a7114b6ae3ebfa7eca795 | |
parent | 623d3c53c4aa45b620bbac0bf235f65250f52bb9 (diff) | |
download | ContactsProvider-jb-release.tar.gz |
Don't sort contacts supplied to global search app.android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1jb-release
They are to be sorted by the global search app itself instead.
While we're at it, also remove 'create contact' and 'dial number'
suggestions since they're not used.
Change-Id: I0c56f638e347d101468e22d8fb2417552891eaa9
-rw-r--r-- | src/com/android/providers/contacts/GlobalSearchSupport.java | 139 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/GlobalSearchSupportTest.java | 56 |
2 files changed, 10 insertions, 185 deletions
diff --git a/src/com/android/providers/contacts/GlobalSearchSupport.java b/src/com/android/providers/contacts/GlobalSearchSupport.java index 70dbd314..d4cddee0 100644 --- a/src/com/android/providers/contacts/GlobalSearchSupport.java +++ b/src/com/android/providers/contacts/GlobalSearchSupport.java @@ -18,14 +18,10 @@ package com.android.providers.contacts; import android.app.SearchManager; import android.content.Context; -import android.content.res.Resources; import android.database.Cursor; import android.database.MatrixCursor; import android.database.sqlite.SQLiteDatabase; -import android.location.Country; -import android.location.CountryDetector; import android.net.Uri; -import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Organization; import android.provider.ContactsContract.CommonDataKinds.Phone; @@ -36,7 +32,6 @@ import android.provider.ContactsContract.StatusUpdates; import android.telephony.TelephonyManager; import android.text.TextUtils; -import com.android.i18n.phonenumbers.PhoneNumberUtil; import com.android.providers.contacts.ContactsDatabaseHelper.AggregatedPresenceColumns; import com.android.providers.contacts.ContactsDatabaseHelper.ContactsColumns; import com.android.providers.contacts.ContactsDatabaseHelper.Tables; @@ -72,31 +67,6 @@ public class GlobalSearchSupport { " FROM " + Tables.AGGREGATED_PRESENCE + " WHERE " + AggregatedPresenceColumns.CONTACT_ID + "=" + ContactsColumns.CONCRETE_ID + ")"; - // Current contacts - those contacted within the last 3 days (in seconds) - private static final long CURRENT_CONTACTS = 3 * 24 * 60 * 60; - - // Recent contacts - those contacted within the last 30 days (in seconds) - private static final long RECENT_CONTACTS = 30 * 24 * 60 * 60; - - private static final String TIME_SINCE_LAST_CONTACTED = - "(strftime('%s', 'now') - contacts." + Contacts.LAST_TIME_CONTACTED + "/1000)"; - - /* - * See {@link ContactsProvider2#EMAIL_FILTER_SORT_ORDER} for the discussion of this - * sorting order. - */ - private static final String SORT_ORDER = - "(CASE WHEN contacts." + Contacts.STARRED + "=1 THEN 0 ELSE 1 END), " - + "(CASE WHEN " + TIME_SINCE_LAST_CONTACTED + " < " + CURRENT_CONTACTS + " THEN 0 " - + " WHEN " + TIME_SINCE_LAST_CONTACTED + " < " + RECENT_CONTACTS + " THEN 1 " - + " ELSE 2 END)," - + "contacts." + Contacts.TIMES_CONTACTED + " DESC, " - + "contacts." + Contacts.DISPLAY_NAME_PRIMARY + ", " - + "contacts." + Contacts._ID; - - private static final String RECENTLY_CONTACTED = - TIME_SINCE_LAST_CONTACTED + " < " + RECENT_CONTACTS; - private static class SearchSuggestion { long contactId; String photoUri; @@ -112,7 +82,7 @@ public class GlobalSearchSupport { String lastAccessTime; @SuppressWarnings({"unchecked"}) - public ArrayList asList(String[] projection) { + public ArrayList<?> asList(String[] projection) { if (icon1 == null) { if (photoUri != null) { icon1 = photoUri.toString(); @@ -192,24 +162,13 @@ public class GlobalSearchSupport { } private final ContactsProvider2 mContactsProvider; - private PhoneNumberUtil mPhoneNumberUtil; - private CountryDetector mCountryDetector; - private String mSimCountryIso; @SuppressWarnings("all") public GlobalSearchSupport(ContactsProvider2 contactsProvider) { mContactsProvider = contactsProvider; - mPhoneNumberUtil = PhoneNumberUtil.getInstance(); - mCountryDetector = (CountryDetector) - mContactsProvider.getContext().getSystemService(Context.COUNTRY_DETECTOR); TelephonyManager telman = (TelephonyManager) mContactsProvider.getContext().getSystemService(Context.TELEPHONY_SERVICE); - // assuming here that the SIM never changes while the phone is booted. ok? - mSimCountryIso = telman == null ? null : telman.getSimCountryIso(); - if (mSimCountryIso != null) { - mSimCountryIso = mSimCountryIso.toUpperCase(); - } // To ensure the data column position. This is dead code if properly configured. if (Organization.COMPANY != Data.DATA1 || Phone.NUMBER != Data.DATA1 @@ -219,54 +178,20 @@ public class GlobalSearchSupport { } } - private boolean isPossibleByPhoneNumberUtil(String query) { - String currentCountry = null; - Country current = mCountryDetector.detectCountry(); - if (current != null) { - currentCountry = current.getCountryIso().toUpperCase(); - } - if (currentCountry != null && mPhoneNumberUtil.isPossibleNumber(query, currentCountry)) { - return true; - } - if (mSimCountryIso != null && !TextUtils.equals(currentCountry, mSimCountryIso)) { - // use the SIM country if it's different, so we can add contacts for home numbers - // while roaming - return mPhoneNumberUtil.isPossibleNumber(query, mSimCountryIso); - } - return false; - } - - private boolean isPhoneNumber(String query) { - if (TextUtils.isEmpty(query)) { - return false; - } - if (ContactsProvider2.countPhoneNumberDigits(query) > 2) { - // 3 or more digits matching the basic pattern - return true; - } - // more advanced check, for 1800-FLOWERS style numbers and the like - return isPossibleByPhoneNumberUtil(query); - } - public Cursor handleSearchSuggestionsQuery( SQLiteDatabase db, Uri uri, String[] projection, String limit) { - final String searchClause; + final MatrixCursor cursor = new MatrixCursor( + projection == null ? SEARCH_SUGGESTIONS_COLUMNS : projection); - final String selection; if (uri.getPathSegments().size() <= 1) { - searchClause = null; - selection = RECENTLY_CONTACTED; + // no search term, return empty } else { - searchClause = uri.getLastPathSegment(); - selection = null; + String selection = null; + String searchClause = uri.getLastPathSegment(); + addSearchSuggestionsBasedOnFilter( + cursor, db, projection, selection, searchClause, limit); } - MatrixCursor cursor = new MatrixCursor( - projection == null ? SEARCH_SUGGESTIONS_COLUMNS : projection); - addSearchSuggestionsBasedOnFilter(cursor, db, projection, selection, searchClause, limit); - if (isPhoneNumber(searchClause)) { - addSearchSuggestionsBasedOnPhoneNumber(cursor, searchClause, projection); - } return cursor; } @@ -294,53 +219,6 @@ public class GlobalSearchSupport { db, projection, ContactsColumns.CONCRETE_ID + "=" + contactId, filter, null); } - private Cursor addSearchSuggestionsBasedOnPhoneNumber(MatrixCursor cursor, - String searchClause, String[] projection) { - Resources r = mContactsProvider.getContext().getResources(); - String s; - int i; - - if (mContactsProvider.isPhone() && mContactsProvider.isVoiceCapable()) { - SearchSuggestion dialNumber = new SearchSuggestion(); - dialNumber.contactId = -1; - s = r.getString(com.android.internal.R.string.dial_number_using, searchClause); - i = s.indexOf('\n'); - if (i < 0) { - dialNumber.text1 = s; - dialNumber.text2 = ""; - } else { - dialNumber.text1 = s.substring(0, i); - dialNumber.text2 = s.substring(i + 1); - } - dialNumber.icon1 = String.valueOf(com.android.internal.R.drawable.call_contact); - dialNumber.intentData = "tel:" + searchClause; - dialNumber.intentAction = - ContactsContract.Intents.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED; - dialNumber.lookupKey = SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT; // shortcut id - cursor.addRow(dialNumber.asList(projection)); - } - - SearchSuggestion createContact = new SearchSuggestion(); - createContact.contactId = -2; - s = r.getString(com.android.internal.R.string.create_contact_using, searchClause); - i = s.indexOf('\n'); - if (i < 0) { - createContact.text1 = s; - createContact.text2 = ""; - } else { - createContact.text1 = s.substring(0, i); - createContact.text2 = s.substring(i + 1); - } - createContact.icon1 = String.valueOf(com.android.internal.R.drawable.create_contact); - createContact.intentData = "tel:" + searchClause; - createContact.intentAction = - ContactsContract.Intents.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED; - createContact.lookupKey = SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT; // shortcut id - cursor.addRow(createContact.asList(projection)); - - return cursor; - } - private Cursor addSearchSuggestionsBasedOnFilter(MatrixCursor cursor, SQLiteDatabase db, String[] projection, String selection, String filter, String limit) { StringBuilder sb = new StringBuilder(); @@ -366,7 +244,6 @@ public class GlobalSearchSupport { if (selection != null) { sb.append(" WHERE ").append(selection); } - sb.append(" ORDER BY " + SORT_ORDER); if (limit != null) { sb.append(" LIMIT " + limit); } diff --git a/tests/src/com/android/providers/contacts/GlobalSearchSupportTest.java b/tests/src/com/android/providers/contacts/GlobalSearchSupportTest.java index 3c95c110..c7761095 100644 --- a/tests/src/com/android/providers/contacts/GlobalSearchSupportTest.java +++ b/tests/src/com/android/providers/contacts/GlobalSearchSupportTest.java @@ -113,8 +113,7 @@ public class GlobalSearchSupportTest extends BaseContactsProvider2Test { GoldenContact contact = new GoldenContactBuilder().name("Deer", "Dough").photo( loadTestPhoto()).phone("1-800-4664-411").build(); new SuggestionTesterBuilder(contact).query("1800").expectIcon1Uri(true).expectedText1( - "Deer Dough").expectedText2("1-800-4664-411").expectedCreateContactNumber("1800") - .build().test(); + "Deer Dough").expectedText2("1-800-4664-411").build().test(); } public void assertCreateContactSuggestion(Cursor c, String number) { @@ -131,42 +130,6 @@ public class GlobalSearchSupportTest extends BaseContactsProvider2Test { assertCursorValues(c, values); } - public void searchSuggestionsByPhoneNumberOnPhoneTest(String number) { - getContactsProvider().setIsPhone(true); - getContactsProvider().setIsVoiceCapable(true); - - ContentValues values = new ContentValues(); - - Uri searchUri = new Uri.Builder().scheme("content").authority(ContactsContract.AUTHORITY) - .appendPath(SearchManager.SUGGEST_URI_PATH_QUERY).appendPath(number).build(); - - Cursor c = mResolver.query(searchUri, null, null, null, null); - assertEquals(2, c.getCount()); - c.moveToFirst(); - values.put(SearchManager.SUGGEST_COLUMN_TEXT_1, "Dial number"); - values.put(SearchManager.SUGGEST_COLUMN_TEXT_2, "using " + number); - values.put(SearchManager.SUGGEST_COLUMN_ICON_1, - String.valueOf(com.android.internal.R.drawable.call_contact)); - values.put(SearchManager.SUGGEST_COLUMN_INTENT_ACTION, - Intents.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED); - values.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA, "tel:" + number); - values.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, - SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT); - assertCursorValues(c, values); - - c.moveToNext(); - assertCreateContactSuggestion(c, number); - c.close(); - } - - public void testSearchSuggestionsByPhoneNumberOnPhone() throws Exception { - searchSuggestionsByPhoneNumberOnPhoneTest("12345678"); - } - - public void testSearchSuggestionsByAlphnumericPhoneNumberOnPhone() throws Exception { - searchSuggestionsByPhoneNumberOnPhoneTest("1800-flowers"); - } - /** * Tests that the quick search suggestion returns the expected contact * information. @@ -185,8 +148,6 @@ public class GlobalSearchSupportTest extends BaseContactsProvider2Test { private final String expectedText2; - private final String expectedCreateContactNumber; - public SuggestionTester(SuggestionTesterBuilder builder) { contact = builder.contact; query = builder.query; @@ -194,7 +155,6 @@ public class GlobalSearchSupportTest extends BaseContactsProvider2Test { expectedIcon2 = builder.expectedIcon2; expectedText1 = builder.expectedText1; expectedText2 = builder.expectedText2; - expectedCreateContactNumber = builder.expectedCreateContactNumber; } /** @@ -222,7 +182,7 @@ public class GlobalSearchSupportTest extends BaseContactsProvider2Test { .appendPath(query).build(); Cursor c = mResolver.query(searchUri, null, null, null, null); - assertEquals(expectedCreateContactNumber == null ? 1 : 2, c.getCount()); + assertEquals(1, c.getCount()); c.moveToFirst(); String icon1 = c.getString(c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_1)); @@ -237,11 +197,6 @@ public class GlobalSearchSupportTest extends BaseContactsProvider2Test { ContentValues values = getContactValues(); assertCursorValues(c, values); - if (expectedCreateContactNumber != null) { - c.moveToNext(); - assertCreateContactSuggestion(c, expectedCreateContactNumber); - } - c.close(); } @@ -360,8 +315,6 @@ public class GlobalSearchSupportTest extends BaseContactsProvider2Test { private String expectedText2; - private String expectedCreateContactNumber; - public SuggestionTesterBuilder(GoldenContact contact) { this.contact = contact; } @@ -418,10 +371,5 @@ public class GlobalSearchSupportTest extends BaseContactsProvider2Test { expectedText2 = value; return this; } - - public SuggestionTesterBuilder expectedCreateContactNumber(String number) { - expectedCreateContactNumber = number; - return this; - } } } |