| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package androidx.window.extensions.embedding; |
| 18 |
|
| 19 |
import static android.content.pm.PackageManager.MATCH_ALL; |
| 20 |
|
| 21 |
import android.app.Activity; |
| 22 |
import android.app.ActivityThread; |
| 23 |
import android.app.WindowConfiguration; |
| 24 |
import android.app.WindowConfiguration.WindowingMode; |
| 25 |
import android.content.Intent; |
| 26 |
import android.content.pm.ActivityInfo; |
| 27 |
import android.content.pm.PackageManager; |
| 28 |
import android.content.pm.ResolveInfo; |
| 29 |
import android.content.res.Configuration; |
| 30 |
import android.graphics.Rect; |
| 31 |
import android.os.Bundle; |
| 32 |
import android.os.IBinder; |
| 33 |
import android.util.LayoutDirection; |
| 34 |
import android.util.Pair; |
| 35 |
import android.util.Size; |
| 36 |
import android.view.View; |
| 37 |
import android.view.WindowInsets; |
| 38 |
import android.view.WindowMetrics; |
| 39 |
import android.window.TaskFragmentAnimationParams; |
| 40 |
import android.window.TaskFragmentCreationParams; |
| 41 |
import android.window.WindowContainerTransaction; |
| 42 |
|
| 43 |
import androidx.annotation.IntDef; |
| 44 |
import androidx.annotation.NonNull; |
| 45 |
import androidx.annotation.Nullable; |
| 46 |
import androidx.window.extensions.embedding.SplitAttributes.SplitType; |
| 47 |
import androidx.window.extensions.embedding.SplitAttributes.SplitType.ExpandContainersSplitType; |
| 48 |
import androidx.window.extensions.embedding.SplitAttributes.SplitType.HingeSplitType; |
| 49 |
import androidx.window.extensions.embedding.SplitAttributes.SplitType.RatioSplitType; |
| 50 |
import androidx.window.extensions.embedding.SplitAttributesCalculator.SplitAttributesCalculatorParams; |
| 51 |
import androidx.window.extensions.embedding.TaskContainer.TaskProperties; |
| 52 |
import androidx.window.extensions.layout.DisplayFeature; |
| 53 |
import androidx.window.extensions.layout.FoldingFeature; |
| 54 |
import androidx.window.extensions.layout.WindowLayoutComponentImpl; |
| 55 |
import androidx.window.extensions.layout.WindowLayoutInfo; |
| 56 |
|
| 57 |
import com.android.internal.annotations.VisibleForTesting; |
| 58 |
|
| 59 |
import java.util.ArrayList; |
| 60 |
import java.util.List; |
| 61 |
import java.util.Objects; |
| 62 |
import java.util.concurrent.Executor; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
@SuppressWarnings("GuardedBy") |
| 71 |
class SplitPresenter extends JetpackTaskFragmentOrganizer { |
| 72 |
@VisibleForTesting |
| 73 |
static final int POSITION_START = 0; |
| 74 |
@VisibleForTesting |
| 75 |
static final int POSITION_END = 1; |
| 76 |
@VisibleForTesting |
| 77 |
static final int POSITION_FILL = 2; |
| 78 |
|
| 79 |
@IntDef(value = { |
| 80 |
POSITION_START, |
| 81 |
POSITION_END, |
| 82 |
POSITION_FILL, |
| 83 |
}) |
| 84 |
private @interface Position {} |
| 85 |
|
| 86 |
private static final int CONTAINER_POSITION_LEFT = 0; |
| 87 |
private static final int CONTAINER_POSITION_TOP = 1; |
| 88 |
private static final int CONTAINER_POSITION_RIGHT = 2; |
| 89 |
private static final int CONTAINER_POSITION_BOTTOM = 3; |
| 90 |
|
| 91 |
@IntDef(value = { |
| 92 |
CONTAINER_POSITION_LEFT, |
| 93 |
CONTAINER_POSITION_TOP, |
| 94 |
CONTAINER_POSITION_RIGHT, |
| 95 |
CONTAINER_POSITION_BOTTOM, |
| 96 |
}) |
| 97 |
private @interface ContainerPosition {} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
static final int RESULT_NOT_EXPANDED = 0; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
static final int RESULT_EXPANDED = 1; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
static final int RESULT_EXPAND_FAILED_NO_TF_INFO = 2; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
@IntDef(value = { |
| 129 |
RESULT_NOT_EXPANDED, |
| 130 |
RESULT_EXPANDED, |
| 131 |
RESULT_EXPAND_FAILED_NO_TF_INFO, |
| 132 |
}) |
| 133 |
private @interface ResultCode {} |
| 134 |
|
| 135 |
@VisibleForTesting |
| 136 |
static final SplitAttributes EXPAND_CONTAINERS_ATTRIBUTES = |
| 137 |
new SplitAttributes.Builder() |
| 138 |
.setSplitType(new ExpandContainersSplitType()) |
| 139 |
.build(); |
| 140 |
|
| 141 |
private final WindowLayoutComponentImpl mWindowLayoutComponent; |
| 142 |
private final SplitController mController; |
| 143 |
|
| 144 |
SplitPresenter(@NonNull Executor executor, |
| 145 |
@NonNull WindowLayoutComponentImpl windowLayoutComponent, |
| 146 |
@NonNull SplitController controller) { |
| 147 |
super(executor, controller); |
| 148 |
mWindowLayoutComponent = windowLayoutComponent; |
| 149 |
mController = controller; |
| 150 |
registerOrganizer(); |
| 151 |
if (!SplitController.ENABLE_SHELL_TRANSITIONS) { |
| 152 |
|
| 153 |
|
| 154 |
overrideSplitAnimation(); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
void cleanupContainer(@NonNull WindowContainerTransaction wct, |
| 163 |
@NonNull TaskFragmentContainer container, boolean shouldFinishDependent) { |
| 164 |
container.finish(shouldFinishDependent, this, wct, mController); |
| 165 |
|
| 166 |
mController.updateContainersInTaskIfVisible(wct, container.getTaskId()); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
@NonNull |
| 174 |
TaskFragmentContainer createNewSplitWithEmptySideContainer( |
| 175 |
@NonNull WindowContainerTransaction wct, @NonNull Activity primaryActivity, |
| 176 |
@NonNull Intent secondaryIntent, @NonNull SplitPairRule rule) { |
| 177 |
final TaskProperties taskProperties = getTaskProperties(primaryActivity); |
| 178 |
final Pair<Size, Size> minDimensionsPair = getActivityIntentMinDimensionsPair( |
| 179 |
primaryActivity, secondaryIntent); |
| 180 |
final SplitAttributes splitAttributes = computeSplitAttributes(taskProperties, rule, |
| 181 |
minDimensionsPair); |
| 182 |
final Rect primaryRectBounds = getBoundsForPosition(POSITION_START, taskProperties, |
| 183 |
splitAttributes); |
| 184 |
final TaskFragmentContainer primaryContainer = prepareContainerForActivity(wct, |
| 185 |
primaryActivity, primaryRectBounds, splitAttributes, null ); |
| 186 |
|
| 187 |
|
| 188 |
final int taskId = primaryContainer.getTaskId(); |
| 189 |
final TaskFragmentContainer secondaryContainer = mController.newContainer( |
| 190 |
secondaryIntent, primaryActivity, taskId); |
| 191 |
final Rect secondaryRectBounds = getBoundsForPosition(POSITION_END, taskProperties, |
| 192 |
splitAttributes); |
| 193 |
final int windowingMode = mController.getTaskContainer(taskId) |
| 194 |
.getWindowingModeForSplitTaskFragment(secondaryRectBounds); |
| 195 |
createTaskFragment(wct, secondaryContainer.getTaskFragmentToken(), |
| 196 |
primaryActivity.getActivityToken(), secondaryRectBounds, |
| 197 |
windowingMode); |
| 198 |
updateAnimationParams(wct, secondaryContainer.getTaskFragmentToken(), splitAttributes); |
| 199 |
|
| 200 |
|
| 201 |
setAdjacentTaskFragments(wct, primaryContainer, secondaryContainer, rule, |
| 202 |
splitAttributes); |
| 203 |
|
| 204 |
mController.registerSplit(wct, primaryContainer, primaryActivity, secondaryContainer, rule, |
| 205 |
splitAttributes); |
| 206 |
|
| 207 |
return secondaryContainer; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
void createNewSplitContainer(@NonNull WindowContainerTransaction wct, |
| 222 |
@NonNull Activity primaryActivity, @NonNull Activity secondaryActivity, |
| 223 |
@NonNull SplitPairRule rule) { |
| 224 |
final TaskProperties taskProperties = getTaskProperties(primaryActivity); |
| 225 |
final Pair<Size, Size> minDimensionsPair = getActivitiesMinDimensionsPair(primaryActivity, |
| 226 |
secondaryActivity); |
| 227 |
final SplitAttributes splitAttributes = computeSplitAttributes(taskProperties, rule, |
| 228 |
minDimensionsPair); |
| 229 |
final Rect primaryRectBounds = getBoundsForPosition(POSITION_START, taskProperties, |
| 230 |
splitAttributes); |
| 231 |
final TaskFragmentContainer primaryContainer = prepareContainerForActivity(wct, |
| 232 |
primaryActivity, primaryRectBounds, splitAttributes, null ); |
| 233 |
|
| 234 |
final Rect secondaryRectBounds = getBoundsForPosition(POSITION_END, taskProperties, |
| 235 |
splitAttributes); |
| 236 |
final TaskFragmentContainer curSecondaryContainer = mController.getContainerWithActivity( |
| 237 |
secondaryActivity); |
| 238 |
TaskFragmentContainer containerToAvoid = primaryContainer; |
| 239 |
if (curSecondaryContainer != null && curSecondaryContainer != primaryContainer |
| 240 |
&& (rule.shouldClearTop() || primaryContainer.isAbove(curSecondaryContainer))) { |
| 241 |
|
| 242 |
|
| 243 |
containerToAvoid = curSecondaryContainer; |
| 244 |
} |
| 245 |
final TaskFragmentContainer secondaryContainer = prepareContainerForActivity(wct, |
| 246 |
secondaryActivity, secondaryRectBounds, splitAttributes, containerToAvoid); |
| 247 |
|
| 248 |
|
| 249 |
setAdjacentTaskFragments(wct, primaryContainer, secondaryContainer, rule, |
| 250 |
splitAttributes); |
| 251 |
|
| 252 |
mController.registerSplit(wct, primaryContainer, primaryActivity, secondaryContainer, rule, |
| 253 |
splitAttributes); |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
private TaskFragmentContainer prepareContainerForActivity( |
| 262 |
@NonNull WindowContainerTransaction wct, @NonNull Activity activity, |
| 263 |
@NonNull Rect bounds, @NonNull SplitAttributes splitAttributes, |
| 264 |
@Nullable TaskFragmentContainer containerToAvoid) { |
| 265 |
TaskFragmentContainer container = mController.getContainerWithActivity(activity); |
| 266 |
final int taskId = container != null ? container.getTaskId() : activity.getTaskId(); |
| 267 |
if (container == null || container == containerToAvoid) { |
| 268 |
container = mController.newContainer(activity, taskId); |
| 269 |
final int windowingMode = mController.getTaskContainer(taskId) |
| 270 |
.getWindowingModeForSplitTaskFragment(bounds); |
| 271 |
createTaskFragment(wct, container.getTaskFragmentToken(), activity.getActivityToken(), |
| 272 |
bounds, windowingMode); |
| 273 |
wct.reparentActivityToTaskFragment(container.getTaskFragmentToken(), |
| 274 |
activity.getActivityToken()); |
| 275 |
} else { |
| 276 |
resizeTaskFragmentIfRegistered(wct, container, bounds); |
| 277 |
final int windowingMode = mController.getTaskContainer(taskId) |
| 278 |
.getWindowingModeForSplitTaskFragment(bounds); |
| 279 |
updateTaskFragmentWindowingModeIfRegistered(wct, container, windowingMode); |
| 280 |
} |
| 281 |
updateAnimationParams(wct, container.getTaskFragmentToken(), splitAttributes); |
| 282 |
|
| 283 |
return container; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
void startActivityToSide(@NonNull WindowContainerTransaction wct, |
| 298 |
@NonNull Activity launchingActivity, @NonNull Intent activityIntent, |
| 299 |
@Nullable Bundle activityOptions, @NonNull SplitRule rule, |
| 300 |
@NonNull SplitAttributes splitAttributes, boolean isPlaceholder) { |
| 301 |
final TaskProperties taskProperties = getTaskProperties(launchingActivity); |
| 302 |
final Rect primaryRectBounds = getBoundsForPosition(POSITION_START, taskProperties, |
| 303 |
splitAttributes); |
| 304 |
final Rect secondaryRectBounds = getBoundsForPosition(POSITION_END, taskProperties, |
| 305 |
splitAttributes); |
| 306 |
|
| 307 |
TaskFragmentContainer primaryContainer = mController.getContainerWithActivity( |
| 308 |
launchingActivity); |
| 309 |
if (primaryContainer == null) { |
| 310 |
primaryContainer = mController.newContainer(launchingActivity, |
| 311 |
launchingActivity.getTaskId()); |
| 312 |
} |
| 313 |
|
| 314 |
final int taskId = primaryContainer.getTaskId(); |
| 315 |
final TaskFragmentContainer secondaryContainer = mController.newContainer( |
| 316 |
null , activityIntent, launchingActivity, taskId, |
| 317 |
|
| 318 |
primaryContainer); |
| 319 |
final TaskContainer taskContainer = mController.getTaskContainer(taskId); |
| 320 |
final int windowingMode = taskContainer.getWindowingModeForSplitTaskFragment( |
| 321 |
primaryRectBounds); |
| 322 |
mController.registerSplit(wct, primaryContainer, launchingActivity, secondaryContainer, |
| 323 |
rule, splitAttributes); |
| 324 |
startActivityToSide(wct, primaryContainer.getTaskFragmentToken(), primaryRectBounds, |
| 325 |
launchingActivity, secondaryContainer.getTaskFragmentToken(), secondaryRectBounds, |
| 326 |
activityIntent, activityOptions, rule, windowingMode, splitAttributes); |
| 327 |
if (isPlaceholder) { |
| 328 |
|
| 329 |
wct.requestFocusOnTaskFragment(primaryContainer.getTaskFragmentToken()); |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
void updateSplitContainer(@NonNull SplitContainer splitContainer, |
| 340 |
@NonNull TaskFragmentContainer updatedContainer, |
| 341 |
@NonNull WindowContainerTransaction wct) { |
| 342 |
|
| 343 |
|
| 344 |
final SplitRule rule = splitContainer.getSplitRule(); |
| 345 |
final TaskFragmentContainer primaryContainer = splitContainer.getPrimaryContainer(); |
| 346 |
final Activity activity = primaryContainer.getTopNonFinishingActivity(); |
| 347 |
if (activity == null) { |
| 348 |
return; |
| 349 |
} |
| 350 |
final TaskProperties taskProperties = getTaskProperties(updatedContainer); |
| 351 |
final SplitAttributes splitAttributes = splitContainer.getSplitAttributes(); |
| 352 |
final Rect primaryRectBounds = getBoundsForPosition(POSITION_START, taskProperties, |
| 353 |
splitAttributes); |
| 354 |
final Rect secondaryRectBounds = getBoundsForPosition(POSITION_END, taskProperties, |
| 355 |
splitAttributes); |
| 356 |
final TaskFragmentContainer secondaryContainer = splitContainer.getSecondaryContainer(); |
| 357 |
|
| 358 |
final boolean isPlaceholderBecomingSplit = splitContainer.isPlaceholderContainer() |
| 359 |
&& secondaryContainer.areLastRequestedBoundsEqual(null ) |
| 360 |
&& !secondaryRectBounds.isEmpty(); |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
resizeTaskFragmentIfRegistered(wct, primaryContainer, primaryRectBounds); |
| 365 |
resizeTaskFragmentIfRegistered(wct, secondaryContainer, secondaryRectBounds); |
| 366 |
setAdjacentTaskFragments(wct, primaryContainer, secondaryContainer, rule, |
| 367 |
splitAttributes); |
| 368 |
if (isPlaceholderBecomingSplit) { |
| 369 |
|
| 370 |
wct.requestFocusOnTaskFragment(primaryContainer.getTaskFragmentToken()); |
| 371 |
} |
| 372 |
final TaskContainer taskContainer = updatedContainer.getTaskContainer(); |
| 373 |
final int windowingMode = taskContainer.getWindowingModeForSplitTaskFragment( |
| 374 |
primaryRectBounds); |
| 375 |
updateTaskFragmentWindowingModeIfRegistered(wct, primaryContainer, windowingMode); |
| 376 |
updateTaskFragmentWindowingModeIfRegistered(wct, secondaryContainer, windowingMode); |
| 377 |
updateAnimationParams(wct, primaryContainer.getTaskFragmentToken(), splitAttributes); |
| 378 |
updateAnimationParams(wct, secondaryContainer.getTaskFragmentToken(), splitAttributes); |
| 379 |
} |
| 380 |
|
| 381 |
private void setAdjacentTaskFragments(@NonNull WindowContainerTransaction wct, |
| 382 |
@NonNull TaskFragmentContainer primaryContainer, |
| 383 |
@NonNull TaskFragmentContainer secondaryContainer, @NonNull SplitRule splitRule, |
| 384 |
@NonNull SplitAttributes splitAttributes) { |
| 385 |
|
| 386 |
|
| 387 |
boolean isStacked = !shouldShowSplit(splitAttributes); |
| 388 |
if (isStacked) { |
| 389 |
setAdjacentTaskFragments(wct, primaryContainer.getTaskFragmentToken(), |
| 390 |
null , null ); |
| 391 |
} else { |
| 392 |
setAdjacentTaskFragments(wct, primaryContainer.getTaskFragmentToken(), |
| 393 |
secondaryContainer.getTaskFragmentToken(), splitRule); |
| 394 |
} |
| 395 |
setCompanionTaskFragment(wct, primaryContainer.getTaskFragmentToken(), |
| 396 |
secondaryContainer.getTaskFragmentToken(), splitRule, isStacked); |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
private void resizeTaskFragmentIfRegistered(@NonNull WindowContainerTransaction wct, |
| 405 |
@NonNull TaskFragmentContainer container, |
| 406 |
@Nullable Rect bounds) { |
| 407 |
if (container.getInfo() == null) { |
| 408 |
return; |
| 409 |
} |
| 410 |
resizeTaskFragment(wct, container.getTaskFragmentToken(), bounds); |
| 411 |
} |
| 412 |
|
| 413 |
private void updateTaskFragmentWindowingModeIfRegistered( |
| 414 |
@NonNull WindowContainerTransaction wct, |
| 415 |
@NonNull TaskFragmentContainer container, |
| 416 |
@WindowingMode int windowingMode) { |
| 417 |
if (container.getInfo() != null) { |
| 418 |
updateWindowingMode(wct, container.getTaskFragmentToken(), windowingMode); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
@Override |
| 423 |
void createTaskFragment(@NonNull WindowContainerTransaction wct, |
| 424 |
@NonNull TaskFragmentCreationParams fragmentOptions) { |
| 425 |
final TaskFragmentContainer container = mController.getContainer( |
| 426 |
fragmentOptions.getFragmentToken()); |
| 427 |
if (container == null) { |
| 428 |
throw new IllegalStateException( |
| 429 |
"Creating a task fragment that is not registered with controller."); |
| 430 |
} |
| 431 |
|
| 432 |
container.setLastRequestedBounds(fragmentOptions.getInitialBounds()); |
| 433 |
container.setLastRequestedWindowingMode(fragmentOptions.getWindowingMode()); |
| 434 |
super.createTaskFragment(wct, fragmentOptions); |
| 435 |
} |
| 436 |
|
| 437 |
@Override |
| 438 |
void resizeTaskFragment(@NonNull WindowContainerTransaction wct, @NonNull IBinder fragmentToken, |
| 439 |
@Nullable Rect bounds) { |
| 440 |
TaskFragmentContainer container = mController.getContainer(fragmentToken); |
| 441 |
if (container == null) { |
| 442 |
throw new IllegalStateException( |
| 443 |
"Resizing a task fragment that is not registered with controller."); |
| 444 |
} |
| 445 |
|
| 446 |
if (container.areLastRequestedBoundsEqual(bounds)) { |
| 447 |
|
| 448 |
return; |
| 449 |
} |
| 450 |
|
| 451 |
container.setLastRequestedBounds(bounds); |
| 452 |
super.resizeTaskFragment(wct, fragmentToken, bounds); |
| 453 |
} |
| 454 |
|
| 455 |
@Override |
| 456 |
void updateWindowingMode(@NonNull WindowContainerTransaction wct, |
| 457 |
@NonNull IBinder fragmentToken, @WindowingMode int windowingMode) { |
| 458 |
final TaskFragmentContainer container = mController.getContainer(fragmentToken); |
| 459 |
if (container == null) { |
| 460 |
throw new IllegalStateException("Setting windowing mode for a task fragment that is" |
| 461 |
+ " not registered with controller."); |
| 462 |
} |
| 463 |
|
| 464 |
if (container.isLastRequestedWindowingModeEqual(windowingMode)) { |
| 465 |
|
| 466 |
return; |
| 467 |
} |
| 468 |
|
| 469 |
container.setLastRequestedWindowingMode(windowingMode); |
| 470 |
super.updateWindowingMode(wct, fragmentToken, windowingMode); |
| 471 |
} |
| 472 |
|
| 473 |
@Override |
| 474 |
void updateAnimationParams(@NonNull WindowContainerTransaction wct, |
| 475 |
@NonNull IBinder fragmentToken, @NonNull TaskFragmentAnimationParams animationParams) { |
| 476 |
final TaskFragmentContainer container = mController.getContainer(fragmentToken); |
| 477 |
if (container == null) { |
| 478 |
throw new IllegalStateException("Setting animation params for a task fragment that is" |
| 479 |
+ " not registered with controller."); |
| 480 |
} |
| 481 |
|
| 482 |
if (container.areLastRequestedAnimationParamsEqual(animationParams)) { |
| 483 |
|
| 484 |
return; |
| 485 |
} |
| 486 |
|
| 487 |
container.setLastRequestAnimationParams(animationParams); |
| 488 |
super.updateAnimationParams(wct, fragmentToken, animationParams); |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
@ResultCode |
| 500 |
int expandSplitContainerIfNeeded(@NonNull WindowContainerTransaction wct, |
| 501 |
@NonNull SplitContainer splitContainer, @NonNull Activity primaryActivity, |
| 502 |
@Nullable Activity secondaryActivity, @Nullable Intent secondaryIntent) { |
| 503 |
if (secondaryActivity == null && secondaryIntent == null) { |
| 504 |
throw new IllegalArgumentException("Either secondaryActivity or secondaryIntent must be" |
| 505 |
+ " non-null."); |
| 506 |
} |
| 507 |
final Pair<Size, Size> minDimensionsPair; |
| 508 |
if (secondaryActivity != null) { |
| 509 |
minDimensionsPair = getActivitiesMinDimensionsPair(primaryActivity, secondaryActivity); |
| 510 |
} else { |
| 511 |
minDimensionsPair = getActivityIntentMinDimensionsPair(primaryActivity, |
| 512 |
secondaryIntent); |
| 513 |
} |
| 514 |
|
| 515 |
final TaskContainer taskContainer = splitContainer.getTaskContainer(); |
| 516 |
final SplitAttributes splitAttributes = sanitizeSplitAttributes( |
| 517 |
taskContainer.getTaskProperties(), splitContainer.getSplitAttributes(), |
| 518 |
minDimensionsPair); |
| 519 |
splitContainer.setSplitAttributes(splitAttributes); |
| 520 |
if (!shouldShowSplit(splitAttributes)) { |
| 521 |
|
| 522 |
|
| 523 |
if (splitContainer.getPrimaryContainer().getInfo() == null |
| 524 |
|| splitContainer.getSecondaryContainer().getInfo() == null) { |
| 525 |
return RESULT_EXPAND_FAILED_NO_TF_INFO; |
| 526 |
} |
| 527 |
final IBinder primaryToken = |
| 528 |
splitContainer.getPrimaryContainer().getTaskFragmentToken(); |
| 529 |
final IBinder secondaryToken = |
| 530 |
splitContainer.getSecondaryContainer().getTaskFragmentToken(); |
| 531 |
expandTaskFragment(wct, primaryToken); |
| 532 |
expandTaskFragment(wct, secondaryToken); |
| 533 |
|
| 534 |
setCompanionTaskFragment(wct, primaryToken, secondaryToken, |
| 535 |
splitContainer.getSplitRule(), true ); |
| 536 |
return RESULT_EXPANDED; |
| 537 |
} |
| 538 |
return RESULT_NOT_EXPANDED; |
| 539 |
} |
| 540 |
|
| 541 |
static boolean shouldShowSplit(@NonNull SplitContainer splitContainer) { |
| 542 |
return shouldShowSplit(splitContainer.getSplitAttributes()); |
| 543 |
} |
| 544 |
|
| 545 |
static boolean shouldShowSplit(@NonNull SplitAttributes splitAttributes) { |
| 546 |
return !(splitAttributes.getSplitType() instanceof ExpandContainersSplitType); |
| 547 |
} |
| 548 |
|
| 549 |
@NonNull |
| 550 |
SplitAttributes computeSplitAttributes(@NonNull TaskProperties taskProperties, |
| 551 |
@NonNull SplitRule rule, @Nullable Pair<Size, Size> minDimensionsPair) { |
| 552 |
final Configuration taskConfiguration = taskProperties.getConfiguration(); |
| 553 |
final WindowMetrics taskWindowMetrics = getTaskWindowMetrics(taskConfiguration); |
| 554 |
final SplitAttributesCalculator calculator = mController.getSplitAttributesCalculator(); |
| 555 |
final SplitAttributes defaultSplitAttributes = rule.getDefaultSplitAttributes(); |
| 556 |
final boolean isDefaultMinSizeSatisfied = rule.checkParentMetrics(taskWindowMetrics); |
| 557 |
if (calculator == null) { |
| 558 |
if (!isDefaultMinSizeSatisfied) { |
| 559 |
return EXPAND_CONTAINERS_ATTRIBUTES; |
| 560 |
} |
| 561 |
return sanitizeSplitAttributes(taskProperties, defaultSplitAttributes, |
| 562 |
minDimensionsPair); |
| 563 |
} |
| 564 |
final WindowLayoutInfo windowLayoutInfo = mWindowLayoutComponent |
| 565 |
.getCurrentWindowLayoutInfo(taskProperties.getDisplayId(), |
| 566 |
taskConfiguration.windowConfiguration); |
| 567 |
final SplitAttributesCalculatorParams params = new SplitAttributesCalculatorParams( |
| 568 |
taskWindowMetrics, taskConfiguration, defaultSplitAttributes, |
| 569 |
isDefaultMinSizeSatisfied, windowLayoutInfo, rule.getTag()); |
| 570 |
final SplitAttributes splitAttributes = calculator.computeSplitAttributesForParams(params); |
| 571 |
return sanitizeSplitAttributes(taskProperties, splitAttributes, minDimensionsPair); |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
@NonNull |
| 580 |
private SplitAttributes sanitizeSplitAttributes(@NonNull TaskProperties taskProperties, |
| 581 |
@NonNull SplitAttributes splitAttributes, |
| 582 |
@Nullable Pair<Size, Size> minDimensionsPair) { |
| 583 |
if (minDimensionsPair == null) { |
| 584 |
return splitAttributes; |
| 585 |
} |
| 586 |
final FoldingFeature foldingFeature = getFoldingFeature(taskProperties); |
| 587 |
final Configuration taskConfiguration = taskProperties.getConfiguration(); |
| 588 |
final Rect primaryBounds = getPrimaryBounds(taskConfiguration, splitAttributes, |
| 589 |
foldingFeature); |
| 590 |
final Rect secondaryBounds = getSecondaryBounds(taskConfiguration, splitAttributes, |
| 591 |
foldingFeature); |
| 592 |
if (boundsSmallerThanMinDimensions(primaryBounds, minDimensionsPair.first) |
| 593 |
|| boundsSmallerThanMinDimensions(secondaryBounds, minDimensionsPair.second)) { |
| 594 |
return EXPAND_CONTAINERS_ATTRIBUTES; |
| 595 |
} |
| 596 |
return splitAttributes; |
| 597 |
} |
| 598 |
|
| 599 |
@NonNull |
| 600 |
private static Pair<Size, Size> getActivitiesMinDimensionsPair( |
| 601 |
@NonNull Activity primaryActivity, @NonNull Activity secondaryActivity) { |
| 602 |
return new Pair<>(getMinDimensions(primaryActivity), getMinDimensions(secondaryActivity)); |
| 603 |
} |
| 604 |
|
| 605 |
@NonNull |
| 606 |
static Pair<Size, Size> getActivityIntentMinDimensionsPair(@NonNull Activity primaryActivity, |
| 607 |
@NonNull Intent secondaryIntent) { |
| 608 |
return new Pair<>(getMinDimensions(primaryActivity), getMinDimensions(secondaryIntent)); |
| 609 |
} |
| 610 |
|
| 611 |
@Nullable |
| 612 |
static Size getMinDimensions(@Nullable Activity activity) { |
| 613 |
if (activity == null) { |
| 614 |
return null; |
| 615 |
} |
| 616 |
final ActivityInfo.WindowLayout windowLayout = activity.getActivityInfo().windowLayout; |
| 617 |
if (windowLayout == null) { |
| 618 |
return null; |
| 619 |
} |
| 620 |
return new Size(windowLayout.minWidth, windowLayout.minHeight); |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
@Nullable |
| 625 |
static Size getMinDimensions(@Nullable Intent intent) { |
| 626 |
if (intent == null) { |
| 627 |
return null; |
| 628 |
} |
| 629 |
final PackageManager packageManager = ActivityThread.currentActivityThread() |
| 630 |
.getApplication().getPackageManager(); |
| 631 |
final ResolveInfo resolveInfo = packageManager.resolveActivity(intent, |
| 632 |
PackageManager.ResolveInfoFlags.of(MATCH_ALL)); |
| 633 |
if (resolveInfo == null) { |
| 634 |
return null; |
| 635 |
} |
| 636 |
final ActivityInfo activityInfo = resolveInfo.activityInfo; |
| 637 |
if (activityInfo == null) { |
| 638 |
return null; |
| 639 |
} |
| 640 |
final ActivityInfo.WindowLayout windowLayout = activityInfo.windowLayout; |
| 641 |
if (windowLayout == null) { |
| 642 |
return null; |
| 643 |
} |
| 644 |
return new Size(windowLayout.minWidth, windowLayout.minHeight); |
| 645 |
} |
| 646 |
|
| 647 |
private static boolean boundsSmallerThanMinDimensions(@NonNull Rect bounds, |
| 648 |
@Nullable Size minDimensions) { |
| 649 |
if (minDimensions == null) { |
| 650 |
return false; |
| 651 |
} |
| 652 |
return bounds.width() < minDimensions.getWidth() |
| 653 |
|| bounds.height() < minDimensions.getHeight(); |
| 654 |
} |
| 655 |
|
| 656 |
@VisibleForTesting |
| 657 |
@NonNull |
| 658 |
Rect getBoundsForPosition(@Position int position, @NonNull TaskProperties taskProperties, |
| 659 |
@NonNull SplitAttributes splitAttributes) { |
| 660 |
final Configuration taskConfiguration = taskProperties.getConfiguration(); |
| 661 |
final FoldingFeature foldingFeature = getFoldingFeature(taskProperties); |
| 662 |
final SplitType splitType = computeSplitType(splitAttributes, taskConfiguration, |
| 663 |
foldingFeature); |
| 664 |
final SplitAttributes computedSplitAttributes = new SplitAttributes.Builder() |
| 665 |
.setSplitType(splitType) |
| 666 |
.setLayoutDirection(splitAttributes.getLayoutDirection()) |
| 667 |
.build(); |
| 668 |
if (!shouldShowSplit(computedSplitAttributes)) { |
| 669 |
return new Rect(); |
| 670 |
} |
| 671 |
switch (position) { |
| 672 |
case POSITION_START: |
| 673 |
return getPrimaryBounds(taskConfiguration, computedSplitAttributes, foldingFeature); |
| 674 |
case POSITION_END: |
| 675 |
return getSecondaryBounds(taskConfiguration, computedSplitAttributes, |
| 676 |
foldingFeature); |
| 677 |
case POSITION_FILL: |
| 678 |
default: |
| 679 |
return new Rect(); |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
@NonNull |
| 684 |
private Rect getPrimaryBounds(@NonNull Configuration taskConfiguration, |
| 685 |
@NonNull SplitAttributes splitAttributes, @Nullable FoldingFeature foldingFeature) { |
| 686 |
if (!shouldShowSplit(splitAttributes)) { |
| 687 |
return new Rect(); |
| 688 |
} |
| 689 |
switch (splitAttributes.getLayoutDirection()) { |
| 690 |
case SplitAttributes.LayoutDirection.LEFT_TO_RIGHT: { |
| 691 |
return getLeftContainerBounds(taskConfiguration, splitAttributes, foldingFeature); |
| 692 |
} |
| 693 |
case SplitAttributes.LayoutDirection.RIGHT_TO_LEFT: { |
| 694 |
return getRightContainerBounds(taskConfiguration, splitAttributes, foldingFeature); |
| 695 |
} |
| 696 |
case SplitAttributes.LayoutDirection.LOCALE: { |
| 697 |
final boolean isLtr = taskConfiguration.getLayoutDirection() |
| 698 |
== View.LAYOUT_DIRECTION_LTR; |
| 699 |
return isLtr |
| 700 |
? getLeftContainerBounds(taskConfiguration, splitAttributes, foldingFeature) |
| 701 |
: getRightContainerBounds(taskConfiguration, splitAttributes, |
| 702 |
foldingFeature); |
| 703 |
} |
| 704 |
case SplitAttributes.LayoutDirection.TOP_TO_BOTTOM: { |
| 705 |
return getTopContainerBounds(taskConfiguration, splitAttributes, foldingFeature); |
| 706 |
} |
| 707 |
case SplitAttributes.LayoutDirection.BOTTOM_TO_TOP: { |
| 708 |
return getBottomContainerBounds(taskConfiguration, splitAttributes, foldingFeature); |
| 709 |
} |
| 710 |
default: |
| 711 |
throw new IllegalArgumentException("Unknown layout direction:" |
| 712 |
+ splitAttributes.getLayoutDirection()); |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
@NonNull |
| 717 |
private Rect getSecondaryBounds(@NonNull Configuration taskConfiguration, |
| 718 |
@NonNull SplitAttributes splitAttributes, @Nullable FoldingFeature foldingFeature) { |
| 719 |
if (!shouldShowSplit(splitAttributes)) { |
| 720 |
return new Rect(); |
| 721 |
} |
| 722 |
switch (splitAttributes.getLayoutDirection()) { |
| 723 |
case SplitAttributes.LayoutDirection.LEFT_TO_RIGHT: { |
| 724 |
return getRightContainerBounds(taskConfiguration, splitAttributes, foldingFeature); |
| 725 |
} |
| 726 |
case SplitAttributes.LayoutDirection.RIGHT_TO_LEFT: { |
| 727 |
return getLeftContainerBounds(taskConfiguration, splitAttributes, foldingFeature); |
| 728 |
} |
| 729 |
case SplitAttributes.LayoutDirection.LOCALE: { |
| 730 |
final boolean isLtr = taskConfiguration.getLayoutDirection() |
| 731 |
== View.LAYOUT_DIRECTION_LTR; |
| 732 |
return isLtr |
| 733 |
? getRightContainerBounds(taskConfiguration, splitAttributes, |
| 734 |
foldingFeature) |
| 735 |
: getLeftContainerBounds(taskConfiguration, splitAttributes, |
| 736 |
foldingFeature); |
| 737 |
} |
| 738 |
case SplitAttributes.LayoutDirection.TOP_TO_BOTTOM: { |
| 739 |
return getBottomContainerBounds(taskConfiguration, splitAttributes, foldingFeature); |
| 740 |
} |
| 741 |
case SplitAttributes.LayoutDirection.BOTTOM_TO_TOP: { |
| 742 |
return getTopContainerBounds(taskConfiguration, splitAttributes, foldingFeature); |
| 743 |
} |
| 744 |
default: |
| 745 |
throw new IllegalArgumentException("Unknown layout direction:" |
| 746 |
+ splitAttributes.getLayoutDirection()); |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
@NonNull |
| 751 |
private Rect getLeftContainerBounds(@NonNull Configuration taskConfiguration, |
| 752 |
@NonNull SplitAttributes splitAttributes, @Nullable FoldingFeature foldingFeature) { |
| 753 |
final int right = computeBoundaryBetweenContainers(taskConfiguration, splitAttributes, |
| 754 |
CONTAINER_POSITION_LEFT, foldingFeature); |
| 755 |
final Rect taskBounds = taskConfiguration.windowConfiguration.getBounds(); |
| 756 |
return new Rect(taskBounds.left, taskBounds.top, right, taskBounds.bottom); |
| 757 |
} |
| 758 |
|
| 759 |
@NonNull |
| 760 |
private Rect getRightContainerBounds(@NonNull Configuration taskConfiguration, |
| 761 |
@NonNull SplitAttributes splitAttributes, @Nullable FoldingFeature foldingFeature) { |
| 762 |
final int left = computeBoundaryBetweenContainers(taskConfiguration, splitAttributes, |
| 763 |
CONTAINER_POSITION_RIGHT, foldingFeature); |
| 764 |
final Rect parentBounds = taskConfiguration.windowConfiguration.getBounds(); |
| 765 |
return new Rect(left, parentBounds.top, parentBounds.right, parentBounds.bottom); |
| 766 |
} |
| 767 |
|
| 768 |
@NonNull |
| 769 |
private Rect getTopContainerBounds(@NonNull Configuration taskConfiguration, |
| 770 |
@NonNull SplitAttributes splitAttributes, @Nullable FoldingFeature foldingFeature) { |
| 771 |
final int bottom = computeBoundaryBetweenContainers(taskConfiguration, splitAttributes, |
| 772 |
CONTAINER_POSITION_TOP, foldingFeature); |
| 773 |
final Rect parentBounds = taskConfiguration.windowConfiguration.getBounds(); |
| 774 |
return new Rect(parentBounds.left, parentBounds.top, parentBounds.right, bottom); |
| 775 |
} |
| 776 |
|
| 777 |
@NonNull |
| 778 |
private Rect getBottomContainerBounds(@NonNull Configuration taskConfiguration, |
| 779 |
@NonNull SplitAttributes splitAttributes, @Nullable FoldingFeature foldingFeature) { |
| 780 |
final int top = computeBoundaryBetweenContainers(taskConfiguration, splitAttributes, |
| 781 |
CONTAINER_POSITION_BOTTOM, foldingFeature); |
| 782 |
final Rect parentBounds = taskConfiguration.windowConfiguration.getBounds(); |
| 783 |
return new Rect(parentBounds.left, top, parentBounds.right, parentBounds.bottom); |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
private int computeBoundaryBetweenContainers(@NonNull Configuration taskConfiguration, |
| 806 |
@NonNull SplitAttributes splitAttributes, @ContainerPosition int position, |
| 807 |
@Nullable FoldingFeature foldingFeature) { |
| 808 |
final Rect parentBounds = taskConfiguration.windowConfiguration.getBounds(); |
| 809 |
final int startPoint = shouldSplitHorizontally(splitAttributes) |
| 810 |
? parentBounds.top |
| 811 |
: parentBounds.left; |
| 812 |
final int dimen = shouldSplitHorizontally(splitAttributes) |
| 813 |
? parentBounds.height() |
| 814 |
: parentBounds.width(); |
| 815 |
final SplitType splitType = splitAttributes.getSplitType(); |
| 816 |
if (splitType instanceof RatioSplitType) { |
| 817 |
final RatioSplitType splitRatio = (RatioSplitType) splitType; |
| 818 |
return (int) (startPoint + dimen * splitRatio.getRatio()); |
| 819 |
} |
| 820 |
|
| 821 |
|
| 822 |
Objects.requireNonNull(foldingFeature); |
| 823 |
if (!(splitType instanceof HingeSplitType)) { |
| 824 |
throw new IllegalArgumentException("Unknown splitType:" + splitType); |
| 825 |
} |
| 826 |
final Rect hingeArea = foldingFeature.getBounds(); |
| 827 |
switch (position) { |
| 828 |
case CONTAINER_POSITION_LEFT: |
| 829 |
return hingeArea.left; |
| 830 |
case CONTAINER_POSITION_TOP: |
| 831 |
return hingeArea.top; |
| 832 |
case CONTAINER_POSITION_RIGHT: |
| 833 |
return hingeArea.right; |
| 834 |
case CONTAINER_POSITION_BOTTOM: |
| 835 |
return hingeArea.bottom; |
| 836 |
default: |
| 837 |
throw new IllegalArgumentException("Unknown position:" + position); |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
@Nullable |
| 842 |
private FoldingFeature getFoldingFeature(@NonNull TaskProperties taskProperties) { |
| 843 |
final int displayId = taskProperties.getDisplayId(); |
| 844 |
final WindowConfiguration windowConfiguration = taskProperties.getConfiguration() |
| 845 |
.windowConfiguration; |
| 846 |
final WindowLayoutInfo info = mWindowLayoutComponent |
| 847 |
.getCurrentWindowLayoutInfo(displayId, windowConfiguration); |
| 848 |
final List<DisplayFeature> displayFeatures = info.getDisplayFeatures(); |
| 849 |
if (displayFeatures.isEmpty()) { |
| 850 |
return null; |
| 851 |
} |
| 852 |
final List<FoldingFeature> foldingFeatures = new ArrayList<>(); |
| 853 |
for (DisplayFeature displayFeature : displayFeatures) { |
| 854 |
if (displayFeature instanceof FoldingFeature) { |
| 855 |
foldingFeatures.add((FoldingFeature) displayFeature); |
| 856 |
} |
| 857 |
} |
| 858 |
|
| 859 |
if (foldingFeatures.size() != 1) { |
| 860 |
return null; |
| 861 |
} |
| 862 |
return foldingFeatures.get(0); |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
private static boolean shouldSplitHorizontally(SplitAttributes splitAttributes) { |
| 870 |
switch (splitAttributes.getLayoutDirection()) { |
| 871 |
case SplitAttributes.LayoutDirection.TOP_TO_BOTTOM: |
| 872 |
case SplitAttributes.LayoutDirection.BOTTOM_TO_TOP: |
| 873 |
return true; |
| 874 |
default: |
| 875 |
return false; |
| 876 |
} |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
private SplitType computeSplitType(@NonNull SplitAttributes splitAttributes, |
| 891 |
@NonNull Configuration taskConfiguration, @Nullable FoldingFeature foldingFeature) { |
| 892 |
final int layoutDirection = splitAttributes.getLayoutDirection(); |
| 893 |
final SplitType splitType = splitAttributes.getSplitType(); |
| 894 |
if (splitType instanceof ExpandContainersSplitType) { |
| 895 |
return splitType; |
| 896 |
} else if (splitType instanceof RatioSplitType) { |
| 897 |
final RatioSplitType splitRatio = (RatioSplitType) splitType; |
| 898 |
|
| 899 |
|
| 900 |
final SplitType reversedSplitType = new RatioSplitType(1 - splitRatio.getRatio()); |
| 901 |
switch (layoutDirection) { |
| 902 |
case SplitAttributes.LayoutDirection.LEFT_TO_RIGHT: |
| 903 |
case SplitAttributes.LayoutDirection.TOP_TO_BOTTOM: |
| 904 |
return splitType; |
| 905 |
case SplitAttributes.LayoutDirection.RIGHT_TO_LEFT: |
| 906 |
case SplitAttributes.LayoutDirection.BOTTOM_TO_TOP: |
| 907 |
return reversedSplitType; |
| 908 |
case LayoutDirection.LOCALE: { |
| 909 |
boolean isLtr = taskConfiguration.getLayoutDirection() |
| 910 |
== View.LAYOUT_DIRECTION_LTR; |
| 911 |
return isLtr ? splitType : reversedSplitType; |
| 912 |
} |
| 913 |
} |
| 914 |
} else if (splitType instanceof HingeSplitType) { |
| 915 |
final HingeSplitType hinge = (HingeSplitType) splitType; |
| 916 |
@WindowingMode |
| 917 |
final int windowingMode = taskConfiguration.windowConfiguration.getWindowingMode(); |
| 918 |
return shouldSplitByHinge(splitAttributes, foldingFeature, windowingMode) |
| 919 |
? hinge : hinge.getFallbackSplitType(); |
| 920 |
} |
| 921 |
throw new IllegalArgumentException("Unknown SplitType:" + splitType); |
| 922 |
} |
| 923 |
|
| 924 |
private static boolean shouldSplitByHinge(@NonNull SplitAttributes splitAttributes, |
| 925 |
@Nullable FoldingFeature foldingFeature, @WindowingMode int taskWindowingMode) { |
| 926 |
|
| 927 |
if (!(splitAttributes.getSplitType() instanceof HingeSplitType)) { |
| 928 |
return false; |
| 929 |
} |
| 930 |
|
| 931 |
if (foldingFeature == null) { |
| 932 |
return false; |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
if (WindowConfiguration.inMultiWindowMode(taskWindowingMode)) { |
| 937 |
return false; |
| 938 |
} |
| 939 |
|
| 940 |
|
| 941 |
return shouldSplitHorizontally(splitAttributes) == isFoldingAreaHorizontal(foldingFeature); |
| 942 |
} |
| 943 |
|
| 944 |
private static boolean isFoldingAreaHorizontal(@NonNull FoldingFeature foldingFeature) { |
| 945 |
final Rect bounds = foldingFeature.getBounds(); |
| 946 |
return bounds.width() > bounds.height(); |
| 947 |
} |
| 948 |
|
| 949 |
@NonNull |
| 950 |
static TaskProperties getTaskProperties(@NonNull TaskFragmentContainer container) { |
| 951 |
return container.getTaskContainer().getTaskProperties(); |
| 952 |
} |
| 953 |
|
| 954 |
@NonNull |
| 955 |
TaskProperties getTaskProperties(@NonNull Activity activity) { |
| 956 |
final TaskContainer taskContainer = mController.getTaskContainer( |
| 957 |
mController.getTaskId(activity)); |
| 958 |
if (taskContainer != null) { |
| 959 |
return taskContainer.getTaskProperties(); |
| 960 |
} |
| 961 |
return TaskProperties.getTaskPropertiesFromActivity(activity); |
| 962 |
} |
| 963 |
|
| 964 |
@NonNull |
| 965 |
WindowMetrics getTaskWindowMetrics(@NonNull Activity activity) { |
| 966 |
return getTaskWindowMetrics(getTaskProperties(activity).getConfiguration()); |
| 967 |
} |
| 968 |
|
| 969 |
@NonNull |
| 970 |
private static WindowMetrics getTaskWindowMetrics(@NonNull Configuration taskConfiguration) { |
| 971 |
final Rect taskBounds = taskConfiguration.windowConfiguration.getBounds(); |
| 972 |
|
| 973 |
return new WindowMetrics(taskBounds, WindowInsets.CONSUMED); |
| 974 |
} |
| 975 |
} |