Remove old caption bar before adding a new one

When adding a new window caption, check if old one is present. If it is,
remove it before adding a new one.

Bug: 257121505
Test: manual, open a task in desktop mode, swipe to overview, click on
overview tile, task is again visible, resize task to check that only one
caption bar is shown

Change-Id: Ib4cc3934207f6d51a2ef101e4685285dd3f82743
This commit is contained in:
Ats Jenk
2022-11-02 15:01:58 -07:00
parent 91d982458c
commit 5aa98410e7
3 changed files with 34 additions and 8 deletions

View File

@@ -98,9 +98,11 @@ public class FreeformTaskTransitionObserver implements Transitions.TransitionObs
switch (change.getMode()) {
case WindowManager.TRANSIT_OPEN:
case WindowManager.TRANSIT_TO_FRONT:
onOpenTransitionReady(change, startT, finishT);
break;
case WindowManager.TRANSIT_TO_FRONT:
onToFrontTransitionReady(change, startT, finishT);
break;
case WindowManager.TRANSIT_CLOSE: {
taskInfoList.add(change.getTaskInfo());
onCloseTransitionReady(change, startT, finishT);
@@ -138,6 +140,21 @@ public class FreeformTaskTransitionObserver implements Transitions.TransitionObs
change.getTaskInfo(), startT, finishT);
}
private void onToFrontTransitionReady(
TransitionInfo.Change change,
SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) {
boolean exists = mWindowDecorViewModel.setupWindowDecorationForTransition(
change.getTaskInfo(),
startT,
finishT);
if (!exists) {
// Window caption does not exist, create it
mWindowDecorViewModel.createWindowDecoration(
change.getTaskInfo(), change.getLeash(), startT, finishT);
}
}
@Override
public void onTransitionStarting(@NonNull IBinder transition) {}

View File

@@ -105,6 +105,11 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) {
if (!shouldShowWindowDecor(taskInfo)) return false;
CaptionWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId);
if (oldDecoration != null) {
// close the old decoration if it exists to avoid two window decorations being added
oldDecoration.close();
}
final CaptionWindowDecoration windowDecoration = new CaptionWindowDecoration(
mContext,
mDisplayController,
@@ -141,23 +146,25 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
}
@Override
public void setupWindowDecorationForTransition(
public boolean setupWindowDecorationForTransition(
RunningTaskInfo taskInfo,
SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) {
final CaptionWindowDecoration decoration = mWindowDecorByTaskId.get(taskInfo.taskId);
if (decoration == null) return;
if (decoration == null) return false;
decoration.relayout(taskInfo, startT, finishT);
return true;
}
@Override
public void destroyWindowDecoration(RunningTaskInfo taskInfo) {
public boolean destroyWindowDecoration(RunningTaskInfo taskInfo) {
final CaptionWindowDecoration decoration =
mWindowDecorByTaskId.removeReturnOld(taskInfo.taskId);
if (decoration == null) return;
if (decoration == null) return false;
decoration.close();
return true;
}
private class CaptionTouchEventListener implements

View File

@@ -44,7 +44,7 @@ public interface WindowDecorViewModel {
* @param taskSurface the surface of the task
* @param startT the start transaction to be applied before the transition
* @param finishT the finish transaction to restore states after the transition
* @return the window decoration object
* @return {@code true} if window decoration was created, {@code false} otherwise
*/
boolean createWindowDecoration(
ActivityManager.RunningTaskInfo taskInfo,
@@ -66,8 +66,9 @@ public interface WindowDecorViewModel {
*
* @param startT the start transaction to be applied before the transition
* @param finishT the finish transaction to restore states after the transition
* @return {@code true} if window decoration exists, {@code false} otherwise
*/
void setupWindowDecorationForTransition(
boolean setupWindowDecorationForTransition(
ActivityManager.RunningTaskInfo taskInfo,
SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT);
@@ -76,6 +77,7 @@ public interface WindowDecorViewModel {
* Destroys the window decoration of the give task.
*
* @param taskInfo the info of the task
* @return {@code true} if window decoration was destroyed, {@code false} otherwise
*/
void destroyWindowDecoration(ActivityManager.RunningTaskInfo taskInfo);
boolean destroyWindowDecoration(ActivityManager.RunningTaskInfo taskInfo);
}