blob: 5b16b7dbf2d71d2da3ed3b88fd0a7f360908ce3d [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;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060025import android.annotation.SystemService;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070026import android.annotation.TestApi;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.ComponentName;
28import android.content.Context;
29import android.content.Intent;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080030import android.content.UriPermission;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070031import android.content.pm.ActivityInfo;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070032import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.pm.ConfigurationInfo;
34import android.content.pm.IPackageDataObserver;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070035import android.content.pm.PackageManager;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080036import android.content.pm.ParceledListSlice;
Dianne Hackborn41203752012-08-31 14:05:51 -070037import android.content.pm.UserInfo;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070038import android.content.res.Configuration;
Kenny Root5ef44b72011-01-26 17:22:20 -080039import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.graphics.Bitmap;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070041import android.graphics.Canvas;
Winson Chunga449dc02014-05-16 11:15:04 -070042import android.graphics.Color;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070043import android.graphics.GraphicBuffer;
44import android.graphics.Matrix;
45import android.graphics.Point;
Craig Mautner967212c2013-04-13 21:10:58 -070046import android.graphics.Rect;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070047import android.os.BatteryStats;
48import android.os.Build;
49import android.os.Build.VERSION_CODES;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070050import android.os.Bundle;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070051import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.os.Handler;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070053import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.Parcel;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070055import android.os.ParcelFileDescriptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.os.Parcelable;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070057import android.os.Process;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070058import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000059import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070060import android.os.SystemProperties;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070061import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.text.TextUtils;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070063import android.util.ArrayMap;
Kenny Root5ef44b72011-01-26 17:22:20 -080064import android.util.DisplayMetrics;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070065import android.util.Singleton;
Winson Chung48a10a52014-08-27 14:36:51 -070066import android.util.Size;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080067
Wale Ogunwalec981ad52017-06-13 11:40:06 -070068import com.android.internal.app.procstats.ProcessStats;
69import com.android.internal.os.RoSystemProperties;
70import com.android.internal.os.TransferPipe;
71import com.android.internal.util.FastPrintWriter;
72import com.android.server.LocalServices;
73
Craig Mautner648f69b2014-09-18 14:16:26 -070074import org.xmlpull.v1.XmlSerializer;
Kenny Root5ef44b72011-01-26 17:22:20 -080075
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070076import java.io.FileDescriptor;
77import java.io.FileOutputStream;
Craig Mautner648f69b2014-09-18 14:16:26 -070078import java.io.IOException;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070079import java.io.PrintWriter;
Michal Karpinski3da5c972015-12-11 18:16:30 +000080import java.lang.annotation.Retention;
81import java.lang.annotation.RetentionPolicy;
Winson Chung1147c402014-05-14 11:05:00 -070082import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083import java.util.List;
84
85/**
Dave Friedman2a3ebad2017-01-04 18:27:26 -080086 * <p>
87 * This class gives information about, and interacts
88 * with, activities, services, and the containing
89 * process.
90 * </p>
91 *
92 * <p>
93 * A number of the methods in this class are for
94 * debugging or informational purposes and they should
95 * not be used to affect any runtime behavior of
96 * your app. These methods are called out as such in
97 * the method level documentation.
98 * </p>
99 *
100 *<p>
101 * Most application developers should not have the need to
102 * use this class, most of whose methods are for specialized
103 * use cases. However, a few methods are more broadly applicable.
104 * For instance, {@link android.app.ActivityManager#isLowRamDevice() isLowRamDevice()}
105 * enables your app to detect whether it is running on a low-memory device,
106 * and behave accordingly.
107 * {@link android.app.ActivityManager#clearApplicationUserData() clearApplicationUserData()}
108 * is for apps with reset-data functionality.
109 * </p>
110 *
111 * <p>
112 * In some special use cases, where an app interacts with
113 * its Task stack, the app may use the
114 * {@link android.app.ActivityManager.AppTask} and
115 * {@link android.app.ActivityManager.RecentTaskInfo} inner
116 * classes. However, in general, the methods in this class should
117 * be used for testing and debugging purposes only.
118 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600120@SystemService(Context.ACTIVITY_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121public class ActivityManager {
122 private static String TAG = "ActivityManager";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123
Dianne Hackborn852975d2014-08-22 17:42:43 -0700124 private static int gMaxRecentTasks = -1;
125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800128 private static volatile boolean sSystemReady = false;
129
Bryce Lee7f936862017-05-09 15:33:18 -0700130
131 private static final int FIRST_START_FATAL_ERROR_CODE = -100;
132 private static final int LAST_START_FATAL_ERROR_CODE = -1;
133 private static final int FIRST_START_SUCCESS_CODE = 0;
134 private static final int LAST_START_SUCCESS_CODE = 99;
135 private static final int FIRST_START_NON_FATAL_ERROR_CODE = 100;
136 private static final int LAST_START_NON_FATAL_ERROR_CODE = 199;
137
Jorim Jaggi02886a82016-12-06 09:10:06 -0800138 /**
139 * System property to enable task snapshots.
140 * @hide
141 */
142 public final static boolean ENABLE_TASK_SNAPSHOTS;
143
144 static {
Robert Carra35e5de2017-03-03 17:04:54 -0800145 ENABLE_TASK_SNAPSHOTS = SystemProperties.getBoolean("persist.enable_task_snapshots", true);
Jorim Jaggi02886a82016-12-06 09:10:06 -0800146 }
147
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700148 static final class UidObserver extends IUidObserver.Stub {
149 final OnUidImportanceListener mListener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700150 final Context mContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700151
Makoto Onukid7e40582017-04-13 14:54:56 -0700152 UidObserver(OnUidImportanceListener listener, Context clientContext) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700153 mListener = listener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700154 mContext = clientContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700155 }
156
157 @Override
Sudheer Shanka80255802017-03-04 14:48:53 -0800158 public void onUidStateChanged(int uid, int procState, long procStateSeq) {
Makoto Onukid7e40582017-04-13 14:54:56 -0700159 mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportanceForClient(
160 procState, mContext));
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700161 }
162
163 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800164 public void onUidGone(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700165 mListener.onUidImportance(uid, RunningAppProcessInfo.IMPORTANCE_GONE);
166 }
167
168 @Override
169 public void onUidActive(int uid) {
170 }
171
172 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800173 public void onUidIdle(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700174 }
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700175
176 @Override public void onUidCachedChanged(int uid, boolean cached) {
177 }
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700178 }
179
180 final ArrayMap<OnUidImportanceListener, UidObserver> mImportanceListeners = new ArrayMap<>();
181
Felipe Lemedc7af962016-01-22 18:27:03 -0800182 /**
183 * Defines acceptable types of bugreports.
184 * @hide
185 */
Michal Karpinski3da5c972015-12-11 18:16:30 +0000186 @Retention(RetentionPolicy.SOURCE)
187 @IntDef({
188 BUGREPORT_OPTION_FULL,
189 BUGREPORT_OPTION_INTERACTIVE,
Wei Liu967fc8d2016-07-08 11:44:20 -0700190 BUGREPORT_OPTION_REMOTE,
Felipe Leme9606c3b2017-01-05 14:57:12 -0800191 BUGREPORT_OPTION_WEAR,
192 BUGREPORT_OPTION_TELEPHONY
Michal Karpinski3da5c972015-12-11 18:16:30 +0000193 })
Michal Karpinski3da5c972015-12-11 18:16:30 +0000194 public @interface BugreportMode {}
195 /**
196 * Takes a bugreport without user interference (and hence causing less
197 * interference to the system), but includes all sections.
198 * @hide
199 */
200 public static final int BUGREPORT_OPTION_FULL = 0;
201 /**
202 * Allows user to monitor progress and enter additional data; might not include all
203 * sections.
204 * @hide
205 */
206 public static final int BUGREPORT_OPTION_INTERACTIVE = 1;
207 /**
208 * Takes a bugreport requested remotely by administrator of the Device Owner app,
209 * not the device's user.
210 * @hide
211 */
212 public static final int BUGREPORT_OPTION_REMOTE = 2;
Wei Liu967fc8d2016-07-08 11:44:20 -0700213 /**
214 * Takes a bugreport on a wearable device.
215 * @hide
216 */
217 public static final int BUGREPORT_OPTION_WEAR = 3;
Michal Karpinski3da5c972015-12-11 18:16:30 +0000218
Dianne Hackborna4972e92012-03-14 10:38:05 -0700219 /**
Felipe Leme9606c3b2017-01-05 14:57:12 -0800220 * Takes a lightweight version of bugreport that only includes a few, urgent sections
221 * used to report telephony bugs.
222 * @hide
223 */
224 public static final int BUGREPORT_OPTION_TELEPHONY = 4;
225
226 /**
Scott Maincc2195b2013-10-16 13:57:46 -0700227 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000228 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
Christopher Tatebd413f62013-09-18 18:31:59 -0700229 * uninstalled in lieu of the declaring one. The package named here must be
Neil Fuller71fbb812015-11-30 09:51:33 +0000230 * signed with the same certificate as the one declaring the {@code <meta-data>}.
Christopher Tatebd413f62013-09-18 18:31:59 -0700231 */
232 public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
233
Bryce Lee7f936862017-05-09 15:33:18 -0700234 // NOTE: Before adding a new start result, please reference the defined ranges to ensure the
235 // result is properly categorized.
236
Christopher Tatebd413f62013-09-18 18:31:59 -0700237 /**
Amith Yamasani42449782016-04-19 11:45:51 -0700238 * Result for IActivityManager.startVoiceActivity: active session is currently hidden.
239 * @hide
240 */
Bryce Lee7f936862017-05-09 15:33:18 -0700241 public static final int START_VOICE_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE;
Amith Yamasani42449782016-04-19 11:45:51 -0700242
243 /**
244 * Result for IActivityManager.startVoiceActivity: active session does not match
245 * the requesting token.
246 * @hide
247 */
Bryce Lee7f936862017-05-09 15:33:18 -0700248 public static final int START_VOICE_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 1;
Amith Yamasani42449782016-04-19 11:45:51 -0700249
250 /**
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700251 * Result for IActivityManager.startActivity: trying to start a background user
252 * activity that shouldn't be displayed for all users.
253 * @hide
254 */
Bryce Lee7f936862017-05-09 15:33:18 -0700255 public static final int START_NOT_CURRENT_USER_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 2;
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700256
257 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700258 * Result for IActivityManager.startActivity: trying to start an activity under voice
259 * control when that activity does not support the VOICE category.
260 * @hide
261 */
Bryce Lee7f936862017-05-09 15:33:18 -0700262 public static final int START_NOT_VOICE_COMPATIBLE = FIRST_START_FATAL_ERROR_CODE + 3;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700263
264 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700265 * Result for IActivityManager.startActivity: an error where the
266 * start had to be canceled.
267 * @hide
268 */
Bryce Lee7f936862017-05-09 15:33:18 -0700269 public static final int START_CANCELED = FIRST_START_FATAL_ERROR_CODE + 4;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700270
271 /**
272 * Result for IActivityManager.startActivity: an error where the
273 * thing being started is not an activity.
274 * @hide
275 */
Bryce Lee7f936862017-05-09 15:33:18 -0700276 public static final int START_NOT_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 5;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700277
278 /**
279 * Result for IActivityManager.startActivity: an error where the
280 * caller does not have permission to start the activity.
281 * @hide
282 */
Bryce Lee7f936862017-05-09 15:33:18 -0700283 public static final int START_PERMISSION_DENIED = FIRST_START_FATAL_ERROR_CODE + 6;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700284
285 /**
286 * Result for IActivityManager.startActivity: an error where the
287 * caller has requested both to forward a result and to receive
288 * a result.
289 * @hide
290 */
Bryce Lee7f936862017-05-09 15:33:18 -0700291 public static final int START_FORWARD_AND_REQUEST_CONFLICT = FIRST_START_FATAL_ERROR_CODE + 7;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700292
293 /**
294 * Result for IActivityManager.startActivity: an error where the
295 * requested class is not found.
296 * @hide
297 */
Bryce Lee7f936862017-05-09 15:33:18 -0700298 public static final int START_CLASS_NOT_FOUND = FIRST_START_FATAL_ERROR_CODE + 8;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700299
300 /**
301 * Result for IActivityManager.startActivity: an error where the
302 * given Intent could not be resolved to an activity.
303 * @hide
304 */
Bryce Lee7f936862017-05-09 15:33:18 -0700305 public static final int START_INTENT_NOT_RESOLVED = FIRST_START_FATAL_ERROR_CODE + 9;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700306
307 /**
Winson Chungfc3ec4c2017-06-01 15:35:48 -0700308 * Result for IActivityManager.startAssistantActivity: active session is currently hidden.
309 * @hide
310 */
311 public static final int START_ASSISTANT_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE + 10;
312
313 /**
314 * Result for IActivityManager.startAssistantActivity: active session does not match
315 * the requesting token.
316 * @hide
317 */
318 public static final int START_ASSISTANT_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 11;
319
320 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700321 * Result for IActivityManaqer.startActivity: the activity was started
322 * successfully as normal.
323 * @hide
324 */
Bryce Lee7f936862017-05-09 15:33:18 -0700325 public static final int START_SUCCESS = FIRST_START_SUCCESS_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700326
327 /**
328 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not
329 * be executed if it is the recipient, and that is indeed the case.
330 * @hide
331 */
Bryce Lee7f936862017-05-09 15:33:18 -0700332 public static final int START_RETURN_INTENT_TO_CALLER = FIRST_START_SUCCESS_CODE + 1;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700333
334 /**
335 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
336 * a task was simply brought to the foreground.
337 * @hide
338 */
Bryce Lee7f936862017-05-09 15:33:18 -0700339 public static final int START_TASK_TO_FRONT = FIRST_START_SUCCESS_CODE + 2;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700340
341 /**
342 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
343 * the given Intent was given to the existing top activity.
344 * @hide
345 */
Bryce Lee7f936862017-05-09 15:33:18 -0700346 public static final int START_DELIVERED_TO_TOP = FIRST_START_SUCCESS_CODE + 3;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700347
348 /**
349 * Result for IActivityManaqer.startActivity: request was canceled because
350 * app switches are temporarily canceled to ensure the user's last request
351 * (such as pressing home) is performed.
352 * @hide
353 */
Bryce Lee7f936862017-05-09 15:33:18 -0700354 public static final int START_SWITCHES_CANCELED = FIRST_START_NON_FATAL_ERROR_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700355
356 /**
Craig Mautneraea74a52014-03-08 14:23:10 -0800357 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started
358 * while in Lock Task Mode.
359 * @hide
360 */
Bryce Lee7f936862017-05-09 15:33:18 -0700361 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION =
362 FIRST_START_NON_FATAL_ERROR_CODE + 1;
Craig Mautneraea74a52014-03-08 14:23:10 -0800363
364 /**
Bryce Leef9d49542017-06-26 16:27:32 -0700365 * Result for IActivityManaqer.startActivity: a new activity start was aborted. Never returned
366 * externally.
367 * @hide
368 */
369 public static final int START_ABORTED = FIRST_START_NON_FATAL_ERROR_CODE + 2;
370
371 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700372 * Flag for IActivityManaqer.startActivity: do special start mode where
373 * a new activity is launched only if it is needed.
374 * @hide
375 */
376 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
377
378 /**
379 * Flag for IActivityManaqer.startActivity: launch the app for
380 * debugging.
381 * @hide
382 */
383 public static final int START_FLAG_DEBUG = 1<<1;
384
385 /**
386 * Flag for IActivityManaqer.startActivity: launch the app for
Man Caocfa78b22015-06-11 20:14:34 -0700387 * allocation tracking.
388 * @hide
389 */
Pablo Ceballosa4d4e822015-10-05 10:27:52 -0700390 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2;
Man Caocfa78b22015-06-11 20:14:34 -0700391
392 /**
Tamas Berghammerdf6cb282016-01-29 12:07:00 +0000393 * Flag for IActivityManaqer.startActivity: launch the app with
394 * native debugging support.
395 * @hide
396 */
397 public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3;
398
399 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700400 * Result for IActivityManaqer.broadcastIntent: success!
401 * @hide
402 */
403 public static final int BROADCAST_SUCCESS = 0;
404
405 /**
406 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast
407 * a sticky intent without appropriate permission.
408 * @hide
409 */
410 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
411
412 /**
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800413 * Result for IActivityManager.broadcastIntent: trying to send a broadcast
414 * to a stopped user. Fail.
415 * @hide
416 */
417 public static final int BROADCAST_FAILED_USER_STOPPED = -2;
418
419 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700420 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
421 * for a sendBroadcast operation.
422 * @hide
423 */
424 public static final int INTENT_SENDER_BROADCAST = 1;
425
426 /**
427 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
428 * for a startActivity operation.
429 * @hide
430 */
431 public static final int INTENT_SENDER_ACTIVITY = 2;
432
433 /**
434 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
435 * for an activity result operation.
436 * @hide
437 */
438 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
439
440 /**
441 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
442 * for a startService operation.
443 * @hide
444 */
445 public static final int INTENT_SENDER_SERVICE = 4;
446
Christopher Tate08992ac2017-03-21 11:37:06 -0700447 /**
448 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
449 * for a startForegroundService operation.
450 * @hide
451 */
452 public static final int INTENT_SENDER_FOREGROUND_SERVICE = 5;
453
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700454 /** @hide User operation call: success! */
455 public static final int USER_OP_SUCCESS = 0;
456
457 /** @hide User operation call: given user id is not known. */
458 public static final int USER_OP_UNKNOWN_USER = -1;
459
460 /** @hide User operation call: given user id is the current user, can't be stopped. */
461 public static final int USER_OP_IS_CURRENT = -2;
462
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700463 /** @hide User operation call: system user can't be stopped. */
464 public static final int USER_OP_ERROR_IS_SYSTEM = -3;
465
466 /** @hide User operation call: one of related users cannot be stopped. */
467 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4;
468
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800469 /** @hide Not a real process state. */
470 public static final int PROCESS_STATE_UNKNOWN = -1;
Ruben Brunka27eef42015-01-28 15:04:16 -0800471
Dianne Hackborna413dc02013-07-12 12:02:55 -0700472 /** @hide Process is a persistent system process. */
473 public static final int PROCESS_STATE_PERSISTENT = 0;
474
475 /** @hide Process is a persistent system process and is doing UI. */
476 public static final int PROCESS_STATE_PERSISTENT_UI = 1;
477
Dianne Hackbornc8230512013-07-13 21:32:12 -0700478 /** @hide Process is hosting the current top activities. Note that this covers
479 * all activities that are visible to the user. */
Dianne Hackborna413dc02013-07-12 12:02:55 -0700480 public static final int PROCESS_STATE_TOP = 2;
481
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700482 /** @hide Process is hosting a foreground service due to a system binding. */
483 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 3;
484
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700485 /** @hide Process is hosting a foreground service. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700486 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700487
488 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700489 public static final int PROCESS_STATE_TOP_SLEEPING = 5;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700490
Dianne Hackborna413dc02013-07-12 12:02:55 -0700491 /** @hide Process is important to the user, and something they are aware of. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700492 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700493
494 /** @hide Process is important to the user, but not something they are aware of. */
Dianne Hackbornab4bb9d2015-06-05 18:08:37 -0700495 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700496
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700497 /** @hide Process is in the background transient so we will try to keep running. */
498 public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 8;
499
Dianne Hackborna413dc02013-07-12 12:02:55 -0700500 /** @hide Process is in the background running a backup/restore operation. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700501 public static final int PROCESS_STATE_BACKUP = 9;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700502
Dianne Hackbornc8230512013-07-13 21:32:12 -0700503 /** @hide Process is in the background, but it can't restore its state so we want
504 * to try to avoid killing it. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700505 public static final int PROCESS_STATE_HEAVY_WEIGHT = 10;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700506
507 /** @hide Process is in the background running a service. Unlike oom_adj, this level
508 * is used for both the normal running in background state and the executing
509 * operations state. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700510 public static final int PROCESS_STATE_SERVICE = 11;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700511
Dianne Hackbornc8230512013-07-13 21:32:12 -0700512 /** @hide Process is in the background running a receiver. Note that from the
513 * perspective of oom_adj receivers run at a higher foreground level, but for our
514 * prioritization here that is not necessary and putting them below services means
515 * many fewer changes in some process states as they receive broadcasts. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700516 public static final int PROCESS_STATE_RECEIVER = 12;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700517
Dianne Hackborna413dc02013-07-12 12:02:55 -0700518 /** @hide Process is in the background but hosts the home activity. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700519 public static final int PROCESS_STATE_HOME = 13;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700520
521 /** @hide Process is in the background but hosts the last shown activity. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700522 public static final int PROCESS_STATE_LAST_ACTIVITY = 14;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700523
Dianne Hackbornc8230512013-07-13 21:32:12 -0700524 /** @hide Process is being cached for later use and contains activities. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700525 public static final int PROCESS_STATE_CACHED_ACTIVITY = 15;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700526
527 /** @hide Process is being cached for later use and is a client of another cached
528 * process that contains activities. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700529 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 16;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700530
531 /** @hide Process is being cached for later use and is empty. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700532 public static final int PROCESS_STATE_CACHED_EMPTY = 17;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700533
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800534 /** @hide Process does not exist. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700535 public static final int PROCESS_STATE_NONEXISTENT = 18;
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800536
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700537 /** @hide The lowest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800538 public static final int MIN_PROCESS_STATE = PROCESS_STATE_PERSISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700539
540 /** @hide The highest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800541 public static final int MAX_PROCESS_STATE = PROCESS_STATE_NONEXISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700542
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700543 /** @hide Should this process state be considered a background state? */
544 public static final boolean isProcStateBackground(int procState) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700545 return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700546 }
547
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700548 /** @hide requestType for assist context: only basic information. */
549 public static final int ASSIST_CONTEXT_BASIC = 0;
550
551 /** @hide requestType for assist context: generate full AssistStructure. */
552 public static final int ASSIST_CONTEXT_FULL = 1;
553
Felipe Leme640f30a2017-03-06 15:44:06 -0800554 /** @hide requestType for assist context: generate full AssistStructure for autofill. */
555 public static final int ASSIST_CONTEXT_AUTOFILL = 2;
Felipe Leme6d553872016-12-08 17:13:25 -0800556
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700557 /** @hide Flag for registerUidObserver: report changes in process state. */
558 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
559
560 /** @hide Flag for registerUidObserver: report uid gone. */
561 public static final int UID_OBSERVER_GONE = 1<<1;
562
563 /** @hide Flag for registerUidObserver: report uid has become idle. */
564 public static final int UID_OBSERVER_IDLE = 1<<2;
565
566 /** @hide Flag for registerUidObserver: report uid has become active. */
567 public static final int UID_OBSERVER_ACTIVE = 1<<3;
568
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700569 /** @hide Flag for registerUidObserver: report uid cached state has changed. */
570 public static final int UID_OBSERVER_CACHED = 1<<4;
571
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800572 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700573 public static final int APP_START_MODE_NORMAL = 0;
574
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800575 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700576 public static final int APP_START_MODE_DELAYED = 1;
577
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800578 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later, with
Dianne Hackborn85e35642017-01-12 15:10:57 -0800579 * rigid errors (throwing exception). */
580 public static final int APP_START_MODE_DELAYED_RIGID = 2;
581
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800582 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: disable/cancel pending
Dianne Hackborn85e35642017-01-12 15:10:57 -0800583 * launches; this is the mode for ephemeral apps. */
584 public static final int APP_START_MODE_DISABLED = 3;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700585
Benjamin Franz43261142015-02-11 15:59:44 +0000586 /**
587 * Lock task mode is not active.
588 */
589 public static final int LOCK_TASK_MODE_NONE = 0;
590
591 /**
592 * Full lock task mode is active.
593 */
594 public static final int LOCK_TASK_MODE_LOCKED = 1;
595
596 /**
597 * App pinning mode is active.
598 */
599 public static final int LOCK_TASK_MODE_PINNED = 2;
600
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700601 Point mAppTaskThumbnailSize;
602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 /*package*/ ActivityManager(Context context, Handler handler) {
604 mContext = context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 }
606
607 /**
Bryce Lee7f936862017-05-09 15:33:18 -0700608 * Returns whether the launch was successful.
609 * @hide
610 */
611 public static final boolean isStartResultSuccessful(int result) {
612 return FIRST_START_SUCCESS_CODE <= result && result <= LAST_START_SUCCESS_CODE;
613 }
614
615 /**
616 * Returns whether the launch result was a fatal error.
617 * @hide
618 */
619 public static final boolean isStartResultFatalError(int result) {
620 return FIRST_START_FATAL_ERROR_CODE <= result && result <= LAST_START_FATAL_ERROR_CODE;
621 }
622
623 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700624 * Screen compatibility mode: the application most always run in
625 * compatibility mode.
626 * @hide
627 */
628 public static final int COMPAT_MODE_ALWAYS = -1;
629
630 /**
631 * Screen compatibility mode: the application can never run in
632 * compatibility mode.
633 * @hide
634 */
635 public static final int COMPAT_MODE_NEVER = -2;
636
637 /**
638 * Screen compatibility mode: unknown.
639 * @hide
640 */
641 public static final int COMPAT_MODE_UNKNOWN = -3;
642
643 /**
644 * Screen compatibility mode: the application currently has compatibility
645 * mode disabled.
646 * @hide
647 */
648 public static final int COMPAT_MODE_DISABLED = 0;
649
650 /**
651 * Screen compatibility mode: the application currently has compatibility
652 * mode enabled.
653 * @hide
654 */
655 public static final int COMPAT_MODE_ENABLED = 1;
656
657 /**
658 * Screen compatibility mode: request to toggle the application's
659 * compatibility mode.
660 * @hide
661 */
662 public static final int COMPAT_MODE_TOGGLE = 2;
663
Marc Hittinger17fb5962017-04-05 15:34:38 -0700664 private static final boolean DEVELOPMENT_FORCE_LOW_RAM =
665 SystemProperties.getBoolean("debug.force_low_ram", false);
666
Wale Ogunwale3797c222015-10-27 14:21:58 -0700667 /** @hide */
668 public static class StackId {
669 /** Invalid stack ID. */
670 public static final int INVALID_STACK_ID = -1;
Chong Zhang5dcb2752015-08-18 13:50:26 -0700671
Wale Ogunwale3797c222015-10-27 14:21:58 -0700672 /** First static stack ID. */
673 public static final int FIRST_STATIC_STACK_ID = 0;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700674
Wale Ogunwale3797c222015-10-27 14:21:58 -0700675 /** Home activity stack ID. */
676 public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700677
Wale Ogunwale3797c222015-10-27 14:21:58 -0700678 /** ID of stack where fullscreen activities are normally launched into. */
679 public static final int FULLSCREEN_WORKSPACE_STACK_ID = 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700680
Wale Ogunwale3797c222015-10-27 14:21:58 -0700681 /** ID of stack where freeform/resized activities are normally launched into. */
682 public static final int FREEFORM_WORKSPACE_STACK_ID = FULLSCREEN_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700683
Wale Ogunwale3797c222015-10-27 14:21:58 -0700684 /** ID of stack that occupies a dedicated region of the screen. */
685 public static final int DOCKED_STACK_ID = FREEFORM_WORKSPACE_STACK_ID + 1;
Wale Ogunwaleb34a7ad2015-08-14 11:05:30 -0700686
Wale Ogunwale3797c222015-10-27 14:21:58 -0700687 /** ID of stack that always on top (always visible) when it exist. */
688 public static final int PINNED_STACK_ID = DOCKED_STACK_ID + 1;
Wale Ogunwale99db1862015-10-23 20:08:22 -0700689
Winson Chung83471632016-12-13 11:02:12 -0800690 /** ID of stack that contains the Recents activity. */
Matthew Ngae1ff4f2016-11-10 15:49:14 -0800691 public static final int RECENTS_STACK_ID = PINNED_STACK_ID + 1;
692
Winson Chung83471632016-12-13 11:02:12 -0800693 /** ID of stack that contains activities launched by the assistant. */
694 public static final int ASSISTANT_STACK_ID = RECENTS_STACK_ID + 1;
695
Wale Ogunwale3797c222015-10-27 14:21:58 -0700696 /** Last static stack stack ID. */
Winson Chung83471632016-12-13 11:02:12 -0800697 public static final int LAST_STATIC_STACK_ID = ASSISTANT_STACK_ID;
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700698
Wale Ogunwale3797c222015-10-27 14:21:58 -0700699 /** Start of ID range used by stacks that are created dynamically. */
700 public static final int FIRST_DYNAMIC_STACK_ID = LAST_STATIC_STACK_ID + 1;
701
702 public static boolean isStaticStack(int stackId) {
703 return stackId >= FIRST_STATIC_STACK_ID && stackId <= LAST_STATIC_STACK_ID;
704 }
705
Andrii Kulian4ede3e02017-01-12 11:52:31 -0800706 public static boolean isDynamicStack(int stackId) {
707 return stackId >= FIRST_DYNAMIC_STACK_ID;
708 }
709
Wale Ogunwale3797c222015-10-27 14:21:58 -0700710 /**
711 * Returns true if the activities contained in the input stack display a shadow around
712 * their border.
713 */
714 public static boolean hasWindowShadow(int stackId) {
715 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID;
716 }
717
718 /**
719 * Returns true if the activities contained in the input stack display a decor view.
720 */
721 public static boolean hasWindowDecor(int stackId) {
722 return stackId == FREEFORM_WORKSPACE_STACK_ID;
723 }
724
725 /**
726 * Returns true if the tasks contained in the stack can be resized independently of the
727 * stack.
728 */
729 public static boolean isTaskResizeAllowed(int stackId) {
730 return stackId == FREEFORM_WORKSPACE_STACK_ID;
731 }
732
Wale Ogunwale807d8822015-12-15 17:05:09 -0800733 /** Returns true if the task bounds should persist across power cycles. */
Wale Ogunwale3797c222015-10-27 14:21:58 -0700734 public static boolean persistTaskBounds(int stackId) {
Wale Ogunwale807d8822015-12-15 17:05:09 -0800735 return stackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700736 }
737
738 /**
739 * Returns true if dynamic stacks are allowed to be visible behind the input stack.
740 */
741 public static boolean isDynamicStacksVisibleBehindAllowed(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800742 return stackId == PINNED_STACK_ID || stackId == ASSISTANT_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700743 }
744
745 /**
746 * Returns true if we try to maintain focus in the current stack when the top activity
747 * finishes.
748 */
749 public static boolean keepFocusInStackIfPossible(int stackId) {
750 return stackId == FREEFORM_WORKSPACE_STACK_ID
751 || stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID;
752 }
753
754 /**
755 * Returns true if Stack size is affected by the docked stack changing size.
756 */
757 public static boolean isResizeableByDockedStack(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800758 return isStaticStack(stackId) && stackId != DOCKED_STACK_ID
759 && stackId != PINNED_STACK_ID && stackId != ASSISTANT_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700760 }
761
762 /**
763 * Returns true if the size of tasks in the input stack are affected by the docked stack
764 * changing size.
765 */
766 public static boolean isTaskResizeableByDockedStack(int stackId) {
767 return isStaticStack(stackId) && stackId != FREEFORM_WORKSPACE_STACK_ID
Winson Chung83471632016-12-13 11:02:12 -0800768 && stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID
769 && stackId != ASSISTANT_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700770 }
771
772 /**
Winson Chung2af04b32017-01-24 16:21:13 -0800773 * Returns true if the input stack is affected by drag resizing.
774 */
775 public static boolean isStackAffectedByDragResizing(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800776 return isStaticStack(stackId) && stackId != PINNED_STACK_ID
777 && stackId != ASSISTANT_STACK_ID;
Winson Chung2af04b32017-01-24 16:21:13 -0800778 }
779
780 /**
Jorim Jaggie9098022016-01-27 19:29:40 -0800781 * Returns true if the windows of tasks being moved to the target stack from the source
782 * stack should be replaced, meaning that window manager will keep the old window around
783 * until the new is ready.
Wale Ogunwale3797c222015-10-27 14:21:58 -0700784 */
Jorim Jaggie9098022016-01-27 19:29:40 -0800785 public static boolean replaceWindowsOnTaskMove(int sourceStackId, int targetStackId) {
786 return sourceStackId == FREEFORM_WORKSPACE_STACK_ID
787 || targetStackId == FREEFORM_WORKSPACE_STACK_ID;
Wale Ogunwale3797c222015-10-27 14:21:58 -0700788 }
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800789
790 /**
Robert Carre6275582016-02-29 15:45:45 -0800791 * Return whether a stackId is a stack containing floating windows. Floating windows
792 * are laid out differently as they are allowed to extend past the display bounds
793 * without overscan insets.
794 */
795 public static boolean tasksAreFloating(int stackId) {
796 return stackId == FREEFORM_WORKSPACE_STACK_ID
797 || stackId == PINNED_STACK_ID;
798 }
799
800 /**
Winson Chung83471632016-12-13 11:02:12 -0800801 * Return whether a stackId is a stack that be a backdrop to a translucent activity. These
802 * are generally fullscreen stacks.
803 */
804 public static boolean isBackdropToTranslucentActivity(int stackId) {
805 return stackId == FULLSCREEN_WORKSPACE_STACK_ID
806 || stackId == ASSISTANT_STACK_ID;
807 }
808
809 /**
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800810 * Returns true if animation specs should be constructed for app transition that moves
811 * the task to the specified stack.
812 */
813 public static boolean useAnimationSpecForAppTransition(int stackId) {
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800814 // TODO: INVALID_STACK_ID is also animated because we don't persist stack id's across
815 // reboots.
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800816 return stackId == FREEFORM_WORKSPACE_STACK_ID
Winson Chung83471632016-12-13 11:02:12 -0800817 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
818 || stackId == ASSISTANT_STACK_ID
819 || stackId == DOCKED_STACK_ID
Jorim Jaggi8a5c6402016-02-12 16:55:18 -0800820 || stackId == INVALID_STACK_ID;
Filip Gruszczynski96daf322015-11-18 18:01:27 -0800821 }
Wale Ogunwaled045c822015-12-02 09:14:28 -0800822
Winson Chung83471632016-12-13 11:02:12 -0800823 /**
824 * Returns true if the windows in the stack can receive input keys.
825 */
Wale Ogunwaled045c822015-12-02 09:14:28 -0800826 public static boolean canReceiveKeys(int stackId) {
827 return stackId != PINNED_STACK_ID;
828 }
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800829
Chong Zhang75b37202015-12-04 14:16:36 -0800830 /**
831 * Returns true if the stack can be visible above lockscreen.
832 */
833 public static boolean isAllowedOverLockscreen(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800834 return stackId == HOME_STACK_ID || stackId == FULLSCREEN_WORKSPACE_STACK_ID ||
835 stackId == ASSISTANT_STACK_ID;
836 }
837
838 /**
839 * Returns true if activities from stasks in the given {@param stackId} are allowed to
840 * enter picture-in-picture.
841 */
842 public static boolean isAllowedToEnterPictureInPicture(int stackId) {
843 return stackId != HOME_STACK_ID && stackId != ASSISTANT_STACK_ID &&
844 stackId != RECENTS_STACK_ID;
Chong Zhang75b37202015-12-04 14:16:36 -0800845 }
846
Filip Gruszczynski114d5ca2015-12-04 09:05:00 -0800847 public static boolean isAlwaysOnTop(int stackId) {
848 return stackId == PINNED_STACK_ID;
849 }
Wale Ogunwalef81c1d12016-01-12 12:20:18 -0800850
851 /**
852 * Returns true if the top task in the task is allowed to return home when finished and
853 * there are other tasks in the stack.
854 */
855 public static boolean allowTopTaskToReturnHome(int stackId) {
856 return stackId != PINNED_STACK_ID;
857 }
Wale Ogunwalecacfaa22016-01-15 11:26:08 -0800858
859 /**
860 * Returns true if the stack should be resized to match the bounds specified by
861 * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack.
862 */
863 public static boolean resizeStackWithLaunchBounds(int stackId) {
864 return stackId == PINNED_STACK_ID;
865 }
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -0800866
867 /**
868 * Returns true if any visible windows belonging to apps in this stack should be kept on
869 * screen when the app is killed due to something like the low memory killer.
870 */
871 public static boolean keepVisibleDeadAppWindowOnScreen(int stackId) {
872 return stackId != PINNED_STACK_ID;
873 }
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800874
875 /**
876 * Returns true if the backdrop on the client side should match the frame of the window.
877 * Returns false, if the backdrop should be fullscreen.
878 */
879 public static boolean useWindowFrameForBackdrop(int stackId) {
880 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID;
881 }
Jorim Jaggi86905582016-02-09 21:36:09 -0800882
883 /**
884 * Returns true if a window from the specified stack with {@param stackId} are normally
885 * fullscreen, i. e. they can become the top opaque fullscreen window, meaning that it
886 * controls system bars, lockscreen occluded/dismissing state, screen rotation animation,
887 * etc.
888 */
889 public static boolean normallyFullscreenWindows(int stackId) {
890 return stackId != PINNED_STACK_ID && stackId != FREEFORM_WORKSPACE_STACK_ID
891 && stackId != DOCKED_STACK_ID;
892 }
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800893
894 /**
895 * Returns true if the input stack id should only be present on a device that supports
896 * multi-window mode.
897 * @see android.app.ActivityManager#supportsMultiWindow
898 */
899 public static boolean isMultiWindowStack(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800900 return stackId == PINNED_STACK_ID || stackId == FREEFORM_WORKSPACE_STACK_ID
901 || stackId == DOCKED_STACK_ID;
Wale Ogunwalefb1c8642016-03-02 08:28:08 -0800902 }
Wale Ogunwale43896cf2016-04-16 10:54:30 -0700903
904 /**
Matthew Ngae1ff4f2016-11-10 15:49:14 -0800905 * Returns true if the input {@param stackId} is HOME_STACK_ID or RECENTS_STACK_ID
906 */
907 public static boolean isHomeOrRecentsStack(int stackId) {
908 return stackId == HOME_STACK_ID || stackId == RECENTS_STACK_ID;
909 }
910
911 /**
Winson Chung83471632016-12-13 11:02:12 -0800912 * Returns true if this stack may be scaled without resizing, and windows within may need
913 * to be configured as such.
Robert Carr1b5ea722016-04-20 13:23:28 -0700914 */
915 public static boolean windowsAreScaleable(int stackId) {
916 return stackId == PINNED_STACK_ID;
917 }
Robert Carrc7294602016-05-13 11:32:05 -0700918
919 /**
Winson Chung83471632016-12-13 11:02:12 -0800920 * Returns true if windows in this stack should be given move animations by default.
Robert Carrc7294602016-05-13 11:32:05 -0700921 */
922 public static boolean hasMovementAnimations(int stackId) {
923 return stackId != PINNED_STACK_ID;
924 }
Wale Ogunwale51362492016-09-08 17:49:17 -0700925
926 /** Returns true if the input stack and its content can affect the device orientation. */
927 public static boolean canSpecifyOrientation(int stackId) {
Winson Chung83471632016-12-13 11:02:12 -0800928 return stackId == HOME_STACK_ID
929 || stackId == RECENTS_STACK_ID
930 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
931 || stackId == ASSISTANT_STACK_ID
932 || isDynamicStack(stackId);
Wale Ogunwale51362492016-09-08 17:49:17 -0700933 }
Wale Ogunwale3797c222015-10-27 14:21:58 -0700934 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700935
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700936 /**
937 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
938 * specifies the position of the created docked stack at the top half of the screen if
939 * in portrait mode or at the left half of the screen if in landscape mode.
940 * @hide
941 */
942 public static final int DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT = 0;
943
944 /**
945 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which
946 * specifies the position of the created docked stack at the bottom half of the screen if
947 * in portrait mode or at the right half of the screen if in landscape mode.
948 * @hide
949 */
950 public static final int DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT = 1;
951
Chong Zhang87b21722015-09-21 15:39:51 -0700952 /**
953 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700954 * that the resize doesn't need to preserve the window, and can be skipped if bounds
955 * is unchanged. This mode is used by window manager in most cases.
Chong Zhang87b21722015-09-21 15:39:51 -0700956 * @hide
957 */
958 public static final int RESIZE_MODE_SYSTEM = 0;
959
960 /**
961 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700962 * that the resize should preserve the window if possible.
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700963 * @hide
964 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700965 public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0);
Chong Zhang87b21722015-09-21 15:39:51 -0700966
967 /**
968 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
969 * that the resize should be performed even if the bounds appears unchanged.
970 * @hide
971 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700972 public static final int RESIZE_MODE_FORCED = (0x1 << 1);
973
974 /**
975 * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window
976 * manager during a screen rotation.
977 * @hide
978 */
979 public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW;
980
981 /**
982 * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the
983 * resize is due to a drag action.
984 * @hide
985 */
986 public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW;
987
988 /**
989 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
990 * that the resize should preserve the window if possible, and should not be skipped
991 * even if the bounds is unchanged. Usually used to force a resizing when a drag action
992 * is ending.
993 * @hide
994 */
995 public static final int RESIZE_MODE_USER_FORCED =
996 RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED;
Chong Zhang87b21722015-09-21 15:39:51 -0700997
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700998 /** @hide */
999 public int getFrontActivityScreenCompatMode() {
1000 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001001 return getService().getFrontActivityScreenCompatMode();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001002 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001003 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001004 }
1005 }
1006
Dianne Hackborndf9799f2011-05-12 15:16:33 -07001007 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001008 public void setFrontActivityScreenCompatMode(int mode) {
1009 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001010 getService().setFrontActivityScreenCompatMode(mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001011 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001012 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001013 }
1014 }
1015
Dianne Hackborndf9799f2011-05-12 15:16:33 -07001016 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001017 public int getPackageScreenCompatMode(String packageName) {
1018 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001019 return getService().getPackageScreenCompatMode(packageName);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001020 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001021 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001022 }
1023 }
1024
Dianne Hackborndf9799f2011-05-12 15:16:33 -07001025 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001026 public void setPackageScreenCompatMode(String packageName, int mode) {
1027 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001028 getService().setPackageScreenCompatMode(packageName, mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001029 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001030 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001031 }
1032 }
1033
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001034 /** @hide */
1035 public boolean getPackageAskScreenCompat(String packageName) {
1036 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001037 return getService().getPackageAskScreenCompat(packageName);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001038 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001039 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001040 }
1041 }
1042
1043 /** @hide */
1044 public void setPackageAskScreenCompat(String packageName, boolean ask) {
1045 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001046 getService().setPackageAskScreenCompat(packageName, ask);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001047 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001048 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -07001049 }
1050 }
1051
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -07001052 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001053 * Return the approximate per-application memory class of the current
1054 * device. This gives you an idea of how hard a memory limit you should
1055 * impose on your application to let the overall system work best. The
1056 * returned value is in megabytes; the baseline Android memory class is
1057 * 16 (which happens to be the Java heap limit of those devices); some
1058 * device with more memory may return 24 or even higher numbers.
1059 */
1060 public int getMemoryClass() {
1061 return staticGetMemoryClass();
1062 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001063
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001064 /** @hide */
1065 static public int staticGetMemoryClass() {
1066 // Really brain dead right now -- just take this from the configured
1067 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -08001068 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -08001069 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
1070 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
1071 }
1072 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -08001073 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001074
Dianne Hackborn4e24aac2010-12-23 11:43:46 -08001075 /**
1076 * Return the approximate per-application memory class of the current
1077 * device when an application is running with a large heap. This is the
1078 * space available for memory-intensive applications; most applications
1079 * should not need this amount of memory, and should instead stay with the
1080 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
1081 * This may be the same size as {@link #getMemoryClass()} on memory
1082 * constrained devices, or it may be significantly larger on devices with
1083 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -08001084 *
1085 * <p>The is the size of the application's Dalvik heap if it has
1086 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -08001087 */
1088 public int getLargeMemoryClass() {
1089 return staticGetLargeMemoryClass();
1090 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001091
Dianne Hackborn4e24aac2010-12-23 11:43:46 -08001092 /** @hide */
1093 static public int staticGetLargeMemoryClass() {
1094 // Really brain dead right now -- just take this from the configured
1095 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001096 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -07001097 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001098 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -07001099
1100 /**
1101 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
1102 * is ultimately up to the device configuration, but currently it generally means
1103 * something in the class of a 512MB device with about a 800x480 or less screen.
1104 * This is mostly intended to be used by apps to determine whether they should turn
1105 * off certain features that require more RAM.
1106 */
1107 public boolean isLowRamDevice() {
1108 return isLowRamDeviceStatic();
1109 }
1110
1111 /** @hide */
1112 public static boolean isLowRamDeviceStatic() {
Marc Hittinger17fb5962017-04-05 15:34:38 -07001113 return RoSystemProperties.CONFIG_LOW_RAM ||
1114 (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
Dianne Hackbornb4e12492013-06-26 15:08:19 -07001115 }
1116
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -07001117 /**
Michael Kwan15eb9982017-04-14 12:34:46 -07001118 * Returns true if this is a small battery device. Exactly whether a device is considered to be
1119 * small battery is ultimately up to the device configuration, but currently it generally means
1120 * something in the class of a device with 1000 mAh or less. This is mostly intended to be used
1121 * to determine whether certain features should be altered to account for a drastically smaller
1122 * battery.
1123 * @hide
1124 */
1125 public static boolean isSmallBatteryDevice() {
1126 return RoSystemProperties.CONFIG_SMALL_BATTERY;
1127 }
1128
1129 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -07001130 * Used by persistent processes to determine if they are running on a
1131 * higher-end device so should be okay using hardware drawing acceleration
1132 * (which tends to consume a lot more RAM).
1133 * @hide
1134 */
Jeff Brown98365d72012-08-19 20:30:52 -07001135 static public boolean isHighEndGfx() {
Dianne Hackbornb4e12492013-06-26 15:08:19 -07001136 return !isLowRamDeviceStatic() &&
1137 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -07001138 }
1139
1140 /**
Dianne Hackborn852975d2014-08-22 17:42:43 -07001141 * Return the maximum number of recents entries that we will maintain and show.
1142 * @hide
1143 */
1144 static public int getMaxRecentTasksStatic() {
1145 if (gMaxRecentTasks < 0) {
Winson7c402912016-05-10 13:59:36 -07001146 return gMaxRecentTasks = isLowRamDeviceStatic() ? 36 : 48;
Dianne Hackborn852975d2014-08-22 17:42:43 -07001147 }
1148 return gMaxRecentTasks;
1149 }
1150
1151 /**
1152 * Return the default limit on the number of recents that an app can make.
1153 * @hide
1154 */
1155 static public int getDefaultAppRecentsLimitStatic() {
1156 return getMaxRecentTasksStatic() / 6;
1157 }
1158
1159 /**
1160 * Return the maximum limit on the number of recents that an app can make.
1161 * @hide
1162 */
1163 static public int getMaxAppRecentsLimitStatic() {
1164 return getMaxRecentTasksStatic() / 2;
1165 }
1166
1167 /**
Wale Ogunwalefb1c8642016-03-02 08:28:08 -08001168 * Returns true if the system supports at least one form of multi-window.
1169 * E.g. freeform, split-screen, picture-in-picture.
1170 * @hide
1171 */
Erik Wolsheimer9be3a062017-05-31 14:59:57 -07001172 static public boolean supportsMultiWindow(Context context) {
1173 // On watches, multi-window is used to present essential system UI, and thus it must be
1174 // supported regardless of device memory characteristics.
1175 boolean isWatch = context.getPackageManager().hasSystemFeature(
1176 PackageManager.FEATURE_WATCH);
1177 return (!isLowRamDeviceStatic() || isWatch)
Wale Ogunwalefb1c8642016-03-02 08:28:08 -08001178 && Resources.getSystem().getBoolean(
1179 com.android.internal.R.bool.config_supportsMultiWindow);
1180 }
1181
1182 /**
Matthew Ng626e0cc2016-12-07 17:25:53 -08001183 * Returns true if the system supports split screen multi-window.
1184 * @hide
1185 */
Erik Wolsheimer9be3a062017-05-31 14:59:57 -07001186 static public boolean supportsSplitScreenMultiWindow(Context context) {
1187 return supportsMultiWindow(context)
Matthew Ng626e0cc2016-12-07 17:25:53 -08001188 && Resources.getSystem().getBoolean(
1189 com.android.internal.R.bool.config_supportsSplitScreenMultiWindow);
1190 }
1191
Jeff Sharkey000ce802017-04-29 13:13:27 -06001192 /** @removed */
Winson Chung709904f2017-04-25 11:00:48 -07001193 @Deprecated
Winson Chunga29eb982016-12-14 12:01:27 -08001194 public static int getMaxNumPictureInPictureActions() {
Winson Chung709904f2017-04-25 11:00:48 -07001195 return 3;
Winson Chunga29eb982016-12-14 12:01:27 -08001196 }
1197
1198 /**
Winson Chung1147c402014-05-14 11:05:00 -07001199 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -07001200 */
Winson Chunga449dc02014-05-16 11:15:04 -07001201 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -07001202 /** @hide */
1203 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
1204 private static final String ATTR_TASKDESCRIPTIONLABEL =
1205 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +00001206 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -07001207 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +00001208 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
1209 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Craig Mautner648f69b2014-09-18 14:16:26 -07001210 private static final String ATTR_TASKDESCRIPTIONICONFILENAME =
1211 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
1212
Winson Chunga449dc02014-05-16 11:15:04 -07001213 private String mLabel;
1214 private Bitmap mIcon;
Craig Mautner648f69b2014-09-18 14:16:26 -07001215 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001216 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +00001217 private int mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001218 private int mStatusBarColor;
1219 private int mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001220
1221 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001222 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001223 *
Winson Chunga449dc02014-05-16 11:15:04 -07001224 * @param label A label and description of the current state of this task.
1225 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +00001226 * @param colorPrimary A color to override the theme's primary color. This color must be
1227 * opaque.
Winson Chung03a9bae2014-05-02 09:56:12 -07001228 */
Winson Chunga449dc02014-05-16 11:15:04 -07001229 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001230 this(label, icon, null, colorPrimary, 0, 0, 0);
Winson Chunga449dc02014-05-16 11:15:04 -07001231 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1232 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1233 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001234 }
1235
Winson Chung03a9bae2014-05-02 09:56:12 -07001236 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001237 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001238 *
1239 * @param label A label and description of the current state of this activity.
1240 * @param icon An icon that represents the current state of this activity.
1241 */
Winson Chunga449dc02014-05-16 11:15:04 -07001242 public TaskDescription(String label, Bitmap icon) {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001243 this(label, icon, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001244 }
1245
1246 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001247 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001248 *
1249 * @param label A label and description of the current state of this activity.
1250 */
Winson Chunga449dc02014-05-16 11:15:04 -07001251 public TaskDescription(String label) {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001252 this(label, null, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001253 }
1254
Winson Chunga449dc02014-05-16 11:15:04 -07001255 /**
1256 * Creates an empty TaskDescription.
1257 */
1258 public TaskDescription() {
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001259 this(null, null, null, 0, 0, 0, 0);
Winson Chung1af8eda2016-02-05 17:55:56 +00001260 }
1261
1262 /** @hide */
1263 public TaskDescription(String label, Bitmap icon, String iconFilename, int colorPrimary,
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001264 int colorBackground, int statusBarColor, int navigationBarColor) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001265 mLabel = label;
1266 mIcon = icon;
1267 mIconFilename = iconFilename;
1268 mColorPrimary = colorPrimary;
1269 mColorBackground = colorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001270 mStatusBarColor = statusBarColor;
1271 mNavigationBarColor = navigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001272 }
1273
Winson Chunga449dc02014-05-16 11:15:04 -07001274 /**
1275 * Creates a copy of another TaskDescription.
1276 */
1277 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -08001278 copyFrom(td);
1279 }
1280
1281 /**
1282 * Copies this the values from another TaskDescription.
1283 * @hide
1284 */
1285 public void copyFrom(TaskDescription other) {
1286 mLabel = other.mLabel;
1287 mIcon = other.mIcon;
1288 mIconFilename = other.mIconFilename;
1289 mColorPrimary = other.mColorPrimary;
1290 mColorBackground = other.mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001291 mStatusBarColor = other.mStatusBarColor;
1292 mNavigationBarColor = other.mNavigationBarColor;
Winson Chunga449dc02014-05-16 11:15:04 -07001293 }
1294
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001295 /**
1296 * Copies this the values from another TaskDescription, but preserves the hidden fields
1297 * if they weren't set on {@code other}
1298 * @hide
1299 */
1300 public void copyFromPreserveHiddenFields(TaskDescription other) {
1301 mLabel = other.mLabel;
1302 mIcon = other.mIcon;
1303 mIconFilename = other.mIconFilename;
1304 mColorPrimary = other.mColorPrimary;
1305 if (other.mColorBackground != 0) {
1306 mColorBackground = other.mColorBackground;
1307 }
1308 if (other.mStatusBarColor != 0) {
1309 mStatusBarColor = other.mStatusBarColor;
1310 }
1311 if (other.mNavigationBarColor != 0) {
1312 mNavigationBarColor = other.mNavigationBarColor;
1313 }
1314 }
1315
Winson Chunga449dc02014-05-16 11:15:04 -07001316 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001317 readFromParcel(source);
1318 }
1319
1320 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001321 * Sets the label for this task description.
1322 * @hide
1323 */
1324 public void setLabel(String label) {
1325 mLabel = label;
1326 }
1327
1328 /**
1329 * Sets the primary color for this task description.
1330 * @hide
1331 */
1332 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001333 // Ensure that the given color is valid
1334 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1335 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1336 }
1337 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001338 }
1339
1340 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001341 * Sets the background color for this task description.
1342 * @hide
1343 */
1344 public void setBackgroundColor(int backgroundColor) {
1345 // Ensure that the given color is valid
1346 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1347 throw new RuntimeException("A TaskDescription's background color should be opaque");
1348 }
1349 mColorBackground = backgroundColor;
1350 }
1351
1352 /**
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001353 * @hide
1354 */
1355 public void setStatusBarColor(int statusBarColor) {
1356 mStatusBarColor = statusBarColor;
1357 }
1358
1359 /**
1360 * @hide
1361 */
1362 public void setNavigationBarColor(int navigationBarColor) {
1363 mNavigationBarColor = navigationBarColor;
1364 }
1365
1366 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001367 * Sets the icon for this task description.
1368 * @hide
1369 */
1370 public void setIcon(Bitmap icon) {
1371 mIcon = icon;
1372 }
1373
1374 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001375 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1376 * bitmap.
1377 * @hide
1378 */
1379 public void setIconFilename(String iconFilename) {
1380 mIconFilename = iconFilename;
1381 mIcon = null;
1382 }
1383
1384 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001385 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001386 */
Winson Chunga449dc02014-05-16 11:15:04 -07001387 public String getLabel() {
1388 return mLabel;
1389 }
1390
1391 /**
1392 * @return The icon that represents the current state of this task.
1393 */
1394 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001395 if (mIcon != null) {
1396 return mIcon;
1397 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001398 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001399 }
1400
1401 /** @hide */
1402 public String getIconFilename() {
1403 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001404 }
1405
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001406 /** @hide */
1407 public Bitmap getInMemoryIcon() {
1408 return mIcon;
1409 }
1410
1411 /** @hide */
Suprabh Shukla23593142015-11-03 17:31:15 -08001412 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001413 if (iconFilename != null) {
1414 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001415 return getService().getTaskDescriptionIcon(iconFilename,
Winson Chung1af8eda2016-02-05 17:55:56 +00001416 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001417 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001418 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001419 }
1420 }
1421 return null;
1422 }
1423
Winson Chunga449dc02014-05-16 11:15:04 -07001424 /**
1425 * @return The color override on the theme's primary color.
1426 */
1427 public int getPrimaryColor() {
1428 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001429 }
1430
Winson Chung1af8eda2016-02-05 17:55:56 +00001431 /**
1432 * @return The background color.
1433 * @hide
1434 */
1435 public int getBackgroundColor() {
1436 return mColorBackground;
1437 }
1438
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001439 /**
1440 * @hide
1441 */
1442 public int getStatusBarColor() {
1443 return mStatusBarColor;
1444 }
1445
1446 /**
1447 * @hide
1448 */
1449 public int getNavigationBarColor() {
1450 return mNavigationBarColor;
1451 }
1452
Craig Mautner648f69b2014-09-18 14:16:26 -07001453 /** @hide */
1454 public void saveToXml(XmlSerializer out) throws IOException {
1455 if (mLabel != null) {
1456 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1457 }
1458 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001459 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1460 Integer.toHexString(mColorPrimary));
1461 }
1462 if (mColorBackground != 0) {
1463 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1464 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001465 }
1466 if (mIconFilename != null) {
1467 out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename);
1468 }
1469 }
1470
1471 /** @hide */
1472 public void restoreFromXml(String attrName, String attrValue) {
1473 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1474 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001475 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001476 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001477 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1478 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Craig Mautner648f69b2014-09-18 14:16:26 -07001479 } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) {
1480 setIconFilename(attrValue);
1481 }
1482 }
1483
Winson Chung03a9bae2014-05-02 09:56:12 -07001484 @Override
1485 public int describeContents() {
1486 return 0;
1487 }
1488
1489 @Override
1490 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001491 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001492 dest.writeInt(0);
1493 } else {
1494 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001495 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001496 }
Winson Chunga449dc02014-05-16 11:15:04 -07001497 if (mIcon == null) {
1498 dest.writeInt(0);
1499 } else {
1500 dest.writeInt(1);
1501 mIcon.writeToParcel(dest, 0);
1502 }
1503 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001504 dest.writeInt(mColorBackground);
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001505 dest.writeInt(mStatusBarColor);
1506 dest.writeInt(mNavigationBarColor);
Craig Mautner648f69b2014-09-18 14:16:26 -07001507 if (mIconFilename == null) {
1508 dest.writeInt(0);
1509 } else {
1510 dest.writeInt(1);
1511 dest.writeString(mIconFilename);
1512 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001513 }
1514
1515 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001516 mLabel = source.readInt() > 0 ? source.readString() : null;
1517 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
1518 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001519 mColorBackground = source.readInt();
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001520 mStatusBarColor = source.readInt();
1521 mNavigationBarColor = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001522 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001523 }
1524
Winson Chunga449dc02014-05-16 11:15:04 -07001525 public static final Creator<TaskDescription> CREATOR
1526 = new Creator<TaskDescription>() {
1527 public TaskDescription createFromParcel(Parcel source) {
1528 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001529 }
Winson Chunga449dc02014-05-16 11:15:04 -07001530 public TaskDescription[] newArray(int size) {
1531 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001532 }
1533 };
1534
1535 @Override
1536 public String toString() {
Winson Chunga449dc02014-05-16 11:15:04 -07001537 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
Winson Chung1af8eda2016-02-05 17:55:56 +00001538 " IconFilename: " + mIconFilename + " colorPrimary: " + mColorPrimary +
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001539 " colorBackground: " + mColorBackground +
1540 " statusBarColor: " + mColorBackground +
1541 " navigationBarColor: " + mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001542 }
1543 }
1544
1545 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 * Information you can retrieve about tasks that the user has most recently
1547 * started or visited.
1548 */
1549 public static class RecentTaskInfo implements Parcelable {
1550 /**
1551 * If this task is currently running, this is the identifier for it.
1552 * If it is not running, this will be -1.
1553 */
1554 public int id;
1555
1556 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001557 * The true identifier of this task, valid even if it is not running.
1558 */
1559 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001560
Dianne Hackbornd94df452011-02-16 18:53:31 -08001561 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 * The original Intent used to launch the task. You can use this
1563 * Intent to re-launch the task (if it is no longer running) or bring
1564 * the current task to the front.
1565 */
1566 public Intent baseIntent;
1567
1568 /**
1569 * If this task was started from an alias, this is the actual
1570 * activity component that was initially started; the component of
1571 * the baseIntent in this case is the name of the actual activity
1572 * implementation that the alias referred to. Otherwise, this is null.
1573 */
1574 public ComponentName origActivity;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001575
1576 /**
James Cook4d0ef042015-07-09 14:28:23 -07001577 * The actual activity component that started the task.
1578 * @hide
1579 */
1580 @Nullable
1581 public ComponentName realActivity;
1582
1583 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001584 * Description of the task's last state.
1585 */
1586 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001587
1588 /**
1589 * The id of the ActivityStack this Task was on most recently.
Craig Mautner27030522013-08-26 12:25:36 -07001590 * @hide
Craig Mautner6d90fed2013-05-22 15:03:10 -07001591 */
1592 public int stackId;
1593
Kenny Guy82326a92014-03-17 17:16:06 +00001594 /**
Craig Mautner2fbd7542014-03-21 09:34:07 -07001595 * The id of the user the task was running as.
Kenny Guy82326a92014-03-17 17:16:06 +00001596 * @hide
1597 */
1598 public int userId;
1599
Craig Mautner2fbd7542014-03-21 09:34:07 -07001600 /**
Winson Chungffa2ec62014-07-03 15:54:42 -07001601 * The first time this task was active.
1602 * @hide
1603 */
1604 public long firstActiveTime;
1605
1606 /**
Winson Chungf1fbd772014-06-24 18:06:58 -07001607 * The last time this task was active.
1608 * @hide
1609 */
1610 public long lastActiveTime;
1611
1612 /**
Winson Chung03a9bae2014-05-02 09:56:12 -07001613 * The recent activity values for the highest activity in the stack to have set the values.
Winson Chunga449dc02014-05-16 11:15:04 -07001614 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
Craig Mautner2fbd7542014-03-21 09:34:07 -07001615 */
Winson Chunga449dc02014-05-16 11:15:04 -07001616 public TaskDescription taskDescription;
Craig Mautner2fbd7542014-03-21 09:34:07 -07001617
Craig Mautnera228ae92014-07-09 05:44:55 -07001618 /**
1619 * Task affiliation for grouping with other tasks.
Craig Mautnera228ae92014-07-09 05:44:55 -07001620 */
1621 public int affiliatedTaskId;
1622
Winson Chungec396d62014-08-06 17:08:00 -07001623 /**
1624 * Task affiliation color of the source task with the affiliated task id.
1625 *
1626 * @hide
1627 */
1628 public int affiliatedTaskColor;
1629
Wale Ogunwale6035e012015-04-14 15:54:10 -07001630 /**
1631 * The component launched as the first activity in the task.
1632 * This can be considered the "application" of this task.
1633 */
1634 public ComponentName baseActivity;
1635
1636 /**
1637 * The activity component at the top of the history stack of the task.
1638 * This is what the user is currently doing.
1639 */
1640 public ComponentName topActivity;
1641
1642 /**
1643 * Number of activities in this task.
1644 */
1645 public int numActivities;
1646
Winson2dd76942015-11-02 09:20:01 -08001647 /**
1648 * The bounds of the task.
1649 * @hide
1650 */
1651 public Rect bounds;
1652
Wale Ogunwale21b60582016-01-27 12:34:16 -08001653 /**
1654 * True if the task can go in the docked stack.
1655 * @hide
1656 */
Winson Chungd3395382016-12-13 11:49:09 -08001657 public boolean supportsSplitScreenMultiWindow;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001658
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001659 /**
1660 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1661 * @hide
1662 */
1663 public int resizeMode;
1664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 public RecentTaskInfo() {
1666 }
1667
Craig Mautner6d90fed2013-05-22 15:03:10 -07001668 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 public int describeContents() {
1670 return 0;
1671 }
1672
Craig Mautner6d90fed2013-05-22 15:03:10 -07001673 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 public void writeToParcel(Parcel dest, int flags) {
1675 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001676 dest.writeInt(persistentId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 if (baseIntent != null) {
1678 dest.writeInt(1);
1679 baseIntent.writeToParcel(dest, 0);
1680 } else {
1681 dest.writeInt(0);
1682 }
1683 ComponentName.writeToParcel(origActivity, dest);
James Cook4d0ef042015-07-09 14:28:23 -07001684 ComponentName.writeToParcel(realActivity, dest);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001685 TextUtils.writeToParcel(description, dest,
1686 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
Winson Chunga449dc02014-05-16 11:15:04 -07001687 if (taskDescription != null) {
Craig Mautner2fbd7542014-03-21 09:34:07 -07001688 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001689 taskDescription.writeToParcel(dest, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001690 } else {
1691 dest.writeInt(0);
Craig Mautner2fbd7542014-03-21 09:34:07 -07001692 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001693 dest.writeInt(stackId);
Kenny Guy82326a92014-03-17 17:16:06 +00001694 dest.writeInt(userId);
Winson Chungffa2ec62014-07-03 15:54:42 -07001695 dest.writeLong(firstActiveTime);
Winson Chungf1fbd772014-06-24 18:06:58 -07001696 dest.writeLong(lastActiveTime);
Craig Mautnera228ae92014-07-09 05:44:55 -07001697 dest.writeInt(affiliatedTaskId);
Winson Chungec396d62014-08-06 17:08:00 -07001698 dest.writeInt(affiliatedTaskColor);
Wale Ogunwale6035e012015-04-14 15:54:10 -07001699 ComponentName.writeToParcel(baseActivity, dest);
1700 ComponentName.writeToParcel(topActivity, dest);
1701 dest.writeInt(numActivities);
Winson2dd76942015-11-02 09:20:01 -08001702 if (bounds != null) {
1703 dest.writeInt(1);
1704 bounds.writeToParcel(dest, 0);
1705 } else {
1706 dest.writeInt(0);
1707 }
Winson Chungd3395382016-12-13 11:49:09 -08001708 dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001709 dest.writeInt(resizeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 }
1711
1712 public void readFromParcel(Parcel source) {
1713 id = source.readInt();
Dianne Hackbornd94df452011-02-16 18:53:31 -08001714 persistentId = source.readInt();
Craig Mautner688b5102014-03-27 16:55:03 -07001715 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 origActivity = ComponentName.readFromParcel(source);
James Cook4d0ef042015-07-09 14:28:23 -07001717 realActivity = ComponentName.readFromParcel(source);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001718 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Winson Chunga449dc02014-05-16 11:15:04 -07001719 taskDescription = source.readInt() > 0 ?
1720 TaskDescription.CREATOR.createFromParcel(source) : null;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001721 stackId = source.readInt();
Kenny Guy82326a92014-03-17 17:16:06 +00001722 userId = source.readInt();
Winson Chungffa2ec62014-07-03 15:54:42 -07001723 firstActiveTime = source.readLong();
Winson Chungf1fbd772014-06-24 18:06:58 -07001724 lastActiveTime = source.readLong();
Craig Mautnera228ae92014-07-09 05:44:55 -07001725 affiliatedTaskId = source.readInt();
Winson Chungec396d62014-08-06 17:08:00 -07001726 affiliatedTaskColor = source.readInt();
Wale Ogunwale6035e012015-04-14 15:54:10 -07001727 baseActivity = ComponentName.readFromParcel(source);
1728 topActivity = ComponentName.readFromParcel(source);
1729 numActivities = source.readInt();
Winson2dd76942015-11-02 09:20:01 -08001730 bounds = source.readInt() > 0 ?
1731 Rect.CREATOR.createFromParcel(source) : null;
Winson Chungd3395382016-12-13 11:49:09 -08001732 supportsSplitScreenMultiWindow = source.readInt() == 1;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001733 resizeMode = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001734 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 public static final Creator<RecentTaskInfo> CREATOR
1737 = new Creator<RecentTaskInfo>() {
1738 public RecentTaskInfo createFromParcel(Parcel source) {
1739 return new RecentTaskInfo(source);
1740 }
1741 public RecentTaskInfo[] newArray(int size) {
1742 return new RecentTaskInfo[size];
1743 }
1744 };
1745
1746 private RecentTaskInfo(Parcel source) {
1747 readFromParcel(source);
1748 }
1749 }
1750
1751 /**
1752 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1753 * that have set their
1754 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1755 */
1756 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001759 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001760 * recent tasks that currently are not available to the user.
1761 */
1762 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001763
1764 /**
Kenny Guy2a764942014-04-02 13:29:20 +01001765 * Provides a list that contains recent tasks for all
1766 * profiles of a user.
Kenny Guy82326a92014-03-17 17:16:06 +00001767 * @hide
1768 */
Kenny Guy2a764942014-04-02 13:29:20 +01001769 public static final int RECENT_INCLUDE_PROFILES = 0x0004;
Kenny Guy82326a92014-03-17 17:16:06 +00001770
1771 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001772 * Ignores all tasks that are on the home stack.
1773 * @hide
1774 */
Matthew Ngae1ff4f2016-11-10 15:49:14 -08001775 public static final int RECENT_IGNORE_HOME_AND_RECENTS_STACK_TASKS = 0x0008;
Winson Chunga4ccb862014-08-22 15:26:27 -07001776
1777 /**
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001778 * Ignores the top task in the docked stack.
Winson Chung0583d3d2015-12-18 10:03:12 -05001779 * @hide
1780 */
Wale Ogunwale64ae08a2016-03-28 08:15:27 -07001781 public static final int RECENT_INGORE_DOCKED_STACK_TOP_TASK = 0x0010;
Winson Chung0583d3d2015-12-18 10:03:12 -05001782
1783 /**
1784 * Ignores all tasks that are on the pinned stack.
1785 * @hide
1786 */
1787 public static final int RECENT_INGORE_PINNED_STACK_TASKS = 0x0020;
1788
1789 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001790 * <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 -08001791 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001792 *
1793 * <p><b>Note: this method is only intended for debugging and presenting
1794 * task management user interfaces</b>. This should never be used for
1795 * core logic in an application, such as deciding between different
1796 * behaviors based on the information found here. Such uses are
1797 * <em>not</em> supported, and will likely break in the future. For
1798 * example, if multiple applications can be actively running at the
1799 * same time, assumptions made about the meaning of the data here for
1800 * purposes of control flow will be incorrect.</p>
1801 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001802 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001803 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001804 * document-centric recents means
1805 * it can leak personal information to the caller. For backwards compatibility,
1806 * it will still return a small subset of its data: at least the caller's
1807 * own tasks (though see {@link #getAppTasks()} for the correct supported
1808 * way to retrieve that information), and possibly some other tasks
1809 * such as home that are known to not be sensitive.
1810 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 * @param maxNum The maximum number of entries to return in the list. The
1812 * actual number returned may be smaller, depending on how many tasks the
1813 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001814 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001815 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001816 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 * @return Returns a list of RecentTaskInfo records describing each of
1818 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001820 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1822 throws SecurityException {
1823 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001824 return getService().getRecentTasks(maxNum,
Jeff Sharkey479212c2016-06-29 16:00:55 -06001825 flags, UserHandle.myUserId()).getList();
Amith Yamasani82644082012-08-03 13:09:11 -07001826 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001827 throw e.rethrowFromSystemServer();
Amith Yamasani82644082012-08-03 13:09:11 -07001828 }
1829 }
1830
1831 /**
1832 * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a
1833 * specific user. It requires holding
1834 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
1835 * @param maxNum The maximum number of entries to return in the list. The
1836 * actual number returned may be smaller, depending on how many tasks the
1837 * user has started and the maximum number the system can remember.
1838 * @param flags Information about what to return. May be any combination
1839 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
1840 *
1841 * @return Returns a list of RecentTaskInfo records describing each of
Vadim Tryshev35605752015-08-31 13:28:08 -07001842 * the recent tasks. Most recently activated tasks go first.
Amith Yamasani82644082012-08-03 13:09:11 -07001843 *
Amith Yamasani82644082012-08-03 13:09:11 -07001844 * @hide
1845 */
1846 public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId)
1847 throws SecurityException {
1848 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001849 return getService().getRecentTasks(maxNum,
Jeff Sharkey479212c2016-06-29 16:00:55 -06001850 flags, userId).getList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001852 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 }
1854 }
1855
1856 /**
1857 * Information you can retrieve about a particular task that is currently
1858 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001859 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 * means that the user has gone to it and never closed it, but currently
1861 * the system may have killed its process and is only holding on to its
1862 * last state in order to restart it when the user returns.
1863 */
1864 public static class RunningTaskInfo implements Parcelable {
1865 /**
1866 * A unique identifier for this task.
1867 */
1868 public int id;
1869
1870 /**
Winson5510f6c2015-10-27 12:11:26 -07001871 * The stack that currently contains this task.
1872 * @hide
1873 */
1874 public int stackId;
1875
1876 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 * The component launched as the first activity in the task. This can
1878 * be considered the "application" of this task.
1879 */
1880 public ComponentName baseActivity;
1881
1882 /**
1883 * The activity component at the top of the history stack of the task.
1884 * This is what the user is currently doing.
1885 */
1886 public ComponentName topActivity;
1887
1888 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001889 * Thumbnail representation of the task's current state. Currently
1890 * always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 */
1892 public Bitmap thumbnail;
1893
1894 /**
1895 * Description of the task's current state.
1896 */
1897 public CharSequence description;
1898
1899 /**
1900 * Number of activities in this task.
1901 */
1902 public int numActivities;
1903
1904 /**
1905 * Number of activities that are currently running (not stopped
1906 * and persisted) in this task.
1907 */
1908 public int numRunning;
1909
Craig Mautnerc0fd8052013-09-19 11:20:17 -07001910 /**
1911 * Last time task was run. For sorting.
1912 * @hide
1913 */
1914 public long lastActiveTime;
1915
Wale Ogunwale21b60582016-01-27 12:34:16 -08001916 /**
1917 * True if the task can go in the docked stack.
1918 * @hide
1919 */
Winson Chungd3395382016-12-13 11:49:09 -08001920 public boolean supportsSplitScreenMultiWindow;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001921
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001922 /**
1923 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1924 * @hide
1925 */
1926 public int resizeMode;
1927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 public RunningTaskInfo() {
1929 }
1930
1931 public int describeContents() {
1932 return 0;
1933 }
1934
1935 public void writeToParcel(Parcel dest, int flags) {
1936 dest.writeInt(id);
Winson5510f6c2015-10-27 12:11:26 -07001937 dest.writeInt(stackId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 ComponentName.writeToParcel(baseActivity, dest);
1939 ComponentName.writeToParcel(topActivity, dest);
1940 if (thumbnail != null) {
1941 dest.writeInt(1);
1942 thumbnail.writeToParcel(dest, 0);
1943 } else {
1944 dest.writeInt(0);
1945 }
1946 TextUtils.writeToParcel(description, dest,
1947 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1948 dest.writeInt(numActivities);
1949 dest.writeInt(numRunning);
Winson Chungd3395382016-12-13 11:49:09 -08001950 dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001951 dest.writeInt(resizeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 }
1953
1954 public void readFromParcel(Parcel source) {
1955 id = source.readInt();
Winson5510f6c2015-10-27 12:11:26 -07001956 stackId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 baseActivity = ComponentName.readFromParcel(source);
1958 topActivity = ComponentName.readFromParcel(source);
1959 if (source.readInt() != 0) {
1960 thumbnail = Bitmap.CREATOR.createFromParcel(source);
1961 } else {
1962 thumbnail = null;
1963 }
1964 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
1965 numActivities = source.readInt();
1966 numRunning = source.readInt();
Winson Chungd3395382016-12-13 11:49:09 -08001967 supportsSplitScreenMultiWindow = source.readInt() != 0;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001968 resizeMode = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
1972 public RunningTaskInfo createFromParcel(Parcel source) {
1973 return new RunningTaskInfo(source);
1974 }
1975 public RunningTaskInfo[] newArray(int size) {
1976 return new RunningTaskInfo[size];
1977 }
1978 };
1979
1980 private RunningTaskInfo(Parcel source) {
1981 readFromParcel(source);
1982 }
1983 }
Winson Chung1147c402014-05-14 11:05:00 -07001984
1985 /**
1986 * Get the list of tasks associated with the calling application.
1987 *
1988 * @return The list of tasks associated with the application making this call.
1989 * @throws SecurityException
1990 */
1991 public List<ActivityManager.AppTask> getAppTasks() {
1992 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001993 List<IBinder> appTasks;
Winson Chung1147c402014-05-14 11:05:00 -07001994 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001995 appTasks = getService().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001996 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001997 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001998 }
1999 int numAppTasks = appTasks.size();
2000 for (int i = 0; i < numAppTasks; i++) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07002001 tasks.add(new AppTask(IAppTask.Stub.asInterface(appTasks.get(i))));
Winson Chung1147c402014-05-14 11:05:00 -07002002 }
2003 return tasks;
2004 }
2005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 /**
Winson Chung48a10a52014-08-27 14:36:51 -07002007 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002008 * with {@link #addAppTask}.
2009 */
Winson Chung48a10a52014-08-27 14:36:51 -07002010 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002011 synchronized (this) {
2012 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07002013 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002014 }
2015 }
2016
2017 private void ensureAppTaskThumbnailSizeLocked() {
2018 if (mAppTaskThumbnailSize == null) {
2019 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002020 mAppTaskThumbnailSize = getService().getAppTaskThumbnailSize();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002021 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002022 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002023 }
2024 }
2025 }
2026
2027 /**
2028 * Add a new {@link AppTask} for the calling application. This will create a new
2029 * recents entry that is added to the <b>end</b> of all existing recents.
2030 *
2031 * @param activity The activity that is adding the entry. This is used to help determine
2032 * the context that the new recents entry will be in.
2033 * @param intent The Intent that describes the recents entry. This is the same Intent that
2034 * you would have used to launch the activity for it. In generally you will want to set
2035 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
2036 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
2037 * entry will exist without an activity, so it doesn't make sense to not retain it when
2038 * its activity disappears. The given Intent here also must have an explicit ComponentName
2039 * set on it.
2040 * @param description Optional additional description information.
2041 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07002042 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
2043 * recreated in your process, probably in a way you don't like, before the recents entry
2044 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002045 *
2046 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
2047 * most likely cause of failure is that there is no more room for more tasks for your app.
2048 */
2049 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
2050 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
2051 Point size;
2052 synchronized (this) {
2053 ensureAppTaskThumbnailSizeLocked();
2054 size = mAppTaskThumbnailSize;
2055 }
2056 final int tw = thumbnail.getWidth();
2057 final int th = thumbnail.getHeight();
2058 if (tw != size.x || th != size.y) {
2059 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
2060
2061 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
2062 float scale;
2063 float dx = 0, dy = 0;
2064 if (tw * size.x > size.y * th) {
2065 scale = (float) size.x / (float) th;
2066 dx = (size.y - tw * scale) * 0.5f;
2067 } else {
2068 scale = (float) size.y / (float) tw;
2069 dy = (size.x - th * scale) * 0.5f;
2070 }
2071 Matrix matrix = new Matrix();
2072 matrix.setScale(scale, scale);
2073 matrix.postTranslate((int) (dx + 0.5f), 0);
2074
2075 Canvas canvas = new Canvas(bm);
2076 canvas.drawBitmap(thumbnail, matrix, null);
2077 canvas.setBitmap(null);
2078
2079 thumbnail = bm;
2080 }
2081 if (description == null) {
2082 description = new TaskDescription();
2083 }
2084 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002085 return getService().addAppTask(activity.getActivityToken(),
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002086 intent, description, thumbnail);
2087 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002088 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07002089 }
2090 }
2091
2092 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002093 * Return a list of the tasks that are currently running, with
2094 * the most recent being first and older ones after in order. Note that
2095 * "running" does not mean any of the task's code is currently loaded or
2096 * activity -- the task may have been frozen by the system, so that it
2097 * can be restarted in its previous state when next brought to the
2098 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07002099 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002100 * <p><b>Note: this method is only intended for debugging and presenting
2101 * task management user interfaces</b>. This should never be used for
2102 * core logic in an application, such as deciding between different
2103 * behaviors based on the information found here. Such uses are
2104 * <em>not</em> supported, and will likely break in the future. For
2105 * example, if multiple applications can be actively running at the
2106 * same time, assumptions made about the meaning of the data here for
2107 * purposes of control flow will be incorrect.</p>
2108 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07002109 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07002110 * is no longer available to third party
2111 * applications: the introduction of document-centric recents means
2112 * it can leak person information to the caller. For backwards compatibility,
Alan Stokes1e4e74a2017-08-02 11:17:37 +01002113 * it will still return a small subset of its data: at least the caller's
Dianne Hackborna25a8b22014-05-30 12:30:35 -07002114 * own tasks, and possibly some other tasks
2115 * such as home that are known to not be sensitive.
2116 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07002117 * @param maxNum The maximum number of entries to return in the list. The
2118 * actual number returned may be smaller, depending on how many tasks the
2119 * user has started.
2120 *
2121 * @return Returns a list of RunningTaskInfo records describing each of
2122 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07002123 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07002124 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07002125 public List<RunningTaskInfo> getRunningTasks(int maxNum)
2126 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07002127 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002128 return getService().getTasks(maxNum, 0);
Dianne Hackborn09233282014-04-30 11:33:59 -07002129 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002130 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07002131 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07002132 }
2133
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002134 /**
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002135 * Completely remove the given task.
2136 *
2137 * @param taskId Identifier of the task to be removed.
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002138 * @return Returns true if the given task was found and removed.
2139 *
2140 * @hide
2141 */
Wale Ogunwaled54b5782014-10-23 15:55:23 -07002142 public boolean removeTask(int taskId) throws SecurityException {
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002143 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002144 return getService().removeTask(taskId);
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002145 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002146 throw e.rethrowFromSystemServer();
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002147 }
2148 }
2149
Winsonc809cbb2015-11-02 12:06:15 -08002150 /**
2151 * Metadata related to the {@link TaskThumbnail}.
2152 *
2153 * @hide
2154 */
2155 public static class TaskThumbnailInfo implements Parcelable {
2156 /** @hide */
2157 public static final String ATTR_TASK_THUMBNAILINFO_PREFIX = "task_thumbnailinfo_";
2158 private static final String ATTR_TASK_WIDTH =
2159 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_width";
2160 private static final String ATTR_TASK_HEIGHT =
2161 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_height";
2162 private static final String ATTR_SCREEN_ORIENTATION =
2163 ATTR_TASK_THUMBNAILINFO_PREFIX + "screen_orientation";
2164
2165 public int taskWidth;
2166 public int taskHeight;
Winson21700932016-03-24 17:26:23 -07002167 public int screenOrientation = Configuration.ORIENTATION_UNDEFINED;
Winsonc809cbb2015-11-02 12:06:15 -08002168
2169 public TaskThumbnailInfo() {
2170 // Do nothing
2171 }
2172
2173 private TaskThumbnailInfo(Parcel source) {
2174 readFromParcel(source);
2175 }
2176
Winsonc6a2da02015-11-11 18:11:59 -08002177 /**
2178 * Resets this info state to the initial state.
2179 * @hide
2180 */
2181 public void reset() {
2182 taskWidth = 0;
2183 taskHeight = 0;
Winson21700932016-03-24 17:26:23 -07002184 screenOrientation = Configuration.ORIENTATION_UNDEFINED;
2185 }
2186
2187 /**
2188 * Copies from another ThumbnailInfo.
2189 */
2190 public void copyFrom(TaskThumbnailInfo o) {
2191 taskWidth = o.taskWidth;
2192 taskHeight = o.taskHeight;
2193 screenOrientation = o.screenOrientation;
Winsonc6a2da02015-11-11 18:11:59 -08002194 }
2195
Winsonc809cbb2015-11-02 12:06:15 -08002196 /** @hide */
2197 public void saveToXml(XmlSerializer out) throws IOException {
2198 out.attribute(null, ATTR_TASK_WIDTH, Integer.toString(taskWidth));
2199 out.attribute(null, ATTR_TASK_HEIGHT, Integer.toString(taskHeight));
2200 out.attribute(null, ATTR_SCREEN_ORIENTATION, Integer.toString(screenOrientation));
2201 }
2202
2203 /** @hide */
2204 public void restoreFromXml(String attrName, String attrValue) {
2205 if (ATTR_TASK_WIDTH.equals(attrName)) {
2206 taskWidth = Integer.parseInt(attrValue);
2207 } else if (ATTR_TASK_HEIGHT.equals(attrName)) {
2208 taskHeight = Integer.parseInt(attrValue);
2209 } else if (ATTR_SCREEN_ORIENTATION.equals(attrName)) {
2210 screenOrientation = Integer.parseInt(attrValue);
2211 }
2212 }
2213
2214 public int describeContents() {
2215 return 0;
2216 }
2217
2218 public void writeToParcel(Parcel dest, int flags) {
2219 dest.writeInt(taskWidth);
2220 dest.writeInt(taskHeight);
2221 dest.writeInt(screenOrientation);
2222 }
2223
2224 public void readFromParcel(Parcel source) {
2225 taskWidth = source.readInt();
2226 taskHeight = source.readInt();
2227 screenOrientation = source.readInt();
2228 }
2229
2230 public static final Creator<TaskThumbnailInfo> CREATOR = new Creator<TaskThumbnailInfo>() {
2231 public TaskThumbnailInfo createFromParcel(Parcel source) {
2232 return new TaskThumbnailInfo(source);
2233 }
2234 public TaskThumbnailInfo[] newArray(int size) {
2235 return new TaskThumbnailInfo[size];
2236 }
2237 };
2238 }
2239
Dianne Hackbornd94df452011-02-16 18:53:31 -08002240 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002241 public static class TaskThumbnail implements Parcelable {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002242 public Bitmap mainThumbnail;
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002243 public ParcelFileDescriptor thumbnailFileDescriptor;
Winsonc809cbb2015-11-02 12:06:15 -08002244 public TaskThumbnailInfo thumbnailInfo;
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002245
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002246 public TaskThumbnail() {
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002247 }
2248
Winsonc809cbb2015-11-02 12:06:15 -08002249 private TaskThumbnail(Parcel source) {
2250 readFromParcel(source);
2251 }
2252
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002253 public int describeContents() {
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002254 if (thumbnailFileDescriptor != null) {
2255 return thumbnailFileDescriptor.describeContents();
2256 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002257 return 0;
2258 }
2259
2260 public void writeToParcel(Parcel dest, int flags) {
2261 if (mainThumbnail != null) {
2262 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002263 mainThumbnail.writeToParcel(dest, flags);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002264 } else {
2265 dest.writeInt(0);
2266 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002267 if (thumbnailFileDescriptor != null) {
2268 dest.writeInt(1);
Dianne Hackborn852975d2014-08-22 17:42:43 -07002269 thumbnailFileDescriptor.writeToParcel(dest, flags);
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002270 } else {
2271 dest.writeInt(0);
2272 }
Winsonc809cbb2015-11-02 12:06:15 -08002273 if (thumbnailInfo != null) {
2274 dest.writeInt(1);
2275 thumbnailInfo.writeToParcel(dest, flags);
2276 } else {
2277 dest.writeInt(0);
2278 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002279 }
2280
2281 public void readFromParcel(Parcel source) {
2282 if (source.readInt() != 0) {
2283 mainThumbnail = Bitmap.CREATOR.createFromParcel(source);
2284 } else {
2285 mainThumbnail = null;
2286 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002287 if (source.readInt() != 0) {
2288 thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source);
2289 } else {
2290 thumbnailFileDescriptor = null;
2291 }
Winsonc809cbb2015-11-02 12:06:15 -08002292 if (source.readInt() != 0) {
2293 thumbnailInfo = TaskThumbnailInfo.CREATOR.createFromParcel(source);
2294 } else {
2295 thumbnailInfo = null;
2296 }
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002297 }
2298
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002299 public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() {
2300 public TaskThumbnail createFromParcel(Parcel source) {
2301 return new TaskThumbnail(source);
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002302 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002303 public TaskThumbnail[] newArray(int size) {
2304 return new TaskThumbnail[size];
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002305 }
2306 };
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002307 }
2308
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002309 /**
2310 * Represents a task snapshot.
2311 * @hide
2312 */
2313 public static class TaskSnapshot implements Parcelable {
2314
2315 private final GraphicBuffer mSnapshot;
2316 private final int mOrientation;
2317 private final Rect mContentInsets;
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002318 private final boolean mReducedResolution;
2319 private final float mScale;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002320
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002321 public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets,
2322 boolean reducedResolution, float scale) {
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002323 mSnapshot = snapshot;
2324 mOrientation = orientation;
2325 mContentInsets = new Rect(contentInsets);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002326 mReducedResolution = reducedResolution;
2327 mScale = scale;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002328 }
2329
2330 private TaskSnapshot(Parcel source) {
2331 mSnapshot = source.readParcelable(null /* classLoader */);
2332 mOrientation = source.readInt();
2333 mContentInsets = source.readParcelable(null /* classLoader */);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002334 mReducedResolution = source.readBoolean();
2335 mScale = source.readFloat();
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002336 }
2337
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002338 /**
2339 * @return The graphic buffer representing the screenshot.
2340 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002341 public GraphicBuffer getSnapshot() {
2342 return mSnapshot;
2343 }
2344
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002345 /**
2346 * @return The screen orientation the screenshot was taken in.
2347 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002348 public int getOrientation() {
2349 return mOrientation;
2350 }
2351
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002352 /**
2353 * @return The system/content insets on the snapshot. These can be clipped off in order to
2354 * remove any areas behind system bars in the snapshot.
2355 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002356 public Rect getContentInsets() {
2357 return mContentInsets;
2358 }
2359
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002360 /**
2361 * @return Whether this snapshot is a down-sampled version of the full resolution.
2362 */
2363 public boolean isReducedResolution() {
2364 return mReducedResolution;
2365 }
2366
2367 /**
2368 * @return The scale this snapshot was taken in.
2369 */
2370 public float getScale() {
2371 return mScale;
2372 }
2373
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002374 @Override
2375 public int describeContents() {
2376 return 0;
2377 }
2378
2379 @Override
2380 public void writeToParcel(Parcel dest, int flags) {
2381 dest.writeParcelable(mSnapshot, 0);
2382 dest.writeInt(mOrientation);
2383 dest.writeParcelable(mContentInsets, 0);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002384 dest.writeBoolean(mReducedResolution);
2385 dest.writeFloat(mScale);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002386 }
2387
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002388 @Override
2389 public String toString() {
2390 return "TaskSnapshot{mSnapshot=" + mSnapshot + " mOrientation=" + mOrientation
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002391 + " mContentInsets=" + mContentInsets.toShortString()
2392 + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale;
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002393 }
2394
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002395 public static final Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
2396 public TaskSnapshot createFromParcel(Parcel source) {
2397 return new TaskSnapshot(source);
2398 }
2399 public TaskSnapshot[] newArray(int size) {
2400 return new TaskSnapshot[size];
2401 }
2402 };
2403 }
2404
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002405 /** @hide */
Craig Mautnerc0ffce52014-07-01 12:38:52 -07002406 public TaskThumbnail getTaskThumbnail(int id) throws SecurityException {
Dianne Hackbornd94df452011-02-16 18:53:31 -08002407 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002408 return getService().getTaskThumbnail(id);
Dianne Hackborn15491c62012-09-19 10:59:14 -07002409 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002410 throw e.rethrowFromSystemServer();
Dianne Hackborn15491c62012-09-19 10:59:14 -07002411 }
2412 }
2413
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002414 /** @hide */
2415 @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = {
2416 MOVE_TASK_WITH_HOME,
2417 MOVE_TASK_NO_USER_ACTION,
2418 })
2419 @Retention(RetentionPolicy.SOURCE)
2420 public @interface MoveTaskFlags {}
2421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002423 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
2424 * activity along with the task, so it is positioned immediately behind
2425 * the task.
2426 */
2427 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
2428
2429 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08002430 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
2431 * user-instigated action, so the current activity will not receive a
2432 * hint that the user is leaving.
2433 */
2434 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
2435
2436 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002437 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
2438 * with a null options argument.
2439 *
2440 * @param taskId The identifier of the task to be moved, as found in
2441 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002442 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002443 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002444 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2445 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002446 moveTaskToFront(taskId, flags, null);
2447 }
2448
2449 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002450 * Ask that the task associated with a given task ID be moved to the
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002451 * front of the stack, so it is now visible to the user.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002452 *
2453 * @param taskId The identifier of the task to be moved, as found in
2454 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002455 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002456 * @param options Additional options for the operation, either null or
2457 * as per {@link Context#startActivity(Intent, android.os.Bundle)
2458 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002459 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002460 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2461 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002462 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002463 getService().moveTaskToFront(taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002464 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002465 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002466 }
2467 }
2468
2469 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 * Information you can retrieve about a particular Service that is
2471 * currently running in the system.
2472 */
2473 public static class RunningServiceInfo implements Parcelable {
2474 /**
2475 * The service component.
2476 */
2477 public ComponentName service;
2478
2479 /**
2480 * If non-zero, this is the process the service is running in.
2481 */
2482 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002485 * The UID that owns this service.
2486 */
2487 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002488
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002489 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 * The name of the process this service runs in.
2491 */
2492 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 /**
2495 * Set to true if the service has asked to run as a foreground process.
2496 */
2497 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002500 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002501 * starting or binding to it. This
2502 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 */
2504 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 /**
2507 * Set to true if this service has been explicitly started.
2508 */
2509 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 /**
2512 * Number of clients connected to the service.
2513 */
2514 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 /**
2517 * Number of times the service's process has crashed while the service
2518 * is running.
2519 */
2520 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 /**
2523 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002524 * explicit requests to start it or clients binding to it). This
2525 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 */
2527 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 /**
2530 * If non-zero, this service is not currently running, but scheduled to
2531 * restart at the given time.
2532 */
2533 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002534
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002535 /**
2536 * Bit for {@link #flags}: set if this service has been
2537 * explicitly started.
2538 */
2539 public static final int FLAG_STARTED = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002540
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002541 /**
2542 * Bit for {@link #flags}: set if the service has asked to
2543 * run as a foreground process.
2544 */
2545 public static final int FLAG_FOREGROUND = 1<<1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002546
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002547 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002548 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002549 * core system process.
2550 */
2551 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002552
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002553 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002554 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002555 * persistent process.
2556 */
2557 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002558
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002559 /**
2560 * Running flags.
2561 */
2562 public int flags;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002563
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002564 /**
2565 * For special services that are bound to by system code, this is
2566 * the package that holds the binding.
2567 */
2568 public String clientPackage;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002569
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002570 /**
2571 * For special services that are bound to by system code, this is
2572 * a string resource providing a user-visible label for who the
2573 * client is.
2574 */
2575 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 public RunningServiceInfo() {
2578 }
2579
2580 public int describeContents() {
2581 return 0;
2582 }
2583
2584 public void writeToParcel(Parcel dest, int flags) {
2585 ComponentName.writeToParcel(service, dest);
2586 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002587 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 dest.writeString(process);
2589 dest.writeInt(foreground ? 1 : 0);
2590 dest.writeLong(activeSince);
2591 dest.writeInt(started ? 1 : 0);
2592 dest.writeInt(clientCount);
2593 dest.writeInt(crashCount);
2594 dest.writeLong(lastActivityTime);
2595 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002596 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002597 dest.writeString(clientPackage);
2598 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002599 }
2600
2601 public void readFromParcel(Parcel source) {
2602 service = ComponentName.readFromParcel(source);
2603 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002604 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605 process = source.readString();
2606 foreground = source.readInt() != 0;
2607 activeSince = source.readLong();
2608 started = source.readInt() != 0;
2609 clientCount = source.readInt();
2610 crashCount = source.readInt();
2611 lastActivityTime = source.readLong();
2612 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002613 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002614 clientPackage = source.readString();
2615 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002616 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
2619 public RunningServiceInfo createFromParcel(Parcel source) {
2620 return new RunningServiceInfo(source);
2621 }
2622 public RunningServiceInfo[] newArray(int size) {
2623 return new RunningServiceInfo[size];
2624 }
2625 };
2626
2627 private RunningServiceInfo(Parcel source) {
2628 readFromParcel(source);
2629 }
2630 }
2631
2632 /**
2633 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002634 *
2635 * <p><b>Note: this method is only intended for debugging or implementing
2636 * service management type user interfaces.</b></p>
2637 *
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002638 * @deprecated As of {@link android.os.Build.VERSION_CODES#O}, this method
2639 * is no longer available to third party applications. For backwards compatibility,
2640 * it will still return the caller's own services.
2641 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 * @param maxNum The maximum number of entries to return in the list. The
2643 * actual number returned may be smaller, depending on how many services
2644 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002645 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002646 * @return Returns a list of RunningServiceInfo records describing each of
2647 * the running tasks.
2648 */
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002649 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002650 public List<RunningServiceInfo> getRunningServices(int maxNum)
2651 throws SecurityException {
2652 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002653 return getService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 .getServices(maxNum, 0);
2655 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002656 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 }
2658 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002660 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002661 * Returns a PendingIntent you can start to show a control panel for the
2662 * given running service. If the service does not have a control panel,
2663 * null is returned.
2664 */
2665 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2666 throws SecurityException {
2667 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002668 return getService()
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002669 .getRunningServiceControlPanel(service);
2670 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002671 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002672 }
2673 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002674
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002675 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 * Information you can retrieve about the available memory through
2677 * {@link ActivityManager#getMemoryInfo}.
2678 */
2679 public static class MemoryInfo implements Parcelable {
2680 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002681 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 * be considered absolute: due to the nature of the kernel, a significant
2683 * portion of this memory is actually in use and needed for the overall
2684 * system to run well.
2685 */
2686 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002687
2688 /**
2689 * The total memory accessible by the kernel. This is basically the
2690 * RAM size of the device, not including below-kernel fixed allocations
2691 * like DMA buffers, RAM for the baseband CPU, etc.
2692 */
2693 public long totalMem;
2694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 /**
2696 * The threshold of {@link #availMem} at which we consider memory to be
2697 * low and start killing background services and other non-extraneous
2698 * processes.
2699 */
2700 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 /**
2703 * Set to true if the system considers itself to currently be in a low
2704 * memory situation.
2705 */
2706 public boolean lowMemory;
2707
Dianne Hackborn7d608422011-08-07 16:24:18 -07002708 /** @hide */
2709 public long hiddenAppThreshold;
2710 /** @hide */
2711 public long secondaryServerThreshold;
2712 /** @hide */
2713 public long visibleAppThreshold;
2714 /** @hide */
2715 public long foregroundAppThreshold;
2716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 public MemoryInfo() {
2718 }
2719
2720 public int describeContents() {
2721 return 0;
2722 }
2723
2724 public void writeToParcel(Parcel dest, int flags) {
2725 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002726 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002727 dest.writeLong(threshold);
2728 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002729 dest.writeLong(hiddenAppThreshold);
2730 dest.writeLong(secondaryServerThreshold);
2731 dest.writeLong(visibleAppThreshold);
2732 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002733 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735 public void readFromParcel(Parcel source) {
2736 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002737 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 threshold = source.readLong();
2739 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002740 hiddenAppThreshold = source.readLong();
2741 secondaryServerThreshold = source.readLong();
2742 visibleAppThreshold = source.readLong();
2743 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002744 }
2745
2746 public static final Creator<MemoryInfo> CREATOR
2747 = new Creator<MemoryInfo>() {
2748 public MemoryInfo createFromParcel(Parcel source) {
2749 return new MemoryInfo(source);
2750 }
2751 public MemoryInfo[] newArray(int size) {
2752 return new MemoryInfo[size];
2753 }
2754 };
2755
2756 private MemoryInfo(Parcel source) {
2757 readFromParcel(source);
2758 }
2759 }
2760
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002761 /**
2762 * Return general information about the memory state of the system. This
2763 * can be used to help decide how to manage your own memory, though note
2764 * that polling is not recommended and
2765 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2766 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2767 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2768 * level of your process as needed, which gives a better hint for how to
2769 * manage its memory.
2770 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 public void getMemoryInfo(MemoryInfo outInfo) {
2772 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002773 getService().getMemoryInfo(outInfo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002775 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 }
2777 }
Craig Mautner967212c2013-04-13 21:10:58 -07002778
Craig Mautner5ff12102013-05-24 12:50:15 -07002779 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002780 * Information you can retrieve about an ActivityStack in the system.
2781 * @hide
2782 */
2783 public static class StackInfo implements Parcelable {
2784 public int stackId;
Craig Mautnered6649f2013-12-02 14:08:25 -08002785 public Rect bounds = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -07002786 public int[] taskIds;
2787 public String[] taskNames;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002788 public Rect[] taskBounds;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002789 public int[] taskUserIds;
Winsond46b7272016-04-20 11:54:27 -07002790 public ComponentName topActivity;
Craig Mautnered6649f2013-12-02 14:08:25 -08002791 public int displayId;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002792 public int userId;
Winsond46b7272016-04-20 11:54:27 -07002793 public boolean visible;
Winson529c8e42016-05-17 11:08:40 -07002794 // Index of the stack in the display's stack list, can be used for comparison of stack order
2795 public int position;
Craig Mautner967212c2013-04-13 21:10:58 -07002796
Craig Mautner967212c2013-04-13 21:10:58 -07002797 @Override
2798 public int describeContents() {
2799 return 0;
2800 }
2801
2802 @Override
2803 public void writeToParcel(Parcel dest, int flags) {
2804 dest.writeInt(stackId);
2805 dest.writeInt(bounds.left);
2806 dest.writeInt(bounds.top);
2807 dest.writeInt(bounds.right);
2808 dest.writeInt(bounds.bottom);
2809 dest.writeIntArray(taskIds);
2810 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002811 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2812 dest.writeInt(boundsCount);
2813 for (int i = 0; i < boundsCount; i++) {
2814 dest.writeInt(taskBounds[i].left);
2815 dest.writeInt(taskBounds[i].top);
2816 dest.writeInt(taskBounds[i].right);
2817 dest.writeInt(taskBounds[i].bottom);
2818 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002819 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002820 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002821 dest.writeInt(userId);
Winsond46b7272016-04-20 11:54:27 -07002822 dest.writeInt(visible ? 1 : 0);
Winson529c8e42016-05-17 11:08:40 -07002823 dest.writeInt(position);
Winsond46b7272016-04-20 11:54:27 -07002824 if (topActivity != null) {
2825 dest.writeInt(1);
2826 topActivity.writeToParcel(dest, 0);
2827 } else {
2828 dest.writeInt(0);
2829 }
Craig Mautner967212c2013-04-13 21:10:58 -07002830 }
2831
2832 public void readFromParcel(Parcel source) {
2833 stackId = source.readInt();
2834 bounds = new Rect(
2835 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2836 taskIds = source.createIntArray();
2837 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002838 final int boundsCount = source.readInt();
2839 if (boundsCount > 0) {
2840 taskBounds = new Rect[boundsCount];
2841 for (int i = 0; i < boundsCount; i++) {
2842 taskBounds[i] = new Rect();
2843 taskBounds[i].set(
2844 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2845 }
2846 } else {
2847 taskBounds = null;
2848 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002849 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002850 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002851 userId = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002852 visible = source.readInt() > 0;
Winson529c8e42016-05-17 11:08:40 -07002853 position = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002854 if (source.readInt() > 0) {
2855 topActivity = ComponentName.readFromParcel(source);
2856 }
Craig Mautner967212c2013-04-13 21:10:58 -07002857 }
2858
2859 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
2860 @Override
2861 public StackInfo createFromParcel(Parcel source) {
2862 return new StackInfo(source);
2863 }
2864 @Override
2865 public StackInfo[] newArray(int size) {
2866 return new StackInfo[size];
2867 }
2868 };
2869
Craig Mautner5ff12102013-05-24 12:50:15 -07002870 public StackInfo() {
2871 }
2872
Craig Mautner967212c2013-04-13 21:10:58 -07002873 private StackInfo(Parcel source) {
2874 readFromParcel(source);
2875 }
2876
Craig Mautner5ff12102013-05-24 12:50:15 -07002877 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002878 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002879 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002880 sb.append(" bounds="); sb.append(bounds.toShortString());
2881 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002882 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002883 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002884 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002885 for (int i = 0; i < taskIds.length; ++i) {
2886 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002887 sb.append(": "); sb.append(taskNames[i]);
2888 if (taskBounds != null) {
2889 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2890 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002891 sb.append(" userId=").append(taskUserIds[i]);
Winsond46b7272016-04-20 11:54:27 -07002892 sb.append(" visible=").append(visible);
2893 if (topActivity != null) {
2894 sb.append(" topActivity=").append(topActivity);
2895 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002896 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002897 }
2898 return sb.toString();
2899 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002900
2901 @Override
2902 public String toString() {
2903 return toString("");
2904 }
Craig Mautner967212c2013-04-13 21:10:58 -07002905 }
2906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 /**
2908 * @hide
2909 */
Svet Ganovf935a702017-08-22 12:15:58 -07002910 @RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA,
2911 Manifest.permission.ACCESS_INSTANT_APPS})
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2913 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002914 return getService().clearApplicationUserData(packageName,
Dianne Hackborn41203752012-08-31 14:05:51 -07002915 observer, UserHandle.myUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002917 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 }
2919 }
Christopher Tatea3664242013-06-26 15:00:18 -07002920
2921 /**
2922 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002923 * the user choosing to clear the app's data from within the device settings UI. It
2924 * erases all dynamic data associated with the app -- its private data and data in its
2925 * private area on external storage -- but does not remove the installed application
2926 * itself, nor any OBB files.
Christopher Tatea3664242013-06-26 15:00:18 -07002927 *
2928 * @return {@code true} if the application successfully requested that the application's
2929 * data be erased; {@code false} otherwise.
2930 */
2931 public boolean clearApplicationUserData() {
2932 return clearApplicationUserData(mContext.getPackageName(), null);
2933 }
2934
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002935
2936 /**
2937 * Permits an application to get the persistent URI permissions granted to another.
2938 *
2939 * <p>Typically called by Settings.
2940 *
2941 * @param packageName application to look for the granted permissions
2942 * @return list of granted URI permissions
2943 *
2944 * @hide
2945 */
2946 public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName) {
2947 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002948 return getService().getGrantedUriPermissions(packageName,
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002949 UserHandle.myUserId());
2950 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002951 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002952 }
2953 }
2954
2955 /**
2956 * Permits an application to clear the persistent URI permissions granted to another.
2957 *
2958 * <p>Typically called by Settings.
2959 *
2960 * @param packageName application to clear its granted permissions
2961 *
2962 * @hide
2963 */
2964 public void clearGrantedUriPermissions(String packageName) {
2965 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002966 getService().clearGrantedUriPermissions(packageName,
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002967 UserHandle.myUserId());
2968 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002969 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002970 }
2971 }
2972
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 /**
2974 * Information you can retrieve about any processes that are in an error condition.
2975 */
2976 public static class ProcessErrorStateInfo implements Parcelable {
2977 /**
2978 * Condition codes
2979 */
2980 public static final int NO_ERROR = 0;
2981 public static final int CRASHED = 1;
2982 public static final int NOT_RESPONDING = 2;
2983
2984 /**
2985 * The condition that the process is in.
2986 */
2987 public int condition;
2988
2989 /**
2990 * The process name in which the crash or error occurred.
2991 */
2992 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 /**
2995 * The pid of this process; 0 if none
2996 */
2997 public int pid;
2998
2999 /**
3000 * The kernel user-ID that has been assigned to this process;
3001 * currently this is not a unique ID (multiple applications can have
3002 * the same uid).
3003 */
3004 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 /**
Dan Egnor60d87622009-12-16 16:32:58 -08003007 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003008 */
3009 public String tag;
3010
3011 /**
3012 * A short message describing the error condition.
3013 */
3014 public String shortMsg;
3015
3016 /**
3017 * A long message describing the error condition.
3018 */
3019 public String longMsg;
3020
3021 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08003022 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 */
Dan Egnorb7f03672009-12-09 16:22:32 -08003024 public String stackTrace;
3025
3026 /**
3027 * to be deprecated: This value will always be null.
3028 */
3029 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030
3031 public ProcessErrorStateInfo() {
3032 }
3033
Craig Mautner5ff12102013-05-24 12:50:15 -07003034 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 public int describeContents() {
3036 return 0;
3037 }
3038
Craig Mautner5ff12102013-05-24 12:50:15 -07003039 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 public void writeToParcel(Parcel dest, int flags) {
3041 dest.writeInt(condition);
3042 dest.writeString(processName);
3043 dest.writeInt(pid);
3044 dest.writeInt(uid);
3045 dest.writeString(tag);
3046 dest.writeString(shortMsg);
3047 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08003048 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003049 }
Craig Mautner5ff12102013-05-24 12:50:15 -07003050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051 public void readFromParcel(Parcel source) {
3052 condition = source.readInt();
3053 processName = source.readString();
3054 pid = source.readInt();
3055 uid = source.readInt();
3056 tag = source.readString();
3057 shortMsg = source.readString();
3058 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08003059 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003061
3062 public static final Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 new Creator<ProcessErrorStateInfo>() {
3064 public ProcessErrorStateInfo createFromParcel(Parcel source) {
3065 return new ProcessErrorStateInfo(source);
3066 }
3067 public ProcessErrorStateInfo[] newArray(int size) {
3068 return new ProcessErrorStateInfo[size];
3069 }
3070 };
3071
3072 private ProcessErrorStateInfo(Parcel source) {
3073 readFromParcel(source);
3074 }
3075 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003078 * 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 -08003079 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003080 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
3082 * current error conditions (it will not return an empty list). This list ordering is not
3083 * specified.
3084 */
3085 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
3086 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003087 return getService().getProcessesInErrorState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003088 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003089 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090 }
3091 }
3092
3093 /**
3094 * Information you can retrieve about a running process.
3095 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07003096 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003097 /**
3098 * The name of the process that this object is associated with
3099 */
3100 public String processName;
3101
3102 /**
3103 * The pid of this process; 0 if none
3104 */
3105 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003106
Dianne Hackborneb034652009-09-07 00:49:58 -07003107 /**
3108 * The user id of this process.
3109 */
3110 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003111
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003112 /**
3113 * All packages that have been loaded into the process.
3114 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003115 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07003116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07003118 * Constant for {@link #flags}: this is an app that is unable to
3119 * correctly save its state when going to the background,
3120 * so it can not be killed while in the background.
3121 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003122 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07003123 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003124
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003125 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003126 * Constant for {@link #flags}: this process is associated with a
3127 * persistent system app.
3128 * @hide
3129 */
3130 public static final int FLAG_PERSISTENT = 1<<1;
3131
3132 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07003133 * Constant for {@link #flags}: this process is associated with a
3134 * persistent system app.
3135 * @hide
3136 */
3137 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
3138
3139 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003140 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07003141 * {@link #FLAG_CANT_SAVE_STATE}.
3142 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003143 */
3144 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003145
3146 /**
3147 * Last memory trim level reported to the process: corresponds to
3148 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
3149 * ComponentCallbacks2.onTrimMemory(int)}.
3150 */
3151 public int lastTrimLevel;
3152
Jeff Sharkey910e0812017-04-21 16:29:27 -06003153 /** @hide */
3154 @IntDef(prefix = { "IMPORTANCE_" }, value = {
3155 IMPORTANCE_FOREGROUND,
3156 IMPORTANCE_FOREGROUND_SERVICE,
3157 IMPORTANCE_TOP_SLEEPING,
3158 IMPORTANCE_VISIBLE,
3159 IMPORTANCE_PERCEPTIBLE,
3160 IMPORTANCE_CANT_SAVE_STATE,
3161 IMPORTANCE_SERVICE,
3162 IMPORTANCE_CACHED,
3163 IMPORTANCE_GONE,
3164 })
3165 @Retention(RetentionPolicy.SOURCE)
3166 public @interface Importance {}
3167
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003168 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003169 * Constant for {@link #importance}: This process is running the
3170 * foreground UI; that is, it is the thing currently at the top of the screen
3171 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 */
3173 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003176 * Constant for {@link #importance}: This process is running a foreground
3177 * service, for example to perform music playback even while the user is
3178 * not immediately in the app. This generally indicates that the process
3179 * is doing something the user actively cares about.
3180 */
3181 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
3182
3183 /**
3184 * Constant for {@link #importance}: This process is running the foreground
3185 * UI, but the device is asleep so it is not visible to the user. This means
3186 * the user is not really aware of the process, because they can not see or
3187 * interact with it, but it is quite important because it what they expect to
3188 * return to once unlocking the device.
3189 */
3190 public static final int IMPORTANCE_TOP_SLEEPING = 150;
3191
3192 /**
3193 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003194 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07003195 * foreground. This may be running a window that is behind the current
3196 * foreground (so paused and with its state saved, not interacting with
3197 * the user, but visible to them to some degree); it may also be running
3198 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07003199 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003200 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003201
Dianne Hackborn860755f2010-06-03 18:47:52 -07003202 /**
Makoto Onukid7e40582017-04-13 14:54:56 -07003203 * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value
3204 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3205 * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed.
3206 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003207 * <p>The system will return this value instead of {@link #IMPORTANCE_PERCEPTIBLE}
3208 * on Android versions below {@link Build.VERSION_CODES#O}.
3209 *
3210 * <p>On Android version {@link Build.VERSION_CODES#O} and later, this value will still be
3211 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3212 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3213 * the correct value {@link #IMPORTANCE_PERCEPTIBLE} will be returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003214 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003215 public static final int IMPORTANCE_PERCEPTIBLE_PRE_26 = 130;
Makoto Onukid7e40582017-04-13 14:54:56 -07003216
3217 /**
3218 * Constant for {@link #importance}: This process is not something the user
3219 * is directly aware of, but is otherwise perceptible to them to some degree.
3220 */
3221 public static final int IMPORTANCE_PERCEPTIBLE = 230;
3222
3223 /**
3224 * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had
3225 * this wrong value
3226 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3227 * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed.
3228 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003229 * <p>The system will return this value instead of {@link #IMPORTANCE_CANT_SAVE_STATE}
3230 * on Android versions below {@link Build.VERSION_CODES#O}.
3231 *
3232 * <p>On Android version {@link Build.VERSION_CODES#O} after, this value will still be
3233 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3234 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3235 * the correct value {@link #IMPORTANCE_CANT_SAVE_STATE} will be returned.
3236 *
Makoto Onukid7e40582017-04-13 14:54:56 -07003237 * @hide
3238 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003239 public static final int IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003240
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003241 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003242 * Constant for {@link #importance}: This process is running an
Dianne Hackborn5383f502010-10-22 12:59:20 -07003243 * application that can not save its state, and thus can't be killed
3244 * while in the background.
3245 * @hide
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003246 */
Makoto Onukid7e40582017-04-13 14:54:56 -07003247 public static final int IMPORTANCE_CANT_SAVE_STATE= 270;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003249 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003250 * Constant for {@link #importance}: This process is contains services
3251 * that should remain running. These are background services apps have
3252 * started, not something the user is aware of, so they may be killed by
3253 * the system relatively freely (though it is generally desired that they
3254 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 */
3256 public static final int IMPORTANCE_SERVICE = 300;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003259 * Constant for {@link #importance}: This process process contains
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003260 * cached code that is expendable, not actively running any app components
3261 * we care about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003263 public static final int IMPORTANCE_CACHED = 400;
3264
3265 /**
3266 * @deprecated Renamed to {@link #IMPORTANCE_CACHED}.
3267 */
3268 public static final int IMPORTANCE_BACKGROUND = IMPORTANCE_CACHED;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003271 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 * actively running code.
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003273 * @deprecated This value is no longer reported, use {@link #IMPORTANCE_CACHED} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003275 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003277
3278 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003279 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003280 */
3281 public static final int IMPORTANCE_GONE = 1000;
3282
Makoto Onukid7e40582017-04-13 14:54:56 -07003283 /**
3284 * Convert a proc state to the correspondent IMPORTANCE_* constant. If the return value
3285 * will be passed to a client, use {@link #procStateToImportanceForClient}.
3286 * @hide
3287 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003288 public static @Importance int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003289 if (procState == PROCESS_STATE_NONEXISTENT) {
3290 return IMPORTANCE_GONE;
3291 } else if (procState >= PROCESS_STATE_HOME) {
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003292 return IMPORTANCE_CACHED;
Dianne Hackborn1e383822015-04-10 14:02:33 -07003293 } else if (procState >= PROCESS_STATE_SERVICE) {
3294 return IMPORTANCE_SERVICE;
3295 } else if (procState > PROCESS_STATE_HEAVY_WEIGHT) {
3296 return IMPORTANCE_CANT_SAVE_STATE;
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003297 } else if (procState >= PROCESS_STATE_TRANSIENT_BACKGROUND) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003298 return IMPORTANCE_PERCEPTIBLE;
3299 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
3300 return IMPORTANCE_VISIBLE;
3301 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
3302 return IMPORTANCE_TOP_SLEEPING;
3303 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) {
3304 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003305 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003306 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003307 }
3308 }
3309
Makoto Onukid7e40582017-04-13 14:54:56 -07003310 /**
3311 * Convert a proc state to the correspondent IMPORTANCE_* constant for a client represented
3312 * by a given {@link Context}, with converting {@link #IMPORTANCE_PERCEPTIBLE}
3313 * and {@link #IMPORTANCE_CANT_SAVE_STATE} to the corresponding "wrong" value if the
3314 * client's target SDK < {@link VERSION_CODES#O}.
3315 * @hide
3316 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003317 public static @Importance int procStateToImportanceForClient(int procState,
3318 Context clientContext) {
Makoto Onukie92f7942017-04-26 14:38:18 -07003319 return procStateToImportanceForTargetSdk(procState,
3320 clientContext.getApplicationInfo().targetSdkVersion);
3321 }
3322
3323 /**
3324 * See {@link #procStateToImportanceForClient}.
3325 * @hide
3326 */
3327 public static @Importance int procStateToImportanceForTargetSdk(int procState,
3328 int targetSdkVersion) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003329 final int importance = procStateToImportance(procState);
3330
3331 // For pre O apps, convert to the old, wrong values.
Makoto Onukie92f7942017-04-26 14:38:18 -07003332 if (targetSdkVersion < VERSION_CODES.O) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003333 switch (importance) {
3334 case IMPORTANCE_PERCEPTIBLE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003335 return IMPORTANCE_PERCEPTIBLE_PRE_26;
Makoto Onukid7e40582017-04-13 14:54:56 -07003336 case IMPORTANCE_CANT_SAVE_STATE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003337 return IMPORTANCE_CANT_SAVE_STATE_PRE_26;
Makoto Onukid7e40582017-04-13 14:54:56 -07003338 }
3339 }
3340 return importance;
3341 }
3342
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003343 /** @hide */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003344 public static int importanceToProcState(@Importance int importance) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003345 if (importance == IMPORTANCE_GONE) {
3346 return PROCESS_STATE_NONEXISTENT;
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003347 } else if (importance >= IMPORTANCE_CACHED) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003348 return PROCESS_STATE_HOME;
3349 } else if (importance >= IMPORTANCE_SERVICE) {
3350 return PROCESS_STATE_SERVICE;
3351 } else if (importance > IMPORTANCE_CANT_SAVE_STATE) {
3352 return PROCESS_STATE_HEAVY_WEIGHT;
3353 } else if (importance >= IMPORTANCE_PERCEPTIBLE) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003354 return PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003355 } else if (importance >= IMPORTANCE_VISIBLE) {
3356 return PROCESS_STATE_IMPORTANT_FOREGROUND;
3357 } else if (importance >= IMPORTANCE_TOP_SLEEPING) {
3358 return PROCESS_STATE_TOP_SLEEPING;
3359 } else if (importance >= IMPORTANCE_FOREGROUND_SERVICE) {
3360 return PROCESS_STATE_FOREGROUND_SERVICE;
3361 } else {
3362 return PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
3363 }
3364 }
3365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 /**
Jeff Sharkey910e0812017-04-21 16:29:27 -06003367 * The relative importance level that the system places on this process.
3368 * These constants are numbered so that "more important" values are
3369 * always smaller than "less important" values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003371 public @Importance int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 /**
3374 * An additional ordering within a particular {@link #importance}
3375 * category, providing finer-grained information about the relative
3376 * utility of processes within a category. This number means nothing
3377 * except that a smaller values are more recently used (and thus
3378 * more important). Currently an LRU value is only maintained for
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003379 * the {@link #IMPORTANCE_CACHED} category, though others may
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 * be maintained in the future.
3381 */
3382 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003383
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003384 /**
3385 * Constant for {@link #importanceReasonCode}: nothing special has
3386 * been specified for the reason for this level.
3387 */
3388 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003389
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003390 /**
3391 * Constant for {@link #importanceReasonCode}: one of the application's
3392 * content providers is being used by another process. The pid of
3393 * the client process is in {@link #importanceReasonPid} and the
3394 * target provider in this process is in
3395 * {@link #importanceReasonComponent}.
3396 */
3397 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003398
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003399 /**
3400 * Constant for {@link #importanceReasonCode}: one of the application's
3401 * content providers is being used by another process. The pid of
3402 * the client process is in {@link #importanceReasonPid} and the
3403 * target provider in this process is in
3404 * {@link #importanceReasonComponent}.
3405 */
3406 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003407
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003408 /**
3409 * The reason for {@link #importance}, if any.
3410 */
3411 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003412
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003413 /**
3414 * For the specified values of {@link #importanceReasonCode}, this
3415 * is the process ID of the other process that is a client of this
3416 * process. This will be 0 if no other process is using this one.
3417 */
3418 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003419
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003420 /**
3421 * For the specified values of {@link #importanceReasonCode}, this
3422 * is the name of the component that is being used in this process.
3423 */
3424 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003425
Dianne Hackborn905577f2011-09-07 18:31:28 -07003426 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003427 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07003428 * of the other pid. @hide
3429 */
3430 public int importanceReasonImportance;
3431
Dianne Hackborn684bf342014-04-29 17:56:57 -07003432 /**
3433 * Current process state, as per PROCESS_STATE_* constants.
3434 * @hide
3435 */
3436 public int processState;
3437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003438 public RunningAppProcessInfo() {
3439 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003440 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07003441 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003442 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
3445 processName = pProcessName;
3446 pid = pPid;
3447 pkgList = pArr;
3448 }
3449
3450 public int describeContents() {
3451 return 0;
3452 }
3453
3454 public void writeToParcel(Parcel dest, int flags) {
3455 dest.writeString(processName);
3456 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07003457 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003458 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003459 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003460 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003461 dest.writeInt(importance);
3462 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003463 dest.writeInt(importanceReasonCode);
3464 dest.writeInt(importanceReasonPid);
3465 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003466 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07003467 dest.writeInt(processState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 }
3469
3470 public void readFromParcel(Parcel source) {
3471 processName = source.readString();
3472 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07003473 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003475 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003476 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003477 importance = source.readInt();
3478 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003479 importanceReasonCode = source.readInt();
3480 importanceReasonPid = source.readInt();
3481 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003482 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07003483 processState = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003484 }
3485
Stefan Kuhne16045c22015-06-05 07:18:06 -07003486 public static final Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 new Creator<RunningAppProcessInfo>() {
3488 public RunningAppProcessInfo createFromParcel(Parcel source) {
3489 return new RunningAppProcessInfo(source);
3490 }
3491 public RunningAppProcessInfo[] newArray(int size) {
3492 return new RunningAppProcessInfo[size];
3493 }
3494 };
3495
3496 private RunningAppProcessInfo(Parcel source) {
3497 readFromParcel(source);
3498 }
3499 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003502 * Returns a list of application processes installed on external media
3503 * that are running on the device.
3504 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003505 * <p><b>Note: this method is only intended for debugging or building
3506 * a user-facing process management UI.</b></p>
3507 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003508 * @return Returns a list of ApplicationInfo records, or null if none
3509 * This list ordering is not specified.
3510 * @hide
3511 */
3512 public List<ApplicationInfo> getRunningExternalApplications() {
3513 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003514 return getService().getRunningExternalApplications();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003515 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003516 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003517 }
3518 }
3519
3520 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003521 * Sets the memory trim mode for a process and schedules a memory trim operation.
3522 *
3523 * <p><b>Note: this method is only intended for testing framework.</b></p>
3524 *
3525 * @return Returns true if successful.
3526 * @hide
3527 */
3528 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
3529 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003530 return getService().setProcessMemoryTrimLevel(process, userId,
Stefan Kuhne16045c22015-06-05 07:18:06 -07003531 level);
3532 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003533 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07003534 }
3535 }
3536
3537 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003539 *
3540 * <p><b>Note: this method is only intended for debugging or building
3541 * a user-facing process management UI.</b></p>
3542 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
3544 * running processes (it will not return an empty list). This list ordering is not
3545 * specified.
3546 */
3547 public List<RunningAppProcessInfo> getRunningAppProcesses() {
3548 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003549 return getService().getRunningAppProcesses();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003551 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 }
3553 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003554
3555 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003556 * Return the importance of a given package name, based on the processes that are
3557 * currently running. The return value is one of the importance constants defined
3558 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3559 * processes that this package has code running inside of. If there are no processes
3560 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07003561 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07003562 */
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003563 @SystemApi @TestApi
Dianne Hackborn9df8f512016-10-24 17:58:30 -07003564 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003565 public @RunningAppProcessInfo.Importance int getPackageImportance(String packageName) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003566 try {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003567 int procState = getService().getPackageProcessState(packageName,
Adam Lesinskic30454c2015-06-24 13:24:35 -07003568 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003569 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn1e383822015-04-10 14:02:33 -07003570 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003571 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07003572 }
3573 }
3574
3575 /**
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003576 * Return the importance of a given uid, based on the processes that are
3577 * currently running. The return value is one of the importance constants defined
3578 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3579 * processes that this uid has running. If there are no processes
3580 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
3581 * @hide
3582 */
3583 @SystemApi @TestApi
3584 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003585 public @RunningAppProcessInfo.Importance int getUidImportance(int uid) {
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003586 try {
3587 int procState = getService().getUidProcessState(uid,
3588 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003589 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003590 } catch (RemoteException e) {
3591 throw e.rethrowFromSystemServer();
3592 }
3593 }
3594
3595 /**
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003596 * Callback to get reports about changes to the importance of a uid. Use with
3597 * {@link #addOnUidImportanceListener}.
3598 * @hide
3599 */
3600 @SystemApi @TestApi
3601 public interface OnUidImportanceListener {
3602 /**
3603 * The importance if a given uid has changed. Will be one of the importance
3604 * values in {@link RunningAppProcessInfo};
3605 * {@link RunningAppProcessInfo#IMPORTANCE_GONE IMPORTANCE_GONE} will be reported
3606 * when the uid is no longer running at all. This callback will happen on a thread
3607 * from a thread pool, not the main UI thread.
3608 * @param uid The uid whose importance has changed.
3609 * @param importance The new importance value as per {@link RunningAppProcessInfo}.
3610 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003611 void onUidImportance(int uid, @RunningAppProcessInfo.Importance int importance);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003612 }
3613
3614 /**
3615 * Start monitoring changes to the imoportance of uids running in the system.
3616 * @param listener The listener callback that will receive change reports.
3617 * @param importanceCutpoint The level of importance in which the caller is interested
3618 * in differences. For example, if {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}
3619 * is used here, you will receive a call each time a uids importance transitions between
3620 * being <= {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE} and
3621 * > {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.
3622 *
3623 * <p>The caller must hold the {@link android.Manifest.permission#PACKAGE_USAGE_STATS}
3624 * permission to use this feature.</p>
3625 *
3626 * @throws IllegalArgumentException If the listener is already registered.
3627 * @throws SecurityException If the caller does not hold
3628 * {@link android.Manifest.permission#PACKAGE_USAGE_STATS}.
3629 * @hide
3630 */
3631 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003632 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003633 public void addOnUidImportanceListener(OnUidImportanceListener listener,
Jeff Sharkey910e0812017-04-21 16:29:27 -06003634 @RunningAppProcessInfo.Importance int importanceCutpoint) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003635 synchronized (this) {
3636 if (mImportanceListeners.containsKey(listener)) {
3637 throw new IllegalArgumentException("Listener already registered: " + listener);
3638 }
3639 // TODO: implement the cut point in the system process to avoid IPCs.
Makoto Onukid7e40582017-04-13 14:54:56 -07003640 UidObserver observer = new UidObserver(listener, mContext);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003641 try {
3642 getService().registerUidObserver(observer,
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003643 UID_OBSERVER_PROCSTATE | UID_OBSERVER_GONE,
3644 RunningAppProcessInfo.importanceToProcState(importanceCutpoint),
3645 mContext.getOpPackageName());
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003646 } catch (RemoteException e) {
3647 throw e.rethrowFromSystemServer();
3648 }
3649 mImportanceListeners.put(listener, observer);
3650 }
3651 }
3652
3653 /**
3654 * Remove an importance listener that was previously registered with
3655 * {@link #addOnUidImportanceListener}.
3656 *
3657 * @throws IllegalArgumentException If the listener is not registered.
3658 * @hide
3659 */
3660 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003661 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003662 public void removeOnUidImportanceListener(OnUidImportanceListener listener) {
3663 synchronized (this) {
3664 UidObserver observer = mImportanceListeners.remove(listener);
3665 if (observer == null) {
3666 throw new IllegalArgumentException("Listener not registered: " + listener);
3667 }
3668 try {
3669 getService().unregisterUidObserver(observer);
3670 } catch (RemoteException e) {
3671 throw e.rethrowFromSystemServer();
3672 }
3673 }
3674 }
3675
3676 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003677 * Return global memory state information for the calling process. This
3678 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
3679 * only fields that will be filled in are
3680 * {@link RunningAppProcessInfo#pid},
3681 * {@link RunningAppProcessInfo#uid},
3682 * {@link RunningAppProcessInfo#lastTrimLevel},
3683 * {@link RunningAppProcessInfo#importance},
3684 * {@link RunningAppProcessInfo#lru}, and
3685 * {@link RunningAppProcessInfo#importanceReasonCode}.
3686 */
3687 static public void getMyMemoryState(RunningAppProcessInfo outState) {
3688 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003689 getService().getMyMemoryState(outState);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003690 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003691 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003692 }
3693 }
3694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003695 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003696 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003697 *
3698 * <p><b>Note: this method is only intended for debugging or building
3699 * a user-facing process management UI.</b></p>
3700 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003701 * @param pids The pids of the processes whose memory usage is to be
3702 * retrieved.
3703 * @return Returns an array of memory information, one for each
3704 * requested pid.
3705 */
3706 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
3707 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003708 return getService().getProcessMemoryInfo(pids);
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003709 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003710 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003711 }
3712 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003713
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003714 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003715 * @deprecated This is now just a wrapper for
3716 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3717 * is no longer available to applications because it allows them to
3718 * break other applications by removing their alarms, stopping their
3719 * services, etc.
3720 */
3721 @Deprecated
3722 public void restartPackage(String packageName) {
3723 killBackgroundProcesses(packageName);
3724 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003725
Dianne Hackborn03abb812010-01-04 18:43:19 -08003726 /**
3727 * Have the system immediately kill all background processes associated
3728 * with the given package. This is the same as the kernel killing those
3729 * processes to reclaim memory; the system will take care of restarting
3730 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003731 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003732 * @param packageName The name of the package whose processes are to
3733 * be killed.
3734 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003735 @RequiresPermission(Manifest.permission.KILL_BACKGROUND_PROCESSES)
Dianne Hackborn03abb812010-01-04 18:43:19 -08003736 public void killBackgroundProcesses(String packageName) {
3737 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003738 getService().killBackgroundProcesses(packageName,
Dianne Hackborn1676c852012-09-10 14:52:30 -07003739 UserHandle.myUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003740 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003741 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003742 }
3743 }
Svet Ganov019d2302015-05-04 11:07:38 -07003744
3745 /**
3746 * Kills the specified UID.
3747 * @param uid The UID to kill.
3748 * @param reason The reason for the kill.
3749 *
3750 * @hide
3751 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08003752 @SystemApi
Svet Ganov019d2302015-05-04 11:07:38 -07003753 @RequiresPermission(Manifest.permission.KILL_UID)
3754 public void killUid(int uid, String reason) {
3755 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003756 getService().killUid(UserHandle.getAppId(uid),
Svetoslavaa41add2015-08-06 15:03:55 -07003757 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003758 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003759 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003760 }
3761 }
3762
Dianne Hackborn03abb812010-01-04 18:43:19 -08003763 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 * Have the system perform a force stop of everything associated with
3765 * the given application package. All processes that share its uid
3766 * will be killed, all services it has running stopped, all activities
3767 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3768 * broadcast will be sent, so that any of its registered alarms can
3769 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003770 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003772 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003774 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003776 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003777 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003778 * @hide This is not available to third party applications due to
3779 * it allowing them to break other applications by stopping their
3780 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 */
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003782 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003784 getService().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003785 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003786 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787 }
3788 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003789
3790 /**
3791 * @see #forceStopPackageAsUser(String, int)
3792 * @hide
3793 */
Jeff Schumacherb8cadef2017-01-03 13:52:48 -08003794 @SystemApi
3795 @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES)
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003796 public void forceStopPackage(String packageName) {
3797 forceStopPackageAsUser(packageName, UserHandle.myUserId());
3798 }
3799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 /**
3801 * Get the device configuration attributes.
3802 */
3803 public ConfigurationInfo getDeviceConfigurationInfo() {
3804 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003805 return getService().getDeviceConfigurationInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003807 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003810
3811 /**
3812 * Get the preferred density of icons for the launcher. This is used when
3813 * custom drawables are created (e.g., for shortcuts).
3814 *
3815 * @return density in terms of DPI
3816 */
3817 public int getLauncherLargeIconDensity() {
3818 final Resources res = mContext.getResources();
3819 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003820 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003821
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003822 if (sw < 600) {
3823 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003824 return density;
3825 }
3826
3827 switch (density) {
3828 case DisplayMetrics.DENSITY_LOW:
3829 return DisplayMetrics.DENSITY_MEDIUM;
3830 case DisplayMetrics.DENSITY_MEDIUM:
3831 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003832 case DisplayMetrics.DENSITY_TV:
3833 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003834 case DisplayMetrics.DENSITY_HIGH:
3835 return DisplayMetrics.DENSITY_XHIGH;
3836 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003837 return DisplayMetrics.DENSITY_XXHIGH;
3838 case DisplayMetrics.DENSITY_XXHIGH:
3839 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003840 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003841 // The density is some abnormal value. Return some other
3842 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003843 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003844 }
3845 }
3846
3847 /**
3848 * Get the preferred launcher icon size. This is used when custom drawables
3849 * are created (e.g., for shortcuts).
3850 *
3851 * @return dimensions of square icons in terms of pixels
3852 */
3853 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003854 return getLauncherLargeIconSizeInner(mContext);
3855 }
3856
3857 static int getLauncherLargeIconSizeInner(Context context) {
3858 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003859 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003860 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003861
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003862 if (sw < 600) {
3863 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003864 return size;
3865 }
3866
3867 final int density = res.getDisplayMetrics().densityDpi;
3868
3869 switch (density) {
3870 case DisplayMetrics.DENSITY_LOW:
3871 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3872 case DisplayMetrics.DENSITY_MEDIUM:
3873 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003874 case DisplayMetrics.DENSITY_TV:
3875 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003876 case DisplayMetrics.DENSITY_HIGH:
3877 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3878 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003879 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3880 case DisplayMetrics.DENSITY_XXHIGH:
3881 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003882 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003883 // The density is some abnormal value. Return some other
3884 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003885 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003886 }
3887 }
3888
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003889 /**
3890 * Returns "true" if the user interface is currently being messed with
3891 * by a monkey.
3892 */
3893 public static boolean isUserAMonkey() {
3894 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003895 return getService().isUserAMonkey();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003896 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003897 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003898 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003899 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003900
3901 /**
3902 * Returns "true" if device is running in a test harness.
3903 */
3904 public static boolean isRunningInTestHarness() {
3905 return SystemProperties.getBoolean("ro.test_harness", false);
3906 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003907
3908 /**
3909 * Returns the launch count of each installed package.
3910 *
3911 * @hide
3912 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003913 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00003914 try {
3915 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
3916 ServiceManager.getService("usagestats"));
3917 if (usageStatsService == null) {
3918 return new HashMap<String, Integer>();
3919 }
3920
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003921 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
3922 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00003923 if (allPkgUsageStats == null) {
3924 return new HashMap<String, Integer>();
3925 }
3926
Peter Visontay8d224ca2011-02-18 16:39:19 +00003927 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003928 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
3929 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00003930 }
3931
3932 return launchCounts;
3933 } catch (RemoteException e) {
3934 Log.w(TAG, "Could not query launch counts", e);
3935 return new HashMap<String, Integer>();
3936 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003937 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003938
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003939 /** @hide */
3940 public static int checkComponentPermission(String permission, int uid,
3941 int owningUid, boolean exported) {
3942 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08003943 final int appId = UserHandle.getAppId(uid);
3944 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003945 return PackageManager.PERMISSION_GRANTED;
3946 }
3947 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003948 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003949 return PackageManager.PERMISSION_DENIED;
3950 }
3951 // If there is a uid that owns whatever is being accessed, it has
3952 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003953 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003954 return PackageManager.PERMISSION_GRANTED;
3955 }
3956 // If the target is not exported, then nobody else can get to it.
3957 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07003958 /*
3959 RuntimeException here = new RuntimeException("here");
3960 here.fillInStackTrace();
3961 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
3962 here);
3963 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003964 return PackageManager.PERMISSION_DENIED;
3965 }
3966 if (permission == null) {
3967 return PackageManager.PERMISSION_GRANTED;
3968 }
3969 try {
3970 return AppGlobals.getPackageManager()
3971 .checkUidPermission(permission, uid);
3972 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003973 throw e.rethrowFromSystemServer();
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003974 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003975 }
3976
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003977 /** @hide */
3978 public static int checkUidPermission(String permission, int uid) {
3979 try {
3980 return AppGlobals.getPackageManager()
3981 .checkUidPermission(permission, uid);
3982 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003983 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003984 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003985 }
3986
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08003987 /**
3988 * @hide
3989 * Helper for dealing with incoming user arguments to system service calls.
3990 * Takes care of checking permissions and converting USER_CURRENT to the
3991 * actual current user.
3992 *
3993 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
3994 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
3995 * @param userId The user id argument supplied by the caller -- this is the user
3996 * they want to run as.
3997 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
3998 * to get a USER_ALL returned and deal with it correctly. If false,
3999 * an exception will be thrown if USER_ALL is supplied.
4000 * @param requireFull If true, the caller must hold
4001 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
4002 * different user than their current process; otherwise they must hold
4003 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
4004 * @param name Optional textual name of the incoming call; only for generating error messages.
4005 * @param callerPackage Optional package name of caller; only for error messages.
4006 *
4007 * @return Returns the user ID that the call should run as. Will always be a concrete
4008 * user number, unless <var>allowAll</var> is true in which case it could also be
4009 * USER_ALL.
4010 */
Dianne Hackborn41203752012-08-31 14:05:51 -07004011 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
4012 boolean allowAll, boolean requireFull, String name, String callerPackage) {
4013 if (UserHandle.getUserId(callingUid) == userId) {
4014 return userId;
4015 }
4016 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004017 return getService().handleIncomingUser(callingPid,
Dianne Hackborn41203752012-08-31 14:05:51 -07004018 callingUid, userId, allowAll, requireFull, name, callerPackage);
4019 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004020 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07004021 }
4022 }
4023
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07004024 /**
4025 * Gets the userId of the current foreground user. Requires system permissions.
4026 * @hide
4027 */
4028 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004029 @RequiresPermission(anyOf = {
4030 "android.permission.INTERACT_ACROSS_USERS",
4031 "android.permission.INTERACT_ACROSS_USERS_FULL"
4032 })
Dianne Hackborn41203752012-08-31 14:05:51 -07004033 public static int getCurrentUser() {
4034 UserInfo ui;
4035 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004036 ui = getService().getCurrentUser();
Dianne Hackborn41203752012-08-31 14:05:51 -07004037 return ui != null ? ui.id : 0;
4038 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004039 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07004040 }
4041 }
4042
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004043 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07004044 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004045 * @hide
4046 */
4047 public boolean switchUser(int userid) {
4048 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004049 return getService().switchUser(userid);
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004050 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004051 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004052 }
4053 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004054
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08004055 /**
4056 * Logs out current current foreground user by switching to the system user and stopping the
4057 * user being switched from.
4058 * @hide
4059 */
4060 public static void logoutCurrentUser() {
4061 int currentUser = ActivityManager.getCurrentUser();
4062 if (currentUser != UserHandle.USER_SYSTEM) {
4063 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004064 getService().switchUser(UserHandle.USER_SYSTEM);
4065 getService().stopUser(currentUser, /* force= */ false, null);
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08004066 } catch (RemoteException e) {
4067 e.rethrowFromSystemServer();
4068 }
4069 }
4070 }
4071
Jeff Sharkeye17ac152015-11-06 22:40:29 -08004072 /** {@hide} */
4073 public static final int FLAG_OR_STOPPED = 1 << 0;
4074 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07004075 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07004076 /** {@hide} */
4077 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeyce18c812016-04-27 16:00:41 -06004078 /** {@hide} */
4079 public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08004080
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004081 /**
4082 * Return whether the given user is actively running. This means that
4083 * the user is in the "started" state, not "stopped" -- it is currently
4084 * allowed to run code through scheduled alarms, receiving broadcasts,
4085 * etc. A started user may be either the current foreground user or a
4086 * background user; the result here does not distinguish between the two.
Dianne Hackborn5614bf52016-11-07 17:26:41 -08004087 * @param userId the user's id. Zero indicates the default user.
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004088 * @hide
4089 */
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004090 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004091 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004092 return getService().isUserRunning(userId, 0);
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004093 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004094 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004095 }
4096 }
4097
4098 /** {@hide} */
Ruben Brunke24b9a62016-02-16 21:38:24 -08004099 public boolean isVrModePackageEnabled(ComponentName component) {
4100 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004101 return getService().isVrModePackageEnabled(component);
Ruben Brunke24b9a62016-02-16 21:38:24 -08004102 } catch (RemoteException e) {
4103 throw e.rethrowFromSystemServer();
4104 }
4105 }
4106
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004107 /**
4108 * Perform a system dump of various state associated with the given application
4109 * package name. This call blocks while the dump is being performed, so should
4110 * not be done on a UI thread. The data will be written to the given file
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004111 * descriptor as text.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07004112 * @param fd The file descriptor that the dump should be written to. The file
4113 * descriptor is <em>not</em> closed by this function; the caller continues to
4114 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004115 * @param packageName The name of the package that is to be dumped.
4116 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004117 @RequiresPermission(Manifest.permission.DUMP)
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004118 public void dumpPackageState(FileDescriptor fd, String packageName) {
4119 dumpPackageStateStatic(fd, packageName);
4120 }
4121
4122 /**
4123 * @hide
4124 */
4125 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
4126 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07004127 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004128 dumpService(pw, fd, "package", new String[] { packageName });
4129 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08004130 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
4131 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004132 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004133 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08004134 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004135 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004136 pw.println();
Dianne Hackborn904a8572013-06-28 18:12:31 -07004137 dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName });
4138 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07004139 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004140 pw.flush();
4141 }
4142
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004143 /**
4144 * @hide
4145 */
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004146 public static boolean isSystemReady() {
4147 if (!sSystemReady) {
4148 if (ActivityThread.isSystem()) {
4149 sSystemReady =
4150 LocalServices.getService(ActivityManagerInternal.class).isSystemReady();
4151 } else {
4152 // Since this is being called from outside system server, system should be
4153 // ready by now.
4154 sSystemReady = true;
4155 }
4156 }
4157 return sSystemReady;
4158 }
4159
4160 /**
4161 * @hide
4162 */
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004163 public static void broadcastStickyIntent(Intent intent, int userId) {
4164 broadcastStickyIntent(intent, AppOpsManager.OP_NONE, userId);
4165 }
4166
4167 /**
4168 * Convenience for sending a sticky broadcast. For internal use only.
4169 *
4170 * @hide
4171 */
4172 public static void broadcastStickyIntent(Intent intent, int appOp, int userId) {
4173 try {
4174 getService().broadcastIntent(
4175 null, intent, null, null, Activity.RESULT_OK, null, null,
4176 null /*permission*/, appOp, null, false, true, userId);
4177 } catch (RemoteException ex) {
4178 }
4179 }
4180
4181 /**
4182 * @hide
4183 */
4184 public static void noteWakeupAlarm(PendingIntent ps, int sourceUid, String sourcePkg,
4185 String tag) {
4186 try {
4187 getService().noteWakeupAlarm((ps != null) ? ps.getTarget() : null,
4188 sourceUid, sourcePkg, tag);
4189 } catch (RemoteException ex) {
4190 }
4191 }
4192
4193 /**
4194 * @hide
4195 */
4196 public static void noteAlarmStart(PendingIntent ps, int sourceUid, String tag) {
4197 try {
4198 getService().noteAlarmStart((ps != null) ? ps.getTarget() : null, sourceUid, tag);
4199 } catch (RemoteException ex) {
4200 }
4201 }
4202
4203 /**
4204 * @hide
4205 */
4206 public static void noteAlarmFinish(PendingIntent ps, int sourceUid, String tag) {
4207 try {
4208 getService().noteAlarmFinish((ps != null) ? ps.getTarget() : null, sourceUid, tag);
4209 } catch (RemoteException ex) {
4210 }
4211 }
4212
4213 /**
4214 * @hide
4215 */
4216 public static IActivityManager getService() {
4217 return IActivityManagerSingleton.get();
4218 }
4219
4220 private static final Singleton<IActivityManager> IActivityManagerSingleton =
4221 new Singleton<IActivityManager>() {
4222 @Override
4223 protected IActivityManager create() {
4224 final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE);
4225 final IActivityManager am = IActivityManager.Stub.asInterface(b);
4226 return am;
4227 }
4228 };
4229
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004230 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
4231 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
4232 IBinder service = ServiceManager.checkService(name);
4233 if (service == null) {
4234 pw.println(" (Service not found)");
4235 return;
4236 }
4237 TransferPipe tp = null;
4238 try {
4239 pw.flush();
4240 tp = new TransferPipe();
4241 tp.setBufferPrefix(" ");
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08004242 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004243 tp.go(fd, 10000);
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004244 } catch (Throwable e) {
4245 if (tp != null) {
4246 tp.kill();
4247 }
4248 pw.println("Failure dumping service:");
4249 e.printStackTrace(pw);
4250 }
4251 }
Craig Mautneraea74a52014-03-08 14:23:10 -08004252
4253 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004254 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07004255 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004256 * sees the associated process with a larger pss size and, when this happens, automatically
4257 * pull a heap dump from it and allow the user to share the data. Note that this request
4258 * continues running even if the process is killed and restarted. To remove the watch,
4259 * use {@link #clearWatchHeapLimit()}.
4260 *
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07004261 * <p>This API only work if the calling process has been marked as
4262 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
4263 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004264 *
4265 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
4266 * handle heap limit reports themselves.</p>
4267 *
4268 * @param pssSize The size in bytes to set the limit at.
4269 */
4270 public void setWatchHeapLimit(long pssSize) {
4271 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004272 getService().setDumpHeapDebugLimit(null, 0, pssSize,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004273 mContext.getPackageName());
4274 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004275 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004276 }
4277 }
4278
4279 /**
4280 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
4281 * If your package has an activity handling this action, it will be launched with the
4282 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
4283 * match the activty must support this action and a MIME type of "*&#47;*".
4284 */
4285 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
4286
4287 /**
4288 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
4289 */
4290 public void clearWatchHeapLimit() {
4291 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004292 getService().setDumpHeapDebugLimit(null, 0, 0, null);
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004293 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004294 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004295 }
4296 }
4297
4298 /**
Craig Mautneraea74a52014-03-08 14:23:10 -08004299 * @hide
4300 */
4301 public void startLockTaskMode(int taskId) {
4302 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004303 getService().startLockTaskModeById(taskId);
Craig Mautneraea74a52014-03-08 14:23:10 -08004304 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004305 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004306 }
4307 }
4308
4309 /**
4310 * @hide
4311 */
4312 public void stopLockTaskMode() {
4313 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004314 getService().stopLockTaskMode();
Craig Mautneraea74a52014-03-08 14:23:10 -08004315 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004316 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004317 }
4318 }
4319
4320 /**
Jason Monk386c94f2014-07-14 16:42:24 -04004321 * Return whether currently in lock task mode. When in this mode
4322 * no new tasks can be created or switched to.
4323 *
4324 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00004325 *
4326 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08004327 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004328 @Deprecated
Craig Mautneraea74a52014-03-08 14:23:10 -08004329 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00004330 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
4331 }
4332
4333 /**
4334 * Return the current state of task locking. The three possible outcomes
4335 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
4336 * and {@link #LOCK_TASK_MODE_PINNED}.
4337 *
4338 * @see Activity#startLockTask()
4339 */
4340 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08004341 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004342 return getService().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08004343 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004344 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004345 }
4346 }
Winson Chung1147c402014-05-14 11:05:00 -07004347
4348 /**
Srinath Sridharane535a582016-06-27 18:13:47 -07004349 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one
4350 * thread can be a VR thread in a process at a time, and that thread may be subject to
4351 * restrictions on the amount of time it can run.
4352 *
Craig Donnerdc4796c2017-03-08 09:51:47 -08004353 * If persistent VR mode is set, whatever thread has been granted aggressive scheduling via this
4354 * method will return to normal operation, and calling this method will do nothing while
4355 * persistent VR mode is enabled.
4356 *
Srinath Sridharane535a582016-06-27 18:13:47 -07004357 * To reset the VR thread for an application, a tid of 0 can be passed.
4358 *
4359 * @see android.os.Process#myTid()
4360 * @param tid tid of the VR thread
4361 */
4362 public static void setVrThread(int tid) {
4363 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004364 getService().setVrThread(tid);
Srinath Sridharane535a582016-06-27 18:13:47 -07004365 } catch (RemoteException e) {
4366 // pass
4367 }
4368 }
4369
4370 /**
Craig Donnerdc4796c2017-03-08 09:51:47 -08004371 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads that persist
Jeff Sharkey910e0812017-04-21 16:29:27 -06004372 * beyond a single process. Only one thread can be a
Craig Donnerdc4796c2017-03-08 09:51:47 -08004373 * persistent VR thread at a time, and that thread may be subject to restrictions on the amount
4374 * of time it can run. Calling this method will disable aggressive scheduling for non-persistent
4375 * VR threads set via {@link #setVrThread}. If persistent VR mode is disabled then the
4376 * persistent VR thread loses its new scheduling priority; this method must be called again to
4377 * set the persistent thread.
4378 *
4379 * To reset the persistent VR thread, a tid of 0 can be passed.
4380 *
4381 * @see android.os.Process#myTid()
4382 * @param tid tid of the VR thread
4383 * @hide
4384 */
4385 @RequiresPermission(Manifest.permission.RESTRICTED_VR_ACCESS)
4386 public static void setPersistentVrThread(int tid) {
4387 try {
4388 getService().setPersistentVrThread(tid);
4389 } catch (RemoteException e) {
4390 // pass
4391 }
4392 }
4393
4394 /**
Winson Chung1147c402014-05-14 11:05:00 -07004395 * The AppTask allows you to manage your own application's tasks.
4396 * See {@link android.app.ActivityManager#getAppTasks()}
4397 */
4398 public static class AppTask {
4399 private IAppTask mAppTaskImpl;
4400
4401 /** @hide */
4402 public AppTask(IAppTask task) {
4403 mAppTaskImpl = task;
4404 }
4405
4406 /**
4407 * Finishes all activities in this task and removes it from the recent tasks list.
4408 */
4409 public void finishAndRemoveTask() {
4410 try {
4411 mAppTaskImpl.finishAndRemoveTask();
4412 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004413 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004414 }
4415 }
4416
4417 /**
4418 * Get the RecentTaskInfo associated with this task.
4419 *
4420 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
4421 */
4422 public RecentTaskInfo getTaskInfo() {
4423 try {
4424 return mAppTaskImpl.getTaskInfo();
4425 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004426 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004427 }
4428 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004429
4430 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004431 * Bring this task to the foreground. If it contains activities, they will be
4432 * brought to the foreground with it and their instances re-created if needed.
4433 * If it doesn't contain activities, the root activity of the task will be
4434 * re-launched.
4435 */
4436 public void moveToFront() {
4437 try {
4438 mAppTaskImpl.moveToFront();
4439 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004440 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004441 }
4442 }
4443
4444 /**
4445 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004446 * is not currently active (that is, its id < 0), then a new activity for the given
4447 * Intent will be launched as the root of the task and the task brought to the
4448 * foreground. Otherwise, if this task is currently active and the Intent does not specify
4449 * an activity to launch in a new task, then a new activity for the given Intent will
4450 * be launched on top of the task and the task brought to the foreground. If this
4451 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
4452 * or would otherwise be launched in to a new task, then the activity not launched but
4453 * this task be brought to the foreground and a new intent delivered to the top
4454 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004455 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004456 * <p>In other words, you generally want to use an Intent here that does not specify
4457 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
4458 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004459 *
4460 * @param intent The Intent describing the new activity to be launched on the task.
4461 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004462 *
4463 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004464 */
4465 public void startActivity(Context context, Intent intent, Bundle options) {
4466 ActivityThread thread = ActivityThread.currentActivityThread();
4467 thread.getInstrumentation().execStartActivityFromAppTask(context,
4468 thread.getApplicationThread(), mAppTaskImpl, intent, options);
4469 }
4470
4471 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004472 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
4473 * Intent of this AppTask.
4474 *
4475 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
4476 * be set; otherwise, it will be cleared.
4477 */
4478 public void setExcludeFromRecents(boolean exclude) {
4479 try {
4480 mAppTaskImpl.setExcludeFromRecents(exclude);
4481 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004482 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004483 }
4484 }
Winson Chung1147c402014-05-14 11:05:00 -07004485 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004486}