• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 android.server.wm;
18 
19 import static android.window.DisplayAreaOrganizer.FEATURE_DEFAULT_TASK_CONTAINER;
20 import static android.window.DisplayAreaOrganizer.FEATURE_ROOT;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import android.platform.test.annotations.Presubmit;
25 import android.server.wm.WindowManagerState.DisplayArea;
26 import android.server.wm.WindowManagerState.DisplayContent;
27 import android.view.Display;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 
32 import java.util.ArrayList;
33 import java.util.HashSet;
34 import java.util.List;
35 import java.util.Set;
36 
37 /**
38  * Build/Install/Run:
39  *     atest CtsWindowManagerDeviceTestCases:DisplayAreaPolicyTests
40  */
41 @Presubmit
42 public class DisplayAreaPolicyTests extends ActivityManagerTestBase {
43 
44     private List<DisplayContent> mDisplays;
45 
46     @Before
47     @Override
setUp()48     public void setUp() throws Exception {
49         super.setUp();
50 
51         // Verify on all displays.
52         mWmState.computeState();
53         mDisplays = mWmState.getDisplays();
54     }
55 
isTrustedDisplay(DisplayContent displayContent)56     private boolean isTrustedDisplay(DisplayContent displayContent) {
57         return (displayContent.getFlags() & Display.FLAG_TRUSTED) != 0;
58     }
59 
60     /**
61      * DisplayContent should have feature id of FEATURE_ROOT.
62      */
63     @Test
testDisplayContent()64     public void testDisplayContent() {
65         for (DisplayContent displayContent : mDisplays) {
66             assertThat(displayContent.getFeatureId()).isEqualTo(FEATURE_ROOT);
67         }
68     }
69 
70     /**
71      * There must be exactly one default TaskDisplayArea per display.
72      */
73     @Test
testDefaultTaskDisplayArea()74     public void testDefaultTaskDisplayArea() {
75         for (DisplayContent displayContent : mDisplays) {
76             final List<DisplayArea> taskDisplayAreas = displayContent.getAllTaskDisplayAreas();
77             final List<DisplayArea> defaultTda = new ArrayList<>();
78             for (DisplayArea taskDisplayArea : taskDisplayAreas) {
79                 if (taskDisplayArea.getFeatureId() == FEATURE_DEFAULT_TASK_CONTAINER) {
80                     defaultTda.add(taskDisplayArea);
81                 }
82             }
83             assertThat(defaultTda).hasSize(1);
84         }
85     }
86 
87     /**
88      * TaskDisplayArea and RootDisplayArea must have unique feature ids per display.
89      */
90     @Test
testDisplayAreaUniqueId()91     public void testDisplayAreaUniqueId() {
92         for (DisplayContent displayContent : mDisplays) {
93             // TaskDisplayArea and RootDisplayArea must have unique feature ids.
94             final Set<Integer> uniqueIds = new HashSet<>();
95             uniqueIds.add(displayContent.getFeatureId());
96             // Other DisplayAreas can have non-unique feature ids, but shouldn't be the same with
97             // any TaskDisplayArea or RootDisplayArea.
98             final Set<Integer> nonUniqueIds = new HashSet<>();
99             final List<DisplayArea> displayAreas = displayContent.getAllChildDisplayAreas();
100 
101             for (DisplayArea displayArea : displayAreas) {
102                 final int featureId = displayArea.getFeatureId();
103                 if (displayArea.isRootDisplayArea() || displayArea.isTaskDisplayArea()) {
104                     assertThat(uniqueIds.add(featureId)).isTrue();
105                     assertThat(nonUniqueIds).doesNotContain(featureId);
106                 } else {
107                     nonUniqueIds.add(featureId);
108                     assertThat(uniqueIds).doesNotContain(featureId);
109                 }
110             }
111         }
112     }
113 }
114