Merge "Adjust caption observer for desktop transition" into tm-qpr-dev am: 556ecc8da9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19973036

Change-Id: I49fb24c8180af93066bd78523fa007ff8c48d5a6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Evan Rosky
2022-09-20 16:44:54 +00:00
committed by Automerger Merge Worker
3 changed files with 49 additions and 12 deletions

View File

@@ -191,15 +191,19 @@ public class FreeformTaskListener<T extends AutoCloseable>
* *
* @param change the change of this task transition that needs to have the task layer as the * @param change the change of this task transition that needs to have the task layer as the
* leash * leash
* @return {@code true} if it adopts the window decoration; {@code false} otherwise * @return {@code true} if it creates the window decoration; {@code false} otherwise
*/ */
void createWindowDecoration( boolean createWindowDecoration(
TransitionInfo.Change change, TransitionInfo.Change change,
SurfaceControl.Transaction startT, SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) { SurfaceControl.Transaction finishT) {
final State<T> state = createOrUpdateTaskState(change.getTaskInfo(), change.getLeash()); final State<T> state = createOrUpdateTaskState(change.getTaskInfo(), change.getLeash());
if (state.mWindowDecoration != null) {
return false;
}
state.mWindowDecoration = mWindowDecorationViewModel.createWindowDecoration( state.mWindowDecoration = mWindowDecorationViewModel.createWindowDecoration(
state.mTaskInfo, state.mLeash, startT, finishT); state.mTaskInfo, state.mLeash, startT, finishT);
return true;
} }
/** /**
@@ -222,6 +226,9 @@ public class FreeformTaskListener<T extends AutoCloseable>
windowDecor = windowDecor =
mWindowDecorOfVanishedTasks.removeReturnOld(taskInfo.taskId); mWindowDecorOfVanishedTasks.removeReturnOld(taskInfo.taskId);
} }
if (windowDecor == null) {
return null;
}
mWindowDecorationViewModel.setupWindowDecorationForTransition( mWindowDecorationViewModel.setupWindowDecorationForTransition(
taskInfo, startT, finishT, windowDecor); taskInfo, startT, finishT, windowDecor);
return windowDecor; return windowDecor;

View File

@@ -26,6 +26,7 @@ import android.util.Log;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.view.WindowManager; import android.view.WindowManager;
import android.window.TransitionInfo; import android.window.TransitionInfo;
import android.window.WindowContainerToken;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -80,6 +81,7 @@ public class FreeformTaskTransitionObserver implements Transitions.TransitionObs
@NonNull SurfaceControl.Transaction startT, @NonNull SurfaceControl.Transaction startT,
@NonNull SurfaceControl.Transaction finishT) { @NonNull SurfaceControl.Transaction finishT) {
final ArrayList<AutoCloseable> windowDecors = new ArrayList<>(); final ArrayList<AutoCloseable> windowDecors = new ArrayList<>();
final ArrayList<WindowContainerToken> taskParents = new ArrayList<>();
for (TransitionInfo.Change change : info.getChanges()) { for (TransitionInfo.Change change : info.getChanges()) {
if ((change.getFlags() & TransitionInfo.FLAG_IS_WALLPAPER) != 0) { if ((change.getFlags() & TransitionInfo.FLAG_IS_WALLPAPER) != 0) {
continue; continue;
@@ -89,9 +91,22 @@ public class FreeformTaskTransitionObserver implements Transitions.TransitionObs
if (taskInfo == null || taskInfo.taskId == -1) { if (taskInfo == null || taskInfo.taskId == -1) {
continue; continue;
} }
// Filter out non-leaf tasks. Freeform/fullscreen don't nest tasks, but split-screen
// does, so this prevents adding duplicate captions in that scenario.
if (change.getParent() != null
&& info.getChange(change.getParent()).getTaskInfo() != null) {
// This logic relies on 2 assumptions: 1 is that child tasks will be visited before
// parents (due to how z-order works). 2 is that no non-tasks are interleaved
// between tasks (hierarchically).
taskParents.add(change.getContainer());
}
if (taskParents.contains(change.getContainer())) {
continue;
}
switch (change.getMode()) { switch (change.getMode()) {
case WindowManager.TRANSIT_OPEN: case WindowManager.TRANSIT_OPEN:
case WindowManager.TRANSIT_TO_FRONT:
onOpenTransitionReady(change, startT, finishT); onOpenTransitionReady(change, startT, finishT);
break; break;
case WindowManager.TRANSIT_CLOSE: { case WindowManager.TRANSIT_CLOSE: {
@@ -154,20 +169,28 @@ public class FreeformTaskTransitionObserver implements Transitions.TransitionObs
boolean adopted = false; boolean adopted = false;
final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo(); final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
if (type == Transitions.TRANSIT_MAXIMIZE if (taskInfo.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) {
&& taskInfo.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) {
windowDecor = mFreeformTaskListener.giveWindowDecoration( windowDecor = mFreeformTaskListener.giveWindowDecoration(
change.getTaskInfo(), startT, finishT); change.getTaskInfo(), startT, finishT);
adopted = mFullscreenTaskListener.adoptWindowDecoration( if (windowDecor != null) {
change, startT, finishT, windowDecor); adopted = mFullscreenTaskListener.adoptWindowDecoration(
change, startT, finishT, windowDecor);
} else {
// will return false if it already has the window decor.
adopted = mFullscreenTaskListener.createWindowDecoration(change, startT, finishT);
}
} }
if (type == Transitions.TRANSIT_RESTORE_FROM_MAXIMIZE if (taskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM) {
&& taskInfo.getWindowingMode() == WINDOWING_MODE_FREEFORM) {
windowDecor = mFullscreenTaskListener.giveWindowDecoration( windowDecor = mFullscreenTaskListener.giveWindowDecoration(
change.getTaskInfo(), startT, finishT); change.getTaskInfo(), startT, finishT);
adopted = mFreeformTaskListener.adoptWindowDecoration( if (windowDecor != null) {
change, startT, finishT, windowDecor); adopted = mFreeformTaskListener.adoptWindowDecoration(
change, startT, finishT, windowDecor);
} else {
// will return false if it already has the window decor.
adopted = mFreeformTaskListener.createWindowDecoration(change, startT, finishT);
}
} }
if (!adopted) { if (!adopted) {

View File

@@ -173,16 +173,23 @@ public class FullscreenTaskListener<T extends AutoCloseable>
* *
* @param change the change of this task transition that needs to have the task layer as the * @param change the change of this task transition that needs to have the task layer as the
* leash * leash
* @return {@code true} if a decoration was actually created.
*/ */
public void createWindowDecoration(TransitionInfo.Change change, public boolean createWindowDecoration(TransitionInfo.Change change,
SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT) { SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT) {
final State<T> state = createOrUpdateTaskState(change.getTaskInfo(), change.getLeash()); final State<T> state = createOrUpdateTaskState(change.getTaskInfo(), change.getLeash());
if (!mWindowDecorViewModelOptional.isPresent()) return; if (!mWindowDecorViewModelOptional.isPresent()) return false;
if (state.mWindowDecoration != null) {
// Already has a decoration.
return false;
}
T newWindowDecor = mWindowDecorViewModelOptional.get().createWindowDecoration( T newWindowDecor = mWindowDecorViewModelOptional.get().createWindowDecoration(
state.mTaskInfo, state.mLeash, startT, finishT); state.mTaskInfo, state.mLeash, startT, finishT);
if (newWindowDecor != null) { if (newWindowDecor != null) {
state.mWindowDecoration = newWindowDecor; state.mWindowDecoration = newWindowDecor;
return true;
} }
return false;
} }
/** /**