Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame^] | 21 | import static android.view.WindowManager.TRANSIT_UNSET; |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 22 | import static com.android.server.wm.TaskSnapshotController.*; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 23 | import static junit.framework.Assert.assertEquals; |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 24 | import static junit.framework.Assert.assertFalse; |
| 25 | import static junit.framework.Assert.assertTrue; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 26 | |
| 27 | import android.platform.test.annotations.Presubmit; |
| 28 | import android.support.test.filters.SmallTest; |
| 29 | import android.support.test.runner.AndroidJUnit4; |
| 30 | import android.util.ArraySet; |
| 31 | |
| 32 | import org.junit.Test; |
| 33 | import 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) |
| 43 | public 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 Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 56 | assertEquals(closingWindow.mAppToken.getTask(), closingTasks.valueAt(0)); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 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 | } |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 75 | |
| 76 | @Test |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 77 | public void testGetSnapshotMode() throws Exception { |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 78 | final WindowState disabledWindow = createWindow(null, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 79 | FIRST_APPLICATION_WINDOW, mDisplayContent, "disabledWindow"); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 80 | disabledWindow.mAppToken.setDisablePreviewScreenshots(true); |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 81 | assertEquals(SNAPSHOT_MODE_APP_THEME, |
| 82 | sWm.mTaskSnapshotController.getSnapshotMode(disabledWindow.getTask())); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 83 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 84 | final WindowState normalWindow = createWindow(null, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 85 | FIRST_APPLICATION_WINDOW, mDisplayContent, "normalWindow"); |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 86 | assertEquals(SNAPSHOT_MODE_REAL, |
| 87 | sWm.mTaskSnapshotController.getSnapshotMode(normalWindow.getTask())); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 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())); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 94 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 95 | } |