Debian Codegraph @

core/java/android/app/TaskInfo.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package 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 * Stores information about a particular Task.
47 */
48 public class TaskInfo {
49 private static final String TAG = "TaskInfo";
50
51 /**
52 * The id of the user the task was running as if this is a leaf task. The id of the current
53 * running user of the system otherwise.
54 * @hide
55 */
56 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
57 public int userId;
58
59 /**
60 * The identifier for this task.
61 */
62 public int taskId;
63
64 /**
65 * Whether or not this task has any running activities.
66 */
67 public boolean isRunning;
68
69 /**
70 * The base intent of the task (generally the intent that launched the task). This intent can
71 * be used to relaunch the task (if it is no longer running) or brought to the front if it is.
72 */
73 @NonNull
74 public Intent baseIntent;
75
76 /**
77 * The component of the first activity in the task, can be considered the "application" of this
78 * task.
79 */
80 @Nullable
81 public ComponentName baseActivity;
82
83 /**
84 * The component of the top activity in the task, currently showing to the user.
85 */
86 @Nullable
87 public ComponentName topActivity;
88
89 /**
90 * The component of the target activity if this task was started from an activity alias.
91 * Otherwise, this is null.
92 */
93 @Nullable
94 public ComponentName origActivity;
95
96 /**
97 * The component of the activity that started this task (may be the component of the activity
98 * alias).
99 * @hide
100 */
101 @Nullable
102 public ComponentName realActivity;
103
104 /**
105 * The number of activities in this task (including running).
106 */
107 public int numActivities;
108
109 /**
110 * The last time this task was active since boot (including time spent in sleep).
111 * @hide
112 */
113 @UnsupportedAppUsage
114 public long lastActiveTime;
115
116 /**
117 * The id of the display this task is associated with.
118 * @hide
119 */
120 public int displayId;
121
122 /**
123 * The feature id of {@link com.android.server.wm.TaskDisplayArea} this task is associated with.
124 * @hide
125 */
126 public int displayAreaFeatureId = FEATURE_UNDEFINED;
127
128 /**
129 * The recent activity values for the highest activity in the stack to have set the values.
130 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
131 */
132 @Nullable
133 public ActivityManager.TaskDescription taskDescription;
134
135 /**
136 * The locusId of the task.
137 * @hide
138 */
139 @Nullable
140 public LocusId mTopActivityLocusId;
141
142 /**
143 * Whether this task supports multi windowing modes based on the device settings and the
144 * root activity resizability and configuration.
145 * @hide
146 */
147 public boolean supportsMultiWindow;
148
149 /**
150 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
151 * @hide
152 */
153 @UnsupportedAppUsage
154 public int resizeMode;
155
156 /**
157 * The current configuration of the task.
158 * @hide
159 */
160 @NonNull
161 @UnsupportedAppUsage
162 public final Configuration configuration = new Configuration();
163
164 /**
165 * Used as an opaque identifier for this task.
166 * @hide
167 */
168 @NonNull
169 public WindowContainerToken token;
170
171 /**
172 * The PictureInPictureParams for the Task, if set.
173 * @hide
174 */
175 @Nullable
176 public PictureInPictureParams pictureInPictureParams;
177
178 /**
179 * @hide
180 */
181 public boolean shouldDockBigOverlays;
182
183 /**
184 * The task id of the host Task of the launch-into-pip Activity, i.e., it points to the Task
185 * the launch-into-pip Activity is originated from.
186 * @hide
187 */
188 public int launchIntoPipHostTaskId;
189
190 /**
191 * The {@link Rect} copied from {@link DisplayCutout#getSafeInsets()} if the cutout is not of
192 * (LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES, LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS),
193 * {@code null} otherwise.
194 * @hide
195 */
196 @Nullable
197 public Rect displayCutoutInsets;
198
199 /**
200 * The activity type of the top activity in this task.
201 * @hide
202 */
203 public @WindowConfiguration.ActivityType int topActivityType;
204
205 /**
206 * The {@link ActivityInfo} of the top activity in this task.
207 * @hide
208 */
209 @Nullable
210 public ActivityInfo topActivityInfo;
211
212 /**
213 * Whether the direct top activity is in size compat mode on foreground.
214 * @hide
215 */
216 public boolean topActivityInSizeCompat;
217
218 /**
219 * Whether the direct top activity is eligible for letterbox education.
220 * @hide
221 */
222 public boolean topActivityEligibleForLetterboxEducation;
223
224 /**
225 * Whether this task is resizable. Unlike {@link #resizeMode} (which is what the top activity
226 * supports), this is what the system actually uses for resizability based on other policy and
227 * developer options.
228 * @hide
229 */
230 public boolean isResizeable;
231
232 /**
233 * Minimal width of the task when it's resizeable.
234 * @hide
235 */
236 public int minWidth;
237
238 /**
239 * Minimal height of the task when it's resizeable.
240 * @hide
241 */
242 public int minHeight;
243
244 /**
245 * The default minimal size of the task used when a minWidth or minHeight is not specified.
246 * @hide
247 */
248 public int defaultMinSize;
249
250 /**
251 * Relative position of the task's top left corner in the parent container.
252 * @hide
253 */
254 public Point positionInParent;
255
256 /**
257 * The launch cookies associated with activities in this task if any.
258 * @see ActivityOptions#setLaunchCookie(IBinder)
259 * @hide
260 */
261 public ArrayList<IBinder> launchCookies = new ArrayList<>();
262
263 /**
264 * The identifier of the parent task that is created by organizer, otherwise
265 * {@link ActivityTaskManager#INVALID_TASK_ID}.
266 * @hide
267 */
268 public int parentTaskId;
269
270 /**
271 * Whether this task is focused.
272 * @hide
273 */
274 public boolean isFocused;
275
276 /**
277 * Whether this task is visible.
278 * @hide
279 */
280 public boolean isVisible;
281
282 /**
283 * Whether this task is sleeping due to sleeping display.
284 * @hide
285 */
286 public boolean isSleeping;
287
288 /**
289 * Camera compat control isn't shown because it's not requested by heuristics.
290 * @hide
291 */
292 public static final int CAMERA_COMPAT_CONTROL_HIDDEN = 0;
293
294 /**
295 * Camera compat control is shown with the treatment suggested.
296 * @hide
297 */
298 public static final int CAMERA_COMPAT_CONTROL_TREATMENT_SUGGESTED = 1;
299
300 /**
301 * Camera compat control is shown to allow reverting the applied treatment.
302 * @hide
303 */
304 public static final int CAMERA_COMPAT_CONTROL_TREATMENT_APPLIED = 2;
305
306 /**
307 * Camera compat control is dismissed by user.
308 * @hide
309 */
310 public static final int CAMERA_COMPAT_CONTROL_DISMISSED = 3;
311
312 /**
313 * Enum for the Camera app compat control states.
314 * @hide
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 * State of the Camera app compat control which is used to correct stretched viewfinder
327 * in apps that don't handle all possible configurations and changes between them correctly.
328 * @hide
329 */
330 @CameraCompatControlState
331 public int cameraCompatControlState = CAMERA_COMPAT_CONTROL_HIDDEN;
332
333 TaskInfo() {
334 // Do nothing
335 }
336
337 private TaskInfo(Parcel source) {
338 readFromParcel(source);
339 }
340
341 /**
342 * Whether this task is visible.
343 */
344 public boolean isVisible() {
345 return isVisible;
346 }
347
348 /** @hide */
349 @NonNull
350 @TestApi
351 public WindowContainerToken getToken() {
352 return token;
353 }
354
355 /** @hide */
356 @NonNull
357 @TestApi
358 public Configuration getConfiguration() {
359 return configuration;
360 }
361
362 /** @hide */
363 @Nullable
364 @TestApi
365 public PictureInPictureParams getPictureInPictureParams() {
366 return pictureInPictureParams;
367 }
368
369 /** @hide */
370 @TestApi
371 public boolean shouldDockBigOverlays() {
372 return shouldDockBigOverlays;
373 }
374
375 /** @hide */
376 @WindowConfiguration.WindowingMode
377 public int getWindowingMode() {
378 return configuration.windowConfiguration.getWindowingMode();
379 }
380
381 /** @hide */
382 @WindowConfiguration.ActivityType
383 public int getActivityType() {
384 return configuration.windowConfiguration.getActivityType();
385 }
386
387 /** @hide */
388 public void addLaunchCookie(IBinder cookie) {
389 if (cookie == null || launchCookies.contains(cookie)) return;
390 launchCookies.add(cookie);
391 }
392
393 /** @hide */
394 public boolean hasCameraCompatControl() {
395 return cameraCompatControlState != CAMERA_COMPAT_CONTROL_HIDDEN
396 && cameraCompatControlState != CAMERA_COMPAT_CONTROL_DISMISSED;
397 }
398
399 /** @hide */
400 public boolean hasCompatUI() {
401 return hasCameraCompatControl() || topActivityInSizeCompat
402 || topActivityEligibleForLetterboxEducation;
403 }
404
405 /**
406 * @return {@code true} if this task contains the launch cookie.
407 * @hide
408 */
409 @TestApi
410 public boolean containsLaunchCookie(@NonNull IBinder cookie) {
411 return launchCookies.contains(cookie);
412 }
413
414 /**
415 * @return The parent task id of this task.
416 * @hide
417 */
418 @TestApi
419 public int getParentTaskId() {
420 return parentTaskId;
421 }
422
423 /** @hide */
424 @TestApi
425 public boolean hasParentTask() {
426 return parentTaskId != INVALID_TASK_ID;
427 }
428
429 /**
430 * Returns {@code true} if the parameters that are important for task organizers are equal
431 * between this {@link TaskInfo} and {@param that}.
432 * @hide
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 * @return {@code true} if parameters that are important for size compat have changed.
458 * @hide
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 // Bounds are important if top activity has compat controls.
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 * Reads the TaskInfo from a parcel.
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 * Writes the TaskInfo to a parcel.
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 /** @hide */
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 }