Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [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. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 24 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Robert Carr | 8360a78 | 2017-11-22 12:47:58 -0800 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 35 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 36 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 37 | |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 38 | import static com.android.server.wm.WindowStateAnimator.PRESERVED_SURFACE_LAYER; |
| 39 | |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 40 | import static com.google.common.truth.Truth.assertThat; |
| 41 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 42 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 43 | import android.view.SurfaceControl; |
| 44 | import android.view.SurfaceSession; |
| 45 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 46 | import androidx.test.filters.FlakyTest; |
| 47 | import androidx.test.filters.SmallTest; |
| 48 | |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 49 | import org.junit.After; |
| 50 | import org.junit.Test; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 51 | |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 52 | import java.util.ArrayList; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 53 | import java.util.HashMap; |
| 54 | import java.util.LinkedList; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 57 | * Tests for the {@link DisplayContent#assignChildLayers(SurfaceControl.Transaction)} method. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 58 | * |
| 59 | * Build/Install/Run: |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 60 | * atest WmTests:ZOrderingTests |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 61 | */ |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 62 | @SmallTest |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 63 | @Presubmit |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 64 | public class ZOrderingTests extends WindowTestsBase { |
| 65 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 66 | private static class LayerRecordingTransaction extends SurfaceControl.Transaction { |
| 67 | // We have WM use our Hierarchy recording subclass of SurfaceControl.Builder |
| 68 | // such that we can keep track of the parents of Surfaces as they are constructed. |
| 69 | private final HashMap<SurfaceControl, SurfaceControl> mParentFor = new HashMap<>(); |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 70 | HashMap<SurfaceControl, Integer> mLayersForControl = new HashMap<>(); |
| 71 | HashMap<SurfaceControl, SurfaceControl> mRelativeLayersForControl = new HashMap<>(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 72 | |
| 73 | @Override |
| 74 | public SurfaceControl.Transaction setLayer(SurfaceControl sc, int layer) { |
| 75 | mRelativeLayersForControl.remove(sc); |
| 76 | mLayersForControl.put(sc, layer); |
Vishnu Nair | aab3d3d | 2019-03-08 10:34:44 -0800 | [diff] [blame] | 77 | return this; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public SurfaceControl.Transaction setRelativeLayer(SurfaceControl sc, |
| 82 | SurfaceControl relativeTo, |
| 83 | int layer) { |
| 84 | mRelativeLayersForControl.put(sc, relativeTo); |
| 85 | mLayersForControl.put(sc, layer); |
Vishnu Nair | aab3d3d | 2019-03-08 10:34:44 -0800 | [diff] [blame] | 86 | return this; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 89 | private int getLayer(SurfaceControl sc) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 90 | return mLayersForControl.getOrDefault(sc, 0); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 93 | private SurfaceControl getRelativeLayer(SurfaceControl sc) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 94 | return mRelativeLayersForControl.get(sc); |
| 95 | } |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 96 | |
| 97 | void addParentFor(SurfaceControl child, SurfaceControl parent) { |
| 98 | mParentFor.put(child, parent); |
| 99 | } |
| 100 | |
| 101 | SurfaceControl getParentFor(SurfaceControl child) { |
| 102 | return mParentFor.get(child); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void close() { |
| 107 | |
| 108 | } |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 109 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 110 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 111 | private static class HierarchyRecorder extends SurfaceControl.Builder { |
| 112 | private LayerRecordingTransaction mTransaction; |
| 113 | private SurfaceControl mPendingParent; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 114 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 115 | HierarchyRecorder(SurfaceSession s, LayerRecordingTransaction transaction) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 116 | super(s); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 117 | mTransaction = transaction; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Tadashi G. Takaoka | 041a05a | 2018-10-15 12:59:51 +0900 | [diff] [blame] | 120 | @Override |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 121 | public SurfaceControl.Builder setParent(SurfaceControl sc) { |
| 122 | mPendingParent = sc; |
| 123 | return super.setParent(sc); |
| 124 | } |
Tadashi G. Takaoka | 041a05a | 2018-10-15 12:59:51 +0900 | [diff] [blame] | 125 | |
| 126 | @Override |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 127 | public SurfaceControl build() { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 128 | final SurfaceControl sc = super.build(); |
| 129 | mTransaction.addParentFor(sc, mPendingParent); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 130 | mPendingParent = null; |
| 131 | return sc; |
| 132 | } |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 133 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 134 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 135 | private static class HierarchyRecordingBuilderFactory implements SurfaceBuilderFactory { |
| 136 | private LayerRecordingTransaction mTransaction; |
| 137 | |
| 138 | HierarchyRecordingBuilderFactory(LayerRecordingTransaction transaction) { |
| 139 | mTransaction = transaction; |
| 140 | } |
| 141 | |
| 142 | @Override |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 143 | public SurfaceControl.Builder make(SurfaceSession s) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 144 | final LayerRecordingTransaction transaction = mTransaction; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 145 | return new HierarchyRecorder(s, transaction); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 146 | } |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 147 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 148 | |
| 149 | private LayerRecordingTransaction mTransaction; |
| 150 | |
| 151 | @Override |
| 152 | void beforeCreateDisplay() { |
| 153 | // We can't use @Before here because it may happen after WindowTestsBase @Before |
| 154 | // which is after construction of the DisplayContent, meaning the HierarchyRecorder |
| 155 | // would miss construction of the top-level layers. |
| 156 | mTransaction = new LayerRecordingTransaction(); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 157 | mWm.mSurfaceBuilderFactory = new HierarchyRecordingBuilderFactory(mTransaction); |
| 158 | mWm.mTransactionFactory = () -> mTransaction; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @After |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 162 | public void tearDown() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 163 | mTransaction.close(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 166 | private static LinkedList<SurfaceControl> getAncestors(LayerRecordingTransaction t, |
| 167 | SurfaceControl sc) { |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 168 | LinkedList<SurfaceControl> p = new LinkedList<>(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 169 | SurfaceControl current = sc; |
| 170 | do { |
| 171 | p.addLast(current); |
| 172 | |
| 173 | SurfaceControl rs = t.getRelativeLayer(current); |
| 174 | if (rs != null) { |
| 175 | current = rs; |
| 176 | } else { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 177 | current = t.getParentFor(current); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 178 | } |
| 179 | } while (current != null); |
| 180 | return p; |
| 181 | } |
| 182 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 183 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 184 | private static void assertZOrderGreaterThan(LayerRecordingTransaction t, SurfaceControl left, |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 185 | SurfaceControl right) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 186 | final LinkedList<SurfaceControl> leftParentChain = getAncestors(t, left); |
| 187 | final LinkedList<SurfaceControl> rightParentChain = getAncestors(t, right); |
| 188 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 189 | SurfaceControl leftTop = leftParentChain.peekLast(); |
| 190 | SurfaceControl rightTop = rightParentChain.peekLast(); |
| 191 | while (leftTop != null && rightTop != null && leftTop == rightTop) { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 192 | leftParentChain.removeLast(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 193 | rightParentChain.removeLast(); |
| 194 | leftTop = leftParentChain.peekLast(); |
| 195 | rightTop = rightParentChain.peekLast(); |
| 196 | } |
| 197 | |
| 198 | if (rightTop == null) { // right is the parent of left. |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 199 | assertThat(t.getLayer(leftTop)).isGreaterThan(0); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 200 | } else if (leftTop == null) { // left is the parent of right. |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 201 | assertThat(t.getLayer(rightTop)).isLessThan(0); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 202 | } else { |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 203 | assertThat(t.getLayer(leftTop)).isGreaterThan(t.getLayer(rightTop)); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 207 | void assertWindowHigher(WindowState left, WindowState right) { |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 208 | assertZOrderGreaterThan(mTransaction, left.getSurfaceControl(), right.getSurfaceControl()); |
| 209 | } |
| 210 | |
| 211 | WindowState createWindow(String name) { |
| 212 | return createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, name); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 215 | @FlakyTest(bugId = 124088319) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 216 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 217 | public void testAssignWindowLayers_ForImeWithNoTarget() { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 218 | mDisplayContent.mInputMethodTarget = null; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 219 | mDisplayContent.assignChildLayers(mTransaction); |
| 220 | |
| 221 | // The Ime has an higher base layer than app windows and lower base layer than system |
| 222 | // windows, so it should be above app windows and below system windows if there isn't an IME |
| 223 | // target. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 224 | assertWindowHigher(mImeWindow, mChildAppWindowAbove); |
| 225 | assertWindowHigher(mImeWindow, mAppWindow); |
| 226 | assertWindowHigher(mNavBarWindow, mImeWindow); |
| 227 | assertWindowHigher(mStatusBarWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 228 | |
| 229 | // And, IME dialogs should always have an higher layer than the IME. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 230 | assertWindowHigher(mImeDialogWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 233 | @FlakyTest(bugId = 124088319) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 234 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 235 | public void testAssignWindowLayers_ForImeWithAppTarget() { |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 236 | final WindowState imeAppTarget = createWindow("imeAppTarget"); |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 237 | mDisplayContent.mInputMethodTarget = imeAppTarget; |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 238 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 239 | mDisplayContent.assignChildLayers(mTransaction); |
| 240 | |
| 241 | // Ime should be above all app windows and below system windows if it is targeting an app |
| 242 | // window. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 243 | assertWindowHigher(mImeWindow, imeAppTarget); |
| 244 | assertWindowHigher(mImeWindow, mChildAppWindowAbove); |
| 245 | assertWindowHigher(mImeWindow, mAppWindow); |
| 246 | assertWindowHigher(mNavBarWindow, mImeWindow); |
| 247 | assertWindowHigher(mStatusBarWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 248 | |
| 249 | // And, IME dialogs should always have an higher layer than the IME. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 250 | assertWindowHigher(mImeDialogWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 253 | @FlakyTest(bugId = 124088319) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 254 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 255 | public void testAssignWindowLayers_ForImeWithAppTargetWithChildWindows() { |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 256 | final WindowState imeAppTarget = createWindow("imeAppTarget"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 257 | final WindowState imeAppTargetChildAboveWindow = createWindow(imeAppTarget, |
| 258 | TYPE_APPLICATION_ATTACHED_DIALOG, imeAppTarget.mToken, |
| 259 | "imeAppTargetChildAboveWindow"); |
| 260 | final WindowState imeAppTargetChildBelowWindow = createWindow(imeAppTarget, |
| 261 | TYPE_APPLICATION_MEDIA_OVERLAY, imeAppTarget.mToken, |
| 262 | "imeAppTargetChildBelowWindow"); |
| 263 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 264 | mDisplayContent.mInputMethodTarget = imeAppTarget; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 265 | mDisplayContent.assignChildLayers(mTransaction); |
| 266 | |
| 267 | // Ime should be above all app windows except for child windows that are z-ordered above it |
| 268 | // and below system windows if it is targeting an app window. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 269 | assertWindowHigher(mImeWindow, imeAppTarget); |
| 270 | assertWindowHigher(imeAppTargetChildAboveWindow, mImeWindow); |
| 271 | assertWindowHigher(mImeWindow, mChildAppWindowAbove); |
| 272 | assertWindowHigher(mImeWindow, mAppWindow); |
| 273 | assertWindowHigher(mNavBarWindow, mImeWindow); |
| 274 | assertWindowHigher(mStatusBarWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 275 | |
| 276 | // And, IME dialogs should always have an higher layer than the IME. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 277 | assertWindowHigher(mImeDialogWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 280 | @FlakyTest(bugId = 124088319) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 281 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 282 | public void testAssignWindowLayers_ForImeWithAppTargetAndAppAbove() { |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 283 | final WindowState appBelowImeTarget = createWindow("appBelowImeTarget"); |
| 284 | final WindowState imeAppTarget = createWindow("imeAppTarget"); |
| 285 | final WindowState appAboveImeTarget = createWindow("appAboveImeTarget"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 286 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 287 | mDisplayContent.mInputMethodTarget = imeAppTarget; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 288 | mDisplayContent.assignChildLayers(mTransaction); |
| 289 | |
| 290 | // Ime should be above all app windows except for non-fullscreen app window above it and |
| 291 | // below system windows if it is targeting an app window. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 292 | assertWindowHigher(mImeWindow, imeAppTarget); |
| 293 | assertWindowHigher(mImeWindow, appBelowImeTarget); |
| 294 | assertWindowHigher(appAboveImeTarget, mImeWindow); |
| 295 | assertWindowHigher(mImeWindow, mChildAppWindowAbove); |
| 296 | assertWindowHigher(mImeWindow, mAppWindow); |
| 297 | assertWindowHigher(mNavBarWindow, mImeWindow); |
| 298 | assertWindowHigher(mStatusBarWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 299 | |
| 300 | // And, IME dialogs should always have an higher layer than the IME. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 301 | assertWindowHigher(mImeDialogWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 304 | @FlakyTest(bugId = 124088319) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 305 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 306 | public void testAssignWindowLayers_ForImeNonAppImeTarget() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 307 | final WindowState imeSystemOverlayTarget = createWindow(null, TYPE_SYSTEM_OVERLAY, |
| 308 | mDisplayContent, "imeSystemOverlayTarget", |
| 309 | true /* ownerCanAddInternalSystemWindow */); |
| 310 | |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 311 | mDisplayContent.mInputMethodTarget = imeSystemOverlayTarget; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 312 | mDisplayContent.assignChildLayers(mTransaction); |
| 313 | |
| 314 | // The IME target base layer is higher than all window except for the nav bar window, so the |
| 315 | // IME should be above all windows except for the nav bar. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 316 | assertWindowHigher(mImeWindow, imeSystemOverlayTarget); |
| 317 | assertWindowHigher(mImeWindow, mChildAppWindowAbove); |
| 318 | assertWindowHigher(mImeWindow, mAppWindow); |
| 319 | assertWindowHigher(mImeWindow, mDockedDividerWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 320 | |
| 321 | // The IME has a higher base layer than the status bar so we may expect it to go |
| 322 | // above the status bar once they are both in the Non-App layer, as past versions of this |
| 323 | // test enforced. However this seems like the wrong behavior unless the status bar is the |
| 324 | // IME target. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 325 | assertWindowHigher(mNavBarWindow, mImeWindow); |
| 326 | assertWindowHigher(mStatusBarWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 327 | |
| 328 | // And, IME dialogs should always have an higher layer than the IME. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 329 | assertWindowHigher(mImeDialogWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 332 | @FlakyTest(bugId = 124088319) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 333 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 334 | public void testAssignWindowLayers_ForStatusBarImeTarget() { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 335 | mDisplayContent.mInputMethodTarget = mStatusBarWindow; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 336 | mDisplayContent.assignChildLayers(mTransaction); |
| 337 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 338 | assertWindowHigher(mImeWindow, mChildAppWindowAbove); |
| 339 | assertWindowHigher(mImeWindow, mAppWindow); |
| 340 | assertWindowHigher(mImeWindow, mDockedDividerWindow); |
| 341 | assertWindowHigher(mImeWindow, mStatusBarWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 342 | |
| 343 | // And, IME dialogs should always have an higher layer than the IME. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 344 | assertWindowHigher(mImeDialogWindow, mImeWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 347 | @FlakyTest(bugId = 124088319) |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 348 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 349 | public void testStackLayers() { |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 350 | final WindowState anyWindow1 = createWindow("anyWindow"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 351 | final WindowState pinnedStackWindow = createWindowOnStack(null, WINDOWING_MODE_PINNED, |
| 352 | ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent, |
| 353 | "pinnedStackWindow"); |
| 354 | final WindowState dockedStackWindow = createWindowOnStack(null, |
| 355 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, |
| 356 | mDisplayContent, "dockedStackWindow"); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 357 | final WindowState assistantStackWindow = createWindowOnStack(null, |
| 358 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, TYPE_BASE_APPLICATION, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 359 | mDisplayContent, "assistantStackWindow"); |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 360 | final WindowState homeActivityWindow = createWindowOnStack(null, WINDOWING_MODE_FULLSCREEN, |
| 361 | ACTIVITY_TYPE_HOME, TYPE_BASE_APPLICATION, |
| 362 | mDisplayContent, "homeActivityWindow"); |
| 363 | final WindowState anyWindow2 = createWindow("anyWindow2"); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 364 | |
| 365 | mDisplayContent.assignChildLayers(mTransaction); |
| 366 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 367 | assertWindowHigher(dockedStackWindow, homeActivityWindow); |
| 368 | assertWindowHigher(assistantStackWindow, homeActivityWindow); |
| 369 | assertWindowHigher(pinnedStackWindow, homeActivityWindow); |
| 370 | assertWindowHigher(anyWindow1, homeActivityWindow); |
| 371 | assertWindowHigher(anyWindow2, homeActivityWindow); |
| 372 | assertWindowHigher(pinnedStackWindow, anyWindow1); |
| 373 | assertWindowHigher(pinnedStackWindow, anyWindow2); |
| 374 | assertWindowHigher(pinnedStackWindow, dockedStackWindow); |
| 375 | assertWindowHigher(pinnedStackWindow, assistantStackWindow); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 376 | } |
Robert Carr | 8360a78 | 2017-11-22 12:47:58 -0800 | [diff] [blame] | 377 | |
| 378 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 379 | public void testAssignWindowLayers_ForSysUiPanels() { |
Robert Carr | 8360a78 | 2017-11-22 12:47:58 -0800 | [diff] [blame] | 380 | final WindowState navBarPanel = |
| 381 | createWindow(null, TYPE_NAVIGATION_BAR_PANEL, mDisplayContent, "NavBarPanel"); |
| 382 | final WindowState statusBarPanel = |
| 383 | createWindow(null, TYPE_STATUS_BAR_PANEL, mDisplayContent, "StatusBarPanel"); |
| 384 | final WindowState statusBarSubPanel = |
| 385 | createWindow(null, TYPE_STATUS_BAR_SUB_PANEL, mDisplayContent, "StatusBarSubPanel"); |
| 386 | mDisplayContent.assignChildLayers(mTransaction); |
| 387 | |
| 388 | // Ime should be above all app windows and below system windows if it is targeting an app |
| 389 | // window. |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 390 | assertWindowHigher(navBarPanel, mNavBarWindow); |
| 391 | assertWindowHigher(statusBarPanel, mStatusBarWindow); |
| 392 | assertWindowHigher(statusBarSubPanel, statusBarPanel); |
Robert Carr | 8360a78 | 2017-11-22 12:47:58 -0800 | [diff] [blame] | 393 | } |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 394 | |
| 395 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 396 | public void testAssignWindowLayers_ForNegativelyZOrderedSubtype() { |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 397 | // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA |
| 398 | // then we can drop all negative layering on the windowing side. |
| 399 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 400 | final WindowState anyWindow = createWindow("anyWindow"); |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 401 | final WindowState child = createWindow(anyWindow, TYPE_APPLICATION_MEDIA, mDisplayContent, |
| 402 | "TypeApplicationMediaChild"); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 403 | final WindowState mediaOverlayChild = createWindow(anyWindow, |
| 404 | TYPE_APPLICATION_MEDIA_OVERLAY, |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 405 | mDisplayContent, "TypeApplicationMediaOverlayChild"); |
| 406 | |
| 407 | mDisplayContent.assignChildLayers(mTransaction); |
| 408 | |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 409 | assertWindowHigher(anyWindow, mediaOverlayChild); |
| 410 | assertWindowHigher(mediaOverlayChild, child); |
| 411 | } |
| 412 | |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 413 | @Test |
| 414 | public void testAssignWindowLayers_ForPostivelyZOrderedSubtype() { |
| 415 | final WindowState anyWindow = createWindow("anyWindow"); |
| 416 | final ArrayList<WindowState> childList = new ArrayList<>(); |
| 417 | childList.add(createWindow(anyWindow, TYPE_APPLICATION_PANEL, mDisplayContent, |
| 418 | "TypeApplicationPanelChild")); |
| 419 | childList.add(createWindow(anyWindow, TYPE_APPLICATION_SUB_PANEL, mDisplayContent, |
| 420 | "TypeApplicationSubPanelChild")); |
| 421 | childList.add(createWindow(anyWindow, TYPE_APPLICATION_ATTACHED_DIALOG, mDisplayContent, |
| 422 | "TypeApplicationAttachedDialogChild")); |
| 423 | childList.add(createWindow(anyWindow, TYPE_APPLICATION_ABOVE_SUB_PANEL, mDisplayContent, |
| 424 | "TypeApplicationAboveSubPanelPanelChild")); |
| 425 | |
| 426 | final LayerRecordingTransaction t = mTransaction; |
| 427 | mDisplayContent.assignChildLayers(t); |
| 428 | |
| 429 | for (int i = childList.size() - 1; i >= 0; i--) { |
| 430 | assertThat(t.getLayer(childList.get(i).getSurfaceControl())) |
| 431 | .isGreaterThan(PRESERVED_SURFACE_LAYER); |
| 432 | } |
| 433 | } |
| 434 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 435 | @FlakyTest(bugId = 124088319) |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 436 | @Test |
Tadashi G. Takaoka | c98f682 | 2018-10-11 17:11:49 +0900 | [diff] [blame] | 437 | public void testDockedDividerPosition() { |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 438 | final WindowState pinnedStackWindow = createWindowOnStack(null, WINDOWING_MODE_PINNED, |
| 439 | ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, mDisplayContent, |
| 440 | "pinnedStackWindow"); |
| 441 | final WindowState splitScreenWindow = createWindowOnStack(null, |
| 442 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD, TYPE_BASE_APPLICATION, |
| 443 | mDisplayContent, "splitScreenWindow"); |
| 444 | final WindowState splitScreenSecondaryWindow = createWindowOnStack(null, |
| 445 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD, |
| 446 | TYPE_BASE_APPLICATION, mDisplayContent, "splitScreenSecondaryWindow"); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 447 | final WindowState assistantStackWindow = createWindowOnStack(null, |
| 448 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, TYPE_BASE_APPLICATION, |
Robert Carr | f7a7ca8 | 2017-12-06 13:17:07 -0800 | [diff] [blame] | 449 | mDisplayContent, "assistantStackWindow"); |
| 450 | |
| 451 | mDisplayContent.assignChildLayers(mTransaction); |
| 452 | |
| 453 | assertWindowHigher(mDockedDividerWindow, splitScreenWindow); |
| 454 | assertWindowHigher(mDockedDividerWindow, splitScreenSecondaryWindow); |
| 455 | assertWindowHigher(pinnedStackWindow, mDockedDividerWindow); |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 456 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 457 | } |