blob: ace179acdeb53f4e30a42ea1e35c71c5e59501b1 [file] [log] [blame]
Bryce Lee81e30a22017-10-06 13:34:12 -07001/*
Wale Ogunwale59507092018-10-29 09:00:30 -07002 * Copyright (C) 2018 The Android Open Source Project
Bryce Lee81e30a22017-10-06 13:34:12 -07003 *
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
Wale Ogunwale59507092018-10-29 09:00:30 -070014 * limitations under the License
Bryce Lee81e30a22017-10-06 13:34:12 -070015 */
16
Wale Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Bryce Lee81e30a22017-10-06 13:34:12 -070018
Bryce Lee81e30a22017-10-06 13:34:12 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
Garfield Tanb5cc09f2018-09-28 10:06:52 -070021import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
22import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
23import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
24import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
Garfield Tanbb0270f2018-12-05 11:30:27 -080025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
26import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
Garfield Tanb5cc09f2018-09-28 10:06:52 -070027import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
Garfield Tanbb0270f2018-12-05 11:30:27 -080028import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
Garfield Tanb5cc09f2018-09-28 10:06:52 -070029import static android.util.DisplayMetrics.DENSITY_DEFAULT;
30import static android.view.Display.DEFAULT_DISPLAY;
Bryce Leedacefc42017-10-10 12:56:02 -070031
Tadashi G. Takaokaa7a66952018-11-16 15:04:21 +090032import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
Wale Ogunwale59507092018-10-29 09:00:30 -070033import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_CONTINUE;
34import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_SKIP;
Bryce Leedacefc42017-10-10 12:56:02 -070035
Bryce Lee81e30a22017-10-06 13:34:12 -070036import static org.junit.Assert.assertEquals;
Garfield Tanb5cc09f2018-09-28 10:06:52 -070037import static org.junit.Assert.assertTrue;
38import static org.mockito.ArgumentMatchers.any;
Bryce Lee81e30a22017-10-06 13:34:12 -070039
Garfield Tanb5cc09f2018-09-28 10:06:52 -070040import android.app.ActivityOptions;
41import android.content.pm.ActivityInfo;
42import android.content.pm.ApplicationInfo;
43import android.content.res.Configuration;
Brett Chabota26eda92018-07-23 13:08:30 -070044import android.graphics.Rect;
Garfield Tanb5cc09f2018-09-28 10:06:52 -070045import android.os.Build;
Brett Chabota26eda92018-07-23 13:08:30 -070046import android.platform.test.annotations.Presubmit;
Garfield Tan891146c2018-10-09 12:14:00 -070047import android.view.Display;
Brett Chabota26eda92018-07-23 13:08:30 -070048import android.view.Gravity;
49
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090050import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070051
Wale Ogunwale59507092018-10-29 09:00:30 -070052import com.android.server.wm.LaunchParamsController.LaunchParams;
Garfield Tanb5cc09f2018-09-28 10:06:52 -070053
Brett Chabota26eda92018-07-23 13:08:30 -070054import org.junit.Before;
55import org.junit.Test;
Bryce Lee81e30a22017-10-06 13:34:12 -070056
Garfield Tanb5cc09f2018-09-28 10:06:52 -070057import java.util.Locale;
58
Bryce Lee81e30a22017-10-06 13:34:12 -070059/**
Garfield Tanb5cc09f2018-09-28 10:06:52 -070060 * Tests for default task bounds.
Bryce Lee81e30a22017-10-06 13:34:12 -070061 *
62 * Build/Install/Run:
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090063 * atest WmTests:TaskLaunchParamsModifierTests
Bryce Lee81e30a22017-10-06 13:34:12 -070064 */
Garfield Tanb5cc09f2018-09-28 10:06:52 -070065@SmallTest
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090066@Presubmit
Bryce Leeec55eb02017-12-05 20:51:27 -080067public class TaskLaunchParamsModifierTests extends ActivityTestsBase {
Bryce Lee81e30a22017-10-06 13:34:12 -070068
Garfield Tanb5cc09f2018-09-28 10:06:52 -070069 private ActivityRecord mActivity;
Bryce Lee81e30a22017-10-06 13:34:12 -070070
Garfield Tanb5cc09f2018-09-28 10:06:52 -070071 private TaskLaunchParamsModifier mTarget;
Bryce Lee81e30a22017-10-06 13:34:12 -070072
Garfield Tanb5cc09f2018-09-28 10:06:52 -070073 private LaunchParams mCurrent;
74 private LaunchParams mResult;
Bryce Leedacefc42017-10-10 12:56:02 -070075
Bryce Lee81e30a22017-10-06 13:34:12 -070076 @Before
Bryce Lee81e30a22017-10-06 13:34:12 -070077 public void setUp() throws Exception {
Garfield Tanb5cc09f2018-09-28 10:06:52 -070078 mActivity = new ActivityBuilder(mService).build();
79 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.N_MR1;
80 mActivity.info.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
Bryce Leedacefc42017-10-10 12:56:02 -070081
Garfield Tanb5cc09f2018-09-28 10:06:52 -070082 mTarget = new TaskLaunchParamsModifier(mSupervisor);
Bryce Leedacefc42017-10-10 12:56:02 -070083
Garfield Tanb5cc09f2018-09-28 10:06:52 -070084 mCurrent = new LaunchParams();
85 mCurrent.reset();
86 mResult = new LaunchParams();
87 mResult.reset();
Bryce Lee81e30a22017-10-06 13:34:12 -070088 }
89
Garfield Tan21d7e172018-10-16 18:07:27 -070090 @Test
91 public void testReturnsSkipWithEmptyActivity() {
92 final TaskRecord task = new TaskBuilder(mSupervisor).build();
93 assertEquals(RESULT_SKIP, mTarget.onCalculate(task, /* layout */ null,
94 /* activity */ null, /* source */ null, /* options */ null, mCurrent, mResult));
95 }
96
Garfield Tanb5cc09f2018-09-28 10:06:52 -070097 // =============================
98 // Display ID Related Tests
99 // =============================
Bryce Lee81e30a22017-10-06 13:34:12 -0700100 @Test
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700101 public void testDefaultToPrimaryDisplay() {
102 createNewActivityDisplay(WINDOWING_MODE_FREEFORM);
103
104 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
105 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
106
107 assertEquals(DEFAULT_DISPLAY, mResult.mPreferredDisplayId);
Bryce Lee81e30a22017-10-06 13:34:12 -0700108 }
109
Bryce Lee81e30a22017-10-06 13:34:12 -0700110 @Test
Garfield Tan891146c2018-10-09 12:14:00 -0700111 public void testUsesDefaultDisplayIfPreviousDisplayNotExists() {
112 mCurrent.mPreferredDisplayId = 19;
113
114 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
115 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
116
117 assertEquals(DEFAULT_DISPLAY, mResult.mPreferredDisplayId);
118 }
119
120 @Test
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700121 public void testUsesPreviousDisplayIdIfSet() {
122 createNewActivityDisplay(WINDOWING_MODE_FREEFORM);
123 final TestActivityDisplay display = createNewActivityDisplay(WINDOWING_MODE_FULLSCREEN);
124
125 mCurrent.mPreferredDisplayId = display.mDisplayId;
126
127 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
128 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
129
130 assertEquals(display.mDisplayId, mResult.mPreferredDisplayId);
Bryce Lee81e30a22017-10-06 13:34:12 -0700131 }
132
Bryce Lee81e30a22017-10-06 13:34:12 -0700133 @Test
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700134 public void testUsesSourcesDisplayIdIfSet() {
135 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
136 WINDOWING_MODE_FREEFORM);
137 final TestActivityDisplay fullscreenDisplay = createNewActivityDisplay(
138 WINDOWING_MODE_FULLSCREEN);
139
140 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
141
142 ActivityRecord source = createSourceActivity(fullscreenDisplay);
143
144 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
145 mActivity, source, /* options */ null, mCurrent, mResult));
146
147 assertEquals(fullscreenDisplay.mDisplayId, mResult.mPreferredDisplayId);
Bryce Lee81e30a22017-10-06 13:34:12 -0700148 }
149
Bryce Lee81e30a22017-10-06 13:34:12 -0700150 @Test
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700151 public void testUsesOptionsDisplayIdIfSet() {
152 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
153 WINDOWING_MODE_FREEFORM);
154 final TestActivityDisplay fullscreenDisplay = createNewActivityDisplay(
155 WINDOWING_MODE_FULLSCREEN);
Bryce Lee81e30a22017-10-06 13:34:12 -0700156
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700157 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
158 ActivityRecord source = createSourceActivity(freeformDisplay);
Bryce Lee81e30a22017-10-06 13:34:12 -0700159
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700160 ActivityOptions options = ActivityOptions.makeBasic();
161 options.setLaunchDisplayId(fullscreenDisplay.mDisplayId);
Bryce Lee81e30a22017-10-06 13:34:12 -0700162
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700163 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
164 mActivity, source, options, mCurrent, mResult));
165
166 assertEquals(fullscreenDisplay.mDisplayId, mResult.mPreferredDisplayId);
Bryce Lee81e30a22017-10-06 13:34:12 -0700167 }
168
Louis Chang40750092018-10-24 21:04:51 +0800169 @Test
Louis Chang6fb1e842018-12-03 16:07:50 +0800170 public void testUsesTasksDisplayIdPriorToSourceIfSet() {
171 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
172 WINDOWING_MODE_FREEFORM);
173 final TestActivityDisplay fullscreenDisplay = createNewActivityDisplay(
174 WINDOWING_MODE_FULLSCREEN);
175
176 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
177 ActivityRecord reusableActivity = createSourceActivity(fullscreenDisplay);
178 ActivityRecord source = createSourceActivity(freeformDisplay);
179
180 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(reusableActivity.getTaskRecord(),
181 /* layout */ null, mActivity, source, /* options */ null, mCurrent, mResult));
182
183 assertEquals(fullscreenDisplay.mDisplayId, mResult.mPreferredDisplayId);
184 }
185
186 @Test
Louis Chang40750092018-10-24 21:04:51 +0800187 public void testUsesTaskDisplayIdIfSet() {
188 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
189 WINDOWING_MODE_FREEFORM);
190 ActivityRecord source = createSourceActivity(freeformDisplay);
191
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800192 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(source.getTaskRecord(), null /* layout */,
Louis Chang40750092018-10-24 21:04:51 +0800193 null /* activity */, null /* source */, null /* options */, mCurrent, mResult));
194
195 assertEquals(freeformDisplay.mDisplayId, mResult.mPreferredDisplayId);
196 }
197
Louis Changd58cb672018-12-24 17:45:16 +0800198 @Test
199 public void testUsesNoDisplaySourceHandoverDisplayIdIfSet() {
200 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
201 WINDOWING_MODE_FREEFORM);
202 final TestActivityDisplay fullscreenDisplay = createNewActivityDisplay(
203 WINDOWING_MODE_FULLSCREEN);
204
205 mCurrent.mPreferredDisplayId = fullscreenDisplay.mDisplayId;
206 ActivityRecord reusableActivity = createSourceActivity(fullscreenDisplay);
207 ActivityRecord source = createSourceActivity(freeformDisplay);
208 source.mHandoverLaunchDisplayId = freeformDisplay.mDisplayId;
209 source.noDisplay = true;
210
211 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(reusableActivity.getTaskRecord(),
212 null /* layout */, mActivity, source, null /* options */, mCurrent, mResult));
213
214 assertEquals(freeformDisplay.mDisplayId, mResult.mPreferredDisplayId);
215 }
216
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700217 // =====================================
218 // Launch Windowing Mode Related Tests
219 // =====================================
220 @Test
221 public void testBoundsInOptionsInfersFreeformOnFreeformDisplay() {
222 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
223 WINDOWING_MODE_FREEFORM);
224
225 final ActivityOptions options = ActivityOptions.makeBasic();
226 options.setLaunchBounds(new Rect(0, 0, 100, 100));
227
228 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
229
230 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
231 mActivity, /* source */ null, options, mCurrent, mResult));
232
233 assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
234 WINDOWING_MODE_FREEFORM);
235 }
236
237 @Test
238 public void testBoundsInOptionsInfersFreeformWithResizeableActivity() {
239 final ActivityOptions options = ActivityOptions.makeBasic();
240 options.setLaunchBounds(new Rect(0, 0, 100, 100));
241
242 mCurrent.mPreferredDisplayId = DEFAULT_DISPLAY;
243
244 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
245 mActivity, /* source */ null, options, mCurrent, mResult));
246
Garfield Tan706dbcb2018-10-15 11:33:02 -0700247 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700248 WINDOWING_MODE_FULLSCREEN);
249 }
250
251 @Test
252 public void testKeepsPictureInPictureLaunchModeInOptions() {
253 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
254 WINDOWING_MODE_FREEFORM);
255
256 final ActivityOptions options = ActivityOptions.makeBasic();
257 options.setLaunchWindowingMode(WINDOWING_MODE_PINNED);
258
259 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
260
261 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
262 mActivity, /* source */ null, options, mCurrent, mResult));
263
264 assertEquivalentWindowingMode(WINDOWING_MODE_PINNED, mResult.mWindowingMode,
265 WINDOWING_MODE_FREEFORM);
266 }
267
268 @Test
269 public void testKeepsPictureInPictureLaunchModeWithBoundsInOptions() {
270 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
271 WINDOWING_MODE_FREEFORM);
272
273 final ActivityOptions options = ActivityOptions.makeBasic();
274 options.setLaunchWindowingMode(WINDOWING_MODE_PINNED);
275 options.setLaunchBounds(new Rect(0, 0, 100, 100));
276
277 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
278
279 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
280 mActivity, /* source */ null, options, mCurrent, mResult));
281
282 assertEquivalentWindowingMode(WINDOWING_MODE_PINNED, mResult.mWindowingMode,
283 WINDOWING_MODE_FREEFORM);
284 }
285
286 @Test
287 public void testKeepsFullscreenLaunchModeInOptionsOnNonFreeformDisplay() {
288 final ActivityOptions options = ActivityOptions.makeBasic();
289 options.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN);
290
291 mCurrent.mPreferredDisplayId = DEFAULT_DISPLAY;
292
293 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
294 mActivity, /* source */ null, options, mCurrent, mResult));
295
296 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
297 WINDOWING_MODE_FULLSCREEN);
298 }
299
300 @Test
301 public void testNonEmptyLayoutInfersFreeformOnFreeformDisplay() {
302 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
303 WINDOWING_MODE_FREEFORM);
304
305 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
306
307 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
308 .setWidth(120).setHeight(80).build();
309
310 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
311 /* source */ null, /* options */ null, mCurrent, mResult));
312
313 assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
314 WINDOWING_MODE_FREEFORM);
315 }
316
317 @Test
318 public void testNonEmptyLayoutInfersFreeformWithEmptySize() {
319 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
320 WINDOWING_MODE_FREEFORM);
321
322 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
323
324 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
325 .setGravity(Gravity.LEFT).build();
326
327 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
328 /* source */ null, /* options */ null, mCurrent, mResult));
329
330 assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
331 WINDOWING_MODE_FREEFORM);
332 }
333
334 @Test
Garfield Tan706dbcb2018-10-15 11:33:02 -0700335 public void testNonEmptyLayoutUsesFullscreenWithResizeableActivity() {
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700336 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
337 .setWidth(120).setHeight(80).build();
338
339 mCurrent.mPreferredDisplayId = DEFAULT_DISPLAY;
340
341 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
342 /* source */ null, /* options */ null, mCurrent, mResult));
343
Garfield Tan706dbcb2018-10-15 11:33:02 -0700344 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700345 WINDOWING_MODE_FULLSCREEN);
346 }
347
348 @Test
349 public void testRespectsFullyResolvedCurrentParam_Fullscreen() {
350 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
351 WINDOWING_MODE_FREEFORM);
352
353 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
354 mCurrent.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
355
356 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
357 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
358
359 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
360 WINDOWING_MODE_FREEFORM);
361 }
362
363 @Test
364 public void testRespectsModeFromFullyResolvedCurrentParam_NonEmptyBounds() {
365 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
366 WINDOWING_MODE_FREEFORM);
367
368 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
369 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
370 mCurrent.mBounds.set(0, 0, 200, 100);
371
372 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
373 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
374
375 assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
376 WINDOWING_MODE_FREEFORM);
377 }
378
379 @Test
380 public void testForceMaximizesPreDApp() {
381 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
382 WINDOWING_MODE_FREEFORM);
383
384 final ActivityOptions options = ActivityOptions.makeBasic();
385 options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
386 options.setLaunchBounds(new Rect(0, 0, 200, 100));
387
388 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
389 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
390 mCurrent.mBounds.set(0, 0, 200, 100);
391
392 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.CUPCAKE;
393
394 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
395 mActivity, /* source */ null, options, mCurrent, mResult));
396
397 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
398 WINDOWING_MODE_FREEFORM);
399 }
400
401 @Test
402 public void testForceMaximizesAppWithoutMultipleDensitySupport() {
403 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
404 WINDOWING_MODE_FREEFORM);
405
406 final ActivityOptions options = ActivityOptions.makeBasic();
407 options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
408 options.setLaunchBounds(new Rect(0, 0, 200, 100));
409
410 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
411 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
412 mCurrent.mBounds.set(0, 0, 200, 100);
413
414 mActivity.appInfo.flags = 0;
415
416 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
417 mActivity, /* source */ null, options, mCurrent, mResult));
418
419 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
420 WINDOWING_MODE_FREEFORM);
421 }
422
423 @Test
424 public void testForceMaximizesUnresizeableApp() {
425 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
426 WINDOWING_MODE_FREEFORM);
427
428 final ActivityOptions options = ActivityOptions.makeBasic();
429 options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
430 options.setLaunchBounds(new Rect(0, 0, 200, 100));
431
432 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
433 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
434 mCurrent.mBounds.set(0, 0, 200, 100);
435
436 mActivity.info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
437
438 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
439 mActivity, /* source */ null, options, mCurrent, mResult));
440
441 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
442 WINDOWING_MODE_FREEFORM);
443 }
444
445 @Test
446 public void testSkipsForceMaximizingAppsOnNonFreeformDisplay() {
447 final ActivityOptions options = ActivityOptions.makeBasic();
448 options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
449 options.setLaunchBounds(new Rect(0, 0, 200, 100));
450
451 mCurrent.mPreferredDisplayId = DEFAULT_DISPLAY;
452 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
453 mCurrent.mBounds.set(0, 0, 200, 100);
454
455 mActivity.info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
456
457 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
458 mActivity, /* source */ null, options, mCurrent, mResult));
459
460 assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
461 WINDOWING_MODE_FULLSCREEN);
462 }
463
464 @Test
465 public void testUsesFullscreenOnNonFreeformDisplay() {
466 final ActivityOptions options = ActivityOptions.makeBasic();
467 options.setLaunchDisplayId(DEFAULT_DISPLAY);
468
469 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
470 mActivity, /* source */ null, options, mCurrent, mResult));
471
472 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
473 WINDOWING_MODE_FULLSCREEN);
474 }
475
476 @Test
477 public void testUsesFreeformByDefaultForPostNApp() {
478 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
479 WINDOWING_MODE_FREEFORM);
480
481 final ActivityOptions options = ActivityOptions.makeBasic();
482 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
483
484 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
485 mActivity, /* source */ null, options, mCurrent, mResult));
486
487 assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
488 WINDOWING_MODE_FREEFORM);
489 }
490
491 @Test
492 public void testUsesFreeformByDefaultForPreNResizeableAppWithoutOrientationRequest() {
493 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
494 WINDOWING_MODE_FREEFORM);
495
496 final ActivityOptions options = ActivityOptions.makeBasic();
497 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
498
499 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
500
501 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
502 mActivity, /* source */ null, options, mCurrent, mResult));
503
504 assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
505 WINDOWING_MODE_FREEFORM);
506 }
507
508 @Test
509 public void testSkipsFreeformForPreNResizeableAppOnNonFullscreenDisplay() {
510 final ActivityOptions options = ActivityOptions.makeBasic();
511 options.setLaunchDisplayId(DEFAULT_DISPLAY);
512
513 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
514
515 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
516 mActivity, /* source */ null, options, mCurrent, mResult));
517
518 assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
519 WINDOWING_MODE_FULLSCREEN);
520 }
521
522 // ================================
523 // Launching Bounds Related Tests
524 // ===============================
525 @Test
526 public void testKeepsBoundsWithPictureInPictureLaunchModeInOptions() {
527 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
528 WINDOWING_MODE_FREEFORM);
529
530 final ActivityOptions options = ActivityOptions.makeBasic();
531 options.setLaunchWindowingMode(WINDOWING_MODE_PINNED);
532
533 final Rect expected = new Rect(0, 0, 100, 100);
534 options.setLaunchBounds(expected);
535
536 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
537
538 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
539 mActivity, /* source */ null, options, mCurrent, mResult));
540
541 assertEquals(expected, mResult.mBounds);
542 }
543
544 @Test
545 public void testNonEmptyLayoutBoundsRespectsGravityWithEmptySize_LeftGravity() {
546 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
547 WINDOWING_MODE_FREEFORM);
548
549 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
550
551 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
552 .setGravity(Gravity.LEFT).build();
553
554 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
555 /* source */ null, /* options */ null, mCurrent, mResult));
556
557 assertEquals(0, mResult.mBounds.left);
558 }
559
560 @Test
561 public void testNonEmptyLayoutBoundsRespectsGravityWithEmptySize_TopGravity() {
562 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
563 WINDOWING_MODE_FREEFORM);
564
565 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
566
567 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
568 .setGravity(Gravity.TOP).build();
569
570 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
571 /* source */ null, /* options */ null, mCurrent, mResult));
572
573 assertEquals(0, mResult.mBounds.top);
574 }
575
576 @Test
577 public void testNonEmptyLayoutBoundsRespectsGravityWithEmptySize_TopLeftGravity() {
578 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
579 WINDOWING_MODE_FREEFORM);
580
581 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
582
583 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
584 .setGravity(Gravity.TOP | Gravity.LEFT).build();
585
586 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
587 /* source */ null, /* options */ null, mCurrent, mResult));
588
589 assertEquals(0, mResult.mBounds.left);
590 assertEquals(0, mResult.mBounds.top);
591 }
592
593 @Test
594 public void testNonEmptyLayoutBoundsRespectsGravityWithEmptySize_RightGravity() {
595 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
596 WINDOWING_MODE_FREEFORM);
597
598 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
599
600 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
601 .setGravity(Gravity.RIGHT).build();
602
603 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
604 /* source */ null, /* options */ null, mCurrent, mResult));
605
606 assertEquals(1920, mResult.mBounds.right);
607 }
608
609 @Test
610 public void testNonEmptyLayoutBoundsRespectsGravityWithEmptySize_BottomGravity() {
611 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
612 WINDOWING_MODE_FREEFORM);
613
614 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
615
616 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
617 .setGravity(Gravity.BOTTOM).build();
618
619 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
620 /* source */ null, /* options */ null, mCurrent, mResult));
621
622 assertEquals(1080, mResult.mBounds.bottom);
623 }
624
625 @Test
626 public void testNonEmptyLayoutBoundsRespectsGravityWithEmptySize_BottomRightGravity() {
627 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
628 WINDOWING_MODE_FREEFORM);
629
630 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
631
632 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
633 .setGravity(Gravity.BOTTOM | Gravity.RIGHT).build();
634
635 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
636 /* source */ null, /* options */ null, mCurrent, mResult));
637
638 assertEquals(1920, mResult.mBounds.right);
639 assertEquals(1080, mResult.mBounds.bottom);
640 }
641
642 @Test
643 public void testNonEmptyLayoutBoundsOnFreeformDisplay_CenterToDisplay() {
644 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
645 WINDOWING_MODE_FREEFORM);
646
647 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
648
649 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
650 .setWidth(120).setHeight(80).build();
651
652 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
653 /* source */ null, /* options */ null, mCurrent, mResult));
654
655 assertEquals(new Rect(900, 500, 1020, 580), mResult.mBounds);
656 }
657
658 @Test
659 public void testNonEmptyLayoutBoundsOnFreeformDisplay_LeftGravity() {
660 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
661 WINDOWING_MODE_FREEFORM);
662
663 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
664
665 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
666 .setWidth(120).setHeight(80).setGravity(Gravity.LEFT).build();
667
668 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
669 /* source */ null, /* options */ null, mCurrent, mResult));
670
671 assertEquals(new Rect(0, 500, 120, 580), mResult.mBounds);
672 }
673
674 @Test
675 public void testNonEmptyLayoutBoundsOnFreeformDisplay_TopGravity() {
676 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
677 WINDOWING_MODE_FREEFORM);
678
679 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
680
681 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
682 .setWidth(120).setHeight(80).setGravity(Gravity.TOP).build();
683
684 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
685 /* source */ null, /* options */ null, mCurrent, mResult));
686
687 assertEquals(new Rect(900, 0, 1020, 80), mResult.mBounds);
688 }
689
690 @Test
691 public void testNonEmptyLayoutBoundsOnFreeformDisplay_TopLeftGravity() {
692 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
693 WINDOWING_MODE_FREEFORM);
694
695 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
696
697 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
698 .setWidth(120).setHeight(80).setGravity(Gravity.TOP | Gravity.LEFT).build();
699
700 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
701 /* source */ null, /* options */ null, mCurrent, mResult));
702
703 assertEquals(new Rect(0, 0, 120, 80), mResult.mBounds);
704 }
705
706 @Test
707 public void testNonEmptyLayoutBoundsOnFreeformDisplay_RightGravity() {
708 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
709 WINDOWING_MODE_FREEFORM);
710
711 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
712
713 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
714 .setWidth(120).setHeight(80).setGravity(Gravity.RIGHT).build();
715
716 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
717 /* source */ null, /* options */ null, mCurrent, mResult));
718
719 assertEquals(new Rect(1800, 500, 1920, 580), mResult.mBounds);
720 }
721
722 @Test
723 public void testNonEmptyLayoutBoundsOnFreeformDisplay_BottomGravity() {
724 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
725 WINDOWING_MODE_FREEFORM);
726
727 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
728
729 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
730 .setWidth(120).setHeight(80).setGravity(Gravity.BOTTOM).build();
731
732 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
733 /* source */ null, /* options */ null, mCurrent, mResult));
734
735 assertEquals(new Rect(900, 1000, 1020, 1080), mResult.mBounds);
736 }
737
738 @Test
739 public void testNonEmptyLayoutBoundsOnFreeformDisplay_RightBottomGravity() {
740 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
741 WINDOWING_MODE_FREEFORM);
742
743 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
744
745 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
746 .setWidth(120).setHeight(80).setGravity(Gravity.BOTTOM | Gravity.RIGHT).build();
747
748 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
749 /* source */ null, /* options */ null, mCurrent, mResult));
750
751 assertEquals(new Rect(1800, 1000, 1920, 1080), mResult.mBounds);
752 }
753
754 @Test
755 public void testNonEmptyLayoutFractionBoundsOnFreeformDisplay() {
756 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
757 WINDOWING_MODE_FREEFORM);
758
759 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
760
761 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
762 .setWidthFraction(0.0625f).setHeightFraction(0.1f).build();
763
764 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
765 /* source */ null, /* options */ null, mCurrent, mResult));
766
767 assertEquals(new Rect(900, 486, 1020, 594), mResult.mBounds);
768 }
769
770 @Test
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700771 public void testRespectBoundsFromFullyResolvedCurrentParam_NonEmptyBounds() {
772 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
773 WINDOWING_MODE_FREEFORM);
774
775 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
776 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
777 mCurrent.mBounds.set(0, 0, 200, 100);
778
779 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
780 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
781
782 assertEquals(new Rect(0, 0, 200, 100), mResult.mBounds);
783 }
784
785 @Test
Garfield Tand5972d12019-01-03 10:31:59 -0800786 public void testReturnBoundsForFullscreenWindowingMode() {
787 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
788 WINDOWING_MODE_FREEFORM);
789
790 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
791 mCurrent.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
792 mCurrent.mBounds.set(0, 0, 200, 100);
793
794 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
795 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
796
797 assertEquals(new Rect(0, 0, 200, 100), mResult.mBounds);
798 }
799
800 @Test
Garfield Tanbb0270f2018-12-05 11:30:27 -0800801 public void testUsesDisplayOrientationForNoSensorOrientation() {
802 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
803 WINDOWING_MODE_FREEFORM);
804
805 final ActivityOptions options = ActivityOptions.makeBasic();
806 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
807 options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
808
809 mActivity.info.screenOrientation = SCREEN_ORIENTATION_NOSENSOR;
810
811 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
812 mActivity, /* source */ null, options, mCurrent, mResult));
813
814 final int orientationForDisplay = orientationFromBounds(freeformDisplay.getBounds());
815 final int orientationForTask = orientationFromBounds(mResult.mBounds);
816 assertEquals("Launch bounds orientation should be the same as the display, but"
817 + " display orientation is "
818 + ActivityInfo.screenOrientationToString(orientationForDisplay)
819 + " launch bounds orientation is "
820 + ActivityInfo.screenOrientationToString(orientationForTask),
821 orientationForDisplay, orientationForTask);
822 }
823
824 @Test
825 public void testRespectsAppRequestedOrientation_Landscape() {
826 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
827 WINDOWING_MODE_FREEFORM);
828
829 final ActivityOptions options = ActivityOptions.makeBasic();
830 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
831 options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
832
833 mActivity.info.screenOrientation = SCREEN_ORIENTATION_LANDSCAPE;
834
835 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
836 mActivity, /* source */ null, options, mCurrent, mResult));
837
838 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, orientationFromBounds(mResult.mBounds));
839 }
840
841 @Test
842 public void testRespectsAppRequestedOrientation_Portrait() {
843 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
844 WINDOWING_MODE_FREEFORM);
845
846 final ActivityOptions options = ActivityOptions.makeBasic();
847 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
848 options.setLaunchWindowingMode(WINDOWING_MODE_FREEFORM);
849
850 mActivity.info.screenOrientation = SCREEN_ORIENTATION_PORTRAIT;
851
852 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
853 mActivity, /* source */ null, options, mCurrent, mResult));
854
855 assertEquals(SCREEN_ORIENTATION_PORTRAIT, orientationFromBounds(mResult.mBounds));
856 }
857
858 @Test
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700859 public void testDefaultSizeSmallerThanBigScreen() {
860 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
861 WINDOWING_MODE_FREEFORM);
862
863 final ActivityOptions options = ActivityOptions.makeBasic();
864 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
865
866 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
867
868 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
869 mActivity, /* source */ null, options, mCurrent, mResult));
870
871 final int resultWidth = mResult.mBounds.width();
872 final int displayWidth = freeformDisplay.getBounds().width();
873 assertTrue("Result width " + resultWidth + " is not smaller than " + displayWidth,
874 resultWidth < displayWidth);
875
876 final int resultHeight = mResult.mBounds.height();
877 final int displayHeight = freeformDisplay.getBounds().height();
878 assertTrue("Result width " + resultHeight + " is not smaller than "
879 + displayHeight, resultHeight < displayHeight);
880 }
881
882 @Test
883 public void testDefaultFreeformSizeCenteredToDisplay() {
884 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
885 WINDOWING_MODE_FREEFORM);
886
887 final ActivityOptions options = ActivityOptions.makeBasic();
888 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
889
890 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
891
892 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
893 mActivity, /* source */ null, options, mCurrent, mResult));
894
895 final Rect displayBounds = freeformDisplay.getBounds();
896 assertEquals("Distance to left and right should be equal.",
897 mResult.mBounds.left - displayBounds.left,
898 displayBounds.right - mResult.mBounds.right);
899 assertEquals("Distance to top and bottom should be equal.",
900 mResult.mBounds.top - displayBounds.top,
901 displayBounds.bottom - mResult.mBounds.bottom);
902 }
903
904 @Test
905 public void testCascadesToSourceSizeForFreeform() {
906 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
907 WINDOWING_MODE_FREEFORM);
908
909 final ActivityOptions options = ActivityOptions.makeBasic();
910 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
911
912 final ActivityRecord source = createSourceActivity(freeformDisplay);
913 source.setBounds(0, 0, 412, 732);
914
915 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
916
917 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
918 mActivity, source, options, mCurrent, mResult));
919
920 final Rect displayBounds = freeformDisplay.getBounds();
921 assertTrue("Left bounds should be larger than 0.", mResult.mBounds.left > 0);
922 assertTrue("Top bounds should be larger than 0.", mResult.mBounds.top > 0);
923 assertTrue("Bounds should be centered at somewhere in the left half, but it's "
924 + "centerX is " + mResult.mBounds.centerX(),
925 mResult.mBounds.centerX() < displayBounds.centerX());
926 assertTrue("Bounds should be centered at somewhere in the top half, but it's "
927 + "centerY is " + mResult.mBounds.centerY(),
928 mResult.mBounds.centerY() < displayBounds.centerY());
929 }
930
931 @Test
932 public void testAdjustBoundsToFitDisplay_TopLeftOutOfDisplay() {
933 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
934 WINDOWING_MODE_FREEFORM);
935
936 final ActivityOptions options = ActivityOptions.makeBasic();
937 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
938
939 final ActivityRecord source = createSourceActivity(freeformDisplay);
940 source.setBounds(0, 0, 200, 400);
941
942 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
943
944 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
945 mActivity, source, options, mCurrent, mResult));
946
947 final Rect displayBounds = freeformDisplay.getBounds();
948 assertTrue("display bounds doesn't contain result. display bounds: "
949 + displayBounds + " result: " + mResult.mBounds,
950 displayBounds.contains(mResult.mBounds));
951 }
952
953 @Test
954 public void testAdjustBoundsToFitDisplay_BottomRightOutOfDisplay() {
955 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
956 WINDOWING_MODE_FREEFORM);
957
958 final ActivityOptions options = ActivityOptions.makeBasic();
959 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
960
961 final ActivityRecord source = createSourceActivity(freeformDisplay);
962 source.setBounds(1720, 680, 1920, 1080);
963
964 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
965
966 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
967 mActivity, source, options, mCurrent, mResult));
968
969 final Rect displayBounds = freeformDisplay.getBounds();
970 assertTrue("display bounds doesn't contain result. display bounds: "
971 + displayBounds + " result: " + mResult.mBounds,
972 displayBounds.contains(mResult.mBounds));
973 }
974
975 @Test
Garfield Tan891146c2018-10-09 12:14:00 -0700976 public void testAdjustBoundsToFitNewDisplay_LargerThanDisplay() {
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700977 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
978 WINDOWING_MODE_FREEFORM);
979
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700980 final ActivityOptions options = ActivityOptions.makeBasic();
981 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
982
Garfield Tan891146c2018-10-09 12:14:00 -0700983 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
984 mCurrent.mBounds.set(100, 200, 2120, 1380);
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700985
986 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
987
988 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
Garfield Tan891146c2018-10-09 12:14:00 -0700989 mActivity, /* source */ null, options, mCurrent, mResult));
Garfield Tanb5cc09f2018-09-28 10:06:52 -0700990
Garfield Tan891146c2018-10-09 12:14:00 -0700991 assertTrue("Result bounds should start from origin, but it's " + mResult.mBounds,
992 mResult.mBounds.left == 0 && mResult.mBounds.top == 0);
993 }
994
995 @Test
996 public void testAdjustBoundsToFitNewDisplay_LargerThanDisplay_RTL() {
Evan Roskydfe3da72018-10-26 17:21:06 -0700997 final Configuration overrideConfig =
998 mRootActivityContainer.getRequestedOverrideConfiguration();
Garfield Tan891146c2018-10-09 12:14:00 -0700999 // Egyptian Arabic is a RTL language.
1000 overrideConfig.setLayoutDirection(new Locale("ar", "EG"));
Evan Roskydfe3da72018-10-26 17:21:06 -07001001 mRootActivityContainer.onRequestedOverrideConfigurationChanged(overrideConfig);
Garfield Tan891146c2018-10-09 12:14:00 -07001002
1003 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1004 WINDOWING_MODE_FREEFORM);
1005
1006 final ActivityOptions options = ActivityOptions.makeBasic();
1007 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1008
1009 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
1010 mCurrent.mBounds.set(100, 200, 2120, 1380);
1011
1012 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
1013
1014 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1015 mActivity, /* source */ null, options, mCurrent, mResult));
1016
1017 assertTrue("Result bounds should start from origin, but it's " + mResult.mBounds,
1018 mResult.mBounds.left == -100 && mResult.mBounds.top == 0);
Garfield Tanb5cc09f2018-09-28 10:06:52 -07001019 }
1020
1021 @Test
1022 public void testRespectsLayoutMinDimensions() {
1023 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1024 WINDOWING_MODE_FREEFORM);
1025
1026 final ActivityOptions options = ActivityOptions.makeBasic();
1027 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1028
1029 final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
1030 .setMinWidth(500).setMinHeight(800).build();
1031
1032 mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP;
1033
1034 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
1035 /* source */ null, options, mCurrent, mResult));
1036
1037 assertEquals(500, mResult.mBounds.width());
1038 assertEquals(800, mResult.mBounds.height());
1039 }
1040
1041 @Test
1042 public void testRotatesInPlaceInitialBoundsMismatchOrientation() {
1043 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1044 WINDOWING_MODE_FREEFORM);
1045
1046 final ActivityOptions options = ActivityOptions.makeBasic();
1047 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1048 options.setLaunchBounds(new Rect(100, 100, 500, 300));
1049
1050 mActivity.info.screenOrientation = SCREEN_ORIENTATION_PORTRAIT;
1051
1052 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1053 mActivity, /* source */ null, options, mCurrent, mResult));
1054
1055 assertEquals(new Rect(200, 0, 400, 400), mResult.mBounds);
1056 }
1057
1058 @Test
1059 public void testShiftsToRightForCloseToLeftBoundsWhenConflict() {
1060 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1061 WINDOWING_MODE_FREEFORM);
1062
1063 addFreeformTaskTo(freeformDisplay, new Rect(50, 50, 100, 150));
1064
1065 final ActivityOptions options = ActivityOptions.makeBasic();
1066 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1067 options.setLaunchBounds(new Rect(50, 50, 500, 300));
1068
1069 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1070 mActivity, /* source */ null, options, mCurrent, mResult));
1071
1072 assertEquals(new Rect(170, 50, 620, 300), mResult.mBounds);
1073 }
1074
1075 @Test
1076 public void testShiftsToLeftForCloseToRightBoundsWhenConflict() {
1077 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1078 WINDOWING_MODE_FREEFORM);
1079
1080 addFreeformTaskTo(freeformDisplay, new Rect(1720, 50, 1830, 150));
1081
1082 final ActivityOptions options = ActivityOptions.makeBasic();
1083 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1084 options.setLaunchBounds(new Rect(1720, 50, 1850, 300));
1085
1086 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1087 mActivity, /* source */ null, options, mCurrent, mResult));
1088
1089 assertEquals(new Rect(1600, 50, 1730, 300), mResult.mBounds);
1090 }
1091
1092 @Test
1093 public void testShiftsToRightFirstForHorizontallyCenteredAndCloseToTopWhenConflict() {
1094 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1095 WINDOWING_MODE_FREEFORM);
1096
1097 addFreeformTaskTo(freeformDisplay, new Rect(0, 0, 100, 300));
1098
1099 final ActivityOptions options = ActivityOptions.makeBasic();
1100 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1101 options.setLaunchBounds(new Rect(0, 0, 1800, 200));
1102
1103 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1104 mActivity, /* source */ null, options, mCurrent, mResult));
1105
1106 assertEquals(new Rect(120, 0, 1920, 200), mResult.mBounds);
1107 }
1108
1109 @Test
1110 public void testShiftsToLeftNoSpaceOnRightForHorizontallyCenteredAndCloseToTopWhenConflict() {
1111 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1112 WINDOWING_MODE_FREEFORM);
1113
1114 addFreeformTaskTo(freeformDisplay, new Rect(120, 0, 240, 300));
1115
1116 final ActivityOptions options = ActivityOptions.makeBasic();
1117 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1118 options.setLaunchBounds(new Rect(120, 0, 1860, 200));
1119
1120 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1121 mActivity, /* source */ null, options, mCurrent, mResult));
1122
1123 assertEquals(new Rect(0, 0, 1740, 200), mResult.mBounds);
1124 }
1125
1126 @Test
1127 public void testShiftsToBottomRightFirstForCenteredBoundsWhenConflict() {
1128 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1129 WINDOWING_MODE_FREEFORM);
1130
1131 addFreeformTaskTo(freeformDisplay, new Rect(120, 0, 240, 100));
1132
1133 final ActivityOptions options = ActivityOptions.makeBasic();
1134 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1135 options.setLaunchBounds(new Rect(120, 0, 1800, 1013));
1136
1137 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1138 mActivity, /* source */ null, options, mCurrent, mResult));
1139
1140 assertEquals(new Rect(240, 67, 1920, 1080), mResult.mBounds);
1141 }
1142
1143 @Test
1144 public void testShiftsToTopLeftIfNoSpaceOnBottomRightForCenteredBoundsWhenConflict() {
1145 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1146 WINDOWING_MODE_FREEFORM);
1147
1148 addFreeformTaskTo(freeformDisplay, new Rect(120, 67, 240, 100));
1149
1150 final ActivityOptions options = ActivityOptions.makeBasic();
1151 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1152 options.setLaunchBounds(new Rect(120, 67, 1800, 1020));
1153
1154 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1155 mActivity, /* source */ null, options, mCurrent, mResult));
1156
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +09001157 assertEquals(new Rect(0, 0, 1680, 953), mResult.mBounds);
Garfield Tanb5cc09f2018-09-28 10:06:52 -07001158 }
1159
Garfield Tan891146c2018-10-09 12:14:00 -07001160 @Test
1161 public void testAdjustsBoundsToFitInDisplayFullyResolvedBounds() {
1162 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1163 WINDOWING_MODE_FREEFORM);
1164
1165 mCurrent.mPreferredDisplayId = Display.INVALID_DISPLAY;
1166 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
1167 mCurrent.mBounds.set(-100, -200, 200, 100);
1168
1169 final ActivityOptions options = ActivityOptions.makeBasic();
1170 options.setLaunchDisplayId(freeformDisplay.mDisplayId);
1171
1172 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1173 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
1174
1175 assertEquals(new Rect(0, 0, 300, 300), mResult.mBounds);
1176 }
1177
1178 @Test
1179 public void testAdjustsBoundsToAvoidConflictFullyResolvedBounds() {
1180 final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
1181 WINDOWING_MODE_FREEFORM);
1182
1183 addFreeformTaskTo(freeformDisplay, new Rect(0, 0, 200, 100));
1184
1185 mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId;
1186 mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM;
1187 mCurrent.mBounds.set(0, 0, 200, 100);
1188
1189 assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
1190 mActivity, /* source */ null, /* options */ null, mCurrent, mResult));
1191
1192 assertEquals(new Rect(120, 0, 320, 100), mResult.mBounds);
1193 }
1194
Garfield Tanb5cc09f2018-09-28 10:06:52 -07001195 private TestActivityDisplay createNewActivityDisplay(int windowingMode) {
1196 final TestActivityDisplay display = addNewActivityDisplayAt(ActivityDisplay.POSITION_TOP);
1197 display.setWindowingMode(windowingMode);
1198 display.setBounds(/* left */ 0, /* top */ 0, /* right */ 1920, /* bottom */ 1080);
1199 display.getConfiguration().densityDpi = DENSITY_DEFAULT;
Garfield Tanbb0270f2018-12-05 11:30:27 -08001200 display.getConfiguration().orientation = ORIENTATION_LANDSCAPE;
Garfield Tanb5cc09f2018-09-28 10:06:52 -07001201 return display;
1202 }
1203
1204 private ActivityRecord createSourceActivity(TestActivityDisplay display) {
1205 final TestActivityStack stack = display.createStack(display.getWindowingMode(),
1206 ACTIVITY_TYPE_STANDARD, true);
1207 return new ActivityBuilder(mService).setStack(stack).setCreateTask(true).build();
1208 }
1209
1210 private void addFreeformTaskTo(TestActivityDisplay display, Rect bounds) {
1211 final TestActivityStack stack = display.createStack(display.getWindowingMode(),
1212 ACTIVITY_TYPE_STANDARD, true);
1213 stack.setWindowingMode(WINDOWING_MODE_FREEFORM);
1214 final TaskRecord task = new TaskBuilder(mSupervisor).setStack(stack).build();
1215 task.setBounds(bounds);
1216 }
1217
1218 private void assertEquivalentWindowingMode(int expected, int actual, int parentWindowingMode) {
1219 if (expected != parentWindowingMode) {
1220 assertEquals(expected, actual);
1221 } else {
1222 assertEquals(WINDOWING_MODE_UNDEFINED, actual);
Bryce Leedacefc42017-10-10 12:56:02 -07001223 }
Bryce Lee81e30a22017-10-06 13:34:12 -07001224 }
1225
Garfield Tanbb0270f2018-12-05 11:30:27 -08001226 private int orientationFromBounds(Rect bounds) {
1227 return bounds.width() > bounds.height() ? SCREEN_ORIENTATION_LANDSCAPE
1228 : SCREEN_ORIENTATION_PORTRAIT;
1229 }
1230
Garfield Tanb5cc09f2018-09-28 10:06:52 -07001231 private static class WindowLayoutBuilder {
1232 private int mWidth = -1;
1233 private int mHeight = -1;
1234 private float mWidthFraction = -1f;
1235 private float mHeightFraction = -1f;
1236 private int mGravity = Gravity.NO_GRAVITY;
1237 private int mMinWidth = -1;
1238 private int mMinHeight = -1;
Bryce Lee81e30a22017-10-06 13:34:12 -07001239
Garfield Tanb5cc09f2018-09-28 10:06:52 -07001240 private WindowLayoutBuilder setWidth(int width) {
1241 mWidth = width;
1242 return this;
Bryce Lee81e30a22017-10-06 13:34:12 -07001243 }
1244
Garfield Tanb5cc09f2018-09-28 10:06:52 -07001245 private WindowLayoutBuilder setHeight(int height) {
1246 mHeight = height;
1247 return this;
1248 }
1249
1250 private WindowLayoutBuilder setWidthFraction(float widthFraction) {
1251 mWidthFraction = widthFraction;
1252 return this;
1253 }
1254
1255 private WindowLayoutBuilder setHeightFraction(float heightFraction) {
1256 mHeightFraction = heightFraction;
1257 return this;
1258 }
1259
1260 private WindowLayoutBuilder setGravity(int gravity) {
1261 mGravity = gravity;
1262 return this;
1263 }
1264
1265 private WindowLayoutBuilder setMinWidth(int minWidth) {
1266 mMinWidth = minWidth;
1267 return this;
1268 }
1269
1270 private WindowLayoutBuilder setMinHeight(int minHeight) {
1271 mMinHeight = minHeight;
1272 return this;
1273 }
1274
1275 private ActivityInfo.WindowLayout build() {
1276 return new ActivityInfo.WindowLayout(mWidth, mWidthFraction, mHeight, mHeightFraction,
1277 mGravity, mMinWidth, mMinHeight);
1278 }
Bryce Lee81e30a22017-10-06 13:34:12 -07001279 }
1280}