blob: ee7288ffd52c13288c99f3abe75aa59a5a721182 [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
Winson Chungb4132992018-07-03 15:52:38 -070019import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
20
Svet Ganov019d2302015-05-04 11:07:38 -070021import android.Manifest;
Matthew Ng54bc9422017-10-02 17:16:28 -070022import android.annotation.DrawableRes;
Michal Karpinski3da5c972015-12-11 18:16:30 +000023import android.annotation.IntDef;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -070024import android.annotation.NonNull;
25import android.annotation.Nullable;
Svet Ganov019d2302015-05-04 11:07:38 -070026import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070027import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060028import android.annotation.SystemService;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070029import android.annotation.TestApi;
Mathew Inwood61e8ae62018-08-14 14:17:44 +010030import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.ComponentName;
32import android.content.Context;
33import android.content.Intent;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070034import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.content.pm.ConfigurationInfo;
36import android.content.pm.IPackageDataObserver;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070037import android.content.pm.PackageManager;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080038import android.content.pm.ParceledListSlice;
Dianne Hackborn41203752012-08-31 14:05:51 -070039import android.content.pm.UserInfo;
Wale Ogunwale68278562017-09-23 17:13:55 -070040import android.content.res.Configuration;
Kenny Root5ef44b72011-01-26 17:22:20 -080041import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.graphics.Bitmap;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070043import android.graphics.Canvas;
Winson Chunga449dc02014-05-16 11:15:04 -070044import android.graphics.Color;
Peiyong Lin9d427402019-01-23 18:39:06 -080045import android.graphics.ColorSpace;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070046import android.graphics.GraphicBuffer;
47import android.graphics.Matrix;
48import android.graphics.Point;
Craig Mautner967212c2013-04-13 21:10:58 -070049import android.graphics.Rect;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070050import android.os.BatteryStats;
Dianne Hackbornc81983a2017-10-20 16:16:32 -070051import android.os.Binder;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070052import android.os.Build;
53import android.os.Build.VERSION_CODES;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070054import android.os.Bundle;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070055import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.os.Handler;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070057import android.os.IBinder;
Maurice Lam522ecbe2018-12-04 20:21:40 -080058import android.os.LocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.os.Parcel;
60import android.os.Parcelable;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070061import android.os.Process;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070062import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000063import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070064import android.os.SystemProperties;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070065import android.os.UserHandle;
Narayan Kamath695cf722017-12-21 18:32:47 +000066import android.os.WorkSource;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070067import android.util.ArrayMap;
Kenny Root5ef44b72011-01-26 17:22:20 -080068import android.util.DisplayMetrics;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070069import android.util.Singleton;
Winson Chung48a10a52014-08-27 14:36:51 -070070import android.util.Size;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080071
Maurice Lam522ecbe2018-12-04 20:21:40 -080072import com.android.internal.app.LocalePicker;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070073import com.android.internal.app.procstats.ProcessStats;
74import com.android.internal.os.RoSystemProperties;
75import com.android.internal.os.TransferPipe;
76import com.android.internal.util.FastPrintWriter;
Dianne Hackborn337e01a2018-02-27 17:16:37 -080077import com.android.internal.util.MemInfoReader;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070078import com.android.server.LocalServices;
79
Craig Mautner648f69b2014-09-18 14:16:26 -070080import org.xmlpull.v1.XmlSerializer;
Kenny Root5ef44b72011-01-26 17:22:20 -080081
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070082import java.io.FileDescriptor;
83import java.io.FileOutputStream;
Craig Mautner648f69b2014-09-18 14:16:26 -070084import java.io.IOException;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070085import java.io.PrintWriter;
Michal Karpinski3da5c972015-12-11 18:16:30 +000086import java.lang.annotation.Retention;
87import java.lang.annotation.RetentionPolicy;
Winson Chung1147c402014-05-14 11:05:00 -070088import java.util.ArrayList;
Maurice Lam522ecbe2018-12-04 20:21:40 -080089import java.util.Collection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import java.util.List;
Maurice Lam522ecbe2018-12-04 20:21:40 -080091import java.util.Locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93/**
Dave Friedman2a3ebad2017-01-04 18:27:26 -080094 * <p>
95 * This class gives information about, and interacts
96 * with, activities, services, and the containing
97 * process.
98 * </p>
99 *
100 * <p>
101 * A number of the methods in this class are for
102 * debugging or informational purposes and they should
103 * not be used to affect any runtime behavior of
104 * your app. These methods are called out as such in
105 * the method level documentation.
106 * </p>
107 *
108 *<p>
109 * Most application developers should not have the need to
110 * use this class, most of whose methods are for specialized
111 * use cases. However, a few methods are more broadly applicable.
112 * For instance, {@link android.app.ActivityManager#isLowRamDevice() isLowRamDevice()}
113 * enables your app to detect whether it is running on a low-memory device,
114 * and behave accordingly.
115 * {@link android.app.ActivityManager#clearApplicationUserData() clearApplicationUserData()}
116 * is for apps with reset-data functionality.
117 * </p>
118 *
119 * <p>
120 * In some special use cases, where an app interacts with
121 * its Task stack, the app may use the
122 * {@link android.app.ActivityManager.AppTask} and
123 * {@link android.app.ActivityManager.RecentTaskInfo} inner
124 * classes. However, in general, the methods in this class should
125 * be used for testing and debugging purposes only.
126 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600128@SystemService(Context.ACTIVITY_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129public class ActivityManager {
130 private static String TAG = "ActivityManager";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100132 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800135 private static volatile boolean sSystemReady = false;
136
Bryce Lee7f936862017-05-09 15:33:18 -0700137
138 private static final int FIRST_START_FATAL_ERROR_CODE = -100;
139 private static final int LAST_START_FATAL_ERROR_CODE = -1;
140 private static final int FIRST_START_SUCCESS_CODE = 0;
141 private static final int LAST_START_SUCCESS_CODE = 99;
142 private static final int FIRST_START_NON_FATAL_ERROR_CODE = 100;
143 private static final int LAST_START_NON_FATAL_ERROR_CODE = 199;
144
Sudheer Shanka8f99bff2018-10-21 16:19:53 -0700145 /**
146 * Disable hidden API checks for the newly started instrumentation.
147 * @hide
148 */
149 public static final int INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS = 1 << 0;
150 /**
151 * Mount full external storage for the newly started instrumentation.
152 * @hide
153 */
154 public static final int INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL = 1 << 1;
155
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700156 static final class UidObserver extends IUidObserver.Stub {
157 final OnUidImportanceListener mListener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700158 final Context mContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700159
Makoto Onukid7e40582017-04-13 14:54:56 -0700160 UidObserver(OnUidImportanceListener listener, Context clientContext) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700161 mListener = listener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700162 mContext = clientContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700163 }
164
165 @Override
Sudheer Shanka80255802017-03-04 14:48:53 -0800166 public void onUidStateChanged(int uid, int procState, long procStateSeq) {
Makoto Onukid7e40582017-04-13 14:54:56 -0700167 mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportanceForClient(
168 procState, mContext));
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700169 }
170
171 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800172 public void onUidGone(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700173 mListener.onUidImportance(uid, RunningAppProcessInfo.IMPORTANCE_GONE);
174 }
175
176 @Override
177 public void onUidActive(int uid) {
178 }
179
180 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800181 public void onUidIdle(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700182 }
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700183
184 @Override public void onUidCachedChanged(int uid, boolean cached) {
185 }
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700186 }
187
188 final ArrayMap<OnUidImportanceListener, UidObserver> mImportanceListeners = new ArrayMap<>();
189
Felipe Lemedc7af962016-01-22 18:27:03 -0800190 /**
191 * Defines acceptable types of bugreports.
192 * @hide
193 */
Michal Karpinski3da5c972015-12-11 18:16:30 +0000194 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700195 @IntDef(prefix = { "BUGREPORT_OPTION_" }, value = {
Michal Karpinski3da5c972015-12-11 18:16:30 +0000196 BUGREPORT_OPTION_FULL,
197 BUGREPORT_OPTION_INTERACTIVE,
Wei Liu967fc8d2016-07-08 11:44:20 -0700198 BUGREPORT_OPTION_REMOTE,
Felipe Leme9606c3b2017-01-05 14:57:12 -0800199 BUGREPORT_OPTION_WEAR,
mukesh agrawald9e1df52018-01-22 14:07:31 -0800200 BUGREPORT_OPTION_TELEPHONY,
201 BUGREPORT_OPTION_WIFI
Michal Karpinski3da5c972015-12-11 18:16:30 +0000202 })
Michal Karpinski3da5c972015-12-11 18:16:30 +0000203 public @interface BugreportMode {}
204 /**
205 * Takes a bugreport without user interference (and hence causing less
206 * interference to the system), but includes all sections.
207 * @hide
208 */
209 public static final int BUGREPORT_OPTION_FULL = 0;
210 /**
211 * Allows user to monitor progress and enter additional data; might not include all
212 * sections.
213 * @hide
214 */
215 public static final int BUGREPORT_OPTION_INTERACTIVE = 1;
216 /**
217 * Takes a bugreport requested remotely by administrator of the Device Owner app,
218 * not the device's user.
219 * @hide
220 */
221 public static final int BUGREPORT_OPTION_REMOTE = 2;
Wei Liu967fc8d2016-07-08 11:44:20 -0700222 /**
223 * Takes a bugreport on a wearable device.
224 * @hide
225 */
226 public static final int BUGREPORT_OPTION_WEAR = 3;
Michal Karpinski3da5c972015-12-11 18:16:30 +0000227
Dianne Hackborna4972e92012-03-14 10:38:05 -0700228 /**
Felipe Leme9606c3b2017-01-05 14:57:12 -0800229 * Takes a lightweight version of bugreport that only includes a few, urgent sections
230 * used to report telephony bugs.
231 * @hide
232 */
233 public static final int BUGREPORT_OPTION_TELEPHONY = 4;
234
235 /**
mukesh agrawald9e1df52018-01-22 14:07:31 -0800236 * Takes a lightweight bugreport that only includes a few sections related to Wifi.
237 * @hide
238 */
239 public static final int BUGREPORT_OPTION_WIFI = 5;
240
241 /**
Scott Maincc2195b2013-10-16 13:57:46 -0700242 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000243 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
Christopher Tatebd413f62013-09-18 18:31:59 -0700244 * uninstalled in lieu of the declaring one. The package named here must be
Neil Fuller71fbb812015-11-30 09:51:33 +0000245 * signed with the same certificate as the one declaring the {@code <meta-data>}.
Christopher Tatebd413f62013-09-18 18:31:59 -0700246 */
247 public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
248
Bryce Lee7f936862017-05-09 15:33:18 -0700249 // NOTE: Before adding a new start result, please reference the defined ranges to ensure the
250 // result is properly categorized.
251
Christopher Tatebd413f62013-09-18 18:31:59 -0700252 /**
Amith Yamasani42449782016-04-19 11:45:51 -0700253 * Result for IActivityManager.startVoiceActivity: active session is currently hidden.
254 * @hide
255 */
Bryce Lee7f936862017-05-09 15:33:18 -0700256 public static final int START_VOICE_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE;
Amith Yamasani42449782016-04-19 11:45:51 -0700257
258 /**
259 * Result for IActivityManager.startVoiceActivity: active session does not match
260 * the requesting token.
261 * @hide
262 */
Bryce Lee7f936862017-05-09 15:33:18 -0700263 public static final int START_VOICE_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 1;
Amith Yamasani42449782016-04-19 11:45:51 -0700264
265 /**
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700266 * Result for IActivityManager.startActivity: trying to start a background user
267 * activity that shouldn't be displayed for all users.
268 * @hide
269 */
Bryce Lee7f936862017-05-09 15:33:18 -0700270 public static final int START_NOT_CURRENT_USER_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 2;
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700271
272 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700273 * Result for IActivityManager.startActivity: trying to start an activity under voice
274 * control when that activity does not support the VOICE category.
275 * @hide
276 */
Bryce Lee7f936862017-05-09 15:33:18 -0700277 public static final int START_NOT_VOICE_COMPATIBLE = FIRST_START_FATAL_ERROR_CODE + 3;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700278
279 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700280 * Result for IActivityManager.startActivity: an error where the
281 * start had to be canceled.
282 * @hide
283 */
Bryce Lee7f936862017-05-09 15:33:18 -0700284 public static final int START_CANCELED = FIRST_START_FATAL_ERROR_CODE + 4;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700285
286 /**
287 * Result for IActivityManager.startActivity: an error where the
288 * thing being started is not an activity.
289 * @hide
290 */
Bryce Lee7f936862017-05-09 15:33:18 -0700291 public static final int START_NOT_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 5;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700292
293 /**
294 * Result for IActivityManager.startActivity: an error where the
295 * caller does not have permission to start the activity.
296 * @hide
297 */
Bryce Lee7f936862017-05-09 15:33:18 -0700298 public static final int START_PERMISSION_DENIED = FIRST_START_FATAL_ERROR_CODE + 6;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700299
300 /**
301 * Result for IActivityManager.startActivity: an error where the
302 * caller has requested both to forward a result and to receive
303 * a result.
304 * @hide
305 */
Bryce Lee7f936862017-05-09 15:33:18 -0700306 public static final int START_FORWARD_AND_REQUEST_CONFLICT = FIRST_START_FATAL_ERROR_CODE + 7;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700307
308 /**
309 * Result for IActivityManager.startActivity: an error where the
310 * requested class is not found.
311 * @hide
312 */
Bryce Lee7f936862017-05-09 15:33:18 -0700313 public static final int START_CLASS_NOT_FOUND = FIRST_START_FATAL_ERROR_CODE + 8;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700314
315 /**
316 * Result for IActivityManager.startActivity: an error where the
317 * given Intent could not be resolved to an activity.
318 * @hide
319 */
Bryce Lee7f936862017-05-09 15:33:18 -0700320 public static final int START_INTENT_NOT_RESOLVED = FIRST_START_FATAL_ERROR_CODE + 9;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700321
322 /**
Winson Chungfc3ec4c2017-06-01 15:35:48 -0700323 * Result for IActivityManager.startAssistantActivity: active session is currently hidden.
324 * @hide
325 */
326 public static final int START_ASSISTANT_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE + 10;
327
328 /**
329 * Result for IActivityManager.startAssistantActivity: active session does not match
330 * the requesting token.
331 * @hide
332 */
333 public static final int START_ASSISTANT_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 11;
334
335 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700336 * Result for IActivityManaqer.startActivity: the activity was started
337 * successfully as normal.
338 * @hide
339 */
Bryce Lee7f936862017-05-09 15:33:18 -0700340 public static final int START_SUCCESS = FIRST_START_SUCCESS_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700341
342 /**
343 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not
344 * be executed if it is the recipient, and that is indeed the case.
345 * @hide
346 */
Bryce Lee7f936862017-05-09 15:33:18 -0700347 public static final int START_RETURN_INTENT_TO_CALLER = FIRST_START_SUCCESS_CODE + 1;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700348
349 /**
350 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
351 * a task was simply brought to the foreground.
352 * @hide
353 */
Bryce Lee7f936862017-05-09 15:33:18 -0700354 public static final int START_TASK_TO_FRONT = FIRST_START_SUCCESS_CODE + 2;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700355
356 /**
357 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
358 * the given Intent was given to the existing top activity.
359 * @hide
360 */
Bryce Lee7f936862017-05-09 15:33:18 -0700361 public static final int START_DELIVERED_TO_TOP = FIRST_START_SUCCESS_CODE + 3;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700362
363 /**
364 * Result for IActivityManaqer.startActivity: request was canceled because
365 * app switches are temporarily canceled to ensure the user's last request
366 * (such as pressing home) is performed.
367 * @hide
368 */
Bryce Lee7f936862017-05-09 15:33:18 -0700369 public static final int START_SWITCHES_CANCELED = FIRST_START_NON_FATAL_ERROR_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700370
371 /**
Craig Mautneraea74a52014-03-08 14:23:10 -0800372 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started
373 * while in Lock Task Mode.
374 * @hide
375 */
Bryce Lee7f936862017-05-09 15:33:18 -0700376 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION =
377 FIRST_START_NON_FATAL_ERROR_CODE + 1;
Craig Mautneraea74a52014-03-08 14:23:10 -0800378
379 /**
Bryce Leef9d49542017-06-26 16:27:32 -0700380 * Result for IActivityManaqer.startActivity: a new activity start was aborted. Never returned
381 * externally.
382 * @hide
383 */
384 public static final int START_ABORTED = FIRST_START_NON_FATAL_ERROR_CODE + 2;
385
386 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700387 * Flag for IActivityManaqer.startActivity: do special start mode where
388 * a new activity is launched only if it is needed.
389 * @hide
390 */
391 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
392
393 /**
394 * Flag for IActivityManaqer.startActivity: launch the app for
395 * debugging.
396 * @hide
397 */
398 public static final int START_FLAG_DEBUG = 1<<1;
399
400 /**
401 * Flag for IActivityManaqer.startActivity: launch the app for
Man Caocfa78b22015-06-11 20:14:34 -0700402 * allocation tracking.
403 * @hide
404 */
Pablo Ceballosa4d4e822015-10-05 10:27:52 -0700405 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2;
Man Caocfa78b22015-06-11 20:14:34 -0700406
407 /**
Tamas Berghammerdf6cb282016-01-29 12:07:00 +0000408 * Flag for IActivityManaqer.startActivity: launch the app with
409 * native debugging support.
410 * @hide
411 */
412 public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3;
413
414 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700415 * Result for IActivityManaqer.broadcastIntent: success!
416 * @hide
417 */
418 public static final int BROADCAST_SUCCESS = 0;
419
420 /**
421 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast
422 * a sticky intent without appropriate permission.
423 * @hide
424 */
425 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
426
427 /**
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800428 * Result for IActivityManager.broadcastIntent: trying to send a broadcast
429 * to a stopped user. Fail.
430 * @hide
431 */
432 public static final int BROADCAST_FAILED_USER_STOPPED = -2;
433
434 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700435 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
436 * for a sendBroadcast operation.
437 * @hide
438 */
439 public static final int INTENT_SENDER_BROADCAST = 1;
440
441 /**
442 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
443 * for a startActivity operation.
444 * @hide
445 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100446 @UnsupportedAppUsage
Dianne Hackborna4972e92012-03-14 10:38:05 -0700447 public static final int INTENT_SENDER_ACTIVITY = 2;
448
449 /**
450 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
451 * for an activity result operation.
452 * @hide
453 */
454 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
455
456 /**
457 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
458 * for a startService operation.
459 * @hide
460 */
461 public static final int INTENT_SENDER_SERVICE = 4;
462
Christopher Tate08992ac2017-03-21 11:37:06 -0700463 /**
464 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
465 * for a startForegroundService operation.
466 * @hide
467 */
468 public static final int INTENT_SENDER_FOREGROUND_SERVICE = 5;
469
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700470 /** @hide User operation call: success! */
471 public static final int USER_OP_SUCCESS = 0;
472
473 /** @hide User operation call: given user id is not known. */
474 public static final int USER_OP_UNKNOWN_USER = -1;
475
476 /** @hide User operation call: given user id is the current user, can't be stopped. */
477 public static final int USER_OP_IS_CURRENT = -2;
478
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700479 /** @hide User operation call: system user can't be stopped. */
480 public static final int USER_OP_ERROR_IS_SYSTEM = -3;
481
482 /** @hide User operation call: one of related users cannot be stopped. */
483 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4;
484
Dianne Hackbornf097d422017-12-15 16:32:19 -0800485 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800486 * @hide
Dianne Hackbornf097d422017-12-15 16:32:19 -0800487 * Process states, describing the kind of state a particular process is in.
488 * When updating these, make sure to also check all related references to the
489 * constant in code, and update these arrays:
490 *
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800491 * @see com.android.internal.app.procstats.ProcessState#PROCESS_STATE_TO_STATE
492 * @see com.android.server.am.ProcessList#sProcStateToProcMem
493 * @see com.android.server.am.ProcessList#sFirstAwakePssTimes
494 * @see com.android.server.am.ProcessList#sSameAwakePssTimes
495 * @see com.android.server.am.ProcessList#sTestFirstPssTimes
496 * @see com.android.server.am.ProcessList#sTestSamePssTimes
Dianne Hackbornf097d422017-12-15 16:32:19 -0800497 */
498
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800499 /** @hide Not a real process state. */
500 public static final int PROCESS_STATE_UNKNOWN = -1;
Ruben Brunka27eef42015-01-28 15:04:16 -0800501
Dianne Hackborna413dc02013-07-12 12:02:55 -0700502 /** @hide Process is a persistent system process. */
503 public static final int PROCESS_STATE_PERSISTENT = 0;
504
505 /** @hide Process is a persistent system process and is doing UI. */
506 public static final int PROCESS_STATE_PERSISTENT_UI = 1;
507
Dianne Hackbornc8230512013-07-13 21:32:12 -0700508 /** @hide Process is hosting the current top activities. Note that this covers
509 * all activities that are visible to the user. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100510 @UnsupportedAppUsage
Dianne Hackborna413dc02013-07-12 12:02:55 -0700511 public static final int PROCESS_STATE_TOP = 2;
512
Amith Yamasania0a30a12019-01-22 11:38:06 -0800513 /** @hide Process is hosting a foreground service with location type. */
514 public static final int PROCESS_STATE_FOREGROUND_SERVICE_LOCATION = 3;
515
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700516 /** @hide Process is hosting a foreground service. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100517 @UnsupportedAppUsage
Amith Yamasania0a30a12019-01-22 11:38:06 -0800518 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4;
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -0800519
520 /** @hide Process is hosting a foreground service due to a system binding. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100521 @UnsupportedAppUsage
Amith Yamasania0a30a12019-01-22 11:38:06 -0800522 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 5;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700523
Dianne Hackborna413dc02013-07-12 12:02:55 -0700524 /** @hide Process is important to the user, and something they are aware of. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800525 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700526
527 /** @hide Process is important to the user, but not something they are aware of. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100528 @UnsupportedAppUsage
Amith Yamasania0a30a12019-01-22 11:38:06 -0800529 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700530
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700531 /** @hide Process is in the background transient so we will try to keep running. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800532 public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 8;
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700533
Dianne Hackborna413dc02013-07-12 12:02:55 -0700534 /** @hide Process is in the background running a backup/restore operation. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800535 public static final int PROCESS_STATE_BACKUP = 9;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700536
Dianne Hackbornc8230512013-07-13 21:32:12 -0700537 /** @hide Process is in the background running a service. Unlike oom_adj, this level
538 * is used for both the normal running in background state and the executing
539 * operations state. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100540 @UnsupportedAppUsage
Amith Yamasania0a30a12019-01-22 11:38:06 -0800541 public static final int PROCESS_STATE_SERVICE = 10;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700542
Dianne Hackbornc8230512013-07-13 21:32:12 -0700543 /** @hide Process is in the background running a receiver. Note that from the
Kweku Adamse6b00c22017-10-23 16:46:45 -0700544 * perspective of oom_adj, receivers run at a higher foreground level, but for our
Dianne Hackbornc8230512013-07-13 21:32:12 -0700545 * prioritization here that is not necessary and putting them below services means
546 * many fewer changes in some process states as they receive broadcasts. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100547 @UnsupportedAppUsage
Amith Yamasania0a30a12019-01-22 11:38:06 -0800548 public static final int PROCESS_STATE_RECEIVER = 11;
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800549
550 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800551 public static final int PROCESS_STATE_TOP_SLEEPING = 12;
Dianne Hackbornf097d422017-12-15 16:32:19 -0800552
553 /** @hide Process is in the background, but it can't restore its state so we want
554 * to try to avoid killing it. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800555 public static final int PROCESS_STATE_HEAVY_WEIGHT = 13;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700556
Dianne Hackborna413dc02013-07-12 12:02:55 -0700557 /** @hide Process is in the background but hosts the home activity. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100558 @UnsupportedAppUsage
Amith Yamasania0a30a12019-01-22 11:38:06 -0800559 public static final int PROCESS_STATE_HOME = 14;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700560
561 /** @hide Process is in the background but hosts the last shown activity. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800562 public static final int PROCESS_STATE_LAST_ACTIVITY = 15;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700563
Dianne Hackbornc8230512013-07-13 21:32:12 -0700564 /** @hide Process is being cached for later use and contains activities. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100565 @UnsupportedAppUsage
Amith Yamasania0a30a12019-01-22 11:38:06 -0800566 public static final int PROCESS_STATE_CACHED_ACTIVITY = 16;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700567
568 /** @hide Process is being cached for later use and is a client of another cached
569 * process that contains activities. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800570 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 17;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700571
Dianne Hackborn68a06332017-11-15 17:54:18 -0800572 /** @hide Process is being cached for later use and has an activity that corresponds
573 * to an existing recent task. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800574 public static final int PROCESS_STATE_CACHED_RECENT = 18;
Dianne Hackborn68a06332017-11-15 17:54:18 -0800575
Dianne Hackbornc8230512013-07-13 21:32:12 -0700576 /** @hide Process is being cached for later use and is empty. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800577 public static final int PROCESS_STATE_CACHED_EMPTY = 19;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700578
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800579 /** @hide Process does not exist. */
Amith Yamasania0a30a12019-01-22 11:38:06 -0800580 public static final int PROCESS_STATE_NONEXISTENT = 20;
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800581
Bookatzdb026a22018-01-10 19:01:56 -0800582 // NOTE: If PROCESS_STATEs are added, then new fields must be added
583 // to frameworks/base/core/proto/android/app/enums.proto and the following method must
Kweku Adamse6b00c22017-10-23 16:46:45 -0700584 // be updated to correctly map between them.
Bookatzdb026a22018-01-10 19:01:56 -0800585 // However, if the current ActivityManager values are merely modified, no update should be made
586 // to enums.proto, to which values can only be added but never modified. Note that the proto
587 // versions do NOT have the ordering restrictions of the ActivityManager process state.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700588 /**
Bookatzdb026a22018-01-10 19:01:56 -0800589 * Maps ActivityManager.PROCESS_STATE_ values to enums.proto ProcessStateEnum value.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700590 *
591 * @param amInt a process state of the form ActivityManager.PROCESS_STATE_
Bookatzdb026a22018-01-10 19:01:56 -0800592 * @return the value of the corresponding enums.proto ProcessStateEnum value.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700593 * @hide
594 */
595 public static final int processStateAmToProto(int amInt) {
Bookatzdb026a22018-01-10 19:01:56 -0800596 switch (amInt) {
597 case PROCESS_STATE_UNKNOWN:
598 return AppProtoEnums.PROCESS_STATE_UNKNOWN;
599 case PROCESS_STATE_PERSISTENT:
600 return AppProtoEnums.PROCESS_STATE_PERSISTENT;
601 case PROCESS_STATE_PERSISTENT_UI:
602 return AppProtoEnums.PROCESS_STATE_PERSISTENT_UI;
603 case PROCESS_STATE_TOP:
604 return AppProtoEnums.PROCESS_STATE_TOP;
Amith Yamasania0a30a12019-01-22 11:38:06 -0800605 case PROCESS_STATE_FOREGROUND_SERVICE_LOCATION:
Bookatzdb026a22018-01-10 19:01:56 -0800606 case PROCESS_STATE_FOREGROUND_SERVICE:
607 return AppProtoEnums.PROCESS_STATE_FOREGROUND_SERVICE;
608 case PROCESS_STATE_BOUND_FOREGROUND_SERVICE:
609 return AppProtoEnums.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
610 case PROCESS_STATE_IMPORTANT_FOREGROUND:
611 return AppProtoEnums.PROCESS_STATE_IMPORTANT_FOREGROUND;
612 case PROCESS_STATE_IMPORTANT_BACKGROUND:
613 return AppProtoEnums.PROCESS_STATE_IMPORTANT_BACKGROUND;
614 case PROCESS_STATE_TRANSIENT_BACKGROUND:
615 return AppProtoEnums.PROCESS_STATE_TRANSIENT_BACKGROUND;
616 case PROCESS_STATE_BACKUP:
617 return AppProtoEnums.PROCESS_STATE_BACKUP;
618 case PROCESS_STATE_SERVICE:
619 return AppProtoEnums.PROCESS_STATE_SERVICE;
620 case PROCESS_STATE_RECEIVER:
621 return AppProtoEnums.PROCESS_STATE_RECEIVER;
622 case PROCESS_STATE_TOP_SLEEPING:
623 return AppProtoEnums.PROCESS_STATE_TOP_SLEEPING;
624 case PROCESS_STATE_HEAVY_WEIGHT:
625 return AppProtoEnums.PROCESS_STATE_HEAVY_WEIGHT;
626 case PROCESS_STATE_HOME:
627 return AppProtoEnums.PROCESS_STATE_HOME;
628 case PROCESS_STATE_LAST_ACTIVITY:
629 return AppProtoEnums.PROCESS_STATE_LAST_ACTIVITY;
630 case PROCESS_STATE_CACHED_ACTIVITY:
631 return AppProtoEnums.PROCESS_STATE_CACHED_ACTIVITY;
632 case PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
633 return AppProtoEnums.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
634 case PROCESS_STATE_CACHED_RECENT:
635 return AppProtoEnums.PROCESS_STATE_CACHED_RECENT;
636 case PROCESS_STATE_CACHED_EMPTY:
637 return AppProtoEnums.PROCESS_STATE_CACHED_EMPTY;
638 case PROCESS_STATE_NONEXISTENT:
639 return AppProtoEnums.PROCESS_STATE_NONEXISTENT;
640 default:
641 // ActivityManager process state (amInt)
642 // could not be mapped to an AppProtoEnums ProcessState state.
643 return AppProtoEnums.PROCESS_STATE_UNKNOWN_TO_PROTO;
644 }
Kweku Adamse6b00c22017-10-23 16:46:45 -0700645 }
646
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700647 /** @hide The lowest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800648 public static final int MIN_PROCESS_STATE = PROCESS_STATE_PERSISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700649
650 /** @hide The highest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800651 public static final int MAX_PROCESS_STATE = PROCESS_STATE_NONEXISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700652
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700653 /** @hide Should this process state be considered a background state? */
654 public static final boolean isProcStateBackground(int procState) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700655 return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700656 }
657
Amith Yamasania0a30a12019-01-22 11:38:06 -0800658 /** @hide Is this a foreground service type? */
659 public static boolean isForegroundService(int procState) {
660 return procState == PROCESS_STATE_FOREGROUND_SERVICE_LOCATION
661 || procState == PROCESS_STATE_FOREGROUND_SERVICE;
662 }
663
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700664 /** @hide requestType for assist context: only basic information. */
665 public static final int ASSIST_CONTEXT_BASIC = 0;
666
667 /** @hide requestType for assist context: generate full AssistStructure. */
668 public static final int ASSIST_CONTEXT_FULL = 1;
669
Felipe Leme640f30a2017-03-06 15:44:06 -0800670 /** @hide requestType for assist context: generate full AssistStructure for autofill. */
671 public static final int ASSIST_CONTEXT_AUTOFILL = 2;
Felipe Leme6d553872016-12-08 17:13:25 -0800672
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700673 /** @hide Flag for registerUidObserver: report changes in process state. */
674 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
675
676 /** @hide Flag for registerUidObserver: report uid gone. */
677 public static final int UID_OBSERVER_GONE = 1<<1;
678
679 /** @hide Flag for registerUidObserver: report uid has become idle. */
680 public static final int UID_OBSERVER_IDLE = 1<<2;
681
682 /** @hide Flag for registerUidObserver: report uid has become active. */
683 public static final int UID_OBSERVER_ACTIVE = 1<<3;
684
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700685 /** @hide Flag for registerUidObserver: report uid cached state has changed. */
686 public static final int UID_OBSERVER_CACHED = 1<<4;
687
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800688 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700689 public static final int APP_START_MODE_NORMAL = 0;
690
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800691 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700692 public static final int APP_START_MODE_DELAYED = 1;
693
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800694 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later, with
Dianne Hackborn85e35642017-01-12 15:10:57 -0800695 * rigid errors (throwing exception). */
696 public static final int APP_START_MODE_DELAYED_RIGID = 2;
697
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800698 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: disable/cancel pending
Dianne Hackborn85e35642017-01-12 15:10:57 -0800699 * launches; this is the mode for ephemeral apps. */
700 public static final int APP_START_MODE_DISABLED = 3;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700701
Benjamin Franz43261142015-02-11 15:59:44 +0000702 /**
703 * Lock task mode is not active.
704 */
705 public static final int LOCK_TASK_MODE_NONE = 0;
706
707 /**
708 * Full lock task mode is active.
709 */
710 public static final int LOCK_TASK_MODE_LOCKED = 1;
711
712 /**
713 * App pinning mode is active.
714 */
715 public static final int LOCK_TASK_MODE_PINNED = 2;
716
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700717 Point mAppTaskThumbnailSize;
718
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100719 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 /*package*/ ActivityManager(Context context, Handler handler) {
721 mContext = context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 }
723
724 /**
Bryce Lee7f936862017-05-09 15:33:18 -0700725 * Returns whether the launch was successful.
726 * @hide
727 */
728 public static final boolean isStartResultSuccessful(int result) {
729 return FIRST_START_SUCCESS_CODE <= result && result <= LAST_START_SUCCESS_CODE;
730 }
731
732 /**
733 * Returns whether the launch result was a fatal error.
734 * @hide
735 */
736 public static final boolean isStartResultFatalError(int result) {
737 return FIRST_START_FATAL_ERROR_CODE <= result && result <= LAST_START_FATAL_ERROR_CODE;
738 }
739
740 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700741 * Screen compatibility mode: the application most always run in
742 * compatibility mode.
743 * @hide
744 */
745 public static final int COMPAT_MODE_ALWAYS = -1;
746
747 /**
748 * Screen compatibility mode: the application can never run in
749 * compatibility mode.
750 * @hide
751 */
752 public static final int COMPAT_MODE_NEVER = -2;
753
754 /**
755 * Screen compatibility mode: unknown.
756 * @hide
757 */
758 public static final int COMPAT_MODE_UNKNOWN = -3;
759
760 /**
761 * Screen compatibility mode: the application currently has compatibility
762 * mode disabled.
763 * @hide
764 */
765 public static final int COMPAT_MODE_DISABLED = 0;
766
767 /**
768 * Screen compatibility mode: the application currently has compatibility
769 * mode enabled.
770 * @hide
771 */
772 public static final int COMPAT_MODE_ENABLED = 1;
773
774 /**
775 * Screen compatibility mode: request to toggle the application's
776 * compatibility mode.
777 * @hide
778 */
779 public static final int COMPAT_MODE_TOGGLE = 2;
780
Marc Hittinger17fb5962017-04-05 15:34:38 -0700781 private static final boolean DEVELOPMENT_FORCE_LOW_RAM =
782 SystemProperties.getBoolean("debug.force_low_ram", false);
783
Wale Ogunwale3797c222015-10-27 14:21:58 -0700784 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700785 public int getFrontActivityScreenCompatMode() {
786 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700787 return getTaskService().getFrontActivityScreenCompatMode();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700788 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700789 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700790 }
791 }
792
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700793 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700794 public void setFrontActivityScreenCompatMode(int mode) {
795 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700796 getTaskService().setFrontActivityScreenCompatMode(mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700797 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700798 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700799 }
800 }
801
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700802 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700803 public int getPackageScreenCompatMode(String packageName) {
804 try {
Wale Ogunwale53783742018-09-16 10:21:51 -0700805 return getTaskService().getPackageScreenCompatMode(packageName);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700806 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700807 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700808 }
809 }
810
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700811 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700812 public void setPackageScreenCompatMode(String packageName, int mode) {
813 try {
Wale Ogunwale53783742018-09-16 10:21:51 -0700814 getTaskService().setPackageScreenCompatMode(packageName, mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700815 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700816 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700817 }
818 }
819
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700820 /** @hide */
821 public boolean getPackageAskScreenCompat(String packageName) {
822 try {
Wale Ogunwale53783742018-09-16 10:21:51 -0700823 return getTaskService().getPackageAskScreenCompat(packageName);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700824 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700825 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700826 }
827 }
828
829 /** @hide */
830 public void setPackageAskScreenCompat(String packageName, boolean ask) {
831 try {
Wale Ogunwale53783742018-09-16 10:21:51 -0700832 getTaskService().setPackageAskScreenCompat(packageName, ask);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700833 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700834 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700835 }
836 }
837
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700838 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700839 * Return the approximate per-application memory class of the current
840 * device. This gives you an idea of how hard a memory limit you should
841 * impose on your application to let the overall system work best. The
842 * returned value is in megabytes; the baseline Android memory class is
843 * 16 (which happens to be the Java heap limit of those devices); some
Kweku Adams983829f2017-12-06 14:53:50 -0800844 * devices with more memory may return 24 or even higher numbers.
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700845 */
846 public int getMemoryClass() {
847 return staticGetMemoryClass();
848 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700849
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700850 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100851 @UnsupportedAppUsage
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700852 static public int staticGetMemoryClass() {
853 // Really brain dead right now -- just take this from the configured
854 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -0800855 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -0800856 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
857 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
858 }
859 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800860 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700861
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800862 /**
863 * Return the approximate per-application memory class of the current
864 * device when an application is running with a large heap. This is the
865 * space available for memory-intensive applications; most applications
866 * should not need this amount of memory, and should instead stay with the
867 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
868 * This may be the same size as {@link #getMemoryClass()} on memory
869 * constrained devices, or it may be significantly larger on devices with
870 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800871 *
Kweku Adams983829f2017-12-06 14:53:50 -0800872 * <p>This is the size of the application's Dalvik heap if it has
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800873 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800874 */
875 public int getLargeMemoryClass() {
876 return staticGetLargeMemoryClass();
877 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700878
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800879 /** @hide */
880 static public int staticGetLargeMemoryClass() {
881 // Really brain dead right now -- just take this from the configured
882 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700883 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -0700884 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700885 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700886
887 /**
888 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
889 * is ultimately up to the device configuration, but currently it generally means
Greg Kaisere2c459e2017-10-26 10:36:37 -0700890 * something with 1GB or less of RAM. This is mostly intended to be used by apps
891 * to determine whether they should turn off certain features that require more RAM.
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700892 */
893 public boolean isLowRamDevice() {
894 return isLowRamDeviceStatic();
895 }
896
897 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100898 @UnsupportedAppUsage
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700899 public static boolean isLowRamDeviceStatic() {
Marc Hittinger17fb5962017-04-05 15:34:38 -0700900 return RoSystemProperties.CONFIG_LOW_RAM ||
901 (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700902 }
903
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700904 /**
Michael Kwan15eb9982017-04-14 12:34:46 -0700905 * Returns true if this is a small battery device. Exactly whether a device is considered to be
906 * small battery is ultimately up to the device configuration, but currently it generally means
907 * something in the class of a device with 1000 mAh or less. This is mostly intended to be used
908 * to determine whether certain features should be altered to account for a drastically smaller
909 * battery.
910 * @hide
911 */
912 public static boolean isSmallBatteryDevice() {
913 return RoSystemProperties.CONFIG_SMALL_BATTERY;
914 }
915
916 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -0700917 * Used by persistent processes to determine if they are running on a
918 * higher-end device so should be okay using hardware drawing acceleration
919 * (which tends to consume a lot more RAM).
920 * @hide
921 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100922 @UnsupportedAppUsage
Jeff Brown98365d72012-08-19 20:30:52 -0700923 static public boolean isHighEndGfx() {
Luis Hector Chavez5e11e5e2018-03-23 14:37:01 -0700924 return !isLowRamDeviceStatic()
925 && !RoSystemProperties.CONFIG_AVOID_GFX_ACCEL
926 && !Resources.getSystem()
927 .getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -0700928 }
929
930 /**
Dianne Hackborn337e01a2018-02-27 17:16:37 -0800931 * Return the total number of bytes of RAM this device has.
932 * @hide
933 */
934 @TestApi
935 public long getTotalRam() {
936 MemInfoReader memreader = new MemInfoReader();
937 memreader.readMemInfo();
938 return memreader.getTotalSize();
939 }
940
941 /**
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700942 * TODO(b/80414790): Remove once no longer on hiddenapi-light-greylist.txt
Dianne Hackborn852975d2014-08-22 17:42:43 -0700943 * @hide
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700944 * @deprecated Use {@link ActivityTaskManager#getMaxRecentTasksStatic()}
Dianne Hackborn852975d2014-08-22 17:42:43 -0700945 */
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700946 @Deprecated
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100947 @UnsupportedAppUsage
Dianne Hackborn852975d2014-08-22 17:42:43 -0700948 static public int getMaxRecentTasksStatic() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700949 return ActivityTaskManager.getMaxRecentTasksStatic();
Matthew Ng626e0cc2016-12-07 17:25:53 -0800950 }
951
Jeff Sharkey000ce802017-04-29 13:13:27 -0600952 /** @removed */
Winson Chung709904f2017-04-25 11:00:48 -0700953 @Deprecated
Winson Chunga29eb982016-12-14 12:01:27 -0800954 public static int getMaxNumPictureInPictureActions() {
Winson Chung709904f2017-04-25 11:00:48 -0700955 return 3;
Winson Chunga29eb982016-12-14 12:01:27 -0800956 }
957
958 /**
Winson Chung1147c402014-05-14 11:05:00 -0700959 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -0700960 */
Winson Chunga449dc02014-05-16 11:15:04 -0700961 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -0700962 /** @hide */
963 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
964 private static final String ATTR_TASKDESCRIPTIONLABEL =
965 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +0000966 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -0700967 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +0000968 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
969 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Matthew Ng54bc9422017-10-02 17:16:28 -0700970 private static final String ATTR_TASKDESCRIPTIONICON_FILENAME =
Craig Mautner648f69b2014-09-18 14:16:26 -0700971 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
Matthew Ng54bc9422017-10-02 17:16:28 -0700972 private static final String ATTR_TASKDESCRIPTIONICON_RESOURCE =
973 ATTR_TASKDESCRIPTION_PREFIX + "icon_resource";
Craig Mautner648f69b2014-09-18 14:16:26 -0700974
Winson Chunga449dc02014-05-16 11:15:04 -0700975 private String mLabel;
976 private Bitmap mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -0700977 private int mIconRes;
Craig Mautner648f69b2014-09-18 14:16:26 -0700978 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -0700979 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +0000980 private int mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +0200981 private int mStatusBarColor;
982 private int mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -0700983
984 /**
Winson Chunga449dc02014-05-16 11:15:04 -0700985 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -0700986 *
Winson Chunga449dc02014-05-16 11:15:04 -0700987 * @param label A label and description of the current state of this task.
988 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +0000989 * @param colorPrimary A color to override the theme's primary color. This color must be
990 * opaque.
Matthew Ng54bc9422017-10-02 17:16:28 -0700991 * @deprecated use TaskDescription constructor with icon resource instead
Winson Chung03a9bae2014-05-02 09:56:12 -0700992 */
Matthew Ng54bc9422017-10-02 17:16:28 -0700993 @Deprecated
Winson Chunga449dc02014-05-16 11:15:04 -0700994 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Matthew Ng54bc9422017-10-02 17:16:28 -0700995 this(label, icon, 0, null, colorPrimary, 0, 0, 0);
996 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
997 throw new RuntimeException("A TaskDescription's primary color should be opaque");
998 }
999 }
1000
1001 /**
1002 * Creates the TaskDescription to the specified values.
1003 *
1004 * @param label A label and description of the current state of this task.
1005 * @param iconRes A drawable resource of an icon that represents the current state of this
1006 * activity.
1007 * @param colorPrimary A color to override the theme's primary color. This color must be
1008 * opaque.
1009 */
1010 public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary) {
1011 this(label, null, iconRes, null, colorPrimary, 0, 0, 0);
Winson Chunga449dc02014-05-16 11:15:04 -07001012 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1013 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1014 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001015 }
1016
Winson Chung03a9bae2014-05-02 09:56:12 -07001017 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001018 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001019 *
1020 * @param label A label and description of the current state of this activity.
1021 * @param icon An icon that represents the current state of this activity.
Matthew Ng54bc9422017-10-02 17:16:28 -07001022 * @deprecated use TaskDescription constructor with icon resource instead
Winson Chung03a9bae2014-05-02 09:56:12 -07001023 */
Matthew Ng54bc9422017-10-02 17:16:28 -07001024 @Deprecated
Winson Chunga449dc02014-05-16 11:15:04 -07001025 public TaskDescription(String label, Bitmap icon) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001026 this(label, icon, 0, null, 0, 0, 0, 0);
1027 }
1028
1029 /**
1030 * Creates the TaskDescription to the specified values.
1031 *
1032 * @param label A label and description of the current state of this activity.
1033 * @param iconRes A drawable resource of an icon that represents the current state of this
1034 * activity.
1035 */
1036 public TaskDescription(String label, @DrawableRes int iconRes) {
1037 this(label, null, iconRes, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001038 }
1039
1040 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001041 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001042 *
1043 * @param label A label and description of the current state of this activity.
1044 */
Winson Chunga449dc02014-05-16 11:15:04 -07001045 public TaskDescription(String label) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001046 this(label, null, 0, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001047 }
1048
Winson Chunga449dc02014-05-16 11:15:04 -07001049 /**
1050 * Creates an empty TaskDescription.
1051 */
1052 public TaskDescription() {
Matthew Ng54bc9422017-10-02 17:16:28 -07001053 this(null, null, 0, null, 0, 0, 0, 0);
Winson Chung1af8eda2016-02-05 17:55:56 +00001054 }
1055
1056 /** @hide */
Matthew Ng54bc9422017-10-02 17:16:28 -07001057 public TaskDescription(String label, Bitmap bitmap, int iconRes, String iconFilename,
1058 int colorPrimary, int colorBackground, int statusBarColor, int navigationBarColor) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001059 mLabel = label;
Matthew Ng54bc9422017-10-02 17:16:28 -07001060 mIcon = bitmap;
1061 mIconRes = iconRes;
Winson Chung1af8eda2016-02-05 17:55:56 +00001062 mIconFilename = iconFilename;
1063 mColorPrimary = colorPrimary;
1064 mColorBackground = colorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001065 mStatusBarColor = statusBarColor;
1066 mNavigationBarColor = navigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001067 }
1068
Winson Chunga449dc02014-05-16 11:15:04 -07001069 /**
1070 * Creates a copy of another TaskDescription.
1071 */
1072 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -08001073 copyFrom(td);
1074 }
1075
1076 /**
1077 * Copies this the values from another TaskDescription.
1078 * @hide
1079 */
1080 public void copyFrom(TaskDescription other) {
1081 mLabel = other.mLabel;
1082 mIcon = other.mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001083 mIconRes = other.mIconRes;
Winsonb6403152016-02-23 13:32:09 -08001084 mIconFilename = other.mIconFilename;
1085 mColorPrimary = other.mColorPrimary;
1086 mColorBackground = other.mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001087 mStatusBarColor = other.mStatusBarColor;
1088 mNavigationBarColor = other.mNavigationBarColor;
Winson Chunga449dc02014-05-16 11:15:04 -07001089 }
1090
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001091 /**
1092 * Copies this the values from another TaskDescription, but preserves the hidden fields
1093 * if they weren't set on {@code other}
1094 * @hide
1095 */
1096 public void copyFromPreserveHiddenFields(TaskDescription other) {
1097 mLabel = other.mLabel;
1098 mIcon = other.mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001099 mIconRes = other.mIconRes;
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001100 mIconFilename = other.mIconFilename;
1101 mColorPrimary = other.mColorPrimary;
1102 if (other.mColorBackground != 0) {
1103 mColorBackground = other.mColorBackground;
1104 }
1105 if (other.mStatusBarColor != 0) {
1106 mStatusBarColor = other.mStatusBarColor;
1107 }
1108 if (other.mNavigationBarColor != 0) {
1109 mNavigationBarColor = other.mNavigationBarColor;
1110 }
1111 }
1112
Winson Chunga449dc02014-05-16 11:15:04 -07001113 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001114 readFromParcel(source);
1115 }
1116
1117 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001118 * Sets the label for this task description.
1119 * @hide
1120 */
1121 public void setLabel(String label) {
1122 mLabel = label;
1123 }
1124
1125 /**
1126 * Sets the primary color for this task description.
1127 * @hide
1128 */
1129 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001130 // Ensure that the given color is valid
1131 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1132 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1133 }
1134 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001135 }
1136
1137 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001138 * Sets the background color for this task description.
1139 * @hide
1140 */
1141 public void setBackgroundColor(int backgroundColor) {
1142 // Ensure that the given color is valid
1143 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1144 throw new RuntimeException("A TaskDescription's background color should be opaque");
1145 }
1146 mColorBackground = backgroundColor;
1147 }
1148
1149 /**
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001150 * @hide
1151 */
1152 public void setStatusBarColor(int statusBarColor) {
1153 mStatusBarColor = statusBarColor;
1154 }
1155
1156 /**
1157 * @hide
1158 */
1159 public void setNavigationBarColor(int navigationBarColor) {
1160 mNavigationBarColor = navigationBarColor;
1161 }
1162
1163 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001164 * Sets the icon for this task description.
1165 * @hide
1166 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001167 @UnsupportedAppUsage
Winson Chung2cb86c72014-06-25 12:03:30 -07001168 public void setIcon(Bitmap icon) {
1169 mIcon = icon;
1170 }
1171
1172 /**
Matthew Ng54bc9422017-10-02 17:16:28 -07001173 * Sets the icon resource for this task description.
1174 * @hide
1175 */
1176 public void setIcon(int iconRes) {
1177 mIconRes = iconRes;
1178 }
1179
1180 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001181 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1182 * bitmap.
1183 * @hide
1184 */
1185 public void setIconFilename(String iconFilename) {
1186 mIconFilename = iconFilename;
1187 mIcon = null;
1188 }
1189
1190 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001191 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001192 */
Winson Chunga449dc02014-05-16 11:15:04 -07001193 public String getLabel() {
1194 return mLabel;
1195 }
1196
1197 /**
1198 * @return The icon that represents the current state of this task.
1199 */
1200 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001201 if (mIcon != null) {
1202 return mIcon;
1203 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001204 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001205 }
1206
1207 /** @hide */
Matthew Ng54bc9422017-10-02 17:16:28 -07001208 @TestApi
1209 public int getIconResource() {
1210 return mIconRes;
1211 }
1212
1213 /** @hide */
1214 @TestApi
Craig Mautner648f69b2014-09-18 14:16:26 -07001215 public String getIconFilename() {
1216 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001217 }
1218
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001219 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001220 @UnsupportedAppUsage
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001221 public Bitmap getInMemoryIcon() {
1222 return mIcon;
1223 }
1224
1225 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001226 @UnsupportedAppUsage
Suprabh Shukla23593142015-11-03 17:31:15 -08001227 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001228 if (iconFilename != null) {
1229 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001230 return getTaskService().getTaskDescriptionIcon(iconFilename,
Winson Chung1af8eda2016-02-05 17:55:56 +00001231 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001232 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001233 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001234 }
1235 }
1236 return null;
1237 }
1238
Winson Chunga449dc02014-05-16 11:15:04 -07001239 /**
1240 * @return The color override on the theme's primary color.
1241 */
1242 public int getPrimaryColor() {
1243 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001244 }
1245
Winson Chung1af8eda2016-02-05 17:55:56 +00001246 /**
1247 * @return The background color.
1248 * @hide
1249 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01001250 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Winson Chung1af8eda2016-02-05 17:55:56 +00001251 public int getBackgroundColor() {
1252 return mColorBackground;
1253 }
1254
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001255 /**
1256 * @hide
1257 */
1258 public int getStatusBarColor() {
1259 return mStatusBarColor;
1260 }
1261
1262 /**
1263 * @hide
1264 */
1265 public int getNavigationBarColor() {
1266 return mNavigationBarColor;
1267 }
1268
Craig Mautner648f69b2014-09-18 14:16:26 -07001269 /** @hide */
1270 public void saveToXml(XmlSerializer out) throws IOException {
1271 if (mLabel != null) {
1272 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1273 }
1274 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001275 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1276 Integer.toHexString(mColorPrimary));
1277 }
1278 if (mColorBackground != 0) {
1279 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1280 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001281 }
1282 if (mIconFilename != null) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001283 out.attribute(null, ATTR_TASKDESCRIPTIONICON_FILENAME, mIconFilename);
1284 }
1285 if (mIconRes != 0) {
1286 out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE, Integer.toString(mIconRes));
Craig Mautner648f69b2014-09-18 14:16:26 -07001287 }
1288 }
1289
1290 /** @hide */
1291 public void restoreFromXml(String attrName, String attrValue) {
1292 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1293 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001294 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001295 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001296 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1297 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Matthew Ng54bc9422017-10-02 17:16:28 -07001298 } else if (ATTR_TASKDESCRIPTIONICON_FILENAME.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001299 setIconFilename(attrValue);
Matthew Ng54bc9422017-10-02 17:16:28 -07001300 } else if (ATTR_TASKDESCRIPTIONICON_RESOURCE.equals(attrName)) {
1301 setIcon(Integer.parseInt(attrValue, 10));
Craig Mautner648f69b2014-09-18 14:16:26 -07001302 }
1303 }
1304
Winson Chung03a9bae2014-05-02 09:56:12 -07001305 @Override
1306 public int describeContents() {
1307 return 0;
1308 }
1309
1310 @Override
1311 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001312 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001313 dest.writeInt(0);
1314 } else {
1315 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001316 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001317 }
Winson Chunga449dc02014-05-16 11:15:04 -07001318 if (mIcon == null) {
1319 dest.writeInt(0);
1320 } else {
1321 dest.writeInt(1);
1322 mIcon.writeToParcel(dest, 0);
1323 }
Matthew Ng54bc9422017-10-02 17:16:28 -07001324 dest.writeInt(mIconRes);
Winson Chunga449dc02014-05-16 11:15:04 -07001325 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001326 dest.writeInt(mColorBackground);
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001327 dest.writeInt(mStatusBarColor);
1328 dest.writeInt(mNavigationBarColor);
Craig Mautner648f69b2014-09-18 14:16:26 -07001329 if (mIconFilename == null) {
1330 dest.writeInt(0);
1331 } else {
1332 dest.writeInt(1);
1333 dest.writeString(mIconFilename);
1334 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001335 }
1336
1337 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001338 mLabel = source.readInt() > 0 ? source.readString() : null;
1339 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
Matthew Ng54bc9422017-10-02 17:16:28 -07001340 mIconRes = source.readInt();
Winson Chunga449dc02014-05-16 11:15:04 -07001341 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001342 mColorBackground = source.readInt();
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001343 mStatusBarColor = source.readInt();
1344 mNavigationBarColor = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001345 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001346 }
1347
Winson Chunga449dc02014-05-16 11:15:04 -07001348 public static final Creator<TaskDescription> CREATOR
1349 = new Creator<TaskDescription>() {
1350 public TaskDescription createFromParcel(Parcel source) {
1351 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001352 }
Winson Chunga449dc02014-05-16 11:15:04 -07001353 public TaskDescription[] newArray(int size) {
1354 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001355 }
1356 };
1357
1358 @Override
1359 public String toString() {
Winson Chunga449dc02014-05-16 11:15:04 -07001360 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
Matthew Ng54bc9422017-10-02 17:16:28 -07001361 " IconRes: " + mIconRes + " IconFilename: " + mIconFilename +
1362 " colorPrimary: " + mColorPrimary + " colorBackground: " + mColorBackground +
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001363 " statusBarColor: " + mColorBackground +
1364 " navigationBarColor: " + mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001365 }
1366 }
1367
1368 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 * Information you can retrieve about tasks that the user has most recently
1370 * started or visited.
1371 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001372 public static class RecentTaskInfo extends TaskInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 /**
1374 * If this task is currently running, this is the identifier for it.
1375 * If it is not running, this will be -1.
Winson Chungabfdcce2018-07-02 17:23:33 -07001376 *
1377 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, use
1378 * {@link RecentTaskInfo#taskId} to get the task id and {@link RecentTaskInfo#isRunning}
1379 * to determine if it is running.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001381 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 public int id;
1383
1384 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001385 * The true identifier of this task, valid even if it is not running.
Winson Chungabfdcce2018-07-02 17:23:33 -07001386 *
1387 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, use
1388 * {@link RecentTaskInfo#taskId}.
Dianne Hackbornd94df452011-02-16 18:53:31 -08001389 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001390 @Deprecated
Dianne Hackbornd94df452011-02-16 18:53:31 -08001391 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001392
Dianne Hackbornd94df452011-02-16 18:53:31 -08001393 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001394 * Description of the task's last state.
Winson Chungabfdcce2018-07-02 17:23:33 -07001395 *
1396 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always null.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001397 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001398 @Deprecated
Dianne Hackbornd2835932010-12-13 16:28:46 -08001399 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001400
1401 /**
Craig Mautnera228ae92014-07-09 05:44:55 -07001402 * Task affiliation for grouping with other tasks.
Winson Chungabfdcce2018-07-02 17:23:33 -07001403 *
1404 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always 0.
Craig Mautnera228ae92014-07-09 05:44:55 -07001405 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001406 @Deprecated
Craig Mautnera228ae92014-07-09 05:44:55 -07001407 public int affiliatedTaskId;
1408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 public RecentTaskInfo() {
1410 }
1411
Winson Chungabfdcce2018-07-02 17:23:33 -07001412 private RecentTaskInfo(Parcel source) {
1413 readFromParcel(source);
1414 }
1415
Craig Mautner6d90fed2013-05-22 15:03:10 -07001416 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001417 public int describeContents() {
1418 return 0;
1419 }
1420
Winson Chungabfdcce2018-07-02 17:23:33 -07001421 public void readFromParcel(Parcel source) {
1422 id = source.readInt();
1423 persistentId = source.readInt();
1424 super.readFromParcel(source);
1425 }
1426
Craig Mautner6d90fed2013-05-22 15:03:10 -07001427 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 public void writeToParcel(Parcel dest, int flags) {
1429 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001430 dest.writeInt(persistentId);
Winson Chungabfdcce2018-07-02 17:23:33 -07001431 super.writeToParcel(dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 public static final Creator<RecentTaskInfo> CREATOR
1435 = new Creator<RecentTaskInfo>() {
1436 public RecentTaskInfo createFromParcel(Parcel source) {
1437 return new RecentTaskInfo(source);
1438 }
1439 public RecentTaskInfo[] newArray(int size) {
1440 return new RecentTaskInfo[size];
1441 }
1442 };
Winson Chungb4132992018-07-03 15:52:38 -07001443
1444 /**
1445 * @hide
1446 */
1447 public void dump(PrintWriter pw, String indent) {
1448 final String activityType = WindowConfiguration.activityTypeToString(
1449 configuration.windowConfiguration.getActivityType());
1450 final String windowingMode = WindowConfiguration.activityTypeToString(
1451 configuration.windowConfiguration.getActivityType());
1452
1453 pw.println(); pw.print(" ");
1454 pw.print(" id=" + persistentId);
1455 pw.print(" stackId=" + stackId);
1456 pw.print(" userId=" + userId);
1457 pw.print(" hasTask=" + (id != -1));
1458 pw.print(" lastActiveTime=" + lastActiveTime);
1459 pw.println(); pw.print(" ");
1460 pw.print(" baseIntent=" + baseIntent);
1461 pw.println(); pw.print(" ");
1462 pw.print(" isExcluded="
1463 + ((baseIntent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) != 0));
1464 pw.print(" activityType=" + activityType);
1465 pw.print(" windowingMode=" + windowingMode);
1466 pw.print(" supportsSplitScreenMultiWindow=" + supportsSplitScreenMultiWindow);
1467 if (taskDescription != null) {
1468 pw.println(); pw.print(" ");
1469 final ActivityManager.TaskDescription td = taskDescription;
1470 pw.print(" taskDescription {");
1471 pw.print(" colorBackground=#" + Integer.toHexString(td.getBackgroundColor()));
1472 pw.print(" colorPrimary=#" + Integer.toHexString(td.getPrimaryColor()));
1473 pw.print(" iconRes=" + (td.getIconResource() != 0));
1474 pw.print(" iconBitmap=" + (td.getIconFilename() != null
1475 || td.getInMemoryIcon() != null));
1476 pw.println(" }");
1477 }
1478 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 }
1480
1481 /**
1482 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1483 * that have set their
1484 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1485 */
1486 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001489 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001490 * recent tasks that currently are not available to the user.
1491 */
1492 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001493
1494 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001495 * <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 -08001496 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001497 *
1498 * <p><b>Note: this method is only intended for debugging and presenting
1499 * task management user interfaces</b>. This should never be used for
1500 * core logic in an application, such as deciding between different
1501 * behaviors based on the information found here. Such uses are
1502 * <em>not</em> supported, and will likely break in the future. For
1503 * example, if multiple applications can be actively running at the
1504 * same time, assumptions made about the meaning of the data here for
1505 * purposes of control flow will be incorrect.</p>
1506 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001507 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001508 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001509 * document-centric recents means
1510 * it can leak personal information to the caller. For backwards compatibility,
1511 * it will still return a small subset of its data: at least the caller's
1512 * own tasks (though see {@link #getAppTasks()} for the correct supported
1513 * way to retrieve that information), and possibly some other tasks
1514 * such as home that are known to not be sensitive.
1515 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 * @param maxNum The maximum number of entries to return in the list. The
1517 * actual number returned may be smaller, depending on how many tasks the
1518 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001519 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001520 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001521 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 * @return Returns a list of RecentTaskInfo records describing each of
1523 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001525 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1527 throws SecurityException {
1528 try {
Winson Chungf067ac72017-10-24 17:32:32 -07001529 if (maxNum < 0) {
1530 throw new IllegalArgumentException("The requested number of tasks should be >= 0");
1531 }
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001532 return getTaskService().getRecentTasks(maxNum, flags, mContext.getUserId()).getList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001534 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 }
1536 }
1537
1538 /**
1539 * Information you can retrieve about a particular task that is currently
1540 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001541 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001542 * means that the user has gone to it and never closed it, but currently
1543 * the system may have killed its process and is only holding on to its
1544 * last state in order to restart it when the user returns.
1545 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001546 public static class RunningTaskInfo extends TaskInfo implements Parcelable {
1547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 /**
1549 * A unique identifier for this task.
Winson Chungabfdcce2018-07-02 17:23:33 -07001550 *
1551 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, use
1552 * {@link RunningTaskInfo#taskId}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001553 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001554 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 public int id;
1556
1557 /**
Winson Chungabfdcce2018-07-02 17:23:33 -07001558 * Thumbnail representation of the task's current state.
1559 *
1560 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always null.
Winson5510f6c2015-10-27 12:11:26 -07001561 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001562 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 public Bitmap thumbnail;
1564
1565 /**
1566 * Description of the task's current state.
Winson Chungabfdcce2018-07-02 17:23:33 -07001567 *
1568 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001570 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 public CharSequence description;
1572
1573 /**
Winson Chungabfdcce2018-07-02 17:23:33 -07001574 * Number of activities that are currently running (not stopped and persisted) in this task.
1575 *
1576 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always 0.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001578 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 public int numRunning;
1580
1581 public RunningTaskInfo() {
1582 }
1583
Winson Chungabfdcce2018-07-02 17:23:33 -07001584 private RunningTaskInfo(Parcel source) {
1585 readFromParcel(source);
1586 }
1587
1588 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 public int describeContents() {
1590 return 0;
1591 }
1592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593 public void readFromParcel(Parcel source) {
1594 id = source.readInt();
Winson Chungabfdcce2018-07-02 17:23:33 -07001595 super.readFromParcel(source);
1596 }
1597
1598 @Override
1599 public void writeToParcel(Parcel dest, int flags) {
1600 dest.writeInt(id);
1601 super.writeToParcel(dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001603
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
1605 public RunningTaskInfo createFromParcel(Parcel source) {
1606 return new RunningTaskInfo(source);
1607 }
1608 public RunningTaskInfo[] newArray(int size) {
1609 return new RunningTaskInfo[size];
1610 }
1611 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 }
Winson Chung1147c402014-05-14 11:05:00 -07001613
1614 /**
1615 * Get the list of tasks associated with the calling application.
1616 *
1617 * @return The list of tasks associated with the application making this call.
1618 * @throws SecurityException
1619 */
1620 public List<ActivityManager.AppTask> getAppTasks() {
1621 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001622 List<IBinder> appTasks;
Winson Chung1147c402014-05-14 11:05:00 -07001623 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001624 appTasks = getTaskService().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001625 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001626 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001627 }
1628 int numAppTasks = appTasks.size();
1629 for (int i = 0; i < numAppTasks; i++) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001630 tasks.add(new AppTask(IAppTask.Stub.asInterface(appTasks.get(i))));
Winson Chung1147c402014-05-14 11:05:00 -07001631 }
1632 return tasks;
1633 }
1634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 /**
Winson Chung48a10a52014-08-27 14:36:51 -07001636 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001637 * with {@link #addAppTask}.
1638 */
Winson Chung48a10a52014-08-27 14:36:51 -07001639 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001640 synchronized (this) {
1641 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07001642 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001643 }
1644 }
1645
1646 private void ensureAppTaskThumbnailSizeLocked() {
1647 if (mAppTaskThumbnailSize == null) {
1648 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001649 mAppTaskThumbnailSize = getTaskService().getAppTaskThumbnailSize();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001650 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001651 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001652 }
1653 }
1654 }
1655
1656 /**
1657 * Add a new {@link AppTask} for the calling application. This will create a new
1658 * recents entry that is added to the <b>end</b> of all existing recents.
1659 *
1660 * @param activity The activity that is adding the entry. This is used to help determine
1661 * the context that the new recents entry will be in.
1662 * @param intent The Intent that describes the recents entry. This is the same Intent that
1663 * you would have used to launch the activity for it. In generally you will want to set
1664 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
1665 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
1666 * entry will exist without an activity, so it doesn't make sense to not retain it when
1667 * its activity disappears. The given Intent here also must have an explicit ComponentName
1668 * set on it.
1669 * @param description Optional additional description information.
1670 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07001671 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
1672 * recreated in your process, probably in a way you don't like, before the recents entry
1673 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001674 *
1675 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
1676 * most likely cause of failure is that there is no more room for more tasks for your app.
1677 */
1678 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
1679 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
1680 Point size;
1681 synchronized (this) {
1682 ensureAppTaskThumbnailSizeLocked();
1683 size = mAppTaskThumbnailSize;
1684 }
1685 final int tw = thumbnail.getWidth();
1686 final int th = thumbnail.getHeight();
1687 if (tw != size.x || th != size.y) {
1688 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
1689
1690 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
1691 float scale;
1692 float dx = 0, dy = 0;
1693 if (tw * size.x > size.y * th) {
1694 scale = (float) size.x / (float) th;
1695 dx = (size.y - tw * scale) * 0.5f;
1696 } else {
1697 scale = (float) size.y / (float) tw;
1698 dy = (size.x - th * scale) * 0.5f;
1699 }
1700 Matrix matrix = new Matrix();
1701 matrix.setScale(scale, scale);
1702 matrix.postTranslate((int) (dx + 0.5f), 0);
1703
1704 Canvas canvas = new Canvas(bm);
1705 canvas.drawBitmap(thumbnail, matrix, null);
1706 canvas.setBitmap(null);
1707
1708 thumbnail = bm;
1709 }
1710 if (description == null) {
1711 description = new TaskDescription();
1712 }
1713 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001714 return getTaskService().addAppTask(activity.getActivityToken(),
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001715 intent, description, thumbnail);
1716 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001717 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001718 }
1719 }
1720
1721 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 * Return a list of the tasks that are currently running, with
1723 * the most recent being first and older ones after in order. Note that
1724 * "running" does not mean any of the task's code is currently loaded or
1725 * activity -- the task may have been frozen by the system, so that it
1726 * can be restarted in its previous state when next brought to the
1727 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001728 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001729 * <p><b>Note: this method is only intended for debugging and presenting
1730 * task management user interfaces</b>. This should never be used for
1731 * core logic in an application, such as deciding between different
1732 * behaviors based on the information found here. Such uses are
1733 * <em>not</em> supported, and will likely break in the future. For
1734 * example, if multiple applications can be actively running at the
1735 * same time, assumptions made about the meaning of the data here for
1736 * purposes of control flow will be incorrect.</p>
1737 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001738 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001739 * is no longer available to third party
1740 * applications: the introduction of document-centric recents means
1741 * it can leak person information to the caller. For backwards compatibility,
Alan Stokes1e4e74a2017-08-02 11:17:37 +01001742 * it will still return a small subset of its data: at least the caller's
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001743 * own tasks, and possibly some other tasks
1744 * such as home that are known to not be sensitive.
1745 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07001746 * @param maxNum The maximum number of entries to return in the list. The
1747 * actual number returned may be smaller, depending on how many tasks the
1748 * user has started.
1749 *
1750 * @return Returns a list of RunningTaskInfo records describing each of
1751 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001752 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001753 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07001754 public List<RunningTaskInfo> getRunningTasks(int maxNum)
1755 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07001756 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001757 return getTaskService().getTasks(maxNum);
Dianne Hackborn09233282014-04-30 11:33:59 -07001758 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001759 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07001760 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07001761 }
1762
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001763 /**
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001764 * Represents a task snapshot.
1765 * @hide
1766 */
1767 public static class TaskSnapshot implements Parcelable {
1768
Winson Chung48b25652018-10-22 14:04:30 -07001769 // Top activity in task when snapshot was taken
1770 private final ComponentName mTopActivityComponent;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001771 private final GraphicBuffer mSnapshot;
1772 private final int mOrientation;
1773 private final Rect mContentInsets;
Winson Chunga4fa8d52018-04-20 15:54:51 -07001774 // Whether this snapshot is a down-sampled version of the full resolution, used mainly for
1775 // low-ram devices
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001776 private final boolean mReducedResolution;
Winson Chunga4fa8d52018-04-20 15:54:51 -07001777 // Whether or not the snapshot is a real snapshot or an app-theme generated snapshot due to
1778 // the task having a secure window or having previews disabled
Winson Chungf3e412e2018-03-08 11:07:40 -08001779 private final boolean mIsRealSnapshot;
Winson Chunga4fa8d52018-04-20 15:54:51 -07001780 private final int mWindowingMode;
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001781 private final float mScale;
Winson Chung173020c2018-05-04 15:36:47 -07001782 private final int mSystemUiVisibility;
1783 private final boolean mIsTranslucent;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001784
Peiyong Lin9d427402019-01-23 18:39:06 -08001785 // TODO(b/116112787) TaskSnapshot must also book keep the color space from hardware bitmap
1786 // when created.
1787 private final ColorSpace mColorSpace = ColorSpace.get(ColorSpace.Named.SRGB);
1788
Winson Chung48b25652018-10-22 14:04:30 -07001789 public TaskSnapshot(@NonNull ComponentName topActivityComponent, GraphicBuffer snapshot,
1790 int orientation, Rect contentInsets, boolean reducedResolution, float scale,
1791 boolean isRealSnapshot, int windowingMode, int systemUiVisibility,
1792 boolean isTranslucent) {
1793 mTopActivityComponent = topActivityComponent;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001794 mSnapshot = snapshot;
1795 mOrientation = orientation;
1796 mContentInsets = new Rect(contentInsets);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001797 mReducedResolution = reducedResolution;
1798 mScale = scale;
Winson Chungf3e412e2018-03-08 11:07:40 -08001799 mIsRealSnapshot = isRealSnapshot;
Winson Chunga4fa8d52018-04-20 15:54:51 -07001800 mWindowingMode = windowingMode;
Winson Chung173020c2018-05-04 15:36:47 -07001801 mSystemUiVisibility = systemUiVisibility;
1802 mIsTranslucent = isTranslucent;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001803 }
1804
1805 private TaskSnapshot(Parcel source) {
Winson Chung48b25652018-10-22 14:04:30 -07001806 mTopActivityComponent = ComponentName.readFromParcel(source);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001807 mSnapshot = source.readParcelable(null /* classLoader */);
1808 mOrientation = source.readInt();
1809 mContentInsets = source.readParcelable(null /* classLoader */);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001810 mReducedResolution = source.readBoolean();
1811 mScale = source.readFloat();
Winson Chungf3e412e2018-03-08 11:07:40 -08001812 mIsRealSnapshot = source.readBoolean();
Winson Chunga4fa8d52018-04-20 15:54:51 -07001813 mWindowingMode = source.readInt();
Winson Chung173020c2018-05-04 15:36:47 -07001814 mSystemUiVisibility = source.readInt();
1815 mIsTranslucent = source.readBoolean();
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001816 }
1817
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001818 /**
Winson Chung48b25652018-10-22 14:04:30 -07001819 * @return The top activity component for the task at the point this snapshot was taken.
1820 */
1821 public ComponentName getTopActivityComponent() {
1822 return mTopActivityComponent;
1823 }
1824
1825 /**
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001826 * @return The graphic buffer representing the screenshot.
1827 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001828 @UnsupportedAppUsage
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001829 public GraphicBuffer getSnapshot() {
1830 return mSnapshot;
1831 }
1832
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001833 /**
Peiyong Lin9d427402019-01-23 18:39:06 -08001834 * @return The color space of graphic buffer representing the screenshot.
1835 */
1836 public ColorSpace getColorSpace() {
1837 return mColorSpace;
1838 }
1839
1840 /**
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001841 * @return The screen orientation the screenshot was taken in.
1842 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001843 @UnsupportedAppUsage
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001844 public int getOrientation() {
1845 return mOrientation;
1846 }
1847
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001848 /**
1849 * @return The system/content insets on the snapshot. These can be clipped off in order to
1850 * remove any areas behind system bars in the snapshot.
1851 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001852 @UnsupportedAppUsage
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001853 public Rect getContentInsets() {
1854 return mContentInsets;
1855 }
1856
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001857 /**
1858 * @return Whether this snapshot is a down-sampled version of the full resolution.
1859 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001860 @UnsupportedAppUsage
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001861 public boolean isReducedResolution() {
1862 return mReducedResolution;
1863 }
1864
1865 /**
Winson Chungf3e412e2018-03-08 11:07:40 -08001866 * @return Whether or not the snapshot is a real snapshot or an app-theme generated snapshot
1867 * due to the task having a secure window or having previews disabled.
1868 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001869 @UnsupportedAppUsage
Winson Chungf3e412e2018-03-08 11:07:40 -08001870 public boolean isRealSnapshot() {
1871 return mIsRealSnapshot;
1872 }
1873
1874 /**
Winson Chung02378b42018-06-04 16:40:09 -07001875 * @return Whether or not the snapshot is of a translucent app window (non-fullscreen or has
1876 * a non-opaque pixel format).
Winson Chung173020c2018-05-04 15:36:47 -07001877 */
1878 public boolean isTranslucent() {
1879 return mIsTranslucent;
1880 }
1881
1882 /**
Winson Chunga4fa8d52018-04-20 15:54:51 -07001883 * @return The windowing mode of the task when this snapshot was taken.
1884 */
1885 public int getWindowingMode() {
1886 return mWindowingMode;
1887 }
1888
1889 /**
Winson Chung173020c2018-05-04 15:36:47 -07001890 * @return The system ui visibility flags for the top most visible fullscreen window at the
1891 * time that the snapshot was taken.
1892 */
1893 public int getSystemUiVisibility() {
1894 return mSystemUiVisibility;
1895 }
1896
1897 /**
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001898 * @return The scale this snapshot was taken in.
1899 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001900 @UnsupportedAppUsage
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001901 public float getScale() {
1902 return mScale;
1903 }
1904
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001905 @Override
1906 public int describeContents() {
1907 return 0;
1908 }
1909
1910 @Override
1911 public void writeToParcel(Parcel dest, int flags) {
Winson Chung48b25652018-10-22 14:04:30 -07001912 ComponentName.writeToParcel(mTopActivityComponent, dest);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001913 dest.writeParcelable(mSnapshot, 0);
1914 dest.writeInt(mOrientation);
1915 dest.writeParcelable(mContentInsets, 0);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001916 dest.writeBoolean(mReducedResolution);
1917 dest.writeFloat(mScale);
Winson Chungf3e412e2018-03-08 11:07:40 -08001918 dest.writeBoolean(mIsRealSnapshot);
Winson Chunga4fa8d52018-04-20 15:54:51 -07001919 dest.writeInt(mWindowingMode);
Winson Chung173020c2018-05-04 15:36:47 -07001920 dest.writeInt(mSystemUiVisibility);
1921 dest.writeBoolean(mIsTranslucent);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001922 }
1923
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01001924 @Override
1925 public String toString() {
Winson Chunga4fa8d52018-04-20 15:54:51 -07001926 final int width = mSnapshot != null ? mSnapshot.getWidth() : 0;
1927 final int height = mSnapshot != null ? mSnapshot.getHeight() : 0;
Winson Chung48b25652018-10-22 14:04:30 -07001928 return "TaskSnapshot{"
1929 + " mTopActivityComponent=" + mTopActivityComponent.flattenToShortString()
1930 + " mSnapshot=" + mSnapshot + " (" + width + "x" + height + ")"
Winson Chunga4fa8d52018-04-20 15:54:51 -07001931 + " mOrientation=" + mOrientation
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001932 + " mContentInsets=" + mContentInsets.toShortString()
Winson Chungf3e412e2018-03-08 11:07:40 -08001933 + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale
Winson Chung173020c2018-05-04 15:36:47 -07001934 + " mIsRealSnapshot=" + mIsRealSnapshot + " mWindowingMode=" + mWindowingMode
1935 + " mSystemUiVisibility=" + mSystemUiVisibility
1936 + " mIsTranslucent=" + mIsTranslucent;
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01001937 }
1938
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001939 public static final Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
1940 public TaskSnapshot createFromParcel(Parcel source) {
1941 return new TaskSnapshot(source);
1942 }
1943 public TaskSnapshot[] newArray(int size) {
1944 return new TaskSnapshot[size];
1945 }
1946 };
1947 }
1948
Dianne Hackbornf26fd992011-04-08 18:14:09 -07001949 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001950 @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = {
1951 MOVE_TASK_WITH_HOME,
1952 MOVE_TASK_NO_USER_ACTION,
1953 })
1954 @Retention(RetentionPolicy.SOURCE)
1955 public @interface MoveTaskFlags {}
1956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001958 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
1959 * activity along with the task, so it is positioned immediately behind
1960 * the task.
1961 */
1962 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
1963
1964 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001965 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
1966 * user-instigated action, so the current activity will not receive a
1967 * hint that the user is leaving.
1968 */
1969 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
1970
1971 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001972 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
1973 * with a null options argument.
1974 *
1975 * @param taskId The identifier of the task to be moved, as found in
1976 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001977 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001978 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001979 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
1980 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001981 moveTaskToFront(taskId, flags, null);
1982 }
1983
1984 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001985 * Ask that the task associated with a given task ID be moved to the
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001986 * front of the stack, so it is now visible to the user.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001987 *
1988 * @param taskId The identifier of the task to be moved, as found in
1989 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001990 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001991 * @param options Additional options for the operation, either null or
1992 * as per {@link Context#startActivity(Intent, android.os.Bundle)
1993 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001994 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001995 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
1996 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001997 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001998 getTaskService().moveTaskToFront(taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001999 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002000 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002001 }
2002 }
2003
2004 /**
Andrii Kulian2eb84b22018-12-13 18:18:54 -08002005 * Check if the context is allowed to start an activity on specified display. Some launch
2006 * restrictions may apply to secondary displays that are private, virtual, or owned by the
2007 * system, in which case an activity start may throw a {@link SecurityException}. Call this
2008 * method prior to starting an activity on a secondary display to check if the current context
2009 * has access to it.
2010 *
2011 * @see ActivityOptions#setLaunchDisplayId(int)
2012 * @see android.view.Display.FLAG_PRIVATE
2013 * @see android.view.Display.TYPE_VIRTUAL
2014 *
2015 * @param context Source context, from which an activity will be started.
2016 * @param displayId Target display id.
2017 * @param intent Intent used to launch an activity.
2018 * @return {@code true} if a call to start an activity on the target display is allowed for the
2019 * provided context and no {@link SecurityException} will be thrown, {@code false} otherwise.
2020 */
2021 public boolean isActivityStartAllowedOnDisplay(Context context, int displayId, Intent intent) {
2022 try {
2023 return getTaskService().isActivityStartAllowedOnDisplay(displayId, intent,
2024 intent.resolveTypeIfNeeded(context.getContentResolver()), context.getUserId());
2025 } catch (RemoteException e) {
Charles Chencfec9182019-02-12 20:58:12 +08002026 e.rethrowFromSystemServer();
Andrii Kulian2eb84b22018-12-13 18:18:54 -08002027 }
Charles Chencfec9182019-02-12 20:58:12 +08002028 return false;
Andrii Kulian2eb84b22018-12-13 18:18:54 -08002029 }
2030
2031 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 * Information you can retrieve about a particular Service that is
2033 * currently running in the system.
2034 */
2035 public static class RunningServiceInfo implements Parcelable {
2036 /**
2037 * The service component.
2038 */
2039 public ComponentName service;
2040
2041 /**
2042 * If non-zero, this is the process the service is running in.
2043 */
2044 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002047 * The UID that owns this service.
2048 */
2049 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002050
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002051 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 * The name of the process this service runs in.
2053 */
2054 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 /**
2057 * Set to true if the service has asked to run as a foreground process.
2058 */
2059 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002060
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002061 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002062 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002063 * starting or binding to it. This
2064 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 */
2066 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002068 /**
2069 * Set to true if this service has been explicitly started.
2070 */
2071 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 /**
2074 * Number of clients connected to the service.
2075 */
2076 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 /**
2079 * Number of times the service's process has crashed while the service
2080 * is running.
2081 */
2082 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 /**
2085 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002086 * explicit requests to start it or clients binding to it). This
2087 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088 */
2089 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 /**
2092 * If non-zero, this service is not currently running, but scheduled to
2093 * restart at the given time.
2094 */
2095 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002096
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002097 /**
2098 * Bit for {@link #flags}: set if this service has been
2099 * explicitly started.
2100 */
2101 public static final int FLAG_STARTED = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002102
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002103 /**
2104 * Bit for {@link #flags}: set if the service has asked to
2105 * run as a foreground process.
2106 */
2107 public static final int FLAG_FOREGROUND = 1<<1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002108
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002109 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002110 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002111 * core system process.
2112 */
2113 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002114
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002115 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002116 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002117 * persistent process.
2118 */
2119 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002120
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002121 /**
2122 * Running flags.
2123 */
2124 public int flags;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002125
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002126 /**
2127 * For special services that are bound to by system code, this is
2128 * the package that holds the binding.
2129 */
2130 public String clientPackage;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002131
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002132 /**
2133 * For special services that are bound to by system code, this is
2134 * a string resource providing a user-visible label for who the
2135 * client is.
2136 */
2137 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002139 public RunningServiceInfo() {
2140 }
2141
2142 public int describeContents() {
2143 return 0;
2144 }
2145
2146 public void writeToParcel(Parcel dest, int flags) {
2147 ComponentName.writeToParcel(service, dest);
2148 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002149 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 dest.writeString(process);
2151 dest.writeInt(foreground ? 1 : 0);
2152 dest.writeLong(activeSince);
2153 dest.writeInt(started ? 1 : 0);
2154 dest.writeInt(clientCount);
2155 dest.writeInt(crashCount);
2156 dest.writeLong(lastActivityTime);
2157 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002158 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002159 dest.writeString(clientPackage);
2160 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 }
2162
2163 public void readFromParcel(Parcel source) {
2164 service = ComponentName.readFromParcel(source);
2165 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002166 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 process = source.readString();
2168 foreground = source.readInt() != 0;
2169 activeSince = source.readLong();
2170 started = source.readInt() != 0;
2171 clientCount = source.readInt();
2172 crashCount = source.readInt();
2173 lastActivityTime = source.readLong();
2174 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002175 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002176 clientPackage = source.readString();
2177 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
2181 public RunningServiceInfo createFromParcel(Parcel source) {
2182 return new RunningServiceInfo(source);
2183 }
2184 public RunningServiceInfo[] newArray(int size) {
2185 return new RunningServiceInfo[size];
2186 }
2187 };
2188
2189 private RunningServiceInfo(Parcel source) {
2190 readFromParcel(source);
2191 }
2192 }
2193
2194 /**
2195 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002196 *
2197 * <p><b>Note: this method is only intended for debugging or implementing
2198 * service management type user interfaces.</b></p>
2199 *
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002200 * @deprecated As of {@link android.os.Build.VERSION_CODES#O}, this method
2201 * is no longer available to third party applications. For backwards compatibility,
2202 * it will still return the caller's own services.
2203 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204 * @param maxNum The maximum number of entries to return in the list. The
2205 * actual number returned may be smaller, depending on how many services
2206 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002207 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002208 * @return Returns a list of RunningServiceInfo records describing each of
2209 * the running tasks.
2210 */
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002211 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 public List<RunningServiceInfo> getRunningServices(int maxNum)
2213 throws SecurityException {
2214 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002215 return getService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002216 .getServices(maxNum, 0);
2217 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002218 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002219 }
2220 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002223 * Returns a PendingIntent you can start to show a control panel for the
2224 * given running service. If the service does not have a control panel,
2225 * null is returned.
2226 */
2227 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2228 throws SecurityException {
2229 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002230 return getService()
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002231 .getRunningServiceControlPanel(service);
2232 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002233 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002234 }
2235 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002236
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002237 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 * Information you can retrieve about the available memory through
2239 * {@link ActivityManager#getMemoryInfo}.
2240 */
2241 public static class MemoryInfo implements Parcelable {
2242 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002243 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 * be considered absolute: due to the nature of the kernel, a significant
2245 * portion of this memory is actually in use and needed for the overall
2246 * system to run well.
2247 */
2248 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002249
2250 /**
2251 * The total memory accessible by the kernel. This is basically the
2252 * RAM size of the device, not including below-kernel fixed allocations
2253 * like DMA buffers, RAM for the baseband CPU, etc.
2254 */
2255 public long totalMem;
2256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 /**
2258 * The threshold of {@link #availMem} at which we consider memory to be
2259 * low and start killing background services and other non-extraneous
2260 * processes.
2261 */
2262 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002263
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 /**
2265 * Set to true if the system considers itself to currently be in a low
2266 * memory situation.
2267 */
2268 public boolean lowMemory;
2269
Dianne Hackborn7d608422011-08-07 16:24:18 -07002270 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002271 @UnsupportedAppUsage
Dianne Hackborn7d608422011-08-07 16:24:18 -07002272 public long hiddenAppThreshold;
2273 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002274 @UnsupportedAppUsage
Dianne Hackborn7d608422011-08-07 16:24:18 -07002275 public long secondaryServerThreshold;
2276 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002277 @UnsupportedAppUsage
Dianne Hackborn7d608422011-08-07 16:24:18 -07002278 public long visibleAppThreshold;
2279 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002280 @UnsupportedAppUsage
Dianne Hackborn7d608422011-08-07 16:24:18 -07002281 public long foregroundAppThreshold;
2282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 public MemoryInfo() {
2284 }
2285
2286 public int describeContents() {
2287 return 0;
2288 }
2289
2290 public void writeToParcel(Parcel dest, int flags) {
2291 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002292 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002293 dest.writeLong(threshold);
2294 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002295 dest.writeLong(hiddenAppThreshold);
2296 dest.writeLong(secondaryServerThreshold);
2297 dest.writeLong(visibleAppThreshold);
2298 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 public void readFromParcel(Parcel source) {
2302 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002303 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 threshold = source.readLong();
2305 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002306 hiddenAppThreshold = source.readLong();
2307 secondaryServerThreshold = source.readLong();
2308 visibleAppThreshold = source.readLong();
2309 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 }
2311
2312 public static final Creator<MemoryInfo> CREATOR
2313 = new Creator<MemoryInfo>() {
2314 public MemoryInfo createFromParcel(Parcel source) {
2315 return new MemoryInfo(source);
2316 }
2317 public MemoryInfo[] newArray(int size) {
2318 return new MemoryInfo[size];
2319 }
2320 };
2321
2322 private MemoryInfo(Parcel source) {
2323 readFromParcel(source);
2324 }
2325 }
2326
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002327 /**
2328 * Return general information about the memory state of the system. This
2329 * can be used to help decide how to manage your own memory, though note
2330 * that polling is not recommended and
2331 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2332 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2333 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2334 * level of your process as needed, which gives a better hint for how to
2335 * manage its memory.
2336 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002337 public void getMemoryInfo(MemoryInfo outInfo) {
2338 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002339 getService().getMemoryInfo(outInfo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002341 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 }
2343 }
Craig Mautner967212c2013-04-13 21:10:58 -07002344
Craig Mautner5ff12102013-05-24 12:50:15 -07002345 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002346 * Information you can retrieve about an ActivityStack in the system.
2347 * @hide
2348 */
2349 public static class StackInfo implements Parcelable {
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002350 @UnsupportedAppUsage
Craig Mautner967212c2013-04-13 21:10:58 -07002351 public int stackId;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002352 @UnsupportedAppUsage
Craig Mautnered6649f2013-12-02 14:08:25 -08002353 public Rect bounds = new Rect();
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002354 @UnsupportedAppUsage
Craig Mautner967212c2013-04-13 21:10:58 -07002355 public int[] taskIds;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002356 @UnsupportedAppUsage
Craig Mautner967212c2013-04-13 21:10:58 -07002357 public String[] taskNames;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002358 @UnsupportedAppUsage
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002359 public Rect[] taskBounds;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002360 @UnsupportedAppUsage
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002361 public int[] taskUserIds;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002362 @UnsupportedAppUsage
Winsond46b7272016-04-20 11:54:27 -07002363 public ComponentName topActivity;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002364 @UnsupportedAppUsage
Craig Mautnered6649f2013-12-02 14:08:25 -08002365 public int displayId;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002366 @UnsupportedAppUsage
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002367 public int userId;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002368 @UnsupportedAppUsage
Winsond46b7272016-04-20 11:54:27 -07002369 public boolean visible;
Winson529c8e42016-05-17 11:08:40 -07002370 // Index of the stack in the display's stack list, can be used for comparison of stack order
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002371 @UnsupportedAppUsage
Winson529c8e42016-05-17 11:08:40 -07002372 public int position;
Wale Ogunwale68278562017-09-23 17:13:55 -07002373 /**
2374 * The full configuration the stack is currently running in.
2375 * @hide
2376 */
Wale Ogunwale89be5762017-10-04 13:27:49 -07002377 final public Configuration configuration = new Configuration();
Craig Mautner967212c2013-04-13 21:10:58 -07002378
Craig Mautner967212c2013-04-13 21:10:58 -07002379 @Override
2380 public int describeContents() {
2381 return 0;
2382 }
2383
2384 @Override
2385 public void writeToParcel(Parcel dest, int flags) {
2386 dest.writeInt(stackId);
2387 dest.writeInt(bounds.left);
2388 dest.writeInt(bounds.top);
2389 dest.writeInt(bounds.right);
2390 dest.writeInt(bounds.bottom);
2391 dest.writeIntArray(taskIds);
2392 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002393 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2394 dest.writeInt(boundsCount);
2395 for (int i = 0; i < boundsCount; i++) {
2396 dest.writeInt(taskBounds[i].left);
2397 dest.writeInt(taskBounds[i].top);
2398 dest.writeInt(taskBounds[i].right);
2399 dest.writeInt(taskBounds[i].bottom);
2400 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002401 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002402 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002403 dest.writeInt(userId);
Winsond46b7272016-04-20 11:54:27 -07002404 dest.writeInt(visible ? 1 : 0);
Winson529c8e42016-05-17 11:08:40 -07002405 dest.writeInt(position);
Winsond46b7272016-04-20 11:54:27 -07002406 if (topActivity != null) {
2407 dest.writeInt(1);
2408 topActivity.writeToParcel(dest, 0);
2409 } else {
2410 dest.writeInt(0);
2411 }
Wale Ogunwale68278562017-09-23 17:13:55 -07002412 configuration.writeToParcel(dest, flags);
Craig Mautner967212c2013-04-13 21:10:58 -07002413 }
2414
2415 public void readFromParcel(Parcel source) {
2416 stackId = source.readInt();
2417 bounds = new Rect(
2418 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2419 taskIds = source.createIntArray();
2420 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002421 final int boundsCount = source.readInt();
2422 if (boundsCount > 0) {
2423 taskBounds = new Rect[boundsCount];
2424 for (int i = 0; i < boundsCount; i++) {
2425 taskBounds[i] = new Rect();
2426 taskBounds[i].set(
2427 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2428 }
2429 } else {
2430 taskBounds = null;
2431 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002432 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002433 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002434 userId = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002435 visible = source.readInt() > 0;
Winson529c8e42016-05-17 11:08:40 -07002436 position = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002437 if (source.readInt() > 0) {
2438 topActivity = ComponentName.readFromParcel(source);
2439 }
Wale Ogunwale68278562017-09-23 17:13:55 -07002440 configuration.readFromParcel(source);
Craig Mautner967212c2013-04-13 21:10:58 -07002441 }
2442
2443 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
2444 @Override
2445 public StackInfo createFromParcel(Parcel source) {
2446 return new StackInfo(source);
2447 }
2448 @Override
2449 public StackInfo[] newArray(int size) {
2450 return new StackInfo[size];
2451 }
2452 };
2453
Craig Mautner5ff12102013-05-24 12:50:15 -07002454 public StackInfo() {
2455 }
2456
Craig Mautner967212c2013-04-13 21:10:58 -07002457 private StackInfo(Parcel source) {
2458 readFromParcel(source);
2459 }
2460
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002461 @UnsupportedAppUsage
Craig Mautner5ff12102013-05-24 12:50:15 -07002462 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002463 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002464 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002465 sb.append(" bounds="); sb.append(bounds.toShortString());
2466 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002467 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002468 sb.append("\n");
Wale Ogunwale68278562017-09-23 17:13:55 -07002469 sb.append(" configuration="); sb.append(configuration);
2470 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002471 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002472 for (int i = 0; i < taskIds.length; ++i) {
2473 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002474 sb.append(": "); sb.append(taskNames[i]);
2475 if (taskBounds != null) {
2476 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2477 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002478 sb.append(" userId=").append(taskUserIds[i]);
Winsond46b7272016-04-20 11:54:27 -07002479 sb.append(" visible=").append(visible);
2480 if (topActivity != null) {
2481 sb.append(" topActivity=").append(topActivity);
2482 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002483 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002484 }
2485 return sb.toString();
2486 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002487
2488 @Override
2489 public String toString() {
2490 return toString("");
2491 }
Craig Mautner967212c2013-04-13 21:10:58 -07002492 }
2493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 /**
2495 * @hide
2496 */
Svet Ganovf935a702017-08-22 12:15:58 -07002497 @RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA,
2498 Manifest.permission.ACCESS_INSTANT_APPS})
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002499 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2501 try {
Christopher Tate1d99c392017-12-07 16:54:04 -08002502 return getService().clearApplicationUserData(packageName, false,
Jeff Sharkeyad357d12018-02-02 13:25:31 -07002503 observer, mContext.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002505 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 }
2507 }
Christopher Tatea3664242013-06-26 15:00:18 -07002508
2509 /**
2510 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002511 * the user choosing to clear the app's data from within the device settings UI. It
2512 * erases all dynamic data associated with the app -- its private data and data in its
2513 * private area on external storage -- but does not remove the installed application
Benjamin Franza77e3572017-06-23 12:01:44 +01002514 * itself, nor any OBB files. It also revokes all runtime permissions that the app has acquired,
2515 * clears all notifications and removes all Uri grants related to this application.
Christopher Tatea3664242013-06-26 15:00:18 -07002516 *
2517 * @return {@code true} if the application successfully requested that the application's
2518 * data be erased; {@code false} otherwise.
2519 */
2520 public boolean clearApplicationUserData() {
2521 return clearApplicationUserData(mContext.getPackageName(), null);
2522 }
2523
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002524 /**
2525 * Permits an application to get the persistent URI permissions granted to another.
2526 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002527 * <p>Typically called by Settings or DocumentsUI, requires
2528 * {@code GET_APP_GRANTED_URI_PERMISSIONS}.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002529 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002530 * @param packageName application to look for the granted permissions, or {@code null} to get
2531 * granted permissions for all applications
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002532 * @return list of granted URI permissions
2533 *
2534 * @hide
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002535 * @deprecated use {@link UriGrantsManager#getGrantedUriPermissions(String)} instead.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002536 */
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002537 @Deprecated
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002538 public ParceledListSlice<GrantedUriPermission> getGrantedUriPermissions(
2539 @Nullable String packageName) {
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002540 return ((UriGrantsManager) mContext.getSystemService(Context.URI_GRANTS_SERVICE))
2541 .getGrantedUriPermissions(packageName);
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002542 }
2543
2544 /**
2545 * Permits an application to clear the persistent URI permissions granted to another.
2546 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002547 * <p>Typically called by Settings, requires {@code CLEAR_APP_GRANTED_URI_PERMISSIONS}.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002548 *
2549 * @param packageName application to clear its granted permissions
2550 *
2551 * @hide
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002552 * @deprecated use {@link UriGrantsManager#clearGrantedUriPermissions(String)} instead.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002553 */
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002554 @Deprecated
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002555 public void clearGrantedUriPermissions(String packageName) {
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002556 ((UriGrantsManager) mContext.getSystemService(Context.URI_GRANTS_SERVICE))
2557 .clearGrantedUriPermissions(packageName);
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002558 }
2559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 /**
2561 * Information you can retrieve about any processes that are in an error condition.
2562 */
2563 public static class ProcessErrorStateInfo implements Parcelable {
2564 /**
2565 * Condition codes
2566 */
2567 public static final int NO_ERROR = 0;
2568 public static final int CRASHED = 1;
2569 public static final int NOT_RESPONDING = 2;
2570
2571 /**
2572 * The condition that the process is in.
2573 */
2574 public int condition;
2575
2576 /**
2577 * The process name in which the crash or error occurred.
2578 */
2579 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 /**
2582 * The pid of this process; 0 if none
2583 */
2584 public int pid;
2585
2586 /**
2587 * The kernel user-ID that has been assigned to this process;
2588 * currently this is not a unique ID (multiple applications can have
2589 * the same uid).
2590 */
2591 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 /**
Dan Egnor60d87622009-12-16 16:32:58 -08002594 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 */
2596 public String tag;
2597
2598 /**
2599 * A short message describing the error condition.
2600 */
2601 public String shortMsg;
2602
2603 /**
2604 * A long message describing the error condition.
2605 */
2606 public String longMsg;
2607
2608 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08002609 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 */
Dan Egnorb7f03672009-12-09 16:22:32 -08002611 public String stackTrace;
2612
2613 /**
2614 * to be deprecated: This value will always be null.
2615 */
2616 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617
2618 public ProcessErrorStateInfo() {
2619 }
2620
Craig Mautner5ff12102013-05-24 12:50:15 -07002621 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 public int describeContents() {
2623 return 0;
2624 }
2625
Craig Mautner5ff12102013-05-24 12:50:15 -07002626 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 public void writeToParcel(Parcel dest, int flags) {
2628 dest.writeInt(condition);
2629 dest.writeString(processName);
2630 dest.writeInt(pid);
2631 dest.writeInt(uid);
2632 dest.writeString(tag);
2633 dest.writeString(shortMsg);
2634 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08002635 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002636 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002638 public void readFromParcel(Parcel source) {
2639 condition = source.readInt();
2640 processName = source.readString();
2641 pid = source.readInt();
2642 uid = source.readInt();
2643 tag = source.readString();
2644 shortMsg = source.readString();
2645 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08002646 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002648
2649 public static final Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002650 new Creator<ProcessErrorStateInfo>() {
2651 public ProcessErrorStateInfo createFromParcel(Parcel source) {
2652 return new ProcessErrorStateInfo(source);
2653 }
2654 public ProcessErrorStateInfo[] newArray(int size) {
2655 return new ProcessErrorStateInfo[size];
2656 }
2657 };
2658
2659 private ProcessErrorStateInfo(Parcel source) {
2660 readFromParcel(source);
2661 }
2662 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002665 * 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 -08002666 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002667 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
2669 * current error conditions (it will not return an empty list). This list ordering is not
2670 * specified.
2671 */
2672 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
2673 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002674 return getService().getProcessesInErrorState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002676 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 }
2678 }
2679
2680 /**
2681 * Information you can retrieve about a running process.
2682 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07002683 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002684 /**
2685 * The name of the process that this object is associated with
2686 */
2687 public String processName;
2688
2689 /**
2690 * The pid of this process; 0 if none
2691 */
2692 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002693
Dianne Hackborneb034652009-09-07 00:49:58 -07002694 /**
2695 * The user id of this process.
2696 */
2697 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002698
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002699 /**
2700 * All packages that have been loaded into the process.
2701 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07002703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07002705 * Constant for {@link #flags}: this is an app that is unable to
2706 * correctly save its state when going to the background,
2707 * so it can not be killed while in the background.
2708 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002709 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07002710 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002711
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002712 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002713 * Constant for {@link #flags}: this process is associated with a
2714 * persistent system app.
2715 * @hide
2716 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002717 @UnsupportedAppUsage
Dianne Hackborn42499172010-10-15 18:45:07 -07002718 public static final int FLAG_PERSISTENT = 1<<1;
2719
2720 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07002721 * Constant for {@link #flags}: this process is associated with a
2722 * persistent system app.
2723 * @hide
2724 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002725 @UnsupportedAppUsage
Dianne Hackborn0c380492012-08-20 17:23:30 -07002726 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
2727
2728 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002729 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07002730 * {@link #FLAG_CANT_SAVE_STATE}.
2731 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002732 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002733 @UnsupportedAppUsage
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002734 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002735
2736 /**
2737 * Last memory trim level reported to the process: corresponds to
2738 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2739 * ComponentCallbacks2.onTrimMemory(int)}.
2740 */
2741 public int lastTrimLevel;
2742
Jeff Sharkey910e0812017-04-21 16:29:27 -06002743 /** @hide */
2744 @IntDef(prefix = { "IMPORTANCE_" }, value = {
2745 IMPORTANCE_FOREGROUND,
2746 IMPORTANCE_FOREGROUND_SERVICE,
2747 IMPORTANCE_TOP_SLEEPING,
2748 IMPORTANCE_VISIBLE,
2749 IMPORTANCE_PERCEPTIBLE,
2750 IMPORTANCE_CANT_SAVE_STATE,
2751 IMPORTANCE_SERVICE,
2752 IMPORTANCE_CACHED,
2753 IMPORTANCE_GONE,
2754 })
2755 @Retention(RetentionPolicy.SOURCE)
2756 public @interface Importance {}
2757
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002758 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002759 * Constant for {@link #importance}: This process is running the
2760 * foreground UI; that is, it is the thing currently at the top of the screen
2761 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 */
2763 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002766 * Constant for {@link #importance}: This process is running a foreground
2767 * service, for example to perform music playback even while the user is
2768 * not immediately in the app. This generally indicates that the process
2769 * is doing something the user actively cares about.
2770 */
2771 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
2772
2773 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002774 * @deprecated Pre-{@link android.os.Build.VERSION_CODES#P} version of
2775 * {@link #IMPORTANCE_TOP_SLEEPING}. As of Android
2776 * {@link android.os.Build.VERSION_CODES#P}, this is considered much less
2777 * important since we want to reduce what apps can do when the screen is off.
Dianne Hackborn1e383822015-04-10 14:02:33 -07002778 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002779 @Deprecated
2780 public static final int IMPORTANCE_TOP_SLEEPING_PRE_28 = 150;
Dianne Hackborn1e383822015-04-10 14:02:33 -07002781
2782 /**
2783 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002784 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07002785 * foreground. This may be running a window that is behind the current
2786 * foreground (so paused and with its state saved, not interacting with
2787 * the user, but visible to them to some degree); it may also be running
2788 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07002789 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002790 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002791
Dianne Hackborn860755f2010-06-03 18:47:52 -07002792 /**
Makoto Onukid7e40582017-04-13 14:54:56 -07002793 * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value
2794 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
2795 * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed.
2796 *
Makoto Onukie92f7942017-04-26 14:38:18 -07002797 * <p>The system will return this value instead of {@link #IMPORTANCE_PERCEPTIBLE}
2798 * on Android versions below {@link Build.VERSION_CODES#O}.
2799 *
2800 * <p>On Android version {@link Build.VERSION_CODES#O} and later, this value will still be
2801 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
2802 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
2803 * the correct value {@link #IMPORTANCE_PERCEPTIBLE} will be returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 */
Makoto Onukie92f7942017-04-26 14:38:18 -07002805 public static final int IMPORTANCE_PERCEPTIBLE_PRE_26 = 130;
Makoto Onukid7e40582017-04-13 14:54:56 -07002806
2807 /**
2808 * Constant for {@link #importance}: This process is not something the user
2809 * is directly aware of, but is otherwise perceptible to them to some degree.
2810 */
2811 public static final int IMPORTANCE_PERCEPTIBLE = 230;
2812
2813 /**
2814 * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had
2815 * this wrong value
2816 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
2817 * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed.
2818 *
Makoto Onukie92f7942017-04-26 14:38:18 -07002819 * <p>The system will return this value instead of {@link #IMPORTANCE_CANT_SAVE_STATE}
2820 * on Android versions below {@link Build.VERSION_CODES#O}.
2821 *
2822 * <p>On Android version {@link Build.VERSION_CODES#O} after, this value will still be
2823 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
2824 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
2825 * the correct value {@link #IMPORTANCE_CANT_SAVE_STATE} will be returned.
2826 *
Makoto Onukid7e40582017-04-13 14:54:56 -07002827 * @hide
2828 */
Sudheer Shankabe85ed62018-08-13 13:10:50 -07002829 @TestApi
Makoto Onukie92f7942017-04-26 14:38:18 -07002830 public static final int IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002831
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002832 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002833 * Constant for {@link #importance}: This process is contains services
2834 * that should remain running. These are background services apps have
2835 * started, not something the user is aware of, so they may be killed by
2836 * the system relatively freely (though it is generally desired that they
2837 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 */
2839 public static final int IMPORTANCE_SERVICE = 300;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002842 * Constant for {@link #importance}: This process is running the foreground
2843 * UI, but the device is asleep so it is not visible to the user. Though the
2844 * system will try hard to keep its process from being killed, in all other
2845 * ways we consider it a kind of cached process, with the limitations that go
2846 * along with that state: network access, running background services, etc.
2847 */
2848 public static final int IMPORTANCE_TOP_SLEEPING = 325;
2849
2850 /**
Dianne Hackbornf097d422017-12-15 16:32:19 -08002851 * Constant for {@link #importance}: This process is running an
2852 * application that can not save its state, and thus can't be killed
2853 * while in the background. This will be used with apps that have
2854 * {@link android.R.attr#cantSaveState} set on their application tag.
2855 */
2856 public static final int IMPORTANCE_CANT_SAVE_STATE = 350;
2857
2858 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002859 * Constant for {@link #importance}: This process process contains
Dianne Hackborn45e69d62017-03-01 16:02:15 -08002860 * cached code that is expendable, not actively running any app components
2861 * we care about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08002863 public static final int IMPORTANCE_CACHED = 400;
2864
2865 /**
2866 * @deprecated Renamed to {@link #IMPORTANCE_CACHED}.
2867 */
2868 public static final int IMPORTANCE_BACKGROUND = IMPORTANCE_CACHED;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002871 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 * actively running code.
Dianne Hackborn45e69d62017-03-01 16:02:15 -08002873 * @deprecated This value is no longer reported, use {@link #IMPORTANCE_CACHED} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08002875 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002877
2878 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002879 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002880 */
2881 public static final int IMPORTANCE_GONE = 1000;
2882
Makoto Onukid7e40582017-04-13 14:54:56 -07002883 /**
2884 * Convert a proc state to the correspondent IMPORTANCE_* constant. If the return value
2885 * will be passed to a client, use {@link #procStateToImportanceForClient}.
2886 * @hide
2887 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002888 @UnsupportedAppUsage
Jeff Sharkey910e0812017-04-21 16:29:27 -06002889 public static @Importance int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002890 if (procState == PROCESS_STATE_NONEXISTENT) {
2891 return IMPORTANCE_GONE;
2892 } else if (procState >= PROCESS_STATE_HOME) {
Dianne Hackborn45e69d62017-03-01 16:02:15 -08002893 return IMPORTANCE_CACHED;
Dianne Hackbornf4ef6eb2017-12-07 13:57:21 -08002894 } else if (procState == PROCESS_STATE_HEAVY_WEIGHT) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002895 return IMPORTANCE_CANT_SAVE_STATE;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002896 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
2897 return IMPORTANCE_TOP_SLEEPING;
Dianne Hackbornf097d422017-12-15 16:32:19 -08002898 } else if (procState >= PROCESS_STATE_SERVICE) {
2899 return IMPORTANCE_SERVICE;
Dianne Hackborn83b40f62017-04-26 13:59:47 -07002900 } else if (procState >= PROCESS_STATE_TRANSIENT_BACKGROUND) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002901 return IMPORTANCE_PERCEPTIBLE;
2902 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
2903 return IMPORTANCE_VISIBLE;
Amith Yamasania0a30a12019-01-22 11:38:06 -08002904 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE_LOCATION) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002905 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002906 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07002907 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002908 }
2909 }
2910
Makoto Onukid7e40582017-04-13 14:54:56 -07002911 /**
2912 * Convert a proc state to the correspondent IMPORTANCE_* constant for a client represented
2913 * by a given {@link Context}, with converting {@link #IMPORTANCE_PERCEPTIBLE}
2914 * and {@link #IMPORTANCE_CANT_SAVE_STATE} to the corresponding "wrong" value if the
2915 * client's target SDK < {@link VERSION_CODES#O}.
2916 * @hide
2917 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06002918 public static @Importance int procStateToImportanceForClient(int procState,
2919 Context clientContext) {
Makoto Onukie92f7942017-04-26 14:38:18 -07002920 return procStateToImportanceForTargetSdk(procState,
2921 clientContext.getApplicationInfo().targetSdkVersion);
2922 }
2923
2924 /**
2925 * See {@link #procStateToImportanceForClient}.
2926 * @hide
2927 */
2928 public static @Importance int procStateToImportanceForTargetSdk(int procState,
2929 int targetSdkVersion) {
Makoto Onukid7e40582017-04-13 14:54:56 -07002930 final int importance = procStateToImportance(procState);
2931
2932 // For pre O apps, convert to the old, wrong values.
Makoto Onukie92f7942017-04-26 14:38:18 -07002933 if (targetSdkVersion < VERSION_CODES.O) {
Makoto Onukid7e40582017-04-13 14:54:56 -07002934 switch (importance) {
2935 case IMPORTANCE_PERCEPTIBLE:
Makoto Onukie92f7942017-04-26 14:38:18 -07002936 return IMPORTANCE_PERCEPTIBLE_PRE_26;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002937 case IMPORTANCE_TOP_SLEEPING:
2938 return IMPORTANCE_TOP_SLEEPING_PRE_28;
Makoto Onukid7e40582017-04-13 14:54:56 -07002939 case IMPORTANCE_CANT_SAVE_STATE:
Makoto Onukie92f7942017-04-26 14:38:18 -07002940 return IMPORTANCE_CANT_SAVE_STATE_PRE_26;
Makoto Onukid7e40582017-04-13 14:54:56 -07002941 }
2942 }
2943 return importance;
2944 }
2945
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002946 /** @hide */
Jeff Sharkey910e0812017-04-21 16:29:27 -06002947 public static int importanceToProcState(@Importance int importance) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002948 if (importance == IMPORTANCE_GONE) {
2949 return PROCESS_STATE_NONEXISTENT;
Dianne Hackborn45e69d62017-03-01 16:02:15 -08002950 } else if (importance >= IMPORTANCE_CACHED) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002951 return PROCESS_STATE_HOME;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002952 } else if (importance >= IMPORTANCE_CANT_SAVE_STATE) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002953 return PROCESS_STATE_HEAVY_WEIGHT;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002954 } else if (importance >= IMPORTANCE_TOP_SLEEPING) {
2955 return PROCESS_STATE_TOP_SLEEPING;
Dianne Hackbornf097d422017-12-15 16:32:19 -08002956 } else if (importance >= IMPORTANCE_SERVICE) {
2957 return PROCESS_STATE_SERVICE;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002958 } else if (importance >= IMPORTANCE_PERCEPTIBLE) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -07002959 return PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002960 } else if (importance >= IMPORTANCE_VISIBLE) {
2961 return PROCESS_STATE_IMPORTANT_FOREGROUND;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002962 } else if (importance >= IMPORTANCE_TOP_SLEEPING_PRE_28) {
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -08002963 return PROCESS_STATE_IMPORTANT_FOREGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002964 } else if (importance >= IMPORTANCE_FOREGROUND_SERVICE) {
2965 return PROCESS_STATE_FOREGROUND_SERVICE;
Amith Yamasania0a30a12019-01-22 11:38:06 -08002966 // TODO: Asymmetrical mapping for LOCATION service type. Ok?
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002967 } else {
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -08002968 return PROCESS_STATE_TOP;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08002969 }
2970 }
2971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 /**
Jeff Sharkey910e0812017-04-21 16:29:27 -06002973 * The relative importance level that the system places on this process.
2974 * These constants are numbered so that "more important" values are
2975 * always smaller than "less important" values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06002977 public @Importance int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 /**
2980 * An additional ordering within a particular {@link #importance}
2981 * category, providing finer-grained information about the relative
2982 * utility of processes within a category. This number means nothing
2983 * except that a smaller values are more recently used (and thus
2984 * more important). Currently an LRU value is only maintained for
Dianne Hackborn45e69d62017-03-01 16:02:15 -08002985 * the {@link #IMPORTANCE_CACHED} category, though others may
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 * be maintained in the future.
2987 */
2988 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002989
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002990 /**
2991 * Constant for {@link #importanceReasonCode}: nothing special has
2992 * been specified for the reason for this level.
2993 */
2994 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002995
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002996 /**
2997 * Constant for {@link #importanceReasonCode}: one of the application's
2998 * content providers is being used by another process. The pid of
2999 * the client process is in {@link #importanceReasonPid} and the
3000 * target provider in this process is in
3001 * {@link #importanceReasonComponent}.
3002 */
3003 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003004
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003005 /**
3006 * Constant for {@link #importanceReasonCode}: one of the application's
3007 * content providers is being used by another process. The pid of
3008 * the client process is in {@link #importanceReasonPid} and the
3009 * target provider in this process is in
3010 * {@link #importanceReasonComponent}.
3011 */
3012 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003013
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003014 /**
3015 * The reason for {@link #importance}, if any.
3016 */
3017 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003018
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003019 /**
3020 * For the specified values of {@link #importanceReasonCode}, this
3021 * is the process ID of the other process that is a client of this
3022 * process. This will be 0 if no other process is using this one.
3023 */
3024 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003025
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003026 /**
3027 * For the specified values of {@link #importanceReasonCode}, this
3028 * is the name of the component that is being used in this process.
3029 */
3030 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003031
Dianne Hackborn905577f2011-09-07 18:31:28 -07003032 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003033 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07003034 * of the other pid. @hide
3035 */
3036 public int importanceReasonImportance;
3037
Dianne Hackborn684bf342014-04-29 17:56:57 -07003038 /**
3039 * Current process state, as per PROCESS_STATE_* constants.
3040 * @hide
3041 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003042 @UnsupportedAppUsage
Dianne Hackborn684bf342014-04-29 17:56:57 -07003043 public int processState;
3044
Chris Morin0260f3d2018-07-10 12:42:06 -07003045 /**
3046 * Whether the app is focused in multi-window environment.
3047 * @hide
3048 */
3049 public boolean isFocused;
3050
3051 /**
3052 * Copy of {@link com.android.server.am.ProcessRecord#lastActivityTime} of the process.
3053 * @hide
3054 */
3055 public long lastActivityTime;
3056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 public RunningAppProcessInfo() {
3058 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003059 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07003060 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
Chris Morin0260f3d2018-07-10 12:42:06 -07003061 isFocused = false;
3062 lastActivityTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003065 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
3066 processName = pProcessName;
3067 pid = pPid;
3068 pkgList = pArr;
Chris Morin0260f3d2018-07-10 12:42:06 -07003069 isFocused = false;
3070 lastActivityTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003071 }
3072
3073 public int describeContents() {
3074 return 0;
3075 }
3076
3077 public void writeToParcel(Parcel dest, int flags) {
3078 dest.writeString(processName);
3079 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07003080 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003082 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003083 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 dest.writeInt(importance);
3085 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003086 dest.writeInt(importanceReasonCode);
3087 dest.writeInt(importanceReasonPid);
3088 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003089 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07003090 dest.writeInt(processState);
Chris Morin0260f3d2018-07-10 12:42:06 -07003091 dest.writeInt(isFocused ? 1 : 0);
3092 dest.writeLong(lastActivityTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003093 }
3094
3095 public void readFromParcel(Parcel source) {
3096 processName = source.readString();
3097 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07003098 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003100 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003101 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003102 importance = source.readInt();
3103 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003104 importanceReasonCode = source.readInt();
3105 importanceReasonPid = source.readInt();
3106 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003107 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07003108 processState = source.readInt();
Chris Morin0260f3d2018-07-10 12:42:06 -07003109 isFocused = source.readInt() != 0;
3110 lastActivityTime = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003111 }
3112
Stefan Kuhne16045c22015-06-05 07:18:06 -07003113 public static final Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 new Creator<RunningAppProcessInfo>() {
3115 public RunningAppProcessInfo createFromParcel(Parcel source) {
3116 return new RunningAppProcessInfo(source);
3117 }
3118 public RunningAppProcessInfo[] newArray(int size) {
3119 return new RunningAppProcessInfo[size];
3120 }
3121 };
3122
3123 private RunningAppProcessInfo(Parcel source) {
3124 readFromParcel(source);
3125 }
3126 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003129 * Returns a list of application processes installed on external media
3130 * that are running on the device.
3131 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003132 * <p><b>Note: this method is only intended for debugging or building
3133 * a user-facing process management UI.</b></p>
3134 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003135 * @return Returns a list of ApplicationInfo records, or null if none
3136 * This list ordering is not specified.
3137 * @hide
3138 */
3139 public List<ApplicationInfo> getRunningExternalApplications() {
3140 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003141 return getService().getRunningExternalApplications();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003142 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003143 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003144 }
3145 }
3146
3147 /**
Suprabh Shukla4d64c092018-02-21 20:06:14 -08003148 * Query whether the user has enabled background restrictions for this app.
3149 *
3150 * <p> The user may chose to do this, if they see that an app is consuming an unreasonable
3151 * amount of battery while in the background. </p>
3152 *
3153 * <p> If true, any work that the app tries to do will be aggressively restricted while it is in
3154 * the background. At a minimum, jobs and alarms will not execute and foreground services
3155 * cannot be started unless an app activity is in the foreground. </p>
3156 *
3157 * <p><b> Note that these restrictions stay in effect even when the device is charging.</b></p>
3158 *
3159 * @return true if user has enforced background restrictions for this app, false otherwise.
3160 */
3161 public boolean isBackgroundRestricted() {
3162 try {
3163 return getService().isBackgroundRestricted(mContext.getOpPackageName());
3164 } catch (RemoteException e) {
3165 throw e.rethrowFromSystemServer();
3166 }
3167 }
3168
3169 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003170 * Sets the memory trim mode for a process and schedules a memory trim operation.
3171 *
3172 * <p><b>Note: this method is only intended for testing framework.</b></p>
3173 *
3174 * @return Returns true if successful.
3175 * @hide
3176 */
3177 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
3178 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003179 return getService().setProcessMemoryTrimLevel(process, userId,
Stefan Kuhne16045c22015-06-05 07:18:06 -07003180 level);
3181 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003182 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07003183 }
3184 }
3185
3186 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003188 *
3189 * <p><b>Note: this method is only intended for debugging or building
3190 * a user-facing process management UI.</b></p>
3191 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
3193 * running processes (it will not return an empty list). This list ordering is not
3194 * specified.
3195 */
3196 public List<RunningAppProcessInfo> getRunningAppProcesses() {
3197 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003198 return getService().getRunningAppProcesses();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003200 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201 }
3202 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003203
3204 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003205 * Return the importance of a given package name, based on the processes that are
3206 * currently running. The return value is one of the importance constants defined
3207 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3208 * processes that this package has code running inside of. If there are no processes
3209 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07003210 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07003211 */
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003212 @SystemApi @TestApi
Dianne Hackborn9df8f512016-10-24 17:58:30 -07003213 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003214 public @RunningAppProcessInfo.Importance int getPackageImportance(String packageName) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003215 try {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003216 int procState = getService().getPackageProcessState(packageName,
Adam Lesinskic30454c2015-06-24 13:24:35 -07003217 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003218 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn1e383822015-04-10 14:02:33 -07003219 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003220 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07003221 }
3222 }
3223
3224 /**
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003225 * Return the importance of a given uid, based on the processes that are
3226 * currently running. The return value is one of the importance constants defined
3227 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3228 * processes that this uid has running. If there are no processes
3229 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
3230 * @hide
3231 */
3232 @SystemApi @TestApi
3233 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003234 public @RunningAppProcessInfo.Importance int getUidImportance(int uid) {
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003235 try {
3236 int procState = getService().getUidProcessState(uid,
3237 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003238 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003239 } catch (RemoteException e) {
3240 throw e.rethrowFromSystemServer();
3241 }
3242 }
3243
3244 /**
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003245 * Callback to get reports about changes to the importance of a uid. Use with
3246 * {@link #addOnUidImportanceListener}.
3247 * @hide
3248 */
3249 @SystemApi @TestApi
3250 public interface OnUidImportanceListener {
3251 /**
3252 * The importance if a given uid has changed. Will be one of the importance
3253 * values in {@link RunningAppProcessInfo};
3254 * {@link RunningAppProcessInfo#IMPORTANCE_GONE IMPORTANCE_GONE} will be reported
3255 * when the uid is no longer running at all. This callback will happen on a thread
3256 * from a thread pool, not the main UI thread.
3257 * @param uid The uid whose importance has changed.
3258 * @param importance The new importance value as per {@link RunningAppProcessInfo}.
3259 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003260 void onUidImportance(int uid, @RunningAppProcessInfo.Importance int importance);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003261 }
3262
3263 /**
3264 * Start monitoring changes to the imoportance of uids running in the system.
3265 * @param listener The listener callback that will receive change reports.
3266 * @param importanceCutpoint The level of importance in which the caller is interested
3267 * in differences. For example, if {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}
3268 * is used here, you will receive a call each time a uids importance transitions between
3269 * being <= {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE} and
3270 * > {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.
3271 *
3272 * <p>The caller must hold the {@link android.Manifest.permission#PACKAGE_USAGE_STATS}
3273 * permission to use this feature.</p>
3274 *
3275 * @throws IllegalArgumentException If the listener is already registered.
3276 * @throws SecurityException If the caller does not hold
3277 * {@link android.Manifest.permission#PACKAGE_USAGE_STATS}.
3278 * @hide
3279 */
3280 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003281 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003282 public void addOnUidImportanceListener(OnUidImportanceListener listener,
Jeff Sharkey910e0812017-04-21 16:29:27 -06003283 @RunningAppProcessInfo.Importance int importanceCutpoint) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003284 synchronized (this) {
3285 if (mImportanceListeners.containsKey(listener)) {
3286 throw new IllegalArgumentException("Listener already registered: " + listener);
3287 }
3288 // TODO: implement the cut point in the system process to avoid IPCs.
Makoto Onukid7e40582017-04-13 14:54:56 -07003289 UidObserver observer = new UidObserver(listener, mContext);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003290 try {
3291 getService().registerUidObserver(observer,
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003292 UID_OBSERVER_PROCSTATE | UID_OBSERVER_GONE,
3293 RunningAppProcessInfo.importanceToProcState(importanceCutpoint),
3294 mContext.getOpPackageName());
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003295 } catch (RemoteException e) {
3296 throw e.rethrowFromSystemServer();
3297 }
3298 mImportanceListeners.put(listener, observer);
3299 }
3300 }
3301
3302 /**
3303 * Remove an importance listener that was previously registered with
3304 * {@link #addOnUidImportanceListener}.
3305 *
3306 * @throws IllegalArgumentException If the listener is not registered.
3307 * @hide
3308 */
3309 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003310 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003311 public void removeOnUidImportanceListener(OnUidImportanceListener listener) {
3312 synchronized (this) {
3313 UidObserver observer = mImportanceListeners.remove(listener);
3314 if (observer == null) {
3315 throw new IllegalArgumentException("Listener not registered: " + listener);
3316 }
3317 try {
3318 getService().unregisterUidObserver(observer);
3319 } catch (RemoteException e) {
3320 throw e.rethrowFromSystemServer();
3321 }
3322 }
3323 }
3324
3325 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003326 * Return global memory state information for the calling process. This
3327 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
3328 * only fields that will be filled in are
3329 * {@link RunningAppProcessInfo#pid},
3330 * {@link RunningAppProcessInfo#uid},
3331 * {@link RunningAppProcessInfo#lastTrimLevel},
3332 * {@link RunningAppProcessInfo#importance},
3333 * {@link RunningAppProcessInfo#lru}, and
3334 * {@link RunningAppProcessInfo#importanceReasonCode}.
3335 */
3336 static public void getMyMemoryState(RunningAppProcessInfo outState) {
3337 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003338 getService().getMyMemoryState(outState);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003339 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003340 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003341 }
3342 }
3343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003345 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003346 *
3347 * <p><b>Note: this method is only intended for debugging or building
3348 * a user-facing process management UI.</b></p>
3349 *
Dianne Hackborn8c76d912018-08-23 15:20:05 -07003350 * <p>As of {@link android.os.Build.VERSION_CODES#Q Android Q}, for regular apps this method
3351 * will only return information about the memory info for the processes running as the
3352 * caller's uid; no other process memory info is available and will be zero.
3353 * Also of {@link android.os.Build.VERSION_CODES#Q Android Q} the sample rate allowed
3354 * by this API is significantly limited, if called faster the limit you will receive the
3355 * same data as the previous call.</p>
3356 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003357 * @param pids The pids of the processes whose memory usage is to be
3358 * retrieved.
3359 * @return Returns an array of memory information, one for each
3360 * requested pid.
3361 */
3362 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
3363 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003364 return getService().getProcessMemoryInfo(pids);
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003365 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003366 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003367 }
3368 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003369
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003370 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003371 * @deprecated This is now just a wrapper for
3372 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3373 * is no longer available to applications because it allows them to
3374 * break other applications by removing their alarms, stopping their
3375 * services, etc.
3376 */
3377 @Deprecated
3378 public void restartPackage(String packageName) {
3379 killBackgroundProcesses(packageName);
3380 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003381
Dianne Hackborn03abb812010-01-04 18:43:19 -08003382 /**
3383 * Have the system immediately kill all background processes associated
3384 * with the given package. This is the same as the kernel killing those
3385 * processes to reclaim memory; the system will take care of restarting
3386 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003387 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003388 * @param packageName The name of the package whose processes are to
3389 * be killed.
3390 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003391 @RequiresPermission(Manifest.permission.KILL_BACKGROUND_PROCESSES)
Dianne Hackborn03abb812010-01-04 18:43:19 -08003392 public void killBackgroundProcesses(String packageName) {
3393 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003394 getService().killBackgroundProcesses(packageName,
Jeff Sharkeyad357d12018-02-02 13:25:31 -07003395 mContext.getUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003396 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003397 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003398 }
3399 }
Svet Ganov019d2302015-05-04 11:07:38 -07003400
3401 /**
3402 * Kills the specified UID.
3403 * @param uid The UID to kill.
3404 * @param reason The reason for the kill.
3405 *
3406 * @hide
3407 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08003408 @SystemApi
Svet Ganov019d2302015-05-04 11:07:38 -07003409 @RequiresPermission(Manifest.permission.KILL_UID)
3410 public void killUid(int uid, String reason) {
3411 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003412 getService().killUid(UserHandle.getAppId(uid),
Svetoslavaa41add2015-08-06 15:03:55 -07003413 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003414 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003415 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003416 }
3417 }
3418
Dianne Hackborn03abb812010-01-04 18:43:19 -08003419 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 * Have the system perform a force stop of everything associated with
3421 * the given application package. All processes that share its uid
3422 * will be killed, all services it has running stopped, all activities
3423 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3424 * broadcast will be sent, so that any of its registered alarms can
3425 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003426 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003427 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003428 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003430 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003432 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003433 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003434 * @hide This is not available to third party applications due to
3435 * it allowing them to break other applications by stopping their
3436 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003438 @UnsupportedAppUsage
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003439 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003441 getService().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003442 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003443 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 }
3445 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003446
3447 /**
3448 * @see #forceStopPackageAsUser(String, int)
3449 * @hide
3450 */
lumark793e0562018-07-09 22:14:33 +08003451 @SystemApi @TestApi
Jeff Schumacherb8cadef2017-01-03 13:52:48 -08003452 @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES)
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003453 public void forceStopPackage(String packageName) {
Jeff Sharkeyad357d12018-02-02 13:25:31 -07003454 forceStopPackageAsUser(packageName, mContext.getUserId());
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003455 }
3456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003457 /**
Maurice Lam522ecbe2018-12-04 20:21:40 -08003458 * Sets the current locales of the device. Calling app must have the permission
3459 * {@code android.permission.CHANGE_CONFIGURATION} and
3460 * {@code android.permission.WRITE_SETTINGS}.
3461 *
3462 * @hide
3463 */
3464 @SystemApi
3465 public void setDeviceLocales(@NonNull LocaleList locales) {
3466 LocalePicker.updateLocales(locales);
3467 }
3468
3469 /**
3470 * Returns a list of supported locales by this system. It includes all locales that are
3471 * selectable by the user, potentially including locales that the framework does not have
3472 * translated resources for. To get locales that the framework has translated resources for, use
3473 * {@code Resources.getSystem().getAssets().getLocales()} instead.
3474 *
3475 * @hide
3476 */
3477 @SystemApi
3478 public @NonNull Collection<Locale> getSupportedLocales() {
3479 ArrayList<Locale> locales = new ArrayList<>();
3480 for (String localeTag : LocalePicker.getSupportedLocales(mContext)) {
3481 locales.add(Locale.forLanguageTag(localeTag));
3482 }
3483 return locales;
3484 }
3485
3486 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 * Get the device configuration attributes.
3488 */
3489 public ConfigurationInfo getDeviceConfigurationInfo() {
3490 try {
Yunfan Chen75157d72018-07-27 14:47:21 +09003491 return getTaskService().getDeviceConfigurationInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003493 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003495 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003496
3497 /**
3498 * Get the preferred density of icons for the launcher. This is used when
3499 * custom drawables are created (e.g., for shortcuts).
3500 *
3501 * @return density in terms of DPI
3502 */
3503 public int getLauncherLargeIconDensity() {
3504 final Resources res = mContext.getResources();
3505 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003506 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003507
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003508 if (sw < 600) {
3509 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003510 return density;
3511 }
3512
3513 switch (density) {
3514 case DisplayMetrics.DENSITY_LOW:
3515 return DisplayMetrics.DENSITY_MEDIUM;
3516 case DisplayMetrics.DENSITY_MEDIUM:
3517 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003518 case DisplayMetrics.DENSITY_TV:
3519 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003520 case DisplayMetrics.DENSITY_HIGH:
3521 return DisplayMetrics.DENSITY_XHIGH;
3522 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003523 return DisplayMetrics.DENSITY_XXHIGH;
3524 case DisplayMetrics.DENSITY_XXHIGH:
3525 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003526 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003527 // The density is some abnormal value. Return some other
3528 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003529 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003530 }
3531 }
3532
3533 /**
3534 * Get the preferred launcher icon size. This is used when custom drawables
3535 * are created (e.g., for shortcuts).
3536 *
3537 * @return dimensions of square icons in terms of pixels
3538 */
3539 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003540 return getLauncherLargeIconSizeInner(mContext);
3541 }
3542
3543 static int getLauncherLargeIconSizeInner(Context context) {
3544 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003545 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003546 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003547
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003548 if (sw < 600) {
3549 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003550 return size;
3551 }
3552
3553 final int density = res.getDisplayMetrics().densityDpi;
3554
3555 switch (density) {
3556 case DisplayMetrics.DENSITY_LOW:
3557 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3558 case DisplayMetrics.DENSITY_MEDIUM:
3559 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003560 case DisplayMetrics.DENSITY_TV:
3561 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003562 case DisplayMetrics.DENSITY_HIGH:
3563 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3564 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003565 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3566 case DisplayMetrics.DENSITY_XXHIGH:
3567 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003568 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003569 // The density is some abnormal value. Return some other
3570 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003571 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003572 }
3573 }
3574
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003575 /**
3576 * Returns "true" if the user interface is currently being messed with
3577 * by a monkey.
3578 */
3579 public static boolean isUserAMonkey() {
3580 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003581 return getService().isUserAMonkey();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003582 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003583 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003584 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003585 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003586
3587 /**
3588 * Returns "true" if device is running in a test harness.
William Hestera96d3d32018-12-19 13:14:51 -08003589 *
3590 * @deprecated this method is false for all user builds. Users looking to check if their device
3591 * is running in a device farm should see {@link #isRunningInUserTestHarness()}.
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003592 */
William Hestera96d3d32018-12-19 13:14:51 -08003593 @Deprecated
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003594 public static boolean isRunningInTestHarness() {
3595 return SystemProperties.getBoolean("ro.test_harness", false);
3596 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003597
3598 /**
William Hestera96d3d32018-12-19 13:14:51 -08003599 * Returns "true" if the device is running in Test Harness Mode.
3600 *
3601 * <p>Test Harness Mode is a feature that allows devices to run without human interaction in a
3602 * device farm/testing harness (such as Firebase Test Lab). You should check this method if you
3603 * want your app to behave differently when running in a test harness to skip setup screens that
3604 * would impede UI testing. e.g. a keyboard application that has a full screen setup page for
3605 * the first time it is launched.
3606 *
3607 * <p>Note that you should <em>not</em> use this to determine whether or not your app is running
3608 * an instrumentation test, as it is not set for a standard device running a test.
3609 */
3610 public static boolean isRunningInUserTestHarness() {
3611 return SystemProperties.getBoolean("persist.sys.test_harness", false);
3612 }
3613
3614 /**
Wale Ogunwale402de822018-03-22 10:03:06 -07003615 * Unsupported compiled sdk warning should always be shown for the intput activity
3616 * even in cases where the system would normally not show the warning. E.g. when running in a
3617 * test harness.
3618 *
3619 * @param activity The component name of the activity to always show the warning for.
3620 *
3621 * @hide
3622 */
3623 @TestApi
3624 public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) {
3625 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07003626 getTaskService().alwaysShowUnsupportedCompileSdkWarning(activity);
Wale Ogunwale402de822018-03-22 10:03:06 -07003627 } catch (RemoteException e) {
3628 throw e.rethrowFromSystemServer();
3629 }
3630 }
3631
3632 /**
Peter Visontay8d224ca2011-02-18 16:39:19 +00003633 * Returns the launch count of each installed package.
3634 *
3635 * @hide
3636 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003637 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00003638 try {
3639 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
3640 ServiceManager.getService("usagestats"));
3641 if (usageStatsService == null) {
3642 return new HashMap<String, Integer>();
3643 }
3644
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003645 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
3646 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00003647 if (allPkgUsageStats == null) {
3648 return new HashMap<String, Integer>();
3649 }
3650
Peter Visontay8d224ca2011-02-18 16:39:19 +00003651 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003652 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
3653 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00003654 }
3655
3656 return launchCounts;
3657 } catch (RemoteException e) {
3658 Log.w(TAG, "Could not query launch counts", e);
3659 return new HashMap<String, Integer>();
3660 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003661 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003662
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003663 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003664 @UnsupportedAppUsage
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003665 public static int checkComponentPermission(String permission, int uid,
3666 int owningUid, boolean exported) {
3667 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08003668 final int appId = UserHandle.getAppId(uid);
3669 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003670 return PackageManager.PERMISSION_GRANTED;
3671 }
3672 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003673 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003674 return PackageManager.PERMISSION_DENIED;
3675 }
3676 // If there is a uid that owns whatever is being accessed, it has
3677 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003678 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003679 return PackageManager.PERMISSION_GRANTED;
3680 }
3681 // If the target is not exported, then nobody else can get to it.
3682 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07003683 /*
3684 RuntimeException here = new RuntimeException("here");
3685 here.fillInStackTrace();
3686 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
3687 here);
3688 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003689 return PackageManager.PERMISSION_DENIED;
3690 }
3691 if (permission == null) {
3692 return PackageManager.PERMISSION_GRANTED;
3693 }
3694 try {
3695 return AppGlobals.getPackageManager()
3696 .checkUidPermission(permission, uid);
3697 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003698 throw e.rethrowFromSystemServer();
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003699 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003700 }
3701
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003702 /** @hide */
3703 public static int checkUidPermission(String permission, int uid) {
3704 try {
3705 return AppGlobals.getPackageManager()
3706 .checkUidPermission(permission, uid);
3707 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003708 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003709 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003710 }
3711
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08003712 /**
3713 * @hide
3714 * Helper for dealing with incoming user arguments to system service calls.
3715 * Takes care of checking permissions and converting USER_CURRENT to the
3716 * actual current user.
3717 *
3718 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
3719 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
3720 * @param userId The user id argument supplied by the caller -- this is the user
3721 * they want to run as.
3722 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
3723 * to get a USER_ALL returned and deal with it correctly. If false,
3724 * an exception will be thrown if USER_ALL is supplied.
3725 * @param requireFull If true, the caller must hold
3726 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
3727 * different user than their current process; otherwise they must hold
3728 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
3729 * @param name Optional textual name of the incoming call; only for generating error messages.
3730 * @param callerPackage Optional package name of caller; only for error messages.
3731 *
3732 * @return Returns the user ID that the call should run as. Will always be a concrete
3733 * user number, unless <var>allowAll</var> is true in which case it could also be
3734 * USER_ALL.
3735 */
Dianne Hackborn41203752012-08-31 14:05:51 -07003736 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
3737 boolean allowAll, boolean requireFull, String name, String callerPackage) {
3738 if (UserHandle.getUserId(callingUid) == userId) {
3739 return userId;
3740 }
3741 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003742 return getService().handleIncomingUser(callingPid,
Dianne Hackborn41203752012-08-31 14:05:51 -07003743 callingUid, userId, allowAll, requireFull, name, callerPackage);
3744 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003745 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003746 }
3747 }
3748
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07003749 /**
3750 * Gets the userId of the current foreground user. Requires system permissions.
3751 * @hide
3752 */
3753 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003754 @RequiresPermission(anyOf = {
3755 "android.permission.INTERACT_ACROSS_USERS",
3756 "android.permission.INTERACT_ACROSS_USERS_FULL"
3757 })
Dianne Hackborn41203752012-08-31 14:05:51 -07003758 public static int getCurrentUser() {
3759 UserInfo ui;
3760 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003761 ui = getService().getCurrentUser();
Dianne Hackborn41203752012-08-31 14:05:51 -07003762 return ui != null ? ui.id : 0;
3763 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003764 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003765 }
3766 }
3767
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003768 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003769 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003770 * @hide
3771 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003772 @UnsupportedAppUsage
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003773 public boolean switchUser(int userid) {
3774 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003775 return getService().switchUser(userid);
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003776 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003777 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003778 }
3779 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003780
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003781 /**
Varun Shah3e75d752018-11-30 18:47:05 -08003782 * Returns whether switching to provided user was successful.
3783 *
3784 * @param user the user to switch to.
Varun Shahe7f6b542019-01-15 17:04:59 -08003785 *
3786 * @throws IllegalArgumentException if the user is null.
Varun Shah3e75d752018-11-30 18:47:05 -08003787 * @hide
3788 */
3789 @SystemApi
3790 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Varun Shahe7f6b542019-01-15 17:04:59 -08003791 public boolean switchUser(@NonNull UserHandle user) {
3792 if (user == null) {
3793 throw new IllegalArgumentException("UserHandle cannot be null.");
3794 }
Varun Shah3e75d752018-11-30 18:47:05 -08003795 return switchUser(user.getIdentifier());
3796 }
3797
3798 /**
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003799 * Logs out current current foreground user by switching to the system user and stopping the
3800 * user being switched from.
3801 * @hide
3802 */
3803 public static void logoutCurrentUser() {
3804 int currentUser = ActivityManager.getCurrentUser();
3805 if (currentUser != UserHandle.USER_SYSTEM) {
3806 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003807 getService().switchUser(UserHandle.USER_SYSTEM);
3808 getService().stopUser(currentUser, /* force= */ false, null);
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003809 } catch (RemoteException e) {
3810 e.rethrowFromSystemServer();
3811 }
3812 }
3813 }
3814
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003815 /** {@hide} */
3816 public static final int FLAG_OR_STOPPED = 1 << 0;
3817 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07003818 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07003819 /** {@hide} */
3820 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeyce18c812016-04-27 16:00:41 -06003821 /** {@hide} */
3822 public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003823
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003824 /**
3825 * Return whether the given user is actively running. This means that
3826 * the user is in the "started" state, not "stopped" -- it is currently
3827 * allowed to run code through scheduled alarms, receiving broadcasts,
3828 * etc. A started user may be either the current foreground user or a
3829 * background user; the result here does not distinguish between the two.
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003830 * @param userId the user's id. Zero indicates the default user.
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003831 * @hide
3832 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003833 @UnsupportedAppUsage
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003834 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003835 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003836 return getService().isUserRunning(userId, 0);
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003837 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003838 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003839 }
3840 }
3841
3842 /** {@hide} */
Ruben Brunke24b9a62016-02-16 21:38:24 -08003843 public boolean isVrModePackageEnabled(ComponentName component) {
3844 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003845 return getService().isVrModePackageEnabled(component);
Ruben Brunke24b9a62016-02-16 21:38:24 -08003846 } catch (RemoteException e) {
3847 throw e.rethrowFromSystemServer();
3848 }
3849 }
3850
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003851 /**
3852 * Perform a system dump of various state associated with the given application
3853 * package name. This call blocks while the dump is being performed, so should
3854 * not be done on a UI thread. The data will be written to the given file
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003855 * descriptor as text.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07003856 * @param fd The file descriptor that the dump should be written to. The file
3857 * descriptor is <em>not</em> closed by this function; the caller continues to
3858 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003859 * @param packageName The name of the package that is to be dumped.
3860 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003861 @RequiresPermission(Manifest.permission.DUMP)
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003862 public void dumpPackageState(FileDescriptor fd, String packageName) {
3863 dumpPackageStateStatic(fd, packageName);
3864 }
3865
3866 /**
3867 * @hide
3868 */
3869 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
3870 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07003871 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003872 dumpService(pw, fd, "package", new String[] { packageName });
3873 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003874 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
3875 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003876 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003877 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003878 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003879 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003880 pw.println();
Esteban Talavera838ea242017-12-19 11:48:43 +00003881 dumpService(pw, fd, "usagestats", new String[] { packageName });
Dianne Hackborn904a8572013-06-28 18:12:31 -07003882 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07003883 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003884 pw.flush();
3885 }
3886
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003887 /**
3888 * @hide
3889 */
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003890 public static boolean isSystemReady() {
3891 if (!sSystemReady) {
3892 if (ActivityThread.isSystem()) {
3893 sSystemReady =
3894 LocalServices.getService(ActivityManagerInternal.class).isSystemReady();
3895 } else {
3896 // Since this is being called from outside system server, system should be
3897 // ready by now.
3898 sSystemReady = true;
3899 }
3900 }
3901 return sSystemReady;
3902 }
3903
3904 /**
3905 * @hide
3906 */
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003907 public static void broadcastStickyIntent(Intent intent, int userId) {
3908 broadcastStickyIntent(intent, AppOpsManager.OP_NONE, userId);
3909 }
3910
3911 /**
3912 * Convenience for sending a sticky broadcast. For internal use only.
3913 *
3914 * @hide
3915 */
3916 public static void broadcastStickyIntent(Intent intent, int appOp, int userId) {
3917 try {
3918 getService().broadcastIntent(
3919 null, intent, null, null, Activity.RESULT_OK, null, null,
3920 null /*permission*/, appOp, null, false, true, userId);
3921 } catch (RemoteException ex) {
3922 }
3923 }
3924
3925 /**
3926 * @hide
3927 */
Wale Ogunwale691af682019-02-11 03:09:10 -08003928 @TestApi
3929 public static void resumeAppSwitches() throws RemoteException {
3930 getService().resumeAppSwitches();
3931 }
3932
3933 /**
3934 * @hide
3935 */
Narayan Kamath695cf722017-12-21 18:32:47 +00003936 public static void noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid,
3937 String sourcePkg, String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003938 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00003939 getService().noteWakeupAlarm((ps != null) ? ps.getTarget() : null, workSource,
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003940 sourceUid, sourcePkg, tag);
3941 } catch (RemoteException ex) {
3942 }
3943 }
3944
3945 /**
3946 * @hide
3947 */
Narayan Kamath695cf722017-12-21 18:32:47 +00003948 public static void noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid,
3949 String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003950 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00003951 getService().noteAlarmStart((ps != null) ? ps.getTarget() : null, workSource,
3952 sourceUid, tag);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003953 } catch (RemoteException ex) {
3954 }
3955 }
3956
Narayan Kamath695cf722017-12-21 18:32:47 +00003957
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003958 /**
3959 * @hide
3960 */
Narayan Kamath695cf722017-12-21 18:32:47 +00003961 public static void noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid,
3962 String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003963 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00003964 getService().noteAlarmFinish((ps != null) ? ps.getTarget() : null, workSource,
3965 sourceUid, tag);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003966 } catch (RemoteException ex) {
3967 }
3968 }
3969
3970 /**
3971 * @hide
3972 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003973 @UnsupportedAppUsage
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003974 public static IActivityManager getService() {
3975 return IActivityManagerSingleton.get();
3976 }
3977
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07003978 private static IActivityTaskManager getTaskService() {
3979 return ActivityTaskManager.getService();
3980 }
3981
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003982 @UnsupportedAppUsage
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003983 private static final Singleton<IActivityManager> IActivityManagerSingleton =
3984 new Singleton<IActivityManager>() {
3985 @Override
3986 protected IActivityManager create() {
3987 final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE);
3988 final IActivityManager am = IActivityManager.Stub.asInterface(b);
3989 return am;
3990 }
3991 };
3992
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003993 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
3994 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
3995 IBinder service = ServiceManager.checkService(name);
3996 if (service == null) {
3997 pw.println(" (Service not found)");
Dianne Hackbornc81983a2017-10-20 16:16:32 -07003998 pw.flush();
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003999 return;
4000 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004001 pw.flush();
4002 if (service instanceof Binder) {
4003 // If this is a local object, it doesn't make sense to do an async dump with it,
4004 // just directly dump.
4005 try {
4006 service.dump(fd, args);
4007 } catch (Throwable e) {
4008 pw.println("Failure dumping service:");
4009 e.printStackTrace(pw);
4010 pw.flush();
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004011 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004012 } else {
4013 // Otherwise, it is remote, do the dump asynchronously to avoid blocking.
4014 TransferPipe tp = null;
4015 try {
4016 pw.flush();
4017 tp = new TransferPipe();
4018 tp.setBufferPrefix(" ");
4019 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
4020 tp.go(fd, 10000);
4021 } catch (Throwable e) {
4022 if (tp != null) {
4023 tp.kill();
4024 }
4025 pw.println("Failure dumping service:");
4026 e.printStackTrace(pw);
4027 }
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004028 }
4029 }
Craig Mautneraea74a52014-03-08 14:23:10 -08004030
4031 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004032 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07004033 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004034 * sees the associated process with a larger pss size and, when this happens, automatically
4035 * pull a heap dump from it and allow the user to share the data. Note that this request
4036 * continues running even if the process is killed and restarted. To remove the watch,
4037 * use {@link #clearWatchHeapLimit()}.
4038 *
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07004039 * <p>This API only work if the calling process has been marked as
4040 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
4041 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004042 *
4043 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
4044 * handle heap limit reports themselves.</p>
4045 *
4046 * @param pssSize The size in bytes to set the limit at.
4047 */
4048 public void setWatchHeapLimit(long pssSize) {
4049 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004050 getService().setDumpHeapDebugLimit(null, 0, pssSize,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004051 mContext.getPackageName());
4052 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004053 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004054 }
4055 }
4056
4057 /**
4058 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
4059 * If your package has an activity handling this action, it will be launched with the
4060 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
4061 * match the activty must support this action and a MIME type of "*&#47;*".
4062 */
4063 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
4064
4065 /**
4066 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
4067 */
4068 public void clearWatchHeapLimit() {
4069 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004070 getService().setDumpHeapDebugLimit(null, 0, 0, null);
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004071 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004072 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004073 }
4074 }
4075
4076 /**
Jason Monk386c94f2014-07-14 16:42:24 -04004077 * Return whether currently in lock task mode. When in this mode
4078 * no new tasks can be created or switched to.
4079 *
4080 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00004081 *
4082 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08004083 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004084 @Deprecated
Craig Mautneraea74a52014-03-08 14:23:10 -08004085 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00004086 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
4087 }
4088
4089 /**
4090 * Return the current state of task locking. The three possible outcomes
4091 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
4092 * and {@link #LOCK_TASK_MODE_PINNED}.
4093 *
4094 * @see Activity#startLockTask()
4095 */
4096 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08004097 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07004098 return getTaskService().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08004099 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004100 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004101 }
4102 }
Winson Chung1147c402014-05-14 11:05:00 -07004103
4104 /**
Srinath Sridharane535a582016-06-27 18:13:47 -07004105 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one
4106 * thread can be a VR thread in a process at a time, and that thread may be subject to
4107 * restrictions on the amount of time it can run.
4108 *
Craig Donnerdc4796c2017-03-08 09:51:47 -08004109 * If persistent VR mode is set, whatever thread has been granted aggressive scheduling via this
4110 * method will return to normal operation, and calling this method will do nothing while
4111 * persistent VR mode is enabled.
4112 *
Srinath Sridharane535a582016-06-27 18:13:47 -07004113 * To reset the VR thread for an application, a tid of 0 can be passed.
4114 *
4115 * @see android.os.Process#myTid()
4116 * @param tid tid of the VR thread
4117 */
4118 public static void setVrThread(int tid) {
4119 try {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07004120 getTaskService().setVrThread(tid);
Srinath Sridharane535a582016-06-27 18:13:47 -07004121 } catch (RemoteException e) {
4122 // pass
4123 }
4124 }
4125
4126 /**
Craig Donnerdc4796c2017-03-08 09:51:47 -08004127 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads that persist
Jeff Sharkey910e0812017-04-21 16:29:27 -06004128 * beyond a single process. Only one thread can be a
Craig Donnerdc4796c2017-03-08 09:51:47 -08004129 * persistent VR thread at a time, and that thread may be subject to restrictions on the amount
4130 * of time it can run. Calling this method will disable aggressive scheduling for non-persistent
4131 * VR threads set via {@link #setVrThread}. If persistent VR mode is disabled then the
4132 * persistent VR thread loses its new scheduling priority; this method must be called again to
4133 * set the persistent thread.
4134 *
4135 * To reset the persistent VR thread, a tid of 0 can be passed.
4136 *
4137 * @see android.os.Process#myTid()
4138 * @param tid tid of the VR thread
4139 * @hide
4140 */
rongliu55492662018-03-21 14:34:58 -07004141 @SystemApi
Craig Donnerdc4796c2017-03-08 09:51:47 -08004142 @RequiresPermission(Manifest.permission.RESTRICTED_VR_ACCESS)
4143 public static void setPersistentVrThread(int tid) {
4144 try {
4145 getService().setPersistentVrThread(tid);
4146 } catch (RemoteException e) {
4147 // pass
4148 }
4149 }
4150
4151 /**
lumark793e0562018-07-09 22:14:33 +08004152 * @hide
4153 */
4154 @TestApi
4155 @RequiresPermission(Manifest.permission.CHANGE_CONFIGURATION)
4156 public void scheduleApplicationInfoChanged(List<String> packages, int userId) {
4157 try {
4158 getService().scheduleApplicationInfoChanged(packages, userId);
4159 } catch (RemoteException e) {
4160 throw e.rethrowFromSystemServer();
4161 }
4162 }
4163
4164 /**
Winson Chung1147c402014-05-14 11:05:00 -07004165 * The AppTask allows you to manage your own application's tasks.
4166 * See {@link android.app.ActivityManager#getAppTasks()}
4167 */
4168 public static class AppTask {
4169 private IAppTask mAppTaskImpl;
4170
4171 /** @hide */
4172 public AppTask(IAppTask task) {
4173 mAppTaskImpl = task;
4174 }
4175
4176 /**
4177 * Finishes all activities in this task and removes it from the recent tasks list.
4178 */
4179 public void finishAndRemoveTask() {
4180 try {
4181 mAppTaskImpl.finishAndRemoveTask();
4182 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004183 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004184 }
4185 }
4186
4187 /**
4188 * Get the RecentTaskInfo associated with this task.
4189 *
4190 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
4191 */
4192 public RecentTaskInfo getTaskInfo() {
4193 try {
4194 return mAppTaskImpl.getTaskInfo();
4195 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004196 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004197 }
4198 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004199
4200 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004201 * Bring this task to the foreground. If it contains activities, they will be
4202 * brought to the foreground with it and their instances re-created if needed.
4203 * If it doesn't contain activities, the root activity of the task will be
4204 * re-launched.
4205 */
4206 public void moveToFront() {
4207 try {
4208 mAppTaskImpl.moveToFront();
4209 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004210 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004211 }
4212 }
4213
4214 /**
4215 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004216 * is not currently active (that is, its id < 0), then a new activity for the given
4217 * Intent will be launched as the root of the task and the task brought to the
4218 * foreground. Otherwise, if this task is currently active and the Intent does not specify
4219 * an activity to launch in a new task, then a new activity for the given Intent will
4220 * be launched on top of the task and the task brought to the foreground. If this
4221 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
4222 * or would otherwise be launched in to a new task, then the activity not launched but
4223 * this task be brought to the foreground and a new intent delivered to the top
4224 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004225 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004226 * <p>In other words, you generally want to use an Intent here that does not specify
4227 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
4228 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004229 *
4230 * @param intent The Intent describing the new activity to be launched on the task.
4231 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004232 *
4233 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004234 */
4235 public void startActivity(Context context, Intent intent, Bundle options) {
4236 ActivityThread thread = ActivityThread.currentActivityThread();
4237 thread.getInstrumentation().execStartActivityFromAppTask(context,
4238 thread.getApplicationThread(), mAppTaskImpl, intent, options);
4239 }
4240
4241 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004242 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
4243 * Intent of this AppTask.
4244 *
4245 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
4246 * be set; otherwise, it will be cleared.
4247 */
4248 public void setExcludeFromRecents(boolean exclude) {
4249 try {
4250 mAppTaskImpl.setExcludeFromRecents(exclude);
4251 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004252 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004253 }
4254 }
Winson Chung1147c402014-05-14 11:05:00 -07004255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004256}