From 60101c9f298e69ee2b5ee5f67943515aae79b187 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 11 Apr 2019 19:04:00 -0700 Subject: [PATCH] Make lifecycle events for bubble activity views report normally There are some extra onPause / onResume events in ActivityView due to SysUI calling startActivity in onActivityViewReady which happens a bit before the display being turned on. This CL posts the startActivity call which is enough to avoid the extra lifecycle events. This CL also adds new method on ActivityView to startActivity with your own ActivityOptions (because posting causes activity transition to occur...) Test: manual - have Bubbles test APK - create a new bubble - adb logcat | grep "BubbleActivity" - observe the logging to make sure lifecycle events behave normally Bug: 130363466 Change-Id: Ia44d6033e5cff625222006632b7bdc4dc1e59e81 --- api/test-current.txt | 1 + core/java/android/app/ActivityView.java | 28 +++++++++++++++++++ .../systemui/bubbles/BubbleExpandedView.java | 7 ++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/api/test-current.txt b/api/test-current.txt index 63c8df047f902..6b0399b7b30eb 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -117,6 +117,7 @@ package android.app { method public void startActivity(@NonNull android.content.Intent); method public void startActivity(@NonNull android.content.Intent, android.os.UserHandle); method public void startActivity(@NonNull android.app.PendingIntent); + method public void startActivity(@NonNull android.app.PendingIntent, @NonNull android.app.ActivityOptions); } public abstract static class ActivityView.StateCallback { diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index 0ccaf62d45b28..fc6fffabc9171 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -254,6 +254,34 @@ public class ActivityView extends ViewGroup { } } + /** + * Launch a new activity into this container. + *

Activity resolved by the provided {@link PendingIntent} must have + * {@link android.R.attr#resizeableActivity} attribute set to {@code true} in order to be + * launched here. Also, if activity is not owned by the owner of this container, it must allow + * embedding and the caller must have permission to embed. + *

Note: This class must finish initializing and + * {@link StateCallback#onActivityViewReady(ActivityView)} callback must be triggered before + * this method can be called. + * + * @param pendingIntent Intent used to launch an activity. + * @param options options for the activity + * + * @see StateCallback + * @see #startActivity(Intent) + */ + public void startActivity(@NonNull PendingIntent pendingIntent, + @NonNull ActivityOptions options) { + options.setLaunchDisplayId(mVirtualDisplay.getDisplay().getDisplayId()); + try { + pendingIntent.send(null /* context */, 0 /* code */, null /* intent */, + null /* onFinished */, null /* handler */, null /* requiredPermission */, + options.toBundle()); + } catch (PendingIntent.CanceledException e) { + throw new RuntimeException(e); + } + } + /** * Check if container is ready to launch and create {@link ActivityOptions} to target the * virtual display. diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java index 63db3618f3e21..346660df7fb5c 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java @@ -25,6 +25,7 @@ import static android.view.Display.INVALID_DISPLAY; import android.animation.LayoutTransition; import android.animation.ObjectAnimator; import android.annotation.Nullable; +import android.app.ActivityOptions; import android.app.ActivityView; import android.app.INotificationManager; import android.app.Notification; @@ -121,7 +122,11 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList public void onActivityViewReady(ActivityView view) { if (!mActivityViewReady) { mActivityViewReady = true; - mActivityView.startActivity(mBubbleIntent); + // Custom options so there is no activity transition animation + ActivityOptions options = ActivityOptions.makeCustomAnimation(getContext(), + 0 /* enterResId */, 0 /* exitResId */); + // Post to keep the lifecycle normal + post(() -> mActivityView.startActivity(mBubbleIntent, options)); } }