blob: d1f514327731f5ca553d48d95ad1f61a748c2a76 [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
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700380 /** @hide The lowest process state number */
381 public static final int MIN_PROCESS_STATE = PROCESS_STATE_NONEXISTENT;
382
383 /** @hide The highest process state number */
384 public static final int MAX_PROCESS_STATE = PROCESS_STATE_CACHED_EMPTY;
385
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700386 /** @hide Should this process state be considered a background state? */
387 public static final boolean isProcStateBackground(int procState) {
388 return procState >= PROCESS_STATE_BACKUP;
389 }
390
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700391 /** @hide requestType for assist context: only basic information. */
392 public static final int ASSIST_CONTEXT_BASIC = 0;
393
394 /** @hide requestType for assist context: generate full AssistStructure. */
395 public static final int ASSIST_CONTEXT_FULL = 1;
396
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700397 /** @hide Flag for registerUidObserver: report changes in process state. */
398 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
399
400 /** @hide Flag for registerUidObserver: report uid gone. */
401 public static final int UID_OBSERVER_GONE = 1<<1;
402
403 /** @hide Flag for registerUidObserver: report uid has become idle. */
404 public static final int UID_OBSERVER_IDLE = 1<<2;
405
406 /** @hide Flag for registerUidObserver: report uid has become active. */
407 public static final int UID_OBSERVER_ACTIVE = 1<<3;
408
409 /** @hide Mode for {@link IActivityManager#getAppStartMode}: normal free-to-run operation. */
410 public static final int APP_START_MODE_NORMAL = 0;
411
412 /** @hide Mode for {@link IActivityManager#getAppStartMode}: delay running until later. */
413 public static final int APP_START_MODE_DELAYED = 1;
414
415 /** @hide Mode for {@link IActivityManager#getAppStartMode}: disable/cancel pending
416 * launches. */
417 public static final int APP_START_MODE_DISABLED = 2;
418
Benjamin Franz43261142015-02-11 15:59:44 +0000419 /**
420 * Lock task mode is not active.
421 */
422 public static final int LOCK_TASK_MODE_NONE = 0;
423
424 /**
425 * Full lock task mode is active.
426 */
427 public static final int LOCK_TASK_MODE_LOCKED = 1;
428
429 /**
430 * App pinning mode is active.
431 */
432 public static final int LOCK_TASK_MODE_PINNED = 2;
433
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700434 Point mAppTaskThumbnailSize;
435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 /*package*/ ActivityManager(Context context, Handler handler) {
437 mContext = context;
438 mHandler = handler;
439 }
440
441 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700442 * Screen compatibility mode: the application most always run in
443 * compatibility mode.
444 * @hide
445 */
446 public static final int COMPAT_MODE_ALWAYS = -1;
447
448 /**
449 * Screen compatibility mode: the application can never run in
450 * compatibility mode.
451 * @hide
452 */
453 public static final int COMPAT_MODE_NEVER = -2;
454
455 /**
456 * Screen compatibility mode: unknown.
457 * @hide
458 */
459 public static final int COMPAT_MODE_UNKNOWN = -3;
460
461 /**
462 * Screen compatibility mode: the application currently has compatibility
463 * mode disabled.
464 * @hide
465 */
466 public static final int COMPAT_MODE_DISABLED = 0;
467
468 /**
469 * Screen compatibility mode: the application currently has compatibility
470 * mode enabled.
471 * @hide
472 */
473 public static final int COMPAT_MODE_ENABLED = 1;
474
475 /**
476 * Screen compatibility mode: request to toggle the application's
477 * compatibility mode.
478 * @hide
479 */
480 public static final int COMPAT_MODE_TOGGLE = 2;
481
Wale Ogunwale3797c222015-10-27 14:21:58 -0700482 /** @hide */
483 public static class StackId {
484 /** Invalid stack ID. */
485 public static final int INVALID_STACK_ID = -1;
Chong Zhang5dcb2752015-08-18 13:50:26 -0700486
Wale Ogunwale3797c222015-10-27 14:21:58 -0700487 /** First static stack ID. */
488 public static final int FIRST_STATIC_STACK_ID = 0;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700489
Wale Ogunwale3797c222015-10-27 14:21:58 -0700490 /** Home activity stack ID. */
491 public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700492
Wale Ogunwale3797c222015-10-27 14:21:58 -0700493 /** ID of stack where fullscreen activities are normally launched into. */
494 public static final int FULLSCREEN_WORKSPACE_STACK_ID = 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700495
Wale Ogunwale3797c222015-10-27 14:21:58 -0700496 /** ID of stack where freeform/resized activities are normally launched into. */
497 public static final int FREEFORM_WORKSPACE_STACK_ID = FULLSCREEN_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700498
Wale Ogunwale3797c222015-10-27 14:21:58 -0700499 /** ID of stack that occupies a dedicated region of the screen. */
500 public static final int DOCKED_STACK_ID = FREEFORM_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700501
Wale Ogunwale3797c222015-10-27 14:21:58 -0700502 /** ID of stack that always on top (always visible) when it exist. */
503 public static final int PINNED_STACK_ID = DOCKED_STACK_ID + 1;
Wale Ogunwale99db1862015-10-23 20:08:22 -0700504
Wale Ogunwale3797c222015-10-27 14:21:58 -0700505 /** Last static stack stack ID. */
506 public static final int LAST_STATIC_STACK_ID = PINNED_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700507
Wale Ogunwale3797c222015-10-27 14:21:58 -0700508 /** Start of ID range used by stacks that are created dynamically. */
509 public static final int FIRST_DYNAMIC_STACK_ID = LAST_STATIC_STACK_ID + 1;
510
511 public static boolean isStaticStack(int stackId) {
512 return stackId >= FIRST_STATIC_STACK_ID && stackId <= LAST_STATIC_STACK_ID;
513 }
514
515 /**
516 * Returns true if the activities contained in the input stack display a shadow around
517 * their border.
518 */
519 public static boolean hasWindowShadow(int stackId) {
520 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID;
521 }
522
523 /**
524 * Returns true if the activities contained in the input stack display a decor view.
525 */
526 public static boolean hasWindowDecor(int stackId) {
527 return stackId == FREEFORM_WORKSPACE_STACK_ID;
528 }
529
530 /**
531 * Returns true if the tasks contained in the stack can be resized independently of the
532 * stack.
533 */
534 public static boolean isTaskResizeAllowed(int stackId) {
535 return stackId == FREEFORM_WORKSPACE_STACK_ID;
536 }
537
Wale Ogunwale807d8822015-12-15 17:05:09 -0800538 /** Returns true if the task bounds should persist across power cycles. */
Wale Ogunwale3797c222015-10-27 14:21:58 -0700539 public static boolean persistTaskBounds(int stackId) {
Wale Ogunwale807d8822015-12-15 17:05:09 -0800540 return stackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700541 }
542
543 /**
544 * Returns true if dynamic stacks are allowed to be visible behind the input stack.
545 */
546 public static boolean isDynamicStacksVisibleBehindAllowed(int stackId) {
547 return stackId == PINNED_STACK_ID;
548 }
549
550 /**
551 * Returns true if we try to maintain focus in the current stack when the top activity
552 * finishes.
553 */
554 public static boolean keepFocusInStackIfPossible(int stackId) {
555 return stackId == FREEFORM_WORKSPACE_STACK_ID
556 || stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID;
557 }
558
559 /**
560 * Returns true if Stack size is affected by the docked stack changing size.
561 */
562 public static boolean isResizeableByDockedStack(int stackId) {
563 return isStaticStack(stackId) &&
564 stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID;
565 }
566
567 /**
568 * Returns true if the size of tasks in the input stack are affected by the docked stack
569 * changing size.
570 */
571 public static boolean isTaskResizeableByDockedStack(int stackId) {
572 return isStaticStack(stackId) && stackId != FREEFORM_WORKSPACE_STACK_ID
573 && stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID;
574 }
575
576 /**
Jorim Jaggie9098022016-01-27 19:29:40 -0800577 * Returns true if the windows of tasks being moved to the target stack from the source
578 * stack should be replaced, meaning that window manager will keep the old window around
579 * until the new is ready.
Wale Ogunwale3797c222015-10-27 14:21:58 -0700580 */
Jorim Jaggie9098022016-01-27 19:29:40 -0800581 public static boolean replaceWindowsOnTaskMove(int sourceStackId, int targetStackId) {
582 return sourceStackId == FREEFORM_WORKSPACE_STACK_ID
583 || targetStackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700584 }
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800585
586 /**
Robert Carre6275582016-02-29 15:45:45 -0800587 * Return whether a stackId is a stack containing floating windows. Floating windows
588 * are laid out differently as they are allowed to extend past the display bounds
589 * without overscan insets.
590 */
591 public static boolean tasksAreFloating(int stackId) {
592 return stackId == FREEFORM_WORKSPACE_STACK_ID
593 || stackId == PINNED_STACK_ID;
594 }
595
596 /**
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800597 * Returns true if animation specs should be constructed for app transition that moves
598 * the task to the specified stack.
599 */
600 public static boolean useAnimationSpecForAppTransition(int stackId) {
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800601
602 // TODO: INVALID_STACK_ID is also animated because we don't persist stack id's across
603 // reboots.
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800604 return stackId == FREEFORM_WORKSPACE_STACK_ID
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800605 || stackId == FULLSCREEN_WORKSPACE_STACK_ID || stackId == DOCKED_STACK_ID
606 || stackId == INVALID_STACK_ID;
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800607 }
Wale Ogunwaled045c822015-12-02 09:14:28 -0800608
609 /** Returns true if the windows in the stack can receive input keys. */
610 public static boolean canReceiveKeys(int stackId) {
611 return stackId != PINNED_STACK_ID;
612 }
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800613
Chong Zhang75b37202015-12-04 14:16:36 -0800614 /**
615 * Returns true if the stack can be visible above lockscreen.
616 */
617 public static boolean isAllowedOverLockscreen(int stackId) {
618 return stackId == HOME_STACK_ID || stackId == FULLSCREEN_WORKSPACE_STACK_ID;
619 }
620
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800621 public static boolean isAlwaysOnTop(int stackId) {
622 return stackId == PINNED_STACK_ID;
623 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800624
625 /**
626 * Returns true if the top task in the task is allowed to return home when finished and
627 * there are other tasks in the stack.
628 */
629 public static boolean allowTopTaskToReturnHome(int stackId) {
630 return stackId != PINNED_STACK_ID;
631 }
Wale Ogunwalecacfaa22016-01-15 11:26:08 -0800632
633 /**
634 * Returns true if the stack should be resized to match the bounds specified by
635 * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack.
636 */
637 public static boolean resizeStackWithLaunchBounds(int stackId) {
638 return stackId == PINNED_STACK_ID;
639 }
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -0800640
641 /**
642 * Returns true if any visible windows belonging to apps in this stack should be kept on
643 * screen when the app is killed due to something like the low memory killer.
644 */
645 public static boolean keepVisibleDeadAppWindowOnScreen(int stackId) {
646 return stackId != PINNED_STACK_ID;
647 }
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800648
649 /**
650 * Returns true if the backdrop on the client side should match the frame of the window.
651 * Returns false, if the backdrop should be fullscreen.
652 */
653 public static boolean useWindowFrameForBackdrop(int stackId) {
654 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID;
655 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800656
657 /**
658 * Returns true if a window from the specified stack with {@param stackId} are normally
659 * fullscreen, i. e. they can become the top opaque fullscreen window, meaning that it
660 * controls system bars, lockscreen occluded/dismissing state, screen rotation animation,
661 * etc.
662 */
663 public static boolean normallyFullscreenWindows(int stackId) {
664 return stackId != PINNED_STACK_ID && stackId != FREEFORM_WORKSPACE_STACK_ID
665 && stackId != DOCKED_STACK_ID;
666 }
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800667
668 /**
669 * Returns true if the input stack id should only be present on a device that supports
670 * multi-window mode.
671 * @see android.app.ActivityManager#supportsMultiWindow
672 */
673 public static boolean isMultiWindowStack(int stackId) {
674 return isStaticStack(stackId) || stackId == PINNED_STACK_ID
675 || stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == DOCKED_STACK_ID;
676 }
Wale Ogunwale3797c222015-10-27 14:21:58 -0700677 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700678
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700679 /**
680 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
681 * specifies the position of the created docked stack at the top half of the screen if
682 * in portrait mode or at the left half of the screen if in landscape mode.
683 * @hide
684 */
685 public static final int DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT = 0;
686
687 /**
688 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
689 * specifies the position of the created docked stack at the bottom half of the screen if
690 * in portrait mode or at the right half of the screen if in landscape mode.
691 * @hide
692 */
693 public static final int DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT = 1;
694
Chong Zhang87b21722015-09-21 15:39:51 -0700695 /**
696 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700697 * that the resize doesn't need to preserve the window, and can be skipped if bounds
698 * is unchanged. This mode is used by window manager in most cases.
Chong Zhang87b21722015-09-21 15:39:51 -0700699 * @hide
700 */
701 public static final int RESIZE_MODE_SYSTEM = 0;
702
703 /**
704 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700705 * that the resize should preserve the window if possible.
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700706 * @hide
707 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700708 public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0);
Chong Zhang87b21722015-09-21 15:39:51 -0700709
710 /**
711 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
712 * that the resize should be performed even if the bounds appears unchanged.
713 * @hide
714 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700715 public static final int RESIZE_MODE_FORCED = (0x1 << 1);
716
717 /**
718 * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window
719 * manager during a screen rotation.
720 * @hide
721 */
722 public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW;
723
724 /**
725 * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the
726 * resize is due to a drag action.
727 * @hide
728 */
729 public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW;
730
731 /**
732 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
733 * that the resize should preserve the window if possible, and should not be skipped
734 * even if the bounds is unchanged. Usually used to force a resizing when a drag action
735 * is ending.
736 * @hide
737 */
738 public static final int RESIZE_MODE_USER_FORCED =
739 RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED;
Chong Zhang87b21722015-09-21 15:39:51 -0700740
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700741 /** @hide */
742 public int getFrontActivityScreenCompatMode() {
743 try {
744 return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode();
745 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700746 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700747 }
748 }
749
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700750 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700751 public void setFrontActivityScreenCompatMode(int mode) {
752 try {
753 ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode);
754 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700755 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700756 }
757 }
758
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700759 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700760 public int getPackageScreenCompatMode(String packageName) {
761 try {
762 return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName);
763 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700764 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700765 }
766 }
767
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700768 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700769 public void setPackageScreenCompatMode(String packageName, int mode) {
770 try {
771 ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode);
772 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700773 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700774 }
775 }
776
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700777 /** @hide */
778 public boolean getPackageAskScreenCompat(String packageName) {
779 try {
780 return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName);
781 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700782 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700783 }
784 }
785
786 /** @hide */
787 public void setPackageAskScreenCompat(String packageName, boolean ask) {
788 try {
789 ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask);
790 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700791 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700792 }
793 }
794
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700795 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700796 * Return the approximate per-application memory class of the current
797 * device. This gives you an idea of how hard a memory limit you should
798 * impose on your application to let the overall system work best. The
799 * returned value is in megabytes; the baseline Android memory class is
800 * 16 (which happens to be the Java heap limit of those devices); some
801 * device with more memory may return 24 or even higher numbers.
802 */
803 public int getMemoryClass() {
804 return staticGetMemoryClass();
805 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700806
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700807 /** @hide */
808 static public int staticGetMemoryClass() {
809 // Really brain dead right now -- just take this from the configured
810 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -0800811 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -0800812 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
813 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
814 }
815 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800816 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700817
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800818 /**
819 * Return the approximate per-application memory class of the current
820 * device when an application is running with a large heap. This is the
821 * space available for memory-intensive applications; most applications
822 * should not need this amount of memory, and should instead stay with the
823 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
824 * This may be the same size as {@link #getMemoryClass()} on memory
825 * constrained devices, or it may be significantly larger on devices with
826 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800827 *
828 * <p>The is the size of the application's Dalvik heap if it has
829 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800830 */
831 public int getLargeMemoryClass() {
832 return staticGetLargeMemoryClass();
833 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700834
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800835 /** @hide */
836 static public int staticGetLargeMemoryClass() {
837 // Really brain dead right now -- just take this from the configured
838 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700839 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -0700840 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700841 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700842
843 /**
844 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
845 * is ultimately up to the device configuration, but currently it generally means
846 * something in the class of a 512MB device with about a 800x480 or less screen.
847 * This is mostly intended to be used by apps to determine whether they should turn
848 * off certain features that require more RAM.
849 */
850 public boolean isLowRamDevice() {
851 return isLowRamDeviceStatic();
852 }
853
854 /** @hide */
855 public static boolean isLowRamDeviceStatic() {
Christopher Tate2f61f912013-08-20 13:55:50 -0700856 return "true".equals(SystemProperties.get("ro.config.low_ram", "false"));
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700857 }
858
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700859 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -0700860 * Used by persistent processes to determine if they are running on a
861 * higher-end device so should be okay using hardware drawing acceleration
862 * (which tends to consume a lot more RAM).
863 * @hide
864 */
Jeff Brown98365d72012-08-19 20:30:52 -0700865 static public boolean isHighEndGfx() {
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700866 return !isLowRamDeviceStatic() &&
867 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -0700868 }
869
870 /**
Dianne Hackborn852975d2014-08-22 17:42:43 -0700871 * Return the maximum number of recents entries that we will maintain and show.
872 * @hide
873 */
874 static public int getMaxRecentTasksStatic() {
875 if (gMaxRecentTasks < 0) {
876 return gMaxRecentTasks = isLowRamDeviceStatic() ? 50 : 100;
877 }
878 return gMaxRecentTasks;
879 }
880
881 /**
882 * Return the default limit on the number of recents that an app can make.
883 * @hide
884 */
885 static public int getDefaultAppRecentsLimitStatic() {
886 return getMaxRecentTasksStatic() / 6;
887 }
888
889 /**
890 * Return the maximum limit on the number of recents that an app can make.
891 * @hide
892 */
893 static public int getMaxAppRecentsLimitStatic() {
894 return getMaxRecentTasksStatic() / 2;
895 }
896
897 /**
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800898 * Returns true if the system supports at least one form of multi-window.
899 * E.g. freeform, split-screen, picture-in-picture.
900 * @hide
901 */
902 static public boolean supportsMultiWindow() {
903 return !isLowRamDeviceStatic()
904 && Resources.getSystem().getBoolean(
905 com.android.internal.R.bool.config_supportsMultiWindow);
906 }
907
908 /**
Winson Chung1147c402014-05-14 11:05:00 -0700909 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -0700910 */
Winson Chunga449dc02014-05-16 11:15:04 -0700911 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -0700912 /** @hide */
913 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
914 private static final String ATTR_TASKDESCRIPTIONLABEL =
915 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +0000916 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -0700917 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +0000918 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
919 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Craig Mautner648f69b2014-09-18 14:16:26 -0700920 private static final String ATTR_TASKDESCRIPTIONICONFILENAME =
921 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
922
Winson Chunga449dc02014-05-16 11:15:04 -0700923 private String mLabel;
924 private Bitmap mIcon;
Craig Mautner648f69b2014-09-18 14:16:26 -0700925 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -0700926 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +0000927 private int mColorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -0700928
929 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700930 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700931 *
Winson Chunga449dc02014-05-16 11:15:04 -0700932 * @param label A label and description of the current state of this task.
933 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +0000934 * @param colorPrimary A color to override the theme's primary color. This color must be
935 * opaque.
Winson Chung03a9bae2014-05-02 09:56:12 -0700936 */
Winson Chunga449dc02014-05-16 11:15:04 -0700937 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Winson Chung1af8eda2016-02-05 17:55:56 +0000938 this(label, icon, null, colorPrimary, 0);
Winson Chunga449dc02014-05-16 11:15:04 -0700939 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
940 throw new RuntimeException("A TaskDescription's primary color should be opaque");
941 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700942 }
943
Winson Chung03a9bae2014-05-02 09:56:12 -0700944 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700945 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700946 *
947 * @param label A label and description of the current state of this activity.
948 * @param icon An icon that represents the current state of this activity.
949 */
Winson Chunga449dc02014-05-16 11:15:04 -0700950 public TaskDescription(String label, Bitmap icon) {
Winson Chung1af8eda2016-02-05 17:55:56 +0000951 this(label, icon, null, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -0700952 }
953
954 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700955 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700956 *
957 * @param label A label and description of the current state of this activity.
958 */
Winson Chunga449dc02014-05-16 11:15:04 -0700959 public TaskDescription(String label) {
Winson Chung1af8eda2016-02-05 17:55:56 +0000960 this(label, null, null, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -0700961 }
962
Winson Chunga449dc02014-05-16 11:15:04 -0700963 /**
964 * Creates an empty TaskDescription.
965 */
966 public TaskDescription() {
Winson Chung1af8eda2016-02-05 17:55:56 +0000967 this(null, null, null, 0, 0);
968 }
969
970 /** @hide */
971 public TaskDescription(String label, Bitmap icon, String iconFilename, int colorPrimary,
972 int colorBackground) {
973 mLabel = label;
974 mIcon = icon;
975 mIconFilename = iconFilename;
976 mColorPrimary = colorPrimary;
977 mColorBackground = colorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -0700978 }
979
Winson Chunga449dc02014-05-16 11:15:04 -0700980 /**
981 * Creates a copy of another TaskDescription.
982 */
983 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -0800984 copyFrom(td);
985 }
986
987 /**
988 * Copies this the values from another TaskDescription.
989 * @hide
990 */
991 public void copyFrom(TaskDescription other) {
992 mLabel = other.mLabel;
993 mIcon = other.mIcon;
994 mIconFilename = other.mIconFilename;
995 mColorPrimary = other.mColorPrimary;
996 mColorBackground = other.mColorBackground;
Winson Chunga449dc02014-05-16 11:15:04 -0700997 }
998
999 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001000 readFromParcel(source);
1001 }
1002
1003 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001004 * Sets the label for this task description.
1005 * @hide
1006 */
1007 public void setLabel(String label) {
1008 mLabel = label;
1009 }
1010
1011 /**
1012 * Sets the primary color for this task description.
1013 * @hide
1014 */
1015 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001016 // Ensure that the given color is valid
1017 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1018 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1019 }
1020 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001021 }
1022
1023 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001024 * Sets the background color for this task description.
1025 * @hide
1026 */
1027 public void setBackgroundColor(int backgroundColor) {
1028 // Ensure that the given color is valid
1029 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1030 throw new RuntimeException("A TaskDescription's background color should be opaque");
1031 }
1032 mColorBackground = backgroundColor;
1033 }
1034
1035 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001036 * Sets the icon for this task description.
1037 * @hide
1038 */
1039 public void setIcon(Bitmap icon) {
1040 mIcon = icon;
1041 }
1042
1043 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001044 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1045 * bitmap.
1046 * @hide
1047 */
1048 public void setIconFilename(String iconFilename) {
1049 mIconFilename = iconFilename;
1050 mIcon = null;
1051 }
1052
1053 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001054 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001055 */
Winson Chunga449dc02014-05-16 11:15:04 -07001056 public String getLabel() {
1057 return mLabel;
1058 }
1059
1060 /**
1061 * @return The icon that represents the current state of this task.
1062 */
1063 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001064 if (mIcon != null) {
1065 return mIcon;
1066 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001067 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001068 }
1069
1070 /** @hide */
1071 public String getIconFilename() {
1072 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001073 }
1074
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001075 /** @hide */
1076 public Bitmap getInMemoryIcon() {
1077 return mIcon;
1078 }
1079
1080 /** @hide */
Suprabh Shukla23593142015-11-03 17:31:15 -08001081 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001082 if (iconFilename != null) {
1083 try {
Winson Chung1af8eda2016-02-05 17:55:56 +00001084 return ActivityManagerNative.getDefault().getTaskDescriptionIcon(iconFilename,
1085 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001086 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001087 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001088 }
1089 }
1090 return null;
1091 }
1092
Winson Chunga449dc02014-05-16 11:15:04 -07001093 /**
1094 * @return The color override on the theme's primary color.
1095 */
1096 public int getPrimaryColor() {
1097 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001098 }
1099
Winson Chung1af8eda2016-02-05 17:55:56 +00001100 /**
1101 * @return The background color.
1102 * @hide
1103 */
1104 public int getBackgroundColor() {
1105 return mColorBackground;
1106 }
1107
Craig Mautner648f69b2014-09-18 14:16:26 -07001108 /** @hide */
1109 public void saveToXml(XmlSerializer out) throws IOException {
1110 if (mLabel != null) {
1111 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1112 }
1113 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001114 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1115 Integer.toHexString(mColorPrimary));
1116 }
1117 if (mColorBackground != 0) {
1118 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1119 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001120 }
1121 if (mIconFilename != null) {
1122 out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename);
1123 }
1124 }
1125
1126 /** @hide */
1127 public void restoreFromXml(String attrName, String attrValue) {
1128 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1129 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001130 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001131 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001132 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1133 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Craig Mautner648f69b2014-09-18 14:16:26 -07001134 } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) {
1135 setIconFilename(attrValue);
1136 }
1137 }
1138
Winson Chung03a9bae2014-05-02 09:56:12 -07001139 @Override
1140 public int describeContents() {
1141 return 0;
1142 }
1143
1144 @Override
1145 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001146 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001147 dest.writeInt(0);
1148 } else {
1149 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001150 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001151 }
Winson Chunga449dc02014-05-16 11:15:04 -07001152 if (mIcon == null) {
1153 dest.writeInt(0);
1154 } else {
1155 dest.writeInt(1);
1156 mIcon.writeToParcel(dest, 0);
1157 }
1158 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001159 dest.writeInt(mColorBackground);
Craig Mautner648f69b2014-09-18 14:16:26 -07001160 if (mIconFilename == null) {
1161 dest.writeInt(0);
1162 } else {
1163 dest.writeInt(1);
1164 dest.writeString(mIconFilename);
1165 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001166 }
1167
1168 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001169 mLabel = source.readInt() > 0 ? source.readString() : null;
1170 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
1171 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001172 mColorBackground = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001173 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001174 }
1175
Winson Chunga449dc02014-05-16 11:15:04 -07001176 public static final Creator<TaskDescription> CREATOR
1177 = new Creator<TaskDescription>() {
1178 public TaskDescription createFromParcel(Parcel source) {
1179 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001180 }
Winson Chunga449dc02014-05-16 11:15:04 -07001181 public TaskDescription[] newArray(int size) {
1182 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001183 }
1184 };
1185
1186 @Override
1187 public String toString() {
Winson Chunga449dc02014-05-16 11:15:04 -07001188 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
Winson Chung1af8eda2016-02-05 17:55:56 +00001189 " IconFilename: " + mIconFilename + " colorPrimary: " + mColorPrimary +
1190 " colorBackground: " + mColorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -07001191 }
1192 }
1193
1194 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 * Information you can retrieve about tasks that the user has most recently
1196 * started or visited.
1197 */
1198 public static class RecentTaskInfo implements Parcelable {
1199 /**
1200 * If this task is currently running, this is the identifier for it.
1201 * If it is not running, this will be -1.
1202 */
1203 public int id;
1204
1205 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001206 * The true identifier of this task, valid even if it is not running.
1207 */
1208 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001209
Dianne Hackbornd94df452011-02-16 18:53:31 -08001210 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001211 * The original Intent used to launch the task. You can use this
1212 * Intent to re-launch the task (if it is no longer running) or bring
1213 * the current task to the front.
1214 */
1215 public Intent baseIntent;
1216
1217 /**
1218 * If this task was started from an alias, this is the actual
1219 * activity component that was initially started; the component of
1220 * the baseIntent in this case is the name of the actual activity
1221 * implementation that the alias referred to. Otherwise, this is null.
1222 */
1223 public ComponentName origActivity;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001224
1225 /**
James Cook4d0ef042015-07-09 14:28:23 -07001226 * The actual activity component that started the task.
1227 * @hide
1228 */
1229 @Nullable
1230 public ComponentName realActivity;
1231
1232 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001233 * Description of the task's last state.
1234 */
1235 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001236
1237 /**
1238 * The id of the ActivityStack this Task was on most recently.
Craig Mautner27030522013-08-26 12:25:36 -07001239 * @hide
Craig Mautner6d90fed2013-05-22 15:03:10 -07001240 */
1241 public int stackId;
1242
Kenny Guy82326a92014-03-17 17:16:06 +00001243 /**
Craig Mautner2fbd7542014-03-21 09:34:07 -07001244 * The id of the user the task was running as.
Kenny Guy82326a92014-03-17 17:16:06 +00001245 * @hide
1246 */
1247 public int userId;
1248
Craig Mautner2fbd7542014-03-21 09:34:07 -07001249 /**
Winson Chungffa2ec62014-07-03 15:54:42 -07001250 * The first time this task was active.
1251 * @hide
1252 */
1253 public long firstActiveTime;
1254
1255 /**
Winson Chungf1fbd772014-06-24 18:06:58 -07001256 * The last time this task was active.
1257 * @hide
1258 */
1259 public long lastActiveTime;
1260
1261 /**
Winson Chung03a9bae2014-05-02 09:56:12 -07001262 * The recent activity values for the highest activity in the stack to have set the values.
Winson Chunga449dc02014-05-16 11:15:04 -07001263 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
Craig Mautner2fbd7542014-03-21 09:34:07 -07001264 */
Winson Chunga449dc02014-05-16 11:15:04 -07001265 public TaskDescription taskDescription;
Craig Mautner2fbd7542014-03-21 09:34:07 -07001266
Craig Mautnera228ae92014-07-09 05:44:55 -07001267 /**
1268 * Task affiliation for grouping with other tasks.
Craig Mautnera228ae92014-07-09 05:44:55 -07001269 */
1270 public int affiliatedTaskId;
1271
Winson Chungec396d62014-08-06 17:08:00 -07001272 /**
1273 * Task affiliation color of the source task with the affiliated task id.
1274 *
1275 * @hide
1276 */
1277 public int affiliatedTaskColor;
1278
Wale Ogunwale6035e012015-04-14 15:54:10 -07001279 /**
1280 * The component launched as the first activity in the task.
1281 * This can be considered the "application" of this task.
1282 */
1283 public ComponentName baseActivity;
1284
1285 /**
1286 * The activity component at the top of the history stack of the task.
1287 * This is what the user is currently doing.
1288 */
1289 public ComponentName topActivity;
1290
1291 /**
1292 * Number of activities in this task.
1293 */
1294 public int numActivities;
1295
Winson2dd76942015-11-02 09:20:01 -08001296 /**
1297 * The bounds of the task.
1298 * @hide
1299 */
1300 public Rect bounds;
1301
Wale Ogunwale21b60582016-01-27 12:34:16 -08001302 /**
1303 * True if the task can go in the docked stack.
1304 * @hide
1305 */
1306 public boolean isDockable;
1307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 public RecentTaskInfo() {
1309 }
1310
Craig Mautner6d90fed2013-05-22 15:03:10 -07001311 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 public int describeContents() {
1313 return 0;
1314 }
1315
Craig Mautner6d90fed2013-05-22 15:03:10 -07001316 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 public void writeToParcel(Parcel dest, int flags) {
1318 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001319 dest.writeInt(persistentId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 if (baseIntent != null) {
1321 dest.writeInt(1);
1322 baseIntent.writeToParcel(dest, 0);
1323 } else {
1324 dest.writeInt(0);
1325 }
1326 ComponentName.writeToParcel(origActivity, dest);
James Cook4d0ef042015-07-09 14:28:23 -07001327 ComponentName.writeToParcel(realActivity, dest);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001328 TextUtils.writeToParcel(description, dest,
1329 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
Winson Chunga449dc02014-05-16 11:15:04 -07001330 if (taskDescription != null) {
Craig Mautner2fbd7542014-03-21 09:34:07 -07001331 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001332 taskDescription.writeToParcel(dest, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001333 } else {
1334 dest.writeInt(0);
Craig Mautner2fbd7542014-03-21 09:34:07 -07001335 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001336 dest.writeInt(stackId);
Kenny Guy82326a92014-03-17 17:16:06 +00001337 dest.writeInt(userId);
Winson Chungffa2ec62014-07-03 15:54:42 -07001338 dest.writeLong(firstActiveTime);
Winson Chungf1fbd772014-06-24 18:06:58 -07001339 dest.writeLong(lastActiveTime);
Craig Mautnera228ae92014-07-09 05:44:55 -07001340 dest.writeInt(affiliatedTaskId);
Winson Chungec396d62014-08-06 17:08:00 -07001341 dest.writeInt(affiliatedTaskColor);
Wale Ogunwale6035e012015-04-14 15:54:10 -07001342 ComponentName.writeToParcel(baseActivity, dest);
1343 ComponentName.writeToParcel(topActivity, dest);
1344 dest.writeInt(numActivities);
Winson2dd76942015-11-02 09:20:01 -08001345 if (bounds != null) {
1346 dest.writeInt(1);
1347 bounds.writeToParcel(dest, 0);
1348 } else {
1349 dest.writeInt(0);
1350 }
Wale Ogunwale21b60582016-01-27 12:34:16 -08001351 dest.writeInt(isDockable ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 }
1353
1354 public void readFromParcel(Parcel source) {
1355 id = source.readInt();
Dianne Hackbornd94df452011-02-16 18:53:31 -08001356 persistentId = source.readInt();
Craig Mautner688b5102014-03-27 16:55:03 -07001357 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 origActivity = ComponentName.readFromParcel(source);
James Cook4d0ef042015-07-09 14:28:23 -07001359 realActivity = ComponentName.readFromParcel(source);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001360 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Winson Chunga449dc02014-05-16 11:15:04 -07001361 taskDescription = source.readInt() > 0 ?
1362 TaskDescription.CREATOR.createFromParcel(source) : null;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001363 stackId = source.readInt();
Kenny Guy82326a92014-03-17 17:16:06 +00001364 userId = source.readInt();
Winson Chungffa2ec62014-07-03 15:54:42 -07001365 firstActiveTime = source.readLong();
Winson Chungf1fbd772014-06-24 18:06:58 -07001366 lastActiveTime = source.readLong();
Craig Mautnera228ae92014-07-09 05:44:55 -07001367 affiliatedTaskId = source.readInt();
Winson Chungec396d62014-08-06 17:08:00 -07001368 affiliatedTaskColor = source.readInt();
Wale Ogunwale6035e012015-04-14 15:54:10 -07001369 baseActivity = ComponentName.readFromParcel(source);
1370 topActivity = ComponentName.readFromParcel(source);
1371 numActivities = source.readInt();
Winson2dd76942015-11-02 09:20:01 -08001372 bounds = source.readInt() > 0 ?
1373 Rect.CREATOR.createFromParcel(source) : null;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001374 isDockable = source.readInt() == 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 public static final Creator<RecentTaskInfo> CREATOR
1378 = new Creator<RecentTaskInfo>() {
1379 public RecentTaskInfo createFromParcel(Parcel source) {
1380 return new RecentTaskInfo(source);
1381 }
1382 public RecentTaskInfo[] newArray(int size) {
1383 return new RecentTaskInfo[size];
1384 }
1385 };
1386
1387 private RecentTaskInfo(Parcel source) {
1388 readFromParcel(source);
1389 }
1390 }
1391
1392 /**
1393 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1394 * that have set their
1395 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1396 */
1397 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001400 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001401 * recent tasks that currently are not available to the user.
1402 */
1403 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001404
1405 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001406 * Provides a list that contains recent tasks for all
1407 * profiles of a user.
Kenny Guy82326a92014-03-17 17:16:06 +00001408 * @hide
1409 */
Kenny Guy2a764942014-04-02 13:29:20 +01001410 public static final int RECENT_INCLUDE_PROFILES = 0x0004;
Kenny Guy82326a92014-03-17 17:16:06 +00001411
1412 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001413 * Ignores all tasks that are on the home stack.
1414 * @hide
1415 */
1416 public static final int RECENT_IGNORE_HOME_STACK_TASKS = 0x0008;
1417
1418 /**
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001419 * Ignores the top task in the docked stack.
Winson Chung0583d3d2015-12-18 10:03:12 -05001420 * @hide
1421 */
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001422 public static final int RECENT_INGORE_DOCKED_STACK_TOP_TASK = 0x0010;
Winson Chung0583d3d2015-12-18 10:03:12 -05001423
1424 /**
1425 * Ignores all tasks that are on the pinned stack.
1426 * @hide
1427 */
1428 public static final int RECENT_INGORE_PINNED_STACK_TASKS = 0x0020;
1429
1430 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001431 * <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 -08001432 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001433 *
1434 * <p><b>Note: this method is only intended for debugging and presenting
1435 * task management user interfaces</b>. This should never be used for
1436 * core logic in an application, such as deciding between different
1437 * behaviors based on the information found here. Such uses are
1438 * <em>not</em> supported, and will likely break in the future. For
1439 * example, if multiple applications can be actively running at the
1440 * same time, assumptions made about the meaning of the data here for
1441 * purposes of control flow will be incorrect.</p>
1442 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001443 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001444 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001445 * document-centric recents means
1446 * it can leak personal information to the caller. For backwards compatibility,
1447 * it will still return a small subset of its data: at least the caller's
1448 * own tasks (though see {@link #getAppTasks()} for the correct supported
1449 * way to retrieve that information), and possibly some other tasks
1450 * such as home that are known to not be sensitive.
1451 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 * @param maxNum The maximum number of entries to return in the list. The
1453 * actual number returned may be smaller, depending on how many tasks the
1454 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001455 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001456 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001457 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 * @return Returns a list of RecentTaskInfo records describing each of
1459 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001461 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1463 throws SecurityException {
1464 try {
1465 return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07001466 flags, UserHandle.myUserId());
Amith Yamasani82644082012-08-03 13:09:11 -07001467 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001468 throw e.rethrowFromSystemServer();
Amith Yamasani82644082012-08-03 13:09:11 -07001469 }
1470 }
1471
1472 /**
1473 * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a
1474 * specific user. It requires holding
1475 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
1476 * @param maxNum The maximum number of entries to return in the list. The
1477 * actual number returned may be smaller, depending on how many tasks the
1478 * user has started and the maximum number the system can remember.
1479 * @param flags Information about what to return. May be any combination
1480 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
1481 *
1482 * @return Returns a list of RecentTaskInfo records describing each of
Vadim Tryshev35605752015-08-31 13:28:08 -07001483 * the recent tasks. Most recently activated tasks go first.
Amith Yamasani82644082012-08-03 13:09:11 -07001484 *
Amith Yamasani82644082012-08-03 13:09:11 -07001485 * @hide
1486 */
1487 public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId)
1488 throws SecurityException {
1489 try {
1490 return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
1491 flags, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001493 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 }
1495 }
1496
1497 /**
1498 * Information you can retrieve about a particular task that is currently
1499 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001500 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 * means that the user has gone to it and never closed it, but currently
1502 * the system may have killed its process and is only holding on to its
1503 * last state in order to restart it when the user returns.
1504 */
1505 public static class RunningTaskInfo implements Parcelable {
1506 /**
1507 * A unique identifier for this task.
1508 */
1509 public int id;
1510
1511 /**
Winson5510f6c2015-10-27 12:11:26 -07001512 * The stack that currently contains this task.
1513 * @hide
1514 */
1515 public int stackId;
1516
1517 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 * The component launched as the first activity in the task. This can
1519 * be considered the "application" of this task.
1520 */
1521 public ComponentName baseActivity;
1522
1523 /**
1524 * The activity component at the top of the history stack of the task.
1525 * This is what the user is currently doing.
1526 */
1527 public ComponentName topActivity;
1528
1529 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001530 * Thumbnail representation of the task's current state. Currently
1531 * always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 */
1533 public Bitmap thumbnail;
1534
1535 /**
1536 * Description of the task's current state.
1537 */
1538 public CharSequence description;
1539
1540 /**
1541 * Number of activities in this task.
1542 */
1543 public int numActivities;
1544
1545 /**
1546 * Number of activities that are currently running (not stopped
1547 * and persisted) in this task.
1548 */
1549 public int numRunning;
1550
Craig Mautnerc0fd8052013-09-19 11:20:17 -07001551 /**
1552 * Last time task was run. For sorting.
1553 * @hide
1554 */
1555 public long lastActiveTime;
1556
Wale Ogunwale21b60582016-01-27 12:34:16 -08001557 /**
1558 * True if the task can go in the docked stack.
1559 * @hide
1560 */
1561 public boolean isDockable;
1562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 public RunningTaskInfo() {
1564 }
1565
1566 public int describeContents() {
1567 return 0;
1568 }
1569
1570 public void writeToParcel(Parcel dest, int flags) {
1571 dest.writeInt(id);
Winson5510f6c2015-10-27 12:11:26 -07001572 dest.writeInt(stackId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 ComponentName.writeToParcel(baseActivity, dest);
1574 ComponentName.writeToParcel(topActivity, dest);
1575 if (thumbnail != null) {
1576 dest.writeInt(1);
1577 thumbnail.writeToParcel(dest, 0);
1578 } else {
1579 dest.writeInt(0);
1580 }
1581 TextUtils.writeToParcel(description, dest,
1582 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1583 dest.writeInt(numActivities);
1584 dest.writeInt(numRunning);
Jorim Jaggiaa6c5742016-03-01 14:10:14 +01001585 dest.writeInt(isDockable ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 }
1587
1588 public void readFromParcel(Parcel source) {
1589 id = source.readInt();
Winson5510f6c2015-10-27 12:11:26 -07001590 stackId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 baseActivity = ComponentName.readFromParcel(source);
1592 topActivity = ComponentName.readFromParcel(source);
1593 if (source.readInt() != 0) {
1594 thumbnail = Bitmap.CREATOR.createFromParcel(source);
1595 } else {
1596 thumbnail = null;
1597 }
1598 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
1599 numActivities = source.readInt();
1600 numRunning = source.readInt();
Jorim Jaggiaa6c5742016-03-01 14:10:14 +01001601 isDockable = source.readInt() != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
1605 public RunningTaskInfo createFromParcel(Parcel source) {
1606 return new RunningTaskInfo(source);
1607 }
1608 public RunningTaskInfo[] newArray(int size) {
1609 return new RunningTaskInfo[size];
1610 }
1611 };
1612
1613 private RunningTaskInfo(Parcel source) {
1614 readFromParcel(source);
1615 }
1616 }
Winson Chung1147c402014-05-14 11:05:00 -07001617
1618 /**
1619 * Get the list of tasks associated with the calling application.
1620 *
1621 * @return The list of tasks associated with the application making this call.
1622 * @throws SecurityException
1623 */
1624 public List<ActivityManager.AppTask> getAppTasks() {
1625 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
1626 List<IAppTask> appTasks;
1627 try {
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001628 appTasks = ActivityManagerNative.getDefault().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001629 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001630 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001631 }
1632 int numAppTasks = appTasks.size();
1633 for (int i = 0; i < numAppTasks; i++) {
1634 tasks.add(new AppTask(appTasks.get(i)));
1635 }
1636 return tasks;
1637 }
1638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 /**
Winson Chung48a10a52014-08-27 14:36:51 -07001640 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001641 * with {@link #addAppTask}.
1642 */
Winson Chung48a10a52014-08-27 14:36:51 -07001643 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001644 synchronized (this) {
1645 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07001646 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001647 }
1648 }
1649
1650 private void ensureAppTaskThumbnailSizeLocked() {
1651 if (mAppTaskThumbnailSize == null) {
1652 try {
1653 mAppTaskThumbnailSize = ActivityManagerNative.getDefault().getAppTaskThumbnailSize();
1654 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001655 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001656 }
1657 }
1658 }
1659
1660 /**
1661 * Add a new {@link AppTask} for the calling application. This will create a new
1662 * recents entry that is added to the <b>end</b> of all existing recents.
1663 *
1664 * @param activity The activity that is adding the entry. This is used to help determine
1665 * the context that the new recents entry will be in.
1666 * @param intent The Intent that describes the recents entry. This is the same Intent that
1667 * you would have used to launch the activity for it. In generally you will want to set
1668 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
1669 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
1670 * entry will exist without an activity, so it doesn't make sense to not retain it when
1671 * its activity disappears. The given Intent here also must have an explicit ComponentName
1672 * set on it.
1673 * @param description Optional additional description information.
1674 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07001675 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
1676 * recreated in your process, probably in a way you don't like, before the recents entry
1677 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001678 *
1679 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
1680 * most likely cause of failure is that there is no more room for more tasks for your app.
1681 */
1682 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
1683 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
1684 Point size;
1685 synchronized (this) {
1686 ensureAppTaskThumbnailSizeLocked();
1687 size = mAppTaskThumbnailSize;
1688 }
1689 final int tw = thumbnail.getWidth();
1690 final int th = thumbnail.getHeight();
1691 if (tw != size.x || th != size.y) {
1692 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
1693
1694 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
1695 float scale;
1696 float dx = 0, dy = 0;
1697 if (tw * size.x > size.y * th) {
1698 scale = (float) size.x / (float) th;
1699 dx = (size.y - tw * scale) * 0.5f;
1700 } else {
1701 scale = (float) size.y / (float) tw;
1702 dy = (size.x - th * scale) * 0.5f;
1703 }
1704 Matrix matrix = new Matrix();
1705 matrix.setScale(scale, scale);
1706 matrix.postTranslate((int) (dx + 0.5f), 0);
1707
1708 Canvas canvas = new Canvas(bm);
1709 canvas.drawBitmap(thumbnail, matrix, null);
1710 canvas.setBitmap(null);
1711
1712 thumbnail = bm;
1713 }
1714 if (description == null) {
1715 description = new TaskDescription();
1716 }
1717 try {
1718 return ActivityManagerNative.getDefault().addAppTask(activity.getActivityToken(),
1719 intent, description, thumbnail);
1720 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001721 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001722 }
1723 }
1724
1725 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 * Return a list of the tasks that are currently running, with
1727 * the most recent being first and older ones after in order. Note that
1728 * "running" does not mean any of the task's code is currently loaded or
1729 * activity -- the task may have been frozen by the system, so that it
1730 * can be restarted in its previous state when next brought to the
1731 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001732 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001733 * <p><b>Note: this method is only intended for debugging and presenting
1734 * task management user interfaces</b>. This should never be used for
1735 * core logic in an application, such as deciding between different
1736 * behaviors based on the information found here. Such uses are
1737 * <em>not</em> supported, and will likely break in the future. For
1738 * example, if multiple applications can be actively running at the
1739 * same time, assumptions made about the meaning of the data here for
1740 * purposes of control flow will be incorrect.</p>
1741 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001742 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001743 * is no longer available to third party
1744 * applications: the introduction of document-centric recents means
1745 * it can leak person information to the caller. For backwards compatibility,
1746 * it will still retu rn a small subset of its data: at least the caller's
1747 * own tasks, and possibly some other tasks
1748 * such as home that are known to not be sensitive.
1749 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07001750 * @param maxNum The maximum number of entries to return in the list. The
1751 * actual number returned may be smaller, depending on how many tasks the
1752 * user has started.
1753 *
1754 * @return Returns a list of RunningTaskInfo records describing each of
1755 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001756 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001757 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07001758 public List<RunningTaskInfo> getRunningTasks(int maxNum)
1759 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07001760 try {
1761 return ActivityManagerNative.getDefault().getTasks(maxNum, 0);
1762 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001763 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07001764 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07001765 }
1766
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001767 /**
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001768 * Completely remove the given task.
1769 *
1770 * @param taskId Identifier of the task to be removed.
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001771 * @return Returns true if the given task was found and removed.
1772 *
1773 * @hide
1774 */
Wale Ogunwaled54b5782014-10-23 15:55:23 -07001775 public boolean removeTask(int taskId) throws SecurityException {
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001776 try {
Wale Ogunwaled54b5782014-10-23 15:55:23 -07001777 return ActivityManagerNative.getDefault().removeTask(taskId);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001778 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001779 throw e.rethrowFromSystemServer();
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001780 }
1781 }
1782
Winsonc809cbb2015-11-02 12:06:15 -08001783 /**
1784 * Metadata related to the {@link TaskThumbnail}.
1785 *
1786 * @hide
1787 */
1788 public static class TaskThumbnailInfo implements Parcelable {
1789 /** @hide */
1790 public static final String ATTR_TASK_THUMBNAILINFO_PREFIX = "task_thumbnailinfo_";
1791 private static final String ATTR_TASK_WIDTH =
1792 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_width";
1793 private static final String ATTR_TASK_HEIGHT =
1794 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_height";
1795 private static final String ATTR_SCREEN_ORIENTATION =
1796 ATTR_TASK_THUMBNAILINFO_PREFIX + "screen_orientation";
1797
1798 public int taskWidth;
1799 public int taskHeight;
Winson21700932016-03-24 17:26:23 -07001800 public int screenOrientation = Configuration.ORIENTATION_UNDEFINED;
Winsonc809cbb2015-11-02 12:06:15 -08001801
1802 public TaskThumbnailInfo() {
1803 // Do nothing
1804 }
1805
1806 private TaskThumbnailInfo(Parcel source) {
1807 readFromParcel(source);
1808 }
1809
Winsonc6a2da02015-11-11 18:11:59 -08001810 /**
1811 * Resets this info state to the initial state.
1812 * @hide
1813 */
1814 public void reset() {
1815 taskWidth = 0;
1816 taskHeight = 0;
Winson21700932016-03-24 17:26:23 -07001817 screenOrientation = Configuration.ORIENTATION_UNDEFINED;
1818 }
1819
1820 /**
1821 * Copies from another ThumbnailInfo.
1822 */
1823 public void copyFrom(TaskThumbnailInfo o) {
1824 taskWidth = o.taskWidth;
1825 taskHeight = o.taskHeight;
1826 screenOrientation = o.screenOrientation;
Winsonc6a2da02015-11-11 18:11:59 -08001827 }
1828
Winsonc809cbb2015-11-02 12:06:15 -08001829 /** @hide */
1830 public void saveToXml(XmlSerializer out) throws IOException {
1831 out.attribute(null, ATTR_TASK_WIDTH, Integer.toString(taskWidth));
1832 out.attribute(null, ATTR_TASK_HEIGHT, Integer.toString(taskHeight));
1833 out.attribute(null, ATTR_SCREEN_ORIENTATION, Integer.toString(screenOrientation));
1834 }
1835
1836 /** @hide */
1837 public void restoreFromXml(String attrName, String attrValue) {
1838 if (ATTR_TASK_WIDTH.equals(attrName)) {
1839 taskWidth = Integer.parseInt(attrValue);
1840 } else if (ATTR_TASK_HEIGHT.equals(attrName)) {
1841 taskHeight = Integer.parseInt(attrValue);
1842 } else if (ATTR_SCREEN_ORIENTATION.equals(attrName)) {
1843 screenOrientation = Integer.parseInt(attrValue);
1844 }
1845 }
1846
1847 public int describeContents() {
1848 return 0;
1849 }
1850
1851 public void writeToParcel(Parcel dest, int flags) {
1852 dest.writeInt(taskWidth);
1853 dest.writeInt(taskHeight);
1854 dest.writeInt(screenOrientation);
1855 }
1856
1857 public void readFromParcel(Parcel source) {
1858 taskWidth = source.readInt();
1859 taskHeight = source.readInt();
1860 screenOrientation = source.readInt();
1861 }
1862
1863 public static final Creator<TaskThumbnailInfo> CREATOR = new Creator<TaskThumbnailInfo>() {
1864 public TaskThumbnailInfo createFromParcel(Parcel source) {
1865 return new TaskThumbnailInfo(source);
1866 }
1867 public TaskThumbnailInfo[] newArray(int size) {
1868 return new TaskThumbnailInfo[size];
1869 }
1870 };
1871 }
1872
Dianne Hackbornd94df452011-02-16 18:53:31 -08001873 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001874 public static class TaskThumbnail implements Parcelable {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001875 public Bitmap mainThumbnail;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001876 public ParcelFileDescriptor thumbnailFileDescriptor;
Winsonc809cbb2015-11-02 12:06:15 -08001877 public TaskThumbnailInfo thumbnailInfo;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001878
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001879 public TaskThumbnail() {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001880 }
1881
Winsonc809cbb2015-11-02 12:06:15 -08001882 private TaskThumbnail(Parcel source) {
1883 readFromParcel(source);
1884 }
1885
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001886 public int describeContents() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001887 if (thumbnailFileDescriptor != null) {
1888 return thumbnailFileDescriptor.describeContents();
1889 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001890 return 0;
1891 }
1892
1893 public void writeToParcel(Parcel dest, int flags) {
1894 if (mainThumbnail != null) {
1895 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001896 mainThumbnail.writeToParcel(dest, flags);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001897 } else {
1898 dest.writeInt(0);
1899 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001900 if (thumbnailFileDescriptor != null) {
1901 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001902 thumbnailFileDescriptor.writeToParcel(dest, flags);
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001903 } else {
1904 dest.writeInt(0);
1905 }
Winsonc809cbb2015-11-02 12:06:15 -08001906 if (thumbnailInfo != null) {
1907 dest.writeInt(1);
1908 thumbnailInfo.writeToParcel(dest, flags);
1909 } else {
1910 dest.writeInt(0);
1911 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001912 }
1913
1914 public void readFromParcel(Parcel source) {
1915 if (source.readInt() != 0) {
1916 mainThumbnail = Bitmap.CREATOR.createFromParcel(source);
1917 } else {
1918 mainThumbnail = null;
1919 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001920 if (source.readInt() != 0) {
1921 thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source);
1922 } else {
1923 thumbnailFileDescriptor = null;
1924 }
Winsonc809cbb2015-11-02 12:06:15 -08001925 if (source.readInt() != 0) {
1926 thumbnailInfo = TaskThumbnailInfo.CREATOR.createFromParcel(source);
1927 } else {
1928 thumbnailInfo = null;
1929 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001930 }
1931
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001932 public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() {
1933 public TaskThumbnail createFromParcel(Parcel source) {
1934 return new TaskThumbnail(source);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001935 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001936 public TaskThumbnail[] newArray(int size) {
1937 return new TaskThumbnail[size];
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001938 }
1939 };
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001940 }
1941
1942 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001943 public TaskThumbnail getTaskThumbnail(int id) throws SecurityException {
Dianne Hackbornd94df452011-02-16 18:53:31 -08001944 try {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001945 return ActivityManagerNative.getDefault().getTaskThumbnail(id);
Dianne Hackborn15491c62012-09-19 10:59:14 -07001946 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001947 throw e.rethrowFromSystemServer();
Dianne Hackborn15491c62012-09-19 10:59:14 -07001948 }
1949 }
1950
Winson Chung303e1ff2014-03-07 15:06:19 -08001951 /** @hide */
1952 public boolean isInHomeStack(int taskId) {
1953 try {
1954 return ActivityManagerNative.getDefault().isInHomeStack(taskId);
1955 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001956 throw e.rethrowFromSystemServer();
Winson Chung303e1ff2014-03-07 15:06:19 -08001957 }
1958 }
1959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001961 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
1962 * activity along with the task, so it is positioned immediately behind
1963 * the task.
1964 */
1965 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
1966
1967 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001968 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
1969 * user-instigated action, so the current activity will not receive a
1970 * hint that the user is leaving.
1971 */
1972 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
1973
1974 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001975 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
1976 * with a null options argument.
1977 *
1978 * @param taskId The identifier of the task to be moved, as found in
1979 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
1980 * @param flags Additional operational flags, 0 or more of
Craig Mautnerecbfe252013-03-28 11:58:25 -07001981 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001982 */
1983 public void moveTaskToFront(int taskId, int flags) {
1984 moveTaskToFront(taskId, flags, null);
1985 }
1986
1987 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001988 * Ask that the task associated with a given task ID be moved to the
1989 * front of the stack, so it is now visible to the user. Requires that
1990 * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS}
1991 * or a SecurityException will be thrown.
1992 *
1993 * @param taskId The identifier of the task to be moved, as found in
1994 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
1995 * @param flags Additional operational flags, 0 or more of
Craig Mautnerecbfe252013-03-28 11:58:25 -07001996 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001997 * @param options Additional options for the operation, either null or
1998 * as per {@link Context#startActivity(Intent, android.os.Bundle)
1999 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002000 */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002001 public void moveTaskToFront(int taskId, int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002002 try {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002003 ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002004 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002005 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002006 }
2007 }
2008
2009 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 * Information you can retrieve about a particular Service that is
2011 * currently running in the system.
2012 */
2013 public static class RunningServiceInfo implements Parcelable {
2014 /**
2015 * The service component.
2016 */
2017 public ComponentName service;
2018
2019 /**
2020 * If non-zero, this is the process the service is running in.
2021 */
2022 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002025 * The UID that owns this service.
2026 */
2027 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002028
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002029 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 * The name of the process this service runs in.
2031 */
2032 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034 /**
2035 * Set to true if the service has asked to run as a foreground process.
2036 */
2037 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002040 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002041 * starting or binding to it. This
2042 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 */
2044 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 /**
2047 * Set to true if this service has been explicitly started.
2048 */
2049 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002051 /**
2052 * Number of clients connected to the service.
2053 */
2054 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 /**
2057 * Number of times the service's process has crashed while the service
2058 * is running.
2059 */
2060 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 /**
2063 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002064 * explicit requests to start it or clients binding to it). This
2065 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 */
2067 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 /**
2070 * If non-zero, this service is not currently running, but scheduled to
2071 * restart at the given time.
2072 */
2073 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002074
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002075 /**
2076 * Bit for {@link #flags}: set if this service has been
2077 * explicitly started.
2078 */
2079 public static final int FLAG_STARTED = 1<<0;
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 has asked to
2083 * run as a foreground process.
2084 */
2085 public static final int FLAG_FOREGROUND = 1<<1;
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 * core system process.
2090 */
2091 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002092
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002093 /**
2094 * Bit for {@link #flags): set if the service is running in a
2095 * persistent process.
2096 */
2097 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002098
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002099 /**
2100 * Running flags.
2101 */
2102 public int flags;
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 * the package that holds the binding.
2107 */
2108 public String clientPackage;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002109
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002110 /**
2111 * For special services that are bound to by system code, this is
2112 * a string resource providing a user-visible label for who the
2113 * client is.
2114 */
2115 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 public RunningServiceInfo() {
2118 }
2119
2120 public int describeContents() {
2121 return 0;
2122 }
2123
2124 public void writeToParcel(Parcel dest, int flags) {
2125 ComponentName.writeToParcel(service, dest);
2126 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002127 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 dest.writeString(process);
2129 dest.writeInt(foreground ? 1 : 0);
2130 dest.writeLong(activeSince);
2131 dest.writeInt(started ? 1 : 0);
2132 dest.writeInt(clientCount);
2133 dest.writeInt(crashCount);
2134 dest.writeLong(lastActivityTime);
2135 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002136 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002137 dest.writeString(clientPackage);
2138 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139 }
2140
2141 public void readFromParcel(Parcel source) {
2142 service = ComponentName.readFromParcel(source);
2143 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002144 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002145 process = source.readString();
2146 foreground = source.readInt() != 0;
2147 activeSince = source.readLong();
2148 started = source.readInt() != 0;
2149 clientCount = source.readInt();
2150 crashCount = source.readInt();
2151 lastActivityTime = source.readLong();
2152 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002153 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002154 clientPackage = source.readString();
2155 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002156 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
2159 public RunningServiceInfo createFromParcel(Parcel source) {
2160 return new RunningServiceInfo(source);
2161 }
2162 public RunningServiceInfo[] newArray(int size) {
2163 return new RunningServiceInfo[size];
2164 }
2165 };
2166
2167 private RunningServiceInfo(Parcel source) {
2168 readFromParcel(source);
2169 }
2170 }
2171
2172 /**
2173 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002174 *
2175 * <p><b>Note: this method is only intended for debugging or implementing
2176 * service management type user interfaces.</b></p>
2177 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 * @param maxNum The maximum number of entries to return in the list. The
2179 * actual number returned may be smaller, depending on how many services
2180 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002181 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 * @return Returns a list of RunningServiceInfo records describing each of
2183 * the running tasks.
2184 */
2185 public List<RunningServiceInfo> getRunningServices(int maxNum)
2186 throws SecurityException {
2187 try {
Amith Yamasani4b2e9342011-03-31 12:38:53 -07002188 return ActivityManagerNative.getDefault()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002189 .getServices(maxNum, 0);
2190 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002191 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 }
2193 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002196 * Returns a PendingIntent you can start to show a control panel for the
2197 * given running service. If the service does not have a control panel,
2198 * null is returned.
2199 */
2200 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2201 throws SecurityException {
2202 try {
2203 return ActivityManagerNative.getDefault()
2204 .getRunningServiceControlPanel(service);
2205 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002206 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002207 }
2208 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002209
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002210 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 * Information you can retrieve about the available memory through
2212 * {@link ActivityManager#getMemoryInfo}.
2213 */
2214 public static class MemoryInfo implements Parcelable {
2215 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002216 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217 * be considered absolute: due to the nature of the kernel, a significant
2218 * portion of this memory is actually in use and needed for the overall
2219 * system to run well.
2220 */
2221 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002222
2223 /**
2224 * The total memory accessible by the kernel. This is basically the
2225 * RAM size of the device, not including below-kernel fixed allocations
2226 * like DMA buffers, RAM for the baseband CPU, etc.
2227 */
2228 public long totalMem;
2229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 /**
2231 * The threshold of {@link #availMem} at which we consider memory to be
2232 * low and start killing background services and other non-extraneous
2233 * processes.
2234 */
2235 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237 /**
2238 * Set to true if the system considers itself to currently be in a low
2239 * memory situation.
2240 */
2241 public boolean lowMemory;
2242
Dianne Hackborn7d608422011-08-07 16:24:18 -07002243 /** @hide */
2244 public long hiddenAppThreshold;
2245 /** @hide */
2246 public long secondaryServerThreshold;
2247 /** @hide */
2248 public long visibleAppThreshold;
2249 /** @hide */
2250 public long foregroundAppThreshold;
2251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 public MemoryInfo() {
2253 }
2254
2255 public int describeContents() {
2256 return 0;
2257 }
2258
2259 public void writeToParcel(Parcel dest, int flags) {
2260 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002261 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 dest.writeLong(threshold);
2263 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002264 dest.writeLong(hiddenAppThreshold);
2265 dest.writeLong(secondaryServerThreshold);
2266 dest.writeLong(visibleAppThreshold);
2267 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 public void readFromParcel(Parcel source) {
2271 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002272 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 threshold = source.readLong();
2274 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002275 hiddenAppThreshold = source.readLong();
2276 secondaryServerThreshold = source.readLong();
2277 visibleAppThreshold = source.readLong();
2278 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 }
2280
2281 public static final Creator<MemoryInfo> CREATOR
2282 = new Creator<MemoryInfo>() {
2283 public MemoryInfo createFromParcel(Parcel source) {
2284 return new MemoryInfo(source);
2285 }
2286 public MemoryInfo[] newArray(int size) {
2287 return new MemoryInfo[size];
2288 }
2289 };
2290
2291 private MemoryInfo(Parcel source) {
2292 readFromParcel(source);
2293 }
2294 }
2295
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002296 /**
2297 * Return general information about the memory state of the system. This
2298 * can be used to help decide how to manage your own memory, though note
2299 * that polling is not recommended and
2300 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2301 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2302 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2303 * level of your process as needed, which gives a better hint for how to
2304 * manage its memory.
2305 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 public void getMemoryInfo(MemoryInfo outInfo) {
2307 try {
2308 ActivityManagerNative.getDefault().getMemoryInfo(outInfo);
2309 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002310 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 }
2312 }
Craig Mautner967212c2013-04-13 21:10:58 -07002313
Craig Mautner5ff12102013-05-24 12:50:15 -07002314 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002315 * Information you can retrieve about an ActivityStack in the system.
2316 * @hide
2317 */
2318 public static class StackInfo implements Parcelable {
2319 public int stackId;
Craig Mautnered6649f2013-12-02 14:08:25 -08002320 public Rect bounds = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -07002321 public int[] taskIds;
2322 public String[] taskNames;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002323 public Rect[] taskBounds;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002324 public int[] taskUserIds;
Craig Mautnered6649f2013-12-02 14:08:25 -08002325 public int displayId;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002326 public int userId;
Craig Mautner967212c2013-04-13 21:10:58 -07002327
Craig Mautner967212c2013-04-13 21:10:58 -07002328 @Override
2329 public int describeContents() {
2330 return 0;
2331 }
2332
2333 @Override
2334 public void writeToParcel(Parcel dest, int flags) {
2335 dest.writeInt(stackId);
2336 dest.writeInt(bounds.left);
2337 dest.writeInt(bounds.top);
2338 dest.writeInt(bounds.right);
2339 dest.writeInt(bounds.bottom);
2340 dest.writeIntArray(taskIds);
2341 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002342 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2343 dest.writeInt(boundsCount);
2344 for (int i = 0; i < boundsCount; i++) {
2345 dest.writeInt(taskBounds[i].left);
2346 dest.writeInt(taskBounds[i].top);
2347 dest.writeInt(taskBounds[i].right);
2348 dest.writeInt(taskBounds[i].bottom);
2349 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002350 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002351 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002352 dest.writeInt(userId);
Craig Mautner967212c2013-04-13 21:10:58 -07002353 }
2354
2355 public void readFromParcel(Parcel source) {
2356 stackId = source.readInt();
2357 bounds = new Rect(
2358 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2359 taskIds = source.createIntArray();
2360 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002361 final int boundsCount = source.readInt();
2362 if (boundsCount > 0) {
2363 taskBounds = new Rect[boundsCount];
2364 for (int i = 0; i < boundsCount; i++) {
2365 taskBounds[i] = new Rect();
2366 taskBounds[i].set(
2367 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2368 }
2369 } else {
2370 taskBounds = null;
2371 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002372 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002373 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002374 userId = source.readInt();
Craig Mautner967212c2013-04-13 21:10:58 -07002375 }
2376
2377 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
2378 @Override
2379 public StackInfo createFromParcel(Parcel source) {
2380 return new StackInfo(source);
2381 }
2382 @Override
2383 public StackInfo[] newArray(int size) {
2384 return new StackInfo[size];
2385 }
2386 };
2387
Craig Mautner5ff12102013-05-24 12:50:15 -07002388 public StackInfo() {
2389 }
2390
Craig Mautner967212c2013-04-13 21:10:58 -07002391 private StackInfo(Parcel source) {
2392 readFromParcel(source);
2393 }
2394
Craig Mautner5ff12102013-05-24 12:50:15 -07002395 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002396 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002397 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002398 sb.append(" bounds="); sb.append(bounds.toShortString());
2399 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002400 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002401 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002402 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002403 for (int i = 0; i < taskIds.length; ++i) {
2404 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002405 sb.append(": "); sb.append(taskNames[i]);
2406 if (taskBounds != null) {
2407 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2408 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002409 sb.append(" userId=").append(taskUserIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002410 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002411 }
2412 return sb.toString();
2413 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002414
2415 @Override
2416 public String toString() {
2417 return toString("");
2418 }
Craig Mautner967212c2013-04-13 21:10:58 -07002419 }
2420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 /**
2422 * @hide
2423 */
2424 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2425 try {
Stefan Kuhne16045c22015-06-05 07:18:06 -07002426 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName,
Dianne Hackborn41203752012-08-31 14:05:51 -07002427 observer, UserHandle.myUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002429 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 }
2431 }
Christopher Tatea3664242013-06-26 15:00:18 -07002432
2433 /**
2434 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002435 * the user choosing to clear the app's data from within the device settings UI. It
2436 * erases all dynamic data associated with the app -- its private data and data in its
2437 * private area on external storage -- but does not remove the installed application
2438 * itself, nor any OBB files.
Christopher Tatea3664242013-06-26 15:00:18 -07002439 *
2440 * @return {@code true} if the application successfully requested that the application's
2441 * data be erased; {@code false} otherwise.
2442 */
2443 public boolean clearApplicationUserData() {
2444 return clearApplicationUserData(mContext.getPackageName(), null);
2445 }
2446
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002447
2448 /**
2449 * Permits an application to get the persistent URI permissions granted to another.
2450 *
2451 * <p>Typically called by Settings.
2452 *
2453 * @param packageName application to look for the granted permissions
2454 * @return list of granted URI permissions
2455 *
2456 * @hide
2457 */
2458 public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName) {
2459 try {
2460 return ActivityManagerNative.getDefault().getGrantedUriPermissions(packageName,
2461 UserHandle.myUserId());
2462 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002463 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002464 }
2465 }
2466
2467 /**
2468 * Permits an application to clear the persistent URI permissions granted to another.
2469 *
2470 * <p>Typically called by Settings.
2471 *
2472 * @param packageName application to clear its granted permissions
2473 *
2474 * @hide
2475 */
2476 public void clearGrantedUriPermissions(String packageName) {
2477 try {
2478 ActivityManagerNative.getDefault().clearGrantedUriPermissions(packageName,
2479 UserHandle.myUserId());
2480 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002481 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002482 }
2483 }
2484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 /**
2486 * Information you can retrieve about any processes that are in an error condition.
2487 */
2488 public static class ProcessErrorStateInfo implements Parcelable {
2489 /**
2490 * Condition codes
2491 */
2492 public static final int NO_ERROR = 0;
2493 public static final int CRASHED = 1;
2494 public static final int NOT_RESPONDING = 2;
2495
2496 /**
2497 * The condition that the process is in.
2498 */
2499 public int condition;
2500
2501 /**
2502 * The process name in which the crash or error occurred.
2503 */
2504 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 /**
2507 * The pid of this process; 0 if none
2508 */
2509 public int pid;
2510
2511 /**
2512 * The kernel user-ID that has been assigned to this process;
2513 * currently this is not a unique ID (multiple applications can have
2514 * the same uid).
2515 */
2516 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 /**
Dan Egnor60d87622009-12-16 16:32:58 -08002519 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002520 */
2521 public String tag;
2522
2523 /**
2524 * A short message describing the error condition.
2525 */
2526 public String shortMsg;
2527
2528 /**
2529 * A long message describing the error condition.
2530 */
2531 public String longMsg;
2532
2533 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08002534 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 */
Dan Egnorb7f03672009-12-09 16:22:32 -08002536 public String stackTrace;
2537
2538 /**
2539 * to be deprecated: This value will always be null.
2540 */
2541 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542
2543 public ProcessErrorStateInfo() {
2544 }
2545
Craig Mautner5ff12102013-05-24 12:50:15 -07002546 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 public int describeContents() {
2548 return 0;
2549 }
2550
Craig Mautner5ff12102013-05-24 12:50:15 -07002551 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 public void writeToParcel(Parcel dest, int flags) {
2553 dest.writeInt(condition);
2554 dest.writeString(processName);
2555 dest.writeInt(pid);
2556 dest.writeInt(uid);
2557 dest.writeString(tag);
2558 dest.writeString(shortMsg);
2559 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08002560 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 public void readFromParcel(Parcel source) {
2564 condition = source.readInt();
2565 processName = source.readString();
2566 pid = source.readInt();
2567 uid = source.readInt();
2568 tag = source.readString();
2569 shortMsg = source.readString();
2570 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08002571 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002573
2574 public static final Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 new Creator<ProcessErrorStateInfo>() {
2576 public ProcessErrorStateInfo createFromParcel(Parcel source) {
2577 return new ProcessErrorStateInfo(source);
2578 }
2579 public ProcessErrorStateInfo[] newArray(int size) {
2580 return new ProcessErrorStateInfo[size];
2581 }
2582 };
2583
2584 private ProcessErrorStateInfo(Parcel source) {
2585 readFromParcel(source);
2586 }
2587 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002590 * 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 -08002591 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002592 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
2594 * current error conditions (it will not return an empty list). This list ordering is not
2595 * specified.
2596 */
2597 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
2598 try {
2599 return ActivityManagerNative.getDefault().getProcessesInErrorState();
2600 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002601 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002602 }
2603 }
2604
2605 /**
2606 * Information you can retrieve about a running process.
2607 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07002608 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 /**
2610 * The name of the process that this object is associated with
2611 */
2612 public String processName;
2613
2614 /**
2615 * The pid of this process; 0 if none
2616 */
2617 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002618
Dianne Hackborneb034652009-09-07 00:49:58 -07002619 /**
2620 * The user id of this process.
2621 */
2622 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002623
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002624 /**
2625 * All packages that have been loaded into the process.
2626 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07002628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07002630 * Constant for {@link #flags}: this is an app that is unable to
2631 * correctly save its state when going to the background,
2632 * so it can not be killed while in the background.
2633 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002634 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07002635 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002636
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002637 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002638 * Constant for {@link #flags}: this process is associated with a
2639 * persistent system app.
2640 * @hide
2641 */
2642 public static final int FLAG_PERSISTENT = 1<<1;
2643
2644 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07002645 * Constant for {@link #flags}: this process is associated with a
2646 * persistent system app.
2647 * @hide
2648 */
2649 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
2650
2651 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002652 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07002653 * {@link #FLAG_CANT_SAVE_STATE}.
2654 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002655 */
2656 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002657
2658 /**
2659 * Last memory trim level reported to the process: corresponds to
2660 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2661 * ComponentCallbacks2.onTrimMemory(int)}.
2662 */
2663 public int lastTrimLevel;
2664
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002665 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002666 * Constant for {@link #importance}: This process is running the
2667 * foreground UI; that is, it is the thing currently at the top of the screen
2668 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002669 */
2670 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002673 * Constant for {@link #importance}: This process is running a foreground
2674 * service, for example to perform music playback even while the user is
2675 * not immediately in the app. This generally indicates that the process
2676 * is doing something the user actively cares about.
2677 */
2678 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
2679
2680 /**
2681 * Constant for {@link #importance}: This process is running the foreground
2682 * UI, but the device is asleep so it is not visible to the user. This means
2683 * the user is not really aware of the process, because they can not see or
2684 * interact with it, but it is quite important because it what they expect to
2685 * return to once unlocking the device.
2686 */
2687 public static final int IMPORTANCE_TOP_SLEEPING = 150;
2688
2689 /**
2690 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002691 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07002692 * foreground. This may be running a window that is behind the current
2693 * foreground (so paused and with its state saved, not interacting with
2694 * the user, but visible to them to some degree); it may also be running
2695 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07002696 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002697 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002698
Dianne Hackborn860755f2010-06-03 18:47:52 -07002699 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002700 * Constant for {@link #importance}: This process is not something the user
2701 * is directly aware of, but is otherwise perceptable to them to some degree.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002703 public static final int IMPORTANCE_PERCEPTIBLE = 130;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002704
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002705 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002706 * Constant for {@link #importance}: This process is running an
Dianne Hackborn5383f502010-10-22 12:59:20 -07002707 * application that can not save its state, and thus can't be killed
2708 * while in the background.
2709 * @hide
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002710 */
Dianne Hackborn5383f502010-10-22 12:59:20 -07002711 public static final int IMPORTANCE_CANT_SAVE_STATE = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002714 * Constant for {@link #importance}: This process is contains services
2715 * that should remain running. These are background services apps have
2716 * started, not something the user is aware of, so they may be killed by
2717 * the system relatively freely (though it is generally desired that they
2718 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002719 */
2720 public static final int IMPORTANCE_SERVICE = 300;
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 process contains
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002724 * background code that is expendable.
2725 */
2726 public static final int IMPORTANCE_BACKGROUND = 400;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002729 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 * actively running code.
2731 */
2732 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002733
2734 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002735 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002736 */
2737 public static final int IMPORTANCE_GONE = 1000;
2738
2739 /** @hide */
2740 public static int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002741 if (procState == PROCESS_STATE_NONEXISTENT) {
2742 return IMPORTANCE_GONE;
2743 } else if (procState >= PROCESS_STATE_HOME) {
2744 return IMPORTANCE_BACKGROUND;
2745 } else if (procState >= PROCESS_STATE_SERVICE) {
2746 return IMPORTANCE_SERVICE;
2747 } else if (procState > PROCESS_STATE_HEAVY_WEIGHT) {
2748 return IMPORTANCE_CANT_SAVE_STATE;
2749 } else if (procState >= PROCESS_STATE_IMPORTANT_BACKGROUND) {
2750 return IMPORTANCE_PERCEPTIBLE;
2751 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
2752 return IMPORTANCE_VISIBLE;
2753 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
2754 return IMPORTANCE_TOP_SLEEPING;
2755 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) {
2756 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002757 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002758 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002759 }
2760 }
2761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 /**
2763 * The relative importance level that the system places on this
2764 * process. May be one of {@link #IMPORTANCE_FOREGROUND},
2765 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE},
2766 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These
2767 * constants are numbered so that "more important" values are always
2768 * smaller than "less important" values.
2769 */
2770 public int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002772 /**
2773 * An additional ordering within a particular {@link #importance}
2774 * category, providing finer-grained information about the relative
2775 * utility of processes within a category. This number means nothing
2776 * except that a smaller values are more recently used (and thus
2777 * more important). Currently an LRU value is only maintained for
2778 * the {@link #IMPORTANCE_BACKGROUND} category, though others may
2779 * be maintained in the future.
2780 */
2781 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002782
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002783 /**
2784 * Constant for {@link #importanceReasonCode}: nothing special has
2785 * been specified for the reason for this level.
2786 */
2787 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002788
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002789 /**
2790 * Constant for {@link #importanceReasonCode}: one of the application's
2791 * content providers is being used by another process. The pid of
2792 * the client process is in {@link #importanceReasonPid} and the
2793 * target provider in this process is in
2794 * {@link #importanceReasonComponent}.
2795 */
2796 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002797
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002798 /**
2799 * Constant for {@link #importanceReasonCode}: one of the application's
2800 * content providers is being used by another process. The pid of
2801 * the client process is in {@link #importanceReasonPid} and the
2802 * target provider in this process is in
2803 * {@link #importanceReasonComponent}.
2804 */
2805 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002806
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002807 /**
2808 * The reason for {@link #importance}, if any.
2809 */
2810 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002811
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002812 /**
2813 * For the specified values of {@link #importanceReasonCode}, this
2814 * is the process ID of the other process that is a client of this
2815 * process. This will be 0 if no other process is using this one.
2816 */
2817 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002818
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002819 /**
2820 * For the specified values of {@link #importanceReasonCode}, this
2821 * is the name of the component that is being used in this process.
2822 */
2823 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002824
Dianne Hackborn905577f2011-09-07 18:31:28 -07002825 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07002826 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07002827 * of the other pid. @hide
2828 */
2829 public int importanceReasonImportance;
2830
Dianne Hackborn684bf342014-04-29 17:56:57 -07002831 /**
2832 * Current process state, as per PROCESS_STATE_* constants.
2833 * @hide
2834 */
2835 public int processState;
2836
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 public RunningAppProcessInfo() {
2838 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002839 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07002840 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
2844 processName = pProcessName;
2845 pid = pPid;
2846 pkgList = pArr;
2847 }
2848
2849 public int describeContents() {
2850 return 0;
2851 }
2852
2853 public void writeToParcel(Parcel dest, int flags) {
2854 dest.writeString(processName);
2855 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07002856 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002858 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002859 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 dest.writeInt(importance);
2861 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002862 dest.writeInt(importanceReasonCode);
2863 dest.writeInt(importanceReasonPid);
2864 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07002865 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07002866 dest.writeInt(processState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 }
2868
2869 public void readFromParcel(Parcel source) {
2870 processName = source.readString();
2871 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07002872 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002874 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002875 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 importance = source.readInt();
2877 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002878 importanceReasonCode = source.readInt();
2879 importanceReasonPid = source.readInt();
2880 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07002881 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07002882 processState = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 }
2884
Stefan Kuhne16045c22015-06-05 07:18:06 -07002885 public static final Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 new Creator<RunningAppProcessInfo>() {
2887 public RunningAppProcessInfo createFromParcel(Parcel source) {
2888 return new RunningAppProcessInfo(source);
2889 }
2890 public RunningAppProcessInfo[] newArray(int size) {
2891 return new RunningAppProcessInfo[size];
2892 }
2893 };
2894
2895 private RunningAppProcessInfo(Parcel source) {
2896 readFromParcel(source);
2897 }
2898 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07002901 * Returns a list of application processes installed on external media
2902 * that are running on the device.
2903 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002904 * <p><b>Note: this method is only intended for debugging or building
2905 * a user-facing process management UI.</b></p>
2906 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07002907 * @return Returns a list of ApplicationInfo records, or null if none
2908 * This list ordering is not specified.
2909 * @hide
2910 */
2911 public List<ApplicationInfo> getRunningExternalApplications() {
2912 try {
2913 return ActivityManagerNative.getDefault().getRunningExternalApplications();
2914 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002915 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07002916 }
2917 }
2918
2919 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002920 * Sets the memory trim mode for a process and schedules a memory trim operation.
2921 *
2922 * <p><b>Note: this method is only intended for testing framework.</b></p>
2923 *
2924 * @return Returns true if successful.
2925 * @hide
2926 */
2927 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
2928 try {
2929 return ActivityManagerNative.getDefault().setProcessMemoryTrimLevel(process, userId,
2930 level);
2931 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002932 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07002933 }
2934 }
2935
2936 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002938 *
2939 * <p><b>Note: this method is only intended for debugging or building
2940 * a user-facing process management UI.</b></p>
2941 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
2943 * running processes (it will not return an empty list). This list ordering is not
2944 * specified.
2945 */
2946 public List<RunningAppProcessInfo> getRunningAppProcesses() {
2947 try {
2948 return ActivityManagerNative.getDefault().getRunningAppProcesses();
2949 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002950 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 }
2952 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002953
2954 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002955 * Return the importance of a given package name, based on the processes that are
2956 * currently running. The return value is one of the importance constants defined
2957 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
2958 * processes that this package has code running inside of. If there are no processes
2959 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07002960 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07002961 */
Dianne Hackbornb7258942015-05-13 15:10:24 -07002962 @SystemApi
Dianne Hackborn1e383822015-04-10 14:02:33 -07002963 public int getPackageImportance(String packageName) {
2964 try {
Adam Lesinskic30454c2015-06-24 13:24:35 -07002965 int procState = ActivityManagerNative.getDefault().getPackageProcessState(packageName,
2966 mContext.getOpPackageName());
Dianne Hackborn1e383822015-04-10 14:02:33 -07002967 return RunningAppProcessInfo.procStateToImportance(procState);
2968 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002969 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07002970 }
2971 }
2972
2973 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002974 * Return global memory state information for the calling process. This
2975 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
2976 * only fields that will be filled in are
2977 * {@link RunningAppProcessInfo#pid},
2978 * {@link RunningAppProcessInfo#uid},
2979 * {@link RunningAppProcessInfo#lastTrimLevel},
2980 * {@link RunningAppProcessInfo#importance},
2981 * {@link RunningAppProcessInfo#lru}, and
2982 * {@link RunningAppProcessInfo#importanceReasonCode}.
2983 */
2984 static public void getMyMemoryState(RunningAppProcessInfo outState) {
2985 try {
2986 ActivityManagerNative.getDefault().getMyMemoryState(outState);
2987 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002988 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002989 }
2990 }
2991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07002993 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002994 *
2995 * <p><b>Note: this method is only intended for debugging or building
2996 * a user-facing process management UI.</b></p>
2997 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07002998 * @param pids The pids of the processes whose memory usage is to be
2999 * retrieved.
3000 * @return Returns an array of memory information, one for each
3001 * requested pid.
3002 */
3003 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
3004 try {
3005 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids);
3006 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003007 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003008 }
3009 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003010
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003011 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003012 * @deprecated This is now just a wrapper for
3013 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3014 * is no longer available to applications because it allows them to
3015 * break other applications by removing their alarms, stopping their
3016 * services, etc.
3017 */
3018 @Deprecated
3019 public void restartPackage(String packageName) {
3020 killBackgroundProcesses(packageName);
3021 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003022
Dianne Hackborn03abb812010-01-04 18:43:19 -08003023 /**
3024 * Have the system immediately kill all background processes associated
3025 * with the given package. This is the same as the kernel killing those
3026 * processes to reclaim memory; the system will take care of restarting
3027 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003028 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003029 * <p>You must hold the permission
3030 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to
3031 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003032 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003033 * @param packageName The name of the package whose processes are to
3034 * be killed.
3035 */
3036 public void killBackgroundProcesses(String packageName) {
3037 try {
Dianne Hackborn1676c852012-09-10 14:52:30 -07003038 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName,
3039 UserHandle.myUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003040 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003041 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003042 }
3043 }
Svet Ganov019d2302015-05-04 11:07:38 -07003044
3045 /**
3046 * Kills the specified UID.
3047 * @param uid The UID to kill.
3048 * @param reason The reason for the kill.
3049 *
3050 * @hide
3051 */
Svet Ganov019d2302015-05-04 11:07:38 -07003052 @RequiresPermission(Manifest.permission.KILL_UID)
3053 public void killUid(int uid, String reason) {
3054 try {
Svetoslavaa41add2015-08-06 15:03:55 -07003055 ActivityManagerNative.getDefault().killUid(UserHandle.getAppId(uid),
3056 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003057 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003058 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003059 }
3060 }
3061
Dianne Hackborn03abb812010-01-04 18:43:19 -08003062 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 * Have the system perform a force stop of everything associated with
3064 * the given application package. All processes that share its uid
3065 * will be killed, all services it has running stopped, all activities
3066 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3067 * broadcast will be sent, so that any of its registered alarms can
3068 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003069 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003071 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003073 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003075 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003076 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003077 * @hide This is not available to third party applications due to
3078 * it allowing them to break other applications by stopping their
3079 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 */
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003081 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 try {
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003083 ActivityManagerNative.getDefault().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003085 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003086 }
3087 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003088
3089 /**
3090 * @see #forceStopPackageAsUser(String, int)
3091 * @hide
3092 */
3093 public void forceStopPackage(String packageName) {
3094 forceStopPackageAsUser(packageName, UserHandle.myUserId());
3095 }
3096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003097 /**
3098 * Get the device configuration attributes.
3099 */
3100 public ConfigurationInfo getDeviceConfigurationInfo() {
3101 try {
3102 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo();
3103 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003104 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003107
3108 /**
3109 * Get the preferred density of icons for the launcher. This is used when
3110 * custom drawables are created (e.g., for shortcuts).
3111 *
3112 * @return density in terms of DPI
3113 */
3114 public int getLauncherLargeIconDensity() {
3115 final Resources res = mContext.getResources();
3116 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003117 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003118
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003119 if (sw < 600) {
3120 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003121 return density;
3122 }
3123
3124 switch (density) {
3125 case DisplayMetrics.DENSITY_LOW:
3126 return DisplayMetrics.DENSITY_MEDIUM;
3127 case DisplayMetrics.DENSITY_MEDIUM:
3128 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003129 case DisplayMetrics.DENSITY_TV:
3130 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003131 case DisplayMetrics.DENSITY_HIGH:
3132 return DisplayMetrics.DENSITY_XHIGH;
3133 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003134 return DisplayMetrics.DENSITY_XXHIGH;
3135 case DisplayMetrics.DENSITY_XXHIGH:
3136 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003137 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003138 // The density is some abnormal value. Return some other
3139 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003140 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003141 }
3142 }
3143
3144 /**
3145 * Get the preferred launcher icon size. This is used when custom drawables
3146 * are created (e.g., for shortcuts).
3147 *
3148 * @return dimensions of square icons in terms of pixels
3149 */
3150 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003151 return getLauncherLargeIconSizeInner(mContext);
3152 }
3153
3154 static int getLauncherLargeIconSizeInner(Context context) {
3155 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003156 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003157 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003158
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003159 if (sw < 600) {
3160 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003161 return size;
3162 }
3163
3164 final int density = res.getDisplayMetrics().densityDpi;
3165
3166 switch (density) {
3167 case DisplayMetrics.DENSITY_LOW:
3168 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3169 case DisplayMetrics.DENSITY_MEDIUM:
3170 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003171 case DisplayMetrics.DENSITY_TV:
3172 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003173 case DisplayMetrics.DENSITY_HIGH:
3174 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3175 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003176 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3177 case DisplayMetrics.DENSITY_XXHIGH:
3178 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003179 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003180 // The density is some abnormal value. Return some other
3181 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003182 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003183 }
3184 }
3185
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003186 /**
3187 * Returns "true" if the user interface is currently being messed with
3188 * by a monkey.
3189 */
3190 public static boolean isUserAMonkey() {
3191 try {
3192 return ActivityManagerNative.getDefault().isUserAMonkey();
3193 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003194 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003195 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003196 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003197
3198 /**
3199 * Returns "true" if device is running in a test harness.
3200 */
3201 public static boolean isRunningInTestHarness() {
3202 return SystemProperties.getBoolean("ro.test_harness", false);
3203 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003204
3205 /**
3206 * Returns the launch count of each installed package.
3207 *
3208 * @hide
3209 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003210 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00003211 try {
3212 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
3213 ServiceManager.getService("usagestats"));
3214 if (usageStatsService == null) {
3215 return new HashMap<String, Integer>();
3216 }
3217
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003218 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
3219 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00003220 if (allPkgUsageStats == null) {
3221 return new HashMap<String, Integer>();
3222 }
3223
Peter Visontay8d224ca2011-02-18 16:39:19 +00003224 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003225 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
3226 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00003227 }
3228
3229 return launchCounts;
3230 } catch (RemoteException e) {
3231 Log.w(TAG, "Could not query launch counts", e);
3232 return new HashMap<String, Integer>();
3233 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003234 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003235
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003236 /** @hide */
3237 public static int checkComponentPermission(String permission, int uid,
3238 int owningUid, boolean exported) {
3239 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08003240 final int appId = UserHandle.getAppId(uid);
3241 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003242 return PackageManager.PERMISSION_GRANTED;
3243 }
3244 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003245 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003246 return PackageManager.PERMISSION_DENIED;
3247 }
3248 // If there is a uid that owns whatever is being accessed, it has
3249 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003250 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003251 return PackageManager.PERMISSION_GRANTED;
3252 }
3253 // If the target is not exported, then nobody else can get to it.
3254 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07003255 /*
3256 RuntimeException here = new RuntimeException("here");
3257 here.fillInStackTrace();
3258 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
3259 here);
3260 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003261 return PackageManager.PERMISSION_DENIED;
3262 }
3263 if (permission == null) {
3264 return PackageManager.PERMISSION_GRANTED;
3265 }
3266 try {
3267 return AppGlobals.getPackageManager()
3268 .checkUidPermission(permission, uid);
3269 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003270 throw e.rethrowFromSystemServer();
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003271 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003272 }
3273
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003274 /** @hide */
3275 public static int checkUidPermission(String permission, int uid) {
3276 try {
3277 return AppGlobals.getPackageManager()
3278 .checkUidPermission(permission, uid);
3279 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003280 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003281 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003282 }
3283
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08003284 /**
3285 * @hide
3286 * Helper for dealing with incoming user arguments to system service calls.
3287 * Takes care of checking permissions and converting USER_CURRENT to the
3288 * actual current user.
3289 *
3290 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
3291 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
3292 * @param userId The user id argument supplied by the caller -- this is the user
3293 * they want to run as.
3294 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
3295 * to get a USER_ALL returned and deal with it correctly. If false,
3296 * an exception will be thrown if USER_ALL is supplied.
3297 * @param requireFull If true, the caller must hold
3298 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
3299 * different user than their current process; otherwise they must hold
3300 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
3301 * @param name Optional textual name of the incoming call; only for generating error messages.
3302 * @param callerPackage Optional package name of caller; only for error messages.
3303 *
3304 * @return Returns the user ID that the call should run as. Will always be a concrete
3305 * user number, unless <var>allowAll</var> is true in which case it could also be
3306 * USER_ALL.
3307 */
Dianne Hackborn41203752012-08-31 14:05:51 -07003308 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
3309 boolean allowAll, boolean requireFull, String name, String callerPackage) {
3310 if (UserHandle.getUserId(callingUid) == userId) {
3311 return userId;
3312 }
3313 try {
3314 return ActivityManagerNative.getDefault().handleIncomingUser(callingPid,
3315 callingUid, userId, allowAll, requireFull, name, callerPackage);
3316 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003317 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003318 }
3319 }
3320
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07003321 /**
3322 * Gets the userId of the current foreground user. Requires system permissions.
3323 * @hide
3324 */
3325 @SystemApi
Dianne Hackborn41203752012-08-31 14:05:51 -07003326 public static int getCurrentUser() {
3327 UserInfo ui;
3328 try {
3329 ui = ActivityManagerNative.getDefault().getCurrentUser();
3330 return ui != null ? ui.id : 0;
3331 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003332 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003333 }
3334 }
3335
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003336 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003337 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003338 * @hide
3339 */
3340 public boolean switchUser(int userid) {
3341 try {
3342 return ActivityManagerNative.getDefault().switchUser(userid);
3343 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003344 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003345 }
3346 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003347
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003348 /**
3349 * Logs out current current foreground user by switching to the system user and stopping the
3350 * user being switched from.
3351 * @hide
3352 */
3353 public static void logoutCurrentUser() {
3354 int currentUser = ActivityManager.getCurrentUser();
3355 if (currentUser != UserHandle.USER_SYSTEM) {
3356 try {
3357 ActivityManagerNative.getDefault().switchUser(UserHandle.USER_SYSTEM);
3358 ActivityManagerNative.getDefault().stopUser(currentUser, /* force= */ false, null);
3359 } catch (RemoteException e) {
3360 e.rethrowFromSystemServer();
3361 }
3362 }
3363 }
3364
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003365 /** {@hide} */
3366 public static final int FLAG_OR_STOPPED = 1 << 0;
3367 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07003368 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07003369 /** {@hide} */
3370 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003371
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003372 /**
3373 * Return whether the given user is actively running. This means that
3374 * the user is in the "started" state, not "stopped" -- it is currently
3375 * allowed to run code through scheduled alarms, receiving broadcasts,
3376 * etc. A started user may be either the current foreground user or a
3377 * background user; the result here does not distinguish between the two.
3378 * @param userid the user's id. Zero indicates the default user.
3379 * @hide
3380 */
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003381 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003382 try {
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003383 return ActivityManagerNative.getDefault().isUserRunning(userId, 0);
3384 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003385 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003386 }
3387 }
3388
3389 /** {@hide} */
3390 public boolean isUserRunningAndLocked(int userId) {
3391 try {
3392 return ActivityManagerNative.getDefault().isUserRunning(userId,
3393 ActivityManager.FLAG_AND_LOCKED);
3394 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003395 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003396 }
3397 }
3398
3399 /** {@hide} */
3400 public boolean isUserRunningAndUnlocked(int userId) {
3401 try {
3402 return ActivityManagerNative.getDefault().isUserRunning(userId,
3403 ActivityManager.FLAG_AND_UNLOCKED);
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003404 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003405 throw e.rethrowFromSystemServer();
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003406 }
3407 }
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003408
Ruben Brunke24b9a62016-02-16 21:38:24 -08003409 /** {@hide} */
3410 public boolean isVrModePackageEnabled(ComponentName component) {
3411 try {
3412 return ActivityManagerNative.getDefault().isVrModePackageEnabled(component);
3413 } catch (RemoteException e) {
3414 throw e.rethrowFromSystemServer();
3415 }
3416 }
3417
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003418 /**
3419 * Perform a system dump of various state associated with the given application
3420 * package name. This call blocks while the dump is being performed, so should
3421 * not be done on a UI thread. The data will be written to the given file
3422 * descriptor as text. An application must hold the
3423 * {@link android.Manifest.permission#DUMP} permission to make this call.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07003424 * @param fd The file descriptor that the dump should be written to. The file
3425 * descriptor is <em>not</em> closed by this function; the caller continues to
3426 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003427 * @param packageName The name of the package that is to be dumped.
3428 */
3429 public void dumpPackageState(FileDescriptor fd, String packageName) {
3430 dumpPackageStateStatic(fd, packageName);
3431 }
3432
3433 /**
3434 * @hide
3435 */
3436 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
3437 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07003438 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003439 dumpService(pw, fd, "package", new String[] { packageName });
3440 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003441 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
3442 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003443 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003444 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003445 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003446 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003447 pw.println();
Dianne Hackborn904a8572013-06-28 18:12:31 -07003448 dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName });
3449 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07003450 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003451 pw.flush();
3452 }
3453
3454 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
3455 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
3456 IBinder service = ServiceManager.checkService(name);
3457 if (service == null) {
3458 pw.println(" (Service not found)");
3459 return;
3460 }
3461 TransferPipe tp = null;
3462 try {
3463 pw.flush();
3464 tp = new TransferPipe();
3465 tp.setBufferPrefix(" ");
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003466 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003467 tp.go(fd, 10000);
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003468 } catch (Throwable e) {
3469 if (tp != null) {
3470 tp.kill();
3471 }
3472 pw.println("Failure dumping service:");
3473 e.printStackTrace(pw);
3474 }
3475 }
Craig Mautneraea74a52014-03-08 14:23:10 -08003476
3477 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003478 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07003479 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003480 * sees the associated process with a larger pss size and, when this happens, automatically
3481 * pull a heap dump from it and allow the user to share the data. Note that this request
3482 * continues running even if the process is killed and restarted. To remove the watch,
3483 * use {@link #clearWatchHeapLimit()}.
3484 *
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07003485 * <p>This API only work if the calling process has been marked as
3486 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
3487 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003488 *
3489 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
3490 * handle heap limit reports themselves.</p>
3491 *
3492 * @param pssSize The size in bytes to set the limit at.
3493 */
3494 public void setWatchHeapLimit(long pssSize) {
3495 try {
3496 ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, pssSize,
3497 mContext.getPackageName());
3498 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003499 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003500 }
3501 }
3502
3503 /**
3504 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
3505 * If your package has an activity handling this action, it will be launched with the
3506 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
3507 * match the activty must support this action and a MIME type of "*&#47;*".
3508 */
3509 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
3510
3511 /**
3512 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
3513 */
3514 public void clearWatchHeapLimit() {
3515 try {
3516 ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, 0, null);
3517 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003518 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003519 }
3520 }
3521
3522 /**
Craig Mautneraea74a52014-03-08 14:23:10 -08003523 * @hide
3524 */
3525 public void startLockTaskMode(int taskId) {
3526 try {
3527 ActivityManagerNative.getDefault().startLockTaskMode(taskId);
3528 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003529 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003530 }
3531 }
3532
3533 /**
3534 * @hide
3535 */
3536 public void stopLockTaskMode() {
3537 try {
3538 ActivityManagerNative.getDefault().stopLockTaskMode();
3539 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003540 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003541 }
3542 }
3543
3544 /**
Jason Monk386c94f2014-07-14 16:42:24 -04003545 * Return whether currently in lock task mode. When in this mode
3546 * no new tasks can be created or switched to.
3547 *
3548 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00003549 *
3550 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08003551 */
3552 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00003553 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
3554 }
3555
3556 /**
3557 * Return the current state of task locking. The three possible outcomes
3558 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
3559 * and {@link #LOCK_TASK_MODE_PINNED}.
3560 *
3561 * @see Activity#startLockTask()
3562 */
3563 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08003564 try {
Benjamin Franz43261142015-02-11 15:59:44 +00003565 return ActivityManagerNative.getDefault().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08003566 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003567 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003568 }
3569 }
Winson Chung1147c402014-05-14 11:05:00 -07003570
3571 /**
3572 * The AppTask allows you to manage your own application's tasks.
3573 * See {@link android.app.ActivityManager#getAppTasks()}
3574 */
3575 public static class AppTask {
3576 private IAppTask mAppTaskImpl;
3577
3578 /** @hide */
3579 public AppTask(IAppTask task) {
3580 mAppTaskImpl = task;
3581 }
3582
3583 /**
3584 * Finishes all activities in this task and removes it from the recent tasks list.
3585 */
3586 public void finishAndRemoveTask() {
3587 try {
3588 mAppTaskImpl.finishAndRemoveTask();
3589 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003590 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07003591 }
3592 }
3593
3594 /**
3595 * Get the RecentTaskInfo associated with this task.
3596 *
3597 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
3598 */
3599 public RecentTaskInfo getTaskInfo() {
3600 try {
3601 return mAppTaskImpl.getTaskInfo();
3602 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003603 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07003604 }
3605 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003606
3607 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003608 * Bring this task to the foreground. If it contains activities, they will be
3609 * brought to the foreground with it and their instances re-created if needed.
3610 * If it doesn't contain activities, the root activity of the task will be
3611 * re-launched.
3612 */
3613 public void moveToFront() {
3614 try {
3615 mAppTaskImpl.moveToFront();
3616 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003617 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003618 }
3619 }
3620
3621 /**
3622 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003623 * is not currently active (that is, its id < 0), then a new activity for the given
3624 * Intent will be launched as the root of the task and the task brought to the
3625 * foreground. Otherwise, if this task is currently active and the Intent does not specify
3626 * an activity to launch in a new task, then a new activity for the given Intent will
3627 * be launched on top of the task and the task brought to the foreground. If this
3628 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
3629 * or would otherwise be launched in to a new task, then the activity not launched but
3630 * this task be brought to the foreground and a new intent delivered to the top
3631 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003632 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003633 * <p>In other words, you generally want to use an Intent here that does not specify
3634 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
3635 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003636 *
3637 * @param intent The Intent describing the new activity to be launched on the task.
3638 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003639 *
3640 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003641 */
3642 public void startActivity(Context context, Intent intent, Bundle options) {
3643 ActivityThread thread = ActivityThread.currentActivityThread();
3644 thread.getInstrumentation().execStartActivityFromAppTask(context,
3645 thread.getApplicationThread(), mAppTaskImpl, intent, options);
3646 }
3647
3648 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003649 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
3650 * Intent of this AppTask.
3651 *
3652 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
3653 * be set; otherwise, it will be cleared.
3654 */
3655 public void setExcludeFromRecents(boolean exclude) {
3656 try {
3657 mAppTaskImpl.setExcludeFromRecents(exclude);
3658 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003659 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003660 }
3661 }
Winson Chung1147c402014-05-14 11:05:00 -07003662 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663}