From 47aa39c7ea423722254b5a70b50dc6c1513b9ee5 Mon Sep 17 00:00:00 2001 From: zachh Date: Mon, 4 Dec 2017 17:26:05 -0800 Subject: Added PhoneLookupSelector. This class is responsible for prioritizing and selecting data from a PhoneLookupInfo object, which contains information from many phone lookup sources. Bug: 34672501 Test: unit PiperOrigin-RevId: 177893924 Change-Id: Ib98a4656fe87141162a7ac53af4a0ad421196046 --- .../phonelookup/PhoneLookupDataSource.java | 7 +--- .../dialer/phonelookup/PhoneLookupSelector.java | 47 ++++++++++++++++++++++ .../composite/CompositePhoneLookup.java | 2 + 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 java/com/android/dialer/phonelookup/PhoneLookupSelector.java (limited to 'java') diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java index 7a7f2070b..010cb8541 100644 --- a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java +++ b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java @@ -31,6 +31,7 @@ import com.android.dialer.calllog.datasources.CallLogMutations; import com.android.dialer.common.LogUtil; import com.android.dialer.phonelookup.PhoneLookup; import com.android.dialer.phonelookup.PhoneLookupInfo; +import com.android.dialer.phonelookup.PhoneLookupSelector; import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.google.common.collect.ImmutableMap; @@ -376,11 +377,7 @@ public final class PhoneLookupDataSource implements CallLogDataSource { } } - // TODO(zachh): Extract this logic into a proper selection class or package. private static String selectName(PhoneLookupInfo phoneLookupInfo) { - if (phoneLookupInfo.getCp2Info().getCp2ContactInfoCount() > 0) { - return phoneLookupInfo.getCp2Info().getCp2ContactInfo(0).getName(); - } - return ""; + return PhoneLookupSelector.selectName(phoneLookupInfo); } } diff --git a/java/com/android/dialer/phonelookup/PhoneLookupSelector.java b/java/com/android/dialer/phonelookup/PhoneLookupSelector.java new file mode 100644 index 000000000..a746ea44f --- /dev/null +++ b/java/com/android/dialer/phonelookup/PhoneLookupSelector.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package com.android.dialer.phonelookup; + +import android.support.annotation.NonNull; + +/** + * Prioritizes information from a {@link PhoneLookupInfo}. + * + *

For example, a single {@link PhoneLookupInfo} may contain different name information from many + * different {@link PhoneLookup} sources. This class defines the rules for deciding which name + * should be selected for display to the user, by prioritizing the data from some {@link PhoneLookup + * PhoneLookups} over others. + * + *

Note that the logic in this class may be highly coupled with the logic in {@code + * CompositePhoneLookup}, because {@code CompositePhoneLookup} may also include prioritization logic + * for short-circuiting low-priority {@link PhoneLookup PhoneLookups}. + */ +public final class PhoneLookupSelector { + + /** + * Select the name associated with this number. Examples of this are a local contact's name or a + * business name received from caller ID. + */ + @NonNull + public static String selectName(PhoneLookupInfo phoneLookupInfo) { + if (phoneLookupInfo.getCp2Info().getCp2ContactInfoCount() > 0) { + // Arbitrarily select the first contact's name. In the future, it may make sense to join the + // names such as "Mom, Dad" in the case that multiple contacts share the same number. + return phoneLookupInfo.getCp2Info().getCp2ContactInfo(0).getName(); + } + return ""; + } +} diff --git a/java/com/android/dialer/phonelookup/composite/CompositePhoneLookup.java b/java/com/android/dialer/phonelookup/composite/CompositePhoneLookup.java index 520c46f9e..f432e27ae 100644 --- a/java/com/android/dialer/phonelookup/composite/CompositePhoneLookup.java +++ b/java/com/android/dialer/phonelookup/composite/CompositePhoneLookup.java @@ -53,6 +53,8 @@ public final class CompositePhoneLookup implements PhoneLookup { */ @Override public ListenableFuture lookup(@NonNull Call call) { + // TODO(zachh): Add short-circuiting logic so that this call is not blocked on low-priority + // lookups finishing when a higher-priority one has already finished. List> futures = new ArrayList<>(); for (PhoneLookup phoneLookup : phoneLookups) { futures.add(phoneLookup.lookup(call)); -- cgit v1.2.3