blob: a01a3d90f7c6319230cad2fa2020b6c1cda6448d [file] [log] [blame]
Winson Chung0f7ec962018-05-03 18:03:15 -07001/*
Wale Ogunwale59507092018-10-29 09:00:30 -07002 * Copyright (C) 2018 The Android Open Source Project
Winson Chung0f7ec962018-05-03 18:03:15 -07003 *
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 Ogunwale59507092018-10-29 09:00:30 -070014 * limitations under the License
Winson Chung0f7ec962018-05-03 18:03:15 -070015 */
16
Wale Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Winson Chung0f7ec962018-05-03 18:03:15 -070018
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;
Brett Chabota26eda92018-07-23 13:08:30 -070041
Winson Chung0f7ec962018-05-03 18:03:15 -070042import org.junit.Before;
43import org.junit.Test;
Winson Chung0f7ec962018-05-03 18:03:15 -070044
45/**
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090046 * Build/Install/Run:
47 * atest WmTests:RecentsAnimationTest
Winson Chung0f7ec962018-05-03 18:03:15 -070048 */
49@MediumTest
50@Presubmit
Winson Chung0f7ec962018-05-03 18:03:15 -070051public class RecentsAnimationTest extends ActivityTestsBase {
Winson Chung0f7ec962018-05-03 18:03:15 -070052
53 private Context mContext = InstrumentationRegistry.getContext();
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090054 private TestActivityTaskManagerService mTestService;
Winson Chung0f7ec962018-05-03 18:03:15 -070055 private ComponentName mRecentsComponent;
56
57 @Before
Winson Chung0f7ec962018-05-03 18:03:15 -070058 public void setUp() throws Exception {
Winson Chung0f7ec962018-05-03 18:03:15 -070059 mRecentsComponent = new ComponentName(mContext.getPackageName(), "RecentsActivity");
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090060 mTestService = spy(new MyTestActivityTaskManagerService(mContext));
61 setupActivityManagerService(mTestService);
Winson Chung0f7ec962018-05-03 18:03:15 -070062 }
63
64 @Test
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090065 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 Chung0f7ec962018-05-03 18:03:15 -070070 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS, true /* onTop */);
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090071 ActivityRecord recentsActivity = new ActivityBuilder(mTestService)
Winson Chung0f7ec962018-05-03 18:03:15 -070072 .setComponent(mRecentsComponent)
73 .setCreateTask(true)
74 .setStack(recentsStack)
75 .build();
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090076 ActivityStack fullscreenStack2 =
77 mTestService.mStackSupervisor.getDefaultDisplay().createStack(
78 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */);
79 ActivityRecord fsActivity = new ActivityBuilder(mTestService)
Winson Chung0f7ec962018-05-03 18:03:15 -070080 .setComponent(new ComponentName(mContext.getPackageName(), "App1"))
81 .setCreateTask(true)
82 .setStack(fullscreenStack2)
83 .build();
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090084 doReturn(true).when(mTestService.mWindowManager).canStartRecentsAnimation();
Winson Chung0f7ec962018-05-03 18:03:15 -070085
86 // Start the recents animation
87 Intent recentsIntent = new Intent();
88 recentsIntent.setComponent(mRecentsComponent);
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090089 mTestService.startRecentsActivity(recentsIntent, null, mock(IRecentsAnimationRunner.class));
Winson Chung0f7ec962018-05-03 18:03:15 -070090
91 fullscreenStack.moveToFront("Activity start");
92
93 // Ensure that the recents animation was canceled
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090094 verify(mTestService.mWindowManager, times(1)).cancelRecentsAnimationSynchronously(
Winson Chung0f7ec962018-05-03 18:03:15 -070095 eq(REORDER_KEEP_IN_PLACE), any());
96 }
97
Wale Ogunwale16e505a2018-05-07 15:00:49 -070098 private class MyTestActivityTaskManagerService extends TestActivityTaskManagerService {
99 MyTestActivityTaskManagerService(Context context) {
Winson Chung0f7ec962018-05-03 18:03:15 -0700100 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}