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

Commit 03e159a5 authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Set task bounds for recents composition.

After reboot, the app bounds and the position in the parent is not
persisted. Use persistent lastNonFullscreenBounds of the task to compose
the tile.

Bug: 365496442
Test: atest RecentTasksControllerTest
Flag: com.android.window.flags.enable_desktop_windowing_persistence
Change-Id: I9b34514ab6802769b349b6521e43ab77ead7c176
parent b3820ebb
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Slog;
@@ -46,6 +47,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.internal.protolog.ProtoLog;
import com.android.window.flags.Flags;
import com.android.wm.shell.common.ExternalInterfaceBinder;
import com.android.wm.shell.common.RemoteCallable;
import com.android.wm.shell.common.ShellExecutor;
@@ -421,6 +423,16 @@ public class RecentTasksController implements TaskStackListenerCallback,
                if (mostRecentFreeformTaskIndex == Integer.MAX_VALUE) {
                    mostRecentFreeformTaskIndex = recentTasks.size();
                }
                // If task has their app bounds set to null which happens after reboot, set the
                // app bounds to persisted lastFullscreenBounds. Also set the position in parent
                // to the top left of the bounds.
                if (Flags.enableDesktopWindowingPersistence()
                        && taskInfo.configuration.windowConfiguration.getAppBounds() == null) {
                    taskInfo.configuration.windowConfiguration.setAppBounds(
                            taskInfo.lastNonFullscreenBounds);
                    taskInfo.positionInParent = new Point(taskInfo.lastNonFullscreenBounds.left,
                            taskInfo.lastNonFullscreenBounds.top);
                }
                freeformTasks.add(taskInfo);
                if (mDesktopModeTaskRepository.get().isMinimizedTask(taskInfo.taskId)) {
                    minimizedFreeformTasks.add(taskInfo.taskId);
+37 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
import static com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_PERSISTENCE;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SNAP_TO_2_50_50;

import static org.junit.Assert.assertEquals;
@@ -50,6 +51,7 @@ import android.app.KeyguardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
@@ -440,6 +442,40 @@ public class RecentTasksControllerTest extends ShellTestCase {
        assertEquals(t4, singleGroup2.getTaskInfo1());
    }

    @Test
    @EnableFlags(FLAG_ENABLE_DESKTOP_WINDOWING_PERSISTENCE)
    public void testGetRecentTasks_hasDesktopTasks_persistenceEnabled_freeformTaskHaveBoundsSet() {
        ActivityManager.RecentTaskInfo t1 = makeTaskInfo(1);
        ActivityManager.RecentTaskInfo t2 = makeTaskInfo(2);

        t1.lastNonFullscreenBounds = new Rect(100, 200, 300, 400);
        t2.lastNonFullscreenBounds = new Rect(150, 250, 350, 450);
        setRawList(t1, t2);

        when(mDesktopModeTaskRepository.isActiveTask(1)).thenReturn(true);
        when(mDesktopModeTaskRepository.isActiveTask(2)).thenReturn(true);

        ArrayList<GroupedRecentTaskInfo> recentTasks = mRecentTasksController.getRecentTasks(
                MAX_VALUE, RECENT_IGNORE_UNAVAILABLE, 0);

        assertEquals(1, recentTasks.size());
        GroupedRecentTaskInfo freeformGroup = recentTasks.get(0);

        // Check bounds
        assertEquals(t1.lastNonFullscreenBounds, freeformGroup.getTaskInfoList().get(
                0).configuration.windowConfiguration.getAppBounds());
        assertEquals(t2.lastNonFullscreenBounds, freeformGroup.getTaskInfoList().get(
                1).configuration.windowConfiguration.getAppBounds());

        // Check position in parent
        assertEquals(new Point(t1.lastNonFullscreenBounds.left,
                        t1.lastNonFullscreenBounds.top),
                freeformGroup.getTaskInfoList().get(0).positionInParent);
        assertEquals(new Point(t2.lastNonFullscreenBounds.left,
                        t2.lastNonFullscreenBounds.top),
                freeformGroup.getTaskInfoList().get(1).positionInParent);
    }

    @Test
    public void testRemovedTaskRemovesSplit() {
        ActivityManager.RecentTaskInfo t1 = makeTaskInfo(1);
@@ -623,6 +659,7 @@ public class RecentTasksControllerTest extends ShellTestCase {
    private ActivityManager.RecentTaskInfo makeTaskInfo(int taskId) {
        ActivityManager.RecentTaskInfo info = new ActivityManager.RecentTaskInfo();
        info.taskId = taskId;
        info.lastNonFullscreenBounds = new Rect();
        return info;
    }