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 android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.TestApi; 22 import android.compat.annotation.UnsupportedAppUsage; 23 import android.content.ComponentName; 24 import android.content.Intent; 25 import android.content.pm.ActivityInfo; 26 import android.content.res.Configuration; 27 import android.os.Parcel; 28 import android.os.RemoteException; 29 import android.util.Log; 30 import android.window.WindowContainerToken; 31 32 /** 33 * Stores information about a particular Task. 34 */ 35 public class TaskInfo { 36 private static final String TAG = "TaskInfo"; 37 38 /** 39 * The id of the user the task was running as. 40 * @hide 41 */ 42 @UnsupportedAppUsage 43 public int userId; 44 45 /** 46 * The id of the ActivityStack that currently contains this task. 47 * @hide 48 */ 49 @UnsupportedAppUsage 50 public int stackId; 51 52 /** 53 * The identifier for this task. 54 */ 55 public int taskId; 56 57 /** 58 * Whether or not this task has any running activities. 59 */ 60 public boolean isRunning; 61 62 /** 63 * The base intent of the task (generally the intent that launched the task). This intent can 64 * be used to relaunch the task (if it is no longer running) or brought to the front if it is. 65 */ 66 @NonNull 67 public Intent baseIntent; 68 69 /** 70 * The component of the first activity in the task, can be considered the "application" of this 71 * task. 72 */ 73 @Nullable 74 public ComponentName baseActivity; 75 76 /** 77 * The component of the top activity in the task, currently showing to the user. 78 */ 79 @Nullable 80 public ComponentName topActivity; 81 82 /** 83 * The component of the target activity if this task was started from an activity alias. 84 * Otherwise, this is null. 85 */ 86 @Nullable 87 public ComponentName origActivity; 88 89 /** 90 * The component of the activity that started this task (may be the component of the activity 91 * alias). 92 * @hide 93 */ 94 @Nullable 95 public ComponentName realActivity; 96 97 /** 98 * The number of activities in this task (including running). 99 */ 100 public int numActivities; 101 102 /** 103 * The last time this task was active since boot (including time spent in sleep). 104 * @hide 105 */ 106 @UnsupportedAppUsage 107 public long lastActiveTime; 108 109 /** 110 * The id of the display this task is associated with. 111 * @hide 112 */ 113 public int displayId; 114 115 /** 116 * The recent activity values for the highest activity in the stack to have set the values. 117 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}. 118 */ 119 @Nullable 120 public ActivityManager.TaskDescription taskDescription; 121 122 /** 123 * True if the task can go in the split-screen primary stack. 124 * @hide 125 */ 126 @UnsupportedAppUsage 127 public boolean supportsSplitScreenMultiWindow; 128 129 /** 130 * The resize mode of the task. See {@link ActivityInfo#resizeMode}. 131 * @hide 132 */ 133 @UnsupportedAppUsage 134 public int resizeMode; 135 136 /** 137 * The current configuration of the task. 138 * @hide 139 */ 140 @NonNull 141 @UnsupportedAppUsage 142 public final Configuration configuration = new Configuration(); 143 144 /** 145 * Used as an opaque identifier for this task. 146 * @hide 147 */ 148 @NonNull 149 public WindowContainerToken token; 150 151 /** 152 * The PictureInPictureParams for the Task, if set. 153 * @hide 154 */ 155 @Nullable 156 public PictureInPictureParams pictureInPictureParams; 157 158 /** 159 * The activity type of the top activity in this task. 160 * @hide 161 */ 162 public @WindowConfiguration.ActivityType int topActivityType; 163 164 /** 165 * The {@link ActivityInfo} of the top activity in this task. 166 * @hide 167 */ 168 @Nullable 169 public ActivityInfo topActivityInfo; 170 171 /** 172 * Whether this task is resizable. Unlike {@link #resizeMode} (which is what the top activity 173 * supports), this is what the system actually uses for resizability based on other policy and 174 * developer options. 175 * @hide 176 */ 177 public boolean isResizeable; 178 179 /** 180 * Screen orientation set by {@link #baseActivity} via 181 * {@link Activity#setRequestedOrientation(int)}. 182 * @hide 183 */ 184 public @ActivityInfo.ScreenOrientation int requestedOrientation; 185 TaskInfo()186 TaskInfo() { 187 // Do nothing 188 } 189 TaskInfo(Parcel source)190 private TaskInfo(Parcel source) { 191 readFromParcel(source); 192 } 193 194 /** 195 * @param isLowResolution 196 * @return 197 * @hide 198 */ getTaskSnapshot(boolean isLowResolution)199 public ActivityManager.TaskSnapshot getTaskSnapshot(boolean isLowResolution) { 200 try { 201 return ActivityManager.getService().getTaskSnapshot(taskId, isLowResolution); 202 } catch (RemoteException e) { 203 Log.e(TAG, "Failed to get task snapshot, taskId=" + taskId, e); 204 return null; 205 } 206 } 207 208 /** @hide */ 209 @NonNull 210 @TestApi getToken()211 public WindowContainerToken getToken() { 212 return token; 213 } 214 215 /** @hide */ 216 @NonNull 217 @TestApi getConfiguration()218 public Configuration getConfiguration() { 219 return configuration; 220 } 221 222 /** 223 * Reads the TaskInfo from a parcel. 224 */ readFromParcel(Parcel source)225 void readFromParcel(Parcel source) { 226 userId = source.readInt(); 227 stackId = source.readInt(); 228 taskId = source.readInt(); 229 displayId = source.readInt(); 230 isRunning = source.readBoolean(); 231 baseIntent = source.readInt() != 0 232 ? Intent.CREATOR.createFromParcel(source) 233 : null; 234 baseActivity = ComponentName.readFromParcel(source); 235 topActivity = ComponentName.readFromParcel(source); 236 origActivity = ComponentName.readFromParcel(source); 237 realActivity = ComponentName.readFromParcel(source); 238 239 numActivities = source.readInt(); 240 lastActiveTime = source.readLong(); 241 242 taskDescription = source.readInt() != 0 243 ? ActivityManager.TaskDescription.CREATOR.createFromParcel(source) 244 : null; 245 supportsSplitScreenMultiWindow = source.readBoolean(); 246 resizeMode = source.readInt(); 247 configuration.readFromParcel(source); 248 token = WindowContainerToken.CREATOR.createFromParcel(source); 249 topActivityType = source.readInt(); 250 pictureInPictureParams = source.readInt() != 0 251 ? PictureInPictureParams.CREATOR.createFromParcel(source) 252 : null; 253 topActivityInfo = source.readInt() != 0 254 ? ActivityInfo.CREATOR.createFromParcel(source) 255 : null; 256 isResizeable = source.readBoolean(); 257 requestedOrientation = source.readInt(); 258 } 259 260 /** 261 * Writes the TaskInfo to a parcel. 262 */ writeToParcel(Parcel dest, int flags)263 void writeToParcel(Parcel dest, int flags) { 264 dest.writeInt(userId); 265 dest.writeInt(stackId); 266 dest.writeInt(taskId); 267 dest.writeInt(displayId); 268 dest.writeBoolean(isRunning); 269 270 if (baseIntent != null) { 271 dest.writeInt(1); 272 baseIntent.writeToParcel(dest, 0); 273 } else { 274 dest.writeInt(0); 275 } 276 ComponentName.writeToParcel(baseActivity, dest); 277 ComponentName.writeToParcel(topActivity, dest); 278 ComponentName.writeToParcel(origActivity, dest); 279 ComponentName.writeToParcel(realActivity, dest); 280 281 dest.writeInt(numActivities); 282 dest.writeLong(lastActiveTime); 283 284 if (taskDescription != null) { 285 dest.writeInt(1); 286 taskDescription.writeToParcel(dest, flags); 287 } else { 288 dest.writeInt(0); 289 } 290 dest.writeBoolean(supportsSplitScreenMultiWindow); 291 dest.writeInt(resizeMode); 292 configuration.writeToParcel(dest, flags); 293 token.writeToParcel(dest, flags); 294 dest.writeInt(topActivityType); 295 if (pictureInPictureParams == null) { 296 dest.writeInt(0); 297 } else { 298 dest.writeInt(1); 299 pictureInPictureParams.writeToParcel(dest, flags); 300 } 301 if (topActivityInfo == null) { 302 dest.writeInt(0); 303 } else { 304 dest.writeInt(1); 305 topActivityInfo.writeToParcel(dest, flags); 306 } 307 dest.writeBoolean(isResizeable); 308 dest.writeInt(requestedOrientation); 309 } 310 311 @Override toString()312 public String toString() { 313 return "TaskInfo{userId=" + userId + " stackId=" + stackId + " taskId=" + taskId 314 + " displayId=" + displayId 315 + " isRunning=" + isRunning 316 + " baseIntent=" + baseIntent + " baseActivity=" + baseActivity 317 + " topActivity=" + topActivity + " origActivity=" + origActivity 318 + " realActivity=" + realActivity 319 + " numActivities=" + numActivities 320 + " lastActiveTime=" + lastActiveTime 321 + " supportsSplitScreenMultiWindow=" + supportsSplitScreenMultiWindow 322 + " resizeMode=" + resizeMode 323 + " isResizeable=" + isResizeable 324 + " token=" + token 325 + " topActivityType=" + topActivityType 326 + " pictureInPictureParams=" + pictureInPictureParams 327 + " topActivityInfo=" + topActivityInfo 328 + " requestedOrientation=" + requestedOrientation; 329 } 330 } 331