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 |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 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; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 22 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 23 | import static com.android.server.wm.TaskSnapshotController.SNAPSHOT_MODE_APP_THEME; |
| 24 | import static com.android.server.wm.TaskSnapshotController.SNAPSHOT_MODE_REAL; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 25 | |
Tadashi G. Takaoka | 82eb7a5 | 2019-03-26 18:22:01 +0900 | [diff] [blame^] | 26 | import static org.junit.Assert.assertEquals; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 27 | |
| 28 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 29 | import android.util.ArraySet; |
| 30 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 31 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 32 | |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 33 | import com.google.android.collect.Sets; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 34 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 35 | import org.junit.Test; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Test class for {@link TaskSnapshotController}. |
| 39 | * |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 40 | * Build/Install/Run: |
| 41 | * * atest FrameworksServicesTests:TaskSnapshotControllerTest |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 42 | */ |
| 43 | @SmallTest |
| 44 | @Presubmit |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 45 | public class TaskSnapshotControllerTest extends WindowTestsBase { |
| 46 | |
| 47 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 48 | public void testGetClosingApps_closing() { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 49 | final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, |
| 50 | "closingWindow"); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 51 | closingWindow.mAppToken.commitVisibility(null, false /* visible */, TRANSIT_UNSET, |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 52 | 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 56 | mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 57 | assertEquals(1, closingTasks.size()); |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 58 | assertEquals(closingWindow.mAppToken.getTask(), closingTasks.valueAt(0)); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 62 | public void testGetClosingApps_notClosing() { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 63 | final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, |
| 64 | "closingWindow"); |
| 65 | final WindowState openingWindow = createAppWindow(closingWindow.getTask(), |
| 66 | FIRST_APPLICATION_WINDOW, "openingWindow"); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 67 | closingWindow.mAppToken.commitVisibility(null, false /* visible */, TRANSIT_UNSET, |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 68 | true /* performLayout */, false /* isVoiceInteraction */); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 69 | openingWindow.mAppToken.commitVisibility(null, true /* visible */, TRANSIT_UNSET, |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 70 | 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 74 | mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 75 | assertEquals(0, closingTasks.size()); |
| 76 | } |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 77 | |
| 78 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 79 | public void testGetClosingApps_skipClosingAppsSnapshotTasks() { |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 80 | final WindowState closingWindow = createWindow(null, FIRST_APPLICATION_WINDOW, |
| 81 | "closingWindow"); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 82 | closingWindow.mAppToken.commitVisibility(null, false /* visible */, TRANSIT_UNSET, |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 83 | 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 87 | mWm.mTaskSnapshotController.addSkipClosingAppSnapshotTasks( |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 88 | Sets.newArraySet(closingWindow.mAppToken.getTask())); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 89 | mWm.mTaskSnapshotController.getClosingTasks(closingApps, closingTasks); |
Winson Chung | 23aa7b1 | 2018-02-01 11:41:43 -0800 | [diff] [blame] | 90 | assertEquals(0, closingTasks.size()); |
| 91 | } |
| 92 | |
| 93 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 94 | public void testGetSnapshotMode() { |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 95 | final WindowState disabledWindow = createWindow(null, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 96 | FIRST_APPLICATION_WINDOW, mDisplayContent, "disabledWindow"); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 97 | disabledWindow.mAppToken.setDisablePreviewScreenshots(true); |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 98 | assertEquals(SNAPSHOT_MODE_APP_THEME, |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 99 | mWm.mTaskSnapshotController.getSnapshotMode(disabledWindow.getTask())); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 100 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 101 | final WindowState normalWindow = createWindow(null, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 102 | FIRST_APPLICATION_WINDOW, mDisplayContent, "normalWindow"); |
Jorim Jaggi | 8f4fe6e | 2017-03-14 18:21:40 +0100 | [diff] [blame] | 103 | assertEquals(SNAPSHOT_MODE_REAL, |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 104 | mWm.mTaskSnapshotController.getSnapshotMode(normalWindow.getTask())); |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 105 | |
| 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. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 110 | mWm.mTaskSnapshotController.getSnapshotMode(secureWindow.getTask())); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 111 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 112 | } |