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 | |
Wale Ogunwale | 0c9199b | 2019-02-14 08:02:24 -0800 | [diff] [blame] | 43 | import androidx.test.filters.FlakyTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 44 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 45 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 46 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 47 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 48 | import org.junit.Before; |
| 49 | import org.junit.Test; |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 50 | import org.mockito.Mock; |
| 51 | import org.mockito.MockitoAnnotations; |
| 52 | |
| 53 | /** |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 54 | * Build/Install/Run: |
| 55 | * atest FrameworksServicesTests:RecentsAnimationControllerTest |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 56 | */ |
| 57 | @SmallTest |
| 58 | @Presubmit |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 59 | public 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 Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 70 | MockitoAnnotations.initMocks(this); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 71 | |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 72 | when(mMockRunner.asBinder()).thenReturn(new Binder()); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 73 | mController = new RecentsAnimationController(mWm, mMockRunner, mAnimationCallbacks, |
Winson Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 74 | 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 Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 96 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 97 | public void testCancelAfterRemove_expectIgnored() { |
Winson Chung | 7906b3e | 2018-05-10 10:32:39 -0700 | [diff] [blame] | 98 | 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 115 | @Test |
Wale Ogunwale | 0c9199b | 2019-02-14 08:02:24 -0800 | [diff] [blame] | 116 | @FlakyTest(bugId = 117117823) |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 117 | public void testIncludedApps_expectTargetAndVisible() { |
| 118 | mWm.setRecentsAnimationController(mController); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 119 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 126 | mDisplayContent.getConfiguration().windowConfiguration.setRotation( |
| 127 | mDisplayContent.getRotation()); |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 128 | 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 Chung | da876c9 | 2018-04-05 18:31:06 -0700 | [diff] [blame] | 136 | private static void verifyNoMoreInteractionsExceptAsBinder(IInterface binder) { |
| 137 | verify(binder, atLeast(0)).asBinder(); |
| 138 | verifyNoMoreInteractions(binder); |
| 139 | } |
| 140 | } |