From 2ca4318cc1ee57dda907ba2069bd61d162b1baef Mon Sep 17 00:00:00 2001 From: Eric Erfanian Date: Thu, 31 Aug 2017 06:57:16 -0700 Subject: Update Dialer source to latest internal Google revision. Previously, Android's Dialer app was developed in an internal Google source control system and only exported to public during AOSP drops. The Dialer team is now switching to a public development model similar to the telephony team. This CL represents all internal Google changes that were committed to Dialer between the public O release and today's tip of tree on internal master. This CL squashes those changes into a single commit. In subsequent changes, changes will be exported on a per-commit basis. Test: make, flash install, run Merged-In: I45270eaa8ce732d71a1bd84b08c7fa0e99af3160 Change-Id: I529aaeb88535b9533c0ae4ef4e6c1222d4e0f1c8 PiperOrigin-RevId: 167068436 --- .../enrichedcall/EnrichedCallCapabilities.java | 53 ++++++++-- .../dialer/enrichedcall/EnrichedCallManager.java | 76 +++++++++----- .../enrichedcall/FuzzyPhoneNumberMatcher.java | 50 ++++++++-- java/com/android/dialer/enrichedcall/Session.java | 25 ++++- .../enrichedcall/extensions/StateExtension.java | 18 ++-- .../historyquery/proto/history_result.proto | 1 + .../enrichedcall/simulator/AndroidManifest.xml | 26 +++++ .../simulator/EnrichedCallSimulatorActivity.java | 110 +++++++++++++++++++++ .../enrichedcall/simulator/SessionViewHolder.java | 37 +++++++ .../enrichedcall/simulator/SessionsAdapter.java | 51 ++++++++++ .../layout/enriched_call_simulator_activity.xml | 38 +++++++ .../simulator/res/layout/session_view_holder.xml | 23 +++++ .../simulator/res/values-af/strings.xml | 20 ++++ .../simulator/res/values-am/strings.xml | 20 ++++ .../simulator/res/values-ar/strings.xml | 20 ++++ .../simulator/res/values-az/strings.xml | 20 ++++ .../simulator/res/values-b+sr+Latn/strings.xml | 20 ++++ .../simulator/res/values-be/strings.xml | 20 ++++ .../simulator/res/values-bg/strings.xml | 20 ++++ .../simulator/res/values-bn/strings.xml | 20 ++++ .../simulator/res/values-bs/strings.xml | 20 ++++ .../simulator/res/values-ca/strings.xml | 20 ++++ .../simulator/res/values-cs/strings.xml | 20 ++++ .../simulator/res/values-da/strings.xml | 20 ++++ .../simulator/res/values-de/strings.xml | 20 ++++ .../simulator/res/values-el/strings.xml | 20 ++++ .../simulator/res/values-en-rAU/strings.xml | 20 ++++ .../simulator/res/values-en-rGB/strings.xml | 20 ++++ .../simulator/res/values-en-rIN/strings.xml | 20 ++++ .../simulator/res/values-es-rUS/strings.xml | 20 ++++ .../simulator/res/values-es/strings.xml | 20 ++++ .../simulator/res/values-et/strings.xml | 20 ++++ .../simulator/res/values-eu/strings.xml | 20 ++++ .../simulator/res/values-fa/strings.xml | 20 ++++ .../simulator/res/values-fi/strings.xml | 20 ++++ .../simulator/res/values-fr-rCA/strings.xml | 20 ++++ .../simulator/res/values-fr/strings.xml | 20 ++++ .../simulator/res/values-gl/strings.xml | 20 ++++ .../simulator/res/values-gu/strings.xml | 20 ++++ .../simulator/res/values-hi/strings.xml | 20 ++++ .../simulator/res/values-hr/strings.xml | 20 ++++ .../simulator/res/values-hu/strings.xml | 20 ++++ .../simulator/res/values-hy/strings.xml | 20 ++++ .../simulator/res/values-in/strings.xml | 20 ++++ .../simulator/res/values-is/strings.xml | 20 ++++ .../simulator/res/values-it/strings.xml | 20 ++++ .../simulator/res/values-iw/strings.xml | 20 ++++ .../simulator/res/values-ja/strings.xml | 20 ++++ .../simulator/res/values-ka/strings.xml | 20 ++++ .../simulator/res/values-kk/strings.xml | 20 ++++ .../simulator/res/values-km/strings.xml | 20 ++++ .../simulator/res/values-kn/strings.xml | 20 ++++ .../simulator/res/values-ko/strings.xml | 20 ++++ .../simulator/res/values-ky/strings.xml | 20 ++++ .../simulator/res/values-lo/strings.xml | 20 ++++ .../simulator/res/values-lt/strings.xml | 20 ++++ .../simulator/res/values-lv/strings.xml | 20 ++++ .../simulator/res/values-mk/strings.xml | 20 ++++ .../simulator/res/values-ml/strings.xml | 20 ++++ .../simulator/res/values-mn/strings.xml | 20 ++++ .../simulator/res/values-mr/strings.xml | 20 ++++ .../simulator/res/values-ms/strings.xml | 20 ++++ .../simulator/res/values-my/strings.xml | 20 ++++ .../simulator/res/values-nb/strings.xml | 20 ++++ .../simulator/res/values-ne/strings.xml | 20 ++++ .../simulator/res/values-nl/strings.xml | 20 ++++ .../simulator/res/values-no/strings.xml | 20 ++++ .../simulator/res/values-pa/strings.xml | 20 ++++ .../simulator/res/values-pl/strings.xml | 20 ++++ .../simulator/res/values-pt-rBR/strings.xml | 20 ++++ .../simulator/res/values-pt-rPT/strings.xml | 20 ++++ .../simulator/res/values-pt/strings.xml | 20 ++++ .../simulator/res/values-ro/strings.xml | 20 ++++ .../simulator/res/values-ru/strings.xml | 20 ++++ .../simulator/res/values-si/strings.xml | 20 ++++ .../simulator/res/values-sk/strings.xml | 20 ++++ .../simulator/res/values-sl/strings.xml | 20 ++++ .../simulator/res/values-sq/strings.xml | 20 ++++ .../simulator/res/values-sr/strings.xml | 20 ++++ .../simulator/res/values-sv/strings.xml | 20 ++++ .../simulator/res/values-sw/strings.xml | 20 ++++ .../simulator/res/values-ta/strings.xml | 20 ++++ .../simulator/res/values-te/strings.xml | 20 ++++ .../simulator/res/values-th/strings.xml | 20 ++++ .../simulator/res/values-tl/strings.xml | 20 ++++ .../simulator/res/values-tr/strings.xml | 20 ++++ .../simulator/res/values-uk/strings.xml | 20 ++++ .../simulator/res/values-ur/strings.xml | 20 ++++ .../simulator/res/values-uz/strings.xml | 20 ++++ .../simulator/res/values-vi/strings.xml | 20 ++++ .../simulator/res/values-zh-rCN/strings.xml | 20 ++++ .../simulator/res/values-zh-rHK/strings.xml | 20 ++++ .../simulator/res/values-zh-rTW/strings.xml | 20 ++++ .../simulator/res/values-zu/strings.xml | 20 ++++ .../enrichedcall/simulator/res/values/strings.xml | 21 ++++ .../enrichedcall/stub/EnrichedCallManagerStub.java | 32 ++++++ .../videoshare/VideoShareListener.java | 1 + .../enrichedcall/videoshare/VideoShareSession.java | 39 ++++++++ 98 files changed, 2187 insertions(+), 54 deletions(-) create mode 100644 java/com/android/dialer/enrichedcall/simulator/AndroidManifest.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/EnrichedCallSimulatorActivity.java create mode 100644 java/com/android/dialer/enrichedcall/simulator/SessionViewHolder.java create mode 100644 java/com/android/dialer/enrichedcall/simulator/SessionsAdapter.java create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/layout/enriched_call_simulator_activity.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/layout/session_view_holder.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-af/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-am/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ar/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-az/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-b+sr+Latn/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-be/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-bg/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-bn/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-bs/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ca/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-cs/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-da/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-de/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-el/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-en-rAU/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-en-rGB/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-en-rIN/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-es-rUS/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-es/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-et/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-eu/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-fa/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-fi/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-fr-rCA/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-fr/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-gl/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-gu/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-hi/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-hr/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-hu/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-hy/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-in/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-is/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-it/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-iw/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ja/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ka/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-kk/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-km/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-kn/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ko/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ky/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-lo/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-lt/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-lv/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-mk/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ml/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-mn/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-mr/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ms/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-my/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-nb/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ne/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-nl/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-no/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-pa/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-pl/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-pt-rBR/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-pt-rPT/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-pt/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ro/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ru/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-si/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-sk/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-sl/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-sq/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-sr/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-sv/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-sw/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ta/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-te/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-th/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-tl/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-tr/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-uk/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-ur/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-uz/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-vi/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-zh-rCN/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-zh-rHK/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-zh-rTW/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values-zu/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/simulator/res/values/strings.xml create mode 100644 java/com/android/dialer/enrichedcall/videoshare/VideoShareSession.java (limited to 'java/com/android/dialer/enrichedcall') diff --git a/java/com/android/dialer/enrichedcall/EnrichedCallCapabilities.java b/java/com/android/dialer/enrichedcall/EnrichedCallCapabilities.java index c3c78c9c8..32054e8d1 100644 --- a/java/com/android/dialer/enrichedcall/EnrichedCallCapabilities.java +++ b/java/com/android/dialer/enrichedcall/EnrichedCallCapabilities.java @@ -22,18 +22,53 @@ import com.google.auto.value.AutoValue; @AutoValue public abstract class EnrichedCallCapabilities { - public static final EnrichedCallCapabilities NO_CAPABILITIES = - EnrichedCallCapabilities.create(false, false, false); + public static final EnrichedCallCapabilities NO_CAPABILITIES = builder().build(); - public static EnrichedCallCapabilities create( - boolean supportsCallComposer, boolean supportsPostCall, boolean supportsVideoCall) { - return new AutoValue_EnrichedCallCapabilities( - supportsCallComposer, supportsPostCall, supportsVideoCall); + public static final EnrichedCallCapabilities ALL_CAPABILITIES = + builder() + .setCallComposerCapable(true) + .setPostCallCapable(true) + .setVideoShareCapable(true) + .build(); + + public abstract boolean isCallComposerCapable(); + + public abstract boolean isPostCallCapable(); + + public abstract boolean isVideoShareCapable(); + + public abstract Builder toBuilder(); + + /** + * Returns {@code true} if these capabilities represent those of a user that is temporarily + * unavailable. This is an indication that capabilities should be refreshed. + */ + public abstract boolean isTemporarilyUnavailable(); + + /** + * Creates an instance of {@link Builder}. + * + *

Unless otherwise set, all fields will default to false. + */ + public static Builder builder() { + return new AutoValue_EnrichedCallCapabilities.Builder() + .setCallComposerCapable(false) + .setPostCallCapable(false) + .setVideoShareCapable(false) + .setTemporarilyUnavailable(false); } - public abstract boolean supportsCallComposer(); + /** Creates instances of {@link EnrichedCallCapabilities}. */ + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder setCallComposerCapable(boolean isCapable); + + public abstract Builder setPostCallCapable(boolean isCapable); - public abstract boolean supportsPostCall(); + public abstract Builder setVideoShareCapable(boolean isCapable); - public abstract boolean supportsVideoShare(); + public abstract Builder setTemporarilyUnavailable(boolean temporarilyUnavailable); + + public abstract EnrichedCallCapabilities build(); + } } diff --git a/java/com/android/dialer/enrichedcall/EnrichedCallManager.java b/java/com/android/dialer/enrichedcall/EnrichedCallManager.java index 0d3ed9e43..0606a00e5 100644 --- a/java/com/android/dialer/enrichedcall/EnrichedCallManager.java +++ b/java/com/android/dialer/enrichedcall/EnrichedCallManager.java @@ -16,7 +16,6 @@ package com.android.dialer.enrichedcall; -import android.support.annotation.IntDef; import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -24,9 +23,8 @@ import com.android.dialer.calldetails.CallDetailsEntries; import com.android.dialer.calldetails.CallDetailsEntries.CallDetailsEntry; import com.android.dialer.enrichedcall.historyquery.proto.HistoryResult; import com.android.dialer.enrichedcall.videoshare.VideoShareListener; +import com.android.dialer.enrichedcall.videoshare.VideoShareSession; import com.android.dialer.multimedia.MultimediaData; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.util.List; import java.util.Map; @@ -81,27 +79,6 @@ public interface EnrichedCallManager { @MainThread void clearCachedData(); - /** Possible states for call composer sessions. */ - @Retention(RetentionPolicy.SOURCE) - @IntDef({ - STATE_NONE, - STATE_STARTING, - STATE_STARTED, - STATE_START_FAILED, - STATE_MESSAGE_SENT, - STATE_MESSAGE_FAILED, - STATE_CLOSED, - }) - @interface State {} - - int STATE_NONE = 0; - int STATE_STARTING = STATE_NONE + 1; - int STATE_STARTED = STATE_STARTING + 1; - int STATE_START_FAILED = STATE_STARTED + 1; - int STATE_MESSAGE_SENT = STATE_START_FAILED + 1; - int STATE_MESSAGE_FAILED = STATE_MESSAGE_SENT + 1; - int STATE_CLOSED = STATE_MESSAGE_FAILED + 1; - /** * Starts a call composer session with the given remote number. * @@ -119,7 +96,7 @@ public interface EnrichedCallManager { * @param sessionId the id for the session. See {@link #startCallComposerSession(String)} * @param data the {@link MultimediaData} * @throws IllegalArgumentException if there's no open session with the given number - * @throws IllegalStateException if the session isn't in the {@link #STATE_STARTED} state + * @throws IllegalStateException if the session isn't in the {@link Session#STATE_STARTED} state */ @MainThread void sendCallComposerData(long sessionId, @NonNull MultimediaData data); @@ -185,12 +162,49 @@ public interface EnrichedCallManager { @Nullable Session getSession(long sessionId); + /** + * Returns a list containing viewable string representations of all existing sessions. + * + *

Intended for debug display purposes only. + */ + @MainThread + @NonNull + List getAllSessionsForDisplay(); + @NonNull Filter createIncomingCallComposerFilter(); @NonNull Filter createOutgoingCallComposerFilter(); + /** Receives updates when the state of an historical data changes. */ + interface HistoricalDataChangedListener { + + /** + * Callback fired when historical data changes. Listeners should call {@link + * #getAllHistoricalData(String, CallDetailsEntries)} to retrieve the new data. + */ + void onHistoricalDataChanged(); + } + + /** + * Registers the given {@link HistoricalDataChangedListener}. + * + *

As a result of this method, the listener will receive updates when the state of any enriched + * call historical data changes. + */ + @MainThread + void registerHistoricalDataChangedListener(@NonNull HistoricalDataChangedListener listener); + + /** + * Unregisters the given {@link HistoricalDataChangedListener}. + * + *

As a result of this method, the listener will not receive updates when the state of enriched + * call historical data changes. + */ + @MainThread + void unregisterHistoricalDataChangedListener(@NonNull HistoricalDataChangedListener listener); + /** * Starts an asynchronous process to get all historical data for the given number and set of * {@link CallDetailsEntries}. @@ -212,6 +226,10 @@ public interface EnrichedCallManager { Map> getAllHistoricalData( @NonNull String number, @NonNull CallDetailsEntries entries); + /** Returns true if any enriched calls have been made or received. */ + @MainThread + boolean hasStoredData(); + /** * Unregisters the given {@link StateChangedListener}. * @@ -309,6 +327,14 @@ public interface EnrichedCallManager { @MainThread long getVideoShareInviteSessionId(@NonNull String number); + /** + * Returns the {@link VideoShareSession} for the given sessionId, or {@code null} if no session + * exists. + */ + @MainThread + @Nullable + VideoShareSession getVideoShareSession(long sessionId); + /** * Ends the given video share session. * diff --git a/java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java b/java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java index 250c64313..6f4d97521 100644 --- a/java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java +++ b/java/com/android/dialer/enrichedcall/FuzzyPhoneNumberMatcher.java @@ -16,20 +16,50 @@ package com.android.dialer.enrichedcall; import android.support.annotation.NonNull; -import com.android.dialer.common.Assert; /** Utility for comparing phone numbers. */ public class FuzzyPhoneNumberMatcher { - /** Returns {@code true} if the given numbers can be interpreted to be the same. */ - public static boolean matches(@NonNull String a, @NonNull String b) { - String aNormalized = Assert.isNotNull(a).replaceAll("[^0-9]", ""); - String bNormalized = Assert.isNotNull(b).replaceAll("[^0-9]", ""); - if (aNormalized.length() < 7 || bNormalized.length() < 7) { - return false; + private static final int REQUIRED_MATCHED_DIGITS = 7; + + /** + * Returns {@code true} if the given numbers can be interpreted to be the same. + * + *

This method is called numerous times when rendering the call log. Using string methods is + * too slow, so character by character matching is used instead. + */ + public static boolean matches(@NonNull String lhs, @NonNull String rhs) { + return lastSevenDigitsCharacterByCharacterMatches(lhs, rhs); + } + + /** + * This strategy examines the numbers character by character starting from the end. If the last + * {@link #REQUIRED_MATCHED_DIGITS} match, it returns {@code true}. + */ + private static boolean lastSevenDigitsCharacterByCharacterMatches( + @NonNull String lhs, @NonNull String rhs) { + int lhsIndex = lhs.length() - 1; + int rhsIndex = rhs.length() - 1; + + int matchedDigits = 0; + + while (lhsIndex >= 0 && rhsIndex >= 0) { + if (!Character.isDigit(lhs.charAt(lhsIndex))) { + --lhsIndex; + continue; + } + if (!Character.isDigit(rhs.charAt(rhsIndex))) { + --rhsIndex; + continue; + } + if (lhs.charAt(lhsIndex) != rhs.charAt(rhsIndex)) { + break; + } + --lhsIndex; + --rhsIndex; + ++matchedDigits; } - String aMatchable = aNormalized.substring(aNormalized.length() - 7); - String bMatchable = bNormalized.substring(bNormalized.length() - 7); - return aMatchable.equals(bMatchable); + + return matchedDigits >= REQUIRED_MATCHED_DIGITS; } } diff --git a/java/com/android/dialer/enrichedcall/Session.java b/java/com/android/dialer/enrichedcall/Session.java index b3f291438..06837e399 100644 --- a/java/com/android/dialer/enrichedcall/Session.java +++ b/java/com/android/dialer/enrichedcall/Session.java @@ -16,14 +16,37 @@ package com.android.dialer.enrichedcall; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import com.android.dialer.enrichedcall.EnrichedCallManager.State; import com.android.dialer.multimedia.MultimediaData; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; /** Holds state information and data about enriched calling sessions. */ public interface Session { + /** Possible states for call composer sessions. */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ + STATE_NONE, + STATE_STARTING, + STATE_STARTED, + STATE_START_FAILED, + STATE_MESSAGE_SENT, + STATE_MESSAGE_FAILED, + STATE_CLOSED, + }) + @interface State {} + + int STATE_NONE = 0; + int STATE_STARTING = STATE_NONE + 1; + int STATE_STARTED = STATE_STARTING + 1; + int STATE_START_FAILED = STATE_STARTED + 1; + int STATE_MESSAGE_SENT = STATE_START_FAILED + 1; + int STATE_MESSAGE_FAILED = STATE_MESSAGE_SENT + 1; + int STATE_CLOSED = STATE_MESSAGE_FAILED + 1; + /** Id used for sessions that fail to start. */ long NO_SESSION_ID = -1; diff --git a/java/com/android/dialer/enrichedcall/extensions/StateExtension.java b/java/com/android/dialer/enrichedcall/extensions/StateExtension.java index 8a4f6409d..5d90829c3 100644 --- a/java/com/android/dialer/enrichedcall/extensions/StateExtension.java +++ b/java/com/android/dialer/enrichedcall/extensions/StateExtension.java @@ -18,8 +18,8 @@ package com.android.dialer.enrichedcall.extensions; import android.support.annotation.NonNull; import com.android.dialer.common.Assert; -import com.android.dialer.enrichedcall.EnrichedCallManager; -import com.android.dialer.enrichedcall.EnrichedCallManager.State; +import com.android.dialer.enrichedcall.Session; +import com.android.dialer.enrichedcall.Session.State; /** Extends the {@link State} to include a toString method. */ public class StateExtension { @@ -27,25 +27,25 @@ public class StateExtension { /** Returns the string representation for the given {@link State}. */ @NonNull public static String toString(@State int callComposerState) { - if (callComposerState == EnrichedCallManager.STATE_NONE) { + if (callComposerState == Session.STATE_NONE) { return "STATE_NONE"; } - if (callComposerState == EnrichedCallManager.STATE_STARTING) { + if (callComposerState == Session.STATE_STARTING) { return "STATE_STARTING"; } - if (callComposerState == EnrichedCallManager.STATE_STARTED) { + if (callComposerState == Session.STATE_STARTED) { return "STATE_STARTED"; } - if (callComposerState == EnrichedCallManager.STATE_START_FAILED) { + if (callComposerState == Session.STATE_START_FAILED) { return "STATE_START_FAILED"; } - if (callComposerState == EnrichedCallManager.STATE_MESSAGE_SENT) { + if (callComposerState == Session.STATE_MESSAGE_SENT) { return "STATE_MESSAGE_SENT"; } - if (callComposerState == EnrichedCallManager.STATE_MESSAGE_FAILED) { + if (callComposerState == Session.STATE_MESSAGE_FAILED) { return "STATE_MESSAGE_FAILED"; } - if (callComposerState == EnrichedCallManager.STATE_CLOSED) { + if (callComposerState == Session.STATE_CLOSED) { return "STATE_CLOSED"; } Assert.checkArgument(false, "Unexpected callComposerState: %d", callComposerState); diff --git a/java/com/android/dialer/enrichedcall/historyquery/proto/history_result.proto b/java/com/android/dialer/enrichedcall/historyquery/proto/history_result.proto index 62d013a46..8efb35cc1 100644 --- a/java/com/android/dialer/enrichedcall/historyquery/proto/history_result.proto +++ b/java/com/android/dialer/enrichedcall/historyquery/proto/history_result.proto @@ -4,6 +4,7 @@ option java_package = "com.android.dialer.enrichedcall.historyquery.proto"; option java_multiple_files = true; option optimize_for = LITE_RUNTIME; + package com.android.dialer.enrichedcall.historyquery.proto; // Holds data that was used in an enrichedcall in the past diff --git a/java/com/android/dialer/enrichedcall/simulator/AndroidManifest.xml b/java/com/android/dialer/enrichedcall/simulator/AndroidManifest.xml new file mode 100644 index 000000000..003ff19d5 --- /dev/null +++ b/java/com/android/dialer/enrichedcall/simulator/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/java/com/android/dialer/enrichedcall/simulator/EnrichedCallSimulatorActivity.java b/java/com/android/dialer/enrichedcall/simulator/EnrichedCallSimulatorActivity.java new file mode 100644 index 000000000..bbc1ada6f --- /dev/null +++ b/java/com/android/dialer/enrichedcall/simulator/EnrichedCallSimulatorActivity.java @@ -0,0 +1,110 @@ +/* + * 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.enrichedcall.simulator; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.android.dialer.enrichedcall.EnrichedCallComponent; +import com.android.dialer.enrichedcall.EnrichedCallManager; +import com.android.dialer.enrichedcall.EnrichedCallManager.StateChangedListener; + +/** + * Activity used to display Enriched call sessions that are currently in memory, and create new + * outgoing sessions with various bits of data. + * + *

This activity will dynamically refresh as new sessions are added or updated, but there's no + * update when sessions are deleted from memory. Use the refresh button to update the view. + */ +public class EnrichedCallSimulatorActivity extends AppCompatActivity + implements StateChangedListener, OnClickListener { + + public static Intent newIntent(@NonNull Context context) { + return new Intent(Assert.isNotNull(context), EnrichedCallSimulatorActivity.class); + } + + private Button refreshButton; + + private SessionsAdapter sessionsAdapter; + + @Override + protected void onCreate(@Nullable Bundle bundle) { + LogUtil.enterBlock("EnrichedCallSimulatorActivity.onCreate"); + super.onCreate(bundle); + setContentView(R.layout.enriched_call_simulator_activity); + Toolbar toolbar = findViewById(R.id.toolbar); + toolbar.setTitle(R.string.enriched_call_simulator_activity); + + refreshButton = findViewById(R.id.refresh); + refreshButton.setOnClickListener(this); + + RecyclerView recyclerView = findViewById(R.id.sessions_recycler_view); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + + sessionsAdapter = new SessionsAdapter(); + sessionsAdapter.setSessionStrings(getEnrichedCallManager().getAllSessionsForDisplay()); + recyclerView.setAdapter(sessionsAdapter); + } + + @Override + protected void onResume() { + LogUtil.enterBlock("EnrichedCallSimulatorActivity.onResume"); + super.onResume(); + getEnrichedCallManager().registerStateChangedListener(this); + } + + @Override + protected void onPause() { + LogUtil.enterBlock("EnrichedCallSimulatorActivity.onPause"); + super.onPause(); + getEnrichedCallManager().unregisterStateChangedListener(this); + } + + @Override + public void onEnrichedCallStateChanged() { + LogUtil.enterBlock("EnrichedCallSimulatorActivity.onEnrichedCallStateChanged"); + refreshSessions(); + } + + @Override + public void onClick(View v) { + if (v == refreshButton) { + LogUtil.i("EnrichedCallSimulatorActivity.onClick", "refreshing sessions"); + refreshSessions(); + } + } + + private void refreshSessions() { + sessionsAdapter.setSessionStrings(getEnrichedCallManager().getAllSessionsForDisplay()); + sessionsAdapter.notifyDataSetChanged(); + } + + private EnrichedCallManager getEnrichedCallManager() { + return EnrichedCallComponent.get(this).getEnrichedCallManager(); + } +} diff --git a/java/com/android/dialer/enrichedcall/simulator/SessionViewHolder.java b/java/com/android/dialer/enrichedcall/simulator/SessionViewHolder.java new file mode 100644 index 000000000..44431253d --- /dev/null +++ b/java/com/android/dialer/enrichedcall/simulator/SessionViewHolder.java @@ -0,0 +1,37 @@ +/* + * 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.enrichedcall.simulator; + +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.TextView; + +/** ViewHolder for an Enriched call session. */ +class SessionViewHolder extends RecyclerView.ViewHolder { + + private final TextView sessionStringView; + + SessionViewHolder(View view) { + super(view); + sessionStringView = view.findViewById(R.id.session_string); + } + + void updateSession(@NonNull String sessionString) { + sessionStringView.setText(sessionString); + } +} diff --git a/java/com/android/dialer/enrichedcall/simulator/SessionsAdapter.java b/java/com/android/dialer/enrichedcall/simulator/SessionsAdapter.java new file mode 100644 index 000000000..25edfc7dd --- /dev/null +++ b/java/com/android/dialer/enrichedcall/simulator/SessionsAdapter.java @@ -0,0 +1,51 @@ +/* + * 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.enrichedcall.simulator; + +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.ViewGroup; +import com.android.dialer.common.Assert; +import java.util.List; + +/** Adapter for the RecyclerView in {@link EnrichedCallSimulatorActivity}. */ +class SessionsAdapter extends RecyclerView.Adapter { + + /** List of the string representation of all in-memory sessions */ + private List sessionStrings; + + void setSessionStrings(@NonNull List sessionStrings) { + this.sessionStrings = Assert.isNotNull(sessionStrings); + } + + @Override + public SessionViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { + LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext()); + return new SessionViewHolder(inflater.inflate(R.layout.session_view_holder, viewGroup, false)); + } + + @Override + public void onBindViewHolder(SessionViewHolder viewHolder, int i) { + viewHolder.updateSession(sessionStrings.get(i)); + } + + @Override + public int getItemCount() { + return sessionStrings.size(); + } +} diff --git a/java/com/android/dialer/enrichedcall/simulator/res/layout/enriched_call_simulator_activity.xml b/java/com/android/dialer/enrichedcall/simulator/res/layout/enriched_call_simulator_activity.xml new file mode 100644 index 000000000..be9aa7dea --- /dev/null +++ b/java/com/android/dialer/enrichedcall/simulator/res/layout/enriched_call_simulator_activity.xml @@ -0,0 +1,38 @@ + + + + + + + + +