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

Commit 34c1fb93 authored by Jerry Chang's avatar Jerry Chang
Browse files

Replace tasks in the same split with the dropping app

When launching a new app into a specific split, evicts all child tasks
that were originally in the same split.

Fix: 202739668
Test: atest WMShellUnitTests
Test: manual check dropping an app to a specific split evicts other
      tasks in the same split.
Change-Id: I3f52a3675d6ead742f0b75c83393462e5778a524
parent a8a33c88
Loading
Loading
Loading
Loading
+12 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.wm.shell.splitscreen;
package com.android.wm.shell.splitscreen;


import static android.app.ActivityManager.START_SUCCESS;
import static android.app.ActivityManager.START_TASK_TO_FRONT;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.RemoteAnimationTarget.MODE_OPENING;
import static android.view.RemoteAnimationTarget.MODE_OPENING;


@@ -213,7 +215,11 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
        options = mStageCoordinator.resolveStartStage(stage, position, options, null /* wct */);
        options = mStageCoordinator.resolveStartStage(stage, position, options, null /* wct */);


        try {
        try {
            final int result =
                    ActivityTaskManager.getService().startActivityFromRecents(taskId, options);
                    ActivityTaskManager.getService().startActivityFromRecents(taskId, options);
            if (result == START_SUCCESS || result == START_TASK_TO_FRONT) {
                mStageCoordinator.evictOccludedChildren(position);
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to launch task", e);
            Slog.e(TAG, "Failed to launch task", e);
        }
        }
@@ -229,6 +235,7 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
                    mContext.getSystemService(LauncherApps.class);
                    mContext.getSystemService(LauncherApps.class);
            launcherApps.startShortcut(packageName, shortcutId, null /* sourceBounds */,
            launcherApps.startShortcut(packageName, shortcutId, null /* sourceBounds */,
                    options, user);
                    options, user);
            mStageCoordinator.evictOccludedChildren(position);
        } catch (ActivityNotFoundException e) {
        } catch (ActivityNotFoundException e) {
            Slog.e(TAG, "Failed to launch shortcut", e);
            Slog.e(TAG, "Failed to launch shortcut", e);
        }
        }
@@ -272,6 +279,10 @@ public class SplitScreenController implements DragAndDropPolicy.Starter,
                        Slog.e(TAG, "Error finishing legacy transition: ", e);
                        Slog.e(TAG, "Error finishing legacy transition: ", e);
                    }
                    }
                }
                }

                // Launching a new app into a specific split evicts tasks previously in the same
                // split.
                mStageCoordinator.evictOccludedChildren(position);
            }
            }
        };
        };
        WindowContainerTransaction wct = new WindowContainerTransaction();
        WindowContainerTransaction wct = new WindowContainerTransaction();
+6 −0
Original line number Original line Diff line number Diff line
@@ -394,6 +394,12 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler,
                TRANSIT_SPLIT_SCREEN_OPEN_TO_SIDE, wct, remoteTransition, this);
                TRANSIT_SPLIT_SCREEN_OPEN_TO_SIDE, wct, remoteTransition, this);
    }
    }


    void evictOccludedChildren(@SplitPosition int position) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        (position == mSideStagePosition ? mSideStage : mMainStage).evictOccludedChildren(wct);
        mTaskOrganizer.applyTransaction(wct);
    }

    Bundle resolveStartStage(@SplitScreen.StageType int stage,
    Bundle resolveStartStage(@SplitScreen.StageType int stage,
            @SplitPosition int position, @androidx.annotation.Nullable Bundle options,
            @SplitPosition int position, @androidx.annotation.Nullable Bundle options,
            @androidx.annotation.Nullable WindowContainerTransaction wct) {
            @androidx.annotation.Nullable WindowContainerTransaction wct) {
+10 −0
Original line number Original line Diff line number Diff line
@@ -68,6 +68,7 @@ class StageTaskListener implements ShellTaskOrganizer.TaskListener {
        void onChildTaskStatusChanged(int taskId, boolean present, boolean visible);
        void onChildTaskStatusChanged(int taskId, boolean present, boolean visible);


        void onRootTaskVanished();
        void onRootTaskVanished();

        void onNoLongerSupportMultiWindow();
        void onNoLongerSupportMultiWindow();
    }
    }


@@ -247,6 +248,15 @@ class StageTaskListener implements ShellTaskOrganizer.TaskListener {
        wct.reorder(mChildrenTaskInfo.get(taskId).token, onTop /* onTop */);
        wct.reorder(mChildrenTaskInfo.get(taskId).token, onTop /* onTop */);
    }
    }


    void evictOccludedChildren(WindowContainerTransaction wct) {
        for (int i = mChildrenTaskInfo.size() - 1; i >= 0; i--) {
            final ActivityManager.RunningTaskInfo taskInfo = mChildrenTaskInfo.valueAt(i);
            if (!taskInfo.isVisible) {
                wct.reparent(taskInfo.token, null /* parent */, false /* onTop */);
            }
        }
    }

    void setVisibility(boolean visible, WindowContainerTransaction wct) {
    void setVisibility(boolean visible, WindowContainerTransaction wct) {
        wct.reorder(mRootTaskInfo.token, visible /* onTop */);
        wct.reorder(mRootTaskInfo.token, visible /* onTop */);
    }
    }