blob: f15b5f7f04b022cf2d4e4c8d029548e3474b7b0e [file] [log] [blame]
Winson Chung0f7ec962018-05-03 18:03:15 -07001/*
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
17package com.android.server.am;
18
Winson Chung0f7ec962018-05-03 18:03:15 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
20import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
21import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Brett Chabota26eda92018-07-23 13:08:30 -070022
Winson Chung0f7ec962018-05-03 18:03:15 -070023import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE;
Brett Chabota26eda92018-07-23 13:08:30 -070024
Winson Chung0f7ec962018-05-03 18:03:15 -070025import static org.mockito.Mockito.any;
Winson Chung0f7ec962018-05-03 18:03:15 -070026import static org.mockito.Mockito.doReturn;
27import static org.mockito.Mockito.eq;
28import static org.mockito.Mockito.mock;
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070029import static org.mockito.Mockito.spy;
Winson Chung0f7ec962018-05-03 18:03:15 -070030import static org.mockito.Mockito.times;
31import static org.mockito.Mockito.verify;
32
33import android.content.ComponentName;
34import android.content.Context;
35import android.content.Intent;
36import android.platform.test.annotations.Presubmit;
Winson Chung0f7ec962018-05-03 18:03:15 -070037import android.view.IRecentsAnimationRunner;
Brett Chabota26eda92018-07-23 13:08:30 -070038
39import androidx.test.InstrumentationRegistry;
40import androidx.test.filters.MediumTest;
41import androidx.test.runner.AndroidJUnit4;
42
Winson Chung0f7ec962018-05-03 18:03:15 -070043import org.junit.Before;
44import org.junit.Test;
45import org.junit.runner.RunWith;
46
47/**
John Reck3d294e72018-09-21 20:26:48 +000048 * atest FrameworksServicesTests:RecentsAnimationTest
Winson Chung0f7ec962018-05-03 18:03:15 -070049 */
50@MediumTest
51@Presubmit
52@RunWith(AndroidJUnit4.class)
53public class RecentsAnimationTest extends ActivityTestsBase {
Winson Chung0f7ec962018-05-03 18:03:15 -070054
55 private Context mContext = InstrumentationRegistry.getContext();
Wale Ogunwale9e4f3e02018-05-17 09:35:39 -070056 private TestActivityTaskManagerService mService;
Winson Chung0f7ec962018-05-03 18:03:15 -070057 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 Ogunwale9e4f3e02018-05-17 09:35:39 -070065 mService = spy(new MyTestActivityTaskManagerService(mContext));
66 setupActivityManagerService(mService);
Winson Chung0f7ec962018-05-03 18:03:15 -070067 }
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 Ogunwale9e4f3e02018-05-17 09:35:39 -070075 ActivityRecord recentsActivity = new ActivityBuilder(mService)
Winson Chung0f7ec962018-05-03 18:03:15 -070076 .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 Ogunwale9e4f3e02018-05-17 09:35:39 -070082 ActivityRecord fsActivity = new ActivityBuilder(mService)
Winson Chung0f7ec962018-05-03 18:03:15 -070083 .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 Ogunwale16e505a2018-05-07 15:00:49 -0700101 private class MyTestActivityTaskManagerService extends TestActivityTaskManagerService {
102 MyTestActivityTaskManagerService(Context context) {
Winson Chung0f7ec962018-05-03 18:03:15 -0700103 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}