blob: 228ece5ab136c4a0902bded72197c0bb29029089 [file] [log] [blame]
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001/*
2 * Copyright (C) 2016 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
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070015 */
16
17package com.android.server.wm;
18
Wale Ogunwale68278562017-09-23 17:13:55 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
Kazuki Takise048e2662018-06-27 17:05:11 +090020import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
21import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Wale Ogunwale68278562017-09-23 17:13:55 -070022import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
Andrii Kulian92c9a942017-10-10 00:41:41 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
24import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
25import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale34247952017-02-19 11:57:53 -080026import static android.view.Display.DEFAULT_DISPLAY;
Issei Suzuki43190bd2018-08-20 17:28:41 +020027import static android.view.DisplayCutout.BOUNDS_POSITION_LEFT;
28import static android.view.DisplayCutout.BOUNDS_POSITION_TOP;
Adrian Roos24264212018-02-19 16:26:15 +010029import static android.view.DisplayCutout.fromBoundingRect;
Wale Ogunwale34247952017-02-19 11:57:53 -080030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
31import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
32import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Andrii Kulian92c9a942017-10-10 00:41:41 -070033import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwale34247952017-02-19 11:57:53 -080034import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
Brett Chabota26eda92018-07-23 13:08:30 -070035
David Stevens46939562017-03-24 13:04:00 -070036import static com.android.server.wm.WindowContainer.POSITION_TOP;
Tiger Huang1e5b10a2018-07-30 20:19:51 +080037import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
chaviwebcbc342018-02-07 13:19:00 -080038
Adrian Roos5251b1d2018-03-23 18:57:43 +010039import static org.hamcrest.Matchers.is;
Wale Ogunwale34247952017-02-19 11:57:53 -080040import static org.junit.Assert.assertEquals;
Andrii Kulianf0379de2018-03-14 16:24:07 -070041import static org.junit.Assert.assertFalse;
Arthur Hungbe5ce212018-09-13 18:41:56 +080042import static org.junit.Assert.assertNotNull;
lumarkff0ab692018-11-05 20:32:30 +080043import static org.junit.Assert.assertNull;
Adrian Roos5251b1d2018-03-23 18:57:43 +010044import static org.junit.Assert.assertThat;
Wale Ogunwale34247952017-02-19 11:57:53 -080045import static org.junit.Assert.assertTrue;
Riddle Hsu654a6f92018-07-13 22:59:36 +080046import static org.mockito.Mockito.doNothing;
47import static org.mockito.Mockito.spy;
Andrii Kulianf0379de2018-03-14 16:24:07 -070048import static org.mockito.Mockito.times;
49import static org.mockito.Mockito.verify;
Wale Ogunwale34247952017-02-19 11:57:53 -080050
Andrii Kulian92c9a942017-10-10 00:41:41 -070051import android.annotation.SuppressLint;
Andrii Kuliand68501e2017-01-10 22:57:27 -080052import android.content.res.Configuration;
Adrian Roos1cf585052018-01-03 18:43:27 +010053import android.graphics.Rect;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070054import android.os.SystemClock;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070055import android.platform.test.annotations.Presubmit;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070056import android.util.DisplayMetrics;
Adrian Roos1cf585052018-01-03 18:43:27 +010057import android.view.DisplayCutout;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080058import android.view.Gravity;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070059import android.view.MotionEvent;
Adrian Roos1cf585052018-01-03 18:43:27 +010060import android.view.Surface;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070061
Brett Chabota26eda92018-07-23 13:08:30 -070062import androidx.test.filters.FlakyTest;
63import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070064
Adrian Roos6a4fa0e2018-03-05 19:50:16 +010065import com.android.server.wm.utils.WmDisplayCutout;
66
Brett Chabota26eda92018-07-23 13:08:30 -070067import org.junit.Test;
Brett Chabota26eda92018-07-23 13:08:30 -070068
Adrian Roos0f9368c2018-04-08 10:59:08 -070069import java.util.ArrayList;
Wale Ogunwale34247952017-02-19 11:57:53 -080070import java.util.Arrays;
Adrian Roos0f9368c2018-04-08 10:59:08 -070071import java.util.Collections;
Wale Ogunwale34247952017-02-19 11:57:53 -080072import java.util.LinkedList;
73import java.util.List;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070074
75/**
76 * Tests for the {@link DisplayContent} class.
77 *
78 * Build/Install/Run:
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070079 * atest FrameworksServicesTests:DisplayContentTests
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070080 */
81@SmallTest
82@Presubmit
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080083public class DisplayContentTests extends WindowTestsBase {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070084
85 @Test
Adrian Roos0f9368c2018-04-08 10:59:08 -070086 @FlakyTest(bugId = 77772044)
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070087 public void testForAllWindows() {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080088 final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070089 mDisplayContent, "exiting app");
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070090 final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken;
91 exitingAppToken.mIsExiting = true;
Bryce Lee6d410262017-02-28 15:30:17 -080092 exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070093
Wale Ogunwale34247952017-02-19 11:57:53 -080094 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -070095 mWallpaperWindow,
Wale Ogunwale34247952017-02-19 11:57:53 -080096 exitingAppWindow,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070097 mChildAppWindowBelow,
98 mAppWindow,
99 mChildAppWindowAbove,
100 mDockedDividerWindow,
101 mStatusBarWindow,
102 mNavBarWindow,
103 mImeWindow,
104 mImeDialogWindow));
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800105 }
106
107 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700108 public void testForAllWindows_WithAppImeTarget() {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800109 final WindowState imeAppTarget =
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700110 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget");
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800111
lumarkff0ab692018-11-05 20:32:30 +0800112 mDisplayContent.mInputMethodTarget = imeAppTarget;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800113
Wale Ogunwale34247952017-02-19 11:57:53 -0800114 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700115 mWallpaperWindow,
116 mChildAppWindowBelow,
117 mAppWindow,
118 mChildAppWindowAbove,
Wale Ogunwale34247952017-02-19 11:57:53 -0800119 imeAppTarget,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700120 mImeWindow,
121 mImeDialogWindow,
122 mDockedDividerWindow,
123 mStatusBarWindow,
124 mNavBarWindow));
Wale Ogunwale34247952017-02-19 11:57:53 -0800125 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800126
Wale Ogunwale34247952017-02-19 11:57:53 -0800127 @Test
lumarkff0ab692018-11-05 20:32:30 +0800128 public void testForAllWindows_WithChildWindowImeTarget() throws Exception {
129 mDisplayContent.mInputMethodTarget = mChildAppWindowAbove;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800130
Wale Ogunwale34247952017-02-19 11:57:53 -0800131 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700132 mWallpaperWindow,
133 mChildAppWindowBelow,
134 mAppWindow,
135 mChildAppWindowAbove,
136 mImeWindow,
137 mImeDialogWindow,
138 mDockedDividerWindow,
139 mStatusBarWindow,
140 mNavBarWindow));
Wale Ogunwaleb783fd82016-11-04 09:51:54 -0700141 }
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800142
143 @Test
lumarkff0ab692018-11-05 20:32:30 +0800144 public void testForAllWindows_WithStatusBarImeTarget() throws Exception {
145 mDisplayContent.mInputMethodTarget = mStatusBarWindow;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800146
Wale Ogunwale34247952017-02-19 11:57:53 -0800147 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700148 mWallpaperWindow,
149 mChildAppWindowBelow,
150 mAppWindow,
151 mChildAppWindowAbove,
152 mDockedDividerWindow,
153 mStatusBarWindow,
154 mImeWindow,
155 mImeDialogWindow,
156 mNavBarWindow));
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800157 }
158
159 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700160 public void testForAllWindows_WithInBetweenWindowToken() {
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800161 // This window is set-up to be z-ordered between some windows that go in the same token like
162 // the nav bar and status bar.
163 final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700164 mDisplayContent, "voiceInteractionWindow");
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800165
Wale Ogunwale34247952017-02-19 11:57:53 -0800166 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700167 mWallpaperWindow,
168 mChildAppWindowBelow,
169 mAppWindow,
170 mChildAppWindowAbove,
171 mDockedDividerWindow,
Wale Ogunwale34247952017-02-19 11:57:53 -0800172 voiceInteractionWindow,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700173 mStatusBarWindow,
174 mNavBarWindow,
175 mImeWindow,
176 mImeDialogWindow));
Wale Ogunwale34247952017-02-19 11:57:53 -0800177 }
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800178
Wale Ogunwale34247952017-02-19 11:57:53 -0800179 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700180 public void testComputeImeTarget() {
Wale Ogunwale34247952017-02-19 11:57:53 -0800181 // Verify that an app window can be an ime target.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700182 final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin");
Wale Ogunwale34247952017-02-19 11:57:53 -0800183 appWin.setHasSurface(true);
184 assertTrue(appWin.canBeImeTarget());
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700185 WindowState imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800186 assertEquals(appWin, imeTarget);
chaviwebcbc342018-02-07 13:19:00 -0800187 appWin.mHidden = false;
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800188
Wale Ogunwale34247952017-02-19 11:57:53 -0800189 // Verify that an child window can be an ime target.
190 final WindowState childWin = createWindow(appWin,
191 TYPE_APPLICATION_ATTACHED_DIALOG, "childWin");
192 childWin.setHasSurface(true);
193 assertTrue(childWin.canBeImeTarget());
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700194 imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800195 assertEquals(childWin, imeTarget);
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800196 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800197
Andrii Kuliand68501e2017-01-10 22:57:27 -0800198 /**
199 * This tests stack movement between displays and proper stack's, task's and app token's display
200 * container references updates.
201 */
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800202 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700203 public void testMoveStackBetweenDisplays() {
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800204 // Create a second display.
205 final DisplayContent dc = createNewDisplay();
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800206
207 // Add stack with activity.
208 final TaskStack stack = createTaskStackOnDisplay(dc);
209 assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId());
210 assertEquals(dc, stack.getParent().getParent());
211 assertEquals(dc, stack.getDisplayContent());
212
213 final Task task = createTaskInStack(stack, 0 /* userId */);
chaviw97d28202018-02-27 16:23:53 -0800214 final WindowTestUtils.TestAppWindowToken token = WindowTestUtils.createTestAppWindowToken(
215 dc);
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800216 task.addChild(token, 0);
217 assertEquals(dc, task.getDisplayContent());
218 assertEquals(dc, token.getDisplayContent());
219
220 // Move stack to first display.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700221 mDisplayContent.moveStackToDisplay(stack, true /* onTop */);
222 assertEquals(mDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId());
223 assertEquals(mDisplayContent, stack.getParent().getParent());
224 assertEquals(mDisplayContent, stack.getDisplayContent());
225 assertEquals(mDisplayContent, task.getDisplayContent());
226 assertEquals(mDisplayContent, token.getDisplayContent());
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800227 }
Andrii Kuliand68501e2017-01-10 22:57:27 -0800228
229 /**
230 * This tests override configuration updates for display content.
231 */
232 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700233 public void testDisplayOverrideConfigUpdate() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700234 final Configuration currentOverrideConfig = mDisplayContent.getOverrideConfiguration();
Andrii Kuliand68501e2017-01-10 22:57:27 -0800235
236 // Create new, slightly changed override configuration and apply it to the display.
237 final Configuration newOverrideConfig = new Configuration(currentOverrideConfig);
238 newOverrideConfig.densityDpi += 120;
239 newOverrideConfig.fontScale += 0.3;
240
Evan Roskye747c3e2018-10-30 20:06:41 -0700241 mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, mDisplayContent);
Andrii Kuliand68501e2017-01-10 22:57:27 -0800242
243 // Check that override config is applied.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700244 assertEquals(newOverrideConfig, mDisplayContent.getOverrideConfiguration());
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800245 }
246
247 /**
248 * This tests global configuration updates when default display config is updated.
249 */
250 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700251 public void testDefaultDisplayOverrideConfigUpdate() {
Evan Roskye747c3e2018-10-30 20:06:41 -0700252 DisplayContent defaultDisplay = mWm.mRoot.getDisplayContent(DEFAULT_DISPLAY);
253 final Configuration currentConfig = defaultDisplay.getConfiguration();
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800254
255 // Create new, slightly changed override configuration and apply it to the display.
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700256 final Configuration newOverrideConfig = new Configuration(currentConfig);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800257 newOverrideConfig.densityDpi += 120;
258 newOverrideConfig.fontScale += 0.3;
259
Evan Roskye747c3e2018-10-30 20:06:41 -0700260 mWm.setNewDisplayOverrideConfiguration(newOverrideConfig, defaultDisplay);
Andrii Kuliand68501e2017-01-10 22:57:27 -0800261
262 // Check that global configuration is updated, as we've updated default display's config.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700263 Configuration globalConfig = mWm.mRoot.getConfiguration();
Andrii Kuliand68501e2017-01-10 22:57:27 -0800264 assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi);
265 assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800266
267 // Return back to original values.
Evan Roskye747c3e2018-10-30 20:06:41 -0700268 mWm.setNewDisplayOverrideConfiguration(currentConfig, defaultDisplay);
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700269 globalConfig = mWm.mRoot.getConfiguration();
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700270 assertEquals(currentConfig.densityDpi, globalConfig.densityDpi);
271 assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */);
Andrii Kuliand68501e2017-01-10 22:57:27 -0800272 }
Wale Ogunwale34247952017-02-19 11:57:53 -0800273
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700274 /**
275 * Tests tapping on a stack in different display results in window gaining focus.
276 */
277 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700278 public void testInputEventBringsCorrectDisplayInFocus() {
279 DisplayContent dc0 = mWm.getDefaultDisplayContentLocked();
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700280 // Create a second display
281 final DisplayContent dc1 = createNewDisplay();
282
283 // Add stack with activity.
284 final TaskStack stack0 = createTaskStackOnDisplay(dc0);
285 final Task task0 = createTaskInStack(stack0, 0 /* userId */);
286 final WindowTestUtils.TestAppWindowToken token =
chaviw97d28202018-02-27 16:23:53 -0800287 WindowTestUtils.createTestAppWindowToken(dc0);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700288 task0.addChild(token, 0);
Arthur Hungbe5ce212018-09-13 18:41:56 +0800289 dc0.configureDisplayPolicy();
290 assertNotNull(dc0.mTapDetector);
291
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700292 final TaskStack stack1 = createTaskStackOnDisplay(dc1);
293 final Task task1 = createTaskInStack(stack1, 0 /* userId */);
294 final WindowTestUtils.TestAppWindowToken token1 =
chaviw97d28202018-02-27 16:23:53 -0800295 WindowTestUtils.createTestAppWindowToken(dc0);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700296 task1.addChild(token1, 0);
Arthur Hungbe5ce212018-09-13 18:41:56 +0800297 dc1.configureDisplayPolicy();
298 assertNotNull(dc1.mTapDetector);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700299
Arthur Hungbe5ce212018-09-13 18:41:56 +0800300 // tap on primary display.
301 tapOnDisplay(dc0);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700302 // Check focus is on primary display.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700303 assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus,
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800304 dc0.findFocusedWindow());
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700305
Arthur Hungbe5ce212018-09-13 18:41:56 +0800306 // Tap on secondary display.
307 tapOnDisplay(dc1);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700308 // Check focus is on secondary.
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700309 assertEquals(mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus,
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800310 dc1.findFocusedWindow());
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700311 }
312
David Stevens46939562017-03-24 13:04:00 -0700313 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700314 public void testFocusedWindowMultipleDisplays() {
Andrii Kulian0214ed92017-05-16 13:44:05 -0700315 // Create a focusable window and check that focus is calculated correctly
David Stevens46939562017-03-24 13:04:00 -0700316 final WindowState window1 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700317 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1");
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800318 updateFocusedWindow();
319 assertTrue(window1.isFocused());
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700320 assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
David Stevens46939562017-03-24 13:04:00 -0700321
322 // Check that a new display doesn't affect focus
323 final DisplayContent dc = createNewDisplay();
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800324 updateFocusedWindow();
325 assertTrue(window1.isFocused());
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700326 assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
David Stevens46939562017-03-24 13:04:00 -0700327
328 // Add a window to the second display, and it should be focused
329 final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2");
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800330 updateFocusedWindow();
331 assertTrue(window1.isFocused());
332 assertTrue(window2.isFocused());
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700333 assertEquals(window2, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
David Stevens46939562017-03-24 13:04:00 -0700334
335 // Move the first window to the to including parents, and make sure focus is updated
336 window1.getParent().positionChildAt(POSITION_TOP, window1, true);
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800337 updateFocusedWindow();
338 assertTrue(window1.isFocused());
339 assertTrue(window2.isFocused());
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700340 assertEquals(window1, mWm.mRoot.getTopFocusedDisplayContent().mCurrentFocus);
Adrian Roos4163d622018-05-22 16:56:35 +0200341 }
342
Bryce Lee27cec322017-03-21 09:41:37 -0700343 /**
344 * This tests setting the maximum ui width on a display.
345 */
346 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700347 public void testMaxUiWidth() {
Riddle Hsu654a6f92018-07-13 22:59:36 +0800348 // Prevent base display metrics for test from being updated to the value of real display.
349 final DisplayContent displayContent = createDisplayNoUpdateDisplayInfo();
Bryce Lee27cec322017-03-21 09:41:37 -0700350 final int baseWidth = 1440;
351 final int baseHeight = 2560;
352 final int baseDensity = 300;
353
Riddle Hsu654a6f92018-07-13 22:59:36 +0800354 displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700355
356 final int maxWidth = 300;
357 final int resultingHeight = (maxWidth * baseHeight) / baseWidth;
358 final int resultingDensity = (maxWidth * baseDensity) / baseWidth;
359
Riddle Hsu654a6f92018-07-13 22:59:36 +0800360 displayContent.setMaxUiWidth(maxWidth);
361 verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700362
363 // Assert setting values again does not change;
Riddle Hsu654a6f92018-07-13 22:59:36 +0800364 displayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity);
365 verifySizes(displayContent, maxWidth, resultingHeight, resultingDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700366
367 final int smallerWidth = 200;
368 final int smallerHeight = 400;
369 final int smallerDensity = 100;
370
371 // Specify smaller dimension, verify that it is honored
Riddle Hsu654a6f92018-07-13 22:59:36 +0800372 displayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity);
373 verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700374
375 // Verify that setting the max width to a greater value than the base width has no effect
Riddle Hsu654a6f92018-07-13 22:59:36 +0800376 displayContent.setMaxUiWidth(maxWidth);
377 verifySizes(displayContent, smallerWidth, smallerHeight, smallerDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700378 }
379
Bryce Lee48f4b572017-04-10 10:54:15 -0700380 /**
Kazuki Takise148d00a2018-05-31 15:32:19 +0900381 * This test enforces that alwaysOnTop stack is placed at proper position.
Bryce Lee48f4b572017-04-10 10:54:15 -0700382 */
383 @Test
Kazuki Takise148d00a2018-05-31 15:32:19 +0900384 public void testAlwaysOnTopStackLocation() {
Kazuki Takise048e2662018-06-27 17:05:11 +0900385 final TaskStack alwaysOnTopStack = createStackControllerOnStackOnDisplay(
386 WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer;
Kazuki Takise4e7e7892018-06-19 13:55:23 +0900387 final Task task = createTaskInStack(alwaysOnTopStack, 0 /* userId */);
Kazuki Takise148d00a2018-05-31 15:32:19 +0900388 alwaysOnTopStack.setAlwaysOnTop(true);
Riddle Hsu57831b52018-07-27 00:31:48 +0800389 mDisplayContent.positionStackAt(POSITION_TOP, alwaysOnTopStack,
390 false /* includingParents */);
Kazuki Takise148d00a2018-05-31 15:32:19 +0900391 assertTrue(alwaysOnTopStack.isAlwaysOnTop());
Kazuki Takise4e7e7892018-06-19 13:55:23 +0900392 // Ensure always on top state is synced to the children of the stack.
393 assertTrue(alwaysOnTopStack.getTopChild().isAlwaysOnTop());
Kazuki Takise148d00a2018-05-31 15:32:19 +0900394 assertEquals(alwaysOnTopStack, mDisplayContent.getTopStack());
395
Wale Ogunwale61911492017-10-11 08:50:50 -0700396 final TaskStack pinnedStack = createStackControllerOnStackOnDisplay(
397 WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer;
Wale Ogunwale61911492017-10-11 08:50:50 -0700398 assertEquals(pinnedStack, mDisplayContent.getPinnedStack());
399 assertEquals(pinnedStack, mDisplayContent.getTopStack());
Kazuki Takise148d00a2018-05-31 15:32:19 +0900400
Kazuki Takise048e2662018-06-27 17:05:11 +0900401 final TaskStack anotherAlwaysOnTopStack = createStackControllerOnStackOnDisplay(
402 WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer;
Kazuki Takise148d00a2018-05-31 15:32:19 +0900403 anotherAlwaysOnTopStack.setAlwaysOnTop(true);
Riddle Hsu57831b52018-07-27 00:31:48 +0800404 mDisplayContent.positionStackAt(POSITION_TOP, anotherAlwaysOnTopStack,
405 false /* includingParents */);
Kazuki Takise148d00a2018-05-31 15:32:19 +0900406 assertTrue(anotherAlwaysOnTopStack.isAlwaysOnTop());
407 int topPosition = mDisplayContent.getStacks().size() - 1;
408 // Ensure the new alwaysOnTop stack is put below the pinned stack, but on top of the
409 // existing alwaysOnTop stack.
410 assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 1));
411
Kazuki Takise048e2662018-06-27 17:05:11 +0900412 final TaskStack nonAlwaysOnTopStack = createStackControllerOnStackOnDisplay(
413 WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer;
Kazuki Takise148d00a2018-05-31 15:32:19 +0900414 assertEquals(mDisplayContent, nonAlwaysOnTopStack.getDisplayContent());
415 topPosition = mDisplayContent.getStacks().size() - 1;
416 // Ensure the non-alwaysOnTop stack is put below the three alwaysOnTop stacks, but above the
417 // existing other non-alwaysOnTop stacks.
418 assertEquals(nonAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 3));
Kazuki Takisef85197b2018-06-18 18:18:36 +0900419
420 anotherAlwaysOnTopStack.setAlwaysOnTop(false);
Riddle Hsu57831b52018-07-27 00:31:48 +0800421 mDisplayContent.positionStackAt(POSITION_TOP, anotherAlwaysOnTopStack,
422 false /* includingParents */);
Kazuki Takisef85197b2018-06-18 18:18:36 +0900423 assertFalse(anotherAlwaysOnTopStack.isAlwaysOnTop());
Kazuki Takisef85197b2018-06-18 18:18:36 +0900424 // Ensure, when always on top is turned off for a stack, the stack is put just below all
425 // other always on top stacks.
426 assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 2));
Kazuki Takise048e2662018-06-27 17:05:11 +0900427 anotherAlwaysOnTopStack.setAlwaysOnTop(true);
428
429 // Ensure always on top state changes properly when windowing mode changes.
430 anotherAlwaysOnTopStack.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
431 assertFalse(anotherAlwaysOnTopStack.isAlwaysOnTop());
432 assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 2));
433 anotherAlwaysOnTopStack.setWindowingMode(WINDOWING_MODE_FREEFORM);
434 assertTrue(anotherAlwaysOnTopStack.isAlwaysOnTop());
435 assertEquals(anotherAlwaysOnTopStack, mDisplayContent.getStacks().get(topPosition - 1));
Bryce Lee48f4b572017-04-10 10:54:15 -0700436 }
437
Andrii Kulian92c9a942017-10-10 00:41:41 -0700438 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700439 public void testDisplayCutout_rot0() {
440 synchronized (mWm.getWindowManagerLock()) {
Adrian Roos1cf585052018-01-03 18:43:27 +0100441 final DisplayContent dc = createNewDisplay();
442 dc.mInitialDisplayWidth = 200;
443 dc.mInitialDisplayHeight = 400;
Adrian Roos24264212018-02-19 16:26:15 +0100444 Rect r = new Rect(80, 0, 120, 10);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100445 final DisplayCutout cutout = new WmDisplayCutout(
Issei Suzuki43190bd2018-08-20 17:28:41 +0200446 fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_TOP), null)
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100447 .computeSafeInsets(200, 400).getDisplayCutout();
Adrian Roos1cf585052018-01-03 18:43:27 +0100448
449 dc.mInitialDisplayCutout = cutout;
450 dc.setRotation(Surface.ROTATION_0);
451 dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo.
452
453 assertEquals(cutout, dc.getDisplayInfo().displayCutout);
454 }
455 }
456
457 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700458 public void testDisplayCutout_rot90() {
459 synchronized (mWm.getWindowManagerLock()) {
Riddle Hsu654a6f92018-07-13 22:59:36 +0800460 // Prevent mInitialDisplayCutout from being updated from real display (e.g. null
461 // if the device has no cutout).
462 final DisplayContent dc = createDisplayNoUpdateDisplayInfo();
463 // Rotation may use real display info to compute bound, so here also uses the
464 // same width and height.
465 final int displayWidth = dc.mInitialDisplayWidth;
466 final int displayHeight = dc.mInitialDisplayHeight;
467 final int cutoutWidth = 40;
468 final int cutoutHeight = 10;
469 final int left = (displayWidth - cutoutWidth) / 2;
470 final int top = 0;
471 final int right = (displayWidth + cutoutWidth) / 2;
472 final int bottom = cutoutHeight;
473
474 final Rect r1 = new Rect(left, top, right, bottom);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100475 final DisplayCutout cutout = new WmDisplayCutout(
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700476 fromBoundingRect(r1.left, r1.top, r1.right, r1.bottom, BOUNDS_POSITION_TOP),
477 null)
Riddle Hsu654a6f92018-07-13 22:59:36 +0800478 .computeSafeInsets(displayWidth, displayHeight).getDisplayCutout();
Adrian Roos1cf585052018-01-03 18:43:27 +0100479
480 dc.mInitialDisplayCutout = cutout;
481 dc.setRotation(Surface.ROTATION_90);
482 dc.computeScreenConfiguration(new Configuration()); // recomputes dc.mDisplayInfo.
483
Riddle Hsu654a6f92018-07-13 22:59:36 +0800484 // ----o---------- -------------
485 // | | | | |
486 // | ------o | o---
487 // | | | |
488 // | | -> | |
489 // | | ---o
490 // | | |
491 // | | -------------
492 final Rect r = new Rect(top, left, bottom, right);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100493 assertEquals(new WmDisplayCutout(
Issei Suzuki43190bd2018-08-20 17:28:41 +0200494 fromBoundingRect(r.left, r.top, r.right, r.bottom, BOUNDS_POSITION_LEFT), null)
Riddle Hsu654a6f92018-07-13 22:59:36 +0800495 .computeSafeInsets(displayHeight, displayWidth)
496 .getDisplayCutout(), dc.getDisplayInfo().displayCutout);
Adrian Roos1cf585052018-01-03 18:43:27 +0100497 }
498 }
499
500 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700501 public void testLayoutSeq_assignedDuringLayout() {
502 synchronized (mWm.getWindowManagerLock()) {
Adrian Roos5251b1d2018-03-23 18:57:43 +0100503
504 final DisplayContent dc = createNewDisplay();
505 final WindowState win = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
506
507 dc.setLayoutNeeded();
508 dc.performLayout(true /* initial */, false /* updateImeWindows */);
509
510 assertThat(win.mLayoutSeq, is(dc.mLayoutSeq));
511 }
512 }
513
514 @Test
Andrii Kulian92c9a942017-10-10 00:41:41 -0700515 @SuppressLint("InlinedApi")
516 public void testOrientationDefinedByKeyguard() {
517 final DisplayContent dc = createNewDisplay();
518 // Create a window that requests landscape orientation. It will define device orientation
519 // by default.
520 final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
521 window.mAppToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
522
523 final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR, dc, "keyguard");
524 keyguard.mHasSurface = true;
525 keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
526
527 assertEquals("Screen orientation must be defined by the app window by default",
528 SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation());
529
530 keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_PORTRAIT;
531 assertEquals("Visible keyguard must influence device orientation",
532 SCREEN_ORIENTATION_PORTRAIT, dc.getOrientation());
533
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700534 mWm.setKeyguardGoingAway(true);
Andrii Kulian92c9a942017-10-10 00:41:41 -0700535 assertEquals("Keyguard that is going away must not influence device orientation",
536 SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation());
537 }
538
Andrii Kulianf0379de2018-03-14 16:24:07 -0700539 @Test
540 public void testDisableDisplayInfoOverrideFromWindowManager() {
541 final DisplayContent dc = createNewDisplay();
542
543 assertTrue(dc.mShouldOverrideDisplayConfiguration);
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700544 mWm.dontOverrideDisplayInfo(dc.getDisplayId());
Andrii Kulianf0379de2018-03-14 16:24:07 -0700545
546 assertFalse(dc.mShouldOverrideDisplayConfiguration);
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700547 verify(mWm.mDisplayManagerInternal, times(1))
Andrii Kulianf0379de2018-03-14 16:24:07 -0700548 .setDisplayInfoOverrideFromWindowManager(dc.getDisplayId(), null);
549 }
550
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800551 @Test
Riddle Hsu85bd04b2018-11-17 00:34:36 +0800552 public void testClearLastFocusWhenReparentingFocusedWindow() {
553 final DisplayContent defaultDisplay = mWm.getDefaultDisplayContentLocked();
554 final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION,
555 defaultDisplay, "window");
556 defaultDisplay.mLastFocus = window;
557 mDisplayContent.mCurrentFocus = window;
558 mDisplayContent.reParentWindowToken(window.mToken);
559
560 assertNull(defaultDisplay.mLastFocus);
561 }
562
563 @Test
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800564 public void testGetPreferredOptionsPanelGravityFromDifferentDisplays() {
565 final DisplayContent portraitDisplay = createNewDisplay();
566 portraitDisplay.mInitialDisplayHeight = 2000;
567 portraitDisplay.mInitialDisplayWidth = 1000;
568
569 portraitDisplay.setRotation(Surface.ROTATION_0);
570 assertFalse(isOptionsPanelAtRight(portraitDisplay.getDisplayId()));
571 portraitDisplay.setRotation(Surface.ROTATION_90);
572 assertTrue(isOptionsPanelAtRight(portraitDisplay.getDisplayId()));
573
574 final DisplayContent landscapeDisplay = createNewDisplay();
575 landscapeDisplay.mInitialDisplayHeight = 1000;
576 landscapeDisplay.mInitialDisplayWidth = 2000;
577
578 landscapeDisplay.setRotation(Surface.ROTATION_0);
579 assertTrue(isOptionsPanelAtRight(landscapeDisplay.getDisplayId()));
580 landscapeDisplay.setRotation(Surface.ROTATION_90);
581 assertFalse(isOptionsPanelAtRight(landscapeDisplay.getDisplayId()));
582 }
583
lumarkff0ab692018-11-05 20:32:30 +0800584 @Test
585 public void testInputMethodTargetUpdateWhenSwitchingOnDisplays() {
586 final DisplayContent newDisplay = createNewDisplay();
587
588 final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin");
589 final WindowState appWin1 = createWindow(null, TYPE_APPLICATION, newDisplay, "appWin1");
590 appWin.setHasSurface(true);
591 appWin1.setHasSurface(true);
592
593 // Set current input method window on default display, make sure the input method target
594 // is appWin & null on the other display.
595 mDisplayContent.setInputMethodWindowLocked(mImeWindow);
596 newDisplay.setInputMethodWindowLocked(null);
597 assertTrue("appWin should be IME target window",
598 appWin.equals(mDisplayContent.mInputMethodTarget));
599 assertNull("newDisplay Ime target: ", newDisplay.mInputMethodTarget);
600
601 // Switch input method window on new display & make sure the input method target also
602 // switched as expected.
603 newDisplay.setInputMethodWindowLocked(mImeWindow);
604 mDisplayContent.setInputMethodWindowLocked(null);
605 assertTrue("appWin1 should be IME target window",
606 appWin1.equals(newDisplay.mInputMethodTarget));
607 assertNull("default display Ime target: ", mDisplayContent.mInputMethodTarget);
608 }
609
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800610 private boolean isOptionsPanelAtRight(int displayId) {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700611 return (mWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800612 }
613
Bryce Lee27cec322017-03-21 09:41:37 -0700614 private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth,
615 int expectedBaseHeight, int expectedBaseDensity) {
616 assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth);
617 assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight);
618 assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity);
619 }
620
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800621 private void updateFocusedWindow() {
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700622 synchronized (mWm.mGlobalLock) {
623 mWm.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false);
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800624 }
625 }
626
Riddle Hsu654a6f92018-07-13 22:59:36 +0800627 /**
628 * Create DisplayContent that does not update display base/initial values from device to keep
629 * the values set by test.
630 */
631 private DisplayContent createDisplayNoUpdateDisplayInfo() {
632 final DisplayContent displayContent = spy(createNewDisplay());
633 doNothing().when(displayContent).updateDisplayInfo();
634 return displayContent;
635 }
636
Adrian Roos0f9368c2018-04-08 10:59:08 -0700637 private void assertForAllWindowsOrder(List<WindowState> expectedWindowsBottomToTop) {
638 final LinkedList<WindowState> actualWindows = new LinkedList<>();
Wale Ogunwale34247952017-02-19 11:57:53 -0800639
640 // Test forward traversal.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700641 mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */);
Adrian Roos0f9368c2018-04-08 10:59:08 -0700642 assertThat("bottomToTop", actualWindows, is(expectedWindowsBottomToTop));
643
644 actualWindows.clear();
Wale Ogunwale34247952017-02-19 11:57:53 -0800645
646 // Test backward traversal.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700647 mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */);
Adrian Roos0f9368c2018-04-08 10:59:08 -0700648 assertThat("topToBottom", actualWindows, is(reverseList(expectedWindowsBottomToTop)));
649 }
650
651 private static List<WindowState> reverseList(List<WindowState> list) {
652 final ArrayList<WindowState> result = new ArrayList<>(list);
653 Collections.reverse(result);
654 return result;
Wale Ogunwale34247952017-02-19 11:57:53 -0800655 }
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700656
Arthur Hungbe5ce212018-09-13 18:41:56 +0800657 private void tapOnDisplay(final DisplayContent dc) {
658 final DisplayMetrics dm = dc.getDisplayMetrics();
659 final float x = dm.widthPixels / 2;
660 final float y = dm.heightPixels / 2;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700661 final long downTime = SystemClock.uptimeMillis();
662 final long eventTime = SystemClock.uptimeMillis() + 100;
Arthur Hungbe5ce212018-09-13 18:41:56 +0800663 // sending ACTION_DOWN
664 final MotionEvent downEvent = MotionEvent.obtain(
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700665 downTime,
Arthur Hungbe5ce212018-09-13 18:41:56 +0800666 downTime,
667 MotionEvent.ACTION_DOWN,
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700668 x,
669 y,
Arthur Hungbe5ce212018-09-13 18:41:56 +0800670 0 /*metaState*/);
671 downEvent.setDisplayId(dc.getDisplayId());
672 dc.mTapDetector.onPointerEvent(downEvent);
673
674 // sending ACTION_UP
675 final MotionEvent upEvent = MotionEvent.obtain(
676 downTime,
677 eventTime,
678 MotionEvent.ACTION_UP,
679 x,
680 y,
681 0 /*metaState*/);
682 upEvent.setDisplayId(dc.getDisplayId());
683 dc.mTapDetector.onPointerEvent(upEvent);
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700684 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -0700685}