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 28 import org.junit.Before; 29 import org.junit.Test; 30 31 import java.util.ArrayList; 32 import java.util.HashSet; 33 import java.util.List; 34 import java.util.Set; 35 36 /** 37 * Build/Install/Run: 38 * atest CtsWindowManagerDeviceTestCases:DisplayAreaPolicyTests 39 */ 40 @Presubmit 41 public class DisplayAreaPolicyTests extends ActivityManagerTestBase { 42 43 private List<DisplayContent> mDisplays; 44 45 @Before 46 @Override setUp()47 public void setUp() throws Exception { 48 super.setUp(); 49 50 // Verify on all displays. 51 mWmState.computeState(); 52 mDisplays = mWmState.getDisplays(); 53 } 54 55 /** 56 * DisplayContent should have feature id of FEATURE_ROOT. It should not be organized. 57 */ 58 @Test testDisplayContent()59 public void testDisplayContent() { 60 for (DisplayContent displayContent : mDisplays) { 61 assertThat(displayContent.getFeatureId()).isEqualTo(FEATURE_ROOT); 62 assertThat(displayContent.isOrganized()).isFalse(); 63 } 64 } 65 66 /** 67 * There must be exactly one default TaskDisplayArea per display. 68 */ 69 @Test testDefaultTaskDisplayArea()70 public void testDefaultTaskDisplayArea() { 71 for (DisplayContent displayContent : mDisplays) { 72 final List<DisplayArea> taskDisplayAreas = displayContent.getAllTaskDisplayAreas(); 73 final List<DisplayArea> defaultTda = new ArrayList<>(); 74 for (DisplayArea taskDisplayArea : taskDisplayAreas) { 75 if (taskDisplayArea.getFeatureId() == FEATURE_DEFAULT_TASK_CONTAINER) { 76 defaultTda.add(taskDisplayArea); 77 } 78 } 79 assertThat(defaultTda).hasSize(1); 80 } 81 } 82 83 /** 84 * TaskDisplayArea and RootDisplayArea must have unique feature ids per display. 85 */ 86 @Test testDisplayAreaUniqueId()87 public void testDisplayAreaUniqueId() { 88 for (DisplayContent displayContent : mDisplays) { 89 // TaskDisplayArea and RootDisplayArea must have unique feature ids. 90 final Set<Integer> uniqueIds = new HashSet<>(); 91 uniqueIds.add(displayContent.getFeatureId()); 92 // Other DisplayAreas can have non-unique feature ids, but shouldn't be the same with 93 // any TaskDisplayArea or RootDisplayArea. 94 final Set<Integer> nonUniqueIds = new HashSet<>(); 95 final List<DisplayArea> displayAreas = displayContent.getAllChildDisplayAreas(); 96 97 for (DisplayArea displayArea : displayAreas) { 98 final int featureId = displayArea.getFeatureId(); 99 if (displayArea.isRootDisplayArea() || displayArea.isTaskDisplayArea()) { 100 assertThat(uniqueIds.add(featureId)).isTrue(); 101 assertThat(nonUniqueIds).doesNotContain(featureId); 102 } else { 103 nonUniqueIds.add(featureId); 104 assertThat(uniqueIds).doesNotContain(featureId); 105 } 106 } 107 } 108 } 109 } 110