Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [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. |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 22 | import static android.view.Display.DEFAULT_DISPLAY; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 23 | |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 24 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast; |
| 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; |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 28 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 29 | import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 30 | |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 31 | import static org.junit.Assert.assertFalse; |
| 32 | import static org.junit.Assert.assertTrue; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 33 | import static org.junit.Assert.fail; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 34 | import static org.mockito.ArgumentMatchers.eq; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 35 | |
| 36 | import android.os.Binder; |
| 37 | import android.os.IInterface; |
| 38 | import android.platform.test.annotations.Presubmit; |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 39 | import android.util.SparseBooleanArray; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 40 | import android.view.IRecentsAnimationRunner; |
| 41 | import android.view.SurfaceControl; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 42 | |
| 43 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 44 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 45 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 46 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 47 | import org.junit.Before; |
| 48 | import org.junit.Test; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 49 | import org.mockito.Mock; |
| 50 | import org.mockito.MockitoAnnotations; |
| 51 | |
| 52 | /** |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 53 | * Build/Install/Run: |
| 54 | * atest FrameworksServicesTests:RecentsAnimationControllerTest |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 55 | */ |
| 56 | @SmallTest |
| 57 | @Presubmit |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 58 | public 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 Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 69 | MockitoAnnotations.initMocks(this); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 70 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 71 | when(mMockRunner.asBinder()).thenReturn(new Binder()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 72 | mController = new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks, |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 73 | 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 Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 95 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 96 | public void testCancelAfterRemove_expectIgnored() { |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 97 | 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 114 | @Test |
| 115 | public void testIncludedApps_expectTargetAndVisible() { |
| 116 | mWm.setRecentsAnimationController(mController); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 117 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 124 | mDisplayContent.getConfiguration().windowConfiguration.setRotation( |
| 125 | mDisplayContent.getRotation()); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 126 | 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 Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 134 | private static void verifyNoMoreInteractionsExceptAsBinder(IInterface binder) { |
| 135 | verify(binder, atLeast(0)).asBinder(); |
| 136 | verifyNoMoreInteractions(binder); |
| 137 | } |
| 138 | } |