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