Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 1 | /* |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 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 |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 14 | * limitations under the License |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 18 | |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 23 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
| 24 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Garfield Tan | bb0270f | 2018-12-05 11:30:27 -0800 | [diff] [blame] | 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; |
| 26 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 27 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; |
Garfield Tan | bb0270f | 2018-12-05 11:30:27 -0800 | [diff] [blame] | 28 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 29 | import static android.util.DisplayMetrics.DENSITY_DEFAULT; |
| 30 | import static android.view.Display.DEFAULT_DISPLAY; |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 31 | |
Tadashi G. Takaoka | a7a6695 | 2018-11-16 15:04:21 +0900 | [diff] [blame] | 32 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 33 | import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_CONTINUE; |
| 34 | import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.RESULT_SKIP; |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 35 | |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 36 | import static org.junit.Assert.assertEquals; |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 37 | import static org.junit.Assert.assertTrue; |
| 38 | import static org.mockito.ArgumentMatchers.any; |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 39 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 40 | import android.app.ActivityOptions; |
| 41 | import android.content.pm.ActivityInfo; |
| 42 | import android.content.pm.ApplicationInfo; |
| 43 | import android.content.res.Configuration; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 44 | import android.graphics.Rect; |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 45 | import android.os.Build; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 46 | import android.platform.test.annotations.Presubmit; |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 47 | import android.view.Display; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 48 | import android.view.Gravity; |
| 49 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 50 | import androidx.test.filters.SmallTest; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 51 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 52 | import com.android.server.wm.LaunchParamsController.LaunchParams; |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 53 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 54 | import org.junit.Before; |
| 55 | import org.junit.Test; |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 56 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 57 | import java.util.Locale; |
| 58 | |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 59 | /** |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 60 | * Tests for default task bounds. |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 61 | * |
| 62 | * Build/Install/Run: |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 63 | * atest WmTests:TaskLaunchParamsModifierTests |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 64 | */ |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 65 | @SmallTest |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 66 | @Presubmit |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 67 | public class TaskLaunchParamsModifierTests extends ActivityTestsBase { |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 68 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 69 | private ActivityRecord mActivity; |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 70 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 71 | private TaskLaunchParamsModifier mTarget; |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 72 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 73 | private LaunchParams mCurrent; |
| 74 | private LaunchParams mResult; |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 75 | |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 76 | @Before |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 77 | public void setUp() throws Exception { |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 78 | 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 Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 81 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 82 | mTarget = new TaskLaunchParamsModifier(mSupervisor); |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 83 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 84 | mCurrent = new LaunchParams(); |
| 85 | mCurrent.reset(); |
| 86 | mResult = new LaunchParams(); |
| 87 | mResult.reset(); |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Garfield Tan | 21d7e17 | 2018-10-16 18:07:27 -0700 | [diff] [blame] | 90 | @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 Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 97 | // ============================= |
| 98 | // Display ID Related Tests |
| 99 | // ============================= |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 100 | @Test |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 101 | 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 Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 110 | @Test |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 111 | 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 Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 121 | 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 Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 133 | @Test |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 134 | 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 Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 150 | @Test |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 151 | public void testUsesOptionsDisplayIdIfSet() { |
| 152 | final TestActivityDisplay freeformDisplay = createNewActivityDisplay( |
| 153 | WINDOWING_MODE_FREEFORM); |
| 154 | final TestActivityDisplay fullscreenDisplay = createNewActivityDisplay( |
| 155 | WINDOWING_MODE_FULLSCREEN); |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 156 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 157 | mCurrent.mPreferredDisplayId = freeformDisplay.mDisplayId; |
| 158 | ActivityRecord source = createSourceActivity(freeformDisplay); |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 159 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 160 | ActivityOptions options = ActivityOptions.makeBasic(); |
| 161 | options.setLaunchDisplayId(fullscreenDisplay.mDisplayId); |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 162 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 163 | assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null, |
| 164 | mActivity, source, options, mCurrent, mResult)); |
| 165 | |
| 166 | assertEquals(fullscreenDisplay.mDisplayId, mResult.mPreferredDisplayId); |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Louis Chang | 4075009 | 2018-10-24 21:04:51 +0800 | [diff] [blame] | 169 | @Test |
Louis Chang | 6fb1e84 | 2018-12-03 16:07:50 +0800 | [diff] [blame] | 170 | 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 Chang | 4075009 | 2018-10-24 21:04:51 +0800 | [diff] [blame] | 187 | public void testUsesTaskDisplayIdIfSet() { |
| 188 | final TestActivityDisplay freeformDisplay = createNewActivityDisplay( |
| 189 | WINDOWING_MODE_FREEFORM); |
| 190 | ActivityRecord source = createSourceActivity(freeformDisplay); |
| 191 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 192 | assertEquals(RESULT_CONTINUE, mTarget.onCalculate(source.getTaskRecord(), null /* layout */, |
Louis Chang | 4075009 | 2018-10-24 21:04:51 +0800 | [diff] [blame] | 193 | null /* activity */, null /* source */, null /* options */, mCurrent, mResult)); |
| 194 | |
| 195 | assertEquals(freeformDisplay.mDisplayId, mResult.mPreferredDisplayId); |
| 196 | } |
| 197 | |
Louis Chang | d58cb67 | 2018-12-24 17:45:16 +0800 | [diff] [blame] | 198 | @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 Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 217 | // ===================================== |
| 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 Tan | 706dbcb | 2018-10-15 11:33:02 -0700 | [diff] [blame] | 247 | assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode, |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 248 | 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 Tan | 706dbcb | 2018-10-15 11:33:02 -0700 | [diff] [blame] | 335 | public void testNonEmptyLayoutUsesFullscreenWithResizeableActivity() { |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 336 | 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 Tan | 706dbcb | 2018-10-15 11:33:02 -0700 | [diff] [blame] | 344 | assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode, |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 345 | 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 Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 771 | 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 Tan | d5972d1 | 2019-01-03 10:31:59 -0800 | [diff] [blame] | 786 | 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 Tan | bb0270f | 2018-12-05 11:30:27 -0800 | [diff] [blame] | 801 | 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 Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 859 | 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 Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 976 | public void testAdjustBoundsToFitNewDisplay_LargerThanDisplay() { |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 977 | final TestActivityDisplay freeformDisplay = createNewActivityDisplay( |
| 978 | WINDOWING_MODE_FREEFORM); |
| 979 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 980 | final ActivityOptions options = ActivityOptions.makeBasic(); |
| 981 | options.setLaunchDisplayId(freeformDisplay.mDisplayId); |
| 982 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 983 | mCurrent.mWindowingMode = WINDOWING_MODE_FREEFORM; |
| 984 | mCurrent.mBounds.set(100, 200, 2120, 1380); |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 985 | |
| 986 | mActivity.appInfo.targetSdkVersion = Build.VERSION_CODES.LOLLIPOP; |
| 987 | |
| 988 | assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null, |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 989 | mActivity, /* source */ null, options, mCurrent, mResult)); |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 990 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 991 | 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 Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 997 | final Configuration overrideConfig = |
| 998 | mRootActivityContainer.getRequestedOverrideConfiguration(); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 999 | // Egyptian Arabic is a RTL language. |
| 1000 | overrideConfig.setLayoutDirection(new Locale("ar", "EG")); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1001 | mRootActivityContainer.onRequestedOverrideConfigurationChanged(overrideConfig); |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1002 | |
| 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 Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 1019 | } |
| 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. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 1157 | assertEquals(new Rect(0, 0, 1680, 953), mResult.mBounds); |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 1160 | @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 Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 1195 | 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 Tan | bb0270f | 2018-12-05 11:30:27 -0800 | [diff] [blame] | 1200 | display.getConfiguration().orientation = ORIENTATION_LANDSCAPE; |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 1201 | 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 Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 1223 | } |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Garfield Tan | bb0270f | 2018-12-05 11:30:27 -0800 | [diff] [blame] | 1226 | private int orientationFromBounds(Rect bounds) { |
| 1227 | return bounds.width() > bounds.height() ? SCREEN_ORIENTATION_LANDSCAPE |
| 1228 | : SCREEN_ORIENTATION_PORTRAIT; |
| 1229 | } |
| 1230 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 1231 | 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 Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 1239 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 1240 | private WindowLayoutBuilder setWidth(int width) { |
| 1241 | mWidth = width; |
| 1242 | return this; |
Bryce Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 1245 | 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 Lee | 81e30a2 | 2017-10-06 13:34:12 -0700 | [diff] [blame] | 1279 | } |
| 1280 | } |