Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60101c9f authored by Mady Mellor's avatar Mady Mellor
Browse files

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
parent 5acc2403
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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 {
+28 −0
Original line number Diff line number Diff line
@@ -254,6 +254,34 @@ public class ActivityView extends ViewGroup {
        }
    }

    /**
     * Launch a new activity into this container.
     * <p>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.
     * <p>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.
+6 −1
Original line number Diff line number Diff line
@@ -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));
            }
        }