blob: 763ea6293fcc0014d932723b11c4fe4fb155b881 [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
Wale Ogunwale0c9199b2019-02-14 08:02:24 -080043import androidx.test.filters.FlakyTest;
Brett Chabota26eda92018-07-23 13:08:30 -070044import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070045
Winson Chungda876c92018-04-05 18:31:06 -070046import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
Brett Chabota26eda92018-07-23 13:08:30 -070047
Winson Chungda876c92018-04-05 18:31:06 -070048import org.junit.Before;
49import org.junit.Test;
Winson Chungda876c92018-04-05 18:31:06 -070050import org.mockito.Mock;
51import org.mockito.MockitoAnnotations;
52
53/**
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070054 * Build/Install/Run:
55 * atest FrameworksServicesTests:RecentsAnimationControllerTest
Winson Chungda876c92018-04-05 18:31:06 -070056 */
57@SmallTest
58@Presubmit
Winson Chungda876c92018-04-05 18:31:06 -070059public class RecentsAnimationControllerTest extends WindowTestsBase {
60
61 @Mock SurfaceControl mMockLeash;
62 @Mock SurfaceControl.Transaction mMockTransaction;
63 @Mock OnAnimationFinishedCallback mFinishedCallback;
64 @Mock IRecentsAnimationRunner mMockRunner;
65 @Mock RecentsAnimationController.RecentsAnimationCallbacks mAnimationCallbacks;
66 private RecentsAnimationController mController;
67
68 @Before
69 public void setUp() throws Exception {
Winson Chungda876c92018-04-05 18:31:06 -070070 MockitoAnnotations.initMocks(this);
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070071
Winson Chungda876c92018-04-05 18:31:06 -070072 when(mMockRunner.asBinder()).thenReturn(new Binder());
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070073 mController = new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks,
Winson Chungda876c92018-04-05 18:31:06 -070074 DEFAULT_DISPLAY);
75 }
76
77 @Test
78 public void testRemovedBeforeStarted_expectCanceled() throws Exception {
79 final AppWindowToken appWindow = createAppWindowToken(mDisplayContent,
80 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
81 AnimationAdapter adapter = mController.addAnimation(appWindow.getTask(),
82 false /* isRecentTaskInvisible */);
83 adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback);
84
85 // Remove the app window so that the animation target can not be created
86 appWindow.removeImmediately();
87 mController.startAnimation();
88
89 // Verify that the finish callback to reparent the leash is called
90 verify(mFinishedCallback).onAnimationFinished(eq(adapter));
91 // Verify the animation canceled callback to the app was made
92 verify(mMockRunner).onAnimationCanceled();
93 verifyNoMoreInteractionsExceptAsBinder(mMockRunner);
94 }
95
Winson Chung7906b3e2018-05-10 10:32:39 -070096 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070097 public void testCancelAfterRemove_expectIgnored() {
Winson Chung7906b3e2018-05-10 10:32:39 -070098 final AppWindowToken appWindow = createAppWindowToken(mDisplayContent,
99 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
100 AnimationAdapter adapter = mController.addAnimation(appWindow.getTask(),
101 false /* isRecentTaskInvisible */);
102 adapter.startAnimation(mMockLeash, mMockTransaction, mFinishedCallback);
103
104 // Remove the app window so that the animation target can not be created
105 appWindow.removeImmediately();
106 mController.startAnimation();
107 mController.cleanupAnimation(REORDER_KEEP_IN_PLACE);
108 try {
109 mController.cancelAnimation(REORDER_MOVE_TO_ORIGINAL_POSITION, "test");
110 } catch (Exception e) {
111 fail("Unexpected failure when canceling animation after finishing it");
112 }
113 }
114
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700115 @Test
Wale Ogunwale0c9199b2019-02-14 08:02:24 -0800116 @FlakyTest(bugId = 117117823)
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700117 public void testIncludedApps_expectTargetAndVisible() {
118 mWm.setRecentsAnimationController(mController);
Winson Chung732446a2018-09-19 13:15:17 -0700119 final AppWindowToken homeAppWindow = createAppWindowToken(mDisplayContent,
120 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME);
121 final AppWindowToken appWindow = createAppWindowToken(mDisplayContent,
122 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
123 final AppWindowToken hiddenAppWindow = createAppWindowToken(mDisplayContent,
124 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
125 hiddenAppWindow.setHidden(true);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800126 mDisplayContent.getConfiguration().windowConfiguration.setRotation(
127 mDisplayContent.getRotation());
Winson Chung732446a2018-09-19 13:15:17 -0700128 mController.initialize(mDisplayContent, ACTIVITY_TYPE_HOME, new SparseBooleanArray());
129
130 // Ensure that we are animating the target activity as well
131 assertTrue(mController.isAnimatingTask(homeAppWindow.getTask()));
132 assertTrue(mController.isAnimatingTask(appWindow.getTask()));
133 assertFalse(mController.isAnimatingTask(hiddenAppWindow.getTask()));
134 }
135
Winson Chungda876c92018-04-05 18:31:06 -0700136 private static void verifyNoMoreInteractionsExceptAsBinder(IInterface binder) {
137 verify(binder, atLeast(0)).asBinder();
138 verifyNoMoreInteractions(binder);
139 }
140}