| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
| 20 |
import static android.window.DisplayAreaOrganizer.FEATURE_UNDEFINED; |
| 21 |
|
| 22 |
import android.annotation.IntDef; |
| 23 |
import android.annotation.NonNull; |
| 24 |
import android.annotation.Nullable; |
| 25 |
import android.annotation.TestApi; |
| 26 |
import android.compat.annotation.UnsupportedAppUsage; |
| 27 |
import android.content.ComponentName; |
| 28 |
import android.content.Intent; |
| 29 |
import android.content.LocusId; |
| 30 |
import android.content.pm.ActivityInfo; |
| 31 |
import android.content.res.Configuration; |
| 32 |
import android.graphics.Point; |
| 33 |
import android.graphics.Rect; |
| 34 |
import android.os.Build; |
| 35 |
import android.os.IBinder; |
| 36 |
import android.os.Parcel; |
| 37 |
import android.view.DisplayCutout; |
| 38 |
import android.window.WindowContainerToken; |
| 39 |
|
| 40 |
import java.lang.annotation.Retention; |
| 41 |
import java.lang.annotation.RetentionPolicy; |
| 42 |
import java.util.ArrayList; |
| 43 |
import java.util.Objects; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public class TaskInfo { |
| 49 |
private static final String TAG = "TaskInfo"; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 57 |
public int userId; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public int taskId; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public boolean isRunning; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
@NonNull |
| 74 |
public Intent baseIntent; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
@Nullable |
| 81 |
public ComponentName baseActivity; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
@Nullable |
| 87 |
public ComponentName topActivity; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
@Nullable |
| 94 |
public ComponentName origActivity; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
@Nullable |
| 102 |
public ComponentName realActivity; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public int numActivities; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
@UnsupportedAppUsage |
| 114 |
public long lastActiveTime; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public int displayId; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public int displayAreaFeatureId = FEATURE_UNDEFINED; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
@Nullable |
| 133 |
public ActivityManager.TaskDescription taskDescription; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
@Nullable |
| 140 |
public LocusId mTopActivityLocusId; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public boolean supportsMultiWindow; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
@UnsupportedAppUsage |
| 154 |
public int resizeMode; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
@NonNull |
| 161 |
@UnsupportedAppUsage |
| 162 |
public final Configuration configuration = new Configuration(); |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
@NonNull |
| 169 |
public WindowContainerToken token; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
@Nullable |
| 176 |
public PictureInPictureParams pictureInPictureParams; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
public boolean shouldDockBigOverlays; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public int launchIntoPipHostTaskId; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
@Nullable |
| 197 |
public Rect displayCutoutInsets; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public @WindowConfiguration.ActivityType int topActivityType; |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
@Nullable |
| 210 |
public ActivityInfo topActivityInfo; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
public boolean topActivityInSizeCompat; |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
public boolean topActivityEligibleForLetterboxEducation; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
public boolean isResizeable; |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
public int minWidth; |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
public int minHeight; |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public int defaultMinSize; |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
public Point positionInParent; |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
public ArrayList<IBinder> launchCookies = new ArrayList<>(); |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public int parentTaskId; |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
public boolean isFocused; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
public boolean isVisible; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
public boolean isSleeping; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public static final int CAMERA_COMPAT_CONTROL_HIDDEN = 0; |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
public static final int CAMERA_COMPAT_CONTROL_TREATMENT_SUGGESTED = 1; |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
public static final int CAMERA_COMPAT_CONTROL_TREATMENT_APPLIED = 2; |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
public static final int CAMERA_COMPAT_CONTROL_DISMISSED = 3; |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
@Retention(RetentionPolicy.SOURCE) |
| 317 |
@IntDef(prefix = { "CAMERA_COMPAT_CONTROL_" }, value = { |
| 318 |
CAMERA_COMPAT_CONTROL_HIDDEN, |
| 319 |
CAMERA_COMPAT_CONTROL_TREATMENT_SUGGESTED, |
| 320 |
CAMERA_COMPAT_CONTROL_TREATMENT_APPLIED, |
| 321 |
CAMERA_COMPAT_CONTROL_DISMISSED, |
| 322 |
}) |
| 323 |
public @interface CameraCompatControlState {}; |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
@CameraCompatControlState |
| 331 |
public int cameraCompatControlState = CAMERA_COMPAT_CONTROL_HIDDEN; |
| 332 |
|
| 333 |
TaskInfo() { |
| 334 |
|
| 335 |
} |
| 336 |
|
| 337 |
private TaskInfo(Parcel source) { |
| 338 |
readFromParcel(source); |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
public boolean isVisible() { |
| 345 |
return isVisible; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
@NonNull |
| 350 |
@TestApi |
| 351 |
public WindowContainerToken getToken() { |
| 352 |
return token; |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
@NonNull |
| 357 |
@TestApi |
| 358 |
public Configuration getConfiguration() { |
| 359 |
return configuration; |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
@Nullable |
| 364 |
@TestApi |
| 365 |
public PictureInPictureParams getPictureInPictureParams() { |
| 366 |
return pictureInPictureParams; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
@TestApi |
| 371 |
public boolean shouldDockBigOverlays() { |
| 372 |
return shouldDockBigOverlays; |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
@WindowConfiguration.WindowingMode |
| 377 |
public int getWindowingMode() { |
| 378 |
return configuration.windowConfiguration.getWindowingMode(); |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
@WindowConfiguration.ActivityType |
| 383 |
public int getActivityType() { |
| 384 |
return configuration.windowConfiguration.getActivityType(); |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
public void addLaunchCookie(IBinder cookie) { |
| 389 |
if (cookie == null || launchCookies.contains(cookie)) return; |
| 390 |
launchCookies.add(cookie); |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
public boolean hasCameraCompatControl() { |
| 395 |
return cameraCompatControlState != CAMERA_COMPAT_CONTROL_HIDDEN |
| 396 |
&& cameraCompatControlState != CAMERA_COMPAT_CONTROL_DISMISSED; |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
public boolean hasCompatUI() { |
| 401 |
return hasCameraCompatControl() || topActivityInSizeCompat |
| 402 |
|| topActivityEligibleForLetterboxEducation; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
@TestApi |
| 410 |
public boolean containsLaunchCookie(@NonNull IBinder cookie) { |
| 411 |
return launchCookies.contains(cookie); |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
@TestApi |
| 419 |
public int getParentTaskId() { |
| 420 |
return parentTaskId; |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
@TestApi |
| 425 |
public boolean hasParentTask() { |
| 426 |
return parentTaskId != INVALID_TASK_ID; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
public boolean equalsForTaskOrganizer(@Nullable TaskInfo that) { |
| 435 |
if (that == null) { |
| 436 |
return false; |
| 437 |
} |
| 438 |
return topActivityType == that.topActivityType |
| 439 |
&& isResizeable == that.isResizeable |
| 440 |
&& supportsMultiWindow == that.supportsMultiWindow |
| 441 |
&& displayAreaFeatureId == that.displayAreaFeatureId |
| 442 |
&& Objects.equals(positionInParent, that.positionInParent) |
| 443 |
&& Objects.equals(pictureInPictureParams, that.pictureInPictureParams) |
| 444 |
&& Objects.equals(shouldDockBigOverlays, that.shouldDockBigOverlays) |
| 445 |
&& Objects.equals(displayCutoutInsets, that.displayCutoutInsets) |
| 446 |
&& getWindowingMode() == that.getWindowingMode() |
| 447 |
&& Objects.equals(taskDescription, that.taskDescription) |
| 448 |
&& isFocused == that.isFocused |
| 449 |
&& isVisible == that.isVisible |
| 450 |
&& isSleeping == that.isSleeping |
| 451 |
&& Objects.equals(mTopActivityLocusId, that.mTopActivityLocusId) |
| 452 |
&& parentTaskId == that.parentTaskId |
| 453 |
&& Objects.equals(topActivity, that.topActivity); |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
public boolean equalsForCompatUi(@Nullable TaskInfo that) { |
| 461 |
if (that == null) { |
| 462 |
return false; |
| 463 |
} |
| 464 |
return displayId == that.displayId |
| 465 |
&& taskId == that.taskId |
| 466 |
&& topActivityInSizeCompat == that.topActivityInSizeCompat |
| 467 |
&& topActivityEligibleForLetterboxEducation |
| 468 |
== that.topActivityEligibleForLetterboxEducation |
| 469 |
&& cameraCompatControlState == that.cameraCompatControlState |
| 470 |
|
| 471 |
&& (!hasCompatUI() || configuration.windowConfiguration.getBounds() |
| 472 |
.equals(that.configuration.windowConfiguration.getBounds())) |
| 473 |
&& (!hasCompatUI() || configuration.getLayoutDirection() |
| 474 |
== that.configuration.getLayoutDirection()) |
| 475 |
&& (!hasCompatUI() || isVisible == that.isVisible); |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
void readFromParcel(Parcel source) { |
| 482 |
userId = source.readInt(); |
| 483 |
taskId = source.readInt(); |
| 484 |
displayId = source.readInt(); |
| 485 |
isRunning = source.readBoolean(); |
| 486 |
baseIntent = source.readTypedObject(Intent.CREATOR); |
| 487 |
baseActivity = ComponentName.readFromParcel(source); |
| 488 |
topActivity = ComponentName.readFromParcel(source); |
| 489 |
origActivity = ComponentName.readFromParcel(source); |
| 490 |
realActivity = ComponentName.readFromParcel(source); |
| 491 |
|
| 492 |
numActivities = source.readInt(); |
| 493 |
lastActiveTime = source.readLong(); |
| 494 |
|
| 495 |
taskDescription = source.readTypedObject(ActivityManager.TaskDescription.CREATOR); |
| 496 |
supportsMultiWindow = source.readBoolean(); |
| 497 |
resizeMode = source.readInt(); |
| 498 |
configuration.readFromParcel(source); |
| 499 |
token = WindowContainerToken.CREATOR.createFromParcel(source); |
| 500 |
topActivityType = source.readInt(); |
| 501 |
pictureInPictureParams = source.readTypedObject(PictureInPictureParams.CREATOR); |
| 502 |
shouldDockBigOverlays = source.readBoolean(); |
| 503 |
launchIntoPipHostTaskId = source.readInt(); |
| 504 |
displayCutoutInsets = source.readTypedObject(Rect.CREATOR); |
| 505 |
topActivityInfo = source.readTypedObject(ActivityInfo.CREATOR); |
| 506 |
isResizeable = source.readBoolean(); |
| 507 |
minWidth = source.readInt(); |
| 508 |
minHeight = source.readInt(); |
| 509 |
defaultMinSize = source.readInt(); |
| 510 |
source.readBinderList(launchCookies); |
| 511 |
positionInParent = source.readTypedObject(Point.CREATOR); |
| 512 |
parentTaskId = source.readInt(); |
| 513 |
isFocused = source.readBoolean(); |
| 514 |
isVisible = source.readBoolean(); |
| 515 |
isSleeping = source.readBoolean(); |
| 516 |
topActivityInSizeCompat = source.readBoolean(); |
| 517 |
topActivityEligibleForLetterboxEducation = source.readBoolean(); |
| 518 |
mTopActivityLocusId = source.readTypedObject(LocusId.CREATOR); |
| 519 |
displayAreaFeatureId = source.readInt(); |
| 520 |
cameraCompatControlState = source.readInt(); |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
void writeToParcel(Parcel dest, int flags) { |
| 527 |
dest.writeInt(userId); |
| 528 |
dest.writeInt(taskId); |
| 529 |
dest.writeInt(displayId); |
| 530 |
dest.writeBoolean(isRunning); |
| 531 |
dest.writeTypedObject(baseIntent, 0); |
| 532 |
|
| 533 |
ComponentName.writeToParcel(baseActivity, dest); |
| 534 |
ComponentName.writeToParcel(topActivity, dest); |
| 535 |
ComponentName.writeToParcel(origActivity, dest); |
| 536 |
ComponentName.writeToParcel(realActivity, dest); |
| 537 |
|
| 538 |
dest.writeInt(numActivities); |
| 539 |
dest.writeLong(lastActiveTime); |
| 540 |
|
| 541 |
dest.writeTypedObject(taskDescription, flags); |
| 542 |
dest.writeBoolean(supportsMultiWindow); |
| 543 |
dest.writeInt(resizeMode); |
| 544 |
configuration.writeToParcel(dest, flags); |
| 545 |
token.writeToParcel(dest, flags); |
| 546 |
dest.writeInt(topActivityType); |
| 547 |
dest.writeTypedObject(pictureInPictureParams, flags); |
| 548 |
dest.writeBoolean(shouldDockBigOverlays); |
| 549 |
dest.writeInt(launchIntoPipHostTaskId); |
| 550 |
dest.writeTypedObject(displayCutoutInsets, flags); |
| 551 |
dest.writeTypedObject(topActivityInfo, flags); |
| 552 |
dest.writeBoolean(isResizeable); |
| 553 |
dest.writeInt(minWidth); |
| 554 |
dest.writeInt(minHeight); |
| 555 |
dest.writeInt(defaultMinSize); |
| 556 |
dest.writeBinderList(launchCookies); |
| 557 |
dest.writeTypedObject(positionInParent, flags); |
| 558 |
dest.writeInt(parentTaskId); |
| 559 |
dest.writeBoolean(isFocused); |
| 560 |
dest.writeBoolean(isVisible); |
| 561 |
dest.writeBoolean(isSleeping); |
| 562 |
dest.writeBoolean(topActivityInSizeCompat); |
| 563 |
dest.writeBoolean(topActivityEligibleForLetterboxEducation); |
| 564 |
dest.writeTypedObject(mTopActivityLocusId, flags); |
| 565 |
dest.writeInt(displayAreaFeatureId); |
| 566 |
dest.writeInt(cameraCompatControlState); |
| 567 |
} |
| 568 |
|
| 569 |
@Override |
| 570 |
public String toString() { |
| 571 |
return "TaskInfo{userId=" + userId + " taskId=" + taskId |
| 572 |
+ " displayId=" + displayId |
| 573 |
+ " isRunning=" + isRunning |
| 574 |
+ " baseIntent=" + baseIntent + " baseActivity=" + baseActivity |
| 575 |
+ " topActivity=" + topActivity + " origActivity=" + origActivity |
| 576 |
+ " realActivity=" + realActivity |
| 577 |
+ " numActivities=" + numActivities |
| 578 |
+ " lastActiveTime=" + lastActiveTime |
| 579 |
+ " supportsMultiWindow=" + supportsMultiWindow |
| 580 |
+ " resizeMode=" + resizeMode |
| 581 |
+ " isResizeable=" + isResizeable |
| 582 |
+ " minWidth=" + minWidth |
| 583 |
+ " minHeight=" + minHeight |
| 584 |
+ " defaultMinSize=" + defaultMinSize |
| 585 |
+ " token=" + token |
| 586 |
+ " topActivityType=" + topActivityType |
| 587 |
+ " pictureInPictureParams=" + pictureInPictureParams |
| 588 |
+ " shouldDockBigOverlays=" + shouldDockBigOverlays |
| 589 |
+ " launchIntoPipHostTaskId=" + launchIntoPipHostTaskId |
| 590 |
+ " displayCutoutSafeInsets=" + displayCutoutInsets |
| 591 |
+ " topActivityInfo=" + topActivityInfo |
| 592 |
+ " launchCookies=" + launchCookies |
| 593 |
+ " positionInParent=" + positionInParent |
| 594 |
+ " parentTaskId=" + parentTaskId |
| 595 |
+ " isFocused=" + isFocused |
| 596 |
+ " isVisible=" + isVisible |
| 597 |
+ " isSleeping=" + isSleeping |
| 598 |
+ " topActivityInSizeCompat=" + topActivityInSizeCompat |
| 599 |
+ " topActivityEligibleForLetterboxEducation= " |
| 600 |
+ topActivityEligibleForLetterboxEducation |
| 601 |
+ " locusId=" + mTopActivityLocusId |
| 602 |
+ " displayAreaFeatureId=" + displayAreaFeatureId |
| 603 |
+ " cameraCompatControlState=" |
| 604 |
+ cameraCompatControlStateToString(cameraCompatControlState) |
| 605 |
+ "}"; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
public static String cameraCompatControlStateToString( |
| 610 |
@CameraCompatControlState int cameraCompatControlState) { |
| 611 |
switch (cameraCompatControlState) { |
| 612 |
case CAMERA_COMPAT_CONTROL_HIDDEN: return "hidden"; |
| 613 |
case CAMERA_COMPAT_CONTROL_TREATMENT_SUGGESTED: return "treatment-suggested"; |
| 614 |
case CAMERA_COMPAT_CONTROL_TREATMENT_APPLIED: return "treatment-applied"; |
| 615 |
case CAMERA_COMPAT_CONTROL_DISMISSED: return "dismissed"; |
| 616 |
default: |
| 617 |
throw new AssertionError( |
| 618 |
"Unexpected camera compat control state: " + cameraCompatControlState); |
| 619 |
} |
| 620 |
} |
| 621 |
} |