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 | |
| 19 | import static android.view.InsetsState.TYPE_IME; |
| 20 | import static android.view.InsetsState.TYPE_NAVIGATION_BAR; |
| 21 | import static android.view.InsetsState.TYPE_TOP_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; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 24 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 25 | import static org.junit.Assert.assertEquals; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 26 | import static org.junit.Assert.assertNotEquals; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 27 | import static org.junit.Assert.assertNotNull; |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 28 | import static org.junit.Assert.assertNull; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 29 | |
| 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 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 36 | import androidx.test.filters.FlakyTest; |
| 37 | import androidx.test.filters.SmallTest; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 38 | |
Yunfan Chen | b04dc00 | 2019-02-14 17:08:39 +0900 | [diff] [blame] | 39 | import org.junit.AfterClass; |
| 40 | import org.junit.BeforeClass; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 41 | import org.junit.Test; |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 42 | import org.junit.runner.RunWith; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 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() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 66 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "topBar"); |
| 67 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 68 | getController().getSourceProvider(TYPE_TOP_BAR).setWindow(topBar, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 69 | topBar.setControllableInsetProvider(getController().getSourceProvider(TYPE_TOP_BAR)); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 70 | assertNotNull(getController().getInsetsForDispatch(app).getSource(TYPE_TOP_BAR)); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void testStripForDispatch_own() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 75 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "topBar"); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 76 | mDisplayContent.getInsetsStateController().getSourceProvider(TYPE_TOP_BAR) |
| 77 | .setWindow(topBar, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 78 | topBar.setControllableInsetProvider(getController().getSourceProvider(TYPE_TOP_BAR)); |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 79 | final InsetsState state = getController().getInsetsForDispatch(topBar); |
| 80 | for (int i = state.getSourcesCount() - 1; i >= 0; i--) { |
| 81 | final InsetsSource source = state.sourceAt(i); |
| 82 | assertNotEquals(TYPE_TOP_BAR, source.getType()); |
| 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"); |
| 89 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "topBar"); |
| 90 | final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime"); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 91 | getController().getSourceProvider(TYPE_TOP_BAR).setWindow(topBar, null); |
| 92 | getController().getSourceProvider(TYPE_NAVIGATION_BAR).setWindow(navBar, null); |
| 93 | getController().getSourceProvider(TYPE_IME).setWindow(ime, 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 |
| 98 | public void testBarControllingWinChanged() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 99 | final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar"); |
| 100 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "topBar"); |
| 101 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 102 | getController().getSourceProvider(TYPE_TOP_BAR).setWindow(topBar, null); |
| 103 | getController().getSourceProvider(TYPE_NAVIGATION_BAR).setWindow(navBar, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 104 | getController().onBarControlTargetChanged(app, null, app, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 105 | InsetsSourceControl[] controls = getController().getControlsForDispatch(app); |
| 106 | assertEquals(2, controls.length); |
| 107 | } |
| 108 | |
| 109 | @Test |
| 110 | public void testControlRevoked() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 111 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "topBar"); |
| 112 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 113 | getController().getSourceProvider(TYPE_TOP_BAR).setWindow(topBar, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 114 | getController().onBarControlTargetChanged(app, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 115 | assertNotNull(getController().getControlsForDispatch(app)); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 116 | getController().onBarControlTargetChanged(null, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 117 | assertNull(getController().getControlsForDispatch(app)); |
| 118 | } |
| 119 | |
Yunfan Chen | d552c16 | 2019-02-08 16:51:28 +0900 | [diff] [blame] | 120 | @FlakyTest(bugId = 124088319) |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 121 | @Test |
| 122 | public void testControlRevoked_animation() { |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 123 | final WindowState topBar = createWindow(null, TYPE_APPLICATION, "topBar"); |
| 124 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 125 | getController().getSourceProvider(TYPE_TOP_BAR).setWindow(topBar, null); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 126 | getController().onBarControlTargetChanged(app, null, null, null); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 127 | assertNotNull(getController().getControlsForDispatch(app)); |
| 128 | topBar.cancelAnimation(); |
| 129 | assertNull(getController().getControlsForDispatch(app)); |
| 130 | } |
| 131 | |
| 132 | private InsetsStateController getController() { |
| 133 | return mDisplayContent.getInsetsStateController(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 134 | } |
| 135 | } |