1/* 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; 20import static android.view.WindowManager.LayoutParams.FLAG_SECURE; 21import static com.android.server.wm.AppTransition.TRANSIT_UNSET; 22import static com.android.server.wm.TaskSnapshotController.*; 23import static junit.framework.Assert.assertEquals; 24import static junit.framework.Assert.assertFalse; 25import static junit.framework.Assert.assertTrue; 26 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()); 56 assertEquals(closingWindow.mAppToken.getTask(), closingTasks.valueAt(0)); 57 } 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 } 75 76 @Test 77 public void testGetSnapshotMode() throws Exception { 78 final WindowState disabledWindow = createWindow(null, 79 FIRST_APPLICATION_WINDOW, mDisplayContent, "disabledWindow"); 80 disabledWindow.mAppToken.setDisablePreviewScreenshots(true); 81 assertEquals(SNAPSHOT_MODE_APP_THEME, 82 sWm.mTaskSnapshotController.getSnapshotMode(disabledWindow.getTask())); 83 84 final WindowState normalWindow = createWindow(null, 85 FIRST_APPLICATION_WINDOW, mDisplayContent, "normalWindow"); 86 assertEquals(SNAPSHOT_MODE_REAL, 87 sWm.mTaskSnapshotController.getSnapshotMode(normalWindow.getTask())); 88 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())); 94 } 95} 96