From 055cdbf0c558792ae6c455d798a7a9281aa09ac9 Mon Sep 17 00:00:00 2001 From: yueg Date: Fri, 22 Jun 2018 14:48:20 -0700 Subject: Remove suggestion from NUI favorite Test: manual PiperOrigin-RevId: 201745094 Change-Id: I7ba7b0d8063f056f0c5edb44c7649a1c807f6549 --- .../speeddial/loader/SpeedDialUiItemMutator.java | 74 +++++++--------------- 1 file changed, 24 insertions(+), 50 deletions(-) diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java index 998793e6e..72f0a68c6 100644 --- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java +++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItemMutator.java @@ -16,14 +16,12 @@ package com.android.dialer.speeddial.loader; -import android.annotation.TargetApi; import android.content.ContentProviderOperation; import android.content.ContentValues; import android.content.Context; import android.content.OperationApplicationException; import android.database.Cursor; import android.net.Uri; -import android.os.Build.VERSION_CODES; import android.os.RemoteException; import android.os.Trace; import android.provider.ContactsContract; @@ -40,7 +38,6 @@ import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.common.concurrent.DialerExecutor.SuccessListener; import com.android.dialer.common.concurrent.DialerFutureSerializer; import com.android.dialer.common.database.Selection; -import com.android.dialer.duo.Duo; import com.android.dialer.duo.DuoComponent; import com.android.dialer.inject.ApplicationContext; import com.android.dialer.speeddial.database.SpeedDialEntry; @@ -72,21 +69,17 @@ import javax.inject.Singleton; *
  • Remove any {@link SpeedDialEntry} that is no longer starred or whose contact was * deleted. *
  • Update each {@link SpeedDialEntry} contact id, lookup key and channel. - *
  • Build a list of {@link SpeedDialUiItem} from {@link Contacts#STREQUENT_PHONE_ONLY}. - *
  • If any starred contacts in that list aren't in the {@link - * SpeedDialEntryDatabaseHelper}, insert them now. + *
  • Build a list of {@link SpeedDialUiItem} from starred contacts. + *
  • If any contacts in that list aren't in the {@link SpeedDialEntryDatabaseHelper}, insert + * them now. *
  • Notify the {@link SuccessListener} of the complete list of {@link SpeedDialUiItem * SpeedDialContacts} composed from {@link SpeedDialEntry SpeedDialEntries} and * non-starred {@link Contacts#STREQUENT_PHONE_ONLY}. * */ -@SuppressWarnings("AndroidApiChecker") -@TargetApi(VERSION_CODES.N) @Singleton public final class SpeedDialUiItemMutator { - private static final int MAX_DUO_SUGGESTIONS = 3; - private final Context appContext; private final ListeningExecutorService backgroundExecutor; // Used to ensure that only one refresh flow runs at a time. @@ -104,8 +97,7 @@ public final class SpeedDialUiItemMutator { /** * Returns a {@link ListenableFuture} for a list of {@link SpeedDialUiItem SpeedDialUiItems}. This - * list is composed of starred contacts from {@link SpeedDialEntryDatabaseHelper} and suggestions - * from {@link Contacts#STREQUENT_PHONE_ONLY}. + * list is composed of starred contacts from {@link SpeedDialEntryDatabaseHelper}. */ public ListenableFuture> loadSpeedDialUiItems() { return dialerFutureSerializer.submit(this::loadSpeedDialUiItemsInternal, backgroundExecutor); @@ -117,8 +109,7 @@ public final class SpeedDialUiItemMutator { *

    If the item is starred, it's entry will be removed from the SpeedDialEntry database. * Additionally, if the contact only has one entry in the database, it will be unstarred. * - *

    If the item isn't starred, it's usage data will be deleted but the suggestion can come back - * if the user calls that contact again. + *

    If the item isn't starred, it's usage data will be deleted. * * @return the updated list of SpeedDialUiItems. */ @@ -281,27 +272,19 @@ public final class SpeedDialUiItemMutator { } Trace.endSection(); // updateOrDeleteEntries - // Get all Strequent Contacts - List strequentContacts = getStrequentContacts(); - - // For each contact, if it isn't starred, add it as a suggestion. + // Get all starred contacts + List starredContacts = getStarredContacts(); // If it is starred and not already accounted for above, then insert into the SpeedDialEntry DB. - Trace.beginSection("addSuggestions"); - for (SpeedDialUiItem contact : strequentContacts) { - if (!contact.isStarred()) { - // Add this contact as a suggestion - // TODO(77754534): improve suggestions beyond just first channel - speedDialUiItems.add( - contact.toBuilder().setDefaultChannel(contact.channels().get(0)).build()); - - } else if (speedDialUiItems.stream().noneMatch(c -> c.contactId() == contact.contactId())) { + Trace.beginSection("addStarredContact"); + for (SpeedDialUiItem contact : starredContacts) { + if (speedDialUiItems.stream().noneMatch(c -> c.contactId() == contact.contactId())) { entriesToInsert.add(contact.buildSpeedDialEntry()); // These are our newly starred contacts speedDialUiItems.add(contact); } } - Trace.endSection(); // addSuggestions + Trace.endSection(); // addStarredContact Trace.beginSection("insertUpdateAndDelete"); ImmutableMap insertedEntriesToIdsMap = @@ -339,7 +322,7 @@ public final class SpeedDialUiItemMutator { } // Starred contacts that aren't in the map, should already have speed dial entry ids. - // Non-starred contacts (suggestions) aren't in the speed dial entry database, so they + // Non-starred contacts aren't in the speed dial entry database, so they // shouldn't have speed dial entry ids. Assert.checkArgument( speedDialUiItem.isStarred() == (speedDialUiItem.speedDialEntryId() != null), @@ -485,23 +468,29 @@ public final class SpeedDialUiItemMutator { } @WorkerThread - private List getStrequentContacts() { + private List getStarredContacts() { Trace.beginSection("getStrequentContacts"); Assert.isWorkerThread(); Set contactIds = new ArraySet<>(); - // Fetch the contact ids of all strequent contacts + // Fetch the contact ids of all starred contacts Uri strequentUri = Contacts.CONTENT_STREQUENT_URI .buildUpon() .appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true") .build(); + Selection selection = Selection.column(Phone.STARRED).is("=", 1); try (Cursor cursor = appContext .getContentResolver() - .query(strequentUri, new String[] {Phone.CONTACT_ID}, null, null, null)) { + .query( + strequentUri, + new String[] {Phone.CONTACT_ID}, + selection.getSelection(), + selection.getSelectionArgs(), + null)) { if (cursor == null) { - LogUtil.e("SpeedDialUiItemMutator.getStrequentContacts", "null cursor"); + LogUtil.e("SpeedDialUiItemMutator.getStarredContacts", "null cursor"); Trace.endSection(); return new ArrayList<>(); } @@ -515,8 +504,7 @@ public final class SpeedDialUiItemMutator { } // Build SpeedDialUiItems from those contact ids - Selection selection = - Selection.builder().and(Selection.column(Phone.CONTACT_ID).in(contactIds)).build(); + selection = Selection.builder().and(Selection.column(Phone.CONTACT_ID).in(contactIds)).build(); try (Cursor cursor = appContext .getContentResolver() @@ -624,24 +612,10 @@ public final class SpeedDialUiItemMutator { Context context, ImmutableList speedDialUiItems) { Assert.isMainThread(); - Duo duo = DuoComponent.get(context).getDuo(); - int maxDuoSuggestions = MAX_DUO_SUGGESTIONS; - ImmutableList.Builder newSpeedDialItemList = ImmutableList.builder(); // for each existing item for (SpeedDialUiItem item : speedDialUiItems) { - // If the item is a suggestion - if (!item.isStarred()) { - // And duo reachable, insert a duo suggestion - if (maxDuoSuggestions > 0 && duo.isReachable(context, item.defaultChannel().number())) { - maxDuoSuggestions--; - Channel defaultChannel = - item.defaultChannel().toBuilder().setTechnology(Channel.DUO).build(); - newSpeedDialItemList.add(item.toBuilder().setDefaultChannel(defaultChannel).build()); - } - // Insert the voice suggestion too - newSpeedDialItemList.add(item); - } else if (item.defaultChannel() == null) { + if (item.defaultChannel() == null) { // If the contact is starred and doesn't have a default channel, insert duo channels newSpeedDialItemList.add(insertDuoChannelsToStarredContact(context, item)); } else { -- cgit v1.2.3