Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 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; |
| 41 | import androidx.test.runner.AndroidJUnit4; |
| 42 | |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 43 | import org.junit.Before; |
| 44 | import org.junit.Test; |
| 45 | import org.junit.runner.RunWith; |
| 46 | |
| 47 | /** |
John Reck | 3d294e7 | 2018-09-21 20:26:48 +0000 | [diff] [blame] | 48 | * atest FrameworksServicesTests:RecentsAnimationTest |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 49 | */ |
| 50 | @MediumTest |
| 51 | @Presubmit |
| 52 | @RunWith(AndroidJUnit4.class) |
| 53 | public class RecentsAnimationTest extends ActivityTestsBase { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 54 | |
| 55 | private Context mContext = InstrumentationRegistry.getContext(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 56 | private TestActivityTaskManagerService mService; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 57 | private ComponentName mRecentsComponent; |
| 58 | |
| 59 | @Before |
| 60 | @Override |
| 61 | public void setUp() throws Exception { |
| 62 | super.setUp(); |
| 63 | |
| 64 | mRecentsComponent = new ComponentName(mContext.getPackageName(), "RecentsActivity"); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 65 | mService = spy(new MyTestActivityTaskManagerService(mContext)); |
| 66 | setupActivityManagerService(mService); |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void testCancelAnimationOnStackOrderChange() throws Exception { |
| 71 | ActivityStack fullscreenStack = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 72 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 73 | ActivityStack recentsStack = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 74 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 75 | ActivityRecord recentsActivity = new ActivityBuilder(mService) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 76 | .setComponent(mRecentsComponent) |
| 77 | .setCreateTask(true) |
| 78 | .setStack(recentsStack) |
| 79 | .build(); |
| 80 | ActivityStack fullscreenStack2 = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 81 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 82 | ActivityRecord fsActivity = new ActivityBuilder(mService) |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 83 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 84 | .setCreateTask(true) |
| 85 | .setStack(fullscreenStack2) |
| 86 | .build(); |
| 87 | doReturn(true).when(mService.mWindowManager).canStartRecentsAnimation(); |
| 88 | |
| 89 | // Start the recents animation |
| 90 | Intent recentsIntent = new Intent(); |
| 91 | recentsIntent.setComponent(mRecentsComponent); |
| 92 | mService.startRecentsActivity(recentsIntent, null, mock(IRecentsAnimationRunner.class)); |
| 93 | |
| 94 | fullscreenStack.moveToFront("Activity start"); |
| 95 | |
| 96 | // Ensure that the recents animation was canceled |
| 97 | verify(mService.mWindowManager, times(1)).cancelRecentsAnimationSynchronously( |
| 98 | eq(REORDER_KEEP_IN_PLACE), any()); |
| 99 | } |
| 100 | |
Wale Ogunwale | 16e505a | 2018-05-07 15:00:49 -0700 | [diff] [blame] | 101 | private class MyTestActivityTaskManagerService extends TestActivityTaskManagerService { |
| 102 | MyTestActivityTaskManagerService(Context context) { |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 103 | super(context); |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | protected RecentTasks createRecentTasks() { |
| 108 | RecentTasks recents = mock(RecentTasks.class); |
| 109 | doReturn(mRecentsComponent).when(recents).getRecentsComponent(); |
| 110 | System.out.println(mRecentsComponent); |
| 111 | return recents; |
| 112 | } |
| 113 | } |
| 114 | } |