blob: 920796ed6a308b7e83c6427ca19bd90a49962bb5 [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
14 * limitations under the License
15 */
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;
Jorim Jaggi8f4fe6e2017-03-14 18:21:40 +010022import static com.android.server.wm.TaskSnapshotController.*;
Jorim Jaggi02886a82016-12-06 09:10:06 -080023import static junit.framework.Assert.assertEquals;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010024import static junit.framework.Assert.assertFalse;
25import static junit.framework.Assert.assertTrue;
Jorim Jaggi02886a82016-12-06 09:10:06 -080026
27import android.platform.test.annotations.Presubmit;
28import android.support.test.filters.SmallTest;
29import android.support.test.runner.AndroidJUnit4;
30import android.util.ArraySet;
31
32import org.junit.Test;
33import org.junit.runner.RunWith;
34
35/**
36 * Test class for {@link TaskSnapshotController}.
37 *
38 * runtest frameworks-services -c com.android.server.wm.TaskSnapshotControllerTest
39 */
40@SmallTest
41@Presubmit
42@RunWith(AndroidJUnit4.class)
43public class TaskSnapshotControllerTest extends WindowTestsBase {
44
45 @Test
46 public void testGetClosingApps_closing() throws Exception {
47 final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW,
48 "closingWindow");
49 closingWindow.mAppToken.setVisibility(null, false /* visible */, TRANSIT_UNSET,
50 true /* performLayout */, false /* isVoiceInteraction */);
51 final ArraySet<AppWindowToken> closingApps = new ArraySet<>();
52 closingApps.add(closingWindow.mAppToken);
53 final ArraySet<Task> closingTasks = new ArraySet<>();
54 sWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks);
55 assertEquals(1, closingTasks.size());
Bryce Lee6d410262017-02-28 15:30:17 -080056 assertEquals(closingWindow.mAppToken.getTask(), closingTasks.valueAt(0));
Jorim Jaggi02886a82016-12-06 09:10:06 -080057 }
58
59 @Test
60 public void testGetClosingApps_notClosing() throws Exception {
61 final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW,
62 "closingWindow");
63 final WindowState openingWindow = createAppWindow(closingWindow.getTask(),
64 FIRST_APPLICATION_WINDOW, "openingWindow");
65 closingWindow.mAppToken.setVisibility(null, false /* visible */, TRANSIT_UNSET,
66 true /* performLayout */, false /* isVoiceInteraction */);
67 openingWindow.mAppToken.setVisibility(null, true /* visible */, TRANSIT_UNSET,
68 true /* performLayout */, false /* isVoiceInteraction */);
69 final ArraySet<AppWindowToken> closingApps = new ArraySet<>();
70 closingApps.add(closingWindow.mAppToken);
71 final ArraySet<Task> closingTasks = new ArraySet<>();
72 sWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks);
73 assertEquals(0, closingTasks.size());
74 }
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010075
76 @Test
Jorim Jaggi8f4fe6e2017-03-14 18:21:40 +010077 public void testGetSnapshotMode() throws Exception {
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010078 final WindowState disabledWindow = createWindow(null,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070079 FIRST_APPLICATION_WINDOW, mDisplayContent, "disabledWindow");
Jorim Jaggid635a4a2017-05-03 15:21:26 +020080 disabledWindow.mAppToken.setDisablePreviewScreenshots(true);
Jorim Jaggi8f4fe6e2017-03-14 18:21:40 +010081 assertEquals(SNAPSHOT_MODE_APP_THEME,
82 sWm.mTaskSnapshotController.getSnapshotMode(disabledWindow.getTask()));
Jorim Jaggid635a4a2017-05-03 15:21:26 +020083
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010084 final WindowState normalWindow = createWindow(null,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070085 FIRST_APPLICATION_WINDOW, mDisplayContent, "normalWindow");
Jorim Jaggi8f4fe6e2017-03-14 18:21:40 +010086 assertEquals(SNAPSHOT_MODE_REAL,
87 sWm.mTaskSnapshotController.getSnapshotMode(normalWindow.getTask()));
Jorim Jaggid635a4a2017-05-03 15:21:26 +020088
89 final WindowState secureWindow = createWindow(null,
90 FIRST_APPLICATION_WINDOW, mDisplayContent, "secureWindow");
91 secureWindow.mAttrs.flags |= FLAG_SECURE;
92 assertEquals(SNAPSHOT_MODE_APP_THEME,
93 sWm.mTaskSnapshotController.getSnapshotMode(secureWindow.getTask()));
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +010094 }
Jorim Jaggi02886a82016-12-06 09:10:06 -080095}