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 | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 19 | import static android.view.InsetsState.ITYPE_IME; |
| 20 | import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; |
| 21 | import static android.view.InsetsState.ITYPE_STATUS_BAR; |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 22 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 24 | import static org.junit.Assert.assertEquals; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 25 | import static org.junit.Assert.assertNotEquals; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 26 | import static org.junit.Assert.assertNotNull; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 27 | import static org.junit.Assert.assertNull; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 28 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 29 | import android.graphics.Rect; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 30 | import android.platform.test.annotations.Presubmit; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 31 | import android.view.InsetsSource; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 32 | import android.view.InsetsSourceControl; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 33 | import android.view.InsetsState; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 34 | import android.view.test.InsetsModeSession; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 35 | |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 36 | import org.junit.AfterClass; |
| 37 | import org.junit.BeforeClass; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 38 | import org.junit.Test; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 39 | import org.junit.runner.RunWith; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 40 | |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 41 | import androidx.test.filters.FlakyTest; |
| 42 | import androidx.test.filters.SmallTest; |
| 43 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 44 | @SmallTest |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 45 | @FlakyTest(detail = "Promote to pre-submit once confirmed stable.") |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 46 | @Presubmit |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 47 | @RunWith(WindowTestRunner.class) |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 48 | public class InsetsStateControllerTest extends WindowTestsBase { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 49 | private static InsetsModeSession sInsetsModeSession; |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 50 | |
| 51 | @BeforeClass |
| 52 | public static void setUpOnce() { |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 53 | // To let the insets provider control the insets visibility, the insets mode has to be |
| 54 | // NEW_INSETS_MODE_FULL. |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 55 | sInsetsModeSession = new InsetsModeSession(NEW_INSETS_MODE_FULL); |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @AfterClass |
| 59 | public static void tearDownOnce() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 60 | sInsetsModeSession.close(); |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 61 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 62 | |
| 63 | @Test |
Wale Ogunwale | 8e85aee | 2019-04-30 15:55:05 -0700 | [diff] [blame] | 64 | @FlakyTest(bugId = 131005232) |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 65 | public void testStripForDispatch_notOwn() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 66 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 67 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 68 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 69 | statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR)); |
| 70 | assertNotNull(getController().getInsetsForDispatch(app).getSource(ITYPE_STATUS_BAR)); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void testStripForDispatch_own() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 75 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 76 | mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR) |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 77 | .setWindow(statusBar, null, null); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 78 | statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR)); |
| 79 | final InsetsState state = getController().getInsetsForDispatch(statusBar); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 80 | for (int i = state.getSourcesCount() - 1; i >= 0; i--) { |
| 81 | final InsetsSource source = state.sourceAt(i); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 82 | assertNotEquals(ITYPE_STATUS_BAR, source.getType()); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 83 | } |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Test |
| 87 | public void testStripForDispatch_navBar() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 88 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 89 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 90 | final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 91 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 92 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
| 93 | getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 94 | assertEquals(0, getController().getInsetsForDispatch(navBar).getSourcesCount()); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Test |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 98 | public void testImeForDispatch() { |
| 99 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
| 100 | final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime"); |
| 101 | InsetsSourceProvider statusBarProvider = |
| 102 | getController().getSourceProvider(ITYPE_STATUS_BAR); |
| 103 | statusBarProvider.setWindow(statusBar, null, ((displayFrames, windowState, rect) -> |
| 104 | rect.set(0, 1, 2, 3))); |
| 105 | getController().getSourceProvider(ITYPE_IME).setWindow(ime, null, null); |
| 106 | statusBar.setControllableInsetProvider(statusBarProvider); |
| 107 | |
| 108 | statusBarProvider.onPostLayout(); |
| 109 | |
| 110 | final InsetsState state = getController().getInsetsForDispatch(ime); |
| 111 | assertEquals(new Rect(0, 1, 2, 3), state.getSource(ITYPE_STATUS_BAR).getFrame()); |
| 112 | } |
| 113 | |
| 114 | @Test |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 115 | public void testBarControllingWinChanged() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 116 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 117 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 118 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 119 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
| 120 | getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 121 | getController().onBarControlTargetChanged(app, null, app, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 122 | InsetsSourceControl[] controls = getController().getControlsForDispatch(app); |
| 123 | assertEquals(2, controls.length); |
| 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void testControlRevoked() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 128 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 129 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 130 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 131 | getController().onBarControlTargetChanged(app, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 132 | assertNotNull(getController().getControlsForDispatch(app)); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 133 | getController().onBarControlTargetChanged(null, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 134 | assertNull(getController().getControlsForDispatch(app)); |
| 135 | } |
| 136 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 137 | @FlakyTest(bugId = 124088319) |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 138 | @Test |
| 139 | public void testControlRevoked_animation() { |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 140 | final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar"); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 141 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | 9b4f420 | 2020-01-28 17:05:06 +0100 | [diff] [blame] | 142 | getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 143 | getController().onBarControlTargetChanged(app, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 144 | assertNotNull(getController().getControlsForDispatch(app)); |
Tiger Huang | 332793b | 2019-10-29 23:21:27 +0800 | [diff] [blame] | 145 | statusBar.cancelAnimation(); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 146 | assertNull(getController().getControlsForDispatch(app)); |
| 147 | } |
| 148 | |
| 149 | private InsetsStateController getController() { |
| 150 | return mDisplayContent.getInsetsStateController(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 151 | } |
| 152 | } |