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

Commit c6aa5189 authored by jainrachit's avatar jainrachit
Browse files

[6/n] Apply the safe region bounds WCT

- The safe region bounds can be applied (including a reset) on the WindowContainer.

Bug: 380132497
Flag: com.android.window.flags.safe_region_letterboxing
Test: atest WindowOrganizerTests
Change-Id: I3efdd2eefcbca9ed6f2bac95cc9ee1b809675abb
parent fba9851a
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_SET_SAFE_REGION_BOUNDS;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_START_SHORTCUT;
import static android.window.WindowContainerTransaction.HierarchyOp.REACHABILITY_EVENT_X;
import static android.window.WindowContainerTransaction.HierarchyOp.REACHABILITY_EVENT_Y;
@@ -1544,6 +1545,19 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                container.setExcludeInsetsTypes(hop.getExcludeInsetsTypes());
                break;
            }
            case HIERARCHY_OP_TYPE_SET_SAFE_REGION_BOUNDS: {
                final WindowContainer container = WindowContainer.fromBinder(hop.getContainer());
                if (container == null || !container.isAttached()) {
                    Slog.e(TAG,
                            "Attempt to operate on unknown or detached container: " + container);
                    break;
                }
                if (chain.mTransition != null) {
                    chain.mTransition.collect(container);
                }
                container.setSafeRegionBounds(hop.getSafeRegionBounds());
                effects |= TRANSACT_EFFECTS_CLIENT_CONFIG;
            }
        }
        return effects;
    }
+46 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -1567,6 +1568,51 @@ public class WindowOrganizerTests extends WindowTestsBase {
        });
    }

    @Test
    @EnableFlags(Flags.FLAG_SAFE_REGION_LETTERBOXING)
    public void testSetSafeRegionBoundsOnRootTask() {
        Task rootTask = mWm.mAtmService.mTaskOrganizerController.createRootTask(
                mDisplayContent, WINDOWING_MODE_FULLSCREEN, null);
        final Task task1 = createRootTask();
        final Task task2 = createTask(rootTask, false /* fakeDraw */);
        WindowContainerTransaction wct = new WindowContainerTransaction();
        Rect safeRegionBounds = new Rect(50, 50, 200, 300);

        wct.setSafeRegionBounds(rootTask.mRemoteToken.toWindowContainerToken(), safeRegionBounds);
        mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct);

        assertEquals(rootTask.getSafeRegionBounds(), safeRegionBounds);
        assertEquals(task2.getSafeRegionBounds(), safeRegionBounds);
        assertNull(task1.getSafeRegionBounds());
    }

    @Test
    @EnableFlags(Flags.FLAG_SAFE_REGION_LETTERBOXING)
    public void testSetSafeRegionBoundsOnRootTask_resetSafeRegionBounds() {
        Task rootTask = mWm.mAtmService.mTaskOrganizerController.createRootTask(
                mDisplayContent, WINDOWING_MODE_FULLSCREEN, null);
        final Task task1 = createRootTask();
        final Task task2 = createTask(rootTask, false /* fakeDraw */);
        WindowContainerTransaction wct = new WindowContainerTransaction();
        Rect safeRegionBounds = new Rect(50, 50, 200, 300);

        wct.setSafeRegionBounds(rootTask.mRemoteToken.toWindowContainerToken(), safeRegionBounds);
        mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct);

        assertEquals(rootTask.getSafeRegionBounds(), safeRegionBounds);
        assertEquals(task2.getSafeRegionBounds(), safeRegionBounds);
        assertNull(task1.getSafeRegionBounds());

        // Reset safe region bounds on the root task
        wct.setSafeRegionBounds(rootTask.mRemoteToken.toWindowContainerToken(),
                /* safeRegionBounds */null);
        mWm.mAtmService.mWindowOrganizerController.applyTransaction(wct);

        assertNull(rootTask.getSafeRegionBounds());
        assertNull(task2.getSafeRegionBounds());
        assertNull(task1.getSafeRegionBounds());
    }

    @Test
    public void testReparentToOrganizedTask() {
        final ITaskOrganizer organizer = registerMockOrganizer();