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