blob: e1f318dc032c5fb8668460b9119e641abc5176c1 [file] [log] [blame]
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001/*
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
17package com.android.server.wm;
18
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080019import org.junit.Test;
20import org.junit.runner.RunWith;
21
22import android.platform.test.annotations.Presubmit;
23import android.support.test.filters.SmallTest;
24import android.support.test.runner.AndroidJUnit4;
25
Winson Chung83471632016-12-13 11:02:12 -080026import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID;
27import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
28import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwaleca9e0612016-12-02 07:45:59 -080030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080031import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080032import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080033
34/**
35 * Tests for the {@link WindowLayersController} class.
36 *
37 * Build/Install/Run:
38 * bit FrameworksServicesTests:com.android.server.wm.WindowLayersControllerTests
39 */
40@SmallTest
41@Presubmit
42@RunWith(AndroidJUnit4.class)
43public class WindowLayersControllerTests extends WindowTestsBase {
44
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080045 @Test
46 public void testAssignWindowLayers_ForImeWithNoTarget() throws Exception {
47 sWm.mInputMethodTarget = null;
Wale Ogunwale11cc5162017-04-25 20:29:13 -070048 mLayersController.assignWindowLayers(mDisplayContent);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080049
50 // The Ime has an higher base layer than app windows and lower base layer than system
51 // windows, so it should be above app windows and below system windows if there isn't an IME
52 // target.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070053 assertWindowLayerGreaterThan(mImeWindow, mChildAppWindowAbove);
54 assertWindowLayerGreaterThan(mImeWindow, mAppWindow);
55 assertWindowLayerGreaterThan(mImeWindow, mDockedDividerWindow);
56 assertWindowLayerGreaterThan(mNavBarWindow, mImeWindow);
57 assertWindowLayerGreaterThan(mStatusBarWindow, mImeWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080058
59 // And, IME dialogs should always have an higher layer than the IME.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070060 assertWindowLayerGreaterThan(mImeDialogWindow, mImeWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080061 }
62
63 @Test
64 public void testAssignWindowLayers_ForImeWithAppTarget() throws Exception {
65 final WindowState imeAppTarget =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070066 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget");
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080067 sWm.mInputMethodTarget = imeAppTarget;
Wale Ogunwale11cc5162017-04-25 20:29:13 -070068 mLayersController.assignWindowLayers(mDisplayContent);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080069
70 // Ime should be above all app windows and below system windows if it is targeting an app
71 // window.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070072 assertWindowLayerGreaterThan(mImeWindow, imeAppTarget);
73 assertWindowLayerGreaterThan(mImeWindow, mChildAppWindowAbove);
74 assertWindowLayerGreaterThan(mImeWindow, mAppWindow);
75 assertWindowLayerGreaterThan(mImeWindow, mDockedDividerWindow);
76 assertWindowLayerGreaterThan(mNavBarWindow, mImeWindow);
77 assertWindowLayerGreaterThan(mStatusBarWindow, mImeWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080078
79 // And, IME dialogs should always have an higher layer than the IME.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070080 assertWindowLayerGreaterThan(mImeDialogWindow, mImeWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080081 }
82
83 @Test
Wale Ogunwaleca9e0612016-12-02 07:45:59 -080084 public void testAssignWindowLayers_ForImeWithAppTargetWithChildWindows() throws Exception {
85 final WindowState imeAppTarget =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070086 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget");
Wale Ogunwaleca9e0612016-12-02 07:45:59 -080087 final WindowState imeAppTargetChildAboveWindow = createWindow(imeAppTarget,
88 TYPE_APPLICATION_ATTACHED_DIALOG, imeAppTarget.mToken,
89 "imeAppTargetChildAboveWindow");
90 final WindowState imeAppTargetChildBelowWindow = createWindow(imeAppTarget,
91 TYPE_APPLICATION_MEDIA_OVERLAY, imeAppTarget.mToken,
92 "imeAppTargetChildBelowWindow");
93
94 sWm.mInputMethodTarget = imeAppTarget;
Wale Ogunwale11cc5162017-04-25 20:29:13 -070095 mLayersController.assignWindowLayers(mDisplayContent);
Wale Ogunwaleca9e0612016-12-02 07:45:59 -080096
97 // Ime should be above all app windows except for child windows that are z-ordered above it
98 // and below system windows if it is targeting an app window.
Wale Ogunwale11cc5162017-04-25 20:29:13 -070099 assertWindowLayerGreaterThan(mImeWindow, imeAppTarget);
100 assertWindowLayerGreaterThan(imeAppTargetChildAboveWindow, mImeWindow);
101 assertWindowLayerGreaterThan(mImeWindow, imeAppTargetChildBelowWindow);
102 assertWindowLayerGreaterThan(mImeWindow, mChildAppWindowAbove);
103 assertWindowLayerGreaterThan(mImeWindow, mAppWindow);
104 assertWindowLayerGreaterThan(mImeWindow, mDockedDividerWindow);
105 assertWindowLayerGreaterThan(mNavBarWindow, mImeWindow);
106 assertWindowLayerGreaterThan(mStatusBarWindow, mImeWindow);
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800107
108 // And, IME dialogs should always have an higher layer than the IME.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700109 assertWindowLayerGreaterThan(mImeDialogWindow, mImeWindow);
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800110 }
111
112 @Test
113 public void testAssignWindowLayers_ForImeWithAppTargetAndAppAbove() throws Exception {
114 final WindowState appBelowImeTarget =
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700115 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "appBelowImeTarget");
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800116 final WindowState imeAppTarget =
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700117 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget");
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800118 final WindowState appAboveImeTarget =
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700119 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "appAboveImeTarget");
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800120
121 sWm.mInputMethodTarget = imeAppTarget;
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700122 mLayersController.assignWindowLayers(mDisplayContent);
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800123
124 // Ime should be above all app windows except for non-fullscreen app window above it and
125 // below system windows if it is targeting an app window.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700126 assertWindowLayerGreaterThan(mImeWindow, imeAppTarget);
127 assertWindowLayerGreaterThan(mImeWindow, appBelowImeTarget);
128 assertWindowLayerGreaterThan(appAboveImeTarget, mImeWindow);
129 assertWindowLayerGreaterThan(mImeWindow, mChildAppWindowAbove);
130 assertWindowLayerGreaterThan(mImeWindow, mAppWindow);
131 assertWindowLayerGreaterThan(mImeWindow, mDockedDividerWindow);
132 assertWindowLayerGreaterThan(mNavBarWindow, mImeWindow);
133 assertWindowLayerGreaterThan(mStatusBarWindow, mImeWindow);
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800134
135 // And, IME dialogs should always have an higher layer than the IME.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700136 assertWindowLayerGreaterThan(mImeDialogWindow, mImeWindow);
Wale Ogunwaleca9e0612016-12-02 07:45:59 -0800137 }
138
139 @Test
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800140 public void testAssignWindowLayers_ForImeNonAppImeTarget() throws Exception {
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800141 final WindowState imeSystemOverlayTarget = createWindow(null, TYPE_SYSTEM_OVERLAY,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700142 mDisplayContent, "imeSystemOverlayTarget",
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800143 true /* ownerCanAddInternalSystemWindow */);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800144
145 sWm.mInputMethodTarget = imeSystemOverlayTarget;
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700146 mLayersController.assignWindowLayers(mDisplayContent);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800147
148 // The IME target base layer is higher than all window except for the nav bar window, so the
149 // IME should be above all windows except for the nav bar.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700150 assertWindowLayerGreaterThan(mImeWindow, imeSystemOverlayTarget);
151 assertWindowLayerGreaterThan(mImeWindow, mChildAppWindowAbove);
152 assertWindowLayerGreaterThan(mImeWindow, mAppWindow);
153 assertWindowLayerGreaterThan(mImeWindow, mDockedDividerWindow);
154 assertWindowLayerGreaterThan(mImeWindow, mStatusBarWindow);
155 assertWindowLayerGreaterThan(mNavBarWindow, mImeWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800156
157 // And, IME dialogs should always have an higher layer than the IME.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700158 assertWindowLayerGreaterThan(mImeDialogWindow, mImeWindow);
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800159 }
160
Winson Chung83471632016-12-13 11:02:12 -0800161 @Test
162 public void testStackLayers() throws Exception {
163 WindowState pinnedStackWindow = createWindowOnStack(null, PINNED_STACK_ID,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700164 TYPE_BASE_APPLICATION, mDisplayContent, "pinnedStackWindow");
Winson Chung83471632016-12-13 11:02:12 -0800165 WindowState dockedStackWindow = createWindowOnStack(null, DOCKED_STACK_ID,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700166 TYPE_BASE_APPLICATION, mDisplayContent, "dockedStackWindow");
Winson Chung83471632016-12-13 11:02:12 -0800167 WindowState assistantStackWindow = createWindowOnStack(null, ASSISTANT_STACK_ID,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700168 TYPE_BASE_APPLICATION, mDisplayContent, "assistantStackWindow");
Winson Chung83471632016-12-13 11:02:12 -0800169
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700170 mLayersController.assignWindowLayers(mDisplayContent);
Winson Chung83471632016-12-13 11:02:12 -0800171
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700172 assertWindowLayerGreaterThan(dockedStackWindow, mAppWindow);
Winson Chung83471632016-12-13 11:02:12 -0800173 assertWindowLayerGreaterThan(assistantStackWindow, dockedStackWindow);
174 assertWindowLayerGreaterThan(pinnedStackWindow, assistantStackWindow);
175 }
176
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800177 private void assertWindowLayerGreaterThan(WindowState first, WindowState second)
178 throws Exception {
179 assertGreaterThan(first.mWinAnimator.mAnimLayer, second.mWinAnimator.mAnimLayer);
180 }
181
182}