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

Commit e07ac6c1 authored by Ikram Gabiyev's avatar Ikram Gabiyev
Browse files

Implement double tap CUJ in PiP2

Implement transitions flow of double tap CUJ in PiP2
(decoupled from the upcoming animator refactoring).
The "double tap" would be triggered via a broadcast intent
to decouple it from the upcoming PipTouchHandler v2 as well.
(current version of touch handler has certain legacy dependencies,
so it will most probably be reimplemented for PiP2)

Also moved PipDoubleTapHelper into the common package
since we will use it both for pip and pip2.

Bug: 321984612
Test: adb shell am broadcast \
	 -a com.android.wm.shell.pip2.phone.PipScheduler \
	 --ei cuj_code_extra 1
Change-Id: I185d32e5a8d2ad5217afa0eca93a7ca893b84129
parent 25bde8f1
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 * Copyright (C) 2024 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.
@@ -14,14 +14,12 @@
 * limitations under the License.
 */

package com.android.wm.shell.pip.phone;
package com.android.wm.shell.common.pip;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.graphics.Rect;

import com.android.wm.shell.common.pip.PipBoundsState;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@@ -50,9 +48,9 @@ public class PipDoubleTapHelper {
    @Retention(RetentionPolicy.SOURCE)
    @interface PipSizeSpec {}

    static final int SIZE_SPEC_DEFAULT = 0;
    static final int SIZE_SPEC_MAX = 1;
    static final int SIZE_SPEC_CUSTOM = 2;
    public static final int SIZE_SPEC_DEFAULT = 0;
    public static final int SIZE_SPEC_MAX = 1;
    public static final int SIZE_SPEC_CUSTOM = 2;

    /**
     * Returns MAX or DEFAULT {@link PipSizeSpec} to toggle to/from.
@@ -84,7 +82,7 @@ public class PipDoubleTapHelper {
     * @return pip screen size to switch to
     */
    @PipSizeSpec
    static int nextSizeSpec(@NonNull PipBoundsState mPipBoundsState,
    public static int nextSizeSpec(@NonNull PipBoundsState mPipBoundsState,
            @NonNull Rect userResizeBounds) {
        // is pip screen at its maximum
        boolean isScreenMax = mPipBoundsState.getBounds().width()
+4 −3
Original line number Diff line number Diff line
@@ -50,15 +50,16 @@ import java.util.Optional;
public abstract class Pip2Module {
    @WMSingleton
    @Provides
    static PipTransition providePipTransition(@NonNull ShellInit shellInit,
    static PipTransition providePipTransition(Context context,
            @NonNull ShellInit shellInit,
            @NonNull ShellTaskOrganizer shellTaskOrganizer,
            @NonNull Transitions transitions,
            PipBoundsState pipBoundsState,
            PipBoundsAlgorithm pipBoundsAlgorithm,
            Optional<PipController> pipController,
            @NonNull PipScheduler pipScheduler) {
        return new PipTransition(shellInit, shellTaskOrganizer, transitions, pipBoundsState, null,
                pipBoundsAlgorithm, pipScheduler);
        return new PipTransition(context, shellInit, shellTaskOrganizer, transitions,
                pipBoundsState, null, pipBoundsAlgorithm, pipScheduler);
    }

    @WMSingleton
+12 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.wm.shell.transition.Transitions;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * Responsible supplying PiP Transitions.
@@ -115,6 +116,17 @@ public abstract class PipTransitionController implements Transitions.TransitionH
        // Default implementation does nothing.
    }

    /**
     * Called when the Shell wants to start resizing Pip transition/animation.
     *
     * @param onFinishResizeCallback callback guaranteed to execute when animation ends and
     *                               client completes any potential draws upon WM state updates.
     */
    public void startResizeTransition(WindowContainerTransaction wct,
            Consumer<Rect> onFinishResizeCallback) {
        // Default implementation does nothing.
    }

    /**
     * Called when the transition animation can't continue (eg. task is removed during
     * animation)
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.pip.PipBoundsAlgorithm;
import com.android.wm.shell.common.pip.PipBoundsState;
import com.android.wm.shell.common.pip.PipDoubleTapHelper;
import com.android.wm.shell.common.pip.PipUiEventLogger;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.common.pip.SizeSpecSource;
+50 −3
Original line number Diff line number Diff line
@@ -24,10 +24,12 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Rect;
import android.view.SurfaceControl;
import android.window.WindowContainerToken;
import android.window.WindowContainerTransaction;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

@@ -36,6 +38,10 @@ import com.android.wm.shell.common.pip.PipBoundsState;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.pip.PipTransitionController;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.function.Consumer;

/**
 * Scheduler for Shell initiated PiP transitions and animations.
 */
@@ -58,13 +64,37 @@ public class PipScheduler {
    private SurfaceControl mPinnedTaskLeash;

    /**
     * A temporary broadcast receiver to initiate exit PiP via expand.
     * This will later be modified to be triggered by the PiP menu.
     * Temporary PiP CUJ codes to schedule PiP related transitions directly from Shell.
     * This is used for a broadcast receiver to resolve intents. This should be removed once
     * there is an equivalent of PipTouchHandler and PipResizeGestureHandler for PiP2.
     */
    private static final int PIP_EXIT_VIA_EXPAND_CODE = 0;
    private static final int PIP_DOUBLE_TAP = 1;

    @IntDef(value = {
            PIP_EXIT_VIA_EXPAND_CODE,
            PIP_DOUBLE_TAP
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface PipUserJourneyCode {}

    /**
     * A temporary broadcast receiver to initiate PiP CUJs.
     */
    private class PipSchedulerReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            int userJourneyCode = intent.getIntExtra("cuj_code_extra", 0);
            switch (userJourneyCode) {
                case PIP_EXIT_VIA_EXPAND_CODE:
                    scheduleExitPipViaExpand();
                    break;
                case PIP_DOUBLE_TAP:
                    scheduleDoubleTapToResize();
                    break;
                default:
                    throw new IllegalStateException("unexpected CUJ code=" + userJourneyCode);
            }
        }
    }

@@ -121,6 +151,23 @@ public class PipScheduler {
        }
    }

    /**
     * Schedules resize PiP via double tap.
     */
    public void scheduleDoubleTapToResize() {}

    /**
     * Animates resizing of the pinned stack given the duration.
     */
    public void scheduleAnimateResizePip(Rect toBounds, Consumer<Rect> onFinishResizeCallback) {
        if (mPipTaskToken == null) {
            return;
        }
        WindowContainerTransaction wct = new WindowContainerTransaction();
        wct.setBounds(mPipTaskToken, toBounds);
        mPipTransitionController.startResizeTransition(wct, onFinishResizeCallback);
    }

    void onExitPip() {
        mPipTaskToken = null;
        mPinnedTaskLeash = null;
Loading