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 | bfa95a7 | 2020-06-18 22:51:49 +0200 | [diff] [blame] | 90 | assertNull(state.peekSource(ITYPE_STATUS_BAR)); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Test |
| 94 | public void testStripForDispatch_navBar() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 95 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 96 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 97 | final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime"); |
Tiger Huang | a1663403 | 2020-02-05 17:10:03 +0800 | [diff] [blame] | 98 | |
| 99 | // IME cannot be the IME target. |
| 100 | ime.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 101 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 102 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 103 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 104 | getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); |
Jorim Jaggi | 963c5c2 | 2020-04-01 22:53:42 +0200 | [diff] [blame] | 105 | assertNull(getController().getInsetsForDispatch(navBar).peekSource(ITYPE_IME)); |
| 106 | assertNull(getController().getInsetsForDispatch(navBar).peekSource(ITYPE_STATUS_BAR)); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Test |
Tiger Huang | 0f5347e | 2020-03-06 17:09:41 +0800 | [diff] [blame] | 110 | public void testStripForDispatch_pip() { |
| 111 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 112 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
| 113 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 114 | |
| 115 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 116 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 117 | app.setWindowingMode(WINDOWING_MODE_PINNED); |
| 118 | |
| 119 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); |
| 120 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); |
| 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void testStripForDispatch_freeform() { |
| 125 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 126 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
| 127 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 128 | |
| 129 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 130 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 131 | app.setWindowingMode(WINDOWING_MODE_FREEFORM); |
| 132 | |
| 133 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); |
| 134 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); |
| 135 | } |
| 136 | |
| 137 | @Test |
Winson Chung | 8a16890 | 2020-03-12 22:39:22 -0700 | [diff] [blame] | 138 | public void testStripForDispatch_multiwindow_alwaysOnTop() { |
| 139 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 140 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
| 141 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 142 | |
| 143 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 144 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 145 | app.setWindowingMode(WINDOWING_MODE_MULTI_WINDOW); |
| 146 | app.setAlwaysOnTop(true); |
| 147 | |
| 148 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_STATUS_BAR)); |
| 149 | assertNull(getController().getInsetsForDispatch(app).peekSource(ITYPE_NAVIGATION_BAR)); |
| 150 | } |
| 151 | |
| 152 | @Test |
Tiger Huang | c0d837a | 2020-04-24 00:49:27 +0800 | [diff] [blame] | 153 | public void testStripForDispatch_independentSources() { |
| 154 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
| 155 | |
| 156 | final WindowState app1 = createWindow(null, TYPE_APPLICATION, "app1"); |
| 157 | app1.mBehindIme = true; |
| 158 | |
| 159 | final WindowState app2 = createWindow(null, TYPE_APPLICATION, "app2"); |
| 160 | app2.mBehindIme = false; |
| 161 | |
| 162 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 163 | assertFalse(getController().getInsetsForDispatch(app2).getSource(ITYPE_IME).isVisible()); |
| 164 | assertTrue(getController().getInsetsForDispatch(app1).getSource(ITYPE_IME).isVisible()); |
| 165 | } |
| 166 | |
| 167 | @Test |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 168 | public void testStripForDispatch_belowIme() { |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 169 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
| 170 | |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 171 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 172 | app.mBehindIme = true; |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 173 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 174 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 175 | assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Test |
| 179 | public void testStripForDispatch_aboveIme() { |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 180 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
| 181 | |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 182 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 183 | app.mBehindIme = false; |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 184 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 185 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 186 | assertFalse(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Test |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 190 | public void testStripForDispatch_imeOrderChanged() { |
| 191 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
| 192 | |
| 193 | // This window can be the IME target while app cannot be the IME target. |
| 194 | createWindow(null, TYPE_APPLICATION, "base"); |
| 195 | |
| 196 | // Send our spy window (app) into the system so that we can detect the invocation. |
| 197 | final WindowState win = createWindow(null, TYPE_APPLICATION, "app"); |
| 198 | final WindowToken parent = win.mToken; |
| 199 | parent.removeChild(win); |
| 200 | final WindowState app = spy(win); |
| 201 | parent.addWindow(app); |
| 202 | |
| 203 | // Adding FLAG_NOT_FOCUSABLE makes app above 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 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 208 | // app won't get visible IME insets while above IME even when IME is visible. |
| 209 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 210 | assertFalse(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 211 | |
| 212 | // Reset invocation counter. |
| 213 | clearInvocations(app); |
| 214 | |
| 215 | // Removing FLAG_NOT_FOCUSABLE makes app below IME. |
| 216 | app.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; |
| 217 | mDisplayContent.computeImeTarget(true); |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 218 | mDisplayContent.applySurfaceChangesTransaction(); |
| 219 | |
| 220 | // Make sure app got notified. |
| 221 | verify(app, atLeast(1)).notifyInsetsChanged(); |
| 222 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 223 | // app will get visible IME insets while below IME when IME is visible. |
| 224 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 225 | assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 53c8eb8 | 2020-03-31 18:22:05 +0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Test |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 229 | public void testStripForDispatch_childWindow_altFocusable() { |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 230 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 231 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 232 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 233 | final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); |
| 234 | child.mAttrs.flags |= FLAG_ALT_FOCUSABLE_IM; |
| 235 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 236 | mDisplayContent.computeImeTarget(true); |
| 237 | mDisplayContent.setLayoutNeeded(); |
| 238 | mDisplayContent.applySurfaceChangesTransaction(); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 239 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 240 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 241 | assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
| 242 | assertFalse(getController().getInsetsForDispatch(child).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | @Test |
| 246 | public void testStripForDispatch_childWindow_splitScreen() { |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 247 | getController().getSourceProvider(ITYPE_IME).setWindow(mImeWindow, null, null); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 248 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 249 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 250 | final WindowState child = createWindow(app, TYPE_APPLICATION, "child"); |
| 251 | child.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 252 | child.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY); |
| 253 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 254 | mDisplayContent.computeImeTarget(true); |
| 255 | mDisplayContent.setLayoutNeeded(); |
| 256 | mDisplayContent.applySurfaceChangesTransaction(); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 257 | |
Tiger Huang | a70fd87 | 2020-04-15 05:25:16 +0800 | [diff] [blame] | 258 | getController().getRawInsetsState().setSourceVisible(ITYPE_IME, true); |
| 259 | assertTrue(getController().getInsetsForDispatch(app).getSource(ITYPE_IME).isVisible()); |
| 260 | assertFalse(getController().getInsetsForDispatch(child).getSource(ITYPE_IME).isVisible()); |
Tiger Huang | 57e2e1c | 2020-03-13 22:54:36 +0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | @Test |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 264 | public void testImeForDispatch() { |
| 265 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 266 | final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime"); |
Tiger Huang | a1663403 | 2020-02-05 17:10:03 +0800 | [diff] [blame] | 267 | |
| 268 | // IME cannot be the IME target. |
| 269 | ime.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 270 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 271 | InsetsSourceProvider statusBarProvider = |
| 272 | getController().getSourceProvider(ITYPE_STATUS_BAR); |
| 273 | statusBarProvider.setWindow(statusBar, null, ((displayFrames, windowState, rect) -> |
| 274 | rect.set(0, 1, 2, 3))); |
| 275 | getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); |
| 276 | statusBar.setControllableInsetProvider(statusBarProvider); |
| 277 | |
| 278 | statusBarProvider.onPostLayout(); |
| 279 | |
| 280 | final InsetsState state = getController().getInsetsForDispatch(ime); |
| 281 | assertEquals(new Rect(0, 1, 2, 3), state.getSource(ITYPE_STATUS_BAR).getFrame()); |
| 282 | } |
| 283 | |
| 284 | @Test |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 285 | public void testBarControllingWinChanged() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 286 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 287 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 288 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 289 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 290 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 291 | getController().onBarControlTargetChanged(app, null, app, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 292 | InsetsSourceControl[] controls = getController().getControlsForDispatch(app); |
| 293 | assertEquals(2, controls.length); |
| 294 | } |
| 295 | |
| 296 | @Test |
| 297 | public void testControlRevoked() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 298 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 299 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 300 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 301 | getController().onBarControlTargetChanged(app, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 302 | assertNotNull(getController().getControlsForDispatch(app)); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 303 | getController().onBarControlTargetChanged(null, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 304 | assertNull(getController().getControlsForDispatch(app)); |
| 305 | } |
| 306 | |
| 307 | @Test |
| 308 | public void testControlRevoked_animation() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 309 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 310 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 311 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 312 | getController().onBarControlTargetChanged(app, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 313 | assertNotNull(getController().getControlsForDispatch(app)); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 314 | statusBar.cancelAnimation(); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 315 | assertNull(getController().getControlsForDispatch(app)); |
| 316 | } |
| 317 | |
| 318 | private InsetsStateController getController() { |
| 319 | return mDisplayContent.getInsetsStateController(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 320 | } |
| 321 | } |