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

Commit f8383085 authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Allows the dim layer to apply on the parent Task of an embedded TF" into main

parents d3f3084d 7113ba11
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2858,7 +2858,8 @@ class Task extends TaskFragment {
    }

    /** Bounds of the task to be used for dimming, as well as touch related tests. */
    void getDimBounds(Rect out) {
    @Override
    void getDimBounds(@NonNull Rect out) {
        if (isRootTask()) {
            getBounds(out);
            return;
+33 −2
Original line number Diff line number Diff line
@@ -213,6 +213,24 @@ class TaskFragment extends WindowContainer<WindowContainer> {
    Dimmer mDimmer = Flags.dimmerRefactor()
            ? new SmoothDimmer(this) : new LegacyDimmer(this);

    /** Apply the dim layer on the embedded TaskFragment. */
    static final int EMBEDDED_DIM_AREA_TASK_FRAGMENT = 0;

    /** Apply the dim layer on the parent Task for an embedded TaskFragment. */
    static final int EMBEDDED_DIM_AREA_PARENT_TASK = 1;

    /**
     * The type of dim layer area for an embedded TaskFragment.
     */
    @IntDef(prefix = {"EMBEDDED_DIM_AREA_"}, value = {
            EMBEDDED_DIM_AREA_TASK_FRAGMENT,
            EMBEDDED_DIM_AREA_PARENT_TASK,
    })
    @interface EmbeddedDimArea {}

    @EmbeddedDimArea
    private int mEmbeddedDimArea = EMBEDDED_DIM_AREA_TASK_FRAGMENT;

    /** This task fragment will be removed when the cleanup of its children are done. */
    private boolean mIsRemovalRequested;

@@ -2931,14 +2949,27 @@ class TaskFragment extends WindowContainer<WindowContainer> {

    @Override
    Dimmer getDimmer() {
        // If the window is in an embedded TaskFragment, we want to dim at the TaskFragment.
        if (asTask() == null) {
        // If this is in an embedded TaskFragment and we want the dim applies on the TaskFragment.
        if (mIsEmbedded && mEmbeddedDimArea == EMBEDDED_DIM_AREA_TASK_FRAGMENT) {
            return mDimmer;
        }

        return super.getDimmer();
    }

    /** Bounds to be used for dimming, as well as touch related tests. */
    void getDimBounds(@NonNull Rect out) {
        if (mIsEmbedded && mEmbeddedDimArea == EMBEDDED_DIM_AREA_PARENT_TASK) {
            out.set(getTask().getBounds());
        } else {
            out.set(getBounds());
        }
    }

    void setEmbeddedDimArea(@EmbeddedDimArea int embeddedDimArea) {
        mEmbeddedDimArea = embeddedDimArea;
    }

    @Override
    void prepareSurfaces() {
        if (asTask() != null) {
+1 −6
Original line number Diff line number Diff line
@@ -2769,12 +2769,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                // bounds, as they would be used to display the dim layer.
                final TaskFragment taskFragment = getTaskFragment();
                if (taskFragment != null) {
                    final Task task = taskFragment.asTask();
                    if (task != null) {
                        task.getDimBounds(mTmpRect);
                    } else {
                        mTmpRect.set(taskFragment.getBounds());
                    }
                    taskFragment.getDimBounds(mTmpRect);
                } else if (getRootTask() != null) {
                    getRootTask().getDimBounds(mTmpRect);
                }
+22 −0
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.server.wm.ActivityRecord.State.RESUMED;
import static com.android.server.wm.TaskFragment.EMBEDDED_DIM_AREA_PARENT_TASK;
import static com.android.server.wm.TaskFragment.EMBEDDED_DIM_AREA_TASK_FRAGMENT;
import static com.android.server.wm.TaskFragment.EMBEDDING_DISALLOWED_MIN_DIMENSION_VIOLATION;
import static com.android.server.wm.TaskFragment.EMBEDDING_DISALLOWED_UNTRUSTED_HOST;
import static com.android.server.wm.WindowContainer.POSITION_TOP;
@@ -687,4 +689,24 @@ public class TaskFragmentTest extends WindowTestsBase {
        tf0.setIsolatedNav(true);
        assertTrue(tf0.isIsolatedNav());
    }

    @Test
    public void testGetDimBounds() {
        final Task task = mTaskFragment.getTask();
        final Rect taskBounds = task.getBounds();
        mTaskFragment.setBounds(taskBounds.left, taskBounds.top, taskBounds.left + 10,
                taskBounds.top + 10);
        final Rect taskFragmentBounds = mTaskFragment.getBounds();

        // Return Task bounds if dimming on parent Task.
        final Rect dimBounds = new Rect();
        mTaskFragment.setEmbeddedDimArea(EMBEDDED_DIM_AREA_PARENT_TASK);
        mTaskFragment.getDimBounds(dimBounds);
        assertEquals(taskBounds, dimBounds);

        // Return TF bounds by default.
        mTaskFragment.setEmbeddedDimArea(EMBEDDED_DIM_AREA_TASK_FRAGMENT);
        mTaskFragment.getDimBounds(dimBounds);
        assertEquals(taskFragmentBounds, dimBounds);
    }
}