From 47e19fb8f2e58ca5dba0da77a4ca2c0ebe848d90 Mon Sep 17 00:00:00 2001 From: yueg Date: Tue, 15 Aug 2017 10:17:51 -0700 Subject: Rewrite bubble logging to remove dependency. Instead of logging expansion and return to call in Bubble.java, add a listener for expansion and send intent with extra package name for return to call. This allows other team to use bubble. Test: BubbleTest PiperOrigin-RevId: 165323455 Change-Id: I6e996dbf6c0849612b8bb69e33f8540db20985be --- .../android/dialer/logging/dialer_impression.proto | 3 ++ java/com/android/dialershared/bubble/Bubble.java | 36 +++++++++++++++++++--- java/com/android/incallui/InCallActivity.java | 10 ++++++ .../android/incallui/ReturnToCallController.java | 31 +++++++++++++++++-- java/com/android/incallui/StatusBarNotifier.java | 8 ++--- 5 files changed, 77 insertions(+), 11 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/logging/dialer_impression.proto b/java/com/android/dialer/logging/dialer_impression.proto index b02c82b57..02dd0cb64 100644 --- a/java/com/android/dialer/logging/dialer_impression.proto +++ b/java/com/android/dialer/logging/dialer_impression.proto @@ -516,5 +516,8 @@ message DialerImpression { VVM_TRANSCRIPTION_RESPONSE_EXPIRED = 1257; VVM_TRANSCRIPTION_RESPONSE_TOO_MANY_ERRORS = 1258; VVM_TRANSCRIPTION_POLLING_TIMEOUT = 1259; + + // Bubble collapse initiated by user, i.e. no hiding after collapse + BUBBLE_COLLAPSE_BY_USER = 1260; } } diff --git a/java/com/android/dialershared/bubble/Bubble.java b/java/com/android/dialershared/bubble/Bubble.java index 9606f5be6..cd2c9fc57 100644 --- a/java/com/android/dialershared/bubble/Bubble.java +++ b/java/com/android/dialershared/bubble/Bubble.java @@ -61,8 +61,6 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; import android.widget.ViewAnimator; -import com.android.dialer.logging.DialerImpression; -import com.android.dialer.logging.Logger; import com.android.dialershared.bubble.BubbleInfo.Action; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -109,6 +107,8 @@ public class Bubble { private Integer overrideGravity; private ViewPropertyAnimator exitAnimator; + private BubbleExpansionStateListener bubbleExpansionStateListener; + @Retention(RetentionPolicy.SOURCE) @IntDef({CollapseEnd.NOTHING, CollapseEnd.HIDE}) private @interface CollapseEnd { @@ -125,6 +125,15 @@ public class Bubble { int EXITING = 3; } + /** Indicate bubble expansion state. */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ExpansionState.START_EXPANDING, ExpansionState.START_COLLAPSING}) + public @interface ExpansionState { + // TODO(yueg): add more states when needed + int START_EXPANDING = 0; + int START_COLLAPSING = 1; + } + /** * Determines whether bubbles can be shown based on permissions obtained. This should be checked * before attempting to create a Bubble. @@ -170,6 +179,11 @@ public class Bubble { Bubble.bubbleFactory = bubbleFactory; } + @VisibleForTesting + public static void resetBubbleFactory() { + Bubble.bubbleFactory = Bubble::new; + } + @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) Bubble(@NonNull Context context) { context = new ContextThemeWrapper(context, R.style.Theme_AppCompat); @@ -371,6 +385,11 @@ public class Bubble { SHOW_TEXT_DURATION_MILLIS); } + public void setBubbleExpansionStateListener( + BubbleExpansionStateListener bubbleExpansionStateListener) { + this.bubbleExpansionStateListener = bubbleExpansionStateListener; + } + @Nullable Integer getGravityOverride() { return overrideGravity; @@ -396,7 +415,6 @@ public class Bubble { void primaryButtonClick() { if (expanded || textShowing || currentInfo.getActions().isEmpty()) { - Logger.get(context).logImpression(DialerImpression.Type.BUBBLE_PRIMARY_BUTTON_RETURN_TO_CALL); try { currentInfo.getPrimaryIntent().send(); } catch (CanceledException e) { @@ -405,7 +423,9 @@ public class Bubble { return; } - Logger.get(context).logImpression(DialerImpression.Type.BUBBLE_PRIMARY_BUTTON_EXPAND); + if (bubbleExpansionStateListener != null) { + bubbleExpansionStateListener.onBubbleExpansionStateChanged(ExpansionState.START_EXPANDING); + } doResize( () -> { onLeftRightSwitch(isDrawingFromRight()); @@ -657,6 +677,9 @@ public class Bubble { if (collapseEndAction == CollapseEnd.NOTHING) { collapseEndAction = endAction; } + if (bubbleExpansionStateListener != null && collapseEndAction == CollapseEnd.NOTHING) { + bubbleExpansionStateListener.onBubbleExpansionStateChanged(ExpansionState.START_COLLAPSING); + } collapseAnimation = expandedView .animate() @@ -848,4 +871,9 @@ public class Bubble { moveHandler.undoGravityOverride(); } } + + /** Listener for bubble expansion state change. */ + public interface BubbleExpansionStateListener { + void onBubbleExpansionStateChanged(@ExpansionState int expansionState); + } } diff --git a/java/com/android/incallui/InCallActivity.java b/java/com/android/incallui/InCallActivity.java index 3ea2b176f..90f532a95 100644 --- a/java/com/android/incallui/InCallActivity.java +++ b/java/com/android/incallui/InCallActivity.java @@ -38,6 +38,7 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.compat.ActivityCompat; import com.android.dialer.configprovider.ConfigProviderBindings; +import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; import com.android.dialer.logging.ScreenEvent; import com.android.incallui.answer.bindings.AnswerBindings; @@ -68,6 +69,10 @@ public class InCallActivity extends TransactionSafeFragmentActivity VideoCallScreenDelegateFactory, PseudoScreenState.StateChangedListener { + public static final int PENDING_INTENT_REQUEST_CODE_NON_FULL_SCREEN = 0; + public static final int PENDING_INTENT_REQUEST_CODE_FULL_SCREEN = 1; + public static final int PENDING_INTENT_REQUEST_CODE_BUBBLE = 2; + private static final String TAG_IN_CALL_SCREEN = "tag_in_call_screen"; private static final String TAG_ANSWER_SCREEN = "tag_answer_screen"; private static final String TAG_VIDEO_CALL_SCREEN = "tag_video_call_screen"; @@ -117,6 +122,11 @@ public class InCallActivity extends TransactionSafeFragmentActivity LogUtil.i("InCallActivity.onCreate", ""); super.onCreate(icicle); + if (getIntent().getBooleanExtra(ReturnToCallController.RETURN_TO_CALL_EXTRA_KEY, false)) { + Logger.get(this).logImpression(DialerImpression.Type.BUBBLE_PRIMARY_BUTTON_RETURN_TO_CALL); + getIntent().removeExtra(ReturnToCallController.RETURN_TO_CALL_EXTRA_KEY); + } + if (icicle != null) { didShowAnswerScreen = icicle.getBoolean(DID_SHOW_ANSWER_SCREEN_KEY); didShowInCallScreen = icicle.getBoolean(DID_SHOW_IN_CALL_SCREEN_KEY); diff --git a/java/com/android/incallui/ReturnToCallController.java b/java/com/android/incallui/ReturnToCallController.java index b0baface4..39a07235c 100644 --- a/java/com/android/incallui/ReturnToCallController.java +++ b/java/com/android/incallui/ReturnToCallController.java @@ -25,8 +25,12 @@ import android.support.annotation.VisibleForTesting; import android.telecom.CallAudioState; import com.android.dialer.common.LogUtil; import com.android.dialer.configprovider.ConfigProviderBindings; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; import com.android.dialer.telecom.TelecomUtil; import com.android.dialershared.bubble.Bubble; +import com.android.dialershared.bubble.Bubble.BubbleExpansionStateListener; +import com.android.dialershared.bubble.Bubble.ExpansionState; import com.android.dialershared.bubble.BubbleInfo; import com.android.dialershared.bubble.BubbleInfo.Action; import com.android.incallui.InCallPresenter.InCallUiListener; @@ -46,6 +50,8 @@ import java.util.List; */ public class ReturnToCallController implements InCallUiListener, Listener, AudioModeListener { + public static final String RETURN_TO_CALL_EXTRA_KEY = "RETURN_TO_CALL_BUBBLE"; + private final Context context; @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @@ -118,12 +124,30 @@ public class ReturnToCallController implements InCallUiListener, Listener, Audio } } - private Bubble startNewBubble() { + @VisibleForTesting + public Bubble startNewBubble() { if (!Bubble.canShowBubbles(context)) { LogUtil.i("ReturnToCallController.startNewBubble", "can't show bubble, no permission"); return null; } Bubble returnToCallBubble = Bubble.createBubble(context, generateBubbleInfo()); + returnToCallBubble.setBubbleExpansionStateListener( + new BubbleExpansionStateListener() { + @Override + public void onBubbleExpansionStateChanged(@ExpansionState int expansionState) { + switch (expansionState) { + case ExpansionState.START_EXPANDING: + Logger.get(context) + .logImpression(DialerImpression.Type.BUBBLE_PRIMARY_BUTTON_EXPAND); + break; + case ExpansionState.START_COLLAPSING: + Logger.get(context).logImpression(DialerImpression.Type.BUBBLE_COLLAPSE_BY_USER); + break; + default: + break; + } + } + }); returnToCallBubble.show(); return returnToCallBubble; } @@ -182,12 +206,15 @@ public class ReturnToCallController implements InCallUiListener, Listener, Audio private BubbleInfo generateBubbleInfo() { Intent activityIntent = InCallActivity.getIntent(context, false, false, false); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activityIntent.putExtra(RETURN_TO_CALL_EXTRA_KEY, true); return BubbleInfo.builder() .setPrimaryColor(context.getResources().getColor(R.color.dialer_theme_color, null)) .setPrimaryIcon(Icon.createWithResource(context, R.drawable.on_going_call)) .setStartingYPosition( context.getResources().getDimensionPixelOffset(R.dimen.return_to_call_initial_offset_y)) - .setPrimaryIntent(PendingIntent.getActivity(context, 0, activityIntent, 0)) + .setPrimaryIntent( + PendingIntent.getActivity( + context, InCallActivity.PENDING_INTENT_REQUEST_CODE_BUBBLE, activityIntent, 0)) .setActions(generateActions()) .build(); } diff --git a/java/com/android/incallui/StatusBarNotifier.java b/java/com/android/incallui/StatusBarNotifier.java index d20c62f4b..5e2cc61d3 100644 --- a/java/com/android/incallui/StatusBarNotifier.java +++ b/java/com/android/incallui/StatusBarNotifier.java @@ -107,9 +107,6 @@ public class StatusBarNotifier // This is non-interruptive, but otherwise behaves the same as NOTIFICATION_INCOMING_CALL private static final int NOTIFICATION_INCOMING_CALL_QUIET = 3; - private static final int PENDING_INTENT_REQUEST_CODE_NON_FULL_SCREEN = 0; - private static final int PENDING_INTENT_REQUEST_CODE_FULL_SCREEN = 1; - private static final long[] VIBRATE_PATTERN = new long[] {0, 1000, 1000}; private final Context mContext; @@ -390,6 +387,7 @@ public class StatusBarNotifier builder.setChannelId(NotificationChannelId.ONGOING_CALL); } break; + default: // fall out } // Set the content @@ -945,11 +943,11 @@ public class StatusBarNotifier InCallActivity.getIntent( mContext, false /* showDialpad */, false /* newOutgoingCall */, isFullScreen); - int requestCode = PENDING_INTENT_REQUEST_CODE_NON_FULL_SCREEN; + int requestCode = InCallActivity.PENDING_INTENT_REQUEST_CODE_NON_FULL_SCREEN; if (isFullScreen) { // Use a unique request code so that the pending intent isn't clobbered by the // non-full screen pending intent. - requestCode = PENDING_INTENT_REQUEST_CODE_FULL_SCREEN; + requestCode = InCallActivity.PENDING_INTENT_REQUEST_CODE_FULL_SCREEN; } // PendingIntent that can be used to launch the InCallActivity. The -- cgit v1.2.3