blob: eefd973112f5aaf32908af2364d524482399bef8 [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
Tadashi G. Takaoka18c909c2018-10-11 07:51:35 +000019import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Winson Chung0f7ec962018-05-03 18:03:15 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
21import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
22import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Tadashi G. Takaoka18c909c2018-10-11 07:51:35 +000023import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
24import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
Winson Chung0f7ec962018-05-03 18:03:15 -070025import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE;
26import static org.mockito.Mockito.any;
Tadashi G. Takaoka18c909c2018-10-11 07:51:35 +000027import static org.mockito.Mockito.anyInt;
Winson Chung0f7ec962018-05-03 18:03:15 -070028import static org.mockito.Mockito.doReturn;
29import static org.mockito.Mockito.eq;
30import static org.mockito.Mockito.mock;
31import static org.mockito.Mockito.times;
32import static org.mockito.Mockito.verify;
33
34import android.content.ComponentName;
35import android.content.Context;
36import android.content.Intent;
37import android.platform.test.annotations.Presubmit;
38import android.support.test.InstrumentationRegistry;
39import android.support.test.filters.MediumTest;
40import android.support.test.runner.AndroidJUnit4;
41import android.view.IRecentsAnimationRunner;
42import com.android.server.AttributeCache;
43import org.junit.Before;
44import org.junit.Test;
45import org.junit.runner.RunWith;
46
47/**
Tadashi G. Takaoka18c909c2018-10-11 07:51:35 +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 {
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}