blob: 0d9be5f0f7285f6720b3a68e54394ea3ed45225a [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;
Jorim Jaggi29379ec2016-04-11 23:43:42 -070025import android.content.pm.ActivityInfo;
Winson21700932016-03-24 17:26:23 -070026import android.content.res.Configuration;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -070027import android.graphics.Canvas;
28import android.graphics.Matrix;
29import android.graphics.Point;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070030import android.os.BatteryStats;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070031import android.os.IBinder;
Craig Mautnerc0ffce52014-07-01 12:38:52 -070032import android.os.ParcelFileDescriptor;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070033
Joe Onorato4eb64fd2016-03-21 15:30:09 -070034import com.android.internal.app.procstats.ProcessStats;
John Reckaa67f682016-09-20 14:24:21 -070035import com.android.internal.os.RoSystemProperties;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070036import com.android.internal.os.TransferPipe;
Dianne Hackborn8c841092013-06-24 13:46:13 -070037import com.android.internal.util.FastPrintWriter;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.content.ComponentName;
40import android.content.Context;
41import android.content.Intent;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080042import android.content.UriPermission;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070043import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.content.pm.ConfigurationInfo;
45import android.content.pm.IPackageDataObserver;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070046import android.content.pm.PackageManager;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080047import android.content.pm.ParceledListSlice;
Dianne Hackborn41203752012-08-31 14:05:51 -070048import android.content.pm.UserInfo;
Kenny Root5ef44b72011-01-26 17:22:20 -080049import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.graphics.Bitmap;
Winson Chunga449dc02014-05-16 11:15:04 -070051import android.graphics.Color;
Craig Mautner967212c2013-04-13 21:10:58 -070052import android.graphics.Rect;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070053import android.os.Bundle;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070054import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.Handler;
56import android.os.Parcel;
57import android.os.Parcelable;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070058import android.os.Process;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070059import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000060import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070061import android.os.SystemProperties;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070062import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.text.TextUtils;
Kenny Root5ef44b72011-01-26 17:22:20 -080064import android.util.DisplayMetrics;
Winson Chung48a10a52014-08-27 14:36:51 -070065import android.util.Size;
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,
Wei Liu967fc8d2016-07-08 11:44:20 -070097 BUGREPORT_OPTION_REMOTE,
98 BUGREPORT_OPTION_WEAR
Michal Karpinski3da5c972015-12-11 18:16:30 +000099 })
Michal Karpinski3da5c972015-12-11 18:16:30 +0000100 public @interface BugreportMode {}
101 /**
102 * Takes a bugreport without user interference (and hence causing less
103 * interference to the system), but includes all sections.
104 * @hide
105 */
106 public static final int BUGREPORT_OPTION_FULL = 0;
107 /**
108 * Allows user to monitor progress and enter additional data; might not include all
109 * sections.
110 * @hide
111 */
112 public static final int BUGREPORT_OPTION_INTERACTIVE = 1;
113 /**
114 * Takes a bugreport requested remotely by administrator of the Device Owner app,
115 * not the device's user.
116 * @hide
117 */
118 public static final int BUGREPORT_OPTION_REMOTE = 2;
Wei Liu967fc8d2016-07-08 11:44:20 -0700119 /**
120 * Takes a bugreport on a wearable device.
121 * @hide
122 */
123 public static final int BUGREPORT_OPTION_WEAR = 3;
Michal Karpinski3da5c972015-12-11 18:16:30 +0000124
Dianne Hackborna4972e92012-03-14 10:38:05 -0700125 /**
Scott Maincc2195b2013-10-16 13:57:46 -0700126 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000127 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
Christopher Tatebd413f62013-09-18 18:31:59 -0700128 * uninstalled in lieu of the declaring one. The package named here must be
Neil Fuller71fbb812015-11-30 09:51:33 +0000129 * signed with the same certificate as the one declaring the {@code <meta-data>}.
Christopher Tatebd413f62013-09-18 18:31:59 -0700130 */
131 public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
132
133 /**
Amith Yamasani42449782016-04-19 11:45:51 -0700134 * Result for IActivityManager.startVoiceActivity: active session is currently hidden.
135 * @hide
136 */
137 public static final int START_VOICE_HIDDEN_SESSION = -10;
138
139 /**
140 * Result for IActivityManager.startVoiceActivity: active session does not match
141 * the requesting token.
142 * @hide
143 */
144 public static final int START_VOICE_NOT_ACTIVE_SESSION = -9;
145
146 /**
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700147 * Result for IActivityManager.startActivity: trying to start a background user
148 * activity that shouldn't be displayed for all users.
149 * @hide
150 */
151 public static final int START_NOT_CURRENT_USER_ACTIVITY = -8;
152
153 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700154 * Result for IActivityManager.startActivity: trying to start an activity under voice
155 * control when that activity does not support the VOICE category.
156 * @hide
157 */
158 public static final int START_NOT_VOICE_COMPATIBLE = -7;
159
160 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700161 * Result for IActivityManager.startActivity: an error where the
162 * start had to be canceled.
163 * @hide
164 */
165 public static final int START_CANCELED = -6;
166
167 /**
168 * Result for IActivityManager.startActivity: an error where the
169 * thing being started is not an activity.
170 * @hide
171 */
172 public static final int START_NOT_ACTIVITY = -5;
173
174 /**
175 * Result for IActivityManager.startActivity: an error where the
176 * caller does not have permission to start the activity.
177 * @hide
178 */
179 public static final int START_PERMISSION_DENIED = -4;
180
181 /**
182 * Result for IActivityManager.startActivity: an error where the
183 * caller has requested both to forward a result and to receive
184 * a result.
185 * @hide
186 */
187 public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3;
188
189 /**
190 * Result for IActivityManager.startActivity: an error where the
191 * requested class is not found.
192 * @hide
193 */
194 public static final int START_CLASS_NOT_FOUND = -2;
195
196 /**
197 * Result for IActivityManager.startActivity: an error where the
198 * given Intent could not be resolved to an activity.
199 * @hide
200 */
201 public static final int START_INTENT_NOT_RESOLVED = -1;
202
203 /**
204 * Result for IActivityManaqer.startActivity: the activity was started
205 * successfully as normal.
206 * @hide
207 */
208 public static final int START_SUCCESS = 0;
209
210 /**
211 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not
212 * be executed if it is the recipient, and that is indeed the case.
213 * @hide
214 */
215 public static final int START_RETURN_INTENT_TO_CALLER = 1;
216
217 /**
218 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
219 * a task was simply brought to the foreground.
220 * @hide
221 */
222 public static final int START_TASK_TO_FRONT = 2;
223
224 /**
225 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
226 * the given Intent was given to the existing top activity.
227 * @hide
228 */
229 public static final int START_DELIVERED_TO_TOP = 3;
230
231 /**
232 * Result for IActivityManaqer.startActivity: request was canceled because
233 * app switches are temporarily canceled to ensure the user's last request
234 * (such as pressing home) is performed.
235 * @hide
236 */
237 public static final int START_SWITCHES_CANCELED = 4;
238
239 /**
Craig Mautneraea74a52014-03-08 14:23:10 -0800240 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started
241 * while in Lock Task Mode.
242 * @hide
243 */
244 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION = 5;
245
246 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700247 * Flag for IActivityManaqer.startActivity: do special start mode where
248 * a new activity is launched only if it is needed.
249 * @hide
250 */
251 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
252
253 /**
254 * Flag for IActivityManaqer.startActivity: launch the app for
255 * debugging.
256 * @hide
257 */
258 public static final int START_FLAG_DEBUG = 1<<1;
259
260 /**
261 * Flag for IActivityManaqer.startActivity: launch the app for
Man Caocfa78b22015-06-11 20:14:34 -0700262 * allocation tracking.
263 * @hide
264 */
Pablo Ceballosa4d4e822015-10-05 10:27:52 -0700265 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2;
Man Caocfa78b22015-06-11 20:14:34 -0700266
267 /**
Tamas Berghammerdf6cb282016-01-29 12:07:00 +0000268 * Flag for IActivityManaqer.startActivity: launch the app with
269 * native debugging support.
270 * @hide
271 */
272 public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3;
273
274 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700275 * Result for IActivityManaqer.broadcastIntent: success!
276 * @hide
277 */
278 public static final int BROADCAST_SUCCESS = 0;
279
280 /**
281 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast
282 * a sticky intent without appropriate permission.
283 * @hide
284 */
285 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
286
287 /**
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800288 * Result for IActivityManager.broadcastIntent: trying to send a broadcast
289 * to a stopped user. Fail.
290 * @hide
291 */
292 public static final int BROADCAST_FAILED_USER_STOPPED = -2;
293
294 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700295 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
296 * for a sendBroadcast operation.
297 * @hide
298 */
299 public static final int INTENT_SENDER_BROADCAST = 1;
300
301 /**
302 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
303 * for a startActivity operation.
304 * @hide
305 */
306 public static final int INTENT_SENDER_ACTIVITY = 2;
307
308 /**
309 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
310 * for an activity result operation.
311 * @hide
312 */
313 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
314
315 /**
316 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
317 * for a startService operation.
318 * @hide
319 */
320 public static final int INTENT_SENDER_SERVICE = 4;
321
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700322 /** @hide User operation call: success! */
323 public static final int USER_OP_SUCCESS = 0;
324
325 /** @hide User operation call: given user id is not known. */
326 public static final int USER_OP_UNKNOWN_USER = -1;
327
328 /** @hide User operation call: given user id is the current user, can't be stopped. */
329 public static final int USER_OP_IS_CURRENT = -2;
330
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700331 /** @hide User operation call: system user can't be stopped. */
332 public static final int USER_OP_ERROR_IS_SYSTEM = -3;
333
334 /** @hide User operation call: one of related users cannot be stopped. */
335 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4;
336
Ruben Brunka27eef42015-01-28 15:04:16 -0800337 /** @hide Process does not exist. */
338 public static final int PROCESS_STATE_NONEXISTENT = -1;
339
Dianne Hackborna413dc02013-07-12 12:02:55 -0700340 /** @hide Process is a persistent system process. */
341 public static final int PROCESS_STATE_PERSISTENT = 0;
342
343 /** @hide Process is a persistent system process and is doing UI. */
344 public static final int PROCESS_STATE_PERSISTENT_UI = 1;
345
Dianne Hackbornc8230512013-07-13 21:32:12 -0700346 /** @hide Process is hosting the current top activities. Note that this covers
347 * all activities that are visible to the user. */
Dianne Hackborna413dc02013-07-12 12:02:55 -0700348 public static final int PROCESS_STATE_TOP = 2;
349
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700350 /** @hide Process is hosting a foreground service due to a system binding. */
351 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 3;
352
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700353 /** @hide Process is hosting a foreground service. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700354 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700355
356 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700357 public static final int PROCESS_STATE_TOP_SLEEPING = 5;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700358
Dianne Hackborna413dc02013-07-12 12:02:55 -0700359 /** @hide Process is important to the user, and something they are aware of. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700360 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700361
362 /** @hide Process is important to the user, but not something they are aware of. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700363 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700364
Dianne Hackborna413dc02013-07-12 12:02:55 -0700365 /** @hide Process is in the background running a backup/restore operation. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700366 public static final int PROCESS_STATE_BACKUP = 8;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700367
Dianne Hackbornc8230512013-07-13 21:32:12 -0700368 /** @hide Process is in the background, but it can't restore its state so we want
369 * to try to avoid killing it. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700370 public static final int PROCESS_STATE_HEAVY_WEIGHT = 9;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700371
372 /** @hide Process is in the background running a service. Unlike oom_adj, this level
373 * is used for both the normal running in background state and the executing
374 * operations state. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700375 public static final int PROCESS_STATE_SERVICE = 10;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700376
Dianne Hackbornc8230512013-07-13 21:32:12 -0700377 /** @hide Process is in the background running a receiver. Note that from the
378 * perspective of oom_adj receivers run at a higher foreground level, but for our
379 * prioritization here that is not necessary and putting them below services means
380 * many fewer changes in some process states as they receive broadcasts. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700381 public static final int PROCESS_STATE_RECEIVER = 11;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700382
Dianne Hackborna413dc02013-07-12 12:02:55 -0700383 /** @hide Process is in the background but hosts the home activity. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700384 public static final int PROCESS_STATE_HOME = 12;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700385
386 /** @hide Process is in the background but hosts the last shown activity. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700387 public static final int PROCESS_STATE_LAST_ACTIVITY = 13;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700388
Dianne Hackbornc8230512013-07-13 21:32:12 -0700389 /** @hide Process is being cached for later use and contains activities. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700390 public static final int PROCESS_STATE_CACHED_ACTIVITY = 14;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700391
392 /** @hide Process is being cached for later use and is a client of another cached
393 * process that contains activities. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700394 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 15;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700395
396 /** @hide Process is being cached for later use and is empty. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700397 public static final int PROCESS_STATE_CACHED_EMPTY = 16;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700398
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700399 /** @hide The lowest process state number */
400 public static final int MIN_PROCESS_STATE = PROCESS_STATE_NONEXISTENT;
401
402 /** @hide The highest process state number */
403 public static final int MAX_PROCESS_STATE = PROCESS_STATE_CACHED_EMPTY;
404
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700405 /** @hide Should this process state be considered a background state? */
406 public static final boolean isProcStateBackground(int procState) {
407 return procState >= PROCESS_STATE_BACKUP;
408 }
409
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700410 /** @hide requestType for assist context: only basic information. */
411 public static final int ASSIST_CONTEXT_BASIC = 0;
412
413 /** @hide requestType for assist context: generate full AssistStructure. */
414 public static final int ASSIST_CONTEXT_FULL = 1;
415
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700416 /** @hide Flag for registerUidObserver: report changes in process state. */
417 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
418
419 /** @hide Flag for registerUidObserver: report uid gone. */
420 public static final int UID_OBSERVER_GONE = 1<<1;
421
422 /** @hide Flag for registerUidObserver: report uid has become idle. */
423 public static final int UID_OBSERVER_IDLE = 1<<2;
424
425 /** @hide Flag for registerUidObserver: report uid has become active. */
426 public static final int UID_OBSERVER_ACTIVE = 1<<3;
427
428 /** @hide Mode for {@link IActivityManager#getAppStartMode}: normal free-to-run operation. */
429 public static final int APP_START_MODE_NORMAL = 0;
430
431 /** @hide Mode for {@link IActivityManager#getAppStartMode}: delay running until later. */
432 public static final int APP_START_MODE_DELAYED = 1;
433
434 /** @hide Mode for {@link IActivityManager#getAppStartMode}: disable/cancel pending
435 * launches. */
436 public static final int APP_START_MODE_DISABLED = 2;
437
Benjamin Franz43261142015-02-11 15:59:44 +0000438 /**
439 * Lock task mode is not active.
440 */
441 public static final int LOCK_TASK_MODE_NONE = 0;
442
443 /**
444 * Full lock task mode is active.
445 */
446 public static final int LOCK_TASK_MODE_LOCKED = 1;
447
448 /**
449 * App pinning mode is active.
450 */
451 public static final int LOCK_TASK_MODE_PINNED = 2;
452
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700453 Point mAppTaskThumbnailSize;
454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 /*package*/ ActivityManager(Context context, Handler handler) {
456 mContext = context;
457 mHandler = handler;
458 }
459
460 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700461 * Screen compatibility mode: the application most always run in
462 * compatibility mode.
463 * @hide
464 */
465 public static final int COMPAT_MODE_ALWAYS = -1;
466
467 /**
468 * Screen compatibility mode: the application can never run in
469 * compatibility mode.
470 * @hide
471 */
472 public static final int COMPAT_MODE_NEVER = -2;
473
474 /**
475 * Screen compatibility mode: unknown.
476 * @hide
477 */
478 public static final int COMPAT_MODE_UNKNOWN = -3;
479
480 /**
481 * Screen compatibility mode: the application currently has compatibility
482 * mode disabled.
483 * @hide
484 */
485 public static final int COMPAT_MODE_DISABLED = 0;
486
487 /**
488 * Screen compatibility mode: the application currently has compatibility
489 * mode enabled.
490 * @hide
491 */
492 public static final int COMPAT_MODE_ENABLED = 1;
493
494 /**
495 * Screen compatibility mode: request to toggle the application's
496 * compatibility mode.
497 * @hide
498 */
499 public static final int COMPAT_MODE_TOGGLE = 2;
500
Wale Ogunwale3797c222015-10-27 14:21:58 -0700501 /** @hide */
502 public static class StackId {
503 /** Invalid stack ID. */
504 public static final int INVALID_STACK_ID = -1;
Chong Zhang5dcb2752015-08-18 13:50:26 -0700505
Wale Ogunwale3797c222015-10-27 14:21:58 -0700506 /** First static stack ID. */
507 public static final int FIRST_STATIC_STACK_ID = 0;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700508
Wale Ogunwale3797c222015-10-27 14:21:58 -0700509 /** Home activity stack ID. */
510 public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700511
Wale Ogunwale3797c222015-10-27 14:21:58 -0700512 /** ID of stack where fullscreen activities are normally launched into. */
513 public static final int FULLSCREEN_WORKSPACE_STACK_ID = 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700514
Wale Ogunwale3797c222015-10-27 14:21:58 -0700515 /** ID of stack where freeform/resized activities are normally launched into. */
516 public static final int FREEFORM_WORKSPACE_STACK_ID = FULLSCREEN_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700517
Wale Ogunwale3797c222015-10-27 14:21:58 -0700518 /** ID of stack that occupies a dedicated region of the screen. */
519 public static final int DOCKED_STACK_ID = FREEFORM_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700520
Wale Ogunwale3797c222015-10-27 14:21:58 -0700521 /** ID of stack that always on top (always visible) when it exist. */
522 public static final int PINNED_STACK_ID = DOCKED_STACK_ID + 1;
Wale Ogunwale99db1862015-10-23 20:08:22 -0700523
Wale Ogunwale3797c222015-10-27 14:21:58 -0700524 /** Last static stack stack ID. */
525 public static final int LAST_STATIC_STACK_ID = PINNED_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700526
Wale Ogunwale3797c222015-10-27 14:21:58 -0700527 /** Start of ID range used by stacks that are created dynamically. */
528 public static final int FIRST_DYNAMIC_STACK_ID = LAST_STATIC_STACK_ID + 1;
529
530 public static boolean isStaticStack(int stackId) {
531 return stackId >= FIRST_STATIC_STACK_ID && stackId <= LAST_STATIC_STACK_ID;
532 }
533
534 /**
535 * Returns true if the activities contained in the input stack display a shadow around
536 * their border.
537 */
538 public static boolean hasWindowShadow(int stackId) {
539 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID;
540 }
541
542 /**
543 * Returns true if the activities contained in the input stack display a decor view.
544 */
545 public static boolean hasWindowDecor(int stackId) {
546 return stackId == FREEFORM_WORKSPACE_STACK_ID;
547 }
548
549 /**
550 * Returns true if the tasks contained in the stack can be resized independently of the
551 * stack.
552 */
553 public static boolean isTaskResizeAllowed(int stackId) {
554 return stackId == FREEFORM_WORKSPACE_STACK_ID;
555 }
556
Wale Ogunwale807d8822015-12-15 17:05:09 -0800557 /** Returns true if the task bounds should persist across power cycles. */
Wale Ogunwale3797c222015-10-27 14:21:58 -0700558 public static boolean persistTaskBounds(int stackId) {
Wale Ogunwale807d8822015-12-15 17:05:09 -0800559 return stackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700560 }
561
562 /**
563 * Returns true if dynamic stacks are allowed to be visible behind the input stack.
564 */
565 public static boolean isDynamicStacksVisibleBehindAllowed(int stackId) {
566 return stackId == PINNED_STACK_ID;
567 }
568
569 /**
570 * Returns true if we try to maintain focus in the current stack when the top activity
571 * finishes.
572 */
573 public static boolean keepFocusInStackIfPossible(int stackId) {
574 return stackId == FREEFORM_WORKSPACE_STACK_ID
575 || stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID;
576 }
577
578 /**
579 * Returns true if Stack size is affected by the docked stack changing size.
580 */
581 public static boolean isResizeableByDockedStack(int stackId) {
582 return isStaticStack(stackId) &&
583 stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID;
584 }
585
586 /**
587 * Returns true if the size of tasks in the input stack are affected by the docked stack
588 * changing size.
589 */
590 public static boolean isTaskResizeableByDockedStack(int stackId) {
591 return isStaticStack(stackId) && stackId != FREEFORM_WORKSPACE_STACK_ID
592 && stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID;
593 }
594
595 /**
Jorim Jaggie9098022016-01-27 19:29:40 -0800596 * Returns true if the windows of tasks being moved to the target stack from the source
597 * stack should be replaced, meaning that window manager will keep the old window around
598 * until the new is ready.
Wale Ogunwale3797c222015-10-27 14:21:58 -0700599 */
Jorim Jaggie9098022016-01-27 19:29:40 -0800600 public static boolean replaceWindowsOnTaskMove(int sourceStackId, int targetStackId) {
601 return sourceStackId == FREEFORM_WORKSPACE_STACK_ID
602 || targetStackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700603 }
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800604
605 /**
Robert Carre6275582016-02-29 15:45:45 -0800606 * Return whether a stackId is a stack containing floating windows. Floating windows
607 * are laid out differently as they are allowed to extend past the display bounds
608 * without overscan insets.
609 */
610 public static boolean tasksAreFloating(int stackId) {
611 return stackId == FREEFORM_WORKSPACE_STACK_ID
612 || stackId == PINNED_STACK_ID;
613 }
614
615 /**
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800616 * Returns true if animation specs should be constructed for app transition that moves
617 * the task to the specified stack.
618 */
619 public static boolean useAnimationSpecForAppTransition(int stackId) {
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800620
621 // TODO: INVALID_STACK_ID is also animated because we don't persist stack id's across
622 // reboots.
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800623 return stackId == FREEFORM_WORKSPACE_STACK_ID
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800624 || stackId == FULLSCREEN_WORKSPACE_STACK_ID || stackId == DOCKED_STACK_ID
625 || stackId == INVALID_STACK_ID;
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800626 }
Wale Ogunwaled045c822015-12-02 09:14:28 -0800627
628 /** Returns true if the windows in the stack can receive input keys. */
629 public static boolean canReceiveKeys(int stackId) {
630 return stackId != PINNED_STACK_ID;
631 }
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800632
Chong Zhang75b37202015-12-04 14:16:36 -0800633 /**
634 * Returns true if the stack can be visible above lockscreen.
635 */
636 public static boolean isAllowedOverLockscreen(int stackId) {
637 return stackId == HOME_STACK_ID || stackId == FULLSCREEN_WORKSPACE_STACK_ID;
638 }
639
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800640 public static boolean isAlwaysOnTop(int stackId) {
641 return stackId == PINNED_STACK_ID;
642 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800643
644 /**
645 * Returns true if the top task in the task is allowed to return home when finished and
646 * there are other tasks in the stack.
647 */
648 public static boolean allowTopTaskToReturnHome(int stackId) {
649 return stackId != PINNED_STACK_ID;
650 }
Wale Ogunwalecacfaa22016-01-15 11:26:08 -0800651
652 /**
653 * Returns true if the stack should be resized to match the bounds specified by
654 * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack.
655 */
656 public static boolean resizeStackWithLaunchBounds(int stackId) {
657 return stackId == PINNED_STACK_ID;
658 }
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -0800659
660 /**
661 * Returns true if any visible windows belonging to apps in this stack should be kept on
662 * screen when the app is killed due to something like the low memory killer.
663 */
664 public static boolean keepVisibleDeadAppWindowOnScreen(int stackId) {
665 return stackId != PINNED_STACK_ID;
666 }
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800667
668 /**
669 * Returns true if the backdrop on the client side should match the frame of the window.
670 * Returns false, if the backdrop should be fullscreen.
671 */
672 public static boolean useWindowFrameForBackdrop(int stackId) {
673 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID;
674 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800675
676 /**
677 * Returns true if a window from the specified stack with {@param stackId} are normally
678 * fullscreen, i. e. they can become the top opaque fullscreen window, meaning that it
679 * controls system bars, lockscreen occluded/dismissing state, screen rotation animation,
680 * etc.
681 */
682 public static boolean normallyFullscreenWindows(int stackId) {
683 return stackId != PINNED_STACK_ID && stackId != FREEFORM_WORKSPACE_STACK_ID
684 && stackId != DOCKED_STACK_ID;
685 }
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800686
687 /**
688 * Returns true if the input stack id should only be present on a device that supports
689 * multi-window mode.
690 * @see android.app.ActivityManager#supportsMultiWindow
691 */
692 public static boolean isMultiWindowStack(int stackId) {
693 return isStaticStack(stackId) || stackId == PINNED_STACK_ID
694 || stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == DOCKED_STACK_ID;
695 }
Wale Ogunwale43896cf2016-04-16 10:54:30 -0700696
697 /**
698 * Returns true if activities contained in this stack can request visible behind by
699 * calling {@link Activity#requestVisibleBehind}.
700 */
701 public static boolean activitiesCanRequestVisibleBehind(int stackId) {
702 return stackId == FULLSCREEN_WORKSPACE_STACK_ID;
703 }
Robert Carr1b5ea722016-04-20 13:23:28 -0700704
705 /**
706 * Returns true if this stack may be scaled without resizing,
707 * and windows within may need to be configured as such.
708 */
709 public static boolean windowsAreScaleable(int stackId) {
710 return stackId == PINNED_STACK_ID;
711 }
Robert Carrc7294602016-05-13 11:32:05 -0700712
713 /**
714 * Returns true if windows in this stack should be given move animations
715 * by default.
716 */
717 public static boolean hasMovementAnimations(int stackId) {
718 return stackId != PINNED_STACK_ID;
719 }
Wale Ogunwale51362492016-09-08 17:49:17 -0700720
721 /** Returns true if the input stack and its content can affect the device orientation. */
722 public static boolean canSpecifyOrientation(int stackId) {
723 return stackId == HOME_STACK_ID || stackId == FULLSCREEN_WORKSPACE_STACK_ID;
724 }
Wale Ogunwale3797c222015-10-27 14:21:58 -0700725 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700726
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700727 /**
728 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
729 * specifies the position of the created docked stack at the top half of the screen if
730 * in portrait mode or at the left half of the screen if in landscape mode.
731 * @hide
732 */
733 public static final int DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT = 0;
734
735 /**
736 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
737 * specifies the position of the created docked stack at the bottom half of the screen if
738 * in portrait mode or at the right half of the screen if in landscape mode.
739 * @hide
740 */
741 public static final int DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT = 1;
742
Chong Zhang87b21722015-09-21 15:39:51 -0700743 /**
744 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700745 * that the resize doesn't need to preserve the window, and can be skipped if bounds
746 * is unchanged. This mode is used by window manager in most cases.
Chong Zhang87b21722015-09-21 15:39:51 -0700747 * @hide
748 */
749 public static final int RESIZE_MODE_SYSTEM = 0;
750
751 /**
752 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700753 * that the resize should preserve the window if possible.
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700754 * @hide
755 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700756 public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0);
Chong Zhang87b21722015-09-21 15:39:51 -0700757
758 /**
759 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
760 * that the resize should be performed even if the bounds appears unchanged.
761 * @hide
762 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700763 public static final int RESIZE_MODE_FORCED = (0x1 << 1);
764
765 /**
766 * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window
767 * manager during a screen rotation.
768 * @hide
769 */
770 public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW;
771
772 /**
773 * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the
774 * resize is due to a drag action.
775 * @hide
776 */
777 public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW;
778
779 /**
780 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
781 * that the resize should preserve the window if possible, and should not be skipped
782 * even if the bounds is unchanged. Usually used to force a resizing when a drag action
783 * is ending.
784 * @hide
785 */
786 public static final int RESIZE_MODE_USER_FORCED =
787 RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED;
Chong Zhang87b21722015-09-21 15:39:51 -0700788
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700789 /** @hide */
790 public int getFrontActivityScreenCompatMode() {
791 try {
792 return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode();
793 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700794 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700795 }
796 }
797
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700798 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700799 public void setFrontActivityScreenCompatMode(int mode) {
800 try {
801 ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode);
802 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700803 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700804 }
805 }
806
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700807 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700808 public int getPackageScreenCompatMode(String packageName) {
809 try {
810 return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName);
811 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700812 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700813 }
814 }
815
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700816 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700817 public void setPackageScreenCompatMode(String packageName, int mode) {
818 try {
819 ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode);
820 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700821 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700822 }
823 }
824
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700825 /** @hide */
826 public boolean getPackageAskScreenCompat(String packageName) {
827 try {
828 return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName);
829 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700830 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700831 }
832 }
833
834 /** @hide */
835 public void setPackageAskScreenCompat(String packageName, boolean ask) {
836 try {
837 ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask);
838 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700839 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700840 }
841 }
842
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700843 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700844 * Return the approximate per-application memory class of the current
845 * device. This gives you an idea of how hard a memory limit you should
846 * impose on your application to let the overall system work best. The
847 * returned value is in megabytes; the baseline Android memory class is
848 * 16 (which happens to be the Java heap limit of those devices); some
849 * device with more memory may return 24 or even higher numbers.
850 */
851 public int getMemoryClass() {
852 return staticGetMemoryClass();
853 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700854
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700855 /** @hide */
856 static public int staticGetMemoryClass() {
857 // Really brain dead right now -- just take this from the configured
858 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -0800859 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -0800860 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
861 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
862 }
863 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800864 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700865
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800866 /**
867 * Return the approximate per-application memory class of the current
868 * device when an application is running with a large heap. This is the
869 * space available for memory-intensive applications; most applications
870 * should not need this amount of memory, and should instead stay with the
871 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
872 * This may be the same size as {@link #getMemoryClass()} on memory
873 * constrained devices, or it may be significantly larger on devices with
874 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800875 *
876 * <p>The is the size of the application's Dalvik heap if it has
877 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800878 */
879 public int getLargeMemoryClass() {
880 return staticGetLargeMemoryClass();
881 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700882
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800883 /** @hide */
884 static public int staticGetLargeMemoryClass() {
885 // Really brain dead right now -- just take this from the configured
886 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700887 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -0700888 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700889 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700890
891 /**
892 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
893 * is ultimately up to the device configuration, but currently it generally means
894 * something in the class of a 512MB device with about a 800x480 or less screen.
895 * This is mostly intended to be used by apps to determine whether they should turn
896 * off certain features that require more RAM.
897 */
898 public boolean isLowRamDevice() {
899 return isLowRamDeviceStatic();
900 }
901
902 /** @hide */
903 public static boolean isLowRamDeviceStatic() {
John Reckaa67f682016-09-20 14:24:21 -0700904 return RoSystemProperties.CONFIG_LOW_RAM;
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700905 }
906
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700907 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -0700908 * Used by persistent processes to determine if they are running on a
909 * higher-end device so should be okay using hardware drawing acceleration
910 * (which tends to consume a lot more RAM).
911 * @hide
912 */
Jeff Brown98365d72012-08-19 20:30:52 -0700913 static public boolean isHighEndGfx() {
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700914 return !isLowRamDeviceStatic() &&
915 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -0700916 }
917
918 /**
Dianne Hackborn852975d2014-08-22 17:42:43 -0700919 * Return the maximum number of recents entries that we will maintain and show.
920 * @hide
921 */
922 static public int getMaxRecentTasksStatic() {
923 if (gMaxRecentTasks < 0) {
Winson7c402912016-05-10 13:59:36 -0700924 return gMaxRecentTasks = isLowRamDeviceStatic() ? 36 : 48;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700925 }
926 return gMaxRecentTasks;
927 }
928
929 /**
930 * Return the default limit on the number of recents that an app can make.
931 * @hide
932 */
933 static public int getDefaultAppRecentsLimitStatic() {
934 return getMaxRecentTasksStatic() / 6;
935 }
936
937 /**
938 * Return the maximum limit on the number of recents that an app can make.
939 * @hide
940 */
941 static public int getMaxAppRecentsLimitStatic() {
942 return getMaxRecentTasksStatic() / 2;
943 }
944
945 /**
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800946 * Returns true if the system supports at least one form of multi-window.
947 * E.g. freeform, split-screen, picture-in-picture.
948 * @hide
949 */
950 static public boolean supportsMultiWindow() {
951 return !isLowRamDeviceStatic()
952 && Resources.getSystem().getBoolean(
953 com.android.internal.R.bool.config_supportsMultiWindow);
954 }
955
956 /**
Winson Chung1147c402014-05-14 11:05:00 -0700957 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -0700958 */
Winson Chunga449dc02014-05-16 11:15:04 -0700959 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -0700960 /** @hide */
961 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
962 private static final String ATTR_TASKDESCRIPTIONLABEL =
963 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +0000964 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -0700965 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +0000966 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
967 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Craig Mautner648f69b2014-09-18 14:16:26 -0700968 private static final String ATTR_TASKDESCRIPTIONICONFILENAME =
969 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
970
Winson Chunga449dc02014-05-16 11:15:04 -0700971 private String mLabel;
972 private Bitmap mIcon;
Craig Mautner648f69b2014-09-18 14:16:26 -0700973 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -0700974 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +0000975 private int mColorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -0700976
977 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700978 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700979 *
Winson Chunga449dc02014-05-16 11:15:04 -0700980 * @param label A label and description of the current state of this task.
981 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +0000982 * @param colorPrimary A color to override the theme's primary color. This color must be
983 * opaque.
Winson Chung03a9bae2014-05-02 09:56:12 -0700984 */
Winson Chunga449dc02014-05-16 11:15:04 -0700985 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Winson Chung1af8eda2016-02-05 17:55:56 +0000986 this(label, icon, null, colorPrimary, 0);
Winson Chunga449dc02014-05-16 11:15:04 -0700987 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
988 throw new RuntimeException("A TaskDescription's primary color should be opaque");
989 }
Craig Mautner648f69b2014-09-18 14:16:26 -0700990 }
991
Winson Chung03a9bae2014-05-02 09:56:12 -0700992 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700993 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700994 *
995 * @param label A label and description of the current state of this activity.
996 * @param icon An icon that represents the current state of this activity.
997 */
Winson Chunga449dc02014-05-16 11:15:04 -0700998 public TaskDescription(String label, Bitmap icon) {
Winson Chung1af8eda2016-02-05 17:55:56 +0000999 this(label, icon, null, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001000 }
1001
1002 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001003 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001004 *
1005 * @param label A label and description of the current state of this activity.
1006 */
Winson Chunga449dc02014-05-16 11:15:04 -07001007 public TaskDescription(String label) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001008 this(label, null, null, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001009 }
1010
Winson Chunga449dc02014-05-16 11:15:04 -07001011 /**
1012 * Creates an empty TaskDescription.
1013 */
1014 public TaskDescription() {
Winson Chung1af8eda2016-02-05 17:55:56 +00001015 this(null, null, null, 0, 0);
1016 }
1017
1018 /** @hide */
1019 public TaskDescription(String label, Bitmap icon, String iconFilename, int colorPrimary,
1020 int colorBackground) {
1021 mLabel = label;
1022 mIcon = icon;
1023 mIconFilename = iconFilename;
1024 mColorPrimary = colorPrimary;
1025 mColorBackground = colorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -07001026 }
1027
Winson Chunga449dc02014-05-16 11:15:04 -07001028 /**
1029 * Creates a copy of another TaskDescription.
1030 */
1031 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -08001032 copyFrom(td);
1033 }
1034
1035 /**
1036 * Copies this the values from another TaskDescription.
1037 * @hide
1038 */
1039 public void copyFrom(TaskDescription other) {
1040 mLabel = other.mLabel;
1041 mIcon = other.mIcon;
1042 mIconFilename = other.mIconFilename;
1043 mColorPrimary = other.mColorPrimary;
1044 mColorBackground = other.mColorBackground;
Winson Chunga449dc02014-05-16 11:15:04 -07001045 }
1046
1047 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001048 readFromParcel(source);
1049 }
1050
1051 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001052 * Sets the label for this task description.
1053 * @hide
1054 */
1055 public void setLabel(String label) {
1056 mLabel = label;
1057 }
1058
1059 /**
1060 * Sets the primary color for this task description.
1061 * @hide
1062 */
1063 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001064 // Ensure that the given color is valid
1065 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1066 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1067 }
1068 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001069 }
1070
1071 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001072 * Sets the background color for this task description.
1073 * @hide
1074 */
1075 public void setBackgroundColor(int backgroundColor) {
1076 // Ensure that the given color is valid
1077 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1078 throw new RuntimeException("A TaskDescription's background color should be opaque");
1079 }
1080 mColorBackground = backgroundColor;
1081 }
1082
1083 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001084 * Sets the icon for this task description.
1085 * @hide
1086 */
1087 public void setIcon(Bitmap icon) {
1088 mIcon = icon;
1089 }
1090
1091 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001092 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1093 * bitmap.
1094 * @hide
1095 */
1096 public void setIconFilename(String iconFilename) {
1097 mIconFilename = iconFilename;
1098 mIcon = null;
1099 }
1100
1101 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001102 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001103 */
Winson Chunga449dc02014-05-16 11:15:04 -07001104 public String getLabel() {
1105 return mLabel;
1106 }
1107
1108 /**
1109 * @return The icon that represents the current state of this task.
1110 */
1111 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001112 if (mIcon != null) {
1113 return mIcon;
1114 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001115 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001116 }
1117
1118 /** @hide */
1119 public String getIconFilename() {
1120 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001121 }
1122
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001123 /** @hide */
1124 public Bitmap getInMemoryIcon() {
1125 return mIcon;
1126 }
1127
1128 /** @hide */
Suprabh Shukla23593142015-11-03 17:31:15 -08001129 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001130 if (iconFilename != null) {
1131 try {
Winson Chung1af8eda2016-02-05 17:55:56 +00001132 return ActivityManagerNative.getDefault().getTaskDescriptionIcon(iconFilename,
1133 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001134 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001135 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001136 }
1137 }
1138 return null;
1139 }
1140
Winson Chunga449dc02014-05-16 11:15:04 -07001141 /**
1142 * @return The color override on the theme's primary color.
1143 */
1144 public int getPrimaryColor() {
1145 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001146 }
1147
Winson Chung1af8eda2016-02-05 17:55:56 +00001148 /**
1149 * @return The background color.
1150 * @hide
1151 */
1152 public int getBackgroundColor() {
1153 return mColorBackground;
1154 }
1155
Craig Mautner648f69b2014-09-18 14:16:26 -07001156 /** @hide */
1157 public void saveToXml(XmlSerializer out) throws IOException {
1158 if (mLabel != null) {
1159 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1160 }
1161 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001162 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1163 Integer.toHexString(mColorPrimary));
1164 }
1165 if (mColorBackground != 0) {
1166 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1167 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001168 }
1169 if (mIconFilename != null) {
1170 out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename);
1171 }
1172 }
1173
1174 /** @hide */
1175 public void restoreFromXml(String attrName, String attrValue) {
1176 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1177 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001178 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001179 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001180 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1181 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Craig Mautner648f69b2014-09-18 14:16:26 -07001182 } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) {
1183 setIconFilename(attrValue);
1184 }
1185 }
1186
Winson Chung03a9bae2014-05-02 09:56:12 -07001187 @Override
1188 public int describeContents() {
1189 return 0;
1190 }
1191
1192 @Override
1193 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001194 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001195 dest.writeInt(0);
1196 } else {
1197 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001198 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001199 }
Winson Chunga449dc02014-05-16 11:15:04 -07001200 if (mIcon == null) {
1201 dest.writeInt(0);
1202 } else {
1203 dest.writeInt(1);
1204 mIcon.writeToParcel(dest, 0);
1205 }
1206 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001207 dest.writeInt(mColorBackground);
Craig Mautner648f69b2014-09-18 14:16:26 -07001208 if (mIconFilename == null) {
1209 dest.writeInt(0);
1210 } else {
1211 dest.writeInt(1);
1212 dest.writeString(mIconFilename);
1213 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001214 }
1215
1216 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001217 mLabel = source.readInt() > 0 ? source.readString() : null;
1218 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
1219 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001220 mColorBackground = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001221 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001222 }
1223
Winson Chunga449dc02014-05-16 11:15:04 -07001224 public static final Creator<TaskDescription> CREATOR
1225 = new Creator<TaskDescription>() {
1226 public TaskDescription createFromParcel(Parcel source) {
1227 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001228 }
Winson Chunga449dc02014-05-16 11:15:04 -07001229 public TaskDescription[] newArray(int size) {
1230 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001231 }
1232 };
1233
1234 @Override
1235 public String toString() {
Winson Chunga449dc02014-05-16 11:15:04 -07001236 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
Winson Chung1af8eda2016-02-05 17:55:56 +00001237 " IconFilename: " + mIconFilename + " colorPrimary: " + mColorPrimary +
1238 " colorBackground: " + mColorBackground;
Winson Chung03a9bae2014-05-02 09:56:12 -07001239 }
1240 }
1241
1242 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 * Information you can retrieve about tasks that the user has most recently
1244 * started or visited.
1245 */
1246 public static class RecentTaskInfo implements Parcelable {
1247 /**
1248 * If this task is currently running, this is the identifier for it.
1249 * If it is not running, this will be -1.
1250 */
1251 public int id;
1252
1253 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001254 * The true identifier of this task, valid even if it is not running.
1255 */
1256 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001257
Dianne Hackbornd94df452011-02-16 18:53:31 -08001258 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 * The original Intent used to launch the task. You can use this
1260 * Intent to re-launch the task (if it is no longer running) or bring
1261 * the current task to the front.
1262 */
1263 public Intent baseIntent;
1264
1265 /**
1266 * If this task was started from an alias, this is the actual
1267 * activity component that was initially started; the component of
1268 * the baseIntent in this case is the name of the actual activity
1269 * implementation that the alias referred to. Otherwise, this is null.
1270 */
1271 public ComponentName origActivity;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001272
1273 /**
James Cook4d0ef042015-07-09 14:28:23 -07001274 * The actual activity component that started the task.
1275 * @hide
1276 */
1277 @Nullable
1278 public ComponentName realActivity;
1279
1280 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001281 * Description of the task's last state.
1282 */
1283 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001284
1285 /**
1286 * The id of the ActivityStack this Task was on most recently.
Craig Mautner27030522013-08-26 12:25:36 -07001287 * @hide
Craig Mautner6d90fed2013-05-22 15:03:10 -07001288 */
1289 public int stackId;
1290
Kenny Guy82326a92014-03-17 17:16:06 +00001291 /**
Craig Mautner2fbd7542014-03-21 09:34:07 -07001292 * The id of the user the task was running as.
Kenny Guy82326a92014-03-17 17:16:06 +00001293 * @hide
1294 */
1295 public int userId;
1296
Craig Mautner2fbd7542014-03-21 09:34:07 -07001297 /**
Winson Chungffa2ec62014-07-03 15:54:42 -07001298 * The first time this task was active.
1299 * @hide
1300 */
1301 public long firstActiveTime;
1302
1303 /**
Winson Chungf1fbd772014-06-24 18:06:58 -07001304 * The last time this task was active.
1305 * @hide
1306 */
1307 public long lastActiveTime;
1308
1309 /**
Winson Chung03a9bae2014-05-02 09:56:12 -07001310 * The recent activity values for the highest activity in the stack to have set the values.
Winson Chunga449dc02014-05-16 11:15:04 -07001311 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
Craig Mautner2fbd7542014-03-21 09:34:07 -07001312 */
Winson Chunga449dc02014-05-16 11:15:04 -07001313 public TaskDescription taskDescription;
Craig Mautner2fbd7542014-03-21 09:34:07 -07001314
Craig Mautnera228ae92014-07-09 05:44:55 -07001315 /**
1316 * Task affiliation for grouping with other tasks.
Craig Mautnera228ae92014-07-09 05:44:55 -07001317 */
1318 public int affiliatedTaskId;
1319
Winson Chungec396d62014-08-06 17:08:00 -07001320 /**
1321 * Task affiliation color of the source task with the affiliated task id.
1322 *
1323 * @hide
1324 */
1325 public int affiliatedTaskColor;
1326
Wale Ogunwale6035e012015-04-14 15:54:10 -07001327 /**
1328 * The component launched as the first activity in the task.
1329 * This can be considered the "application" of this task.
1330 */
1331 public ComponentName baseActivity;
1332
1333 /**
1334 * The activity component at the top of the history stack of the task.
1335 * This is what the user is currently doing.
1336 */
1337 public ComponentName topActivity;
1338
1339 /**
1340 * Number of activities in this task.
1341 */
1342 public int numActivities;
1343
Winson2dd76942015-11-02 09:20:01 -08001344 /**
1345 * The bounds of the task.
1346 * @hide
1347 */
1348 public Rect bounds;
1349
Wale Ogunwale21b60582016-01-27 12:34:16 -08001350 /**
1351 * True if the task can go in the docked stack.
1352 * @hide
1353 */
1354 public boolean isDockable;
1355
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001356 /**
1357 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1358 * @hide
1359 */
1360 public int resizeMode;
1361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 public RecentTaskInfo() {
1363 }
1364
Craig Mautner6d90fed2013-05-22 15:03:10 -07001365 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 public int describeContents() {
1367 return 0;
1368 }
1369
Craig Mautner6d90fed2013-05-22 15:03:10 -07001370 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001371 public void writeToParcel(Parcel dest, int flags) {
1372 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001373 dest.writeInt(persistentId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 if (baseIntent != null) {
1375 dest.writeInt(1);
1376 baseIntent.writeToParcel(dest, 0);
1377 } else {
1378 dest.writeInt(0);
1379 }
1380 ComponentName.writeToParcel(origActivity, dest);
James Cook4d0ef042015-07-09 14:28:23 -07001381 ComponentName.writeToParcel(realActivity, dest);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001382 TextUtils.writeToParcel(description, dest,
1383 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
Winson Chunga449dc02014-05-16 11:15:04 -07001384 if (taskDescription != null) {
Craig Mautner2fbd7542014-03-21 09:34:07 -07001385 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001386 taskDescription.writeToParcel(dest, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001387 } else {
1388 dest.writeInt(0);
Craig Mautner2fbd7542014-03-21 09:34:07 -07001389 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001390 dest.writeInt(stackId);
Kenny Guy82326a92014-03-17 17:16:06 +00001391 dest.writeInt(userId);
Winson Chungffa2ec62014-07-03 15:54:42 -07001392 dest.writeLong(firstActiveTime);
Winson Chungf1fbd772014-06-24 18:06:58 -07001393 dest.writeLong(lastActiveTime);
Craig Mautnera228ae92014-07-09 05:44:55 -07001394 dest.writeInt(affiliatedTaskId);
Winson Chungec396d62014-08-06 17:08:00 -07001395 dest.writeInt(affiliatedTaskColor);
Wale Ogunwale6035e012015-04-14 15:54:10 -07001396 ComponentName.writeToParcel(baseActivity, dest);
1397 ComponentName.writeToParcel(topActivity, dest);
1398 dest.writeInt(numActivities);
Winson2dd76942015-11-02 09:20:01 -08001399 if (bounds != null) {
1400 dest.writeInt(1);
1401 bounds.writeToParcel(dest, 0);
1402 } else {
1403 dest.writeInt(0);
1404 }
Wale Ogunwale21b60582016-01-27 12:34:16 -08001405 dest.writeInt(isDockable ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001406 dest.writeInt(resizeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 }
1408
1409 public void readFromParcel(Parcel source) {
1410 id = source.readInt();
Dianne Hackbornd94df452011-02-16 18:53:31 -08001411 persistentId = source.readInt();
Craig Mautner688b5102014-03-27 16:55:03 -07001412 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001413 origActivity = ComponentName.readFromParcel(source);
James Cook4d0ef042015-07-09 14:28:23 -07001414 realActivity = ComponentName.readFromParcel(source);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001415 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Winson Chunga449dc02014-05-16 11:15:04 -07001416 taskDescription = source.readInt() > 0 ?
1417 TaskDescription.CREATOR.createFromParcel(source) : null;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001418 stackId = source.readInt();
Kenny Guy82326a92014-03-17 17:16:06 +00001419 userId = source.readInt();
Winson Chungffa2ec62014-07-03 15:54:42 -07001420 firstActiveTime = source.readLong();
Winson Chungf1fbd772014-06-24 18:06:58 -07001421 lastActiveTime = source.readLong();
Craig Mautnera228ae92014-07-09 05:44:55 -07001422 affiliatedTaskId = source.readInt();
Winson Chungec396d62014-08-06 17:08:00 -07001423 affiliatedTaskColor = source.readInt();
Wale Ogunwale6035e012015-04-14 15:54:10 -07001424 baseActivity = ComponentName.readFromParcel(source);
1425 topActivity = ComponentName.readFromParcel(source);
1426 numActivities = source.readInt();
Winson2dd76942015-11-02 09:20:01 -08001427 bounds = source.readInt() > 0 ?
1428 Rect.CREATOR.createFromParcel(source) : null;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001429 isDockable = source.readInt() == 1;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001430 resizeMode = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 public static final Creator<RecentTaskInfo> CREATOR
1434 = new Creator<RecentTaskInfo>() {
1435 public RecentTaskInfo createFromParcel(Parcel source) {
1436 return new RecentTaskInfo(source);
1437 }
1438 public RecentTaskInfo[] newArray(int size) {
1439 return new RecentTaskInfo[size];
1440 }
1441 };
1442
1443 private RecentTaskInfo(Parcel source) {
1444 readFromParcel(source);
1445 }
1446 }
1447
1448 /**
1449 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1450 * that have set their
1451 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1452 */
1453 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001455 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001456 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001457 * recent tasks that currently are not available to the user.
1458 */
1459 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001460
1461 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001462 * Provides a list that contains recent tasks for all
1463 * profiles of a user.
Kenny Guy82326a92014-03-17 17:16:06 +00001464 * @hide
1465 */
Kenny Guy2a764942014-04-02 13:29:20 +01001466 public static final int RECENT_INCLUDE_PROFILES = 0x0004;
Kenny Guy82326a92014-03-17 17:16:06 +00001467
1468 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001469 * Ignores all tasks that are on the home stack.
1470 * @hide
1471 */
1472 public static final int RECENT_IGNORE_HOME_STACK_TASKS = 0x0008;
1473
1474 /**
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001475 * Ignores the top task in the docked stack.
Winson Chung0583d3d2015-12-18 10:03:12 -05001476 * @hide
1477 */
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001478 public static final int RECENT_INGORE_DOCKED_STACK_TOP_TASK = 0x0010;
Winson Chung0583d3d2015-12-18 10:03:12 -05001479
1480 /**
1481 * Ignores all tasks that are on the pinned stack.
1482 * @hide
1483 */
1484 public static final int RECENT_INGORE_PINNED_STACK_TASKS = 0x0020;
1485
1486 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001487 * <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 -08001488 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001489 *
1490 * <p><b>Note: this method is only intended for debugging and presenting
1491 * task management user interfaces</b>. This should never be used for
1492 * core logic in an application, such as deciding between different
1493 * behaviors based on the information found here. Such uses are
1494 * <em>not</em> supported, and will likely break in the future. For
1495 * example, if multiple applications can be actively running at the
1496 * same time, assumptions made about the meaning of the data here for
1497 * purposes of control flow will be incorrect.</p>
1498 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001499 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001500 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001501 * document-centric recents means
1502 * it can leak personal information to the caller. For backwards compatibility,
1503 * it will still return a small subset of its data: at least the caller's
1504 * own tasks (though see {@link #getAppTasks()} for the correct supported
1505 * way to retrieve that information), and possibly some other tasks
1506 * such as home that are known to not be sensitive.
1507 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 * @param maxNum The maximum number of entries to return in the list. The
1509 * actual number returned may be smaller, depending on how many tasks the
1510 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001511 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001512 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001513 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 * @return Returns a list of RecentTaskInfo records describing each of
1515 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001517 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1519 throws SecurityException {
1520 try {
1521 return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
Jeff Sharkey479212c2016-06-29 16:00:55 -06001522 flags, UserHandle.myUserId()).getList();
Amith Yamasani82644082012-08-03 13:09:11 -07001523 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001524 throw e.rethrowFromSystemServer();
Amith Yamasani82644082012-08-03 13:09:11 -07001525 }
1526 }
1527
1528 /**
1529 * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a
1530 * specific user. It requires holding
1531 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
1532 * @param maxNum The maximum number of entries to return in the list. The
1533 * actual number returned may be smaller, depending on how many tasks the
1534 * user has started and the maximum number the system can remember.
1535 * @param flags Information about what to return. May be any combination
1536 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
1537 *
1538 * @return Returns a list of RecentTaskInfo records describing each of
Vadim Tryshev35605752015-08-31 13:28:08 -07001539 * the recent tasks. Most recently activated tasks go first.
Amith Yamasani82644082012-08-03 13:09:11 -07001540 *
Amith Yamasani82644082012-08-03 13:09:11 -07001541 * @hide
1542 */
1543 public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId)
1544 throws SecurityException {
1545 try {
1546 return ActivityManagerNative.getDefault().getRecentTasks(maxNum,
Jeff Sharkey479212c2016-06-29 16:00:55 -06001547 flags, userId).getList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001549 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 }
1551 }
1552
1553 /**
1554 * Information you can retrieve about a particular task that is currently
1555 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001556 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 * means that the user has gone to it and never closed it, but currently
1558 * the system may have killed its process and is only holding on to its
1559 * last state in order to restart it when the user returns.
1560 */
1561 public static class RunningTaskInfo implements Parcelable {
1562 /**
1563 * A unique identifier for this task.
1564 */
1565 public int id;
1566
1567 /**
Winson5510f6c2015-10-27 12:11:26 -07001568 * The stack that currently contains this task.
1569 * @hide
1570 */
1571 public int stackId;
1572
1573 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 * The component launched as the first activity in the task. This can
1575 * be considered the "application" of this task.
1576 */
1577 public ComponentName baseActivity;
1578
1579 /**
1580 * The activity component at the top of the history stack of the task.
1581 * This is what the user is currently doing.
1582 */
1583 public ComponentName topActivity;
1584
1585 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001586 * Thumbnail representation of the task's current state. Currently
1587 * always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 */
1589 public Bitmap thumbnail;
1590
1591 /**
1592 * Description of the task's current state.
1593 */
1594 public CharSequence description;
1595
1596 /**
1597 * Number of activities in this task.
1598 */
1599 public int numActivities;
1600
1601 /**
1602 * Number of activities that are currently running (not stopped
1603 * and persisted) in this task.
1604 */
1605 public int numRunning;
1606
Craig Mautnerc0fd8052013-09-19 11:20:17 -07001607 /**
1608 * Last time task was run. For sorting.
1609 * @hide
1610 */
1611 public long lastActiveTime;
1612
Wale Ogunwale21b60582016-01-27 12:34:16 -08001613 /**
1614 * True if the task can go in the docked stack.
1615 * @hide
1616 */
1617 public boolean isDockable;
1618
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001619 /**
1620 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1621 * @hide
1622 */
1623 public int resizeMode;
1624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 public RunningTaskInfo() {
1626 }
1627
1628 public int describeContents() {
1629 return 0;
1630 }
1631
1632 public void writeToParcel(Parcel dest, int flags) {
1633 dest.writeInt(id);
Winson5510f6c2015-10-27 12:11:26 -07001634 dest.writeInt(stackId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 ComponentName.writeToParcel(baseActivity, dest);
1636 ComponentName.writeToParcel(topActivity, dest);
1637 if (thumbnail != null) {
1638 dest.writeInt(1);
1639 thumbnail.writeToParcel(dest, 0);
1640 } else {
1641 dest.writeInt(0);
1642 }
1643 TextUtils.writeToParcel(description, dest,
1644 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1645 dest.writeInt(numActivities);
1646 dest.writeInt(numRunning);
Jorim Jaggiaa6c5742016-03-01 14:10:14 +01001647 dest.writeInt(isDockable ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001648 dest.writeInt(resizeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 }
1650
1651 public void readFromParcel(Parcel source) {
1652 id = source.readInt();
Winson5510f6c2015-10-27 12:11:26 -07001653 stackId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 baseActivity = ComponentName.readFromParcel(source);
1655 topActivity = ComponentName.readFromParcel(source);
1656 if (source.readInt() != 0) {
1657 thumbnail = Bitmap.CREATOR.createFromParcel(source);
1658 } else {
1659 thumbnail = null;
1660 }
1661 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
1662 numActivities = source.readInt();
1663 numRunning = source.readInt();
Jorim Jaggiaa6c5742016-03-01 14:10:14 +01001664 isDockable = source.readInt() != 0;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001665 resizeMode = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
1669 public RunningTaskInfo createFromParcel(Parcel source) {
1670 return new RunningTaskInfo(source);
1671 }
1672 public RunningTaskInfo[] newArray(int size) {
1673 return new RunningTaskInfo[size];
1674 }
1675 };
1676
1677 private RunningTaskInfo(Parcel source) {
1678 readFromParcel(source);
1679 }
1680 }
Winson Chung1147c402014-05-14 11:05:00 -07001681
1682 /**
1683 * Get the list of tasks associated with the calling application.
1684 *
1685 * @return The list of tasks associated with the application making this call.
1686 * @throws SecurityException
1687 */
1688 public List<ActivityManager.AppTask> getAppTasks() {
1689 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
1690 List<IAppTask> appTasks;
1691 try {
Dianne Hackborn885fbe52014-08-23 15:23:58 -07001692 appTasks = ActivityManagerNative.getDefault().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001693 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001694 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001695 }
1696 int numAppTasks = appTasks.size();
1697 for (int i = 0; i < numAppTasks; i++) {
1698 tasks.add(new AppTask(appTasks.get(i)));
1699 }
1700 return tasks;
1701 }
1702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 /**
Winson Chung48a10a52014-08-27 14:36:51 -07001704 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001705 * with {@link #addAppTask}.
1706 */
Winson Chung48a10a52014-08-27 14:36:51 -07001707 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001708 synchronized (this) {
1709 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07001710 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001711 }
1712 }
1713
1714 private void ensureAppTaskThumbnailSizeLocked() {
1715 if (mAppTaskThumbnailSize == null) {
1716 try {
1717 mAppTaskThumbnailSize = ActivityManagerNative.getDefault().getAppTaskThumbnailSize();
1718 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001719 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001720 }
1721 }
1722 }
1723
1724 /**
1725 * Add a new {@link AppTask} for the calling application. This will create a new
1726 * recents entry that is added to the <b>end</b> of all existing recents.
1727 *
1728 * @param activity The activity that is adding the entry. This is used to help determine
1729 * the context that the new recents entry will be in.
1730 * @param intent The Intent that describes the recents entry. This is the same Intent that
1731 * you would have used to launch the activity for it. In generally you will want to set
1732 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
1733 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
1734 * entry will exist without an activity, so it doesn't make sense to not retain it when
1735 * its activity disappears. The given Intent here also must have an explicit ComponentName
1736 * set on it.
1737 * @param description Optional additional description information.
1738 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07001739 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
1740 * recreated in your process, probably in a way you don't like, before the recents entry
1741 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001742 *
1743 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
1744 * most likely cause of failure is that there is no more room for more tasks for your app.
1745 */
1746 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
1747 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
1748 Point size;
1749 synchronized (this) {
1750 ensureAppTaskThumbnailSizeLocked();
1751 size = mAppTaskThumbnailSize;
1752 }
1753 final int tw = thumbnail.getWidth();
1754 final int th = thumbnail.getHeight();
1755 if (tw != size.x || th != size.y) {
1756 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
1757
1758 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
1759 float scale;
1760 float dx = 0, dy = 0;
1761 if (tw * size.x > size.y * th) {
1762 scale = (float) size.x / (float) th;
1763 dx = (size.y - tw * scale) * 0.5f;
1764 } else {
1765 scale = (float) size.y / (float) tw;
1766 dy = (size.x - th * scale) * 0.5f;
1767 }
1768 Matrix matrix = new Matrix();
1769 matrix.setScale(scale, scale);
1770 matrix.postTranslate((int) (dx + 0.5f), 0);
1771
1772 Canvas canvas = new Canvas(bm);
1773 canvas.drawBitmap(thumbnail, matrix, null);
1774 canvas.setBitmap(null);
1775
1776 thumbnail = bm;
1777 }
1778 if (description == null) {
1779 description = new TaskDescription();
1780 }
1781 try {
1782 return ActivityManagerNative.getDefault().addAppTask(activity.getActivityToken(),
1783 intent, description, thumbnail);
1784 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001785 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001786 }
1787 }
1788
1789 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 * Return a list of the tasks that are currently running, with
1791 * the most recent being first and older ones after in order. Note that
1792 * "running" does not mean any of the task's code is currently loaded or
1793 * activity -- the task may have been frozen by the system, so that it
1794 * can be restarted in its previous state when next brought to the
1795 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001796 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001797 * <p><b>Note: this method is only intended for debugging and presenting
1798 * task management user interfaces</b>. This should never be used for
1799 * core logic in an application, such as deciding between different
1800 * behaviors based on the information found here. Such uses are
1801 * <em>not</em> supported, and will likely break in the future. For
1802 * example, if multiple applications can be actively running at the
1803 * same time, assumptions made about the meaning of the data here for
1804 * purposes of control flow will be incorrect.</p>
1805 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001806 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001807 * is no longer available to third party
1808 * applications: the introduction of document-centric recents means
1809 * it can leak person information to the caller. For backwards compatibility,
1810 * it will still retu rn a small subset of its data: at least the caller's
1811 * own tasks, and possibly some other tasks
1812 * such as home that are known to not be sensitive.
1813 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07001814 * @param maxNum The maximum number of entries to return in the list. The
1815 * actual number returned may be smaller, depending on how many tasks the
1816 * user has started.
1817 *
1818 * @return Returns a list of RunningTaskInfo records describing each of
1819 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001820 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001821 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07001822 public List<RunningTaskInfo> getRunningTasks(int maxNum)
1823 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07001824 try {
1825 return ActivityManagerNative.getDefault().getTasks(maxNum, 0);
1826 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001827 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07001828 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07001829 }
1830
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001831 /**
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001832 * Completely remove the given task.
1833 *
1834 * @param taskId Identifier of the task to be removed.
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001835 * @return Returns true if the given task was found and removed.
1836 *
1837 * @hide
1838 */
Wale Ogunwaled54b5782014-10-23 15:55:23 -07001839 public boolean removeTask(int taskId) throws SecurityException {
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001840 try {
Wale Ogunwaled54b5782014-10-23 15:55:23 -07001841 return ActivityManagerNative.getDefault().removeTask(taskId);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001842 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001843 throw e.rethrowFromSystemServer();
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001844 }
1845 }
1846
Winsonc809cbb2015-11-02 12:06:15 -08001847 /**
1848 * Metadata related to the {@link TaskThumbnail}.
1849 *
1850 * @hide
1851 */
1852 public static class TaskThumbnailInfo implements Parcelable {
1853 /** @hide */
1854 public static final String ATTR_TASK_THUMBNAILINFO_PREFIX = "task_thumbnailinfo_";
1855 private static final String ATTR_TASK_WIDTH =
1856 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_width";
1857 private static final String ATTR_TASK_HEIGHT =
1858 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_height";
1859 private static final String ATTR_SCREEN_ORIENTATION =
1860 ATTR_TASK_THUMBNAILINFO_PREFIX + "screen_orientation";
1861
1862 public int taskWidth;
1863 public int taskHeight;
Winson21700932016-03-24 17:26:23 -07001864 public int screenOrientation = Configuration.ORIENTATION_UNDEFINED;
Winsonc809cbb2015-11-02 12:06:15 -08001865
1866 public TaskThumbnailInfo() {
1867 // Do nothing
1868 }
1869
1870 private TaskThumbnailInfo(Parcel source) {
1871 readFromParcel(source);
1872 }
1873
Winsonc6a2da02015-11-11 18:11:59 -08001874 /**
1875 * Resets this info state to the initial state.
1876 * @hide
1877 */
1878 public void reset() {
1879 taskWidth = 0;
1880 taskHeight = 0;
Winson21700932016-03-24 17:26:23 -07001881 screenOrientation = Configuration.ORIENTATION_UNDEFINED;
1882 }
1883
1884 /**
1885 * Copies from another ThumbnailInfo.
1886 */
1887 public void copyFrom(TaskThumbnailInfo o) {
1888 taskWidth = o.taskWidth;
1889 taskHeight = o.taskHeight;
1890 screenOrientation = o.screenOrientation;
Winsonc6a2da02015-11-11 18:11:59 -08001891 }
1892
Winsonc809cbb2015-11-02 12:06:15 -08001893 /** @hide */
1894 public void saveToXml(XmlSerializer out) throws IOException {
1895 out.attribute(null, ATTR_TASK_WIDTH, Integer.toString(taskWidth));
1896 out.attribute(null, ATTR_TASK_HEIGHT, Integer.toString(taskHeight));
1897 out.attribute(null, ATTR_SCREEN_ORIENTATION, Integer.toString(screenOrientation));
1898 }
1899
1900 /** @hide */
1901 public void restoreFromXml(String attrName, String attrValue) {
1902 if (ATTR_TASK_WIDTH.equals(attrName)) {
1903 taskWidth = Integer.parseInt(attrValue);
1904 } else if (ATTR_TASK_HEIGHT.equals(attrName)) {
1905 taskHeight = Integer.parseInt(attrValue);
1906 } else if (ATTR_SCREEN_ORIENTATION.equals(attrName)) {
1907 screenOrientation = Integer.parseInt(attrValue);
1908 }
1909 }
1910
1911 public int describeContents() {
1912 return 0;
1913 }
1914
1915 public void writeToParcel(Parcel dest, int flags) {
1916 dest.writeInt(taskWidth);
1917 dest.writeInt(taskHeight);
1918 dest.writeInt(screenOrientation);
1919 }
1920
1921 public void readFromParcel(Parcel source) {
1922 taskWidth = source.readInt();
1923 taskHeight = source.readInt();
1924 screenOrientation = source.readInt();
1925 }
1926
1927 public static final Creator<TaskThumbnailInfo> CREATOR = new Creator<TaskThumbnailInfo>() {
1928 public TaskThumbnailInfo createFromParcel(Parcel source) {
1929 return new TaskThumbnailInfo(source);
1930 }
1931 public TaskThumbnailInfo[] newArray(int size) {
1932 return new TaskThumbnailInfo[size];
1933 }
1934 };
1935 }
1936
Dianne Hackbornd94df452011-02-16 18:53:31 -08001937 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001938 public static class TaskThumbnail implements Parcelable {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001939 public Bitmap mainThumbnail;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001940 public ParcelFileDescriptor thumbnailFileDescriptor;
Winsonc809cbb2015-11-02 12:06:15 -08001941 public TaskThumbnailInfo thumbnailInfo;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001942
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001943 public TaskThumbnail() {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001944 }
1945
Winsonc809cbb2015-11-02 12:06:15 -08001946 private TaskThumbnail(Parcel source) {
1947 readFromParcel(source);
1948 }
1949
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001950 public int describeContents() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001951 if (thumbnailFileDescriptor != null) {
1952 return thumbnailFileDescriptor.describeContents();
1953 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001954 return 0;
1955 }
1956
1957 public void writeToParcel(Parcel dest, int flags) {
1958 if (mainThumbnail != null) {
1959 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001960 mainThumbnail.writeToParcel(dest, flags);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001961 } else {
1962 dest.writeInt(0);
1963 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001964 if (thumbnailFileDescriptor != null) {
1965 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07001966 thumbnailFileDescriptor.writeToParcel(dest, flags);
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001967 } else {
1968 dest.writeInt(0);
1969 }
Winsonc809cbb2015-11-02 12:06:15 -08001970 if (thumbnailInfo != null) {
1971 dest.writeInt(1);
1972 thumbnailInfo.writeToParcel(dest, flags);
1973 } else {
1974 dest.writeInt(0);
1975 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001976 }
1977
1978 public void readFromParcel(Parcel source) {
1979 if (source.readInt() != 0) {
1980 mainThumbnail = Bitmap.CREATOR.createFromParcel(source);
1981 } else {
1982 mainThumbnail = null;
1983 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001984 if (source.readInt() != 0) {
1985 thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source);
1986 } else {
1987 thumbnailFileDescriptor = null;
1988 }
Winsonc809cbb2015-11-02 12:06:15 -08001989 if (source.readInt() != 0) {
1990 thumbnailInfo = TaskThumbnailInfo.CREATOR.createFromParcel(source);
1991 } else {
1992 thumbnailInfo = null;
1993 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001994 }
1995
Craig Mautnerc0ffce52014-07-01 12:38:52 -07001996 public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() {
1997 public TaskThumbnail createFromParcel(Parcel source) {
1998 return new TaskThumbnail(source);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001999 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002000 public TaskThumbnail[] newArray(int size) {
2001 return new TaskThumbnail[size];
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002002 }
2003 };
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002004 }
2005
2006 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002007 public TaskThumbnail getTaskThumbnail(int id) throws SecurityException {
Dianne Hackbornd94df452011-02-16 18:53:31 -08002008 try {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002009 return ActivityManagerNative.getDefault().getTaskThumbnail(id);
Dianne Hackborn15491c62012-09-19 10:59:14 -07002010 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002011 throw e.rethrowFromSystemServer();
Dianne Hackborn15491c62012-09-19 10:59:14 -07002012 }
2013 }
2014
Winson Chung303e1ff2014-03-07 15:06:19 -08002015 /** @hide */
2016 public boolean isInHomeStack(int taskId) {
2017 try {
2018 return ActivityManagerNative.getDefault().isInHomeStack(taskId);
2019 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002020 throw e.rethrowFromSystemServer();
Winson Chung303e1ff2014-03-07 15:06:19 -08002021 }
2022 }
2023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002025 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
2026 * activity along with the task, so it is positioned immediately behind
2027 * the task.
2028 */
2029 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
2030
2031 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08002032 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
2033 * user-instigated action, so the current activity will not receive a
2034 * hint that the user is leaving.
2035 */
2036 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
2037
2038 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002039 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
2040 * with a null options argument.
2041 *
2042 * @param taskId The identifier of the task to be moved, as found in
2043 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
2044 * @param flags Additional operational flags, 0 or more of
Craig Mautnerecbfe252013-03-28 11:58:25 -07002045 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002046 */
2047 public void moveTaskToFront(int taskId, int flags) {
2048 moveTaskToFront(taskId, flags, null);
2049 }
2050
2051 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002052 * Ask that the task associated with a given task ID be moved to the
2053 * front of the stack, so it is now visible to the user. Requires that
2054 * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS}
2055 * or a SecurityException will be thrown.
2056 *
2057 * @param taskId The identifier of the task to be moved, as found in
2058 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
2059 * @param flags Additional operational flags, 0 or more of
Craig Mautnerecbfe252013-03-28 11:58:25 -07002060 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002061 * @param options Additional options for the operation, either null or
2062 * as per {@link Context#startActivity(Intent, android.os.Bundle)
2063 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002064 */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002065 public void moveTaskToFront(int taskId, int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002066 try {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002067 ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002068 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002069 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002070 }
2071 }
2072
2073 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 * Information you can retrieve about a particular Service that is
2075 * currently running in the system.
2076 */
2077 public static class RunningServiceInfo implements Parcelable {
2078 /**
2079 * The service component.
2080 */
2081 public ComponentName service;
2082
2083 /**
2084 * If non-zero, this is the process the service is running in.
2085 */
2086 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002089 * The UID that owns this service.
2090 */
2091 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002092
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002093 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 * The name of the process this service runs in.
2095 */
2096 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 /**
2099 * Set to true if the service has asked to run as a foreground process.
2100 */
2101 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002103 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002104 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002105 * starting or binding to it. This
2106 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002107 */
2108 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002110 /**
2111 * Set to true if this service has been explicitly started.
2112 */
2113 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 /**
2116 * Number of clients connected to the service.
2117 */
2118 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 /**
2121 * Number of times the service's process has crashed while the service
2122 * is running.
2123 */
2124 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 /**
2127 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002128 * explicit requests to start it or clients binding to it). This
2129 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002130 */
2131 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 /**
2134 * If non-zero, this service is not currently running, but scheduled to
2135 * restart at the given time.
2136 */
2137 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002138
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002139 /**
2140 * Bit for {@link #flags}: set if this service has been
2141 * explicitly started.
2142 */
2143 public static final int FLAG_STARTED = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002144
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002145 /**
2146 * Bit for {@link #flags}: set if the service has asked to
2147 * run as a foreground process.
2148 */
2149 public static final int FLAG_FOREGROUND = 1<<1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002150
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002151 /**
2152 * Bit for {@link #flags): set if the service is running in a
2153 * core system process.
2154 */
2155 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002156
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002157 /**
2158 * Bit for {@link #flags): set if the service is running in a
2159 * persistent process.
2160 */
2161 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002162
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002163 /**
2164 * Running flags.
2165 */
2166 public int flags;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002167
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002168 /**
2169 * For special services that are bound to by system code, this is
2170 * the package that holds the binding.
2171 */
2172 public String clientPackage;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002173
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002174 /**
2175 * For special services that are bound to by system code, this is
2176 * a string resource providing a user-visible label for who the
2177 * client is.
2178 */
2179 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 public RunningServiceInfo() {
2182 }
2183
2184 public int describeContents() {
2185 return 0;
2186 }
2187
2188 public void writeToParcel(Parcel dest, int flags) {
2189 ComponentName.writeToParcel(service, dest);
2190 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002191 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002192 dest.writeString(process);
2193 dest.writeInt(foreground ? 1 : 0);
2194 dest.writeLong(activeSince);
2195 dest.writeInt(started ? 1 : 0);
2196 dest.writeInt(clientCount);
2197 dest.writeInt(crashCount);
2198 dest.writeLong(lastActivityTime);
2199 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002200 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002201 dest.writeString(clientPackage);
2202 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 }
2204
2205 public void readFromParcel(Parcel source) {
2206 service = ComponentName.readFromParcel(source);
2207 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002208 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 process = source.readString();
2210 foreground = source.readInt() != 0;
2211 activeSince = source.readLong();
2212 started = source.readInt() != 0;
2213 clientCount = source.readInt();
2214 crashCount = source.readInt();
2215 lastActivityTime = source.readLong();
2216 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002217 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002218 clientPackage = source.readString();
2219 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
2223 public RunningServiceInfo createFromParcel(Parcel source) {
2224 return new RunningServiceInfo(source);
2225 }
2226 public RunningServiceInfo[] newArray(int size) {
2227 return new RunningServiceInfo[size];
2228 }
2229 };
2230
2231 private RunningServiceInfo(Parcel source) {
2232 readFromParcel(source);
2233 }
2234 }
2235
2236 /**
2237 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002238 *
2239 * <p><b>Note: this method is only intended for debugging or implementing
2240 * service management type user interfaces.</b></p>
2241 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002242 * @param maxNum The maximum number of entries to return in the list. The
2243 * actual number returned may be smaller, depending on how many services
2244 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002245 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 * @return Returns a list of RunningServiceInfo records describing each of
2247 * the running tasks.
2248 */
2249 public List<RunningServiceInfo> getRunningServices(int maxNum)
2250 throws SecurityException {
2251 try {
Amith Yamasani4b2e9342011-03-31 12:38:53 -07002252 return ActivityManagerNative.getDefault()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 .getServices(maxNum, 0);
2254 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002255 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 }
2257 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002260 * Returns a PendingIntent you can start to show a control panel for the
2261 * given running service. If the service does not have a control panel,
2262 * null is returned.
2263 */
2264 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2265 throws SecurityException {
2266 try {
2267 return ActivityManagerNative.getDefault()
2268 .getRunningServiceControlPanel(service);
2269 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002270 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002271 }
2272 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002273
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002274 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 * Information you can retrieve about the available memory through
2276 * {@link ActivityManager#getMemoryInfo}.
2277 */
2278 public static class MemoryInfo implements Parcelable {
2279 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002280 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 * be considered absolute: due to the nature of the kernel, a significant
2282 * portion of this memory is actually in use and needed for the overall
2283 * system to run well.
2284 */
2285 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002286
2287 /**
2288 * The total memory accessible by the kernel. This is basically the
2289 * RAM size of the device, not including below-kernel fixed allocations
2290 * like DMA buffers, RAM for the baseband CPU, etc.
2291 */
2292 public long totalMem;
2293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 /**
2295 * The threshold of {@link #availMem} at which we consider memory to be
2296 * low and start killing background services and other non-extraneous
2297 * processes.
2298 */
2299 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 /**
2302 * Set to true if the system considers itself to currently be in a low
2303 * memory situation.
2304 */
2305 public boolean lowMemory;
2306
Dianne Hackborn7d608422011-08-07 16:24:18 -07002307 /** @hide */
2308 public long hiddenAppThreshold;
2309 /** @hide */
2310 public long secondaryServerThreshold;
2311 /** @hide */
2312 public long visibleAppThreshold;
2313 /** @hide */
2314 public long foregroundAppThreshold;
2315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 public MemoryInfo() {
2317 }
2318
2319 public int describeContents() {
2320 return 0;
2321 }
2322
2323 public void writeToParcel(Parcel dest, int flags) {
2324 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002325 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 dest.writeLong(threshold);
2327 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002328 dest.writeLong(hiddenAppThreshold);
2329 dest.writeLong(secondaryServerThreshold);
2330 dest.writeLong(visibleAppThreshold);
2331 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334 public void readFromParcel(Parcel source) {
2335 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002336 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 threshold = source.readLong();
2338 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002339 hiddenAppThreshold = source.readLong();
2340 secondaryServerThreshold = source.readLong();
2341 visibleAppThreshold = source.readLong();
2342 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 }
2344
2345 public static final Creator<MemoryInfo> CREATOR
2346 = new Creator<MemoryInfo>() {
2347 public MemoryInfo createFromParcel(Parcel source) {
2348 return new MemoryInfo(source);
2349 }
2350 public MemoryInfo[] newArray(int size) {
2351 return new MemoryInfo[size];
2352 }
2353 };
2354
2355 private MemoryInfo(Parcel source) {
2356 readFromParcel(source);
2357 }
2358 }
2359
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002360 /**
2361 * Return general information about the memory state of the system. This
2362 * can be used to help decide how to manage your own memory, though note
2363 * that polling is not recommended and
2364 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2365 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2366 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2367 * level of your process as needed, which gives a better hint for how to
2368 * manage its memory.
2369 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 public void getMemoryInfo(MemoryInfo outInfo) {
2371 try {
2372 ActivityManagerNative.getDefault().getMemoryInfo(outInfo);
2373 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002374 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 }
2376 }
Craig Mautner967212c2013-04-13 21:10:58 -07002377
Craig Mautner5ff12102013-05-24 12:50:15 -07002378 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002379 * Information you can retrieve about an ActivityStack in the system.
2380 * @hide
2381 */
2382 public static class StackInfo implements Parcelable {
2383 public int stackId;
Craig Mautnered6649f2013-12-02 14:08:25 -08002384 public Rect bounds = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -07002385 public int[] taskIds;
2386 public String[] taskNames;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002387 public Rect[] taskBounds;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002388 public int[] taskUserIds;
Winsond46b7272016-04-20 11:54:27 -07002389 public ComponentName topActivity;
Craig Mautnered6649f2013-12-02 14:08:25 -08002390 public int displayId;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002391 public int userId;
Winsond46b7272016-04-20 11:54:27 -07002392 public boolean visible;
Winson529c8e42016-05-17 11:08:40 -07002393 // Index of the stack in the display's stack list, can be used for comparison of stack order
2394 public int position;
Craig Mautner967212c2013-04-13 21:10:58 -07002395
Craig Mautner967212c2013-04-13 21:10:58 -07002396 @Override
2397 public int describeContents() {
2398 return 0;
2399 }
2400
2401 @Override
2402 public void writeToParcel(Parcel dest, int flags) {
2403 dest.writeInt(stackId);
2404 dest.writeInt(bounds.left);
2405 dest.writeInt(bounds.top);
2406 dest.writeInt(bounds.right);
2407 dest.writeInt(bounds.bottom);
2408 dest.writeIntArray(taskIds);
2409 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002410 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2411 dest.writeInt(boundsCount);
2412 for (int i = 0; i < boundsCount; i++) {
2413 dest.writeInt(taskBounds[i].left);
2414 dest.writeInt(taskBounds[i].top);
2415 dest.writeInt(taskBounds[i].right);
2416 dest.writeInt(taskBounds[i].bottom);
2417 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002418 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002419 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002420 dest.writeInt(userId);
Winsond46b7272016-04-20 11:54:27 -07002421 dest.writeInt(visible ? 1 : 0);
Winson529c8e42016-05-17 11:08:40 -07002422 dest.writeInt(position);
Winsond46b7272016-04-20 11:54:27 -07002423 if (topActivity != null) {
2424 dest.writeInt(1);
2425 topActivity.writeToParcel(dest, 0);
2426 } else {
2427 dest.writeInt(0);
2428 }
Craig Mautner967212c2013-04-13 21:10:58 -07002429 }
2430
2431 public void readFromParcel(Parcel source) {
2432 stackId = source.readInt();
2433 bounds = new Rect(
2434 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2435 taskIds = source.createIntArray();
2436 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002437 final int boundsCount = source.readInt();
2438 if (boundsCount > 0) {
2439 taskBounds = new Rect[boundsCount];
2440 for (int i = 0; i < boundsCount; i++) {
2441 taskBounds[i] = new Rect();
2442 taskBounds[i].set(
2443 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2444 }
2445 } else {
2446 taskBounds = null;
2447 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002448 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002449 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002450 userId = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002451 visible = source.readInt() > 0;
Winson529c8e42016-05-17 11:08:40 -07002452 position = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002453 if (source.readInt() > 0) {
2454 topActivity = ComponentName.readFromParcel(source);
2455 }
Craig Mautner967212c2013-04-13 21:10:58 -07002456 }
2457
2458 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
2459 @Override
2460 public StackInfo createFromParcel(Parcel source) {
2461 return new StackInfo(source);
2462 }
2463 @Override
2464 public StackInfo[] newArray(int size) {
2465 return new StackInfo[size];
2466 }
2467 };
2468
Craig Mautner5ff12102013-05-24 12:50:15 -07002469 public StackInfo() {
2470 }
2471
Craig Mautner967212c2013-04-13 21:10:58 -07002472 private StackInfo(Parcel source) {
2473 readFromParcel(source);
2474 }
2475
Craig Mautner5ff12102013-05-24 12:50:15 -07002476 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002477 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002478 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002479 sb.append(" bounds="); sb.append(bounds.toShortString());
2480 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002481 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002482 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002483 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002484 for (int i = 0; i < taskIds.length; ++i) {
2485 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002486 sb.append(": "); sb.append(taskNames[i]);
2487 if (taskBounds != null) {
2488 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2489 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002490 sb.append(" userId=").append(taskUserIds[i]);
Winsond46b7272016-04-20 11:54:27 -07002491 sb.append(" visible=").append(visible);
2492 if (topActivity != null) {
2493 sb.append(" topActivity=").append(topActivity);
2494 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002495 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002496 }
2497 return sb.toString();
2498 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002499
2500 @Override
2501 public String toString() {
2502 return toString("");
2503 }
Craig Mautner967212c2013-04-13 21:10:58 -07002504 }
2505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 /**
2507 * @hide
2508 */
2509 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2510 try {
Stefan Kuhne16045c22015-06-05 07:18:06 -07002511 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName,
Dianne Hackborn41203752012-08-31 14:05:51 -07002512 observer, UserHandle.myUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002514 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 }
2516 }
Christopher Tatea3664242013-06-26 15:00:18 -07002517
2518 /**
2519 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002520 * the user choosing to clear the app's data from within the device settings UI. It
2521 * erases all dynamic data associated with the app -- its private data and data in its
2522 * private area on external storage -- but does not remove the installed application
2523 * itself, nor any OBB files.
Christopher Tatea3664242013-06-26 15:00:18 -07002524 *
2525 * @return {@code true} if the application successfully requested that the application's
2526 * data be erased; {@code false} otherwise.
2527 */
2528 public boolean clearApplicationUserData() {
2529 return clearApplicationUserData(mContext.getPackageName(), null);
2530 }
2531
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002532
2533 /**
2534 * Permits an application to get the persistent URI permissions granted to another.
2535 *
2536 * <p>Typically called by Settings.
2537 *
2538 * @param packageName application to look for the granted permissions
2539 * @return list of granted URI permissions
2540 *
2541 * @hide
2542 */
2543 public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName) {
2544 try {
2545 return ActivityManagerNative.getDefault().getGrantedUriPermissions(packageName,
2546 UserHandle.myUserId());
2547 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002548 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002549 }
2550 }
2551
2552 /**
2553 * Permits an application to clear the persistent URI permissions granted to another.
2554 *
2555 * <p>Typically called by Settings.
2556 *
2557 * @param packageName application to clear its granted permissions
2558 *
2559 * @hide
2560 */
2561 public void clearGrantedUriPermissions(String packageName) {
2562 try {
2563 ActivityManagerNative.getDefault().clearGrantedUriPermissions(packageName,
2564 UserHandle.myUserId());
2565 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002566 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002567 }
2568 }
2569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 /**
2571 * Information you can retrieve about any processes that are in an error condition.
2572 */
2573 public static class ProcessErrorStateInfo implements Parcelable {
2574 /**
2575 * Condition codes
2576 */
2577 public static final int NO_ERROR = 0;
2578 public static final int CRASHED = 1;
2579 public static final int NOT_RESPONDING = 2;
2580
2581 /**
2582 * The condition that the process is in.
2583 */
2584 public int condition;
2585
2586 /**
2587 * The process name in which the crash or error occurred.
2588 */
2589 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 /**
2592 * The pid of this process; 0 if none
2593 */
2594 public int pid;
2595
2596 /**
2597 * The kernel user-ID that has been assigned to this process;
2598 * currently this is not a unique ID (multiple applications can have
2599 * the same uid).
2600 */
2601 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 /**
Dan Egnor60d87622009-12-16 16:32:58 -08002604 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 */
2606 public String tag;
2607
2608 /**
2609 * A short message describing the error condition.
2610 */
2611 public String shortMsg;
2612
2613 /**
2614 * A long message describing the error condition.
2615 */
2616 public String longMsg;
2617
2618 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08002619 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002620 */
Dan Egnorb7f03672009-12-09 16:22:32 -08002621 public String stackTrace;
2622
2623 /**
2624 * to be deprecated: This value will always be null.
2625 */
2626 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627
2628 public ProcessErrorStateInfo() {
2629 }
2630
Craig Mautner5ff12102013-05-24 12:50:15 -07002631 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 public int describeContents() {
2633 return 0;
2634 }
2635
Craig Mautner5ff12102013-05-24 12:50:15 -07002636 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637 public void writeToParcel(Parcel dest, int flags) {
2638 dest.writeInt(condition);
2639 dest.writeString(processName);
2640 dest.writeInt(pid);
2641 dest.writeInt(uid);
2642 dest.writeString(tag);
2643 dest.writeString(shortMsg);
2644 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08002645 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 public void readFromParcel(Parcel source) {
2649 condition = source.readInt();
2650 processName = source.readString();
2651 pid = source.readInt();
2652 uid = source.readInt();
2653 tag = source.readString();
2654 shortMsg = source.readString();
2655 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08002656 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002658
2659 public static final Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 new Creator<ProcessErrorStateInfo>() {
2661 public ProcessErrorStateInfo createFromParcel(Parcel source) {
2662 return new ProcessErrorStateInfo(source);
2663 }
2664 public ProcessErrorStateInfo[] newArray(int size) {
2665 return new ProcessErrorStateInfo[size];
2666 }
2667 };
2668
2669 private ProcessErrorStateInfo(Parcel source) {
2670 readFromParcel(source);
2671 }
2672 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002675 * 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 -08002676 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002677 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002678 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
2679 * current error conditions (it will not return an empty list). This list ordering is not
2680 * specified.
2681 */
2682 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
2683 try {
2684 return ActivityManagerNative.getDefault().getProcessesInErrorState();
2685 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002686 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 }
2688 }
2689
2690 /**
2691 * Information you can retrieve about a running process.
2692 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07002693 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002694 /**
2695 * The name of the process that this object is associated with
2696 */
2697 public String processName;
2698
2699 /**
2700 * The pid of this process; 0 if none
2701 */
2702 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002703
Dianne Hackborneb034652009-09-07 00:49:58 -07002704 /**
2705 * The user id of this process.
2706 */
2707 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002708
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002709 /**
2710 * All packages that have been loaded into the process.
2711 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07002713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07002715 * Constant for {@link #flags}: this is an app that is unable to
2716 * correctly save its state when going to the background,
2717 * so it can not be killed while in the background.
2718 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002719 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07002720 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002721
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002722 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002723 * Constant for {@link #flags}: this process is associated with a
2724 * persistent system app.
2725 * @hide
2726 */
2727 public static final int FLAG_PERSISTENT = 1<<1;
2728
2729 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07002730 * Constant for {@link #flags}: this process is associated with a
2731 * persistent system app.
2732 * @hide
2733 */
2734 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
2735
2736 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002737 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07002738 * {@link #FLAG_CANT_SAVE_STATE}.
2739 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002740 */
2741 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002742
2743 /**
2744 * Last memory trim level reported to the process: corresponds to
2745 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2746 * ComponentCallbacks2.onTrimMemory(int)}.
2747 */
2748 public int lastTrimLevel;
2749
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002750 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002751 * Constant for {@link #importance}: This process is running the
2752 * foreground UI; that is, it is the thing currently at the top of the screen
2753 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 */
2755 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002758 * Constant for {@link #importance}: This process is running a foreground
2759 * service, for example to perform music playback even while the user is
2760 * not immediately in the app. This generally indicates that the process
2761 * is doing something the user actively cares about.
2762 */
2763 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
2764
2765 /**
2766 * Constant for {@link #importance}: This process is running the foreground
2767 * UI, but the device is asleep so it is not visible to the user. This means
2768 * the user is not really aware of the process, because they can not see or
2769 * interact with it, but it is quite important because it what they expect to
2770 * return to once unlocking the device.
2771 */
2772 public static final int IMPORTANCE_TOP_SLEEPING = 150;
2773
2774 /**
2775 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002776 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07002777 * foreground. This may be running a window that is behind the current
2778 * foreground (so paused and with its state saved, not interacting with
2779 * the user, but visible to them to some degree); it may also be running
2780 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07002781 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002782 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002783
Dianne Hackborn860755f2010-06-03 18:47:52 -07002784 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002785 * Constant for {@link #importance}: This process is not something the user
2786 * is directly aware of, but is otherwise perceptable to them to some degree.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002788 public static final int IMPORTANCE_PERCEPTIBLE = 130;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002789
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002790 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002791 * Constant for {@link #importance}: This process is running an
Dianne Hackborn5383f502010-10-22 12:59:20 -07002792 * application that can not save its state, and thus can't be killed
2793 * while in the background.
2794 * @hide
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002795 */
Dianne Hackborn5383f502010-10-22 12:59:20 -07002796 public static final int IMPORTANCE_CANT_SAVE_STATE = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002799 * Constant for {@link #importance}: This process is contains services
2800 * that should remain running. These are background services apps have
2801 * started, not something the user is aware of, so they may be killed by
2802 * the system relatively freely (though it is generally desired that they
2803 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 */
2805 public static final int IMPORTANCE_SERVICE = 300;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002808 * Constant for {@link #importance}: This process process contains
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 * background code that is expendable.
2810 */
2811 public static final int IMPORTANCE_BACKGROUND = 400;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002814 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 * actively running code.
2816 */
2817 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002818
2819 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002820 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002821 */
2822 public static final int IMPORTANCE_GONE = 1000;
2823
2824 /** @hide */
2825 public static int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002826 if (procState == PROCESS_STATE_NONEXISTENT) {
2827 return IMPORTANCE_GONE;
2828 } else if (procState >= PROCESS_STATE_HOME) {
2829 return IMPORTANCE_BACKGROUND;
2830 } else if (procState >= PROCESS_STATE_SERVICE) {
2831 return IMPORTANCE_SERVICE;
2832 } else if (procState > PROCESS_STATE_HEAVY_WEIGHT) {
2833 return IMPORTANCE_CANT_SAVE_STATE;
2834 } else if (procState >= PROCESS_STATE_IMPORTANT_BACKGROUND) {
2835 return IMPORTANCE_PERCEPTIBLE;
2836 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
2837 return IMPORTANCE_VISIBLE;
2838 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
2839 return IMPORTANCE_TOP_SLEEPING;
2840 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) {
2841 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002842 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002843 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002844 }
2845 }
2846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 /**
2848 * The relative importance level that the system places on this
2849 * process. May be one of {@link #IMPORTANCE_FOREGROUND},
2850 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE},
2851 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These
2852 * constants are numbered so that "more important" values are always
2853 * smaller than "less important" values.
2854 */
2855 public int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 /**
2858 * An additional ordering within a particular {@link #importance}
2859 * category, providing finer-grained information about the relative
2860 * utility of processes within a category. This number means nothing
2861 * except that a smaller values are more recently used (and thus
2862 * more important). Currently an LRU value is only maintained for
2863 * the {@link #IMPORTANCE_BACKGROUND} category, though others may
2864 * be maintained in the future.
2865 */
2866 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002867
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002868 /**
2869 * Constant for {@link #importanceReasonCode}: nothing special has
2870 * been specified for the reason for this level.
2871 */
2872 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002873
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002874 /**
2875 * Constant for {@link #importanceReasonCode}: one of the application's
2876 * content providers is being used by another process. The pid of
2877 * the client process is in {@link #importanceReasonPid} and the
2878 * target provider in this process is in
2879 * {@link #importanceReasonComponent}.
2880 */
2881 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002882
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002883 /**
2884 * Constant for {@link #importanceReasonCode}: one of the application's
2885 * content providers is being used by another process. The pid of
2886 * the client process is in {@link #importanceReasonPid} and the
2887 * target provider in this process is in
2888 * {@link #importanceReasonComponent}.
2889 */
2890 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002891
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002892 /**
2893 * The reason for {@link #importance}, if any.
2894 */
2895 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002896
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002897 /**
2898 * For the specified values of {@link #importanceReasonCode}, this
2899 * is the process ID of the other process that is a client of this
2900 * process. This will be 0 if no other process is using this one.
2901 */
2902 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002903
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002904 /**
2905 * For the specified values of {@link #importanceReasonCode}, this
2906 * is the name of the component that is being used in this process.
2907 */
2908 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002909
Dianne Hackborn905577f2011-09-07 18:31:28 -07002910 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07002911 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07002912 * of the other pid. @hide
2913 */
2914 public int importanceReasonImportance;
2915
Dianne Hackborn684bf342014-04-29 17:56:57 -07002916 /**
2917 * Current process state, as per PROCESS_STATE_* constants.
2918 * @hide
2919 */
2920 public int processState;
2921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 public RunningAppProcessInfo() {
2923 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002924 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07002925 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
2929 processName = pProcessName;
2930 pid = pPid;
2931 pkgList = pArr;
2932 }
2933
2934 public int describeContents() {
2935 return 0;
2936 }
2937
2938 public void writeToParcel(Parcel dest, int flags) {
2939 dest.writeString(processName);
2940 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07002941 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002943 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002944 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 dest.writeInt(importance);
2946 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002947 dest.writeInt(importanceReasonCode);
2948 dest.writeInt(importanceReasonPid);
2949 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07002950 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07002951 dest.writeInt(processState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 }
2953
2954 public void readFromParcel(Parcel source) {
2955 processName = source.readString();
2956 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07002957 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002959 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002960 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 importance = source.readInt();
2962 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002963 importanceReasonCode = source.readInt();
2964 importanceReasonPid = source.readInt();
2965 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07002966 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07002967 processState = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 }
2969
Stefan Kuhne16045c22015-06-05 07:18:06 -07002970 public static final Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 new Creator<RunningAppProcessInfo>() {
2972 public RunningAppProcessInfo createFromParcel(Parcel source) {
2973 return new RunningAppProcessInfo(source);
2974 }
2975 public RunningAppProcessInfo[] newArray(int size) {
2976 return new RunningAppProcessInfo[size];
2977 }
2978 };
2979
2980 private RunningAppProcessInfo(Parcel source) {
2981 readFromParcel(source);
2982 }
2983 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07002986 * Returns a list of application processes installed on external media
2987 * that are running on the device.
2988 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002989 * <p><b>Note: this method is only intended for debugging or building
2990 * a user-facing process management UI.</b></p>
2991 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07002992 * @return Returns a list of ApplicationInfo records, or null if none
2993 * This list ordering is not specified.
2994 * @hide
2995 */
2996 public List<ApplicationInfo> getRunningExternalApplications() {
2997 try {
2998 return ActivityManagerNative.getDefault().getRunningExternalApplications();
2999 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003000 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003001 }
3002 }
3003
3004 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003005 * Sets the memory trim mode for a process and schedules a memory trim operation.
3006 *
3007 * <p><b>Note: this method is only intended for testing framework.</b></p>
3008 *
3009 * @return Returns true if successful.
3010 * @hide
3011 */
3012 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
3013 try {
3014 return ActivityManagerNative.getDefault().setProcessMemoryTrimLevel(process, userId,
3015 level);
3016 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003017 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07003018 }
3019 }
3020
3021 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003023 *
3024 * <p><b>Note: this method is only intended for debugging or building
3025 * a user-facing process management UI.</b></p>
3026 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
3028 * running processes (it will not return an empty list). This list ordering is not
3029 * specified.
3030 */
3031 public List<RunningAppProcessInfo> getRunningAppProcesses() {
3032 try {
3033 return ActivityManagerNative.getDefault().getRunningAppProcesses();
3034 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003035 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 }
3037 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003038
3039 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003040 * Return the importance of a given package name, based on the processes that are
3041 * currently running. The return value is one of the importance constants defined
3042 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3043 * processes that this package has code running inside of. If there are no processes
3044 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07003045 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07003046 */
Dianne Hackbornb7258942015-05-13 15:10:24 -07003047 @SystemApi
Dianne Hackborn1e383822015-04-10 14:02:33 -07003048 public int getPackageImportance(String packageName) {
3049 try {
Adam Lesinskic30454c2015-06-24 13:24:35 -07003050 int procState = ActivityManagerNative.getDefault().getPackageProcessState(packageName,
3051 mContext.getOpPackageName());
Dianne Hackborn1e383822015-04-10 14:02:33 -07003052 return RunningAppProcessInfo.procStateToImportance(procState);
3053 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003054 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07003055 }
3056 }
3057
3058 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003059 * Return global memory state information for the calling process. This
3060 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
3061 * only fields that will be filled in are
3062 * {@link RunningAppProcessInfo#pid},
3063 * {@link RunningAppProcessInfo#uid},
3064 * {@link RunningAppProcessInfo#lastTrimLevel},
3065 * {@link RunningAppProcessInfo#importance},
3066 * {@link RunningAppProcessInfo#lru}, and
3067 * {@link RunningAppProcessInfo#importanceReasonCode}.
3068 */
3069 static public void getMyMemoryState(RunningAppProcessInfo outState) {
3070 try {
3071 ActivityManagerNative.getDefault().getMyMemoryState(outState);
3072 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003073 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003074 }
3075 }
3076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003078 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003079 *
3080 * <p><b>Note: this method is only intended for debugging or building
3081 * a user-facing process management UI.</b></p>
3082 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003083 * @param pids The pids of the processes whose memory usage is to be
3084 * retrieved.
3085 * @return Returns an array of memory information, one for each
3086 * requested pid.
3087 */
3088 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
3089 try {
3090 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids);
3091 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003092 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003093 }
3094 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003095
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003096 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003097 * @deprecated This is now just a wrapper for
3098 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3099 * is no longer available to applications because it allows them to
3100 * break other applications by removing their alarms, stopping their
3101 * services, etc.
3102 */
3103 @Deprecated
3104 public void restartPackage(String packageName) {
3105 killBackgroundProcesses(packageName);
3106 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003107
Dianne Hackborn03abb812010-01-04 18:43:19 -08003108 /**
3109 * Have the system immediately kill all background processes associated
3110 * with the given package. This is the same as the kernel killing those
3111 * processes to reclaim memory; the system will take care of restarting
3112 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003113 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003114 * <p>You must hold the permission
3115 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to
3116 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003117 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003118 * @param packageName The name of the package whose processes are to
3119 * be killed.
3120 */
3121 public void killBackgroundProcesses(String packageName) {
3122 try {
Dianne Hackborn1676c852012-09-10 14:52:30 -07003123 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName,
3124 UserHandle.myUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003125 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003126 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003127 }
3128 }
Svet Ganov019d2302015-05-04 11:07:38 -07003129
3130 /**
3131 * Kills the specified UID.
3132 * @param uid The UID to kill.
3133 * @param reason The reason for the kill.
3134 *
3135 * @hide
3136 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08003137 @SystemApi
Svet Ganov019d2302015-05-04 11:07:38 -07003138 @RequiresPermission(Manifest.permission.KILL_UID)
3139 public void killUid(int uid, String reason) {
3140 try {
Svetoslavaa41add2015-08-06 15:03:55 -07003141 ActivityManagerNative.getDefault().killUid(UserHandle.getAppId(uid),
3142 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003143 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003144 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003145 }
3146 }
3147
Dianne Hackborn03abb812010-01-04 18:43:19 -08003148 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 * Have the system perform a force stop of everything associated with
3150 * the given application package. All processes that share its uid
3151 * will be killed, all services it has running stopped, all activities
3152 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3153 * broadcast will be sent, so that any of its registered alarms can
3154 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003155 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003157 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003159 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003161 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003162 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003163 * @hide This is not available to third party applications due to
3164 * it allowing them to break other applications by stopping their
3165 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 */
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003167 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168 try {
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003169 ActivityManagerNative.getDefault().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003171 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 }
3173 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003174
3175 /**
3176 * @see #forceStopPackageAsUser(String, int)
3177 * @hide
3178 */
3179 public void forceStopPackage(String packageName) {
3180 forceStopPackageAsUser(packageName, UserHandle.myUserId());
3181 }
3182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 /**
3184 * Get the device configuration attributes.
3185 */
3186 public ConfigurationInfo getDeviceConfigurationInfo() {
3187 try {
3188 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo();
3189 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003190 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003193
3194 /**
3195 * Get the preferred density of icons for the launcher. This is used when
3196 * custom drawables are created (e.g., for shortcuts).
3197 *
3198 * @return density in terms of DPI
3199 */
3200 public int getLauncherLargeIconDensity() {
3201 final Resources res = mContext.getResources();
3202 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003203 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003204
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003205 if (sw < 600) {
3206 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003207 return density;
3208 }
3209
3210 switch (density) {
3211 case DisplayMetrics.DENSITY_LOW:
3212 return DisplayMetrics.DENSITY_MEDIUM;
3213 case DisplayMetrics.DENSITY_MEDIUM:
3214 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003215 case DisplayMetrics.DENSITY_TV:
3216 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003217 case DisplayMetrics.DENSITY_HIGH:
3218 return DisplayMetrics.DENSITY_XHIGH;
3219 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003220 return DisplayMetrics.DENSITY_XXHIGH;
3221 case DisplayMetrics.DENSITY_XXHIGH:
3222 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003223 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003224 // The density is some abnormal value. Return some other
3225 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003226 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003227 }
3228 }
3229
3230 /**
3231 * Get the preferred launcher icon size. This is used when custom drawables
3232 * are created (e.g., for shortcuts).
3233 *
3234 * @return dimensions of square icons in terms of pixels
3235 */
3236 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003237 return getLauncherLargeIconSizeInner(mContext);
3238 }
3239
3240 static int getLauncherLargeIconSizeInner(Context context) {
3241 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003242 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003243 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003244
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003245 if (sw < 600) {
3246 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003247 return size;
3248 }
3249
3250 final int density = res.getDisplayMetrics().densityDpi;
3251
3252 switch (density) {
3253 case DisplayMetrics.DENSITY_LOW:
3254 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3255 case DisplayMetrics.DENSITY_MEDIUM:
3256 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003257 case DisplayMetrics.DENSITY_TV:
3258 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003259 case DisplayMetrics.DENSITY_HIGH:
3260 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3261 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003262 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3263 case DisplayMetrics.DENSITY_XXHIGH:
3264 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003265 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003266 // The density is some abnormal value. Return some other
3267 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003268 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003269 }
3270 }
3271
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003272 /**
3273 * Returns "true" if the user interface is currently being messed with
3274 * by a monkey.
3275 */
3276 public static boolean isUserAMonkey() {
3277 try {
3278 return ActivityManagerNative.getDefault().isUserAMonkey();
3279 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003280 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003281 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003282 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003283
3284 /**
3285 * Returns "true" if device is running in a test harness.
3286 */
3287 public static boolean isRunningInTestHarness() {
3288 return SystemProperties.getBoolean("ro.test_harness", false);
3289 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003290
3291 /**
3292 * Returns the launch count of each installed package.
3293 *
3294 * @hide
3295 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003296 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00003297 try {
3298 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
3299 ServiceManager.getService("usagestats"));
3300 if (usageStatsService == null) {
3301 return new HashMap<String, Integer>();
3302 }
3303
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003304 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
3305 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00003306 if (allPkgUsageStats == null) {
3307 return new HashMap<String, Integer>();
3308 }
3309
Peter Visontay8d224ca2011-02-18 16:39:19 +00003310 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003311 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
3312 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00003313 }
3314
3315 return launchCounts;
3316 } catch (RemoteException e) {
3317 Log.w(TAG, "Could not query launch counts", e);
3318 return new HashMap<String, Integer>();
3319 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003320 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003321
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003322 /** @hide */
3323 public static int checkComponentPermission(String permission, int uid,
3324 int owningUid, boolean exported) {
3325 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08003326 final int appId = UserHandle.getAppId(uid);
3327 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003328 return PackageManager.PERMISSION_GRANTED;
3329 }
3330 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003331 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003332 return PackageManager.PERMISSION_DENIED;
3333 }
3334 // If there is a uid that owns whatever is being accessed, it has
3335 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003336 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003337 return PackageManager.PERMISSION_GRANTED;
3338 }
3339 // If the target is not exported, then nobody else can get to it.
3340 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07003341 /*
3342 RuntimeException here = new RuntimeException("here");
3343 here.fillInStackTrace();
3344 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
3345 here);
3346 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003347 return PackageManager.PERMISSION_DENIED;
3348 }
3349 if (permission == null) {
3350 return PackageManager.PERMISSION_GRANTED;
3351 }
3352 try {
3353 return AppGlobals.getPackageManager()
3354 .checkUidPermission(permission, uid);
3355 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003356 throw e.rethrowFromSystemServer();
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003357 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003358 }
3359
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003360 /** @hide */
3361 public static int checkUidPermission(String permission, int uid) {
3362 try {
3363 return AppGlobals.getPackageManager()
3364 .checkUidPermission(permission, uid);
3365 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003366 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003367 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003368 }
3369
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08003370 /**
3371 * @hide
3372 * Helper for dealing with incoming user arguments to system service calls.
3373 * Takes care of checking permissions and converting USER_CURRENT to the
3374 * actual current user.
3375 *
3376 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
3377 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
3378 * @param userId The user id argument supplied by the caller -- this is the user
3379 * they want to run as.
3380 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
3381 * to get a USER_ALL returned and deal with it correctly. If false,
3382 * an exception will be thrown if USER_ALL is supplied.
3383 * @param requireFull If true, the caller must hold
3384 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
3385 * different user than their current process; otherwise they must hold
3386 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
3387 * @param name Optional textual name of the incoming call; only for generating error messages.
3388 * @param callerPackage Optional package name of caller; only for error messages.
3389 *
3390 * @return Returns the user ID that the call should run as. Will always be a concrete
3391 * user number, unless <var>allowAll</var> is true in which case it could also be
3392 * USER_ALL.
3393 */
Dianne Hackborn41203752012-08-31 14:05:51 -07003394 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
3395 boolean allowAll, boolean requireFull, String name, String callerPackage) {
3396 if (UserHandle.getUserId(callingUid) == userId) {
3397 return userId;
3398 }
3399 try {
3400 return ActivityManagerNative.getDefault().handleIncomingUser(callingPid,
3401 callingUid, userId, allowAll, requireFull, name, callerPackage);
3402 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003403 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003404 }
3405 }
3406
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07003407 /**
3408 * Gets the userId of the current foreground user. Requires system permissions.
3409 * @hide
3410 */
3411 @SystemApi
Dianne Hackborn41203752012-08-31 14:05:51 -07003412 public static int getCurrentUser() {
3413 UserInfo ui;
3414 try {
3415 ui = ActivityManagerNative.getDefault().getCurrentUser();
3416 return ui != null ? ui.id : 0;
3417 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003418 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003419 }
3420 }
3421
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003422 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003423 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003424 * @hide
3425 */
3426 public boolean switchUser(int userid) {
3427 try {
3428 return ActivityManagerNative.getDefault().switchUser(userid);
3429 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003430 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003431 }
3432 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003433
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003434 /**
3435 * Logs out current current foreground user by switching to the system user and stopping the
3436 * user being switched from.
3437 * @hide
3438 */
3439 public static void logoutCurrentUser() {
3440 int currentUser = ActivityManager.getCurrentUser();
3441 if (currentUser != UserHandle.USER_SYSTEM) {
3442 try {
3443 ActivityManagerNative.getDefault().switchUser(UserHandle.USER_SYSTEM);
3444 ActivityManagerNative.getDefault().stopUser(currentUser, /* force= */ false, null);
3445 } catch (RemoteException e) {
3446 e.rethrowFromSystemServer();
3447 }
3448 }
3449 }
3450
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003451 /** {@hide} */
3452 public static final int FLAG_OR_STOPPED = 1 << 0;
3453 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07003454 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07003455 /** {@hide} */
3456 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeyce18c812016-04-27 16:00:41 -06003457 /** {@hide} */
3458 public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003459
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003460 /**
3461 * Return whether the given user is actively running. This means that
3462 * the user is in the "started" state, not "stopped" -- it is currently
3463 * allowed to run code through scheduled alarms, receiving broadcasts,
3464 * etc. A started user may be either the current foreground user or a
3465 * background user; the result here does not distinguish between the two.
3466 * @param userid the user's id. Zero indicates the default user.
3467 * @hide
3468 */
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003469 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003470 try {
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003471 return ActivityManagerNative.getDefault().isUserRunning(userId, 0);
3472 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003473 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003474 }
3475 }
3476
3477 /** {@hide} */
Ruben Brunke24b9a62016-02-16 21:38:24 -08003478 public boolean isVrModePackageEnabled(ComponentName component) {
3479 try {
3480 return ActivityManagerNative.getDefault().isVrModePackageEnabled(component);
3481 } catch (RemoteException e) {
3482 throw e.rethrowFromSystemServer();
3483 }
3484 }
3485
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003486 /**
3487 * Perform a system dump of various state associated with the given application
3488 * package name. This call blocks while the dump is being performed, so should
3489 * not be done on a UI thread. The data will be written to the given file
3490 * descriptor as text. An application must hold the
3491 * {@link android.Manifest.permission#DUMP} permission to make this call.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07003492 * @param fd The file descriptor that the dump should be written to. The file
3493 * descriptor is <em>not</em> closed by this function; the caller continues to
3494 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003495 * @param packageName The name of the package that is to be dumped.
3496 */
3497 public void dumpPackageState(FileDescriptor fd, String packageName) {
3498 dumpPackageStateStatic(fd, packageName);
3499 }
3500
3501 /**
3502 * @hide
3503 */
3504 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
3505 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07003506 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003507 dumpService(pw, fd, "package", new String[] { packageName });
3508 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003509 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
3510 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003511 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003512 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003513 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003514 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003515 pw.println();
Dianne Hackborn904a8572013-06-28 18:12:31 -07003516 dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName });
3517 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07003518 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003519 pw.flush();
3520 }
3521
3522 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
3523 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
3524 IBinder service = ServiceManager.checkService(name);
3525 if (service == null) {
3526 pw.println(" (Service not found)");
3527 return;
3528 }
3529 TransferPipe tp = null;
3530 try {
3531 pw.flush();
3532 tp = new TransferPipe();
3533 tp.setBufferPrefix(" ");
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003534 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003535 tp.go(fd, 10000);
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003536 } catch (Throwable e) {
3537 if (tp != null) {
3538 tp.kill();
3539 }
3540 pw.println("Failure dumping service:");
3541 e.printStackTrace(pw);
3542 }
3543 }
Craig Mautneraea74a52014-03-08 14:23:10 -08003544
3545 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003546 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07003547 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003548 * sees the associated process with a larger pss size and, when this happens, automatically
3549 * pull a heap dump from it and allow the user to share the data. Note that this request
3550 * continues running even if the process is killed and restarted. To remove the watch,
3551 * use {@link #clearWatchHeapLimit()}.
3552 *
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07003553 * <p>This API only work if the calling process has been marked as
3554 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
3555 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003556 *
3557 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
3558 * handle heap limit reports themselves.</p>
3559 *
3560 * @param pssSize The size in bytes to set the limit at.
3561 */
3562 public void setWatchHeapLimit(long pssSize) {
3563 try {
3564 ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, pssSize,
3565 mContext.getPackageName());
3566 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003567 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003568 }
3569 }
3570
3571 /**
3572 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
3573 * If your package has an activity handling this action, it will be launched with the
3574 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
3575 * match the activty must support this action and a MIME type of "*&#47;*".
3576 */
3577 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
3578
3579 /**
3580 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
3581 */
3582 public void clearWatchHeapLimit() {
3583 try {
3584 ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, 0, null);
3585 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003586 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07003587 }
3588 }
3589
3590 /**
Craig Mautneraea74a52014-03-08 14:23:10 -08003591 * @hide
3592 */
3593 public void startLockTaskMode(int taskId) {
3594 try {
3595 ActivityManagerNative.getDefault().startLockTaskMode(taskId);
3596 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003597 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003598 }
3599 }
3600
3601 /**
3602 * @hide
3603 */
3604 public void stopLockTaskMode() {
3605 try {
3606 ActivityManagerNative.getDefault().stopLockTaskMode();
3607 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003608 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003609 }
3610 }
3611
3612 /**
Jason Monk386c94f2014-07-14 16:42:24 -04003613 * Return whether currently in lock task mode. When in this mode
3614 * no new tasks can be created or switched to.
3615 *
3616 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00003617 *
3618 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08003619 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07003620 @Deprecated
Craig Mautneraea74a52014-03-08 14:23:10 -08003621 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00003622 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
3623 }
3624
3625 /**
3626 * Return the current state of task locking. The three possible outcomes
3627 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
3628 * and {@link #LOCK_TASK_MODE_PINNED}.
3629 *
3630 * @see Activity#startLockTask()
3631 */
3632 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08003633 try {
Benjamin Franz43261142015-02-11 15:59:44 +00003634 return ActivityManagerNative.getDefault().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08003635 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003636 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08003637 }
3638 }
Winson Chung1147c402014-05-14 11:05:00 -07003639
3640 /**
Srinath Sridharane535a582016-06-27 18:13:47 -07003641 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one
3642 * thread can be a VR thread in a process at a time, and that thread may be subject to
3643 * restrictions on the amount of time it can run.
3644 *
3645 * To reset the VR thread for an application, a tid of 0 can be passed.
3646 *
3647 * @see android.os.Process#myTid()
3648 * @param tid tid of the VR thread
3649 */
3650 public static void setVrThread(int tid) {
3651 try {
3652 ActivityManagerNative.getDefault().setVrThread(tid);
3653 } catch (RemoteException e) {
3654 // pass
3655 }
3656 }
3657
3658 /**
Winson Chung1147c402014-05-14 11:05:00 -07003659 * The AppTask allows you to manage your own application's tasks.
3660 * See {@link android.app.ActivityManager#getAppTasks()}
3661 */
3662 public static class AppTask {
3663 private IAppTask mAppTaskImpl;
3664
3665 /** @hide */
3666 public AppTask(IAppTask task) {
3667 mAppTaskImpl = task;
3668 }
3669
3670 /**
3671 * Finishes all activities in this task and removes it from the recent tasks list.
3672 */
3673 public void finishAndRemoveTask() {
3674 try {
3675 mAppTaskImpl.finishAndRemoveTask();
3676 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003677 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07003678 }
3679 }
3680
3681 /**
3682 * Get the RecentTaskInfo associated with this task.
3683 *
3684 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
3685 */
3686 public RecentTaskInfo getTaskInfo() {
3687 try {
3688 return mAppTaskImpl.getTaskInfo();
3689 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003690 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07003691 }
3692 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003693
3694 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003695 * Bring this task to the foreground. If it contains activities, they will be
3696 * brought to the foreground with it and their instances re-created if needed.
3697 * If it doesn't contain activities, the root activity of the task will be
3698 * re-launched.
3699 */
3700 public void moveToFront() {
3701 try {
3702 mAppTaskImpl.moveToFront();
3703 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003704 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003705 }
3706 }
3707
3708 /**
3709 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003710 * is not currently active (that is, its id < 0), then a new activity for the given
3711 * Intent will be launched as the root of the task and the task brought to the
3712 * foreground. Otherwise, if this task is currently active and the Intent does not specify
3713 * an activity to launch in a new task, then a new activity for the given Intent will
3714 * be launched on top of the task and the task brought to the foreground. If this
3715 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
3716 * or would otherwise be launched in to a new task, then the activity not launched but
3717 * this task be brought to the foreground and a new intent delivered to the top
3718 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003719 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003720 * <p>In other words, you generally want to use an Intent here that does not specify
3721 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
3722 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003723 *
3724 * @param intent The Intent describing the new activity to be launched on the task.
3725 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07003726 *
3727 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07003728 */
3729 public void startActivity(Context context, Intent intent, Bundle options) {
3730 ActivityThread thread = ActivityThread.currentActivityThread();
3731 thread.getInstrumentation().execStartActivityFromAppTask(context,
3732 thread.getApplicationThread(), mAppTaskImpl, intent, options);
3733 }
3734
3735 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003736 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
3737 * Intent of this AppTask.
3738 *
3739 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
3740 * be set; otherwise, it will be cleared.
3741 */
3742 public void setExcludeFromRecents(boolean exclude) {
3743 try {
3744 mAppTaskImpl.setExcludeFromRecents(exclude);
3745 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003746 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07003747 }
3748 }
Winson Chung1147c402014-05-14 11:05:00 -07003749 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750}