Merge "Rename WindowDecor classes for Desktop Mode." into tm-qpr-dev

This commit is contained in:
Merissa Mitchell
2022-12-27 00:20:48 +00:00
committed by Android (Google) Code Review
4 changed files with 67 additions and 60 deletions

View File

@@ -93,7 +93,7 @@ import com.android.wm.shell.unfold.animation.SplitTaskUnfoldAnimator;
import com.android.wm.shell.unfold.animation.UnfoldTaskAnimator;
import com.android.wm.shell.unfold.qualifier.UnfoldShellTransition;
import com.android.wm.shell.unfold.qualifier.UnfoldTransition;
import com.android.wm.shell.windowdecor.CaptionWindowDecorViewModel;
import com.android.wm.shell.windowdecor.DesktopModeWindowDecorViewModel;
import com.android.wm.shell.windowdecor.WindowDecorViewModel;
import java.util.ArrayList;
@@ -192,7 +192,7 @@ public abstract class WMShellModule {
SyncTransactionQueue syncQueue,
Optional<DesktopModeController> desktopModeController,
Optional<DesktopTasksController> desktopTasksController) {
return new CaptionWindowDecorViewModel(
return new DesktopModeWindowDecorViewModel(
context,
mainHandler,
mainChoreographer,

View File

@@ -61,12 +61,12 @@ import java.util.Optional;
/**
* View model for the window decoration with a caption and shadows. Works with
* {@link CaptionWindowDecoration}.
* {@link DesktopModeWindowDecoration}.
*/
public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
private static final String TAG = "CaptionViewModel";
private final CaptionWindowDecoration.Factory mCaptionWindowDecorFactory;
public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
private static final String TAG = "DesktopModeWindowDecorViewModel";
private final DesktopModeWindowDecoration.Factory mDesktopModeWindowDecorFactory;
private final ActivityTaskManager mActivityTaskManager;
private final ShellTaskOrganizer mTaskOrganizer;
private final Context mContext;
@@ -81,11 +81,12 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
private SparseArray<EventReceiver> mEventReceiversByDisplay = new SparseArray<>();
private final SparseArray<CaptionWindowDecoration> mWindowDecorByTaskId = new SparseArray<>();
private final SparseArray<DesktopModeWindowDecoration> mWindowDecorByTaskId =
new SparseArray<>();
private final DragStartListenerImpl mDragStartListener = new DragStartListenerImpl();
private InputMonitorFactory mInputMonitorFactory;
public CaptionWindowDecorViewModel(
public DesktopModeWindowDecorViewModel(
Context context,
Handler mainHandler,
Choreographer mainChoreographer,
@@ -103,12 +104,12 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
syncQueue,
desktopModeController,
desktopTasksController,
new CaptionWindowDecoration.Factory(),
new DesktopModeWindowDecoration.Factory(),
new InputMonitorFactory());
}
@VisibleForTesting
CaptionWindowDecorViewModel(
DesktopModeWindowDecorViewModel(
Context context,
Handler mainHandler,
Choreographer mainChoreographer,
@@ -117,7 +118,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
SyncTransactionQueue syncQueue,
Optional<DesktopModeController> desktopModeController,
Optional<DesktopTasksController> desktopTasksController,
CaptionWindowDecoration.Factory captionWindowDecorFactory,
DesktopModeWindowDecoration.Factory desktopModeWindowDecorFactory,
InputMonitorFactory inputMonitorFactory) {
mContext = context;
mMainHandler = mainHandler;
@@ -129,7 +130,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
mDesktopModeController = desktopModeController;
mDesktopTasksController = desktopTasksController;
mCaptionWindowDecorFactory = captionWindowDecorFactory;
mDesktopModeWindowDecorFactory = desktopModeWindowDecorFactory;
mInputMonitorFactory = inputMonitorFactory;
}
@@ -151,7 +152,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
@Override
public void onTaskInfoChanged(RunningTaskInfo taskInfo) {
final CaptionWindowDecoration decoration = mWindowDecorByTaskId.get(taskInfo.taskId);
final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(taskInfo.taskId);
if (decoration == null) return;
@@ -170,7 +171,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
SurfaceControl taskSurface,
SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) {
final CaptionWindowDecoration decoration = mWindowDecorByTaskId.get(taskInfo.taskId);
final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(taskInfo.taskId);
if (!shouldShowWindowDecor(taskInfo)) {
if (decoration != null) {
@@ -191,7 +192,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
RunningTaskInfo taskInfo,
SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) {
final CaptionWindowDecoration decoration = mWindowDecorByTaskId.get(taskInfo.taskId);
final DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(taskInfo.taskId);
if (decoration == null) return;
decoration.relayout(taskInfo, startT, finishT);
@@ -199,7 +200,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
@Override
public void destroyWindowDecoration(RunningTaskInfo taskInfo) {
final CaptionWindowDecoration decoration =
final DesktopModeWindowDecoration decoration =
mWindowDecorByTaskId.removeReturnOld(taskInfo.taskId);
if (decoration == null) return;
@@ -232,7 +233,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
@Override
public void onClick(View v) {
CaptionWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId);
DesktopModeWindowDecoration decoration = mWindowDecorByTaskId.get(mTaskId);
final int id = v.getId();
if (id == R.id.close_window) {
WindowContainerTransaction wct = new WindowContainerTransaction();
@@ -373,7 +374,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
boolean handled = false;
if (event instanceof MotionEvent) {
handled = true;
CaptionWindowDecorViewModel.this
DesktopModeWindowDecorViewModel.this
.handleReceivedMotionEvent((MotionEvent) event, mInputMonitor);
}
finishInputEvent(event, handled);
@@ -433,7 +434,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
*/
private void handleReceivedMotionEvent(MotionEvent ev, InputMonitor inputMonitor) {
if (DesktopModeStatus.isProto2Enabled()) {
CaptionWindowDecoration focusedDecor = getFocusedDecor();
DesktopModeWindowDecoration focusedDecor = getFocusedDecor();
if (focusedDecor == null
|| focusedDecor.mTaskInfo.getWindowingMode() != WINDOWING_MODE_FREEFORM) {
handleCaptionThroughStatusBar(ev);
@@ -460,7 +461,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
private void handleEventOutsideFocusedCaption(MotionEvent ev) {
int action = ev.getActionMasked();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
CaptionWindowDecoration focusedDecor = getFocusedDecor();
DesktopModeWindowDecoration focusedDecor = getFocusedDecor();
if (focusedDecor == null) {
return;
}
@@ -480,7 +481,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
// Begin drag through status bar if applicable.
CaptionWindowDecoration focusedDecor = getFocusedDecor();
DesktopModeWindowDecoration focusedDecor = getFocusedDecor();
if (focusedDecor != null) {
boolean dragFromStatusBarAllowed = false;
if (DesktopModeStatus.isProto2Enabled()) {
@@ -499,7 +500,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
break;
}
case MotionEvent.ACTION_UP: {
CaptionWindowDecoration focusedDecor = getFocusedDecor();
DesktopModeWindowDecoration focusedDecor = getFocusedDecor();
if (focusedDecor == null) {
mTransitionDragActive = false;
return;
@@ -529,11 +530,11 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
}
@Nullable
private CaptionWindowDecoration getFocusedDecor() {
private DesktopModeWindowDecoration getFocusedDecor() {
int size = mWindowDecorByTaskId.size();
CaptionWindowDecoration focusedDecor = null;
DesktopModeWindowDecoration focusedDecor = null;
for (int i = 0; i < size; i++) {
CaptionWindowDecoration decor = mWindowDecorByTaskId.valueAt(i);
DesktopModeWindowDecoration decor = mWindowDecorByTaskId.valueAt(i);
if (decor != null && decor.isFocused()) {
focusedDecor = decor;
break;
@@ -571,13 +572,13 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
SurfaceControl taskSurface,
SurfaceControl.Transaction startT,
SurfaceControl.Transaction finishT) {
CaptionWindowDecoration oldDecoration = mWindowDecorByTaskId.get(taskInfo.taskId);
DesktopModeWindowDecoration 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 =
mCaptionWindowDecorFactory.create(
final DesktopModeWindowDecoration windowDecoration =
mDesktopModeWindowDecorFactory.create(
mContext,
mDisplayController,
mTaskOrganizer,

View File

@@ -43,12 +43,12 @@ import com.android.wm.shell.desktopmode.DesktopModeStatus;
/**
* Defines visuals and behaviors of a window decoration of a caption bar and shadows. It works with
* {@link CaptionWindowDecorViewModel}. The caption bar contains a handle, back button, and close
* button.
* {@link DesktopModeWindowDecorViewModel}. The caption bar contains a handle, back button, and
* close button.
*
* The shadow's thickness is 20dp when the window is in focus and 5dp when the window isn't.
*/
public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearLayout> {
public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLinearLayout> {
private final Handler mHandler;
private final Choreographer mChoreographer;
private final SyncTransactionQueue mSyncQueue;
@@ -69,7 +69,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
private AdditionalWindow mHandleMenu;
CaptionWindowDecoration(
DesktopModeWindowDecoration(
Context context,
DisplayController displayController,
ShellTaskOrganizer taskOrganizer,
@@ -424,7 +424,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
static class Factory {
CaptionWindowDecoration create(
DesktopModeWindowDecoration create(
Context context,
DisplayController displayController,
ShellTaskOrganizer taskOrganizer,
@@ -433,7 +433,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
Handler handler,
Choreographer choreographer,
SyncTransactionQueue syncQueue) {
return new CaptionWindowDecoration(
return new DesktopModeWindowDecoration(
context,
displayController,
taskOrganizer,

View File

@@ -60,14 +60,14 @@ import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/** Tests of {@link CaptionWindowDecorViewModel} */
/** Tests of {@link DesktopModeWindowDecorViewModel} */
@SmallTest
public class CaptionWindowDecorViewModelTests extends ShellTestCase {
public class DesktopModeWindowDecorViewModelTests extends ShellTestCase {
private static final String TAG = "CaptionWindowDecorViewModelTests";
private static final String TAG = "DesktopModeWindowDecorViewModelTests";
@Mock private CaptionWindowDecoration mCaptionWindowDecoration;
@Mock private CaptionWindowDecoration.Factory mCaptionWindowDecorFactory;
@Mock private DesktopModeWindowDecoration mDesktopModeWindowDecoration;
@Mock private DesktopModeWindowDecoration.Factory mDesktopModeWindowDecorFactory;
@Mock private Handler mMainHandler;
@Mock private Choreographer mMainChoreographer;
@@ -79,17 +79,17 @@ public class CaptionWindowDecorViewModelTests extends ShellTestCase {
@Mock private InputMonitor mInputMonitor;
@Mock private InputManager mInputManager;
@Mock private CaptionWindowDecorViewModel.InputMonitorFactory mMockInputMonitorFactory;
@Mock private DesktopModeWindowDecorViewModel.InputMonitorFactory mMockInputMonitorFactory;
private final List<InputManager> mMockInputManagers = new ArrayList<>();
private CaptionWindowDecorViewModel mCaptionWindowDecorViewModel;
private DesktopModeWindowDecorViewModel mDesktopModeWindowDecorViewModel;
@Before
public void setUp() {
mMockInputManagers.add(mInputManager);
mCaptionWindowDecorViewModel =
new CaptionWindowDecorViewModel(
mDesktopModeWindowDecorViewModel =
new DesktopModeWindowDecorViewModel(
mContext,
mMainHandler,
mMainChoreographer,
@@ -98,12 +98,12 @@ public class CaptionWindowDecorViewModelTests extends ShellTestCase {
mSyncQueue,
Optional.of(mDesktopModeController),
Optional.of(mDesktopTasksController),
mCaptionWindowDecorFactory,
mDesktopModeWindowDecorFactory,
mMockInputMonitorFactory
);
doReturn(mCaptionWindowDecoration)
.when(mCaptionWindowDecorFactory)
doReturn(mDesktopModeWindowDecoration)
.when(mDesktopModeWindowDecorFactory)
.create(any(), any(), any(), any(), any(), any(), any(), any());
when(mMockInputMonitorFactory.create(any(), any())).thenReturn(mInputMonitor);
@@ -123,13 +123,15 @@ public class CaptionWindowDecorViewModelTests extends ShellTestCase {
final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
mCaptionWindowDecorViewModel.onTaskOpening(taskInfo, surfaceControl, startT, finishT);
mDesktopModeWindowDecorViewModel.onTaskOpening(
taskInfo, surfaceControl, startT, finishT);
taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_UNDEFINED);
taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
mDesktopModeWindowDecorViewModel.onTaskChanging(
taskInfo, surfaceControl, startT, finishT);
});
verify(mCaptionWindowDecorFactory)
verify(mDesktopModeWindowDecorFactory)
.create(
mContext,
mDisplayController,
@@ -139,7 +141,7 @@ public class CaptionWindowDecorViewModelTests extends ShellTestCase {
mMainHandler,
mMainChoreographer,
mSyncQueue);
verify(mCaptionWindowDecoration).close();
verify(mDesktopModeWindowDecoration).close();
}
@Test
@@ -153,14 +155,16 @@ public class CaptionWindowDecorViewModelTests extends ShellTestCase {
final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
mDesktopModeWindowDecorViewModel.onTaskChanging(
taskInfo, surfaceControl, startT, finishT);
taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
taskInfo.configuration.windowConfiguration.setActivityType(ACTIVITY_TYPE_STANDARD);
mCaptionWindowDecorViewModel.onTaskChanging(taskInfo, surfaceControl, startT, finishT);
mDesktopModeWindowDecorViewModel.onTaskChanging(
taskInfo, surfaceControl, startT, finishT);
});
verify(mCaptionWindowDecorFactory, times(1))
verify(mDesktopModeWindowDecorFactory, times(1))
.create(
mContext,
mDisplayController,
@@ -183,9 +187,10 @@ public class CaptionWindowDecorViewModelTests extends ShellTestCase {
final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
mCaptionWindowDecorViewModel.onTaskOpening(taskInfo, surfaceControl, startT, finishT);
mDesktopModeWindowDecorViewModel.onTaskOpening(
taskInfo, surfaceControl, startT, finishT);
mCaptionWindowDecorViewModel.destroyWindowDecoration(taskInfo);
mDesktopModeWindowDecorViewModel.destroyWindowDecoration(taskInfo);
});
verify(mMockInputMonitorFactory).create(any(), any());
verify(mInputMonitor).dispose();
@@ -214,13 +219,14 @@ public class CaptionWindowDecorViewModelTests extends ShellTestCase {
final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
final SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
mCaptionWindowDecorViewModel.onTaskOpening(taskInfo, surfaceControl, startT, finishT);
mCaptionWindowDecorViewModel.onTaskOpening(secondTaskInfo, surfaceControl,
mDesktopModeWindowDecorViewModel.onTaskOpening(taskInfo, surfaceControl, startT,
finishT);
mDesktopModeWindowDecorViewModel.onTaskOpening(secondTaskInfo, surfaceControl,
startT, finishT);
mCaptionWindowDecorViewModel.onTaskOpening(thirdTaskInfo, surfaceControl,
mDesktopModeWindowDecorViewModel.onTaskOpening(thirdTaskInfo, surfaceControl,
startT, finishT);
mCaptionWindowDecorViewModel.destroyWindowDecoration(thirdTaskInfo);
mCaptionWindowDecorViewModel.destroyWindowDecoration(taskInfo);
mDesktopModeWindowDecorViewModel.destroyWindowDecoration(thirdTaskInfo);
mDesktopModeWindowDecorViewModel.destroyWindowDecoration(taskInfo);
});
verify(mMockInputMonitorFactory, times(2)).create(any(), any());
verify(mInputMonitor, times(1)).dispose();