Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1 | /* |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame^] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 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 |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame^] | 14 | * limitations under the License |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame^] | 17 | package com.android.server.wm; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 18 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 22 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 23 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 24 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 25 | import static org.mockito.Mockito.any; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 26 | import static org.mockito.Mockito.doReturn; |
| 27 | import static org.mockito.Mockito.eq; |
| 28 | import static org.mockito.Mockito.mock; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 29 | import static org.mockito.Mockito.spy; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 30 | import static org.mockito.Mockito.times; |
| 31 | import static org.mockito.Mockito.verify; |
| 32 | |
| 33 | import android.content.ComponentName; |
| 34 | import android.content.Context; |
| 35 | import android.content.Intent; |
| 36 | import android.platform.test.annotations.Presubmit; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 37 | import android.view.IRecentsAnimationRunner; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 38 | |
| 39 | import androidx.test.InstrumentationRegistry; |
| 40 | import androidx.test.filters.MediumTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 41 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 42 | import org.junit.Before; |
| 43 | import org.junit.Test; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 46 | * Build/Install/Run: |
| 47 | * atest WmTests:RecentsAnimationTest |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 48 | */ |
| 49 | @MediumTest |
| 50 | @Presubmit |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 51 | public class RecentsAnimationTest extends ActivityTestsBase { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 52 | |
| 53 | private Context mContext = InstrumentationRegistry.getContext(); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 54 | private TestActivityTaskManagerService mTestService; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 55 | private ComponentName mRecentsComponent; |
| 56 | |
| 57 | @Before |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 58 | public void setUp() throws Exception { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 59 | mRecentsComponent = new ComponentName(mContext.getPackageName(), "RecentsActivity"); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 60 | mTestService = spy(new MyTestActivityTaskManagerService(mContext)); |
| 61 | setupActivityManagerService(mTestService); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Test |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 65 | public void testCancelAnimationOnStackOrderChange() { |
| 66 | ActivityStack fullscreenStack = |
| 67 | mTestService.mStackSupervisor.getDefaultDisplay().createStack( |
| 68 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 69 | ActivityStack recentsStack = mTestService.mStackSupervisor.getDefaultDisplay().createStack( |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 70 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 71 | ActivityRecord recentsActivity = new ActivityBuilder(mTestService) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 72 | .setComponent(mRecentsComponent) |
| 73 | .setCreateTask(true) |
| 74 | .setStack(recentsStack) |
| 75 | .build(); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 76 | ActivityStack fullscreenStack2 = |
| 77 | mTestService.mStackSupervisor.getDefaultDisplay().createStack( |
| 78 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 79 | ActivityRecord fsActivity = new ActivityBuilder(mTestService) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 80 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 81 | .setCreateTask(true) |
| 82 | .setStack(fullscreenStack2) |
| 83 | .build(); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 84 | doReturn(true).when(mTestService.mWindowManager).canStartRecentsAnimation(); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 85 | |
| 86 | // Start the recents animation |
| 87 | Intent recentsIntent = new Intent(); |
| 88 | recentsIntent.setComponent(mRecentsComponent); |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 89 | mTestService.startRecentsActivity(recentsIntent, null, mock(IRecentsAnimationRunner.class)); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 90 | |
| 91 | fullscreenStack.moveToFront("Activity start"); |
| 92 | |
| 93 | // Ensure that the recents animation was canceled |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 94 | verify(mTestService.mWindowManager, times(1)).cancelRecentsAnimationSynchronously( |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 95 | eq(REORDER_KEEP_IN_PLACE), any()); |
| 96 | } |
| 97 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 98 | private class MyTestActivityTaskManagerService extends TestActivityTaskManagerService { |
| 99 | MyTestActivityTaskManagerService(Context context) { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 100 | super(context); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | protected RecentTasks createRecentTasks() { |
| 105 | RecentTasks recents = mock(RecentTasks.class); |
| 106 | doReturn(mRecentsComponent).when(recents).getRecentsComponent(); |
| 107 | System.out.println(mRecentsComponent); |
| 108 | return recents; |
| 109 | } |
| 110 | } |
| 111 | } |