blob: 113f3c8e237c0b782df73b6b4fa07fa3a9b5428c [file] [log] [blame]
Jorim Jaggi02886a82016-12-06 09:10:06 -08001/*
2 * Copyright (C) 2016 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
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Jorim Jaggi02886a82016-12-06 09:10:06 -080015 */
16
17package com.android.server.wm;
18
19import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020020import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010021import static android.view.WindowManager.TRANSIT_UNSET;
Brett Chabota26eda92018-07-23 13:08:30 -070022
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070023import static com.android.server.wm.TaskSnapshotController.SNAPSHOT_MODE_APP_THEME;
24import static com.android.server.wm.TaskSnapshotController.SNAPSHOT_MODE_REAL;
Brett Chabota26eda92018-07-23 13:08:30 -070025
Tadashi G. Takaoka82eb7a52019-03-26 18:22:01 +090026import static org.junit.Assert.assertEquals;
Jorim Jaggi02886a82016-12-06 09:10:06 -080027
28import android.platform.test.annotations.Presubmit;
Jorim Jaggi02886a82016-12-06 09:10:06 -080029import android.util.ArraySet;
30
Brett Chabota26eda92018-07-23 13:08:30 -070031import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070032
Winson Chung23aa7b12018-02-01 11:41:43 -080033import com.google.android.collect.Sets;
Brett Chabota26eda92018-07-23 13:08:30 -070034
Jorim Jaggi02886a82016-12-06 09:10:06 -080035import org.junit.Test;
Jorim Jaggi02886a82016-12-06 09:10:06 -080036
37/**
38 * Test class for {@link TaskSnapshotController}.
39 *
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070040 * Build/Install/Run:
41 * * atest FrameworksServicesTests:TaskSnapshotControllerTest
Jorim Jaggi02886a82016-12-06 09:10:06 -080042 */
43@SmallTest
44@Presubmit
Jorim Jaggi02886a82016-12-06 09:10:06 -080045public class TaskSnapshotControllerTest extends WindowTestsBase {
46
47 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070048 public void testGetClosingApps_closing() {
Jorim Jaggi02886a82016-12-06 09:10:06 -080049 final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW,
50 "closingWindow");
Yunfan Chen1ee84ea2018-11-13 16:03:37 -080051 closingWindow.mAppToken.commitVisibility(null, false /* visible */, TRANSIT_UNSET,
Jorim Jaggi02886a82016-12-06 09:10:06 -080052 true /* performLayout */, false /* isVoiceInteraction */);
53 final ArraySet<AppWindowToken> closingApps = new ArraySet<>();
54 closingApps.add(closingWindow.mAppToken);
55 final ArraySet<Task> closingTasks = new ArraySet<>();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070056 mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks);
Jorim Jaggi02886a82016-12-06 09:10:06 -080057 assertEquals(1, closingTasks.size());
Bryce Lee6d410262017-02-28 15:30:17 -080058 assertEquals(closingWindow.mAppToken.getTask(), closingTasks.valueAt(0));
Jorim Jaggi02886a82016-12-06 09:10:06 -080059 }
60
61 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070062 public void testGetClosingApps_notClosing() {
Jorim Jaggi02886a82016-12-06 09:10:06 -080063 final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW,
64 "closingWindow");
65 final WindowState openingWindow = createAppWindow(closingWindow.getTask(),
66 FIRST_APPLICATION_WINDOW, "openingWindow");
Yunfan Chen1ee84ea2018-11-13 16:03:37 -080067 closingWindow.mAppToken.commitVisibility(null, false /* visible */, TRANSIT_UNSET,
Jorim Jaggi02886a82016-12-06 09:10:06 -080068 true /* performLayout */, false /* isVoiceInteraction */);
Yunfan Chen1ee84ea2018-11-13 16:03:37 -080069 openingWindow.mAppToken.commitVisibility(null, true /* visible */, TRANSIT_UNSET,
Jorim Jaggi02886a82016-12-06 09:10:06 -080070 true /* performLayout */, false /* isVoiceInteraction */);
71 final ArraySet<AppWindowToken> closingApps = new ArraySet<>();
72 closingApps.add(closingWindow.mAppToken);
73 final ArraySet<Task> closingTasks = new ArraySet<>();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070074 mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks);
Jorim Jaggi02886a82016-12-06 09:10:06 -080075 assertEquals(0, closingTasks.size());
76 }
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010077
78 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070079 public void testGetClosingApps_skipClosingAppsSnapshotTasks() {
Winson Chung23aa7b12018-02-01 11:41:43 -080080 final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW,
81 "closingWindow");
Yunfan Chen1ee84ea2018-11-13 16:03:37 -080082 closingWindow.mAppToken.commitVisibility(null, false /* visible */, TRANSIT_UNSET,
Winson Chung23aa7b12018-02-01 11:41:43 -080083 true /* performLayout */, false /* isVoiceInteraction */);
84 final ArraySet<AppWindowToken> closingApps = new ArraySet<>();
85 closingApps.add(closingWindow.mAppToken);
86 final ArraySet<Task> closingTasks = new ArraySet<>();
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070087 mWm.mTaskSnapshotController.addSkipClosingAppSnapshotTasks(
Winson Chung23aa7b12018-02-01 11:41:43 -080088 Sets.newArraySet(closingWindow.mAppToken.getTask()));
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070089 mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks);
Winson Chung23aa7b12018-02-01 11:41:43 -080090 assertEquals(0, closingTasks.size());
91 }
92
93 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070094 public void testGetSnapshotMode() {
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010095 final WindowState disabledWindow = createWindow(null,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070096 FIRST_APPLICATION_WINDOW, mDisplayContent, "disabledWindow");
Jorim Jaggid635a4a2017-05-03 15:21:26 +020097 disabledWindow.mAppToken.setDisablePreviewScreenshots(true);
Jorim Jaggi8f4fe6e2017-03-14 18:21:40 +010098 assertEquals(SNAPSHOT_MODE_APP_THEME,
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070099 mWm.mTaskSnapshotController.getSnapshotMode(disabledWindow.getTask()));
Jorim Jaggid635a4a2017-05-03 15:21:26 +0200100
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100101 final WindowState normalWindow = createWindow(null,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700102 FIRST_APPLICATION_WINDOW, mDisplayContent, "normalWindow");
Jorim Jaggi8f4fe6e2017-03-14 18:21:40 +0100103 assertEquals(SNAPSHOT_MODE_REAL,
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700104 mWm.mTaskSnapshotController.getSnapshotMode(normalWindow.getTask()));
Jorim Jaggid635a4a2017-05-03 15:21:26 +0200105
106 final WindowState secureWindow = createWindow(null,
107 FIRST_APPLICATION_WINDOW, mDisplayContent, "secureWindow");
108 secureWindow.mAttrs.flags |= FLAG_SECURE;
109 assertEquals(SNAPSHOT_MODE_APP_THEME,
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700110 mWm.mTaskSnapshotController.getSnapshotMode(secureWindow.getTask()));
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100111 }
Jorim Jaggi02886a82016-12-06 09:10:06 -0800112}