summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/precall
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2018-02-02 17:06:23 -0800
committerCopybara-Service <copybara-piper@google.com>2018-02-02 17:30:50 -0800
commit9232b28859f16b0ca1fe285b4dd3589d6a3dcbbc (patch)
treeef9576290bde650b0f32e416f4db472334e64c9e /java/com/android/dialer/precall
parenta792792df68ef0fecad8056a1709cacbe0f474ac (diff)
Exit early when phone_lookup returned duplicated results for Preferred SIM
Previously all results are validated then checked if there are duplicate. In this CL once duplicates are found it will exit early. Bug: 72873001 Test: Existing unit tests. No behavior changes except query counts and latency which we don't test. PiperOrigin-RevId: 184355913 Change-Id: I5ef89c25b100752d939daba69fcfeca3c9d32521
Diffstat (limited to 'java/com/android/dialer/precall')
-rw-r--r--java/com/android/dialer/precall/impl/CallingAccountSelector.java25
1 files changed, 11 insertions, 14 deletions
diff --git a/java/com/android/dialer/precall/impl/CallingAccountSelector.java b/java/com/android/dialer/precall/impl/CallingAccountSelector.java
index 8d7d75952..f014b270b 100644
--- a/java/com/android/dialer/precall/impl/CallingAccountSelector.java
+++ b/java/com/android/dialer/precall/impl/CallingAccountSelector.java
@@ -38,7 +38,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
-import android.support.v4.util.ArraySet;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
@@ -67,7 +66,6 @@ import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
/** PreCallAction to select which phone account to call with. Ignored if there's only one account */
@SuppressWarnings("MissingPermission")
@@ -353,24 +351,23 @@ public class CallingAccountSelector implements PreCallAction {
return Optional.absent();
}
ImmutableSet<String> validAccountTypes = PreferredAccountUtil.getValidAccountTypes(context);
- Set<String> result = new ArraySet<>();
+ String result = null;
while (cursor.moveToNext()) {
Optional<String> accountType =
getAccountType(context.getContentResolver(), cursor.getLong(0));
- if (accountType.isPresent() && validAccountTypes.contains(accountType.get())) {
- result.add(cursor.getString(0));
- } else {
+ if (!accountType.isPresent() || !validAccountTypes.contains(accountType.get())) {
LogUtil.i("CallingAccountSelector.getDataId", "ignoring non-writable " + accountType);
+ continue;
}
+ if (result != null && !result.equals(cursor.getString(0))) {
+ // TODO(twyen): if there are multiple entries attempt to grab from the contact that
+ // initiated the call.
+ LogUtil.i("CallingAccountSelector.getDataId", "lookup result not unique, ignoring");
+ return Optional.absent();
+ }
+ result = cursor.getString(0);
}
- // TODO(twyen): if there are multiples attempt to grab from the contact that initiated the
- // call.
- if (result.size() == 1) {
- return Optional.of(result.iterator().next());
- } else {
- LogUtil.i("CallingAccountSelector.getDataId", "lookup result not unique, ignoring");
- return Optional.absent();
- }
+ return Optional.fromNullable(result);
}
}