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 | |
Tadashi G. Takaoka | 18c909c | 2018-10-11 07:51:35 +0000 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
| 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Tadashi G. Takaoka | 18c909c | 2018-10-11 07:51:35 +0000 | [diff] [blame] | 23 | import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; |
| 24 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 25 | import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE; |
| 26 | import static org.mockito.Mockito.any; |
Tadashi G. Takaoka | 18c909c | 2018-10-11 07:51:35 +0000 | [diff] [blame] | 27 | import static org.mockito.Mockito.anyInt; |
Winson Chung | 0f7ec96 | 2018-05-03 18:03:15 -0700 | [diff] [blame] | 28 | import static org.mockito.Mockito.doReturn; |
| 29 | import static org.mockito.Mockito.eq; |
| 30 | import static org.mockito.Mockito.mock; |
| 31 | import static org.mockito.Mockito.times; |
| 32 | import static org.mockito.Mockito.verify; |
| 33 | |
| 34 | import android.content.ComponentName; |
| 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
| 37 | import android.platform.test.annotations.Presubmit; |
| 38 | import android.support.test.InstrumentationRegistry; |
| 39 | import android.support.test.filters.MediumTest; |
| 40 | import android.support.test.runner.AndroidJUnit4; |
| 41 | import android.view.IRecentsAnimationRunner; |
| 42 | import com.android.server.AttributeCache; |
| 43 | import org.junit.Before; |
| 44 | import org.junit.Test; |
| 45 | import org.junit.runner.RunWith; |
| 46 | |
| 47 | /** |
Tadashi G. Takaoka | 18c909c | 2018-10-11 07:51:35 +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 { |
| 54 | private static final int TEST_CALLING_PID = 3; |
| 55 | |
| 56 | private Context mContext = InstrumentationRegistry.getContext(); |
| 57 | private ActivityManagerService mService; |
| 58 | private ComponentName mRecentsComponent; |
| 59 | |
| 60 | @Before |
| 61 | @Override |
| 62 | public void setUp() throws Exception { |
| 63 | super.setUp(); |
| 64 | |
| 65 | mRecentsComponent = new ComponentName(mContext.getPackageName(), "RecentsActivity"); |
| 66 | mService = setupActivityManagerService(new MyTestActivityManagerService(mContext)); |
| 67 | AttributeCache.init(mContext); |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void testCancelAnimationOnStackOrderChange() throws Exception { |
| 72 | ActivityStack fullscreenStack = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 73 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 74 | ActivityStack recentsStack = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 75 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */); |
| 76 | ActivityRecord recentsActivity = new ActivityBuilder(mService) |
| 77 | .setComponent(mRecentsComponent) |
| 78 | .setCreateTask(true) |
| 79 | .setStack(recentsStack) |
| 80 | .build(); |
| 81 | ActivityStack fullscreenStack2 = mService.mStackSupervisor.getDefaultDisplay().createStack( |
| 82 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */); |
| 83 | ActivityRecord fsActivity = new ActivityBuilder(mService) |
| 84 | .setComponent(new ComponentName(mContext.getPackageName(), "App1")) |
| 85 | .setCreateTask(true) |
| 86 | .setStack(fullscreenStack2) |
| 87 | .build(); |
| 88 | doReturn(true).when(mService.mWindowManager).canStartRecentsAnimation(); |
| 89 | |
| 90 | // Start the recents animation |
| 91 | Intent recentsIntent = new Intent(); |
| 92 | recentsIntent.setComponent(mRecentsComponent); |
| 93 | mService.startRecentsActivity(recentsIntent, null, mock(IRecentsAnimationRunner.class)); |
| 94 | |
| 95 | fullscreenStack.moveToFront("Activity start"); |
| 96 | |
| 97 | // Ensure that the recents animation was canceled |
| 98 | verify(mService.mWindowManager, times(1)).cancelRecentsAnimationSynchronously( |
| 99 | eq(REORDER_KEEP_IN_PLACE), any()); |
| 100 | } |
| 101 | |
| 102 | private class MyTestActivityManagerService extends TestActivityManagerService { |
| 103 | MyTestActivityManagerService(Context context) { |
| 104 | super(context); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | protected RecentTasks createRecentTasks() { |
| 109 | RecentTasks recents = mock(RecentTasks.class); |
| 110 | doReturn(mRecentsComponent).when(recents).getRecentsComponent(); |
| 111 | System.out.println(mRecentsComponent); |
| 112 | return recents; |
| 113 | } |
| 114 | } |
| 115 | } |