Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
| 19 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 20 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
| 21 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 22 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
| 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 24 | import static android.view.Surface.ROTATION_270; |
| 25 | import static android.view.Surface.ROTATION_90; |
| 26 | |
| 27 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
| 28 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq; |
| 29 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
| 30 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
| 31 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
| 32 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 33 | |
| 34 | import static org.junit.Assert.assertEquals; |
| 35 | import static org.junit.Assert.assertFalse; |
| 36 | import static org.junit.Assert.assertNotEquals; |
| 37 | import static org.junit.Assert.assertTrue; |
| 38 | import static org.mockito.ArgumentMatchers.anyString; |
| 39 | import static org.mockito.Mockito.when; |
| 40 | |
| 41 | import android.app.ActivityManager; |
| 42 | import android.app.ActivityManagerInternal; |
| 43 | import android.app.TaskStackListener; |
| 44 | import android.app.WindowConfiguration; |
| 45 | import android.content.pm.ActivityInfo; |
| 46 | import android.content.res.Configuration; |
| 47 | import android.graphics.Rect; |
| 48 | import android.os.IBinder; |
| 49 | import android.platform.test.annotations.Presubmit; |
| 50 | |
| 51 | import androidx.test.filters.MediumTest; |
| 52 | |
| 53 | import org.junit.Test; |
| 54 | import org.junit.runner.RunWith; |
| 55 | |
| 56 | import java.util.ArrayList; |
| 57 | import java.util.concurrent.TimeUnit; |
| 58 | |
| 59 | /** |
| 60 | * Tests for Size Compatibility mode. |
| 61 | * |
| 62 | * Build/Install/Run: |
| 63 | * atest WmTests:SizeCompatTests |
| 64 | */ |
| 65 | @MediumTest |
| 66 | @Presubmit |
| 67 | @RunWith(WindowTestRunner.class) |
| 68 | public class SizeCompatTests extends ActivityTestsBase { |
| 69 | private ActivityStack mStack; |
| 70 | private Task mTask; |
| 71 | private ActivityRecord mActivity; |
| 72 | |
| 73 | private void setUpApp(ActivityDisplay display) { |
| 74 | mStack = new StackBuilder(mRootActivityContainer).setDisplay(display).build(); |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame^] | 75 | mTask = mStack.getBottomMostTask(); |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 76 | mActivity = mTask.getTopNonFinishingActivity(); |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | private void ensureActivityConfiguration() { |
| 80 | mActivity.ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */); |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testRestartProcessIfVisible() { |
| 85 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).build()); |
| 86 | doNothing().when(mSupervisor).scheduleRestartTimeout(mActivity); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 87 | mActivity.mVisibleRequested = true; |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 88 | mActivity.setSavedState(null /* savedState */); |
| 89 | mActivity.setState(ActivityStack.ActivityState.RESUMED, "testRestart"); |
| 90 | prepareUnresizable(1.5f /* maxAspect */, SCREEN_ORIENTATION_UNSPECIFIED); |
| 91 | |
| 92 | final Rect originalOverrideBounds = new Rect(mActivity.getBounds()); |
| 93 | resizeDisplay(mStack.getDisplay(), 600, 1200); |
| 94 | // The visible activity should recompute configuration according to the last parent bounds. |
| 95 | mService.restartActivityProcessIfVisible(mActivity.appToken); |
| 96 | |
| 97 | assertEquals(ActivityStack.ActivityState.RESTARTING_PROCESS, mActivity.getState()); |
| 98 | assertNotEquals(originalOverrideBounds, mActivity.getBounds()); |
| 99 | } |
| 100 | |
| 101 | @Test |
| 102 | public void testKeepBoundsWhenChangingFromFreeformToFullscreen() { |
| 103 | removeGlobalMinSizeRestriction(); |
| 104 | // create freeform display and a freeform app |
| 105 | ActivityDisplay display = new TestActivityDisplay.Builder(mService, 2000, 1000) |
| 106 | .setCanRotate(false) |
| 107 | .setWindowingMode(WindowConfiguration.WINDOWING_MODE_FREEFORM).build(); |
| 108 | setUpApp(display); |
| 109 | |
| 110 | // Put app window into freeform and then make it a compat app. |
| 111 | mTask.setBounds(100, 100, 400, 600); |
| 112 | prepareUnresizable(-1.f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT); |
| 113 | |
| 114 | final Rect bounds = new Rect(mActivity.getBounds()); |
| 115 | final int density = mActivity.getConfiguration().densityDpi; |
| 116 | |
| 117 | // change display configuration to fullscreen |
| 118 | Configuration c = new Configuration(display.getRequestedOverrideConfiguration()); |
| 119 | c.windowConfiguration.setWindowingMode(WindowConfiguration.WINDOWING_MODE_FULLSCREEN); |
| 120 | display.onRequestedOverrideConfigurationChanged(c); |
| 121 | |
| 122 | // check if dimensions stay the same |
| 123 | assertTrue(mActivity.inSizeCompatMode()); |
| 124 | assertEquals(bounds.width(), mActivity.getBounds().width()); |
| 125 | assertEquals(bounds.height(), mActivity.getBounds().height()); |
| 126 | assertEquals(density, mActivity.getConfiguration().densityDpi); |
| 127 | } |
| 128 | |
| 129 | @Test |
| 130 | public void testFixedAspectRatioBoundsWithDecor() { |
| 131 | final int decorHeight = 200; // e.g. The device has cutout. |
| 132 | setUpApp(new TestActivityDisplay.Builder(mService, 600, 800) |
| 133 | .setNotch(decorHeight).build()); |
| 134 | |
| 135 | mActivity.info.minAspectRatio = mActivity.info.maxAspectRatio = 1; |
| 136 | prepareUnresizable(-1f, SCREEN_ORIENTATION_UNSPECIFIED); |
| 137 | |
| 138 | // The parent configuration doesn't change since the first resolved configuration, so the |
| 139 | // activity shouldn't be in the size compatibility mode. |
| 140 | assertFalse(mActivity.inSizeCompatMode()); |
| 141 | |
| 142 | final Rect appBounds = mActivity.getWindowConfiguration().getAppBounds(); |
| 143 | // Ensure the app bounds keep the declared aspect ratio. |
| 144 | assertEquals(appBounds.width(), appBounds.height()); |
| 145 | // The decor height should be a part of the effective bounds. |
| 146 | assertEquals(mActivity.getBounds().height(), appBounds.height() + decorHeight); |
| 147 | |
| 148 | mTask.getConfiguration().windowConfiguration.setRotation(ROTATION_90); |
| 149 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 150 | // After changing orientation, the aspect ratio should be the same. |
| 151 | assertEquals(appBounds.width(), appBounds.height()); |
| 152 | // The decor height will be included in width. |
| 153 | assertEquals(mActivity.getBounds().width(), appBounds.width() + decorHeight); |
| 154 | } |
| 155 | |
| 156 | @Test |
| 157 | public void testFixedScreenConfigurationWhenMovingToDisplay() { |
| 158 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).build()); |
| 159 | |
| 160 | // Make a new less-tall display with lower density |
| 161 | final ActivityDisplay newDisplay = |
| 162 | new TestActivityDisplay.Builder(mService, 1000, 2000) |
| 163 | .setDensityDpi(200).build(); |
| 164 | |
| 165 | mActivity = new ActivityBuilder(mService) |
| 166 | .setTask(mTask) |
| 167 | .setResizeMode(RESIZE_MODE_UNRESIZEABLE) |
| 168 | .setMaxAspectRatio(1.5f) |
| 169 | .build(); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 170 | mActivity.mVisibleRequested = true; |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 171 | |
| 172 | final Rect originalBounds = new Rect(mActivity.getBounds()); |
| 173 | final int originalDpi = mActivity.getConfiguration().densityDpi; |
| 174 | |
| 175 | // Move the non-resizable activity to the new display. |
| 176 | mStack.reparent(newDisplay.mDisplayContent, true /* onTop */); |
| 177 | |
| 178 | assertEquals(originalBounds.width(), mActivity.getBounds().width()); |
| 179 | assertEquals(originalBounds.height(), mActivity.getBounds().height()); |
| 180 | assertEquals(originalDpi, mActivity.getConfiguration().densityDpi); |
| 181 | assertTrue(mActivity.inSizeCompatMode()); |
| 182 | } |
| 183 | |
| 184 | @Test |
| 185 | public void testFixedScreenBoundsWhenDisplaySizeChanged() { |
| 186 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).build()); |
| 187 | prepareUnresizable(-1f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT); |
| 188 | assertFalse(mActivity.inSizeCompatMode()); |
| 189 | |
| 190 | final Rect origBounds = new Rect(mActivity.getBounds()); |
| 191 | |
| 192 | // Change the size of current display. |
| 193 | resizeDisplay(mStack.getDisplay(), 1000, 2000); |
| 194 | ensureActivityConfiguration(); |
| 195 | |
| 196 | assertEquals(origBounds.width(), mActivity.getWindowConfiguration().getBounds().width()); |
| 197 | assertEquals(origBounds.height(), mActivity.getWindowConfiguration().getBounds().height()); |
| 198 | assertTrue(mActivity.inSizeCompatMode()); |
| 199 | |
| 200 | // Change display size to a different orientation |
| 201 | resizeDisplay(mStack.getDisplay(), 2000, 1000); |
| 202 | ensureActivityConfiguration(); |
| 203 | assertEquals(origBounds.width(), mActivity.getWindowConfiguration().getBounds().width()); |
| 204 | assertEquals(origBounds.height(), mActivity.getWindowConfiguration().getBounds().height()); |
| 205 | } |
| 206 | |
| 207 | @Test |
| 208 | public void testLetterboxFullscreenBounds() { |
| 209 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).build()); |
| 210 | |
| 211 | // Fill out required fields on default display since WM-side is mocked out |
| 212 | prepareUnresizable(-1.f /* maxAspect */, SCREEN_ORIENTATION_LANDSCAPE); |
| 213 | assertFalse(mActivity.inSizeCompatMode()); |
| 214 | assertTrue(mActivity.getBounds().width() > mActivity.getBounds().height()); |
| 215 | } |
| 216 | |
| 217 | @Test |
| 218 | public void testMoveToDifferentOrientDisplay() { |
| 219 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).build()); |
| 220 | |
| 221 | final ActivityDisplay newDisplay = |
| 222 | new TestActivityDisplay.Builder(mService, 2000, 1000) |
| 223 | .setCanRotate(false).build(); |
| 224 | |
| 225 | prepareUnresizable(-1.f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT); |
| 226 | assertFalse(mActivity.inSizeCompatMode()); |
| 227 | |
| 228 | final Rect origBounds = new Rect(mActivity.getBounds()); |
| 229 | |
| 230 | // Move the non-resizable activity to the new display. |
| 231 | mStack.reparent(newDisplay.mDisplayContent, true /* onTop */); |
| 232 | ensureActivityConfiguration(); |
| 233 | assertEquals(origBounds.width(), mActivity.getWindowConfiguration().getBounds().width()); |
| 234 | assertEquals(origBounds.height(), mActivity.getWindowConfiguration().getBounds().height()); |
| 235 | assertTrue(mActivity.inSizeCompatMode()); |
| 236 | } |
| 237 | |
| 238 | @Test |
| 239 | public void testFixedOrientRotateCutoutDisplay() { |
| 240 | // Create a display with a notch/cutout |
| 241 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).setNotch(60).build()); |
| 242 | prepareUnresizable(1.4f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT); |
| 243 | |
| 244 | final Rect origBounds = new Rect(mActivity.getBounds()); |
| 245 | final Rect origAppBounds = new Rect(mActivity.getWindowConfiguration().getAppBounds()); |
| 246 | |
| 247 | // Rotate the display |
| 248 | Configuration c = new Configuration(); |
| 249 | mStack.getDisplay().mDisplayContent.getDisplayRotation().setRotation(ROTATION_270); |
| 250 | mStack.getDisplay().mDisplayContent.computeScreenConfiguration(c); |
| 251 | mStack.getDisplay().onRequestedOverrideConfigurationChanged(c); |
| 252 | |
| 253 | // Make sure the app size is the same |
| 254 | assertEquals(ROTATION_270, mStack.getWindowConfiguration().getRotation()); |
| 255 | assertEquals(origBounds.width(), mActivity.getWindowConfiguration().getBounds().width()); |
| 256 | assertEquals(origBounds.height(), mActivity.getWindowConfiguration().getBounds().height()); |
| 257 | assertEquals(origAppBounds.width(), |
| 258 | mActivity.getWindowConfiguration().getAppBounds().width()); |
| 259 | assertEquals(origAppBounds.height(), |
| 260 | mActivity.getWindowConfiguration().getAppBounds().height()); |
| 261 | } |
| 262 | |
| 263 | @Test |
| 264 | public void testFixedAspOrientChangeOrient() { |
| 265 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).build()); |
| 266 | |
| 267 | prepareUnresizable(1.4f /* maxAspect */, SCREEN_ORIENTATION_LANDSCAPE); |
Riddle Hsu | 359c84d | 2019-12-10 17:49:52 +0800 | [diff] [blame] | 268 | // The display aspect ratio 2.5 > 1.4 (max of activity), so the size is fitted. |
| 269 | assertFalse(mActivity.inSizeCompatMode()); |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 270 | |
| 271 | final Rect originalBounds = new Rect(mActivity.getBounds()); |
| 272 | final Rect originalAppBounds = new Rect(mActivity.getWindowConfiguration().getAppBounds()); |
| 273 | |
| 274 | // Change the fixed orientation |
| 275 | mActivity.mOrientation = SCREEN_ORIENTATION_PORTRAIT; |
| 276 | mActivity.info.screenOrientation = SCREEN_ORIENTATION_PORTRAIT; |
| 277 | // TaskRecord's configuration actually depends on the activity config right now for |
| 278 | // pillarboxing. |
| 279 | mActivity.getTask().onRequestedOverrideConfigurationChanged( |
| 280 | mActivity.getTask().getRequestedOverrideConfiguration()); |
| 281 | |
| 282 | assertEquals(originalBounds.width(), mActivity.getBounds().height()); |
| 283 | assertEquals(originalBounds.height(), mActivity.getBounds().width()); |
| 284 | assertEquals(originalAppBounds.width(), |
| 285 | mActivity.getWindowConfiguration().getAppBounds().height()); |
| 286 | assertEquals(originalAppBounds.height(), |
| 287 | mActivity.getWindowConfiguration().getAppBounds().width()); |
| 288 | } |
| 289 | |
| 290 | @Test |
| 291 | public void testFixedScreenLayoutSizeBits() { |
| 292 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).build()); |
| 293 | final int fixedScreenLayout = Configuration.SCREENLAYOUT_LONG_NO |
Riddle Hsu | ca92856 | 2019-11-22 01:04:14 +0800 | [diff] [blame] | 294 | | Configuration.SCREENLAYOUT_SIZE_NORMAL |
| 295 | | Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 296 | final int layoutMask = Configuration.SCREENLAYOUT_LONG_MASK |
| 297 | | Configuration.SCREENLAYOUT_SIZE_MASK |
Riddle Hsu | ca92856 | 2019-11-22 01:04:14 +0800 | [diff] [blame] | 298 | | Configuration.SCREENLAYOUT_LAYOUTDIR_MASK |
| 299 | | Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 300 | Configuration c = new Configuration(mTask.getRequestedOverrideConfiguration()); |
| 301 | c.screenLayout = fixedScreenLayout | Configuration.SCREENLAYOUT_LAYOUTDIR_LTR; |
| 302 | mTask.onRequestedOverrideConfigurationChanged(c); |
| 303 | prepareUnresizable(1.5f, SCREEN_ORIENTATION_UNSPECIFIED); |
| 304 | |
| 305 | // The initial configuration should inherit from parent. |
| 306 | assertEquals(fixedScreenLayout | Configuration.SCREENLAYOUT_LAYOUTDIR_LTR, |
| 307 | mActivity.getConfiguration().screenLayout & layoutMask); |
| 308 | |
| 309 | mTask.getConfiguration().screenLayout = Configuration.SCREENLAYOUT_LAYOUTDIR_RTL |
| 310 | | Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 311 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 312 | |
| 313 | // The size and aspect ratio bits don't change, but the layout direction should be updated. |
| 314 | assertEquals(fixedScreenLayout | Configuration.SCREENLAYOUT_LAYOUTDIR_RTL, |
| 315 | mActivity.getConfiguration().screenLayout & layoutMask); |
| 316 | } |
| 317 | |
| 318 | @Test |
| 319 | public void testResetNonVisibleActivity() { |
| 320 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2500).build()); |
| 321 | final ActivityDisplay display = mStack.getDisplay(); |
| 322 | spyOn(display); |
| 323 | |
| 324 | prepareUnresizable(1.5f, SCREEN_ORIENTATION_UNSPECIFIED); |
| 325 | mActivity.setState(STOPPED, "testSizeCompatMode"); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 326 | mActivity.mVisibleRequested = false; |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 327 | mActivity.app.setReportedProcState(ActivityManager.PROCESS_STATE_CACHED_ACTIVITY); |
| 328 | // Make the parent bounds to be different so the activity is in size compatibility mode. |
| 329 | mTask.getWindowConfiguration().setAppBounds(new Rect(0, 0, 600, 1200)); |
| 330 | |
| 331 | // Simulate the display changes orientation. |
| 332 | when(display.getLastOverrideConfigurationChanges()).thenReturn( |
| 333 | ActivityInfo.CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION |
| 334 | | ActivityInfo.CONFIG_WINDOW_CONFIGURATION); |
| 335 | mActivity.onConfigurationChanged(mTask.getConfiguration()); |
| 336 | when(display.getLastOverrideConfigurationChanges()).thenCallRealMethod(); |
| 337 | // The override configuration should not change so it is still in size compatibility mode. |
| 338 | assertTrue(mActivity.inSizeCompatMode()); |
| 339 | |
| 340 | // Change display density |
| 341 | final DisplayContent displayContent = mStack.getDisplay().mDisplayContent; |
| 342 | displayContent.mBaseDisplayDensity = (int) (0.7f * displayContent.mBaseDisplayDensity); |
| 343 | final Configuration c = new Configuration(); |
| 344 | displayContent.computeScreenConfiguration(c); |
| 345 | mService.mAmInternal = mock(ActivityManagerInternal.class); |
| 346 | mStack.getDisplay().onRequestedOverrideConfigurationChanged(c); |
| 347 | |
| 348 | // The override configuration should be reset and the activity's process will be killed. |
| 349 | assertFalse(mActivity.inSizeCompatMode()); |
| 350 | verify(mActivity).restartProcessIfVisible(); |
| 351 | mLockRule.runWithScissors(mService.mH, () -> { }, TimeUnit.SECONDS.toMillis(3)); |
| 352 | verify(mService.mAmInternal).killProcess( |
| 353 | eq(mActivity.app.mName), eq(mActivity.app.mUid), anyString()); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Ensures that {@link TaskStackListener} can receive callback about the activity in size |
| 358 | * compatibility mode. |
| 359 | */ |
| 360 | @Test |
| 361 | public void testHandleActivitySizeCompatMode() { |
| 362 | setUpApp(new TestActivityDisplay.Builder(mService, 1000, 2000).build()); |
| 363 | ActivityRecord activity = mActivity; |
| 364 | activity.setState(ActivityStack.ActivityState.RESUMED, "testHandleActivitySizeCompatMode"); |
| 365 | prepareUnresizable(-1.f /* maxAspect */, SCREEN_ORIENTATION_PORTRAIT); |
| 366 | ensureActivityConfiguration(); |
| 367 | assertFalse(mActivity.inSizeCompatMode()); |
| 368 | |
| 369 | final ArrayList<IBinder> compatTokens = new ArrayList<>(); |
| 370 | mService.getTaskChangeNotificationController().registerTaskStackListener( |
| 371 | new TaskStackListener() { |
| 372 | @Override |
| 373 | public void onSizeCompatModeActivityChanged(int displayId, |
| 374 | IBinder activityToken) { |
| 375 | compatTokens.add(activityToken); |
| 376 | } |
| 377 | }); |
| 378 | |
| 379 | // Resize the display so that the activity exercises size-compat mode. |
| 380 | resizeDisplay(mStack.getDisplay(), 1000, 2500); |
| 381 | |
| 382 | // Expect the exact token when the activity is in size compatibility mode. |
| 383 | assertEquals(1, compatTokens.size()); |
| 384 | assertEquals(activity.appToken, compatTokens.get(0)); |
| 385 | |
| 386 | compatTokens.clear(); |
| 387 | // Make the activity resizable again by restarting it |
| 388 | activity.info.resizeMode = ActivityInfo.RESIZE_MODE_RESIZEABLE; |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 389 | activity.mVisibleRequested = true; |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 390 | activity.restartProcessIfVisible(); |
| 391 | // The full lifecycle isn't hooked up so manually set state to resumed |
| 392 | activity.setState(ActivityStack.ActivityState.RESUMED, "testHandleActivitySizeCompatMode"); |
| 393 | mStack.getDisplay().handleActivitySizeCompatModeIfNeeded(activity); |
| 394 | |
| 395 | // Expect null token when switching to non-size-compat mode activity. |
| 396 | assertEquals(1, compatTokens.size()); |
| 397 | assertEquals(null, compatTokens.get(0)); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Setup {@link #mActivity} as a size-compat-mode-able activity with fixed aspect and/or |
| 402 | * orientation. |
| 403 | */ |
| 404 | private void prepareUnresizable(float maxAspect, int screenOrientation) { |
| 405 | mActivity.info.resizeMode = RESIZE_MODE_UNRESIZEABLE; |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 406 | mActivity.mVisibleRequested = true; |
Evan Rosky | 0177507 | 2019-09-11 17:28:07 -0700 | [diff] [blame] | 407 | if (maxAspect >= 0) { |
| 408 | mActivity.info.maxAspectRatio = maxAspect; |
| 409 | } |
| 410 | if (screenOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
| 411 | mActivity.mOrientation = screenOrientation; |
| 412 | mActivity.info.screenOrientation = screenOrientation; |
| 413 | // TaskRecord's configuration actually depends on the activity config right now for |
| 414 | // pillarboxing. |
| 415 | mActivity.getTask().onRequestedOverrideConfigurationChanged( |
| 416 | mActivity.getTask().getRequestedOverrideConfiguration()); |
| 417 | } |
| 418 | ensureActivityConfiguration(); |
| 419 | } |
| 420 | |
| 421 | private void resizeDisplay(ActivityDisplay display, int width, int height) { |
| 422 | final DisplayContent displayContent = display.mDisplayContent; |
| 423 | displayContent.mBaseDisplayWidth = width; |
| 424 | displayContent.mBaseDisplayHeight = height; |
| 425 | Configuration c = new Configuration(); |
| 426 | displayContent.computeScreenConfiguration(c); |
| 427 | display.onRequestedOverrideConfigurationChanged(c); |
| 428 | } |
| 429 | } |