Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Tiger Huang | 0f5347e | 2020-03-06 17:09:41 +0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Winson Chung | 8a16890 | 2020-03-12 22:39:22 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; |
Tiger Huang | 0f5347e | 2020-03-06 17:09:41 +0800 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 23 | import static android.view.InsetsState.ITYPE_IME; |
| 24 | import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; |
| 25 | import static android.view.InsetsState.ITYPE_STATUS_BAR; |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 26 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Tiger Huang | a1663403 | 2020-02-05 17:10:03 +0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Tiger Huang | a1663403 | 2020-02-05 17:10:03 +0800 | [diff] [blame] | 30 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 31 | import static org.junit.Assert.assertEquals; |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 32 | import static org.junit.Assert.assertFalse; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 33 | import static org.junit.Assert.assertNotEquals; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 34 | import static org.junit.Assert.assertNotNull; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 35 | import static org.junit.Assert.assertNull; |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 36 | import static org.junit.Assert.assertTrue; |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 37 | import static org.mockito.Mockito.atLeast; |
| 38 | import static org.mockito.Mockito.clearInvocations; |
| 39 | import static org.mockito.Mockito.spy; |
| 40 | import static org.mockito.Mockito.verify; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 41 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 42 | import android.graphics.Rect; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 43 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 44 | import android.view.InsetsSource; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 45 | import android.view.InsetsSourceControl; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 46 | import android.view.InsetsState; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 47 | import android.view.test.InsetsModeSession; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 48 | |
Tiger Huang | a1663403 | 2020-02-05 17:10:03 +0800 | [diff] [blame] | 49 | import androidx.test.filters.SmallTest; |
| 50 | |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 51 | import org.junit.AfterClass; |
| 52 | import org.junit.BeforeClass; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 53 | import org.junit.Test; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 54 | import org.junit.runner.RunWith; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 55 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 56 | @SmallTest |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 57 | @Presubmit |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 58 | @RunWith(WindowTestRunner.class) |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 59 | public class InsetsStateControllerTest extends WindowTestsBase { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 60 | private static InsetsModeSession sInsetsModeSession; |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 61 | |
| 62 | @BeforeClass |
| 63 | public static void setUpOnce() { |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 64 | // To let the insets provider control the insets visibility, the insets mode has to be |
| 65 | // NEW_INSETS_MODE_FULL. |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 66 | sInsetsModeSession = new InsetsModeSession(NEW_INSETS_MODE_FULL); |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @AfterClass |
| 70 | public static void tearDownOnce() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 71 | sInsetsModeSession.close(); |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 72 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 73 | |
| 74 | @Test |
| 75 | public void testStripForDispatch_notOwn() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 76 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 77 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 78 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 79 | statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR)); |
Tiger Huang | 0f5347e | 2020-03-06 17:09:41 +0800 | [diff] [blame] | 80 | assertNotNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testStripForDispatch_own() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 85 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 86 | mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR) |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 87 | .setWindow(statusBar, null, null); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 88 | statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR)); |
| 89 | final InsetsState state = getController().getInsetsForDispatch(statusBar); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 90 | for (int i = state.getSourcesCount() - 1; i >= 0; i--) { |
| 91 | final InsetsSource source = state.sourceAt(i); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 92 | assertNotEquals(ITYPE_STATUS_BAR, source.getType()); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 93 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Test |
| 97 | public void testStripForDispatch_navBar() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 98 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 99 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 100 | final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime"); |
Tiger Huang | a1663403 | 2020-02-05 17:10:03 +0800 | [diff] [blame] | 101 | |
| 102 | // IME cannot be the IME target. |
| 103 | ime.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 104 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 105 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 106 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 107 | getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); |
Jorim Jaggi | 963c5c2 | 2020-04-01 22:53:42 +0200 | [diff] [blame] | 108 | assertNull(getController().getInsetsForDispatch(navBar).peekSource(ITYPE_IME)); |
| 109 | assertNull(getController().getInsetsForDispatch(navBar).peekSource(ITYPE_STATUS_BAR)); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Test |
Tiger Huang | 0f5347e | 2020-03-06 17:09:41 +0800 | [diff] [blame] | 113 | public void testStripForDispatch_pip() { |
| 114 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 115 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
| 116 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 117 | |
| 118 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 119 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 120 | app.setWindowingMode(WINDOWING_MODE_PINNED); |
| 121 | |
| 122 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); |
| 123 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); |
| 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void testStripForDispatch_freeform() { |
| 128 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 129 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
| 130 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 131 | |
| 132 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 133 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 134 | app.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 135 | |
| 136 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); |
| 137 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); |
| 138 | } |
| 139 | |
| 140 | @Test |
Winson Chung | 8a16890 | 2020-03-12 22:39:22 -0700 | [diff] [blame] | 141 | public void testStripForDispatch_multiwindow_alwaysOnTop() { |
| 142 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 143 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
| 144 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 145 | |
| 146 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 147 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 148 | app.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
| 149 | app.setAlwaysOnTop(true); |
| 150 | |
| 151 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); |
| 152 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); |
| 153 | } |
| 154 | |
| 155 | @Test |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 156 | public void testStripForDispatch_belowIme() { |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 157 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
| 158 | |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 159 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 160 | app.mBehindIme = true; |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 161 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 162 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 163 | assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Test |
| 167 | public void testStripForDispatch_aboveIme() { |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 168 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
| 169 | |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 170 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 171 | app.mBehindIme = false; |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 172 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 173 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 174 | assertFalse(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Test |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 178 | public void testStripForDispatch_imeOrderChanged() { |
| 179 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
| 180 | |
| 181 | // This window can be the IME target while app cannot be the IME target. |
| 182 | createWindow(null, TYPE_APPLICATION, "base"); |
| 183 | |
| 184 | // Send our spy window (app) into the system so that we can detect the invocation. |
| 185 | final WindowState win = createWindow(null, TYPE_APPLICATION, "app"); |
| 186 | final WindowToken parent = win.mToken; |
| 187 | parent.removeChild(win); |
| 188 | final WindowState app = spy(win); |
| 189 | parent.addWindow(app); |
| 190 | |
| 191 | // Adding FLAG_NOT_FOCUSABLE makes app above IME. |
| 192 | app.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 193 | mDisplayContent.computeImeTarget(true); |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 194 | mDisplayContent.applySurfaceChangesTransaction(); |
| 195 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 196 | // app won't get visible IME insets while above IME even when IME is visible. |
| 197 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 198 | assertFalse(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 199 | |
| 200 | // Reset invocation counter. |
| 201 | clearInvocations(app); |
| 202 | |
| 203 | // Removing FLAG_NOT_FOCUSABLE makes app below IME. |
| 204 | app.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; |
| 205 | mDisplayContent.computeImeTarget(true); |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 206 | mDisplayContent.applySurfaceChangesTransaction(); |
| 207 | |
| 208 | // Make sure app got notified. |
| 209 | verify(app, atLeast(1)).notifyInsetsChanged(); |
| 210 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 211 | // app will get visible IME insets while below IME when IME is visible. |
| 212 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 213 | assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | @Test |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 217 | public void testStripForDispatch_childWindow_altFocusable() { |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 218 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 219 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 220 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 221 | final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); |
| 222 | child.mAttrs.flags |= FLAG_ALT_FOCUSABLE_IM; |
| 223 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 224 | mDisplayContent.computeImeTarget(true); |
| 225 | mDisplayContent.setLayoutNeeded(); |
| 226 | mDisplayContent.applySurfaceChangesTransaction(); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 227 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 228 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 229 | assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
| 230 | assertFalse(getController().getInsetsForDispatch(child).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Test |
| 234 | public void testStripForDispatch_childWindow_splitScreen() { |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 235 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 236 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 237 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 238 | final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); |
| 239 | child.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 240 | child.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 241 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 242 | mDisplayContent.computeImeTarget(true); |
| 243 | mDisplayContent.setLayoutNeeded(); |
| 244 | mDisplayContent.applySurfaceChangesTransaction(); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 245 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 246 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 247 | assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
| 248 | assertFalse(getController().getInsetsForDispatch(child).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Test |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 252 | public void testImeForDispatch() { |
| 253 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 254 | final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime"); |
Tiger Huang | a1663403 | 2020-02-05 17:10:03 +0800 | [diff] [blame] | 255 | |
| 256 | // IME cannot be the IME target. |
| 257 | ime.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 258 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 259 | InsetsSourceProvider statusBarProvider = |
| 260 | getController().getSourceProvider(ITYPE_STATUS_BAR); |
| 261 | statusBarProvider.setWindow(statusBar, null, ((displayFrames, windowState, rect) -> |
| 262 | rect.set(0, 1, 2, 3))); |
| 263 | getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); |
| 264 | statusBar.setControllableInsetProvider(statusBarProvider); |
| 265 | |
| 266 | statusBarProvider.onPostLayout(); |
| 267 | |
| 268 | final InsetsState state = getController().getInsetsForDispatch(ime); |
| 269 | assertEquals(new Rect(0, 1, 2, 3), state.getSource(ITYPE_STATUS_BAR).getFrame()); |
| 270 | } |
| 271 | |
| 272 | @Test |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 273 | public void testBarControllingWinChanged() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 274 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 275 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 276 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 277 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 278 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 279 | getController().onBarControlTargetChanged(app, null, app, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 280 | InsetsSourceControl[] controls = getController().getControlsForDispatch(app); |
| 281 | assertEquals(2, controls.length); |
| 282 | } |
| 283 | |
| 284 | @Test |
| 285 | public void testControlRevoked() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 286 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 287 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 288 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 289 | getController().onBarControlTargetChanged(app, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 290 | assertNotNull(getController().getControlsForDispatch(app)); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 291 | getController().onBarControlTargetChanged(null, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 292 | assertNull(getController().getControlsForDispatch(app)); |
| 293 | } |
| 294 | |
| 295 | @Test |
| 296 | public void testControlRevoked_animation() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 297 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 298 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 299 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 300 | getController().onBarControlTargetChanged(app, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 301 | assertNotNull(getController().getControlsForDispatch(app)); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 302 | statusBar.cancelAnimation(); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 303 | assertNull(getController().getControlsForDispatch(app)); |
| 304 | } |
| 305 | |
| 306 | private InsetsStateController getController() { |
| 307 | return mDisplayContent.getInsetsStateController(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 308 | } |
| 309 | } |