blob: baaa55d348418a93f4075b7a6e4d90ab3adc8678 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
17package android.app;
18
Svet Ganov019d2302015-05-04 11:07:38 -070019import android.Manifest;
Michal Karpinski3da5c972015-12-11 18:16:30 +000020import android.annotation.IntDef;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -070021import android.annotation.NonNull;
22import android.annotation.Nullable;
Svet Ganov019d2302015-05-04 11:07:38 -070023import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070024import android.annotation.SystemApi;
Winson21700932016-03-24 17:26:23 -070025import android.content.res.Configuration;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -070026import android.graphics.Canvas;
27import android.graphics.Matrix;
28import android.graphics.Point;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070029import android.os.BatteryStats;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070030import android.os.IBinder;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070031import android.os.ParcelFileDescriptor;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070032
Svet Ganov019d2302015-05-04 11:07:38 -070033import android.util.Log;
Joe Onorato4eb64fd2016-03-21 15:30:09 -070034import com.android.internal.app.procstats.ProcessStats;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070035import com.android.internal.os.TransferPipe;
Dianne Hackborn8c841092013-06-24 13:46:13 -070036import com.android.internal.util.FastPrintWriter;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070037
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.content.ComponentName;
39import android.content.Context;
40import android.content.Intent;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080041import android.content.UriPermission;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070042import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.content.pm.ConfigurationInfo;
44import android.content.pm.IPackageDataObserver;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070045import android.content.pm.PackageManager;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080046import android.content.pm.ParceledListSlice;
Dianne Hackborn41203752012-08-31 14:05:51 -070047import android.content.pm.UserInfo;
Kenny Root5ef44b72011-01-26 17:22:20 -080048import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.graphics.Bitmap;
Winson Chunga449dc02014-05-16 11:15:04 -070050import android.graphics.Color;
Craig Mautner967212c2013-04-13 21:10:58 -070051import android.graphics.Rect;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070052import android.os.Bundle;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070053import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.Handler;
55import android.os.Parcel;
56import android.os.Parcelable;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070057import android.os.Process;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070058import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000059import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070060import android.os.SystemProperties;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070061import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.text.TextUtils;
Kenny Root5ef44b72011-01-26 17:22:20 -080063import android.util.DisplayMetrics;
Winson Chung48a10a52014-08-27 14:36:51 -070064import android.util.Size;
Dianne Hackbornb3756322011-08-12 13:58:13 -070065import android.util.Slog;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080066
Craig Mautner648f69b2014-09-18 14:16:26 -070067import org.xmlpull.v1.XmlSerializer;
Kenny Root5ef44b72011-01-26 17:22:20 -080068
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070069import java.io.FileDescriptor;
70import java.io.FileOutputStream;
Craig Mautner648f69b2014-09-18 14:16:26 -070071import java.io.IOException;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070072import java.io.PrintWriter;
Michal Karpinski3da5c972015-12-11 18:16:30 +000073import java.lang.annotation.Retention;
74import java.lang.annotation.RetentionPolicy;
Winson Chung1147c402014-05-14 11:05:00 -070075import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import java.util.List;
77
78/**
79 * Interact with the overall activities running in the system.
80 */
81public class ActivityManager {
82 private static String TAG = "ActivityManager";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
Dianne Hackborn852975d2014-08-22 17:42:43 -070084 private static int gMaxRecentTasks = -1;
85
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 private final Context mContext;
87 private final Handler mHandler;
88
Felipe Lemedc7af962016-01-22 18:27:03 -080089 /**
90 * Defines acceptable types of bugreports.
91 * @hide
92 */
Michal Karpinski3da5c972015-12-11 18:16:30 +000093 @Retention(RetentionPolicy.SOURCE)
94 @IntDef({
95 BUGREPORT_OPTION_FULL,
96 BUGREPORT_OPTION_INTERACTIVE,
97 BUGREPORT_OPTION_REMOTE
98 })
Michal Karpinski3da5c972015-12-11 18:16:30 +000099 public @interface BugreportMode {}
100 /**
101 * Takes a bugreport without user interference (and hence causing less
102 * interference to the system), but includes all sections.
103 * @hide
104 */
105 public static final int BUGREPORT_OPTION_FULL = 0;
106 /**
107 * Allows user to monitor progress and enter additional data; might not include all
108 * sections.
109 * @hide
110 */
111 public static final int BUGREPORT_OPTION_INTERACTIVE = 1;
112 /**
113 * Takes a bugreport requested remotely by administrator of the Device Owner app,
114 * not the device's user.
115 * @hide
116 */
117 public static final int BUGREPORT_OPTION_REMOTE = 2;
118
Dianne Hackborna4972e92012-03-14 10:38:05 -0700119 /**
Scott Maincc2195b2013-10-16 13:57:46 -0700120 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000121 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
Christopher Tatebd413f62013-09-18 18:31:59 -0700122 * uninstalled in lieu of the declaring one. The package named here must be
Neil Fuller71fbb812015-11-30 09:51:33 +0000123 * signed with the same certificate as the one declaring the {@code <meta-data>}.
Christopher Tatebd413f62013-09-18 18:31:59 -0700124 */
125 public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
126
127 /**
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700128 * Result for IActivityManager.startActivity: trying to start a background user
129 * activity that shouldn't be displayed for all users.
130 * @hide
131 */
132 public static final int START_NOT_CURRENT_USER_ACTIVITY = -8;
133
134 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700135 * Result for IActivityManager.startActivity: trying to start an activity under voice
136 * control when that activity does not support the VOICE category.
137 * @hide
138 */
139 public static final int START_NOT_VOICE_COMPATIBLE = -7;
140
141 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700142 * Result for IActivityManager.startActivity: an error where the
143 * start had to be canceled.
144 * @hide
145 */
146 public static final int START_CANCELED = -6;
147
148 /**
149 * Result for IActivityManager.startActivity: an error where the
150 * thing being started is not an activity.
151 * @hide
152 */
153 public static final int START_NOT_ACTIVITY = -5;
154
155 /**
156 * Result for IActivityManager.startActivity: an error where the
157 * caller does not have permission to start the activity.
158 * @hide
159 */
160 public static final int START_PERMISSION_DENIED = -4;
161
162 /**
163 * Result for IActivityManager.startActivity: an error where the
164 * caller has requested both to forward a result and to receive
165 * a result.
166 * @hide
167 */
168 public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3;
169
170 /**
171 * Result for IActivityManager.startActivity: an error where the
172 * requested class is not found.
173 * @hide
174 */
175 public static final int START_CLASS_NOT_FOUND = -2;
176
177 /**
178 * Result for IActivityManager.startActivity: an error where the
179 * given Intent could not be resolved to an activity.
180 * @hide
181 */
182 public static final int START_INTENT_NOT_RESOLVED = -1;
183
184 /**
185 * Result for IActivityManaqer.startActivity: the activity was started
186 * successfully as normal.
187 * @hide
188 */
189 public static final int START_SUCCESS = 0;
190
191 /**
192 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not
193 * be executed if it is the recipient, and that is indeed the case.
194 * @hide
195 */
196 public static final int START_RETURN_INTENT_TO_CALLER = 1;
197
198 /**
199 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
200 * a task was simply brought to the foreground.
201 * @hide
202 */
203 public static final int START_TASK_TO_FRONT = 2;
204
205 /**
206 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
207 * the given Intent was given to the existing top activity.
208 * @hide
209 */
210 public static final int START_DELIVERED_TO_TOP = 3;
211
212 /**
213 * Result for IActivityManaqer.startActivity: request was canceled because
214 * app switches are temporarily canceled to ensure the user's last request
215 * (such as pressing home) is performed.
216 * @hide
217 */
218 public static final int START_SWITCHES_CANCELED = 4;
219
220 /**
Craig Mautneraea74a52014-03-08 14:23:10 -0800221 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started
222 * while in Lock Task Mode.
223 * @hide
224 */
225 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION = 5;
226
227 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700228 * Flag for IActivityManaqer.startActivity: do special start mode where
229 * a new activity is launched only if it is needed.
230 * @hide
231 */
232 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
233
234 /**
235 * Flag for IActivityManaqer.startActivity: launch the app for
236 * debugging.
237 * @hide
238 */
239 public static final int START_FLAG_DEBUG = 1<<1;
240
241 /**
242 * Flag for IActivityManaqer.startActivity: launch the app for
Man Caocfa78b22015-06-11 20:14:34 -0700243 * allocation tracking.
244 * @hide
245 */
Pablo Ceballosa4d4e822015-10-05 10:27:52 -0700246 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2;
Man Caocfa78b22015-06-11 20:14:34 -0700247
248 /**
Tamas Berghammerdf6cb282016-01-29 12:07:00 +0000249 * Flag for IActivityManaqer.startActivity: launch the app with
250 * native debugging support.
251 * @hide
252 */
253 public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3;
254
255 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700256 * Result for IActivityManaqer.broadcastIntent: success!
257 * @hide
258 */
259 public static final int BROADCAST_SUCCESS = 0;
260
261 /**
262 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast
263 * a sticky intent without appropriate permission.
264 * @hide
265 */
266 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
267
268 /**
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800269 * Result for IActivityManager.broadcastIntent: trying to send a broadcast
270 * to a stopped user. Fail.
271 * @hide
272 */
273 public static final int BROADCAST_FAILED_USER_STOPPED = -2;
274
275 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700276 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
277 * for a sendBroadcast operation.
278 * @hide
279 */
280 public static final int INTENT_SENDER_BROADCAST = 1;
281
282 /**
283 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
284 * for a startActivity operation.
285 * @hide
286 */
287 public static final int INTENT_SENDER_ACTIVITY = 2;
288
289 /**
290 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
291 * for an activity result operation.
292 * @hide
293 */
294 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
295
296 /**
297 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
298 * for a startService operation.
299 * @hide
300 */
301 public static final int INTENT_SENDER_SERVICE = 4;
302
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700303 /** @hide User operation call: success! */
304 public static final int USER_OP_SUCCESS = 0;
305
306 /** @hide User operation call: given user id is not known. */
307 public static final int USER_OP_UNKNOWN_USER = -1;
308
309 /** @hide User operation call: given user id is the current user, can't be stopped. */
310 public static final int USER_OP_IS_CURRENT = -2;
311
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700312 /** @hide User operation call: system user can't be stopped. */
313 public static final int USER_OP_ERROR_IS_SYSTEM = -3;
314
315 /** @hide User operation call: one of related users cannot be stopped. */
316 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4;
317
Ruben Brunka27eef42015-01-28 15:04:16 -0800318 /** @hide Process does not exist. */
319 public static final int PROCESS_STATE_NONEXISTENT = -1;
320
Dianne Hackborna413dc02013-07-12 12:02:55 -0700321 /** @hide Process is a persistent system process. */
322 public static final int PROCESS_STATE_PERSISTENT = 0;
323
324 /** @hide Process is a persistent system process and is doing UI. */
325 public static final int PROCESS_STATE_PERSISTENT_UI = 1;
326
Dianne Hackbornc8230512013-07-13 21:32:12 -0700327 /** @hide Process is hosting the current top activities. Note that this covers
328 * all activities that are visible to the user. */
Dianne Hackborna413dc02013-07-12 12:02:55 -0700329 public static final int PROCESS_STATE_TOP = 2;
330
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700331 /** @hide Process is hosting a foreground service due to a system binding. */
332 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 3;
333
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700334 /** @hide Process is hosting a foreground service. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700335 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700336
337 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700338 public static final int PROCESS_STATE_TOP_SLEEPING = 5;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700339
Dianne Hackborna413dc02013-07-12 12:02:55 -0700340 /** @hide Process is important to the user, and something they are aware of. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700341 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700342
343 /** @hide Process is important to the user, but not something they are aware of. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700344 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700345
Dianne Hackborna413dc02013-07-12 12:02:55 -0700346 /** @hide Process is in the background running a backup/restore operation. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700347 public static final int PROCESS_STATE_BACKUP = 8;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700348
Dianne Hackbornc8230512013-07-13 21:32:12 -0700349 /** @hide Process is in the background, but it can't restore its state so we want
350 * to try to avoid killing it. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700351 public static final int PROCESS_STATE_HEAVY_WEIGHT = 9;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700352
353 /** @hide Process is in the background running a service. Unlike oom_adj, this level
354 * is used for both the normal running in background state and the executing
355 * operations state. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700356 public static final int PROCESS_STATE_SERVICE = 10;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700357
Dianne Hackbornc8230512013-07-13 21:32:12 -0700358 /** @hide Process is in the background running a receiver. Note that from the
359 * perspective of oom_adj receivers run at a higher foreground level, but for our
360 * prioritization here that is not necessary and putting them below services means
361 * many fewer changes in some process states as they receive broadcasts. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700362 public static final int PROCESS_STATE_RECEIVER = 11;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700363
Dianne Hackborna413dc02013-07-12 12:02:55 -0700364 /** @hide Process is in the background but hosts the home activity. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700365 public static final int PROCESS_STATE_HOME = 12;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700366
367 /** @hide Process is in the background but hosts the last shown activity. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700368 public static final int PROCESS_STATE_LAST_ACTIVITY = 13;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700369
Dianne Hackbornc8230512013-07-13 21:32:12 -0700370 /** @hide Process is being cached for later use and contains activities. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700371 public static final int PROCESS_STATE_CACHED_ACTIVITY = 14;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700372
373 /** @hide Process is being cached for later use and is a client of another cached
374 * process that contains activities. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700375 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 15;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700376
377 /** @hide Process is being cached for later use and is empty. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700378 public static final int PROCESS_STATE_CACHED_EMPTY = 16;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700379
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700380 /** @hide Should this process state be considered a background state? */
381 public static final boolean isProcStateBackground(int procState) {
382 return procState >= PROCESS_STATE_BACKUP;
383 }
384
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700385 /** @hide requestType for assist context: only basic information. */
386 public static final int ASSIST_CONTEXT_BASIC = 0;
387
388 /** @hide requestType for assist context: generate full AssistStructure. */
389 public static final int ASSIST_CONTEXT_FULL = 1;
390
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700391 /** @hide Flag for registerUidObserver: report changes in process state. */
392 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
393
394 /** @hide Flag for registerUidObserver: report uid gone. */
395 public static final int UID_OBSERVER_GONE = 1<<1;
396
397 /** @hide Flag for registerUidObserver: report uid has become idle. */
398 public static final int UID_OBSERVER_IDLE = 1<<2;
399
400 /** @hide Flag for registerUidObserver: report uid has become active. */
401 public static final int UID_OBSERVER_ACTIVE = 1<<3;
402
403 /** @hide Mode for {@link IActivityManager#getAppStartMode}: normal free-to-run operation. */
404 public static final int APP_START_MODE_NORMAL = 0;
405
406 /** @hide Mode for {@link IActivityManager#getAppStartMode}: delay running until later. */
407 public static final int APP_START_MODE_DELAYED = 1;
408
409 /** @hide Mode for {@link IActivityManager#getAppStartMode}: disable/cancel pending
410 * launches. */
411 public static final int APP_START_MODE_DISABLED = 2;
412
Benjamin Franz43261142015-02-11 15:59:44 +0000413 /**
414 * Lock task mode is not active.
415 */
416 public static final int LOCK_TASK_MODE_NONE = 0;
417
418 /**
419 * Full lock task mode is active.
420 */
421 public static final int LOCK_TASK_MODE_LOCKED = 1;
422
423 /**
424 * App pinning mode is active.
425 */
426 public static final int LOCK_TASK_MODE_PINNED = 2;
427
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700428 Point mAppTaskThumbnailSize;
429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 /*package*/ ActivityManager(Context context, Handler handler) {
431 mContext = context;
432 mHandler = handler;
433 }
434
435 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700436 * Screen compatibility mode: the application most always run in
437 * compatibility mode.
438 * @hide
439 */
440 public static final int COMPAT_MODE_ALWAYS = -1;
441
442 /**
443 * Screen compatibility mode: the application can never run in
444 * compatibility mode.
445 * @hide
446 */
447 public static final int COMPAT_MODE_NEVER = -2;
448
449 /**
450 * Screen compatibility mode: unknown.
451 * @hide
452 */
453 public static final int COMPAT_MODE_UNKNOWN = -3;
454
455 /**
456 * Screen compatibility mode: the application currently has compatibility
457 * mode disabled.
458 * @hide
459 */
460 public static final int COMPAT_MODE_DISABLED = 0;
461
462 /**
463 * Screen compatibility mode: the application currently has compatibility
464 * mode enabled.
465 * @hide
466 */
467 public static final int COMPAT_MODE_ENABLED = 1;
468
469 /**
470 * Screen compatibility mode: request to toggle the application's
471 * compatibility mode.
472 * @hide
473 */
474 public static final int COMPAT_MODE_TOGGLE = 2;
475
Wale Ogunwale3797c222015-10-27 14:21:58 -0700476 /** @hide */
477 public static class StackId {
478 /** Invalid stack ID. */
479 public static final int INVALID_STACK_ID = -1;
Chong Zhang5dcb2752015-08-18 13:50:26 -0700480
Wale Ogunwale3797c222015-10-27 14:21:58 -0700481 /** First static stack ID. */
482 public static final int FIRST_STATIC_STACK_ID = 0;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700483
Wale Ogunwale3797c222015-10-27 14:21:58 -0700484 /** Home activity stack ID. */
485 public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700486
Wale Ogunwale3797c222015-10-27 14:21:58 -0700487 /** ID of stack where fullscreen activities are normally launched into. */
488 public static final int FULLSCREEN_WORKSPACE_STACK_ID = 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700489
Wale Ogunwale3797c222015-10-27 14:21:58 -0700490 /** ID of stack where freeform/resized activities are normally launched into. */
491 public static final int FREEFORM_WORKSPACE_STACK_ID = FULLSCREEN_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700492
Wale Ogunwale3797c222015-10-27 14:21:58 -0700493 /** ID of stack that occupies a dedicated region of the screen. */
494 public static final int DOCKED_STACK_ID = FREEFORM_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700495
Wale Ogunwale3797c222015-10-27 14:21:58 -0700496 /** ID of stack that always on top (always visible) when it exist. */
497 public static final int PINNED_STACK_ID = DOCKED_STACK_ID + 1;
Wale Ogunwale99db1862015-10-23 20:08:22 -0700498
Wale Ogunwale3797c222015-10-27 14:21:58 -0700499 /** Last static stack stack ID. */
500 public static final int LAST_STATIC_STACK_ID = PINNED_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700501
Wale Ogunwale3797c222015-10-27 14:21:58 -0700502 /** Start of ID range used by stacks that are created dynamically. */
503 public static final int FIRST_DYNAMIC_STACK_ID = LAST_STATIC_STACK_ID + 1;
504
505 public static boolean isStaticStack(int stackId) {
506 return stackId >= FIRST_STATIC_STACK_ID && stackId <= LAST_STATIC_STACK_ID;
507 }
508
509 /**
510 * Returns true if the activities contained in the input stack display a shadow around
511 * their border.
512 */
513 public static boolean hasWindowShadow(int stackId) {
514 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID;
515 }
516
517 /**
518 * Returns true if the activities contained in the input stack display a decor view.
519 */
520 public static boolean hasWindowDecor(int stackId) {
521 return stackId == FREEFORM_WORKSPACE_STACK_ID;
522 }
523
524 /**
525 * Returns true if the tasks contained in the stack can be resized independently of the
526 * stack.
527 */
528 public static boolean isTaskResizeAllowed(int stackId) {
529 return stackId == FREEFORM_WORKSPACE_STACK_ID;
530 }
531
Wale Ogunwale807d8822015-12-15 17:05:09 -0800532 /** Returns true if the task bounds should persist across power cycles. */
Wale Ogunwale3797c222015-10-27 14:21:58 -0700533 public static boolean persistTaskBounds(int stackId) {
Wale Ogunwale807d8822015-12-15 17:05:09 -0800534 return stackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700535 }
536
537 /**
538 * Returns true if dynamic stacks are allowed to be visible behind the input stack.
539 */
540 public static boolean isDynamicStacksVisibleBehindAllowed(int stackId) {
541 return stackId == PINNED_STACK_ID;
542 }
543
544 /**
545 * Returns true if we try to maintain focus in the current stack when the top activity
546 * finishes.
547 */
548 public static boolean keepFocusInStackIfPossible(int stackId) {
549 return stackId == FREEFORM_WORKSPACE_STACK_ID
550 || stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID;
551 }
552
553 /**
554 * Returns true if Stack size is affected by the docked stack changing size.
555 */
556 public static boolean isResizeableByDockedStack(int stackId) {
557 return isStaticStack(stackId) &&
558 stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID;
559 }
560
561 /**
562 * Returns true if the size of tasks in the input stack are affected by the docked stack
563 * changing size.
564 */
565 public static boolean isTaskResizeableByDockedStack(int stackId) {
566 return isStaticStack(stackId) && stackId != FREEFORM_WORKSPACE_STACK_ID
567 && stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID;
568 }
569
570 /**
Jorim Jaggie9098022016-01-27 19:29:40 -0800571 * Returns true if the windows of tasks being moved to the target stack from the source
572 * stack should be replaced, meaning that window manager will keep the old window around
573 * until the new is ready.
Wale Ogunwale3797c222015-10-27 14:21:58 -0700574 */
Jorim Jaggie9098022016-01-27 19:29:40 -0800575 public static boolean replaceWindowsOnTaskMove(int sourceStackId, int targetStackId) {
576 return sourceStackId == FREEFORM_WORKSPACE_STACK_ID
577 || targetStackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700578 }
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800579
580 /**
Robert Carre6275582016-02-29 15:45:45 -0800581 * Return whether a stackId is a stack containing floating windows. Floating windows
582 * are laid out differently as they are allowed to extend past the display bounds
583 * without overscan insets.
584 */
585 public static boolean tasksAreFloating(int stackId) {
586 return stackId == FREEFORM_WORKSPACE_STACK_ID
587 || stackId == PINNED_STACK_ID;
588 }
589
590 /**
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800591 * Returns true if animation specs should be constructed for app transition that moves
592 * the task to the specified stack.
593 */
594 public static boolean useAnimationSpecForAppTransition(int stackId) {
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800595
596 // TODO: INVALID_STACK_ID is also animated because we don't persist stack id's across
597 // reboots.
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800598 return stackId == FREEFORM_WORKSPACE_STACK_ID
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800599 || stackId == FULLSCREEN_WORKSPACE_STACK_ID || stackId == DOCKED_STACK_ID
600 || stackId == INVALID_STACK_ID;
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800601 }
Wale Ogunwaled045c822015-12-02 09:14:28 -0800602
603 /** Returns true if the windows in the stack can receive input keys. */
604 public static boolean canReceiveKeys(int stackId) {
605 return stackId != PINNED_STACK_ID;
606 }
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800607
Chong Zhang75b37202015-12-04 14:16:36 -0800608 /**
609 * Returns true if the stack can be visible above lockscreen.
610 */
611 public static boolean isAllowedOverLockscreen(int stackId) {
612 return stackId == HOME_STACK_ID || stackId == FULLSCREEN_WORKSPACE_STACK_ID;
613 }
614
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800615 public static boolean isAlwaysOnTop(int stackId) {
616 return stackId == PINNED_STACK_ID;
617 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800618
619 /**
620 * Returns true if the top task in the task is allowed to return home when finished and
621 * there are other tasks in the stack.
622 */
623 public static boolean allowTopTaskToReturnHome(int stackId) {
624 return stackId != PINNED_STACK_ID;
625 }
Wale Ogunwalecacfaa22016-01-15 11:26:08 -0800626
627 /**
628 * Returns true if the stack should be resized to match the bounds specified by
629 * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack.
630 */
631 public static boolean resizeStackWithLaunchBounds(int stackId) {
632 return stackId == PINNED_STACK_ID;
633 }
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -0800634
635 /**
636 * Returns true if any visible windows belonging to apps in this stack should be kept on
637 * screen when the app is killed due to something like the low memory killer.
638 */
639 public static boolean keepVisibleDeadAppWindowOnScreen(int stackId) {
640 return stackId != PINNED_STACK_ID;
641 }
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800642
643 /**
644 * Returns true if the backdrop on the client side should match the frame of the window.
645 * Returns false, if the backdrop should be fullscreen.
646 */
647 public static boolean useWindowFrameForBackdrop(int stackId) {
648 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID;
649 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800650
651 /**
652 * Returns true if a window from the specified stack with {@param stackId} are normally
653 * fullscreen, i. e. they can become the top opaque fullscreen window, meaning that it
654 * controls system bars, lockscreen occluded/dismissing state, screen rotation animation,
655 * etc.
656 */
657 public static boolean normallyFullscreenWindows(int stackId) {
658 return stackId != PINNED_STACK_ID && stackId != FREEFORM_WORKSPACE_STACK_ID
659 && stackId != DOCKED_STACK_ID;
660 }
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800661
662 /**
663 * Returns true if the input stack id should only be present on a device that supports
664 * multi-window mode.
665 * @see android.app.ActivityManager#supportsMultiWindow
666 */
667 public static boolean isMultiWindowStack(int stackId) {
668 return isStaticStack(stackId) || stackId == PINNED_STACK_ID
669 || stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == DOCKED_STACK_ID;
670 }
Wale Ogunwale3797c222015-10-27 14:21:58 -0700671 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700672
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700673 /**
674 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
675 * specifies the position of the created docked stack at the top half of the screen if
676 * in portrait mode or at the left half of the screen if in landscape mode.
677 * @hide
678 */
679 public static final int DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT = 0;
680
681 /**
682 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
683 * specifies the position of the created docked stack at the bottom half of the screen if
684 * in portrait mode or at the right half of the screen if in landscape mode.
685 * @hide
686 */
687 public static final int DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT = 1;
688
Chong Zhang87b21722015-09-21 15:39:51 -0700689 /**
690 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700691 * that the resize doesn't need to preserve the window, and can be skipped if bounds
692 * is unchanged. This mode is used by window manager in most cases.
Chong Zhang87b21722015-09-21 15:39:51 -0700693 * @hide
694 */
695 public static final int RESIZE_MODE_SYSTEM = 0;
696
697 /**
698 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700699 * that the resize should preserve the window if possible.
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700700 * @hide
701 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700702 public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0);
Chong Zhang87b21722015-09-21 15:39:51 -0700703
704 /**
705 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
706 * that the resize should be performed even if the bounds appears unchanged.
707 * @hide
708 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700709 public static final int RESIZE_MODE_FORCED = (0x1 << 1);
710
711 /**
712 * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window
713 * manager during a screen rotation.
714 * @hide
715 */
716 public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW;
717
718 /**
719 * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the
720 * resize is due to a drag action.
721 * @hide
722 */
723 public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW;
724
725 /**
726 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
727 * that the resize should preserve the window if possible, and should not be skipped
728 * even if the bounds is unchanged. Usually used to force a resizing when a drag action
729 * is ending.
730 * @hide
731 */
732 public static final int RESIZE_MODE_USER_FORCED =
733 RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED;
Chong Zhang87b21722015-09-21 15:39:51 -0700734
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700735 /** @hide */
736 public int getFrontActivityScreenCompatMode() {
737 try {
738 return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode();
739 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700740 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700741 }
742 }
743
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700744 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700745 public void setFrontActivityScreenCompatMode(int mode) {
746 try {
747 ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode);
748 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700749 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700750 }
751 }
752
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700753 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700754 public int getPackageScreenCompatMode(String packageName) {
755 try {
756 return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName);
757 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700758 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700759 }
760 }
761
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700762 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700763 public void setPackageScreenCompatMode(String packageName, int mode) {
764 try {
765 ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode);
766 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700767 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700768 }
769 }
770
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700771 /** @hide */
772 public boolean getPackageAskScreenCompat(String packageName) {
773 try {
774 return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName);
775 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700776 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700777 }
778 }
779
780 /** @hide */
781 public void setPackageAskScreenCompat(String packageName, boolean ask) {
782 try {
783 ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask);
784 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700785 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700786 }
787 }
788
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700789 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700790 * Return the approximate per-application memory class of the current
791 * device. This gives you an idea of how hard a memory limit you should
792 * impose on your application to let the overall system work best. The
793 * returned value is in megabytes; the baseline Android memory class is
794 * 16 (which happens to be the Java heap limit of those devices); some
795 * device with more memory may return 24 or even higher numbers.
796 */
797 public int getMemoryClass() {
798 return staticGetMemoryClass();
799 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700800
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700801 /** @hide */
802 static public int staticGetMemoryClass() {
803 // Really brain dead right now -- just take this from the configured
804 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -0800805 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -0800806 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
807 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
808 }
809 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800810 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700811
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800812 /**
813 * Return the approximate per-application memory class of the current
814 * device when an application is running with a large heap. This is the
815 * space available for memory-intensive applications; most applications
816 * should not need this amount of memory, and should instead stay with the
817 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
818 * This may be the same size as {@link #getMemoryClass()} on memory
819 * constrained devices, or it may be significantly larger on devices with
820 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800821 *
822 * <p>The is the size of the application's Dalvik heap if it has
823 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800824 */
825 public int getLargeMemoryClass() {
826 return staticGetLargeMemoryClass();
827 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700828
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800829 /** @hide */
830 static public int staticGetLargeMemoryClass() {
831 // Really brain dead right now -- just take this from the configured
832 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700833 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -0700834 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700835 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700836
837 /**
838 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
839 * is ultimately up to the device configuration, but currently it generally means
840 * something in the class of a 512MB device with about a 800x480 or less screen.
841 * This is mostly intended to be used by apps to determine whether they should turn
842 * off certain features that require more RAM.
843 */
844 public boolean isLowRamDevice() {
845 return isLowRamDeviceStatic();
846 }
847
848 /** @hide */
849 public static boolean isLowRamDeviceStatic() {
Christopher Tate2f61f912013-08-20 13:55:50 -0700850 return "true".equals(SystemProperties.get("ro.config.low_ram", "false"));
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700851 }
852
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700853 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -0700854 * Used by persistent processes to determine if they are running on a
855 * higher-end device so should be okay using hardware drawing acceleration
856 * (which tends to consume a lot more RAM).
857 * @hide
858 */
Jeff Brown98365d72012-08-19 20:30:52 -0700859 static public boolean isHighEndGfx() {
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700860 return !isLowRamDeviceStatic() &&
861 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -0700862 }
863
864 /**
Dianne Hackborn852975d2014-08-22 17:42:43 -0700865 * Return the maximum number of recents entries that we will maintain and show.
866 * @hide
867 */
868 static public int getMaxRecentTasksStatic() {
869 if (gMaxRecentTasks < 0) {
870 return gMaxRecentTasks = isLowRamDeviceStatic() ? 50 : 100;
871 }
872 return gMaxRecentTasks;
873 }
874
875 /**
876 * Return the default limit on the number of recents that an app can make.
877 * @hide
878 */
879 static public int getDefaultAppRecentsLimitStatic() {
880 return getMaxRecentTasksStatic() / 6;
881 }
882
883 /**
884 * Return the maximum limit on the number of recents that an app can make.
885 * @hide
886 */
887 static public int getMaxAppRecentsLimitStatic() {
888 return getMaxRecentTasksStatic() / 2;
889 }
890
891 /**
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800892 * Returns true if the system supports at least one form of multi-window.
893 * E.g. freeform, split-screen, picture-in-picture.
894 * @hide
895 */
896 static public boolean supportsMultiWindow() {
897 return !isLowRamDeviceStatic()
898 && Resources.getSystem().getBoolean(
899 com.android.internal.R.bool.config_supportsMultiWindow);
900 }
901
902 /**
Winson Chung1147c402014-05-14 11:05:00 -0700903 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -0700904 */
Winson Chunga449dc02014-05-16 11:15:04 -0700905 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -0700906 /** @hide */
907 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
908 private static final String ATTR_TASKDESCRIPTIONLABEL =
909 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +0000910 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -0700911 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +0000912 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
913 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Craig Mautner648f69b2014-09-18 14:16:26 -0700914 private static final String ATTR_TASKDESCRIPTIONICONFILENAME =
915 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
916
Winson Chunga449dc02014-05-16 11:15:04 -0700917 private String mLabel;
918 private Bitmap mIcon;
Craig Mautner648f69b2014-09-18 14:16:26 -0700919 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -0700920 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +0000921 private int mColorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -0700922
923 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700924 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700925 *
Winson Chunga449dc02014-05-16 11:15:04 -0700926 * @param label A label and description of the current state of this task.
927 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +0000928 * @param colorPrimary A color to override the theme's primary color. This color must be
929 * opaque.
Winson Chung03a9bae2014-05-02 09:56:12 -0700930 */
Winson Chunga449dc02014-05-16 11:15:04 -0700931 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Winson Chung1af8eda2016-02-05 17:55:56 +0000932 this(label, icon, null, colorPrimary, 0);
Winson Chunga449dc02014-05-16 11:15:04 -0700933 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
934 throw new RuntimeException("A TaskDescription's primary color should be opaque");
935 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700936 }
937
Winson Chung03a9bae2014-05-02 09:56:12 -0700938 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700939 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700940 *
941 * @param label A label and description of the current state of this activity.
942 * @param icon An icon that represents the current state of this activity.
943 */
Winson Chunga449dc02014-05-16 11:15:04 -0700944 public TaskDescription(String label, Bitmap icon) {
Winson Chung1af8eda2016-02-05 17:55:56 +0000945 this(label, icon, null, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -0700946 }
947
948 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700949 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700950 *
951 * @param label A label and description of the current state of this activity.
952 */
Winson Chunga449dc02014-05-16 11:15:04 -0700953 public TaskDescription(String label) {
Winson Chung1af8eda2016-02-05 17:55:56 +0000954 this(label, null, null, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -0700955 }
956
Winson Chunga449dc02014-05-16 11:15:04 -0700957 /**
958 * Creates an empty TaskDescription.
959 */
960 public TaskDescription() {
Winson Chung1af8eda2016-02-05 17:55:56 +0000961 this(null, null, null, 0, 0);
962 }
963
964 /** @hide */
965 public TaskDescription(String label, Bitmap icon, String iconFilename, int colorPrimary,
966 int colorBackground) {
967 mLabel = label;
968 mIcon = icon;
969 mIconFilename = iconFilename;
970 mColorPrimary = colorPrimary;
971 mColorBackground = colorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -0700972 }
973
Winson Chunga449dc02014-05-16 11:15:04 -0700974 /**
975 * Creates a copy of another TaskDescription.
976 */
977 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -0800978 copyFrom(td);
979 }
980
981 /**
982 * Copies this the values from another TaskDescription.
983 * @hide
984 */
985 public void copyFrom(TaskDescription other) {
986 mLabel = other.mLabel;
987 mIcon = other.mIcon;
988 mIconFilename = other.mIconFilename;
989 mColorPrimary = other.mColorPrimary;
990 mColorBackground = other.mColorBackground;
Winson Chunga449dc02014-05-16 11:15:04 -0700991 }
992
993 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -0700994 readFromParcel(source);
995 }
996
997 /**
Winson Chung2cb86c72014-06-25 12:03:30 -0700998 * Sets the label for this task description.
999 * @hide
1000 */
1001 public void setLabel(String label) {
1002 mLabel = label;
1003 }
1004
1005 /**
1006 * Sets the primary color for this task description.
1007 * @hide
1008 */
1009 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001010 // Ensure that the given color is valid
1011 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1012 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1013 }
1014 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001015 }
1016
1017 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001018 * Sets the background color for this task description.
1019 * @hide
1020 */
1021 public void setBackgroundColor(int backgroundColor) {
1022 // Ensure that the given color is valid
1023 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1024 throw new RuntimeException("A TaskDescription's background color should be opaque");
1025 }
1026 mColorBackground = backgroundColor;
1027 }
1028
1029 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001030 * Sets the icon for this task description.
1031 * @hide
1032 */
1033 public void setIcon(Bitmap icon) {
1034 mIcon = icon;
1035 }
1036
1037 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001038 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1039 * bitmap.
1040 * @hide
1041 */
1042 public void setIconFilename(String iconFilename) {
1043 mIconFilename = iconFilename;
1044 mIcon = null;
1045 }
1046
1047 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001048 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001049 */
Winson Chunga449dc02014-05-16 11:15:04 -07001050 public String getLabel() {
1051 return mLabel;
1052 }
1053
1054 /**
1055 * @return The icon that represents the current state of this task.
1056 */
1057 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001058 if (mIcon != null) {
1059 return mIcon;
1060 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001061 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001062 }
1063
1064 /** @hide */
1065 public String getIconFilename() {
1066 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001067 }
1068
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001069 /** @hide */
1070 public Bitmap getInMemoryIcon() {
1071 return mIcon;
1072 }
1073
1074 /** @hide */
Suprabh Shukla23593142015-11-03 17:31:15 -08001075 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001076 if (iconFilename != null) {
1077 try {
Winson Chung1af8eda2016-02-05 17:55:56 +00001078 return ActivityManagerNative.getDefault().getTaskDescriptionIcon(iconFilename,
1079 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001080 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001081 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001082 }
1083 }
1084 return null;
1085 }
1086
Winson Chunga449dc02014-05-16 11:15:04 -07001087 /**
1088 * @return The color override on the theme's primary color.
1089 */
1090 public int getPrimaryColor() {
1091 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001092 }
1093
Winson Chung1af8eda2016-02-05 17:55:56 +00001094 /**
1095 * @return The background color.
1096 * @hide
1097 */
1098 public int getBackgroundColor() {
1099 return mColorBackground;
1100 }
1101
Craig Mautner648f69b2014-09-18 14:16:26 -07001102 /** @hide */
1103 public void saveToXml(XmlSerializer out) throws IOException {
1104 if (mLabel != null) {
1105 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1106 }
1107 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001108 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1109 Integer.toHexString(mColorPrimary));
1110 }
1111 if (mColorBackground != 0) {
1112 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1113 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001114 }
1115 if (mIconFilename != null) {
1116 out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename);
1117 }
1118 }
1119
1120 /** @hide */
1121 public void restoreFromXml(String attrName, String attrValue) {
1122 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1123 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001124 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001125 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001126 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1127 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Craig Mautner648f69b2014-09-18 14:16:26 -07001128 } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) {
1129 setIconFilename(attrValue);
1130 }
1131 }
1132
Winson Chung03a9bae2014-05-02 09:56:12 -07001133 @Override
1134 public int describeContents() {
1135 return 0;
1136 }
1137
1138 @Override
1139 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001140 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001141 dest.writeInt(0);
1142 } else {
1143 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001144 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001145 }
Winson Chunga449dc02014-05-16 11:15:04 -07001146 if (mIcon == null) {
1147 dest.writeInt(0);
1148 } else {
1149 dest.writeInt(1);
1150 mIcon.writeToParcel(dest, 0);
1151 }
1152 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001153 dest.writeInt(mColorBackground);
Craig Mautner648f69b2014-09-18 14:16:26 -07001154 if (mIconFilename == null) {
1155 dest.writeInt(0);
1156 } else {
1157 dest.writeInt(1);
1158 dest.writeString(mIconFilename);
1159 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001160 }
1161
1162 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001163 mLabel = source.readInt() > 0 ? source.readString() : null;
1164 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
1165 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001166 mColorBackground = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001167 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001168 }
1169
Winson Chunga449dc02014-05-16 11:15:04 -07001170 public static final Creator<TaskDescription> CREATOR
1171 = new Creator<TaskDescription>() {
1172 public TaskDescription createFromParcel(Parcel source) {
1173 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001174 }
Winson Chunga449dc02014-05-16 11:15:04 -07001175 public TaskDescription[] newArray(int size) {
1176 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001177 }
1178 };
1179
1180 @Override
1181 public String toString() {
Winson Chunga449dc02014-05-16 11:15:04 -07001182 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
Winson Chung1af8eda2016-02-05 17:55:56 +00001183 " IconFilename: " + mIconFilename + " colorPrimary: " + mColorPrimary +
1184 " colorBackground: " + mColorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -07001185 }
1186 }
1187
1188 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 * Information you can retrieve about tasks that the user has most recently
1190 * started or visited.
1191 */
1192 public static class RecentTaskInfo implements Parcelable {
1193 /**
1194 * If this task is currently running, this is the identifier for it.
1195 * If it is not running, this will be -1.
1196 */
1197 public int id;
1198
1199 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001200 * The true identifier of this task, valid even if it is not running.
1201 */
1202 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001203
Dianne Hackbornd94df452011-02-16 18:53:31 -08001204 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 * The original Intent used to launch the task. You can use this
1206 * Intent to re-launch the task (if it is no longer running) or bring
1207 * the current task to the front.
1208 */
1209 public Intent baseIntent;
1210
1211 /**
1212 * If this task was started from an alias, this is the actual
1213 * activity component that was initially started; the component of
1214 * the baseIntent in this case is the name of the actual activity
1215 * implementation that the alias referred to. Otherwise, this is null.
1216 */
1217 public ComponentName origActivity;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001218
1219 /**
James Cook4d0ef042015-07-09 14:28:23 -07001220 * The actual activity component that started the task.
1221 * @hide
1222 */
1223 @Nullable
1224 public ComponentName realActivity;
1225
1226 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001227 * Description of the task's last state.
1228 */
1229 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001230
1231 /**
1232 * The id of the ActivityStack this Task was on most recently.
Craig Mautner27030522013-08-26 12:25:36 -07001233 * @hide
Craig Mautner6d90fed2013-05-22 15:03:10 -07001234 */
1235 public int stackId;
1236
Kenny Guy82326a92014-03-17 17:16:06 +00001237 /**
Craig Mautner2fbd7542014-03-21 09:34:07 -07001238 * The id of the user the task was running as.
Kenny Guy82326a92014-03-17 17:16:06 +00001239 * @hide
1240 */
1241 public int userId;
1242
Craig Mautner2fbd7542014-03-21 09:34:07 -07001243 /**
Winson Chungffa2ec62014-07-03 15:54:42 -07001244 * The first time this task was active.
1245 * @hide
1246 */
1247 public long firstActiveTime;
1248
1249 /**
Winson Chungf1fbd772014-06-24 18:06:58 -07001250 * The last time this task was active.
1251 * @hide
1252 */
1253 public long lastActiveTime;
1254
1255 /**
Winson Chung03a9bae2014-05-02 09:56:12 -07001256 * The recent activity values for the highest activity in the stack to have set the values.
Winson Chunga449dc02014-05-16 11:15:04 -07001257 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
Craig Mautner2fbd7542014-03-21 09:34:07 -07001258 */
Winson Chunga449dc02014-05-16 11:15:04 -07001259 public TaskDescription taskDescription;
Craig Mautner2fbd7542014-03-21 09:34:07 -07001260
Craig Mautnera228ae92014-07-09 05:44:55 -07001261 /**
1262 * Task affiliation for grouping with other tasks.
Craig Mautnera228ae92014-07-09 05:44:55 -07001263 */
1264 public int affiliatedTaskId;
1265
Winson Chungec396d62014-08-06 17:08:00 -07001266 /**
1267 * Task affiliation color of the source task with the affiliated task id.
1268 *
1269 * @hide
1270 */
1271 public int affiliatedTaskColor;
1272
Wale Ogunwale6035e012015-04-14 15:54:10 -07001273 /**
1274 * The component launched as the first activity in the task.
1275 * This can be considered the "application" of this task.
1276 */
1277 public ComponentName baseActivity;
1278
1279 /**
1280 * The activity component at the top of the history stack of the task.
1281 * This is what the user is currently doing.
1282 */
1283 public ComponentName topActivity;
1284
1285 /**
1286 * Number of activities in this task.
1287 */
1288 public int numActivities;
1289
Winson2dd76942015-11-02 09:20:01 -08001290 /**
1291 * The bounds of the task.
1292 * @hide
1293 */
1294 public Rect bounds;
1295
Wale Ogunwale21b60582016-01-27 12:34:16 -08001296 /**
1297 * True if the task can go in the docked stack.
1298 * @hide
1299 */
1300 public boolean isDockable;
1301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 public RecentTaskInfo() {
1303 }
1304
Craig Mautner6d90fed2013-05-22 15:03:10 -07001305 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001306 public int describeContents() {
1307 return 0;
1308 }
1309
Craig Mautner6d90fed2013-05-22 15:03:10 -07001310 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 public void writeToParcel(Parcel dest, int flags) {
1312 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001313 dest.writeInt(persistentId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 if (baseIntent != null) {
1315 dest.writeInt(1);
1316 baseIntent.writeToParcel(dest, 0);
1317 } else {
1318 dest.writeInt(0);
1319 }
1320 ComponentName.writeToParcel(origActivity, dest);
James Cook4d0ef042015-07-09 14:28:23 -07001321 ComponentName.writeToParcel(realActivity, dest);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001322 TextUtils.writeToParcel(description, dest,
1323 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
Winson Chunga449dc02014-05-16 11:15:04 -07001324 if (taskDescription != null) {
Craig Mautner2fbd7542014-03-21 09:34:07 -07001325 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001326 taskDescription.writeToParcel(dest, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001327 } else {
1328 dest.writeInt(0);
Craig Mautner2fbd7542014-03-21 09:34:07 -07001329 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001330 dest.writeInt(stackId);
Kenny Guy82326a92014-03-17 17:16:06 +00001331 dest.writeInt(userId);
Winson Chungffa2ec62014-07-03 15:54:42 -07001332 dest.writeLong(firstActiveTime);
Winson Chungf1fbd772014-06-24 18:06:58 -07001333 dest.writeLong(lastActiveTime);
Craig Mautnera228ae92014-07-09 05:44:55 -07001334 dest.writeInt(affiliatedTaskId);
Winson Chungec396d62014-08-06 17:08:00 -07001335 dest.writeInt(affiliatedTaskColor);
Wale Ogunwale6035e012015-04-14 15:54:10 -07001336 ComponentName.writeToParcel(baseActivity, dest);
1337 ComponentName.writeToParcel(topActivity, dest);
1338 dest.writeInt(numActivities);
Winson2dd76942015-11-02 09:20:01 -08001339 if (bounds != null) {
1340 dest.writeInt(1);
1341 bounds.writeToParcel(dest, 0);
1342 } else {
1343 dest.writeInt(0);
1344 }
Wale Ogunwale21b60582016-01-27 12:34:16 -08001345 dest.writeInt(isDockable ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001346 }
1347
1348 public void readFromParcel(Parcel source) {
1349 id = source.readInt();
Dianne Hackbornd94df452011-02-16 18:53:31 -08001350 persistentId = source.readInt();
Craig Mautner688b5102014-03-27 16:55:03 -07001351 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 origActivity = ComponentName.readFromParcel(source);
James Cook4d0ef042015-07-09 14:28:23 -07001353 realActivity = ComponentName.readFromParcel(source);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001354 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Winson Chunga449dc02014-05-16 11:15:04 -07001355 taskDescription = source.readInt() > 0 ?
1356 TaskDescription.CREATOR.createFromParcel(source) : null;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001357 stackId = source.readInt();
Kenny Guy82326a92014-03-17 17:16:06 +00001358 userId = source.readInt();
Winson Chungffa2ec62014-07-03 15:54:42 -07001359 firstActiveTime = source.readLong();
Winson Chungf1fbd772014-06-24 18:06:58 -07001360 lastActiveTime = source.readLong();
Craig Mautnera228ae92014-07-09 05:44:55 -07001361 affiliatedTaskId = source.readInt();
Winson Chungec396d62014-08-06 17:08:00 -07001362 affiliatedTaskColor = source.readInt();
Wale Ogunwale6035e012015-04-14 15:54:10 -07001363 baseActivity = ComponentName.readFromParcel(source);
1364 topActivity = ComponentName.readFromParcel(source);
1365 numActivities = source.readInt();
Winson2dd76942015-11-02 09:20:01 -08001366 bounds = source.readInt() > 0 ?
1367 Rect.CREATOR.createFromParcel(source) : null;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001368 isDockable = source.readInt() == 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 public static final Creator<RecentTaskInfo> CREATOR
1372 = new Creator<RecentTaskInfo>() {
1373 public RecentTaskInfo createFromParcel(Parcel source) {
1374 return new RecentTaskInfo(source);
1375 }
1376 public RecentTaskInfo[] newArray(int size) {
1377 return new RecentTaskInfo[size];
1378 }
1379 };
1380
1381 private RecentTaskInfo(Parcel source) {
1382 readFromParcel(source);
1383 }
1384 }
1385
1386 /**
1387 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1388 * that have set their
1389 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1390 */
1391 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001393 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001394 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001395 * recent tasks that currently are not available to the user.
1396 */
1397 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001398
1399 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001400 * Provides a list that contains recent tasks for all
1401 * profiles of a user.
Kenny Guy82326a92014-03-17 17:16:06 +00001402 * @hide
1403 */
Kenny Guy2a764942014-04-02 13:29:20 +01001404 public static final int RECENT_INCLUDE_PROFILES = 0x0004;
Kenny Guy82326a92014-03-17 17:16:06 +00001405
1406 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001407 * Ignores all tasks that are on the home stack.
1408 * @hide
1409 */
1410 public static final int RECENT_IGNORE_HOME_STACK_TASKS = 0x0008;
1411
1412 /**
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001413 * Ignores the top task in the docked stack.
Winson Chung0583d3d2015-12-18 10:03:12 -05001414 * @hide
1415 */
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001416 public static final int RECENT_INGORE_DOCKED_STACK_TOP_TASK = 0x0010;
Winson Chung0583d3d2015-12-18 10:03:12 -05001417
1418 /**
1419 * Ignores all tasks that are on the pinned stack.
1420 * @hide
1421 */
1422 public static final int RECENT_INGORE_PINNED_STACK_TASKS = 0x0020;
1423
1424 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001425 * <p></p>Return a list of the tasks that the user has recently launched, with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001427 *
1428 * <p><b>Note: this method is only intended for debugging and presenting
1429 * task management user interfaces</b>. This should never be used for
1430 * core logic in an application, such as deciding between different
1431 * behaviors based on the information found here. Such uses are
1432 * <em>not</em> supported, and will likely break in the future. For
1433 * example, if multiple applications can be actively running at the
1434 * same time, assumptions made about the meaning of the data here for
1435 * purposes of control flow will be incorrect.</p>
1436 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001437 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001438 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001439 * document-centric recents means
1440 * it can leak personal information to the caller. For backwards compatibility,
1441 * it will still return a small subset of its data: at least the caller's
1442 * own tasks (though see {@link #getAppTasks()} for the correct supported
1443 * way to retrieve that information), and possibly some other tasks
1444 * such as home that are known to not be sensitive.
1445 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 * @param maxNum The maximum number of entries to return in the list. The
1447 * actual number returned may be smaller, depending on how many tasks the
1448 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001449 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001450 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001451 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 * @return Returns a list of RecentTaskInfo records describing each of
1453 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001455 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1457 throws SecurityException {
1458 try {
1459 return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07001460 flags, UserHandle.myUserId());
Amith Yamasani82644082012-08-03 13:09:11 -07001461 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001462 throw e.rethrowFromSystemServer();
Amith Yamasani82644082012-08-03 13:09:11 -07001463 }
1464 }
1465
1466 /**
1467 * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a
1468 * specific user. It requires holding
1469 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
1470 * @param maxNum The maximum number of entries to return in the list. The
1471 * actual number returned may be smaller, depending on how many tasks the
1472 * user has started and the maximum number the system can remember.
1473 * @param flags Information about what to return. May be any combination
1474 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
1475 *
1476 * @return Returns a list of RecentTaskInfo records describing each of
Vadim Tryshev35605752015-08-31 13:28:08 -07001477 * the recent tasks. Most recently activated tasks go first.
Amith Yamasani82644082012-08-03 13:09:11 -07001478 *
Amith Yamasani82644082012-08-03 13:09:11 -07001479 * @hide
1480 */
1481 public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId)
1482 throws SecurityException {
1483 try {
1484 return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
1485 flags, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001487 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 }
1489 }
1490
1491 /**
1492 * Information you can retrieve about a particular task that is currently
1493 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001494 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 * means that the user has gone to it and never closed it, but currently
1496 * the system may have killed its process and is only holding on to its
1497 * last state in order to restart it when the user returns.
1498 */
1499 public static class RunningTaskInfo implements Parcelable {
1500 /**
1501 * A unique identifier for this task.
1502 */
1503 public int id;
1504
1505 /**
Winson5510f6c2015-10-27 12:11:26 -07001506 * The stack that currently contains this task.
1507 * @hide
1508 */
1509 public int stackId;
1510
1511 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 * The component launched as the first activity in the task. This can
1513 * be considered the "application" of this task.
1514 */
1515 public ComponentName baseActivity;
1516
1517 /**
1518 * The activity component at the top of the history stack of the task.
1519 * This is what the user is currently doing.
1520 */
1521 public ComponentName topActivity;
1522
1523 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001524 * Thumbnail representation of the task's current state. Currently
1525 * always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 */
1527 public Bitmap thumbnail;
1528
1529 /**
1530 * Description of the task's current state.
1531 */
1532 public CharSequence description;
1533
1534 /**
1535 * Number of activities in this task.
1536 */
1537 public int numActivities;
1538
1539 /**
1540 * Number of activities that are currently running (not stopped
1541 * and persisted) in this task.
1542 */
1543 public int numRunning;
1544
Craig Mautnerc0fd8052013-09-19 11:20:17 -07001545 /**
1546 * Last time task was run. For sorting.
1547 * @hide
1548 */
1549 public long lastActiveTime;
1550
Wale Ogunwale21b60582016-01-27 12:34:16 -08001551 /**
1552 * True if the task can go in the docked stack.
1553 * @hide
1554 */
1555 public boolean isDockable;
1556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 public RunningTaskInfo() {
1558 }
1559
1560 public int describeContents() {
1561 return 0;
1562 }
1563
1564 public void writeToParcel(Parcel dest, int flags) {
1565 dest.writeInt(id);
Winson5510f6c2015-10-27 12:11:26 -07001566 dest.writeInt(stackId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 ComponentName.writeToParcel(baseActivity, dest);
1568 ComponentName.writeToParcel(topActivity, dest);
1569 if (thumbnail != null) {
1570 dest.writeInt(1);
1571 thumbnail.writeToParcel(dest, 0);
1572 } else {
1573 dest.writeInt(0);
1574 }
1575 TextUtils.writeToParcel(description, dest,
1576 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1577 dest.writeInt(numActivities);
1578 dest.writeInt(numRunning);
Jorim Jaggiaa6c5742016-03-01 14:10:14 +01001579 dest.writeInt(isDockable ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 }
1581
1582 public void readFromParcel(Parcel source) {
1583 id = source.readInt();
Winson5510f6c2015-10-27 12:11:26 -07001584 stackId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 baseActivity = ComponentName.readFromParcel(source);
1586 topActivity = ComponentName.readFromParcel(source);
1587 if (source.readInt() != 0) {
1588 thumbnail = Bitmap.CREATOR.createFromParcel(source);
1589 } else {
1590 thumbnail = null;
1591 }
1592 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
1593 numActivities = source.readInt();
1594 numRunning = source.readInt();
Jorim Jaggiaa6c5742016-03-01 14:10:14 +01001595 isDockable = source.readInt() != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
1599 public RunningTaskInfo createFromParcel(Parcel source) {
1600 return new RunningTaskInfo(source);
1601 }
1602 public RunningTaskInfo[] newArray(int size) {
1603 return new RunningTaskInfo[size];
1604 }
1605 };
1606
1607 private RunningTaskInfo(Parcel source) {
1608 readFromParcel(source);
1609 }
1610 }
Winson Chung1147c402014-05-14 11:05:00 -07001611
1612 /**
1613 * Get the list of tasks associated with the calling application.
1614 *
1615 * @return The list of tasks associated with the application making this call.
1616 * @throws SecurityException
1617 */
1618 public List<ActivityManager.AppTask> getAppTasks() {
1619 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
1620 List<IAppTask> appTasks;
1621 try {
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001622 appTasks = ActivityManagerNative.getDefault().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001623 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001624 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001625 }
1626 int numAppTasks = appTasks.size();
1627 for (int i = 0; i < numAppTasks; i++) {
1628 tasks.add(new AppTask(appTasks.get(i)));
1629 }
1630 return tasks;
1631 }
1632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 /**
Winson Chung48a10a52014-08-27 14:36:51 -07001634 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001635 * with {@link #addAppTask}.
1636 */
Winson Chung48a10a52014-08-27 14:36:51 -07001637 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001638 synchronized (this) {
1639 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07001640 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001641 }
1642 }
1643
1644 private void ensureAppTaskThumbnailSizeLocked() {
1645 if (mAppTaskThumbnailSize == null) {
1646 try {
1647 mAppTaskThumbnailSize = ActivityManagerNative.getDefault().getAppTaskThumbnailSize();
1648 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001649 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001650 }
1651 }
1652 }
1653
1654 /**
1655 * Add a new {@link AppTask} for the calling application. This will create a new
1656 * recents entry that is added to the <b>end</b> of all existing recents.
1657 *
1658 * @param activity The activity that is adding the entry. This is used to help determine
1659 * the context that the new recents entry will be in.
1660 * @param intent The Intent that describes the recents entry. This is the same Intent that
1661 * you would have used to launch the activity for it. In generally you will want to set
1662 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
1663 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
1664 * entry will exist without an activity, so it doesn't make sense to not retain it when
1665 * its activity disappears. The given Intent here also must have an explicit ComponentName
1666 * set on it.
1667 * @param description Optional additional description information.
1668 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07001669 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
1670 * recreated in your process, probably in a way you don't like, before the recents entry
1671 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001672 *
1673 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
1674 * most likely cause of failure is that there is no more room for more tasks for your app.
1675 */
1676 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
1677 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
1678 Point size;
1679 synchronized (this) {
1680 ensureAppTaskThumbnailSizeLocked();
1681 size = mAppTaskThumbnailSize;
1682 }
1683 final int tw = thumbnail.getWidth();
1684 final int th = thumbnail.getHeight();
1685 if (tw != size.x || th != size.y) {
1686 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
1687
1688 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
1689 float scale;
1690 float dx = 0, dy = 0;
1691 if (tw * size.x > size.y * th) {
1692 scale = (float) size.x / (float) th;
1693 dx = (size.y - tw * scale) * 0.5f;
1694 } else {
1695 scale = (float) size.y / (float) tw;
1696 dy = (size.x - th * scale) * 0.5f;
1697 }
1698 Matrix matrix = new Matrix();
1699 matrix.setScale(scale, scale);
1700 matrix.postTranslate((int) (dx + 0.5f), 0);
1701
1702 Canvas canvas = new Canvas(bm);
1703 canvas.drawBitmap(thumbnail, matrix, null);
1704 canvas.setBitmap(null);
1705
1706 thumbnail = bm;
1707 }
1708 if (description == null) {
1709 description = new TaskDescription();
1710 }
1711 try {
1712 return ActivityManagerNative.getDefault().addAppTask(activity.getActivityToken(),
1713 intent, description, thumbnail);
1714 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001715 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001716 }
1717 }
1718
1719 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 * Return a list of the tasks that are currently running, with
1721 * the most recent being first and older ones after in order. Note that
1722 * "running" does not mean any of the task's code is currently loaded or
1723 * activity -- the task may have been frozen by the system, so that it
1724 * can be restarted in its previous state when next brought to the
1725 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001726 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001727 * <p><b>Note: this method is only intended for debugging and presenting
1728 * task management user interfaces</b>. This should never be used for
1729 * core logic in an application, such as deciding between different
1730 * behaviors based on the information found here. Such uses are
1731 * <em>not</em> supported, and will likely break in the future. For
1732 * example, if multiple applications can be actively running at the
1733 * same time, assumptions made about the meaning of the data here for
1734 * purposes of control flow will be incorrect.</p>
1735 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001736 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001737 * is no longer available to third party
1738 * applications: the introduction of document-centric recents means
1739 * it can leak person information to the caller. For backwards compatibility,
1740 * it will still retu rn a small subset of its data: at least the caller's
1741 * own tasks, and possibly some other tasks
1742 * such as home that are known to not be sensitive.
1743 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07001744 * @param maxNum The maximum number of entries to return in the list. The
1745 * actual number returned may be smaller, depending on how many tasks the
1746 * user has started.
1747 *
1748 * @return Returns a list of RunningTaskInfo records describing each of
1749 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001750 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001751 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07001752 public List<RunningTaskInfo> getRunningTasks(int maxNum)
1753 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07001754 try {
1755 return ActivityManagerNative.getDefault().getTasks(maxNum, 0);
1756 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001757 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07001758 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07001759 }
1760
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001761 /**
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001762 * Completely remove the given task.
1763 *
1764 * @param taskId Identifier of the task to be removed.
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001765 * @return Returns true if the given task was found and removed.
1766 *
1767 * @hide
1768 */
Wale Ogunwaled54b5782014-10-23 15:55:23 -07001769 public boolean removeTask(int taskId) throws SecurityException {
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001770 try {
Wale Ogunwaled54b5782014-10-23 15:55:23 -07001771 return ActivityManagerNative.getDefault().removeTask(taskId);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001772 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001773 throw e.rethrowFromSystemServer();
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001774 }
1775 }
1776
Winsonc809cbb2015-11-02 12:06:15 -08001777 /**
1778 * Metadata related to the {@link TaskThumbnail}.
1779 *
1780 * @hide
1781 */
1782 public static class TaskThumbnailInfo implements Parcelable {
1783 /** @hide */
1784 public static final String ATTR_TASK_THUMBNAILINFO_PREFIX = "task_thumbnailinfo_";
1785 private static final String ATTR_TASK_WIDTH =
1786 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_width";
1787 private static final String ATTR_TASK_HEIGHT =
1788 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_height";
1789 private static final String ATTR_SCREEN_ORIENTATION =
1790 ATTR_TASK_THUMBNAILINFO_PREFIX + "screen_orientation";
1791
1792 public int taskWidth;
1793 public int taskHeight;
Winson21700932016-03-24 17:26:23 -07001794 public int screenOrientation = Configuration.ORIENTATION_UNDEFINED;
Winsonc809cbb2015-11-02 12:06:15 -08001795
1796 public TaskThumbnailInfo() {
1797 // Do nothing
1798 }
1799
1800 private TaskThumbnailInfo(Parcel source) {
1801 readFromParcel(source);
1802 }
1803
Winsonc6a2da02015-11-11 18:11:59 -08001804 /**
1805 * Resets this info state to the initial state.
1806 * @hide
1807 */
1808 public void reset() {
1809 taskWidth = 0;
1810 taskHeight = 0;
Winson21700932016-03-24 17:26:23 -07001811 screenOrientation = Configuration.ORIENTATION_UNDEFINED;
1812 }
1813
1814 /**
1815 * Copies from another ThumbnailInfo.
1816 */
1817 public void copyFrom(TaskThumbnailInfo o) {
1818 taskWidth = o.taskWidth;
1819 taskHeight = o.taskHeight;
1820 screenOrientation = o.screenOrientation;
Winsonc6a2da02015-11-11 18:11:59 -08001821 }
1822
Winsonc809cbb2015-11-02 12:06:15 -08001823 /** @hide */
1824 public void saveToXml(XmlSerializer out) throws IOException {
1825 out.attribute(null, ATTR_TASK_WIDTH, Integer.toString(taskWidth));
1826 out.attribute(null, ATTR_TASK_HEIGHT, Integer.toString(taskHeight));
1827 out.attribute(null, ATTR_SCREEN_ORIENTATION, Integer.toString(screenOrientation));
1828 }
1829
1830 /** @hide */
1831 public void restoreFromXml(String attrName, String attrValue) {
1832 if (ATTR_TASK_WIDTH.equals(attrName)) {
1833 taskWidth = Integer.parseInt(attrValue);
1834 } else if (ATTR_TASK_HEIGHT.equals(attrName)) {
1835 taskHeight = Integer.parseInt(attrValue);
1836 } else if (ATTR_SCREEN_ORIENTATION.equals(attrName)) {
1837 screenOrientation = Integer.parseInt(attrValue);
1838 }
1839 }
1840
1841 public int describeContents() {
1842 return 0;
1843 }
1844
1845 public void writeToParcel(Parcel dest, int flags) {
1846 dest.writeInt(taskWidth);
1847 dest.writeInt(taskHeight);
1848 dest.writeInt(screenOrientation);
1849 }
1850
1851 public void readFromParcel(Parcel source) {
1852 taskWidth = source.readInt();
1853 taskHeight = source.readInt();
1854 screenOrientation = source.readInt();
1855 }
1856
1857 public static final Creator<TaskThumbnailInfo> CREATOR = new Creator<TaskThumbnailInfo>() {
1858 public TaskThumbnailInfo createFromParcel(Parcel source) {
1859 return new TaskThumbnailInfo(source);
1860 }
1861 public TaskThumbnailInfo[] newArray(int size) {
1862 return new TaskThumbnailInfo[size];
1863 }
1864 };
1865 }
1866
Dianne Hackbornd94df452011-02-16 18:53:31 -08001867 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001868 public static class TaskThumbnail implements Parcelable {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001869 public Bitmap mainThumbnail;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001870 public ParcelFileDescriptor thumbnailFileDescriptor;
Winsonc809cbb2015-11-02 12:06:15 -08001871 public TaskThumbnailInfo thumbnailInfo;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001872
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001873 public TaskThumbnail() {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001874 }
1875
Winsonc809cbb2015-11-02 12:06:15 -08001876 private TaskThumbnail(Parcel source) {
1877 readFromParcel(source);
1878 }
1879
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001880 public int describeContents() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001881 if (thumbnailFileDescriptor != null) {
1882 return thumbnailFileDescriptor.describeContents();
1883 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001884 return 0;
1885 }
1886
1887 public void writeToParcel(Parcel dest, int flags) {
1888 if (mainThumbnail != null) {
1889 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001890 mainThumbnail.writeToParcel(dest, flags);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001891 } else {
1892 dest.writeInt(0);
1893 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001894 if (thumbnailFileDescriptor != null) {
1895 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001896 thumbnailFileDescriptor.writeToParcel(dest, flags);
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001897 } else {
1898 dest.writeInt(0);
1899 }
Winsonc809cbb2015-11-02 12:06:15 -08001900 if (thumbnailInfo != null) {
1901 dest.writeInt(1);
1902 thumbnailInfo.writeToParcel(dest, flags);
1903 } else {
1904 dest.writeInt(0);
1905 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001906 }
1907
1908 public void readFromParcel(Parcel source) {
1909 if (source.readInt() != 0) {
1910 mainThumbnail = Bitmap.CREATOR.createFromParcel(source);
1911 } else {
1912 mainThumbnail = null;
1913 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001914 if (source.readInt() != 0) {
1915 thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source);
1916 } else {
1917 thumbnailFileDescriptor = null;
1918 }
Winsonc809cbb2015-11-02 12:06:15 -08001919 if (source.readInt() != 0) {
1920 thumbnailInfo = TaskThumbnailInfo.CREATOR.createFromParcel(source);
1921 } else {
1922 thumbnailInfo = null;
1923 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001924 }
1925
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001926 public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() {
1927 public TaskThumbnail createFromParcel(Parcel source) {
1928 return new TaskThumbnail(source);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001929 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001930 public TaskThumbnail[] newArray(int size) {
1931 return new TaskThumbnail[size];
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001932 }
1933 };
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001934 }
1935
1936 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001937 public TaskThumbnail getTaskThumbnail(int id) throws SecurityException {
Dianne Hackbornd94df452011-02-16 18:53:31 -08001938 try {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001939 return ActivityManagerNative.getDefault().getTaskThumbnail(id);
Dianne Hackborn15491c62012-09-19 10:59:14 -07001940 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001941 throw e.rethrowFromSystemServer();
Dianne Hackborn15491c62012-09-19 10:59:14 -07001942 }
1943 }
1944
Winson Chung303e1ff2014-03-07 15:06:19 -08001945 /** @hide */
1946 public boolean isInHomeStack(int taskId) {
1947 try {
1948 return ActivityManagerNative.getDefault().isInHomeStack(taskId);
1949 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001950 throw e.rethrowFromSystemServer();
Winson Chung303e1ff2014-03-07 15:06:19 -08001951 }
1952 }
1953
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001955 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
1956 * activity along with the task, so it is positioned immediately behind
1957 * the task.
1958 */
1959 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
1960
1961 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001962 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
1963 * user-instigated action, so the current activity will not receive a
1964 * hint that the user is leaving.
1965 */
1966 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
1967
1968 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001969 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
1970 * with a null options argument.
1971 *
1972 * @param taskId The identifier of the task to be moved, as found in
1973 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
1974 * @param flags Additional operational flags, 0 or more of
Craig Mautnerecbfe252013-03-28 11:58:25 -07001975 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001976 */
1977 public void moveTaskToFront(int taskId, int flags) {
1978 moveTaskToFront(taskId, flags, null);
1979 }
1980
1981 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001982 * Ask that the task associated with a given task ID be moved to the
1983 * front of the stack, so it is now visible to the user. Requires that
1984 * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS}
1985 * or a SecurityException will be thrown.
1986 *
1987 * @param taskId The identifier of the task to be moved, as found in
1988 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
1989 * @param flags Additional operational flags, 0 or more of
Craig Mautnerecbfe252013-03-28 11:58:25 -07001990 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001991 * @param options Additional options for the operation, either null or
1992 * as per {@link Context#startActivity(Intent, android.os.Bundle)
1993 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001994 */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001995 public void moveTaskToFront(int taskId, int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001996 try {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001997 ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001998 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001999 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002000 }
2001 }
2002
2003 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 * Information you can retrieve about a particular Service that is
2005 * currently running in the system.
2006 */
2007 public static class RunningServiceInfo implements Parcelable {
2008 /**
2009 * The service component.
2010 */
2011 public ComponentName service;
2012
2013 /**
2014 * If non-zero, this is the process the service is running in.
2015 */
2016 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002019 * The UID that owns this service.
2020 */
2021 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002022
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002023 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 * The name of the process this service runs in.
2025 */
2026 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 /**
2029 * Set to true if the service has asked to run as a foreground process.
2030 */
2031 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002034 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002035 * starting or binding to it. This
2036 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002037 */
2038 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002040 /**
2041 * Set to true if this service has been explicitly started.
2042 */
2043 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045 /**
2046 * Number of clients connected to the service.
2047 */
2048 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 /**
2051 * Number of times the service's process has crashed while the service
2052 * is running.
2053 */
2054 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 /**
2057 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002058 * explicit requests to start it or clients binding to it). This
2059 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 */
2061 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 /**
2064 * If non-zero, this service is not currently running, but scheduled to
2065 * restart at the given time.
2066 */
2067 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002068
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002069 /**
2070 * Bit for {@link #flags}: set if this service has been
2071 * explicitly started.
2072 */
2073 public static final int FLAG_STARTED = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002074
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002075 /**
2076 * Bit for {@link #flags}: set if the service has asked to
2077 * run as a foreground process.
2078 */
2079 public static final int FLAG_FOREGROUND = 1<<1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002080
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002081 /**
2082 * Bit for {@link #flags): set if the service is running in a
2083 * core system process.
2084 */
2085 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002086
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002087 /**
2088 * Bit for {@link #flags): set if the service is running in a
2089 * persistent process.
2090 */
2091 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002092
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002093 /**
2094 * Running flags.
2095 */
2096 public int flags;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002097
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002098 /**
2099 * For special services that are bound to by system code, this is
2100 * the package that holds the binding.
2101 */
2102 public String clientPackage;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002103
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002104 /**
2105 * For special services that are bound to by system code, this is
2106 * a string resource providing a user-visible label for who the
2107 * client is.
2108 */
2109 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002111 public RunningServiceInfo() {
2112 }
2113
2114 public int describeContents() {
2115 return 0;
2116 }
2117
2118 public void writeToParcel(Parcel dest, int flags) {
2119 ComponentName.writeToParcel(service, dest);
2120 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002121 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 dest.writeString(process);
2123 dest.writeInt(foreground ? 1 : 0);
2124 dest.writeLong(activeSince);
2125 dest.writeInt(started ? 1 : 0);
2126 dest.writeInt(clientCount);
2127 dest.writeInt(crashCount);
2128 dest.writeLong(lastActivityTime);
2129 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002130 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002131 dest.writeString(clientPackage);
2132 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 }
2134
2135 public void readFromParcel(Parcel source) {
2136 service = ComponentName.readFromParcel(source);
2137 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002138 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139 process = source.readString();
2140 foreground = source.readInt() != 0;
2141 activeSince = source.readLong();
2142 started = source.readInt() != 0;
2143 clientCount = source.readInt();
2144 crashCount = source.readInt();
2145 lastActivityTime = source.readLong();
2146 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002147 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002148 clientPackage = source.readString();
2149 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
2153 public RunningServiceInfo createFromParcel(Parcel source) {
2154 return new RunningServiceInfo(source);
2155 }
2156 public RunningServiceInfo[] newArray(int size) {
2157 return new RunningServiceInfo[size];
2158 }
2159 };
2160
2161 private RunningServiceInfo(Parcel source) {
2162 readFromParcel(source);
2163 }
2164 }
2165
2166 /**
2167 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002168 *
2169 * <p><b>Note: this method is only intended for debugging or implementing
2170 * service management type user interfaces.</b></p>
2171 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002172 * @param maxNum The maximum number of entries to return in the list. The
2173 * actual number returned may be smaller, depending on how many services
2174 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002175 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 * @return Returns a list of RunningServiceInfo records describing each of
2177 * the running tasks.
2178 */
2179 public List<RunningServiceInfo> getRunningServices(int maxNum)
2180 throws SecurityException {
2181 try {
Amith Yamasani4b2e9342011-03-31 12:38:53 -07002182 return ActivityManagerNative.getDefault()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 .getServices(maxNum, 0);
2184 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002185 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 }
2187 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002190 * Returns a PendingIntent you can start to show a control panel for the
2191 * given running service. If the service does not have a control panel,
2192 * null is returned.
2193 */
2194 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2195 throws SecurityException {
2196 try {
2197 return ActivityManagerNative.getDefault()
2198 .getRunningServiceControlPanel(service);
2199 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002200 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002201 }
2202 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002203
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002204 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 * Information you can retrieve about the available memory through
2206 * {@link ActivityManager#getMemoryInfo}.
2207 */
2208 public static class MemoryInfo implements Parcelable {
2209 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002210 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 * be considered absolute: due to the nature of the kernel, a significant
2212 * portion of this memory is actually in use and needed for the overall
2213 * system to run well.
2214 */
2215 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002216
2217 /**
2218 * The total memory accessible by the kernel. This is basically the
2219 * RAM size of the device, not including below-kernel fixed allocations
2220 * like DMA buffers, RAM for the baseband CPU, etc.
2221 */
2222 public long totalMem;
2223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002224 /**
2225 * The threshold of {@link #availMem} at which we consider memory to be
2226 * low and start killing background services and other non-extraneous
2227 * processes.
2228 */
2229 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002231 /**
2232 * Set to true if the system considers itself to currently be in a low
2233 * memory situation.
2234 */
2235 public boolean lowMemory;
2236
Dianne Hackborn7d608422011-08-07 16:24:18 -07002237 /** @hide */
2238 public long hiddenAppThreshold;
2239 /** @hide */
2240 public long secondaryServerThreshold;
2241 /** @hide */
2242 public long visibleAppThreshold;
2243 /** @hide */
2244 public long foregroundAppThreshold;
2245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 public MemoryInfo() {
2247 }
2248
2249 public int describeContents() {
2250 return 0;
2251 }
2252
2253 public void writeToParcel(Parcel dest, int flags) {
2254 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002255 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 dest.writeLong(threshold);
2257 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002258 dest.writeLong(hiddenAppThreshold);
2259 dest.writeLong(secondaryServerThreshold);
2260 dest.writeLong(visibleAppThreshold);
2261 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 public void readFromParcel(Parcel source) {
2265 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002266 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 threshold = source.readLong();
2268 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002269 hiddenAppThreshold = source.readLong();
2270 secondaryServerThreshold = source.readLong();
2271 visibleAppThreshold = source.readLong();
2272 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 }
2274
2275 public static final Creator<MemoryInfo> CREATOR
2276 = new Creator<MemoryInfo>() {
2277 public MemoryInfo createFromParcel(Parcel source) {
2278 return new MemoryInfo(source);
2279 }
2280 public MemoryInfo[] newArray(int size) {
2281 return new MemoryInfo[size];
2282 }
2283 };
2284
2285 private MemoryInfo(Parcel source) {
2286 readFromParcel(source);
2287 }
2288 }
2289
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002290 /**
2291 * Return general information about the memory state of the system. This
2292 * can be used to help decide how to manage your own memory, though note
2293 * that polling is not recommended and
2294 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2295 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2296 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2297 * level of your process as needed, which gives a better hint for how to
2298 * manage its memory.
2299 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 public void getMemoryInfo(MemoryInfo outInfo) {
2301 try {
2302 ActivityManagerNative.getDefault().getMemoryInfo(outInfo);
2303 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002304 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 }
2306 }
Craig Mautner967212c2013-04-13 21:10:58 -07002307
Craig Mautner5ff12102013-05-24 12:50:15 -07002308 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002309 * Information you can retrieve about an ActivityStack in the system.
2310 * @hide
2311 */
2312 public static class StackInfo implements Parcelable {
2313 public int stackId;
Craig Mautnered6649f2013-12-02 14:08:25 -08002314 public Rect bounds = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -07002315 public int[] taskIds;
2316 public String[] taskNames;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002317 public Rect[] taskBounds;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002318 public int[] taskUserIds;
Craig Mautnered6649f2013-12-02 14:08:25 -08002319 public int displayId;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002320 public int userId;
Craig Mautner967212c2013-04-13 21:10:58 -07002321
Craig Mautner967212c2013-04-13 21:10:58 -07002322 @Override
2323 public int describeContents() {
2324 return 0;
2325 }
2326
2327 @Override
2328 public void writeToParcel(Parcel dest, int flags) {
2329 dest.writeInt(stackId);
2330 dest.writeInt(bounds.left);
2331 dest.writeInt(bounds.top);
2332 dest.writeInt(bounds.right);
2333 dest.writeInt(bounds.bottom);
2334 dest.writeIntArray(taskIds);
2335 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002336 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2337 dest.writeInt(boundsCount);
2338 for (int i = 0; i < boundsCount; i++) {
2339 dest.writeInt(taskBounds[i].left);
2340 dest.writeInt(taskBounds[i].top);
2341 dest.writeInt(taskBounds[i].right);
2342 dest.writeInt(taskBounds[i].bottom);
2343 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002344 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002345 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002346 dest.writeInt(userId);
Craig Mautner967212c2013-04-13 21:10:58 -07002347 }
2348
2349 public void readFromParcel(Parcel source) {
2350 stackId = source.readInt();
2351 bounds = new Rect(
2352 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2353 taskIds = source.createIntArray();
2354 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002355 final int boundsCount = source.readInt();
2356 if (boundsCount > 0) {
2357 taskBounds = new Rect[boundsCount];
2358 for (int i = 0; i < boundsCount; i++) {
2359 taskBounds[i] = new Rect();
2360 taskBounds[i].set(
2361 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2362 }
2363 } else {
2364 taskBounds = null;
2365 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002366 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002367 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002368 userId = source.readInt();
Craig Mautner967212c2013-04-13 21:10:58 -07002369 }
2370
2371 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
2372 @Override
2373 public StackInfo createFromParcel(Parcel source) {
2374 return new StackInfo(source);
2375 }
2376 @Override
2377 public StackInfo[] newArray(int size) {
2378 return new StackInfo[size];
2379 }
2380 };
2381
Craig Mautner5ff12102013-05-24 12:50:15 -07002382 public StackInfo() {
2383 }
2384
Craig Mautner967212c2013-04-13 21:10:58 -07002385 private StackInfo(Parcel source) {
2386 readFromParcel(source);
2387 }
2388
Craig Mautner5ff12102013-05-24 12:50:15 -07002389 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002390 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002391 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002392 sb.append(" bounds="); sb.append(bounds.toShortString());
2393 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002394 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002395 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002396 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002397 for (int i = 0; i < taskIds.length; ++i) {
2398 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002399 sb.append(": "); sb.append(taskNames[i]);
2400 if (taskBounds != null) {
2401 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2402 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002403 sb.append(" userId=").append(taskUserIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002404 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002405 }
2406 return sb.toString();
2407 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002408
2409 @Override
2410 public String toString() {
2411 return toString("");
2412 }
Craig Mautner967212c2013-04-13 21:10:58 -07002413 }
2414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 /**
2416 * @hide
2417 */
2418 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2419 try {
Stefan Kuhne16045c22015-06-05 07:18:06 -07002420 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName,
Dianne Hackborn41203752012-08-31 14:05:51 -07002421 observer, UserHandle.myUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002423 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 }
2425 }
Christopher Tatea3664242013-06-26 15:00:18 -07002426
2427 /**
2428 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002429 * the user choosing to clear the app's data from within the device settings UI. It
2430 * erases all dynamic data associated with the app -- its private data and data in its
2431 * private area on external storage -- but does not remove the installed application
2432 * itself, nor any OBB files.
Christopher Tatea3664242013-06-26 15:00:18 -07002433 *
2434 * @return {@code true} if the application successfully requested that the application's
2435 * data be erased; {@code false} otherwise.
2436 */
2437 public boolean clearApplicationUserData() {
2438 return clearApplicationUserData(mContext.getPackageName(), null);
2439 }
2440
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002441
2442 /**
2443 * Permits an application to get the persistent URI permissions granted to another.
2444 *
2445 * <p>Typically called by Settings.
2446 *
2447 * @param packageName application to look for the granted permissions
2448 * @return list of granted URI permissions
2449 *
2450 * @hide
2451 */
2452 public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName) {
2453 try {
2454 return ActivityManagerNative.getDefault().getGrantedUriPermissions(packageName,
2455 UserHandle.myUserId());
2456 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002457 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002458 }
2459 }
2460
2461 /**
2462 * Permits an application to clear the persistent URI permissions granted to another.
2463 *
2464 * <p>Typically called by Settings.
2465 *
2466 * @param packageName application to clear its granted permissions
2467 *
2468 * @hide
2469 */
2470 public void clearGrantedUriPermissions(String packageName) {
2471 try {
2472 ActivityManagerNative.getDefault().clearGrantedUriPermissions(packageName,
2473 UserHandle.myUserId());
2474 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002475 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002476 }
2477 }
2478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 /**
2480 * Information you can retrieve about any processes that are in an error condition.
2481 */
2482 public static class ProcessErrorStateInfo implements Parcelable {
2483 /**
2484 * Condition codes
2485 */
2486 public static final int NO_ERROR = 0;
2487 public static final int CRASHED = 1;
2488 public static final int NOT_RESPONDING = 2;
2489
2490 /**
2491 * The condition that the process is in.
2492 */
2493 public int condition;
2494
2495 /**
2496 * The process name in which the crash or error occurred.
2497 */
2498 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 /**
2501 * The pid of this process; 0 if none
2502 */
2503 public int pid;
2504
2505 /**
2506 * The kernel user-ID that has been assigned to this process;
2507 * currently this is not a unique ID (multiple applications can have
2508 * the same uid).
2509 */
2510 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 /**
Dan Egnor60d87622009-12-16 16:32:58 -08002513 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 */
2515 public String tag;
2516
2517 /**
2518 * A short message describing the error condition.
2519 */
2520 public String shortMsg;
2521
2522 /**
2523 * A long message describing the error condition.
2524 */
2525 public String longMsg;
2526
2527 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08002528 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 */
Dan Egnorb7f03672009-12-09 16:22:32 -08002530 public String stackTrace;
2531
2532 /**
2533 * to be deprecated: This value will always be null.
2534 */
2535 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536
2537 public ProcessErrorStateInfo() {
2538 }
2539
Craig Mautner5ff12102013-05-24 12:50:15 -07002540 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 public int describeContents() {
2542 return 0;
2543 }
2544
Craig Mautner5ff12102013-05-24 12:50:15 -07002545 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 public void writeToParcel(Parcel dest, int flags) {
2547 dest.writeInt(condition);
2548 dest.writeString(processName);
2549 dest.writeInt(pid);
2550 dest.writeInt(uid);
2551 dest.writeString(tag);
2552 dest.writeString(shortMsg);
2553 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08002554 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 public void readFromParcel(Parcel source) {
2558 condition = source.readInt();
2559 processName = source.readString();
2560 pid = source.readInt();
2561 uid = source.readInt();
2562 tag = source.readString();
2563 shortMsg = source.readString();
2564 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08002565 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002567
2568 public static final Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 new Creator<ProcessErrorStateInfo>() {
2570 public ProcessErrorStateInfo createFromParcel(Parcel source) {
2571 return new ProcessErrorStateInfo(source);
2572 }
2573 public ProcessErrorStateInfo[] newArray(int size) {
2574 return new ProcessErrorStateInfo[size];
2575 }
2576 };
2577
2578 private ProcessErrorStateInfo(Parcel source) {
2579 readFromParcel(source);
2580 }
2581 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002584 * Returns a list of any processes that are currently in an error condition. The result
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002586 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
2588 * current error conditions (it will not return an empty list). This list ordering is not
2589 * specified.
2590 */
2591 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
2592 try {
2593 return ActivityManagerNative.getDefault().getProcessesInErrorState();
2594 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002595 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002596 }
2597 }
2598
2599 /**
2600 * Information you can retrieve about a running process.
2601 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07002602 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 /**
2604 * The name of the process that this object is associated with
2605 */
2606 public String processName;
2607
2608 /**
2609 * The pid of this process; 0 if none
2610 */
2611 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002612
Dianne Hackborneb034652009-09-07 00:49:58 -07002613 /**
2614 * The user id of this process.
2615 */
2616 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002617
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002618 /**
2619 * All packages that have been loaded into the process.
2620 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07002622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07002624 * Constant for {@link #flags}: this is an app that is unable to
2625 * correctly save its state when going to the background,
2626 * so it can not be killed while in the background.
2627 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002628 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07002629 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002630
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002631 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002632 * Constant for {@link #flags}: this process is associated with a
2633 * persistent system app.
2634 * @hide
2635 */
2636 public static final int FLAG_PERSISTENT = 1<<1;
2637
2638 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07002639 * Constant for {@link #flags}: this process is associated with a
2640 * persistent system app.
2641 * @hide
2642 */
2643 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
2644
2645 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002646 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07002647 * {@link #FLAG_CANT_SAVE_STATE}.
2648 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002649 */
2650 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002651
2652 /**
2653 * Last memory trim level reported to the process: corresponds to
2654 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2655 * ComponentCallbacks2.onTrimMemory(int)}.
2656 */
2657 public int lastTrimLevel;
2658
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002659 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002660 * Constant for {@link #importance}: This process is running the
2661 * foreground UI; that is, it is the thing currently at the top of the screen
2662 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002663 */
2664 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002667 * Constant for {@link #importance}: This process is running a foreground
2668 * service, for example to perform music playback even while the user is
2669 * not immediately in the app. This generally indicates that the process
2670 * is doing something the user actively cares about.
2671 */
2672 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
2673
2674 /**
2675 * Constant for {@link #importance}: This process is running the foreground
2676 * UI, but the device is asleep so it is not visible to the user. This means
2677 * the user is not really aware of the process, because they can not see or
2678 * interact with it, but it is quite important because it what they expect to
2679 * return to once unlocking the device.
2680 */
2681 public static final int IMPORTANCE_TOP_SLEEPING = 150;
2682
2683 /**
2684 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002685 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07002686 * foreground. This may be running a window that is behind the current
2687 * foreground (so paused and with its state saved, not interacting with
2688 * the user, but visible to them to some degree); it may also be running
2689 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07002690 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002691 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002692
Dianne Hackborn860755f2010-06-03 18:47:52 -07002693 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002694 * Constant for {@link #importance}: This process is not something the user
2695 * is directly aware of, but is otherwise perceptable to them to some degree.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002697 public static final int IMPORTANCE_PERCEPTIBLE = 130;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002698
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002699 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002700 * Constant for {@link #importance}: This process is running an
Dianne Hackborn5383f502010-10-22 12:59:20 -07002701 * application that can not save its state, and thus can't be killed
2702 * while in the background.
2703 * @hide
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002704 */
Dianne Hackborn5383f502010-10-22 12:59:20 -07002705 public static final int IMPORTANCE_CANT_SAVE_STATE = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002708 * Constant for {@link #importance}: This process is contains services
2709 * that should remain running. These are background services apps have
2710 * started, not something the user is aware of, so they may be killed by
2711 * the system relatively freely (though it is generally desired that they
2712 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 */
2714 public static final int IMPORTANCE_SERVICE = 300;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002715
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002717 * Constant for {@link #importance}: This process process contains
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 * background code that is expendable.
2719 */
2720 public static final int IMPORTANCE_BACKGROUND = 400;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002723 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002724 * actively running code.
2725 */
2726 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002727
2728 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002729 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002730 */
2731 public static final int IMPORTANCE_GONE = 1000;
2732
2733 /** @hide */
2734 public static int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002735 if (procState == PROCESS_STATE_NONEXISTENT) {
2736 return IMPORTANCE_GONE;
2737 } else if (procState >= PROCESS_STATE_HOME) {
2738 return IMPORTANCE_BACKGROUND;
2739 } else if (procState >= PROCESS_STATE_SERVICE) {
2740 return IMPORTANCE_SERVICE;
2741 } else if (procState > PROCESS_STATE_HEAVY_WEIGHT) {
2742 return IMPORTANCE_CANT_SAVE_STATE;
2743 } else if (procState >= PROCESS_STATE_IMPORTANT_BACKGROUND) {
2744 return IMPORTANCE_PERCEPTIBLE;
2745 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
2746 return IMPORTANCE_VISIBLE;
2747 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
2748 return IMPORTANCE_TOP_SLEEPING;
2749 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) {
2750 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002751 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002752 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002753 }
2754 }
2755
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756 /**
2757 * The relative importance level that the system places on this
2758 * process. May be one of {@link #IMPORTANCE_FOREGROUND},
2759 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE},
2760 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These
2761 * constants are numbered so that "more important" values are always
2762 * smaller than "less important" values.
2763 */
2764 public int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 /**
2767 * An additional ordering within a particular {@link #importance}
2768 * category, providing finer-grained information about the relative
2769 * utility of processes within a category. This number means nothing
2770 * except that a smaller values are more recently used (and thus
2771 * more important). Currently an LRU value is only maintained for
2772 * the {@link #IMPORTANCE_BACKGROUND} category, though others may
2773 * be maintained in the future.
2774 */
2775 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002776
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002777 /**
2778 * Constant for {@link #importanceReasonCode}: nothing special has
2779 * been specified for the reason for this level.
2780 */
2781 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002782
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002783 /**
2784 * Constant for {@link #importanceReasonCode}: one of the application's
2785 * content providers is being used by another process. The pid of
2786 * the client process is in {@link #importanceReasonPid} and the
2787 * target provider in this process is in
2788 * {@link #importanceReasonComponent}.
2789 */
2790 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002791
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002792 /**
2793 * Constant for {@link #importanceReasonCode}: one of the application's
2794 * content providers is being used by another process. The pid of
2795 * the client process is in {@link #importanceReasonPid} and the
2796 * target provider in this process is in
2797 * {@link #importanceReasonComponent}.
2798 */
2799 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002800
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002801 /**
2802 * The reason for {@link #importance}, if any.
2803 */
2804 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002805
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002806 /**
2807 * For the specified values of {@link #importanceReasonCode}, this
2808 * is the process ID of the other process that is a client of this
2809 * process. This will be 0 if no other process is using this one.
2810 */
2811 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002812
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002813 /**
2814 * For the specified values of {@link #importanceReasonCode}, this
2815 * is the name of the component that is being used in this process.
2816 */
2817 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002818
Dianne Hackborn905577f2011-09-07 18:31:28 -07002819 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07002820 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07002821 * of the other pid. @hide
2822 */
2823 public int importanceReasonImportance;
2824
Dianne Hackborn684bf342014-04-29 17:56:57 -07002825 /**
2826 * Current process state, as per PROCESS_STATE_* constants.
2827 * @hide
2828 */
2829 public int processState;
2830
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831 public RunningAppProcessInfo() {
2832 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002833 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07002834 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
2838 processName = pProcessName;
2839 pid = pPid;
2840 pkgList = pArr;
2841 }
2842
2843 public int describeContents() {
2844 return 0;
2845 }
2846
2847 public void writeToParcel(Parcel dest, int flags) {
2848 dest.writeString(processName);
2849 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07002850 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002851 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002852 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002853 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 dest.writeInt(importance);
2855 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002856 dest.writeInt(importanceReasonCode);
2857 dest.writeInt(importanceReasonPid);
2858 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07002859 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07002860 dest.writeInt(processState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 }
2862
2863 public void readFromParcel(Parcel source) {
2864 processName = source.readString();
2865 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07002866 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002868 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002869 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 importance = source.readInt();
2871 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002872 importanceReasonCode = source.readInt();
2873 importanceReasonPid = source.readInt();
2874 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07002875 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07002876 processState = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 }
2878
Stefan Kuhne16045c22015-06-05 07:18:06 -07002879 public static final Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 new Creator<RunningAppProcessInfo>() {
2881 public RunningAppProcessInfo createFromParcel(Parcel source) {
2882 return new RunningAppProcessInfo(source);
2883 }
2884 public RunningAppProcessInfo[] newArray(int size) {
2885 return new RunningAppProcessInfo[size];
2886 }
2887 };
2888
2889 private RunningAppProcessInfo(Parcel source) {
2890 readFromParcel(source);
2891 }
2892 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07002895 * Returns a list of application processes installed on external media
2896 * that are running on the device.
2897 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002898 * <p><b>Note: this method is only intended for debugging or building
2899 * a user-facing process management UI.</b></p>
2900 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07002901 * @return Returns a list of ApplicationInfo records, or null if none
2902 * This list ordering is not specified.
2903 * @hide
2904 */
2905 public List<ApplicationInfo> getRunningExternalApplications() {
2906 try {
2907 return ActivityManagerNative.getDefault().getRunningExternalApplications();
2908 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002909 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07002910 }
2911 }
2912
2913 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002914 * Sets the memory trim mode for a process and schedules a memory trim operation.
2915 *
2916 * <p><b>Note: this method is only intended for testing framework.</b></p>
2917 *
2918 * @return Returns true if successful.
2919 * @hide
2920 */
2921 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
2922 try {
2923 return ActivityManagerNative.getDefault().setProcessMemoryTrimLevel(process, userId,
2924 level);
2925 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002926 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07002927 }
2928 }
2929
2930 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002932 *
2933 * <p><b>Note: this method is only intended for debugging or building
2934 * a user-facing process management UI.</b></p>
2935 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002936 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
2937 * running processes (it will not return an empty list). This list ordering is not
2938 * specified.
2939 */
2940 public List<RunningAppProcessInfo> getRunningAppProcesses() {
2941 try {
2942 return ActivityManagerNative.getDefault().getRunningAppProcesses();
2943 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002944 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 }
2946 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002947
2948 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002949 * Return the importance of a given package name, based on the processes that are
2950 * currently running. The return value is one of the importance constants defined
2951 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
2952 * processes that this package has code running inside of. If there are no processes
2953 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07002954 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07002955 */
Dianne Hackbornb7258942015-05-13 15:10:24 -07002956 @SystemApi
Dianne Hackborn1e383822015-04-10 14:02:33 -07002957 public int getPackageImportance(String packageName) {
2958 try {
Adam Lesinskic30454c2015-06-24 13:24:35 -07002959 int procState = ActivityManagerNative.getDefault().getPackageProcessState(packageName,
2960 mContext.getOpPackageName());
Dianne Hackborn1e383822015-04-10 14:02:33 -07002961 return RunningAppProcessInfo.procStateToImportance(procState);
2962 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002963 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07002964 }
2965 }
2966
2967 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002968 * Return global memory state information for the calling process. This
2969 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
2970 * only fields that will be filled in are
2971 * {@link RunningAppProcessInfo#pid},
2972 * {@link RunningAppProcessInfo#uid},
2973 * {@link RunningAppProcessInfo#lastTrimLevel},
2974 * {@link RunningAppProcessInfo#importance},
2975 * {@link RunningAppProcessInfo#lru}, and
2976 * {@link RunningAppProcessInfo#importanceReasonCode}.
2977 */
2978 static public void getMyMemoryState(RunningAppProcessInfo outState) {
2979 try {
2980 ActivityManagerNative.getDefault().getMyMemoryState(outState);
2981 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002982 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002983 }
2984 }
2985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07002987 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002988 *
2989 * <p><b>Note: this method is only intended for debugging or building
2990 * a user-facing process management UI.</b></p>
2991 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07002992 * @param pids The pids of the processes whose memory usage is to be
2993 * retrieved.
2994 * @return Returns an array of memory information, one for each
2995 * requested pid.
2996 */
2997 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
2998 try {
2999 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids);
3000 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003001 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003002 }
3003 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003004
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003005 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003006 * @deprecated This is now just a wrapper for
3007 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3008 * is no longer available to applications because it allows them to
3009 * break other applications by removing their alarms, stopping their
3010 * services, etc.
3011 */
3012 @Deprecated
3013 public void restartPackage(String packageName) {
3014 killBackgroundProcesses(packageName);
3015 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003016
Dianne Hackborn03abb812010-01-04 18:43:19 -08003017 /**
3018 * Have the system immediately kill all background processes associated
3019 * with the given package. This is the same as the kernel killing those
3020 * processes to reclaim memory; the system will take care of restarting
3021 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003022 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003023 * <p>You must hold the permission
3024 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to
3025 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003026 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003027 * @param packageName The name of the package whose processes are to
3028 * be killed.
3029 */
3030 public void killBackgroundProcesses(String packageName) {
3031 try {
Dianne Hackborn1676c852012-09-10 14:52:30 -07003032 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName,
3033 UserHandle.myUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003034 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003035 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003036 }
3037 }
Svet Ganov019d2302015-05-04 11:07:38 -07003038
3039 /**
3040 * Kills the specified UID.
3041 * @param uid The UID to kill.
3042 * @param reason The reason for the kill.
3043 *
3044 * @hide
3045 */
Svet Ganov019d2302015-05-04 11:07:38 -07003046 @RequiresPermission(Manifest.permission.KILL_UID)
3047 public void killUid(int uid, String reason) {
3048 try {
Svetoslavaa41add2015-08-06 15:03:55 -07003049 ActivityManagerNative.getDefault().killUid(UserHandle.getAppId(uid),
3050 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003051 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003052 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003053 }
3054 }
3055
Dianne Hackborn03abb812010-01-04 18:43:19 -08003056 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 * Have the system perform a force stop of everything associated with
3058 * the given application package. All processes that share its uid
3059 * will be killed, all services it has running stopped, all activities
3060 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3061 * broadcast will be sent, so that any of its registered alarms can
3062 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003063 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003065 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003067 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003069 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003070 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003071 * @hide This is not available to third party applications due to
3072 * it allowing them to break other applications by stopping their
3073 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 */
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003075 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 try {
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003077 ActivityManagerNative.getDefault().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003079 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 }
3081 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003082
3083 /**
3084 * @see #forceStopPackageAsUser(String, int)
3085 * @hide
3086 */
3087 public void forceStopPackage(String packageName) {
3088 forceStopPackageAsUser(packageName, UserHandle.myUserId());
3089 }
3090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003091 /**
3092 * Get the device configuration attributes.
3093 */
3094 public ConfigurationInfo getDeviceConfigurationInfo() {
3095 try {
3096 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo();
3097 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003098 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003100 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003101
3102 /**
3103 * Get the preferred density of icons for the launcher. This is used when
3104 * custom drawables are created (e.g., for shortcuts).
3105 *
3106 * @return density in terms of DPI
3107 */
3108 public int getLauncherLargeIconDensity() {
3109 final Resources res = mContext.getResources();
3110 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003111 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003112
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003113 if (sw < 600) {
3114 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003115 return density;
3116 }
3117
3118 switch (density) {
3119 case DisplayMetrics.DENSITY_LOW:
3120 return DisplayMetrics.DENSITY_MEDIUM;
3121 case DisplayMetrics.DENSITY_MEDIUM:
3122 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003123 case DisplayMetrics.DENSITY_TV:
3124 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003125 case DisplayMetrics.DENSITY_HIGH:
3126 return DisplayMetrics.DENSITY_XHIGH;
3127 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003128 return DisplayMetrics.DENSITY_XXHIGH;
3129 case DisplayMetrics.DENSITY_XXHIGH:
3130 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003131 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003132 // The density is some abnormal value. Return some other
3133 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003134 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003135 }
3136 }
3137
3138 /**
3139 * Get the preferred launcher icon size. This is used when custom drawables
3140 * are created (e.g., for shortcuts).
3141 *
3142 * @return dimensions of square icons in terms of pixels
3143 */
3144 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003145 return getLauncherLargeIconSizeInner(mContext);
3146 }
3147
3148 static int getLauncherLargeIconSizeInner(Context context) {
3149 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003150 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003151 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003152
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003153 if (sw < 600) {
3154 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003155 return size;
3156 }
3157
3158 final int density = res.getDisplayMetrics().densityDpi;
3159
3160 switch (density) {
3161 case DisplayMetrics.DENSITY_LOW:
3162 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3163 case DisplayMetrics.DENSITY_MEDIUM:
3164 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003165 case DisplayMetrics.DENSITY_TV:
3166 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003167 case DisplayMetrics.DENSITY_HIGH:
3168 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3169 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003170 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3171 case DisplayMetrics.DENSITY_XXHIGH:
3172 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003173 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003174 // The density is some abnormal value. Return some other
3175 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003176 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003177 }
3178 }
3179
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003180 /**
3181 * Returns "true" if the user interface is currently being messed with
3182 * by a monkey.
3183 */
3184 public static boolean isUserAMonkey() {
3185 try {
3186 return ActivityManagerNative.getDefault().isUserAMonkey();
3187 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003188 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003189 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003190 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003191
3192 /**
3193 * Returns "true" if device is running in a test harness.
3194 */
3195 public static boolean isRunningInTestHarness() {
3196 return SystemProperties.getBoolean("ro.test_harness", false);
3197 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003198
3199 /**
3200 * Returns the launch count of each installed package.
3201 *
3202 * @hide
3203 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003204 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00003205 try {
3206 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
3207 ServiceManager.getService("usagestats"));
3208 if (usageStatsService == null) {
3209 return new HashMap<String, Integer>();
3210 }
3211
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003212 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
3213 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00003214 if (allPkgUsageStats == null) {
3215 return new HashMap<String, Integer>();
3216 }
3217
Peter Visontay8d224ca2011-02-18 16:39:19 +00003218 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003219 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
3220 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00003221 }
3222
3223 return launchCounts;
3224 } catch (RemoteException e) {
3225 Log.w(TAG, "Could not query launch counts", e);
3226 return new HashMap<String, Integer>();
3227 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003228 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003229
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003230 /** @hide */
3231 public static int checkComponentPermission(String permission, int uid,
3232 int owningUid, boolean exported) {
3233 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08003234 final int appId = UserHandle.getAppId(uid);
3235 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003236 return PackageManager.PERMISSION_GRANTED;
3237 }
3238 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003239 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003240 return PackageManager.PERMISSION_DENIED;
3241 }
3242 // If there is a uid that owns whatever is being accessed, it has
3243 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003244 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003245 return PackageManager.PERMISSION_GRANTED;
3246 }
3247 // If the target is not exported, then nobody else can get to it.
3248 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07003249 /*
3250 RuntimeException here = new RuntimeException("here");
3251 here.fillInStackTrace();
3252 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
3253 here);
3254 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003255 return PackageManager.PERMISSION_DENIED;
3256 }
3257 if (permission == null) {
3258 return PackageManager.PERMISSION_GRANTED;
3259 }
3260 try {
3261 return AppGlobals.getPackageManager()
3262 .checkUidPermission(permission, uid);
3263 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003264 throw e.rethrowFromSystemServer();
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003265 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003266 }
3267
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003268 /** @hide */
3269 public static int checkUidPermission(String permission, int uid) {
3270 try {
3271 return AppGlobals.getPackageManager()
3272 .checkUidPermission(permission, uid);
3273 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003274 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003275 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003276 }
3277
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08003278 /**
3279 * @hide
3280 * Helper for dealing with incoming user arguments to system service calls.
3281 * Takes care of checking permissions and converting USER_CURRENT to the
3282 * actual current user.
3283 *
3284 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
3285 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
3286 * @param userId The user id argument supplied by the caller -- this is the user
3287 * they want to run as.
3288 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
3289 * to get a USER_ALL returned and deal with it correctly. If false,
3290 * an exception will be thrown if USER_ALL is supplied.
3291 * @param requireFull If true, the caller must hold
3292 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
3293 * different user than their current process; otherwise they must hold
3294 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
3295 * @param name Optional textual name of the incoming call; only for generating error messages.
3296 * @param callerPackage Optional package name of caller; only for error messages.
3297 *
3298 * @return Returns the user ID that the call should run as. Will always be a concrete
3299 * user number, unless <var>allowAll</var> is true in which case it could also be
3300 * USER_ALL.
3301 */
Dianne Hackborn41203752012-08-31 14:05:51 -07003302 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
3303 boolean allowAll, boolean requireFull, String name, String callerPackage) {
3304 if (UserHandle.getUserId(callingUid) == userId) {
3305 return userId;
3306 }
3307 try {
3308 return ActivityManagerNative.getDefault().handleIncomingUser(callingPid,
3309 callingUid, userId, allowAll, requireFull, name, callerPackage);
3310 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003311 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003312 }
3313 }
3314
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07003315 /**
3316 * Gets the userId of the current foreground user. Requires system permissions.
3317 * @hide
3318 */
3319 @SystemApi
Dianne Hackborn41203752012-08-31 14:05:51 -07003320 public static int getCurrentUser() {
3321 UserInfo ui;
3322 try {
3323 ui = ActivityManagerNative.getDefault().getCurrentUser();
3324 return ui != null ? ui.id : 0;
3325 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003326 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003327 }
3328 }
3329
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003330 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003331 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003332 * @hide
3333 */
3334 public boolean switchUser(int userid) {
3335 try {
3336 return ActivityManagerNative.getDefault().switchUser(userid);
3337 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003338 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003339 }
3340 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003341
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003342 /**
3343 * Logs out current current foreground user by switching to the system user and stopping the
3344 * user being switched from.
3345 * @hide
3346 */
3347 public static void logoutCurrentUser() {
3348 int currentUser = ActivityManager.getCurrentUser();
3349 if (currentUser != UserHandle.USER_SYSTEM) {
3350 try {
3351 ActivityManagerNative.getDefault().switchUser(UserHandle.USER_SYSTEM);
3352 ActivityManagerNative.getDefault().stopUser(currentUser, /* force= */ false, null);
3353 } catch (RemoteException e) {
3354 e.rethrowFromSystemServer();
3355 }
3356 }
3357 }
3358
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003359 /** {@hide} */
3360 public static final int FLAG_OR_STOPPED = 1 << 0;
3361 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07003362 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07003363 /** {@hide} */
3364 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003365
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003366 /**
3367 * Return whether the given user is actively running. This means that
3368 * the user is in the "started" state, not "stopped" -- it is currently
3369 * allowed to run code through scheduled alarms, receiving broadcasts,
3370 * etc. A started user may be either the current foreground user or a
3371 * background user; the result here does not distinguish between the two.
3372 * @param userid the user's id. Zero indicates the default user.
3373 * @hide
3374 */
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003375 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003376 try {
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003377 return ActivityManagerNative.getDefault().isUserRunning(userId, 0);
3378 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003379 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003380 }
3381 }
3382
3383 /** {@hide} */
3384 public boolean isUserRunningAndLocked(int userId) {
3385 try {
3386 return ActivityManagerNative.getDefault().isUserRunning(userId,
3387 ActivityManager.FLAG_AND_LOCKED);
3388 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003389 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003390 }
3391 }
3392
3393 /** {@hide} */
3394 public boolean isUserRunningAndUnlocked(int userId) {
3395 try {
3396 return ActivityManagerNative.getDefault().isUserRunning(userId,
3397 ActivityManager.FLAG_AND_UNLOCKED);
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003398 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003399 throw e.rethrowFromSystemServer();
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003400 }
3401 }
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003402
Ruben Brunke24b9a62016-02-16 21:38:24 -08003403 /** {@hide} */
3404 public boolean isVrModePackageEnabled(ComponentName component) {
3405 try {
3406 return ActivityManagerNative.getDefault().isVrModePackageEnabled(component);
3407 } catch (RemoteException e) {
3408 throw e.rethrowFromSystemServer();
3409 }
3410 }
3411
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003412 /**
3413 * Perform a system dump of various state associated with the given application
3414 * package name. This call blocks while the dump is being performed, so should
3415 * not be done on a UI thread. The data will be written to the given file
3416 * descriptor as text. An application must hold the
3417 * {@link android.Manifest.permission#DUMP} permission to make this call.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07003418 * @param fd The file descriptor that the dump should be written to. The file
3419 * descriptor is <em>not</em> closed by this function; the caller continues to
3420 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003421 * @param packageName The name of the package that is to be dumped.
3422 */
3423 public void dumpPackageState(FileDescriptor fd, String packageName) {
3424 dumpPackageStateStatic(fd, packageName);
3425 }
3426
3427 /**
3428 * @hide
3429 */
3430 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
3431 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07003432 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003433 dumpService(pw, fd, "package", new String[] { packageName });
3434 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003435 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
3436 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003437 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003438 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003439 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003440 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003441 pw.println();
Dianne Hackborn904a8572013-06-28 18:12:31 -07003442 dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName });
3443 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07003444 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003445 pw.flush();
3446 }
3447
3448 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
3449 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
3450 IBinder service = ServiceManager.checkService(name);
3451 if (service == null) {
3452 pw.println(" (Service not found)");
3453 return;
3454 }
3455 TransferPipe tp = null;
3456 try {
3457 pw.flush();
3458 tp = new TransferPipe();
3459 tp.setBufferPrefix(" ");
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003460 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003461 tp.go(fd, 10000);
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003462 } catch (Throwable e) {
3463 if (tp != null) {
3464 tp.kill();
3465 }
3466 pw.println("Failure dumping service:");
3467 e.printStackTrace(pw);
3468 }
3469 }
Craig Mautneraea74a52014-03-08 14:23:10 -08003470
3471 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003472 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07003473 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003474 * sees the associated process with a larger pss size and, when this happens, automatically
3475 * pull a heap dump from it and allow the user to share the data. Note that this request
3476 * continues running even if the process is killed and restarted. To remove the watch,
3477 * use {@link #clearWatchHeapLimit()}.
3478 *
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07003479 * <p>This API only work if the calling process has been marked as
3480 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
3481 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003482 *
3483 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
3484 * handle heap limit reports themselves.</p>
3485 *
3486 * @param pssSize The size in bytes to set the limit at.
3487 */
3488 public void setWatchHeapLimit(long pssSize) {
3489 try {
3490 ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, pssSize,
3491 mContext.getPackageName());
3492 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003493 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003494 }
3495 }
3496
3497 /**
3498 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
3499 * If your package has an activity handling this action, it will be launched with the
3500 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
3501 * match the activty must support this action and a MIME type of "*&#47;*".
3502 */
3503 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
3504
3505 /**
3506 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
3507 */
3508 public void clearWatchHeapLimit() {
3509 try {
3510 ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, 0, null);
3511 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003512 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003513 }
3514 }
3515
3516 /**
Craig Mautneraea74a52014-03-08 14:23:10 -08003517 * @hide
3518 */
3519 public void startLockTaskMode(int taskId) {
3520 try {
3521 ActivityManagerNative.getDefault().startLockTaskMode(taskId);
3522 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003523 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003524 }
3525 }
3526
3527 /**
3528 * @hide
3529 */
3530 public void stopLockTaskMode() {
3531 try {
3532 ActivityManagerNative.getDefault().stopLockTaskMode();
3533 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003534 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003535 }
3536 }
3537
3538 /**
Jason Monk386c94f2014-07-14 16:42:24 -04003539 * Return whether currently in lock task mode. When in this mode
3540 * no new tasks can be created or switched to.
3541 *
3542 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00003543 *
3544 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08003545 */
3546 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00003547 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
3548 }
3549
3550 /**
3551 * Return the current state of task locking. The three possible outcomes
3552 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
3553 * and {@link #LOCK_TASK_MODE_PINNED}.
3554 *
3555 * @see Activity#startLockTask()
3556 */
3557 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08003558 try {
Benjamin Franz43261142015-02-11 15:59:44 +00003559 return ActivityManagerNative.getDefault().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08003560 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003561 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003562 }
3563 }
Winson Chung1147c402014-05-14 11:05:00 -07003564
3565 /**
3566 * The AppTask allows you to manage your own application's tasks.
3567 * See {@link android.app.ActivityManager#getAppTasks()}
3568 */
3569 public static class AppTask {
3570 private IAppTask mAppTaskImpl;
3571
3572 /** @hide */
3573 public AppTask(IAppTask task) {
3574 mAppTaskImpl = task;
3575 }
3576
3577 /**
3578 * Finishes all activities in this task and removes it from the recent tasks list.
3579 */
3580 public void finishAndRemoveTask() {
3581 try {
3582 mAppTaskImpl.finishAndRemoveTask();
3583 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003584 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07003585 }
3586 }
3587
3588 /**
3589 * Get the RecentTaskInfo associated with this task.
3590 *
3591 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
3592 */
3593 public RecentTaskInfo getTaskInfo() {
3594 try {
3595 return mAppTaskImpl.getTaskInfo();
3596 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003597 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07003598 }
3599 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003600
3601 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003602 * Bring this task to the foreground. If it contains activities, they will be
3603 * brought to the foreground with it and their instances re-created if needed.
3604 * If it doesn't contain activities, the root activity of the task will be
3605 * re-launched.
3606 */
3607 public void moveToFront() {
3608 try {
3609 mAppTaskImpl.moveToFront();
3610 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003611 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003612 }
3613 }
3614
3615 /**
3616 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003617 * is not currently active (that is, its id < 0), then a new activity for the given
3618 * Intent will be launched as the root of the task and the task brought to the
3619 * foreground. Otherwise, if this task is currently active and the Intent does not specify
3620 * an activity to launch in a new task, then a new activity for the given Intent will
3621 * be launched on top of the task and the task brought to the foreground. If this
3622 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
3623 * or would otherwise be launched in to a new task, then the activity not launched but
3624 * this task be brought to the foreground and a new intent delivered to the top
3625 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003626 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003627 * <p>In other words, you generally want to use an Intent here that does not specify
3628 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
3629 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003630 *
3631 * @param intent The Intent describing the new activity to be launched on the task.
3632 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003633 *
3634 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003635 */
3636 public void startActivity(Context context, Intent intent, Bundle options) {
3637 ActivityThread thread = ActivityThread.currentActivityThread();
3638 thread.getInstrumentation().execStartActivityFromAppTask(context,
3639 thread.getApplicationThread(), mAppTaskImpl, intent, options);
3640 }
3641
3642 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003643 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
3644 * Intent of this AppTask.
3645 *
3646 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
3647 * be set; otherwise, it will be cleared.
3648 */
3649 public void setExcludeFromRecents(boolean exclude) {
3650 try {
3651 mAppTaskImpl.setExcludeFromRecents(exclude);
3652 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003653 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003654 }
3655 }
Winson Chung1147c402014-05-14 11:05:00 -07003656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657}