Andrii Kulian | d276563 | 2016-12-12 22:26:34 -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.app.ActivityManager.StackId.PINNED_STACK_ID; |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame^] | 20 | import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 21 | |
| 22 | import org.junit.Test; |
| 23 | import org.junit.runner.RunWith; |
| 24 | |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame^] | 25 | import android.hardware.display.DisplayManagerGlobal; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 26 | import android.platform.test.annotations.Presubmit; |
| 27 | import android.support.test.filters.SmallTest; |
| 28 | import android.support.test.runner.AndroidJUnit4; |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame^] | 29 | import android.view.Display; |
| 30 | import android.view.DisplayInfo; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 31 | |
| 32 | import static org.junit.Assert.assertEquals; |
| 33 | import static org.junit.Assert.assertFalse; |
| 34 | import static org.junit.Assert.assertNotNull; |
| 35 | import static org.junit.Assert.assertNull; |
| 36 | import static org.junit.Assert.assertTrue; |
| 37 | |
| 38 | /** |
| 39 | * Tests for the {@link DisplayContent.TaskStackContainers} container in {@link DisplayContent}. |
| 40 | * |
| 41 | * Build/Install/Run: |
| 42 | * bit FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests |
| 43 | */ |
| 44 | @SmallTest |
| 45 | @Presubmit |
| 46 | @RunWith(AndroidJUnit4.class) |
| 47 | public class TaskStackContainersTests extends WindowTestsBase { |
| 48 | |
| 49 | @Test |
| 50 | public void testStackPositionChildAt() throws Exception { |
| 51 | // Test that always-on-top stack can't be moved to position other than top. |
| 52 | final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent); |
| 53 | final TaskStack stack2 = createTaskStackOnDisplay(sDisplayContent); |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 54 | final TaskStack pinnedStack = addPinnedStack(); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 55 | |
| 56 | final WindowContainer taskStackContainer = stack1.getParent(); |
| 57 | |
| 58 | final int stack1Pos = taskStackContainer.mChildren.indexOf(stack1); |
| 59 | final int stack2Pos = taskStackContainer.mChildren.indexOf(stack2); |
| 60 | final int pinnedStackPos = taskStackContainer.mChildren.indexOf(pinnedStack); |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 61 | assertGreaterThan(pinnedStackPos, stack2Pos); |
| 62 | assertGreaterThan(stack2Pos, stack1Pos); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 63 | |
| 64 | taskStackContainer.positionChildAt(WindowContainer.POSITION_BOTTOM, pinnedStack, false); |
| 65 | assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1); |
| 66 | assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2); |
| 67 | assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), pinnedStack); |
| 68 | |
| 69 | taskStackContainer.positionChildAt(1, pinnedStack, false); |
| 70 | assertEquals(taskStackContainer.mChildren.get(stack1Pos), stack1); |
| 71 | assertEquals(taskStackContainer.mChildren.get(stack2Pos), stack2); |
| 72 | assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), pinnedStack); |
| 73 | } |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 74 | @Test |
| 75 | public void testStackPositionBelowPinnedStack() throws Exception { |
| 76 | // Test that no stack can be above pinned stack. |
| 77 | final TaskStack pinnedStack = addPinnedStack(); |
| 78 | final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent); |
| 79 | |
| 80 | final WindowContainer taskStackContainer = stack1.getParent(); |
| 81 | |
| 82 | final int stackPos = taskStackContainer.mChildren.indexOf(stack1); |
| 83 | final int pinnedStackPos = taskStackContainer.mChildren.indexOf(pinnedStack); |
| 84 | assertGreaterThan(pinnedStackPos, stackPos); |
| 85 | |
| 86 | taskStackContainer.positionChildAt(WindowContainer.POSITION_TOP, stack1, false); |
| 87 | assertEquals(taskStackContainer.mChildren.get(stackPos), stack1); |
| 88 | assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), pinnedStack); |
| 89 | |
| 90 | taskStackContainer.positionChildAt(taskStackContainer.mChildren.size() - 1, stack1, false); |
| 91 | assertEquals(taskStackContainer.mChildren.get(stackPos), stack1); |
| 92 | assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), pinnedStack); |
| 93 | } |
| 94 | |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame^] | 95 | @Test |
| 96 | public void testReparentBetweenDisplays() throws Exception { |
| 97 | // Create first stack on primary display. |
| 98 | final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent); |
| 99 | final TestTaskWindowContainerController taskController = |
| 100 | new TestTaskWindowContainerController(stack1.mStackId); |
| 101 | final TestTask task1 = (TestTask) taskController.mContainer; |
| 102 | task1.mOnDisplayChangedCalled = false; |
| 103 | |
| 104 | // Create second display and put second stack on it. |
| 105 | final Display display = new Display(DisplayManagerGlobal.getInstance(), |
| 106 | sDisplayContent.getDisplayId() + 1, new DisplayInfo(), |
| 107 | DEFAULT_DISPLAY_ADJUSTMENTS); |
| 108 | final DisplayContent dc = new DisplayContent(display, sWm, sLayersController, |
| 109 | new WallpaperController(sWm)); |
| 110 | sWm.mRoot.addChild(dc, 1); |
| 111 | final TaskStack stack2 = createTaskStackOnDisplay(dc); |
| 112 | |
| 113 | // Reparent and check state.DisplayContent.java:2572 |
| 114 | sWm.moveStackToDisplay(stack1.mStackId, dc.getDisplayId()); |
| 115 | assertEquals(dc, stack1.getDisplayContent()); |
| 116 | final int stack1PositionInParent = stack1.getParent().mChildren.indexOf(stack1); |
| 117 | final int stack2PositionInParent = stack1.getParent().mChildren.indexOf(stack2); |
| 118 | assertEquals(stack1PositionInParent, stack2PositionInParent + 1); |
| 119 | assertTrue(task1.mOnDisplayChangedCalled); |
| 120 | } |
| 121 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 122 | private TaskStack addPinnedStack() { |
| 123 | TaskStack pinnedStack = sWm.mStackIdToStack.get(PINNED_STACK_ID); |
| 124 | if (pinnedStack == null) { |
| 125 | sDisplayContent.addStackToDisplay(PINNED_STACK_ID, true); |
| 126 | pinnedStack = sWm.mStackIdToStack.get(PINNED_STACK_ID); |
| 127 | } |
| 128 | |
| 129 | if (!pinnedStack.isVisible()) { |
| 130 | // Stack should contain visible app window to be considered visible. |
| 131 | final Task pinnedTask = createTaskInStack(pinnedStack, 0 /* userId */); |
| 132 | assertFalse(pinnedStack.isVisible()); |
| 133 | final TestAppWindowToken pinnedApp = new TestAppWindowToken(sDisplayContent); |
| 134 | pinnedTask.addChild(pinnedApp, 0 /* addPos */); |
| 135 | assertTrue(pinnedStack.isVisible()); |
| 136 | } |
| 137 | |
| 138 | return pinnedStack; |
| 139 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 140 | } |