Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1 | /* |
| 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 20 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 21 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 22 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 23 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 24 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 25 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
| 26 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoMoreInteractions; |
| 27 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 28 | import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; |
| 29 | import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_WINDOW_ANIMATION; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 30 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 31 | import static org.junit.Assert.assertEquals; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 32 | import static org.junit.Assert.assertNotNull; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 33 | import static org.mockito.ArgumentMatchers.eq; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 34 | import static org.mockito.Mockito.mock; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 35 | |
| 36 | import android.graphics.Point; |
| 37 | import android.graphics.Rect; |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 38 | import android.os.Binder; |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 39 | import android.os.IBinder; |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 40 | import android.os.IInterface; |
| 41 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 42 | import android.view.IRemoteAnimationFinishedCallback; |
| 43 | import android.view.IRemoteAnimationRunner; |
| 44 | import android.view.RemoteAnimationAdapter; |
| 45 | import android.view.RemoteAnimationTarget; |
| 46 | import android.view.SurfaceControl; |
| 47 | import android.view.SurfaceControl.Transaction; |
| 48 | |
Vishnu Nair | 1d3f237 | 2019-05-22 22:12:26 -0700 | [diff] [blame] | 49 | import androidx.test.filters.FlakyTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 50 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 51 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 52 | import com.android.server.testutils.OffsettableClock; |
| 53 | import com.android.server.testutils.TestHandler; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 54 | import com.android.server.wm.RemoteAnimationController.RemoteAnimationRecord; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 55 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
| 56 | |
| 57 | import org.junit.Before; |
| 58 | import org.junit.Test; |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 59 | import org.junit.runner.RunWith; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 60 | import org.mockito.ArgumentCaptor; |
| 61 | import org.mockito.Mock; |
| 62 | import org.mockito.MockitoAnnotations; |
| 63 | |
| 64 | /** |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 65 | * Build/Install/Run: |
Andrii Kulian | f5d1411 | 2019-10-31 17:37:54 -0700 | [diff] [blame] | 66 | * atest WmTests:RemoteAnimationControllerTest |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 67 | */ |
| 68 | @SmallTest |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 69 | @Presubmit |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 70 | @RunWith(WindowTestRunner.class) |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 71 | public class RemoteAnimationControllerTest extends WindowTestsBase { |
| 72 | |
| 73 | @Mock SurfaceControl mMockLeash; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 74 | @Mock SurfaceControl mMockThumbnailLeash; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 75 | @Mock Transaction mMockTransaction; |
| 76 | @Mock OnAnimationFinishedCallback mFinishedCallback; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 77 | @Mock OnAnimationFinishedCallback mThumbnailFinishedCallback; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 78 | @Mock IRemoteAnimationRunner mMockRunner; |
| 79 | private RemoteAnimationAdapter mAdapter; |
| 80 | private RemoteAnimationController mController; |
| 81 | private final OffsettableClock mClock = new OffsettableClock.Stopped(); |
| 82 | private TestHandler mHandler; |
| 83 | |
| 84 | @Before |
| 85 | public void setUp() throws Exception { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 86 | MockitoAnnotations.initMocks(this); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 87 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 88 | when(mMockRunner.asBinder()).thenReturn(new Binder()); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 89 | mAdapter = new RemoteAnimationAdapter(mMockRunner, 100, 50, true /* changeNeedsSnapshot */); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 90 | mAdapter.setCallingPidUid(123, 456); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 91 | runWithScissors(mWm.mH, () -> mHandler = new TestHandler(null, mClock), 0); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 92 | mController = new RemoteAnimationController(mWm, mAdapter, mHandler); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void testRun() throws Exception { |
| 97 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 98 | mDisplayContent.mOpeningApps.add(win.mActivityRecord); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 99 | try { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 100 | final AnimationAdapter adapter = mController.createRemoteAnimationRecord(win.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 101 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null).mAdapter; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 102 | adapter.startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_APP_TRANSITION, |
| 103 | mFinishedCallback); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 104 | mController.goodToGo(); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 105 | mWm.mAnimator.executeAfterPrepareSurfacesRunnables(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 106 | final ArgumentCaptor<RemoteAnimationTarget[]> appsCaptor = |
| 107 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 108 | final ArgumentCaptor<RemoteAnimationTarget[]> wallpapersCaptor = |
| 109 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 110 | final ArgumentCaptor<IRemoteAnimationFinishedCallback> finishedCaptor = |
| 111 | ArgumentCaptor.forClass(IRemoteAnimationFinishedCallback.class); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 112 | verify(mMockRunner).onAnimationStart(appsCaptor.capture(), wallpapersCaptor.capture(), |
| 113 | finishedCaptor.capture()); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 114 | assertEquals(1, appsCaptor.getValue().length); |
| 115 | final RemoteAnimationTarget app = appsCaptor.getValue()[0]; |
| 116 | assertEquals(new Point(50, 100), app.position); |
| 117 | assertEquals(new Rect(50, 100, 150, 150), app.sourceContainerBounds); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 118 | assertEquals(win.mActivityRecord.getPrefixOrderIndex(), app.prefixOrderIndex); |
| 119 | assertEquals(win.mActivityRecord.getTask().mTaskId, app.taskId); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 120 | assertEquals(mMockLeash, app.leash); |
| 121 | assertEquals(win.mWinAnimator.mLastClipRect, app.clipRect); |
| 122 | assertEquals(false, app.isTranslucent); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 123 | verify(mMockTransaction).setPosition(mMockLeash, app.position.x, app.position.y); |
Evan Rosky | b96326e | 2019-07-01 09:59:17 -0700 | [diff] [blame] | 124 | verify(mMockTransaction).setWindowCrop(mMockLeash, 100, 50); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 125 | |
| 126 | finishedCaptor.getValue().onAnimationFinished(); |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 127 | verify(mFinishedCallback).onAnimationFinished(eq(ANIMATION_TYPE_APP_TRANSITION), |
| 128 | eq(adapter)); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 129 | } finally { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 130 | mDisplayContent.mOpeningApps.clear(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
| 134 | @Test |
| 135 | public void testCancel() throws Exception { |
| 136 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 137 | final AnimationAdapter adapter = mController.createRemoteAnimationRecord(win.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 138 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null).mAdapter; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 139 | adapter.startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_APP_TRANSITION, |
| 140 | mFinishedCallback); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 141 | mController.goodToGo(); |
| 142 | |
| 143 | adapter.onAnimationCancelled(mMockLeash); |
| 144 | verify(mMockRunner).onAnimationCancelled(); |
| 145 | } |
| 146 | |
| 147 | @Test |
| 148 | public void testTimeout() throws Exception { |
| 149 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 150 | final AnimationAdapter adapter = mController.createRemoteAnimationRecord(win.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 151 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null).mAdapter; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 152 | adapter.startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_APP_TRANSITION, |
| 153 | mFinishedCallback); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 154 | mController.goodToGo(); |
| 155 | |
| 156 | mClock.fastForward(2500); |
| 157 | mHandler.timeAdvance(); |
| 158 | |
| 159 | verify(mMockRunner).onAnimationCancelled(); |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 160 | verify(mFinishedCallback).onAnimationFinished(eq(ANIMATION_TYPE_APP_TRANSITION), |
| 161 | eq(adapter)); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 162 | } |
Jorim Jaggi | 93f9fe3 | 2018-01-25 15:06:13 +0100 | [diff] [blame] | 163 | |
| 164 | @Test |
Jorim Jaggi | a19d781 | 2018-02-01 15:03:59 +0100 | [diff] [blame] | 165 | public void testTimeout_scaled() throws Exception { |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 166 | try { |
Tadashi G. Takaoka | 809cbc5 | 2018-12-19 14:11:30 +0900 | [diff] [blame] | 167 | mWm.setAnimationScale(2, 5.0f); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 168 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, |
| 169 | "testWin"); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 170 | final AnimationAdapter adapter = mController.createRemoteAnimationRecord( |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 171 | win.mActivityRecord, new Point(50, 100), null, new Rect(50, 100, 150, 150), |
| 172 | null).mAdapter; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 173 | adapter.startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_APP_TRANSITION, |
| 174 | mFinishedCallback); |
Jorim Jaggi | a19d781 | 2018-02-01 15:03:59 +0100 | [diff] [blame] | 175 | mController.goodToGo(); |
| 176 | |
| 177 | mClock.fastForward(2500); |
| 178 | mHandler.timeAdvance(); |
| 179 | |
| 180 | verify(mMockRunner, never()).onAnimationCancelled(); |
| 181 | |
| 182 | mClock.fastForward(10000); |
| 183 | mHandler.timeAdvance(); |
| 184 | |
| 185 | verify(mMockRunner).onAnimationCancelled(); |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 186 | verify(mFinishedCallback).onAnimationFinished(eq(ANIMATION_TYPE_APP_TRANSITION), |
| 187 | eq(adapter)); |
Jorim Jaggi | a19d781 | 2018-02-01 15:03:59 +0100 | [diff] [blame] | 188 | } finally { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 189 | mWm.setAnimationScale(2, 1.0f); |
Jorim Jaggi | a19d781 | 2018-02-01 15:03:59 +0100 | [diff] [blame] | 190 | } |
Jorim Jaggi | a19d781 | 2018-02-01 15:03:59 +0100 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 194 | public void testZeroAnimations() { |
Jorim Jaggi | 93f9fe3 | 2018-01-25 15:06:13 +0100 | [diff] [blame] | 195 | mController.goodToGo(); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 196 | verifyNoMoreInteractionsExceptAsBinder(mMockRunner); |
Jorim Jaggi | 93f9fe3 | 2018-01-25 15:06:13 +0100 | [diff] [blame] | 197 | } |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 198 | |
| 199 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 200 | public void testNotReallyStarted() { |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 201 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 202 | mController.createRemoteAnimationRecord(win.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 203 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 204 | mController.goodToGo(); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 205 | verifyNoMoreInteractionsExceptAsBinder(mMockRunner); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | @Test |
| 209 | public void testOneNotStarted() throws Exception { |
| 210 | final WindowState win1 = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin1"); |
| 211 | final WindowState win2 = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin2"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 212 | mController.createRemoteAnimationRecord(win1.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 213 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 214 | final AnimationAdapter adapter = mController.createRemoteAnimationRecord(win2.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 215 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null).mAdapter; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 216 | adapter.startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_APP_TRANSITION, |
| 217 | mFinishedCallback); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 218 | mController.goodToGo(); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 219 | mWm.mAnimator.executeAfterPrepareSurfacesRunnables(); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 220 | final ArgumentCaptor<RemoteAnimationTarget[]> appsCaptor = |
| 221 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 222 | final ArgumentCaptor<RemoteAnimationTarget[]> wallpapersCaptor = |
| 223 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 224 | final ArgumentCaptor<IRemoteAnimationFinishedCallback> finishedCaptor = |
| 225 | ArgumentCaptor.forClass(IRemoteAnimationFinishedCallback.class); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 226 | verify(mMockRunner).onAnimationStart(appsCaptor.capture(), wallpapersCaptor.capture(), |
| 227 | finishedCaptor.capture()); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 228 | assertEquals(1, appsCaptor.getValue().length); |
| 229 | assertEquals(mMockLeash, appsCaptor.getValue()[0].leash); |
| 230 | } |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 231 | |
| 232 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 233 | public void testRemovedBeforeStarted() { |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 234 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 235 | final AnimationAdapter adapter = mController.createRemoteAnimationRecord(win.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 236 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null).mAdapter; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 237 | adapter.startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_APP_TRANSITION, |
| 238 | mFinishedCallback); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 239 | win.mActivityRecord.removeImmediately(); |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 240 | mController.goodToGo(); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 241 | verifyNoMoreInteractionsExceptAsBinder(mMockRunner); |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 242 | verify(mFinishedCallback).onAnimationFinished(eq(ANIMATION_TYPE_APP_TRANSITION), |
| 243 | eq(adapter)); |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 244 | } |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 245 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 246 | @Test |
| 247 | public void testChange() throws Exception { |
| 248 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 249 | mDisplayContent.mChangingContainers.add(win.mActivityRecord); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 250 | try { |
| 251 | final RemoteAnimationRecord record = mController.createRemoteAnimationRecord( |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 252 | win.mActivityRecord, new Point(50, 100), null, new Rect(50, 100, 150, 150), |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 253 | new Rect(0, 0, 200, 200)); |
| 254 | assertNotNull(record.mThumbnailAdapter); |
| 255 | ((AnimationAdapter) record.mAdapter) |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 256 | .startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_WINDOW_ANIMATION, |
| 257 | mFinishedCallback); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 258 | ((AnimationAdapter) record.mThumbnailAdapter).startAnimation(mMockThumbnailLeash, |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 259 | mMockTransaction, ANIMATION_TYPE_WINDOW_ANIMATION, mThumbnailFinishedCallback); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 260 | mController.goodToGo(); |
| 261 | mWm.mAnimator.executeAfterPrepareSurfacesRunnables(); |
| 262 | final ArgumentCaptor<RemoteAnimationTarget[]> appsCaptor = |
| 263 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 264 | final ArgumentCaptor<RemoteAnimationTarget[]> wallpapersCaptor = |
| 265 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 266 | final ArgumentCaptor<IRemoteAnimationFinishedCallback> finishedCaptor = |
| 267 | ArgumentCaptor.forClass(IRemoteAnimationFinishedCallback.class); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 268 | verify(mMockRunner).onAnimationStart(appsCaptor.capture(), wallpapersCaptor.capture(), |
| 269 | finishedCaptor.capture()); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 270 | assertEquals(1, appsCaptor.getValue().length); |
| 271 | final RemoteAnimationTarget app = appsCaptor.getValue()[0]; |
| 272 | assertEquals(RemoteAnimationTarget.MODE_CHANGING, app.mode); |
| 273 | assertEquals(new Point(50, 100), app.position); |
| 274 | assertEquals(new Rect(50, 100, 150, 150), app.sourceContainerBounds); |
| 275 | assertEquals(new Rect(0, 0, 200, 200), app.startBounds); |
| 276 | assertEquals(mMockLeash, app.leash); |
| 277 | assertEquals(mMockThumbnailLeash, app.startLeash); |
| 278 | assertEquals(win.mWinAnimator.mLastClipRect, app.clipRect); |
| 279 | assertEquals(false, app.isTranslucent); |
Evan Rosky | b96326e | 2019-07-01 09:59:17 -0700 | [diff] [blame] | 280 | verify(mMockTransaction).setPosition( |
| 281 | mMockLeash, app.startBounds.left, app.startBounds.top); |
| 282 | verify(mMockTransaction).setWindowCrop(mMockLeash, 200, 200); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 283 | verify(mMockTransaction).setPosition(mMockThumbnailLeash, 0, 0); |
| 284 | |
| 285 | finishedCaptor.getValue().onAnimationFinished(); |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 286 | verify(mFinishedCallback).onAnimationFinished(eq(ANIMATION_TYPE_WINDOW_ANIMATION), |
| 287 | eq(record.mAdapter)); |
| 288 | verify(mThumbnailFinishedCallback).onAnimationFinished( |
| 289 | eq(ANIMATION_TYPE_WINDOW_ANIMATION), eq(record.mThumbnailAdapter)); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 290 | } finally { |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 291 | mDisplayContent.mChangingContainers.clear(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 295 | @Test |
| 296 | public void testWallpaperIncluded_expectTarget() throws Exception { |
| 297 | final WindowToken wallpaperWindowToken = new WallpaperWindowToken(mWm, mock(IBinder.class), |
| 298 | true, mDisplayContent, true /* ownerCanManageAppTokens */); |
| 299 | spyOn(mDisplayContent.mWallpaperController); |
| 300 | doReturn(true).when(mDisplayContent.mWallpaperController).isWallpaperVisible(); |
| 301 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 302 | mDisplayContent.mOpeningApps.add(win.mActivityRecord); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 303 | try { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 304 | final AnimationAdapter adapter = mController.createRemoteAnimationRecord(win.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 305 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null).mAdapter; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 306 | adapter.startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_APP_TRANSITION, |
| 307 | mFinishedCallback); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 308 | mController.goodToGo(); |
| 309 | mWm.mAnimator.executeAfterPrepareSurfacesRunnables(); |
| 310 | final ArgumentCaptor<RemoteAnimationTarget[]> appsCaptor = |
| 311 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
| 312 | final ArgumentCaptor<RemoteAnimationTarget[]> wallpapersCaptor = |
| 313 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
| 314 | final ArgumentCaptor<IRemoteAnimationFinishedCallback> finishedCaptor = |
| 315 | ArgumentCaptor.forClass(IRemoteAnimationFinishedCallback.class); |
| 316 | verify(mMockRunner).onAnimationStart(appsCaptor.capture(), wallpapersCaptor.capture(), |
| 317 | finishedCaptor.capture()); |
| 318 | assertEquals(1, wallpapersCaptor.getValue().length); |
| 319 | } finally { |
| 320 | mDisplayContent.mOpeningApps.clear(); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | @Test |
| 325 | public void testWallpaperAnimatorCanceled_expectAnimationKeepsRunning() throws Exception { |
| 326 | final WindowToken wallpaperWindowToken = new WallpaperWindowToken(mWm, mock(IBinder.class), |
| 327 | true, mDisplayContent, true /* ownerCanManageAppTokens */); |
| 328 | spyOn(mDisplayContent.mWallpaperController); |
| 329 | doReturn(true).when(mDisplayContent.mWallpaperController).isWallpaperVisible(); |
| 330 | final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, "testWin"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 331 | mDisplayContent.mOpeningApps.add(win.mActivityRecord); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 332 | try { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 333 | final AnimationAdapter adapter = mController.createRemoteAnimationRecord(win.mActivityRecord, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 334 | new Point(50, 100), null, new Rect(50, 100, 150, 150), null).mAdapter; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 335 | adapter.startAnimation(mMockLeash, mMockTransaction, ANIMATION_TYPE_APP_TRANSITION, |
| 336 | mFinishedCallback); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 337 | mController.goodToGo(); |
| 338 | mWm.mAnimator.executeAfterPrepareSurfacesRunnables(); |
| 339 | final ArgumentCaptor<RemoteAnimationTarget[]> appsCaptor = |
| 340 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
| 341 | final ArgumentCaptor<RemoteAnimationTarget[]> wallpapersCaptor = |
| 342 | ArgumentCaptor.forClass(RemoteAnimationTarget[].class); |
| 343 | final ArgumentCaptor<IRemoteAnimationFinishedCallback> finishedCaptor = |
| 344 | ArgumentCaptor.forClass(IRemoteAnimationFinishedCallback.class); |
| 345 | verify(mMockRunner).onAnimationStart(appsCaptor.capture(), wallpapersCaptor.capture(), |
| 346 | finishedCaptor.capture()); |
| 347 | assertEquals(1, wallpapersCaptor.getValue().length); |
| 348 | |
| 349 | // Cancel the wallpaper window animator and ensure the runner is not canceled |
| 350 | wallpaperWindowToken.cancelAnimation(); |
| 351 | verify(mMockRunner, never()).onAnimationCancelled(); |
| 352 | } finally { |
| 353 | mDisplayContent.mOpeningApps.clear(); |
| 354 | } |
| 355 | } |
| 356 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 357 | private static void verifyNoMoreInteractionsExceptAsBinder(IInterface binder) { |
| 358 | verify(binder, atLeast(0)).asBinder(); |
| 359 | verifyNoMoreInteractions(binder); |
| 360 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 361 | } |