blob: a03d28b470575e3d42b64570bfeaa0de0e523d1e [file] [log] [blame]
Winson Chungda876c92018-04-05 18:31:06 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Winson Chungda876c92018-04-05 18:31:06 -070015 */
16
17package com.android.server.wm;
18
Winson Chung732446a2018-09-19 13:15:17 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Winson Chungda876c92018-04-05 18:31:06 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
21import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
22import static android.view.Display.DEFAULT_DISPLAY;
Brett Chabota26eda92018-07-23 13:08:30 -070023
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090024import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast;
25import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
26import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoMoreInteractions;
27import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
Winson Chung7906b3e2018-05-10 10:32:39 -070028import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE;
29import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION;
Brett Chabota26eda92018-07-23 13:08:30 -070030
Winson Chung732446a2018-09-19 13:15:17 -070031import static org.junit.Assert.assertFalse;
32import static org.junit.Assert.assertTrue;
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070033import static org.junit.Assert.fail;
Winson Chungda876c92018-04-05 18:31:06 -070034import static org.mockito.ArgumentMatchers.eq;
Winson Chungda876c92018-04-05 18:31:06 -070035
36import android.os.Binder;
37import android.os.IInterface;
38import android.platform.test.annotations.Presubmit;
Winson Chung732446a2018-09-19 13:15:17 -070039import android.util.SparseBooleanArray;
Winson Chungda876c92018-04-05 18:31:06 -070040import android.view.IRecentsAnimationRunner;
41import android.view.SurfaceControl;
Brett Chabota26eda92018-07-23 13:08:30 -070042
43import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070044
Winson Chungda876c92018-04-05 18:31:06 -070045import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
Brett Chabota26eda92018-07-23 13:08:30 -070046
Winson Chungda876c92018-04-05 18:31:06 -070047import org.junit.Before;
48import org.junit.Test;
Winson Chungda876c92018-04-05 18:31:06 -070049import org.mockito.Mock;
50import org.mockito.MockitoAnnotations;
51
52/**
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070053 * Build/Install/Run:
54 * atest FrameworksServicesTests:RecentsAnimationControllerTest
Winson Chungda876c92018-04-05 18:31:06 -070055 */
56@SmallTest
57@Presubmit
Winson Chungda876c92018-04-05 18:31:06 -070058public class RecentsAnimationControllerTest extends WindowTestsBase {
59
60 @Mock SurfaceControl mMockLeash;
61 @Mock SurfaceControl.Transaction mMockTransaction;
62 @Mock OnAnimationFinishedCallback mFinishedCallback;
63 @Mock IRecentsAnimationRunner mMockRunner;
64 @Mock RecentsAnimationController.RecentsAnimationCallbacks mAnimationCallbacks;
65 private RecentsAnimationController mController;
66
67 @Before
68 public void setUp() throws Exception {
Winson Chungda876c92018-04-05 18:31:06 -070069 MockitoAnnotations.initMocks(this);
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070070
Winson Chungda876c92018-04-05 18:31:06 -070071 when(mMockRunner.asBinder()).thenReturn(new Binder());
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070072 mController = new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks,
Winson Chungda876c92018-04-05 18:31:06 -070073 DEFAULT_DISPLAY);
74 }
75
76 @Test
77 public void testRemovedBeforeStarted_expectCanceled() throws Exception {
78 final AppWindowToken appWindow = createAppWindowToken(mDisplayContent,
79 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
80 AnimationAdapter adapter = mController.addAnimation(appWindow.getTask(),
81 false /* isRecentTaskInvisible */);
82 adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback);
83
84 // Remove the app window so that the animation target can not be created
85 appWindow.removeImmediately();
86 mController.startAnimation();
87
88 // Verify that the finish callback to reparent the leash is called
89 verify(mFinishedCallback).onAnimationFinished(eq(adapter));
90 // Verify the animation canceled callback to the app was made
91 verify(mMockRunner).onAnimationCanceled();
92 verifyNoMoreInteractionsExceptAsBinder(mMockRunner);
93 }
94
Winson Chung7906b3e2018-05-10 10:32:39 -070095 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070096 public void testCancelAfterRemove_expectIgnored() {
Winson Chung7906b3e2018-05-10 10:32:39 -070097 final AppWindowToken appWindow = createAppWindowToken(mDisplayContent,
98 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
99 AnimationAdapter adapter = mController.addAnimation(appWindow.getTask(),
100 false /* isRecentTaskInvisible */);
101 adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback);
102
103 // Remove the app window so that the animation target can not be created
104 appWindow.removeImmediately();
105 mController.startAnimation();
106 mController.cleanupAnimation(REORDER_KEEP_IN_PLACE);
107 try {
108 mController.cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "test");
109 } catch (Exception e) {
110 fail("Unexpected failure when canceling animation after finishing it");
111 }
112 }
113
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700114 @Test
115 public void testIncludedApps_expectTargetAndVisible() {
116 mWm.setRecentsAnimationController(mController);
Winson Chung732446a2018-09-19 13:15:17 -0700117 final AppWindowToken homeAppWindow = createAppWindowToken(mDisplayContent,
118 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME);
119 final AppWindowToken appWindow = createAppWindowToken(mDisplayContent,
120 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
121 final AppWindowToken hiddenAppWindow = createAppWindowToken(mDisplayContent,
122 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
123 hiddenAppWindow.setHidden(true);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800124 mDisplayContent.getConfiguration().windowConfiguration.setRotation(
125 mDisplayContent.getRotation());
Winson Chung732446a2018-09-19 13:15:17 -0700126 mController.initialize(mDisplayContent, ACTIVITY_TYPE_HOME, new SparseBooleanArray());
127
128 // Ensure that we are animating the target activity as well
129 assertTrue(mController.isAnimatingTask(homeAppWindow.getTask()));
130 assertTrue(mController.isAnimatingTask(appWindow.getTask()));
131 assertFalse(mController.isAnimatingTask(hiddenAppWindow.getTask()));
132 }
133
Winson Chungda876c92018-04-05 18:31:06 -0700134 private static void verifyNoMoreInteractionsExceptAsBinder(IInterface binder) {
135 verify(binder, atLeast(0)).asBinder();
136 verifyNoMoreInteractions(binder);
137 }
138}