blob: d13baeccb68a3fbc5e68f09549a9c5b78b1d7593 [file] [log] [blame]
Jorim Jaggif96c90a2018-09-26 16:55:15 +02001/*
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
17package com.android.server.wm;
18
Tiger Huang332793b2019-10-29 23:21:27 +080019import static android.view.InsetsState.ITYPE_IME;
20import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
21import static android.view.InsetsState.ITYPE_STATUS_BAR;
Yunfan Chenb04dc002019-02-14 17:08:39 +090022import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020023import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090024
Jorim Jaggif96c90a2018-09-26 16:55:15 +020025import static org.junit.Assert.assertEquals;
Jorim Jaggi28620472019-01-02 23:21:49 +010026import static org.junit.Assert.assertNotEquals;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020027import static org.junit.Assert.assertNotNull;
Jorim Jaggib6030952018-10-23 18:31:52 +020028import static org.junit.Assert.assertNull;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020029
30import android.platform.test.annotations.Presubmit;
Jorim Jaggi28620472019-01-02 23:21:49 +010031import android.view.InsetsSource;
Jorim Jaggib6030952018-10-23 18:31:52 +020032import android.view.InsetsSourceControl;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020033import android.view.InsetsState;
Jorim Jaggi28620472019-01-02 23:21:49 +010034import android.view.test.InsetsModeSession;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020035
Jorim Jaggif96c90a2018-09-26 16:55:15 +020036import androidx.test.filters.FlakyTest;
37import androidx.test.filters.SmallTest;
Jorim Jaggif96c90a2018-09-26 16:55:15 +020038
Yunfan Chenb04dc002019-02-14 17:08:39 +090039import org.junit.AfterClass;
40import org.junit.BeforeClass;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090041import org.junit.Test;
Jorim Jaggi28620472019-01-02 23:21:49 +010042import org.junit.runner.RunWith;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090043
Jorim Jaggif96c90a2018-09-26 16:55:15 +020044@SmallTest
Jorim Jaggi28620472019-01-02 23:21:49 +010045@FlakyTest(detail = "Promote to pre-submit once confirmed stable.")
Jorim Jaggif96c90a2018-09-26 16:55:15 +020046@Presubmit
Jorim Jaggi28620472019-01-02 23:21:49 +010047@RunWith(WindowTestRunner.class)
Jorim Jaggif96c90a2018-09-26 16:55:15 +020048public class InsetsStateControllerTest extends WindowTestsBase {
Jorim Jaggi28620472019-01-02 23:21:49 +010049 private static InsetsModeSession sInsetsModeSession;
Yunfan Chenb04dc002019-02-14 17:08:39 +090050
51 @BeforeClass
52 public static void setUpOnce() {
Yunfan Chenb04dc002019-02-14 17:08:39 +090053 // To let the insets provider control the insets visibility, the insets mode has to be
54 // NEW_INSETS_MODE_FULL.
Jorim Jaggi28620472019-01-02 23:21:49 +010055 sInsetsModeSession = new InsetsModeSession(NEW_INSETS_MODE_FULL);
Yunfan Chenb04dc002019-02-14 17:08:39 +090056 }
57
58 @AfterClass
59 public static void tearDownOnce() {
Jorim Jaggi28620472019-01-02 23:21:49 +010060 sInsetsModeSession.close();
Yunfan Chenb04dc002019-02-14 17:08:39 +090061 }
Jorim Jaggif96c90a2018-09-26 16:55:15 +020062
63 @Test
Wale Ogunwale8e85aee2019-04-30 15:55:05 -070064 @FlakyTest(bugId = 131005232)
Jorim Jaggif96c90a2018-09-26 16:55:15 +020065 public void testStripForDispatch_notOwn() {
Tiger Huang332793b2019-10-29 23:21:27 +080066 final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
Jorim Jaggi28620472019-01-02 23:21:49 +010067 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
Tiger Huang332793b2019-10-29 23:21:27 +080068 getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null);
69 statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR));
70 assertNotNull(getController().getInsetsForDispatch(app).getSource(ITYPE_STATUS_BAR));
Jorim Jaggif96c90a2018-09-26 16:55:15 +020071 }
72
73 @Test
74 public void testStripForDispatch_own() {
Tiger Huang332793b2019-10-29 23:21:27 +080075 final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
76 mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR)
77 .setWindow(statusBar, null);
78 statusBar.setControllableInsetProvider(getController().getSourceProvider(ITYPE_STATUS_BAR));
79 final InsetsState state = getController().getInsetsForDispatch(statusBar);
Jorim Jaggi28620472019-01-02 23:21:49 +010080 for (int i = state.getSourcesCount() - 1; i >= 0; i--) {
81 final InsetsSource source = state.sourceAt(i);
Tiger Huang332793b2019-10-29 23:21:27 +080082 assertNotEquals(ITYPE_STATUS_BAR, source.getType());
Jorim Jaggi28620472019-01-02 23:21:49 +010083 }
Jorim Jaggif96c90a2018-09-26 16:55:15 +020084 }
85
86 @Test
87 public void testStripForDispatch_navBar() {
Jorim Jaggi28620472019-01-02 23:21:49 +010088 final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar");
Tiger Huang332793b2019-10-29 23:21:27 +080089 final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
Jorim Jaggi28620472019-01-02 23:21:49 +010090 final WindowState ime = createWindow(null, TYPE_APPLICATION, "ime");
Tiger Huang332793b2019-10-29 23:21:27 +080091 getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null);
92 getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null);
93 getController().getSourceProvider(ITYPE_IME).setWindow(ime, null);
Jorim Jaggi28620472019-01-02 23:21:49 +010094 assertEquals(0, getController().getInsetsForDispatch(navBar).getSourcesCount());
Jorim Jaggib6030952018-10-23 18:31:52 +020095 }
96
97 @Test
98 public void testBarControllingWinChanged() {
Jorim Jaggi28620472019-01-02 23:21:49 +010099 final WindowState navBar = createWindow(null, TYPE_APPLICATION, "navBar");
Tiger Huang332793b2019-10-29 23:21:27 +0800100 final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
Jorim Jaggi28620472019-01-02 23:21:49 +0100101 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
Tiger Huang332793b2019-10-29 23:21:27 +0800102 getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null);
103 getController().getSourceProvider(ITYPE_NAVIGATION_BAR).setWindow(navBar, null);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100104 getController().onBarControlTargetChanged(app, null, app, null);
Jorim Jaggib6030952018-10-23 18:31:52 +0200105 InsetsSourceControl[] controls = getController().getControlsForDispatch(app);
106 assertEquals(2, controls.length);
107 }
108
109 @Test
110 public void testControlRevoked() {
Tiger Huang332793b2019-10-29 23:21:27 +0800111 final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
Jorim Jaggi28620472019-01-02 23:21:49 +0100112 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
Tiger Huang332793b2019-10-29 23:21:27 +0800113 getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100114 getController().onBarControlTargetChanged(app, null, null, null);
Jorim Jaggib6030952018-10-23 18:31:52 +0200115 assertNotNull(getController().getControlsForDispatch(app));
Jorim Jaggi956ca412019-01-07 14:49:14 +0100116 getController().onBarControlTargetChanged(null, null, null, null);
Jorim Jaggib6030952018-10-23 18:31:52 +0200117 assertNull(getController().getControlsForDispatch(app));
118 }
119
Yunfan Chend552c162019-02-08 16:51:28 +0900120 @FlakyTest(bugId = 124088319)
Jorim Jaggib6030952018-10-23 18:31:52 +0200121 @Test
122 public void testControlRevoked_animation() {
Tiger Huang332793b2019-10-29 23:21:27 +0800123 final WindowState statusBar = createWindow(null, TYPE_APPLICATION, "statusBar");
Jorim Jaggi28620472019-01-02 23:21:49 +0100124 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
Tiger Huang332793b2019-10-29 23:21:27 +0800125 getController().getSourceProvider(ITYPE_STATUS_BAR).setWindow(statusBar, null);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100126 getController().onBarControlTargetChanged(app, null, null, null);
Jorim Jaggib6030952018-10-23 18:31:52 +0200127 assertNotNull(getController().getControlsForDispatch(app));
Tiger Huang332793b2019-10-29 23:21:27 +0800128 statusBar.cancelAnimation();
Jorim Jaggib6030952018-10-23 18:31:52 +0200129 assertNull(getController().getControlsForDispatch(app));
130 }
131
132 private InsetsStateController getController() {
133 return mDisplayContent.getInsetsStateController();
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200134 }
135}