From b87334b303f63cca464dd6c99ff8d9fb89e1ca28 Mon Sep 17 00:00:00 2001 From: maxwelb Date: Mon, 14 May 2018 13:57:32 -0700 Subject: Update DialerCall to use SpamStatus instead of booleans Test: Tap PiperOrigin-RevId: 196562314 Change-Id: Ie90a5ad183d4fb65ff512ea158a8687fe1f77963 --- .../dialer/spam/status/SimpleSpamStatus.java | 28 +++++++-- java/com/android/incallui/call/CallList.java | 69 +--------------------- java/com/android/incallui/call/DialerCall.java | 59 +++++++++--------- 3 files changed, 51 insertions(+), 105 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/spam/status/SimpleSpamStatus.java b/java/com/android/dialer/spam/status/SimpleSpamStatus.java index ff080ed1d..5f45c1a4f 100644 --- a/java/com/android/dialer/spam/status/SimpleSpamStatus.java +++ b/java/com/android/dialer/spam/status/SimpleSpamStatus.java @@ -26,7 +26,11 @@ public abstract class SimpleSpamStatus implements SpamStatus { /** Returns a SimpleSpamStatus with the given boolean and timestamp. */ public static SimpleSpamStatus create(boolean isSpam, @Nullable Long timestampMillis) { - return new AutoValue_SimpleSpamStatus(isSpam, Optional.fromNullable(timestampMillis)); + return builder() + .setSpam(isSpam) + .setTimestampMillis(timestampMillis) + .setSpamMetadata(SpamMetadata.empty()) + .build(); } /** Returns a SimpleSpamStatus that's not marked as spam and has no timestamp. */ @@ -34,9 +38,23 @@ public abstract class SimpleSpamStatus implements SpamStatus { return create(false, null); } - /** Returns an empty {@link SpamMetadata}. */ - @Override - public final SpamMetadata getSpamMetadata() { - return SpamMetadata.empty(); + public static Builder builder() { + return new AutoValue_SimpleSpamStatus.Builder(); + } + + /** Creates instances of SimpleSpamStatus. */ + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder setSpam(boolean isSpam); + + abstract Builder setTimestampMillis(Optional timestamp); + + public Builder setTimestampMillis(@Nullable Long timestampMillis) { + return setTimestampMillis(Optional.fromNullable(timestampMillis)); + } + + public abstract Builder setSpamMetadata(SpamMetadata spamMetadata); + + public abstract SimpleSpamStatus build(); } } diff --git a/java/com/android/incallui/call/CallList.java b/java/com/android/incallui/call/CallList.java index 13be252dd..6940f7d6c 100644 --- a/java/com/android/incallui/call/CallList.java +++ b/java/com/android/incallui/call/CallList.java @@ -23,13 +23,11 @@ import android.os.Trace; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; -import android.support.v4.os.BuildCompat; import android.telecom.Call; import android.telecom.DisconnectCause; import android.telecom.PhoneAccount; import android.util.ArrayMap; import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; -import com.android.dialer.blocking.FilteredNumbersUtil; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutorComponent; @@ -41,7 +39,6 @@ import com.android.dialer.metrics.Metrics; import com.android.dialer.metrics.MetricsComponent; import com.android.dialer.promotion.RttPromotion; import com.android.dialer.shortcuts.ShortcutUsageReporter; -import com.android.dialer.spam.Spam; import com.android.dialer.spam.SpamComponent; import com.android.dialer.spam.status.SpamStatus; import com.android.dialer.telecom.TelecomCallUtil; @@ -164,20 +161,7 @@ public class CallList implements DialerCallDelegate { call.getState() == DialerCallState.INCOMING || call.getState() == DialerCallState.CALL_WAITING; boolean isSpam = result.isSpam(); - if (isSpam) { - if (!isIncomingCall) { - LogUtil.i( - "CallList.onCallAdded", - "marking spam call as not spam because it's not an incoming call"); - isSpam = false; - } else if (isPotentialEmergencyCallback(context, call)) { - LogUtil.i( - "CallList.onCallAdded", - "marking spam call as not spam because an emergency call was made on this" - + " device recently"); - isSpam = false; - } - } + call.setSpamStatus(result); if (isIncomingCall) { Logger.get(context) @@ -188,7 +172,6 @@ public class CallList implements DialerCallDelegate { call.getUniqueCallId(), call.getTimeAddedMs()); } - call.setSpam(isSpam); onUpdateCall(call); notifyGenericListeners(); } @@ -201,7 +184,6 @@ public class CallList implements DialerCallDelegate { DialerExecutorComponent.get(context).uiExecutor()); Trace.beginSection("updateUserMarkedSpamStatus"); - updateUserMarkedSpamStatus(call, context, number); Trace.endSection(); } Trace.endSection(); @@ -279,60 +261,11 @@ public class CallList implements DialerCallDelegate { impression, incomingCall.getUniqueCallId(), incomingCall.getTimeAddedMs()); } - private static boolean isPotentialEmergencyCallback(Context context, DialerCall call) { - if (BuildCompat.isAtLeastO()) { - return call.isPotentialEmergencyCallback(); - } else { - long timestampMillis = FilteredNumbersUtil.getLastEmergencyCallTimeMillis(context); - return call.isInEmergencyCallbackWindow(timestampMillis); - } - } - @Override public DialerCall getDialerCallFromTelecomCall(Call telecomCall) { return callByTelecomCall.get(telecomCall); } - private void updateUserMarkedSpamStatus( - final DialerCall call, final Context context, String number) { - - SpamComponent.get(context) - .spam() - .checkUserMarkedNonSpamStatus( - number, - call.getCountryIso(), - new Spam.Listener() { - @Override - public void onComplete(boolean isInUserWhiteList) { - call.setIsInUserWhiteList(isInUserWhiteList); - } - }); - - SpamComponent.get(context) - .spam() - .checkGlobalSpamListStatus( - number, - call.getCountryIso(), - new Spam.Listener() { - @Override - public void onComplete(boolean isInGlobalSpamList) { - call.setIsInGlobalSpamList(isInGlobalSpamList); - } - }); - - SpamComponent.get(context) - .spam() - .checkUserMarkedSpamStatus( - number, - call.getCountryIso(), - new Spam.Listener() { - @Override - public void onComplete(boolean isInUserSpamList) { - call.setIsInUserSpamList(isInUserSpamList); - } - }); - } - public void onCallRemoved(Context context, android.telecom.Call telecomCall) { if (callByTelecomCall.containsKey(telecomCall)) { DialerCall call = callByTelecomCall.get(telecomCall); diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java index 431634a0c..da7c54d27 100644 --- a/java/com/android/incallui/call/DialerCall.java +++ b/java/com/android/incallui/call/DialerCall.java @@ -52,6 +52,7 @@ import android.widget.Toast; import com.android.contacts.common.compat.CallCompat; import com.android.dialer.assisteddialing.ConcreteCreator; import com.android.dialer.assisteddialing.TransformationInfo; +import com.android.dialer.blocking.FilteredNumbersUtil; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentParser; import com.android.dialer.callintent.CallSpecificAppData; @@ -76,6 +77,7 @@ import com.android.dialer.logging.Logger; import com.android.dialer.preferredsim.PreferredAccountRecorder; import com.android.dialer.rtt.RttTranscript; import com.android.dialer.rtt.RttTranscriptUtil; +import com.android.dialer.spam.status.SpamStatus; import com.android.dialer.telecom.TelecomCallUtil; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.theme.R; @@ -91,6 +93,7 @@ import com.android.incallui.videotech.duo.DuoVideoTech; import com.android.incallui.videotech.empty.EmptyVideoTech; import com.android.incallui.videotech.ims.ImsVideoTech; import com.android.incallui.videotech.utils.VideoUtils; +import com.google.common.base.Optional; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import java.io.IOException; @@ -165,14 +168,10 @@ public class DialerCall implements VideoTechListener, StateChangedListener, Capa private String callSubject; @Nullable private PhoneAccountHandle phoneAccountHandle; @CallHistoryStatus private int callHistoryStatus = CALL_HISTORY_STATUS_UNKNOWN; - private boolean isSpam; - private boolean isBlocked; - - @Nullable private Boolean isInUserSpamList; - @Nullable private Boolean isInUserWhiteList; + @Nullable private SpamStatus spamStatus; + private boolean isBlocked; - @Nullable private Boolean isInGlobalSpamList; private boolean didShowCameraPermission; private boolean didDismissVideoChargesAlertDialog; private PersistableBundle carrierConfig; @@ -820,6 +819,13 @@ public class DialerCall implements VideoTechListener, StateChangedListener, Capa if (hasProperty(Details.PROPERTY_EMERGENCY_CALLBACK_MODE)) { return true; } + + // Call.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS is available starting in O + if (VERSION.SDK_INT < VERSION_CODES.O) { + long timestampMillis = FilteredNumbersUtil.getLastEmergencyCallTimeMillis(context); + return isInEmergencyCallbackWindow(timestampMillis); + } + // We want to treat any incoming call that arrives a short time after an outgoing emergency call // as a potential emergency callback. if (getExtras() != null @@ -1270,39 +1276,28 @@ public class DialerCall implements VideoTechListener, StateChangedListener, Capa didDismissVideoChargesAlertDialog = didDismiss; } - @Nullable - public Boolean isInGlobalSpamList() { - return isInGlobalSpamList; - } - - public void setIsInGlobalSpamList(boolean inSpamList) { - isInGlobalSpamList = inSpamList; - } - - @Nullable - public Boolean isInUserSpamList() { - return isInUserSpamList; + public void setSpamStatus(@Nullable SpamStatus spamStatus) { + this.spamStatus = spamStatus; } - public void setIsInUserSpamList(boolean inSpamList) { - isInUserSpamList = inSpamList; + public Optional getSpamStatus() { + return Optional.fromNullable(spamStatus); } - @Nullable - public Boolean isInUserWhiteList() { - return isInUserWhiteList; - } + public boolean isSpam() { + if (spamStatus == null || !spamStatus.isSpam()) { + return false; + } - public void setIsInUserWhiteList(boolean inWhiteList) { - isInUserWhiteList = inWhiteList; - } + if (!isIncoming()) { + return false; + } - public boolean isSpam() { - return isSpam; - } + if (isPotentialEmergencyCallback()) { + return false; + } - public void setSpam(boolean isSpam) { - this.isSpam = isSpam; + return true; } public boolean isBlocked() { -- cgit v1.2.3