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

Commit 75bacc46 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix how task info is retrieved for split screen

Previously this was grabbing the top two tasks from the
task list, but this isn't guaranteed to be what's on the
screen. Instead, when already in split, use the taskInfo
from the split controller.

Test: manual - 1) have stuff in split
               2) keep dragging different apps into split
               => verify the app icon shown in the non
                  highlighted side matches the app on that
                  side
Bug: 209504662
Change-Id: Ib959f44bc9eaebfb5e3f640d69cb6f3ddccedfcf
parent eeb998c0
Loading
Loading
Loading
Loading
+32 −32
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.draganddrop;

import static android.app.StatusBarManager.DISABLE_NONE;

import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT;

import android.animation.Animator;
@@ -165,10 +166,13 @@ public class DragLayout extends LinearLayout {
        mHasDropped = false;
        mCurrentTarget = null;

        boolean alreadyInSplit = mSplitScreenController != null
                && mSplitScreenController.isSplitScreenVisible();
        if (!alreadyInSplit) {
            List<ActivityManager.RunningTaskInfo> tasks = null;
        // Figure out the splashscreen info for the existing task(s).
            // Figure out the splashscreen info for the existing task.
            try {
            tasks = ActivityTaskManager.getService().getTasks(2,
                tasks = ActivityTaskManager.getService().getTasks(1,
                        false /* filterOnlyVisibleRecents */,
                        false /* keepIntentExtra */);
            } catch (RemoteException e) {
@@ -178,27 +182,23 @@ public class DragLayout extends LinearLayout {
                ActivityManager.RunningTaskInfo taskInfo1 = tasks.get(0);
                Drawable icon1 = mIconProvider.getIcon(taskInfo1.topActivityInfo);
                int bgColor1 = getResizingBackgroundColor(taskInfo1);

            boolean alreadyInSplit = mSplitScreenController != null
                    && mSplitScreenController.isSplitScreenVisible();
            if (alreadyInSplit && tasks.size() > 1) {
                ActivityManager.RunningTaskInfo taskInfo2 = tasks.get(1);
                Drawable icon2 = mIconProvider.getIcon(taskInfo2.topActivityInfo);
                int bgColor2 = getResizingBackgroundColor(taskInfo2);

                // figure out which task is on which side
                int splitPosition1 = mSplitScreenController.getSplitPosition(taskInfo1.taskId);
                boolean isTask1TopOrLeft = splitPosition1 == SPLIT_POSITION_TOP_OR_LEFT;
                if (isTask1TopOrLeft) {
                mDropZoneView1.setAppInfo(bgColor1, icon1);
                    mDropZoneView2.setAppInfo(bgColor2, icon2);
                } else {
                mDropZoneView2.setAppInfo(bgColor1, icon1);
                    mDropZoneView1.setAppInfo(bgColor2, icon2);
            }
        } else {
                mDropZoneView1.setAppInfo(bgColor1, icon1);
                mDropZoneView2.setAppInfo(bgColor1, icon1);
            // We're already in split so get taskInfo from the controller to populate icon / color.
            ActivityManager.RunningTaskInfo topOrLeftTask =
                    mSplitScreenController.getTaskInfo(SPLIT_POSITION_TOP_OR_LEFT);
            ActivityManager.RunningTaskInfo bottomOrRightTask =
                    mSplitScreenController.getTaskInfo(SPLIT_POSITION_BOTTOM_OR_RIGHT);
            if (topOrLeftTask != null && bottomOrRightTask != null) {
                Drawable topOrLeftIcon = mIconProvider.getIcon(topOrLeftTask.topActivityInfo);
                int topOrLeftColor = getResizingBackgroundColor(topOrLeftTask);
                Drawable bottomOrRightIcon = mIconProvider.getIcon(
                        bottomOrRightTask.topActivityInfo);
                int bottomOrRightColor = getResizingBackgroundColor(bottomOrRightTask);
                mDropZoneView1.setAppInfo(topOrLeftColor, topOrLeftIcon);
                mDropZoneView2.setAppInfo(bottomOrRightColor, bottomOrRightIcon);
            }
        }
    }
+9 −0
Original line number Diff line number Diff line
@@ -184,6 +184,15 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
        return mStageCoordinator.isSplitScreenVisible();
    }

    @Nullable
    public ActivityManager.RunningTaskInfo getTaskInfo(@SplitPosition int splitPosition) {
        if (isSplitScreenVisible()) {
            int taskId = mStageCoordinator.getTaskId(splitPosition);
            return mTaskOrganizer.getRunningTaskInfo(taskId);
        }
        return null;
    }

    public boolean isTaskInSplitScreen(int taskId) {
        return isSplitScreenVisible()
                && mStageCoordinator.getStageOfTask(taskId) != STAGE_TYPE_UNDEFINED;
+8 −0
Original line number Diff line number Diff line
@@ -521,6 +521,14 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
        return SplitLayout.reversePosition(mSideStagePosition);
    }

    int getTaskId(@SplitPosition int splitPosition) {
        if (mSideStagePosition == splitPosition) {
            return mSideStage.getTopVisibleChildTaskId();
        } else {
            return mMainStage.getTopVisibleChildTaskId();
        }
    }

    void setSideStagePosition(@SplitPosition int sideStagePosition,
            @Nullable WindowContainerTransaction wct) {
        setSideStagePosition(sideStagePosition, true /* updateBounds */, wct);