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

Commit 0508c7f4 authored by Ikram Gabiyev's avatar Ikram Gabiyev
Browse files

[PiP2] [2/2] Start with a non-null pip params

We need to make sure PiP params are not null when
swiping home to PiP as well. This is because a client can
call into enterPictureInPictureMode() with an empty PiP params
which Core's fillTaskInfo() will resolve as a null pip params.

So always operate on a non-null PictureInPictureParams to avoid NPE.

Do the same for expand animation too, when querying cached params.

Bug: 376141728
Flag: com.android.wm.shell.enable_pip2
Test: swipe-pip-to-home with an invalid src-rect-hint
Change-Id: I7bb1158bd0593788a1e1514f538c0a433841ad61
parent 777bbee0
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -371,7 +371,9 @@ public class PipTransition extends PipTransitionController implements

        // Update the src-rect-hint in params in place, to set up initial animator transform.
        Rect sourceRectHint = getAdjustedSourceRectHint(info, pipChange, pipActivityChange);
        pipChange.getTaskInfo().pictureInPictureParams.getSourceRectHint().set(sourceRectHint);
        final PictureInPictureParams params = getPipParams(pipChange);
        params.copyOnlySet(
                new PictureInPictureParams.Builder().setSourceRectHint(sourceRectHint).build());

        // Config-at-end transitions need to have their activities transformed before starting
        // the animation; this makes the buffer seem like it's been updated to final size.
@@ -416,9 +418,7 @@ public class PipTransition extends PipTransitionController implements
        final SurfaceControl pipLeash = getLeash(pipChange);
        final Rect startBounds = pipChange.getStartAbsBounds();
        final Rect endBounds = pipChange.getEndAbsBounds();
        final PictureInPictureParams params = pipChange.getTaskInfo().pictureInPictureParams != null
                ? pipChange.getTaskInfo().pictureInPictureParams
                : new PictureInPictureParams.Builder().build();
        final PictureInPictureParams params = getPipParams(pipChange);
        final Rect adjustedSourceRectHint = getAdjustedSourceRectHint(info, pipChange,
                pipActivityChange);

@@ -598,10 +598,10 @@ public class PipTransition extends PipTransitionController implements
        PictureInPictureParams params = null;
        if (pipChange.getTaskInfo() != null) {
            // single activity
            params = pipChange.getTaskInfo().pictureInPictureParams;
            params = getPipParams(pipChange);
        } else if (parentBeforePip != null && parentBeforePip.getTaskInfo() != null) {
            // multi activity
            params = parentBeforePip.getTaskInfo().pictureInPictureParams;
            params = getPipParams(parentBeforePip);
        }
        final Rect sourceRectHint = PipBoundsAlgorithm.getValidSourceHintRect(params, endBounds,
                startBounds);
@@ -842,19 +842,25 @@ public class PipTransition extends PipTransitionController implements
                    initActivityPos.y);
        }
    }
    void cacheAndStartTransitionAnimator(@NonNull ValueAnimator animator) {
        mTransitionAnimator = animator;
        mTransitionAnimator.start();
    }

    @NonNull
    private static PictureInPictureParams getPipParams(@NonNull TransitionInfo.Change pipChange) {
        return pipChange.getTaskInfo().pictureInPictureParams != null
                ? pipChange.getTaskInfo().pictureInPictureParams
                : new PictureInPictureParams.Builder().build();
    }

    @NonNull
    private SurfaceControl getLeash(TransitionInfo.Change change) {
    private static SurfaceControl getLeash(TransitionInfo.Change change) {
        SurfaceControl leash = change.getLeash();
        Preconditions.checkNotNull(leash, "Leash is null for change=" + change);
        return leash;
    }

    void cacheAndStartTransitionAnimator(@NonNull ValueAnimator animator) {
        mTransitionAnimator = animator;
        mTransitionAnimator.start();
    }

    //
    // Miscellaneous callbacks and listeners
    //