blob: dba3020d0dcd357c6dec6b6d3b8b86959d9922ab [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;
Yunfan Chen674f9692019-11-05 14:41:08 -080020import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
Winson Chungb4132992018-07-03 15:52:38 -070021
Svet Ganov019d2302015-05-04 11:07:38 -070022import android.Manifest;
Matthew Ng54bc9422017-10-02 17:16:28 -070023import android.annotation.DrawableRes;
Michal Karpinski3da5c972015-12-11 18:16:30 +000024import android.annotation.IntDef;
Jing Ji8055a3a2019-12-17 15:55:33 -080025import android.annotation.IntRange;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -070026import android.annotation.NonNull;
27import android.annotation.Nullable;
Svet Ganov019d2302015-05-04 11:07:38 -070028import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070029import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060030import android.annotation.SystemService;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070031import android.annotation.TestApi;
Artur Satayevc895b1b2019-12-10 17:47:51 +000032import android.compat.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.ComponentName;
34import android.content.Context;
35import android.content.Intent;
Yunfan Chen674f9692019-11-05 14:41:08 -080036import android.content.pm.ActivityInfo;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070037import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.content.pm.ConfigurationInfo;
39import android.content.pm.IPackageDataObserver;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070040import android.content.pm.PackageManager;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080041import android.content.pm.ParceledListSlice;
Dianne Hackborn41203752012-08-31 14:05:51 -070042import android.content.pm.UserInfo;
Wale Ogunwale68278562017-09-23 17:13:55 -070043import android.content.res.Configuration;
Kenny Root5ef44b72011-01-26 17:22:20 -080044import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.graphics.Bitmap;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070046import android.graphics.Canvas;
Winson Chunga449dc02014-05-16 11:15:04 -070047import android.graphics.Color;
Peiyong Lin9d427402019-01-23 18:39:06 -080048import android.graphics.ColorSpace;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070049import android.graphics.GraphicBuffer;
50import android.graphics.Matrix;
51import android.graphics.Point;
Craig Mautner967212c2013-04-13 21:10:58 -070052import android.graphics.Rect;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070053import android.os.BatteryStats;
Dianne Hackbornc81983a2017-10-20 16:16:32 -070054import android.os.Binder;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070055import android.os.Build;
56import android.os.Build.VERSION_CODES;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070057import android.os.Bundle;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070058import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.os.Handler;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070060import android.os.IBinder;
Maurice Lam522ecbe2018-12-04 20:21:40 -080061import android.os.LocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.os.Parcel;
63import android.os.Parcelable;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070064import android.os.Process;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070065import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000066import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070067import android.os.SystemProperties;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070068import android.os.UserHandle;
Grace Jia15b4c262020-01-07 14:25:24 -080069import android.os.UserManager;
Narayan Kamath695cf722017-12-21 18:32:47 +000070import android.os.WorkSource;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070071import android.util.ArrayMap;
Kenny Root5ef44b72011-01-26 17:22:20 -080072import android.util.DisplayMetrics;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070073import android.util.Singleton;
Winson Chung48a10a52014-08-27 14:36:51 -070074import android.util.Size;
Evan Rosky282ee672019-11-13 15:50:46 -080075import android.view.IWindowContainer;
Vinit Nayakffd9dff2019-11-05 15:20:11 -080076import android.view.Surface;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080077
Maurice Lam522ecbe2018-12-04 20:21:40 -080078import com.android.internal.app.LocalePicker;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070079import com.android.internal.app.procstats.ProcessStats;
80import com.android.internal.os.RoSystemProperties;
81import com.android.internal.os.TransferPipe;
82import com.android.internal.util.FastPrintWriter;
Dianne Hackborn337e01a2018-02-27 17:16:37 -080083import com.android.internal.util.MemInfoReader;
Malcolm Chenc99b83b2020-01-10 15:55:30 -080084import com.android.internal.util.Preconditions;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070085import com.android.server.LocalServices;
86
Craig Mautner648f69b2014-09-18 14:16:26 -070087import org.xmlpull.v1.XmlSerializer;
Kenny Root5ef44b72011-01-26 17:22:20 -080088
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070089import java.io.FileDescriptor;
90import java.io.FileOutputStream;
Craig Mautner648f69b2014-09-18 14:16:26 -070091import java.io.IOException;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070092import java.io.PrintWriter;
Michal Karpinski3da5c972015-12-11 18:16:30 +000093import java.lang.annotation.Retention;
94import java.lang.annotation.RetentionPolicy;
Winson Chung1147c402014-05-14 11:05:00 -070095import java.util.ArrayList;
Maurice Lam522ecbe2018-12-04 20:21:40 -080096import java.util.Collection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import java.util.List;
Maurice Lam522ecbe2018-12-04 20:21:40 -080098import java.util.Locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099
100/**
Dave Friedman2a3ebad2017-01-04 18:27:26 -0800101 * <p>
102 * This class gives information about, and interacts
103 * with, activities, services, and the containing
104 * process.
105 * </p>
106 *
107 * <p>
108 * A number of the methods in this class are for
109 * debugging or informational purposes and they should
110 * not be used to affect any runtime behavior of
111 * your app. These methods are called out as such in
112 * the method level documentation.
113 * </p>
114 *
115 *<p>
116 * Most application developers should not have the need to
117 * use this class, most of whose methods are for specialized
118 * use cases. However, a few methods are more broadly applicable.
119 * For instance, {@link android.app.ActivityManager#isLowRamDevice() isLowRamDevice()}
120 * enables your app to detect whether it is running on a low-memory device,
121 * and behave accordingly.
122 * {@link android.app.ActivityManager#clearApplicationUserData() clearApplicationUserData()}
123 * is for apps with reset-data functionality.
124 * </p>
125 *
126 * <p>
127 * In some special use cases, where an app interacts with
128 * its Task stack, the app may use the
129 * {@link android.app.ActivityManager.AppTask} and
130 * {@link android.app.ActivityManager.RecentTaskInfo} inner
131 * classes. However, in general, the methods in this class should
132 * be used for testing and debugging purposes only.
133 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600135@SystemService(Context.ACTIVITY_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136public class ActivityManager {
137 private static String TAG = "ActivityManager";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100139 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800142 private static volatile boolean sSystemReady = false;
143
Bryce Lee7f936862017-05-09 15:33:18 -0700144
145 private static final int FIRST_START_FATAL_ERROR_CODE = -100;
146 private static final int LAST_START_FATAL_ERROR_CODE = -1;
147 private static final int FIRST_START_SUCCESS_CODE = 0;
148 private static final int LAST_START_SUCCESS_CODE = 99;
149 private static final int FIRST_START_NON_FATAL_ERROR_CODE = 100;
150 private static final int LAST_START_NON_FATAL_ERROR_CODE = 199;
151
Sudheer Shanka8f99bff2018-10-21 16:19:53 -0700152 /**
153 * Disable hidden API checks for the newly started instrumentation.
154 * @hide
155 */
156 public static final int INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS = 1 << 0;
157 /**
158 * Mount full external storage for the newly started instrumentation.
159 * @hide
160 */
161 public static final int INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL = 1 << 1;
162
Artur Satayevab4d5af2019-10-31 12:07:55 +0000163 /**
164 * Disable test API access for the newly started instrumentation.
165 * @hide
166 */
167 public static final int INSTR_FLAG_DISABLE_TEST_API_CHECKS = 1 << 2;
168
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700169 static final class UidObserver extends IUidObserver.Stub {
170 final OnUidImportanceListener mListener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700171 final Context mContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700172
Makoto Onukid7e40582017-04-13 14:54:56 -0700173 UidObserver(OnUidImportanceListener listener, Context clientContext) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700174 mListener = listener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700175 mContext = clientContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700176 }
177
178 @Override
Hui Yu26969322019-08-21 14:56:35 -0700179 public void onUidStateChanged(int uid, int procState, long procStateSeq, int capability) {
Makoto Onukid7e40582017-04-13 14:54:56 -0700180 mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportanceForClient(
181 procState, mContext));
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700182 }
183
184 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800185 public void onUidGone(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700186 mListener.onUidImportance(uid, RunningAppProcessInfo.IMPORTANCE_GONE);
187 }
188
189 @Override
190 public void onUidActive(int uid) {
191 }
192
193 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800194 public void onUidIdle(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700195 }
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700196
197 @Override public void onUidCachedChanged(int uid, boolean cached) {
198 }
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700199 }
200
201 final ArrayMap<OnUidImportanceListener, UidObserver> mImportanceListeners = new ArrayMap<>();
202
Felipe Lemedc7af962016-01-22 18:27:03 -0800203 /**
Scott Maincc2195b2013-10-16 13:57:46 -0700204 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000205 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
Christopher Tatebd413f62013-09-18 18:31:59 -0700206 * uninstalled in lieu of the declaring one. The package named here must be
Neil Fuller71fbb812015-11-30 09:51:33 +0000207 * signed with the same certificate as the one declaring the {@code <meta-data>}.
Christopher Tatebd413f62013-09-18 18:31:59 -0700208 */
209 public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
210
Bryce Lee7f936862017-05-09 15:33:18 -0700211 // NOTE: Before adding a new start result, please reference the defined ranges to ensure the
212 // result is properly categorized.
213
Christopher Tatebd413f62013-09-18 18:31:59 -0700214 /**
Amith Yamasani42449782016-04-19 11:45:51 -0700215 * Result for IActivityManager.startVoiceActivity: active session is currently hidden.
216 * @hide
217 */
Bryce Lee7f936862017-05-09 15:33:18 -0700218 public static final int START_VOICE_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE;
Amith Yamasani42449782016-04-19 11:45:51 -0700219
220 /**
221 * Result for IActivityManager.startVoiceActivity: active session does not match
222 * the requesting token.
223 * @hide
224 */
Bryce Lee7f936862017-05-09 15:33:18 -0700225 public static final int START_VOICE_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 1;
Amith Yamasani42449782016-04-19 11:45:51 -0700226
227 /**
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700228 * Result for IActivityManager.startActivity: trying to start a background user
229 * activity that shouldn't be displayed for all users.
230 * @hide
231 */
Bryce Lee7f936862017-05-09 15:33:18 -0700232 public static final int START_NOT_CURRENT_USER_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 2;
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700233
234 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700235 * Result for IActivityManager.startActivity: trying to start an activity under voice
236 * control when that activity does not support the VOICE category.
237 * @hide
238 */
Bryce Lee7f936862017-05-09 15:33:18 -0700239 public static final int START_NOT_VOICE_COMPATIBLE = FIRST_START_FATAL_ERROR_CODE + 3;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700240
241 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700242 * Result for IActivityManager.startActivity: an error where the
243 * start had to be canceled.
244 * @hide
245 */
Bryce Lee7f936862017-05-09 15:33:18 -0700246 public static final int START_CANCELED = FIRST_START_FATAL_ERROR_CODE + 4;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700247
248 /**
249 * Result for IActivityManager.startActivity: an error where the
250 * thing being started is not an activity.
251 * @hide
252 */
Bryce Lee7f936862017-05-09 15:33:18 -0700253 public static final int START_NOT_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 5;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700254
255 /**
256 * Result for IActivityManager.startActivity: an error where the
257 * caller does not have permission to start the activity.
258 * @hide
259 */
Bryce Lee7f936862017-05-09 15:33:18 -0700260 public static final int START_PERMISSION_DENIED = FIRST_START_FATAL_ERROR_CODE + 6;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700261
262 /**
263 * Result for IActivityManager.startActivity: an error where the
264 * caller has requested both to forward a result and to receive
265 * a result.
266 * @hide
267 */
Bryce Lee7f936862017-05-09 15:33:18 -0700268 public static final int START_FORWARD_AND_REQUEST_CONFLICT = FIRST_START_FATAL_ERROR_CODE + 7;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700269
270 /**
271 * Result for IActivityManager.startActivity: an error where the
272 * requested class is not found.
273 * @hide
274 */
Bryce Lee7f936862017-05-09 15:33:18 -0700275 public static final int START_CLASS_NOT_FOUND = FIRST_START_FATAL_ERROR_CODE + 8;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700276
277 /**
278 * Result for IActivityManager.startActivity: an error where the
279 * given Intent could not be resolved to an activity.
280 * @hide
281 */
Bryce Lee7f936862017-05-09 15:33:18 -0700282 public static final int START_INTENT_NOT_RESOLVED = FIRST_START_FATAL_ERROR_CODE + 9;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700283
284 /**
Winson Chungfc3ec4c2017-06-01 15:35:48 -0700285 * Result for IActivityManager.startAssistantActivity: active session is currently hidden.
286 * @hide
287 */
288 public static final int START_ASSISTANT_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE + 10;
289
290 /**
291 * Result for IActivityManager.startAssistantActivity: active session does not match
292 * the requesting token.
293 * @hide
294 */
295 public static final int START_ASSISTANT_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 11;
296
297 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700298 * Result for IActivityManaqer.startActivity: the activity was started
299 * successfully as normal.
300 * @hide
301 */
Bryce Lee7f936862017-05-09 15:33:18 -0700302 public static final int START_SUCCESS = FIRST_START_SUCCESS_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700303
304 /**
305 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not
306 * be executed if it is the recipient, and that is indeed the case.
307 * @hide
308 */
Bryce Lee7f936862017-05-09 15:33:18 -0700309 public static final int START_RETURN_INTENT_TO_CALLER = FIRST_START_SUCCESS_CODE + 1;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700310
311 /**
312 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
313 * a task was simply brought to the foreground.
314 * @hide
315 */
Bryce Lee7f936862017-05-09 15:33:18 -0700316 public static final int START_TASK_TO_FRONT = FIRST_START_SUCCESS_CODE + 2;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700317
318 /**
319 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
320 * the given Intent was given to the existing top activity.
321 * @hide
322 */
Bryce Lee7f936862017-05-09 15:33:18 -0700323 public static final int START_DELIVERED_TO_TOP = FIRST_START_SUCCESS_CODE + 3;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700324
325 /**
326 * Result for IActivityManaqer.startActivity: request was canceled because
327 * app switches are temporarily canceled to ensure the user's last request
328 * (such as pressing home) is performed.
329 * @hide
330 */
Bryce Lee7f936862017-05-09 15:33:18 -0700331 public static final int START_SWITCHES_CANCELED = FIRST_START_NON_FATAL_ERROR_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700332
333 /**
Craig Mautneraea74a52014-03-08 14:23:10 -0800334 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started
335 * while in Lock Task Mode.
336 * @hide
337 */
Bryce Lee7f936862017-05-09 15:33:18 -0700338 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION =
339 FIRST_START_NON_FATAL_ERROR_CODE + 1;
Craig Mautneraea74a52014-03-08 14:23:10 -0800340
341 /**
Bryce Leef9d49542017-06-26 16:27:32 -0700342 * Result for IActivityManaqer.startActivity: a new activity start was aborted. Never returned
343 * externally.
344 * @hide
345 */
346 public static final int START_ABORTED = FIRST_START_NON_FATAL_ERROR_CODE + 2;
347
348 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700349 * Flag for IActivityManaqer.startActivity: do special start mode where
350 * a new activity is launched only if it is needed.
351 * @hide
352 */
353 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
354
355 /**
356 * Flag for IActivityManaqer.startActivity: launch the app for
357 * debugging.
358 * @hide
359 */
360 public static final int START_FLAG_DEBUG = 1<<1;
361
362 /**
363 * Flag for IActivityManaqer.startActivity: launch the app for
Man Caocfa78b22015-06-11 20:14:34 -0700364 * allocation tracking.
365 * @hide
366 */
Pablo Ceballosa4d4e822015-10-05 10:27:52 -0700367 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2;
Man Caocfa78b22015-06-11 20:14:34 -0700368
369 /**
Tamas Berghammerdf6cb282016-01-29 12:07:00 +0000370 * Flag for IActivityManaqer.startActivity: launch the app with
371 * native debugging support.
372 * @hide
373 */
374 public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3;
375
376 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700377 * Result for IActivityManaqer.broadcastIntent: success!
378 * @hide
379 */
380 public static final int BROADCAST_SUCCESS = 0;
381
382 /**
383 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast
384 * a sticky intent without appropriate permission.
385 * @hide
386 */
387 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
388
389 /**
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800390 * Result for IActivityManager.broadcastIntent: trying to send a broadcast
391 * to a stopped user. Fail.
392 * @hide
393 */
394 public static final int BROADCAST_FAILED_USER_STOPPED = -2;
395
396 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700397 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
398 * for a sendBroadcast operation.
399 * @hide
400 */
401 public static final int INTENT_SENDER_BROADCAST = 1;
402
403 /**
404 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
405 * for a startActivity operation.
406 * @hide
407 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100408 @UnsupportedAppUsage
Dianne Hackborna4972e92012-03-14 10:38:05 -0700409 public static final int INTENT_SENDER_ACTIVITY = 2;
410
411 /**
412 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
413 * for an activity result operation.
414 * @hide
415 */
416 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
417
418 /**
419 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
420 * for a startService operation.
421 * @hide
422 */
423 public static final int INTENT_SENDER_SERVICE = 4;
424
Christopher Tate08992ac2017-03-21 11:37:06 -0700425 /**
426 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
427 * for a startForegroundService operation.
428 * @hide
429 */
430 public static final int INTENT_SENDER_FOREGROUND_SERVICE = 5;
431
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700432 /** @hide User operation call: success! */
433 public static final int USER_OP_SUCCESS = 0;
434
435 /** @hide User operation call: given user id is not known. */
436 public static final int USER_OP_UNKNOWN_USER = -1;
437
438 /** @hide User operation call: given user id is the current user, can't be stopped. */
439 public static final int USER_OP_IS_CURRENT = -2;
440
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700441 /** @hide User operation call: system user can't be stopped. */
442 public static final int USER_OP_ERROR_IS_SYSTEM = -3;
443
444 /** @hide User operation call: one of related users cannot be stopped. */
445 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4;
446
Dianne Hackbornf097d422017-12-15 16:32:19 -0800447 /**
448 * Process states, describing the kind of state a particular process is in.
449 * When updating these, make sure to also check all related references to the
450 * constant in code, and update these arrays:
451 *
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800452 * @see com.android.internal.app.procstats.ProcessState#PROCESS_STATE_TO_STATE
453 * @see com.android.server.am.ProcessList#sProcStateToProcMem
454 * @see com.android.server.am.ProcessList#sFirstAwakePssTimes
455 * @see com.android.server.am.ProcessList#sSameAwakePssTimes
456 * @see com.android.server.am.ProcessList#sTestFirstPssTimes
457 * @see com.android.server.am.ProcessList#sTestSamePssTimes
Hui Yu26969322019-08-21 14:56:35 -0700458 * @hide
Dianne Hackbornf097d422017-12-15 16:32:19 -0800459 */
Hui Yu26969322019-08-21 14:56:35 -0700460 @IntDef(flag = false, prefix = { "PROCESS_STATE_" }, value = {
461 PROCESS_STATE_UNKNOWN, // -1
462 PROCESS_STATE_PERSISTENT, // 0
463 PROCESS_STATE_PERSISTENT_UI,
464 PROCESS_STATE_TOP,
465 PROCESS_STATE_BOUND_TOP,
466 PROCESS_STATE_FOREGROUND_SERVICE,
467 PROCESS_STATE_BOUND_FOREGROUND_SERVICE,
468 PROCESS_STATE_IMPORTANT_FOREGROUND,
469 PROCESS_STATE_IMPORTANT_BACKGROUND,
470 PROCESS_STATE_TRANSIENT_BACKGROUND,
471 PROCESS_STATE_BACKUP,
472 PROCESS_STATE_SERVICE,
473 PROCESS_STATE_RECEIVER,
474 PROCESS_STATE_TOP_SLEEPING,
475 PROCESS_STATE_HEAVY_WEIGHT,
476 PROCESS_STATE_HOME,
477 PROCESS_STATE_LAST_ACTIVITY,
478 PROCESS_STATE_CACHED_ACTIVITY,
479 PROCESS_STATE_CACHED_ACTIVITY_CLIENT,
480 PROCESS_STATE_CACHED_RECENT,
481 PROCESS_STATE_CACHED_EMPTY,
482 })
483 @Retention(RetentionPolicy.SOURCE)
484 public @interface ProcessState {}
485
Dianne Hackbornf097d422017-12-15 16:32:19 -0800486
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800487 /** @hide Not a real process state. */
488 public static final int PROCESS_STATE_UNKNOWN = -1;
Ruben Brunka27eef42015-01-28 15:04:16 -0800489
Dianne Hackborna413dc02013-07-12 12:02:55 -0700490 /** @hide Process is a persistent system process. */
491 public static final int PROCESS_STATE_PERSISTENT = 0;
492
493 /** @hide Process is a persistent system process and is doing UI. */
494 public static final int PROCESS_STATE_PERSISTENT_UI = 1;
495
Dianne Hackbornc8230512013-07-13 21:32:12 -0700496 /** @hide Process is hosting the current top activities. Note that this covers
497 * all activities that are visible to the user. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100498 @UnsupportedAppUsage
Dianne Hackborna413dc02013-07-12 12:02:55 -0700499 public static final int PROCESS_STATE_TOP = 2;
500
Amith Yamasanif235d0b2019-03-20 22:49:43 -0700501 /** @hide Process is bound to a TOP app. This is ranked below SERVICE_LOCATION so that
502 * it doesn't get the capability of location access while-in-use. */
Hui Yu26969322019-08-21 14:56:35 -0700503 public static final int PROCESS_STATE_BOUND_TOP = 3;
Amith Yamasanif235d0b2019-03-20 22:49:43 -0700504
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700505 /** @hide Process is hosting a foreground service. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100506 @UnsupportedAppUsage
Hui Yu26969322019-08-21 14:56:35 -0700507 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4;
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -0800508
509 /** @hide Process is hosting a foreground service due to a system binding. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100510 @UnsupportedAppUsage
Hui Yu26969322019-08-21 14:56:35 -0700511 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 5;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700512
Dianne Hackborna413dc02013-07-12 12:02:55 -0700513 /** @hide Process is important to the user, and something they are aware of. */
Hui Yu26969322019-08-21 14:56:35 -0700514 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700515
516 /** @hide Process is important to the user, but not something they are aware of. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100517 @UnsupportedAppUsage
Hui Yu26969322019-08-21 14:56:35 -0700518 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700519
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700520 /** @hide Process is in the background transient so we will try to keep running. */
Hui Yu26969322019-08-21 14:56:35 -0700521 public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 8;
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700522
Dianne Hackborna413dc02013-07-12 12:02:55 -0700523 /** @hide Process is in the background running a backup/restore operation. */
Hui Yu26969322019-08-21 14:56:35 -0700524 public static final int PROCESS_STATE_BACKUP = 9;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700525
Dianne Hackbornc8230512013-07-13 21:32:12 -0700526 /** @hide Process is in the background running a service. Unlike oom_adj, this level
527 * is used for both the normal running in background state and the executing
528 * operations state. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100529 @UnsupportedAppUsage
Hui Yu26969322019-08-21 14:56:35 -0700530 public static final int PROCESS_STATE_SERVICE = 10;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700531
Dianne Hackbornc8230512013-07-13 21:32:12 -0700532 /** @hide Process is in the background running a receiver. Note that from the
Kweku Adamse6b00c22017-10-23 16:46:45 -0700533 * perspective of oom_adj, receivers run at a higher foreground level, but for our
Dianne Hackbornc8230512013-07-13 21:32:12 -0700534 * prioritization here that is not necessary and putting them below services means
535 * many fewer changes in some process states as they receive broadcasts. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100536 @UnsupportedAppUsage
Hui Yu26969322019-08-21 14:56:35 -0700537 public static final int PROCESS_STATE_RECEIVER = 11;
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800538
539 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
Hui Yu26969322019-08-21 14:56:35 -0700540 public static final int PROCESS_STATE_TOP_SLEEPING = 12;
Dianne Hackbornf097d422017-12-15 16:32:19 -0800541
542 /** @hide Process is in the background, but it can't restore its state so we want
543 * to try to avoid killing it. */
Hui Yu26969322019-08-21 14:56:35 -0700544 public static final int PROCESS_STATE_HEAVY_WEIGHT = 13;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700545
Dianne Hackborna413dc02013-07-12 12:02:55 -0700546 /** @hide Process is in the background but hosts the home activity. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100547 @UnsupportedAppUsage
Hui Yu26969322019-08-21 14:56:35 -0700548 public static final int PROCESS_STATE_HOME = 14;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700549
550 /** @hide Process is in the background but hosts the last shown activity. */
Hui Yu26969322019-08-21 14:56:35 -0700551 public static final int PROCESS_STATE_LAST_ACTIVITY = 15;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700552
Dianne Hackbornc8230512013-07-13 21:32:12 -0700553 /** @hide Process is being cached for later use and contains activities. */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100554 @UnsupportedAppUsage
Hui Yu26969322019-08-21 14:56:35 -0700555 public static final int PROCESS_STATE_CACHED_ACTIVITY = 16;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700556
557 /** @hide Process is being cached for later use and is a client of another cached
558 * process that contains activities. */
Hui Yu26969322019-08-21 14:56:35 -0700559 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 17;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700560
Dianne Hackborn68a06332017-11-15 17:54:18 -0800561 /** @hide Process is being cached for later use and has an activity that corresponds
562 * to an existing recent task. */
Hui Yu26969322019-08-21 14:56:35 -0700563 public static final int PROCESS_STATE_CACHED_RECENT = 18;
Dianne Hackborn68a06332017-11-15 17:54:18 -0800564
Dianne Hackbornc8230512013-07-13 21:32:12 -0700565 /** @hide Process is being cached for later use and is empty. */
Hui Yu26969322019-08-21 14:56:35 -0700566 public static final int PROCESS_STATE_CACHED_EMPTY = 19;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700567
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800568 /** @hide Process does not exist. */
Hui Yu26969322019-08-21 14:56:35 -0700569 public static final int PROCESS_STATE_NONEXISTENT = 20;
570
571 /**
572 * The set of flags for process capability.
573 * @hide
574 */
575 @IntDef(flag = true, prefix = { "PROCESS_CAPABILITY_" }, value = {
576 PROCESS_CAPABILITY_NONE,
577 PROCESS_CAPABILITY_FOREGROUND_LOCATION,
Hui Yu85679b42020-01-15 15:52:08 -0800578 PROCESS_CAPABILITY_FOREGROUND_CAMERA,
579 PROCESS_CAPABILITY_FOREGROUND_MICROPHONE,
Hui Yu26969322019-08-21 14:56:35 -0700580 })
581 @Retention(RetentionPolicy.SOURCE)
582 public @interface ProcessCapability {}
583
584 /** @hide Process does not have any capability */
585 @TestApi
586 public static final int PROCESS_CAPABILITY_NONE = 0;
587
588 /** @hide Process can access location while in foreground */
589 @TestApi
590 public static final int PROCESS_CAPABILITY_FOREGROUND_LOCATION = 1 << 0;
591
Hui Yu85679b42020-01-15 15:52:08 -0800592 /** @hide Process can access camera while in foreground */
593 @TestApi
594 public static final int PROCESS_CAPABILITY_FOREGROUND_CAMERA = 1 << 1;
595
596 /** @hide Process can access microphone while in foreground */
597 @TestApi
598 public static final int PROCESS_CAPABILITY_FOREGROUND_MICROPHONE = 1 << 2;
599
Hui Yu26969322019-08-21 14:56:35 -0700600 /** @hide all capabilities, the ORing of all flags in {@link ProcessCapability}*/
601 @TestApi
Hui Yu85679b42020-01-15 15:52:08 -0800602 public static final int PROCESS_CAPABILITY_ALL = PROCESS_CAPABILITY_FOREGROUND_LOCATION
603 | PROCESS_CAPABILITY_FOREGROUND_CAMERA
604 | PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
Hui Yu88910de2019-12-16 14:35:27 -0800605 /**
606 * All explicit capabilities. These are capabilities that need to be specified from manifest
607 * file.
608 * @hide
609 */
610 @TestApi
611 public static final int PROCESS_CAPABILITY_ALL_EXPLICIT =
612 PROCESS_CAPABILITY_FOREGROUND_LOCATION;
613
614 /**
615 * All implicit capabilities. There are capabilities that process automatically have.
616 * @hide
617 */
618 @TestApi
619 public static final int PROCESS_CAPABILITY_ALL_IMPLICIT = PROCESS_CAPABILITY_FOREGROUND_CAMERA
620 | PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800621
Bookatzdb026a22018-01-10 19:01:56 -0800622 // NOTE: If PROCESS_STATEs are added, then new fields must be added
623 // to frameworks/base/core/proto/android/app/enums.proto and the following method must
Kweku Adamse6b00c22017-10-23 16:46:45 -0700624 // be updated to correctly map between them.
Bookatzdb026a22018-01-10 19:01:56 -0800625 // However, if the current ActivityManager values are merely modified, no update should be made
626 // to enums.proto, to which values can only be added but never modified. Note that the proto
627 // versions do NOT have the ordering restrictions of the ActivityManager process state.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700628 /**
Bookatzdb026a22018-01-10 19:01:56 -0800629 * Maps ActivityManager.PROCESS_STATE_ values to enums.proto ProcessStateEnum value.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700630 *
631 * @param amInt a process state of the form ActivityManager.PROCESS_STATE_
Bookatzdb026a22018-01-10 19:01:56 -0800632 * @return the value of the corresponding enums.proto ProcessStateEnum value.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700633 * @hide
634 */
635 public static final int processStateAmToProto(int amInt) {
Bookatzdb026a22018-01-10 19:01:56 -0800636 switch (amInt) {
637 case PROCESS_STATE_UNKNOWN:
638 return AppProtoEnums.PROCESS_STATE_UNKNOWN;
639 case PROCESS_STATE_PERSISTENT:
640 return AppProtoEnums.PROCESS_STATE_PERSISTENT;
641 case PROCESS_STATE_PERSISTENT_UI:
642 return AppProtoEnums.PROCESS_STATE_PERSISTENT_UI;
643 case PROCESS_STATE_TOP:
644 return AppProtoEnums.PROCESS_STATE_TOP;
Amith Yamasanif235d0b2019-03-20 22:49:43 -0700645 case PROCESS_STATE_BOUND_TOP:
646 return AppProtoEnums.PROCESS_STATE_BOUND_TOP;
Bookatzdb026a22018-01-10 19:01:56 -0800647 case PROCESS_STATE_FOREGROUND_SERVICE:
648 return AppProtoEnums.PROCESS_STATE_FOREGROUND_SERVICE;
649 case PROCESS_STATE_BOUND_FOREGROUND_SERVICE:
650 return AppProtoEnums.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
651 case PROCESS_STATE_IMPORTANT_FOREGROUND:
652 return AppProtoEnums.PROCESS_STATE_IMPORTANT_FOREGROUND;
653 case PROCESS_STATE_IMPORTANT_BACKGROUND:
654 return AppProtoEnums.PROCESS_STATE_IMPORTANT_BACKGROUND;
655 case PROCESS_STATE_TRANSIENT_BACKGROUND:
656 return AppProtoEnums.PROCESS_STATE_TRANSIENT_BACKGROUND;
657 case PROCESS_STATE_BACKUP:
658 return AppProtoEnums.PROCESS_STATE_BACKUP;
659 case PROCESS_STATE_SERVICE:
660 return AppProtoEnums.PROCESS_STATE_SERVICE;
661 case PROCESS_STATE_RECEIVER:
662 return AppProtoEnums.PROCESS_STATE_RECEIVER;
663 case PROCESS_STATE_TOP_SLEEPING:
664 return AppProtoEnums.PROCESS_STATE_TOP_SLEEPING;
665 case PROCESS_STATE_HEAVY_WEIGHT:
666 return AppProtoEnums.PROCESS_STATE_HEAVY_WEIGHT;
667 case PROCESS_STATE_HOME:
668 return AppProtoEnums.PROCESS_STATE_HOME;
669 case PROCESS_STATE_LAST_ACTIVITY:
670 return AppProtoEnums.PROCESS_STATE_LAST_ACTIVITY;
671 case PROCESS_STATE_CACHED_ACTIVITY:
672 return AppProtoEnums.PROCESS_STATE_CACHED_ACTIVITY;
673 case PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
674 return AppProtoEnums.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
675 case PROCESS_STATE_CACHED_RECENT:
676 return AppProtoEnums.PROCESS_STATE_CACHED_RECENT;
677 case PROCESS_STATE_CACHED_EMPTY:
678 return AppProtoEnums.PROCESS_STATE_CACHED_EMPTY;
679 case PROCESS_STATE_NONEXISTENT:
680 return AppProtoEnums.PROCESS_STATE_NONEXISTENT;
681 default:
682 // ActivityManager process state (amInt)
683 // could not be mapped to an AppProtoEnums ProcessState state.
684 return AppProtoEnums.PROCESS_STATE_UNKNOWN_TO_PROTO;
685 }
Kweku Adamse6b00c22017-10-23 16:46:45 -0700686 }
687
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700688 /** @hide The lowest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800689 public static final int MIN_PROCESS_STATE = PROCESS_STATE_PERSISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700690
691 /** @hide The highest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800692 public static final int MAX_PROCESS_STATE = PROCESS_STATE_NONEXISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700693
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700694 /** @hide Should this process state be considered a background state? */
695 public static final boolean isProcStateBackground(int procState) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700696 return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700697 }
698
Amith Yamasania0a30a12019-01-22 11:38:06 -0800699 /** @hide Is this a foreground service type? */
700 public static boolean isForegroundService(int procState) {
Hui Yu26969322019-08-21 14:56:35 -0700701 return procState == PROCESS_STATE_FOREGROUND_SERVICE;
Amith Yamasania0a30a12019-01-22 11:38:06 -0800702 }
703
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700704 /** @hide requestType for assist context: only basic information. */
705 public static final int ASSIST_CONTEXT_BASIC = 0;
706
707 /** @hide requestType for assist context: generate full AssistStructure. */
708 public static final int ASSIST_CONTEXT_FULL = 1;
709
Felipe Leme640f30a2017-03-06 15:44:06 -0800710 /** @hide requestType for assist context: generate full AssistStructure for autofill. */
711 public static final int ASSIST_CONTEXT_AUTOFILL = 2;
Felipe Leme6d553872016-12-08 17:13:25 -0800712
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700713 /** @hide Flag for registerUidObserver: report changes in process state. */
714 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
715
716 /** @hide Flag for registerUidObserver: report uid gone. */
717 public static final int UID_OBSERVER_GONE = 1<<1;
718
719 /** @hide Flag for registerUidObserver: report uid has become idle. */
720 public static final int UID_OBSERVER_IDLE = 1<<2;
721
722 /** @hide Flag for registerUidObserver: report uid has become active. */
723 public static final int UID_OBSERVER_ACTIVE = 1<<3;
724
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700725 /** @hide Flag for registerUidObserver: report uid cached state has changed. */
726 public static final int UID_OBSERVER_CACHED = 1<<4;
727
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800728 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700729 public static final int APP_START_MODE_NORMAL = 0;
730
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800731 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700732 public static final int APP_START_MODE_DELAYED = 1;
733
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800734 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later, with
Dianne Hackborn85e35642017-01-12 15:10:57 -0800735 * rigid errors (throwing exception). */
736 public static final int APP_START_MODE_DELAYED_RIGID = 2;
737
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800738 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: disable/cancel pending
Dianne Hackborn85e35642017-01-12 15:10:57 -0800739 * launches; this is the mode for ephemeral apps. */
740 public static final int APP_START_MODE_DISABLED = 3;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700741
Benjamin Franz43261142015-02-11 15:59:44 +0000742 /**
743 * Lock task mode is not active.
744 */
745 public static final int LOCK_TASK_MODE_NONE = 0;
746
747 /**
748 * Full lock task mode is active.
749 */
750 public static final int LOCK_TASK_MODE_LOCKED = 1;
751
752 /**
753 * App pinning mode is active.
754 */
755 public static final int LOCK_TASK_MODE_PINNED = 2;
756
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700757 Point mAppTaskThumbnailSize;
758
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100759 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 /*package*/ ActivityManager(Context context, Handler handler) {
761 mContext = context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 }
763
764 /**
Bryce Lee7f936862017-05-09 15:33:18 -0700765 * Returns whether the launch was successful.
766 * @hide
767 */
768 public static final boolean isStartResultSuccessful(int result) {
769 return FIRST_START_SUCCESS_CODE <= result && result <= LAST_START_SUCCESS_CODE;
770 }
771
772 /**
773 * Returns whether the launch result was a fatal error.
774 * @hide
775 */
776 public static final boolean isStartResultFatalError(int result) {
777 return FIRST_START_FATAL_ERROR_CODE <= result && result <= LAST_START_FATAL_ERROR_CODE;
778 }
779
780 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700781 * Screen compatibility mode: the application most always run in
782 * compatibility mode.
783 * @hide
784 */
785 public static final int COMPAT_MODE_ALWAYS = -1;
786
787 /**
788 * Screen compatibility mode: the application can never run in
789 * compatibility mode.
790 * @hide
791 */
792 public static final int COMPAT_MODE_NEVER = -2;
793
794 /**
795 * Screen compatibility mode: unknown.
796 * @hide
797 */
798 public static final int COMPAT_MODE_UNKNOWN = -3;
799
800 /**
801 * Screen compatibility mode: the application currently has compatibility
802 * mode disabled.
803 * @hide
804 */
805 public static final int COMPAT_MODE_DISABLED = 0;
806
807 /**
808 * Screen compatibility mode: the application currently has compatibility
809 * mode enabled.
810 * @hide
811 */
812 public static final int COMPAT_MODE_ENABLED = 1;
813
814 /**
815 * Screen compatibility mode: request to toggle the application's
816 * compatibility mode.
817 * @hide
818 */
819 public static final int COMPAT_MODE_TOGGLE = 2;
820
Marc Hittinger17fb5962017-04-05 15:34:38 -0700821 private static final boolean DEVELOPMENT_FORCE_LOW_RAM =
822 SystemProperties.getBoolean("debug.force_low_ram", false);
823
Wale Ogunwale3797c222015-10-27 14:21:58 -0700824 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700825 public int getFrontActivityScreenCompatMode() {
826 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700827 return getTaskService().getFrontActivityScreenCompatMode();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700828 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700829 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700830 }
831 }
832
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700833 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700834 public void setFrontActivityScreenCompatMode(int mode) {
835 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700836 getTaskService().setFrontActivityScreenCompatMode(mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700837 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700838 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700839 }
840 }
841
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700842 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700843 public int getPackageScreenCompatMode(String packageName) {
844 try {
Wale Ogunwale53783742018-09-16 10:21:51 -0700845 return getTaskService().getPackageScreenCompatMode(packageName);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700846 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700847 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700848 }
849 }
850
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700851 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700852 public void setPackageScreenCompatMode(String packageName, int mode) {
853 try {
Wale Ogunwale53783742018-09-16 10:21:51 -0700854 getTaskService().setPackageScreenCompatMode(packageName, mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700856 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700857 }
858 }
859
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700860 /** @hide */
861 public boolean getPackageAskScreenCompat(String packageName) {
862 try {
Wale Ogunwale53783742018-09-16 10:21:51 -0700863 return getTaskService().getPackageAskScreenCompat(packageName);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700864 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700865 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700866 }
867 }
868
869 /** @hide */
870 public void setPackageAskScreenCompat(String packageName, boolean ask) {
871 try {
Wale Ogunwale53783742018-09-16 10:21:51 -0700872 getTaskService().setPackageAskScreenCompat(packageName, ask);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700873 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700874 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700875 }
876 }
877
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700878 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700879 * Return the approximate per-application memory class of the current
880 * device. This gives you an idea of how hard a memory limit you should
881 * impose on your application to let the overall system work best. The
882 * returned value is in megabytes; the baseline Android memory class is
883 * 16 (which happens to be the Java heap limit of those devices); some
Kweku Adams983829f2017-12-06 14:53:50 -0800884 * devices with more memory may return 24 or even higher numbers.
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700885 */
886 public int getMemoryClass() {
887 return staticGetMemoryClass();
888 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700889
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700890 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100891 @UnsupportedAppUsage
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700892 static public int staticGetMemoryClass() {
893 // Really brain dead right now -- just take this from the configured
894 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -0800895 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -0800896 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
897 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
898 }
899 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800900 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700901
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800902 /**
903 * Return the approximate per-application memory class of the current
904 * device when an application is running with a large heap. This is the
905 * space available for memory-intensive applications; most applications
906 * should not need this amount of memory, and should instead stay with the
907 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
908 * This may be the same size as {@link #getMemoryClass()} on memory
909 * constrained devices, or it may be significantly larger on devices with
910 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800911 *
Kweku Adams983829f2017-12-06 14:53:50 -0800912 * <p>This is the size of the application's Dalvik heap if it has
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800913 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800914 */
915 public int getLargeMemoryClass() {
916 return staticGetLargeMemoryClass();
917 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700918
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800919 /** @hide */
920 static public int staticGetLargeMemoryClass() {
921 // Really brain dead right now -- just take this from the configured
922 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700923 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -0700924 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700925 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700926
927 /**
928 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
929 * is ultimately up to the device configuration, but currently it generally means
Greg Kaisere2c459e2017-10-26 10:36:37 -0700930 * something with 1GB or less of RAM. This is mostly intended to be used by apps
931 * to determine whether they should turn off certain features that require more RAM.
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700932 */
933 public boolean isLowRamDevice() {
934 return isLowRamDeviceStatic();
935 }
936
937 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100938 @UnsupportedAppUsage
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700939 public static boolean isLowRamDeviceStatic() {
Marc Hittinger17fb5962017-04-05 15:34:38 -0700940 return RoSystemProperties.CONFIG_LOW_RAM ||
941 (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700942 }
943
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700944 /**
Michael Kwan15eb9982017-04-14 12:34:46 -0700945 * Returns true if this is a small battery device. Exactly whether a device is considered to be
946 * small battery is ultimately up to the device configuration, but currently it generally means
947 * something in the class of a device with 1000 mAh or less. This is mostly intended to be used
948 * to determine whether certain features should be altered to account for a drastically smaller
949 * battery.
950 * @hide
951 */
952 public static boolean isSmallBatteryDevice() {
953 return RoSystemProperties.CONFIG_SMALL_BATTERY;
954 }
955
956 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -0700957 * Used by persistent processes to determine if they are running on a
958 * higher-end device so should be okay using hardware drawing acceleration
959 * (which tends to consume a lot more RAM).
960 * @hide
961 */
Adrian Roos5af40872019-07-15 12:05:54 +0200962 @TestApi
Jeff Brown98365d72012-08-19 20:30:52 -0700963 static public boolean isHighEndGfx() {
Luis Hector Chavez5e11e5e2018-03-23 14:37:01 -0700964 return !isLowRamDeviceStatic()
965 && !RoSystemProperties.CONFIG_AVOID_GFX_ACCEL
966 && !Resources.getSystem()
967 .getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -0700968 }
969
970 /**
Dianne Hackborn337e01a2018-02-27 17:16:37 -0800971 * Return the total number of bytes of RAM this device has.
972 * @hide
973 */
974 @TestApi
975 public long getTotalRam() {
976 MemInfoReader memreader = new MemInfoReader();
977 memreader.readMemInfo();
978 return memreader.getTotalSize();
979 }
980
981 /**
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700982 * TODO(b/80414790): Remove once no longer on hiddenapi-light-greylist.txt
Dianne Hackborn852975d2014-08-22 17:42:43 -0700983 * @hide
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700984 * @deprecated Use {@link ActivityTaskManager#getMaxRecentTasksStatic()}
Dianne Hackborn852975d2014-08-22 17:42:43 -0700985 */
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700986 @Deprecated
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100987 @UnsupportedAppUsage
Dianne Hackborn852975d2014-08-22 17:42:43 -0700988 static public int getMaxRecentTasksStatic() {
Wale Ogunwale65ebd952018-04-25 15:41:44 -0700989 return ActivityTaskManager.getMaxRecentTasksStatic();
Matthew Ng626e0cc2016-12-07 17:25:53 -0800990 }
991
Jeff Sharkey000ce802017-04-29 13:13:27 -0600992 /** @removed */
Winson Chung709904f2017-04-25 11:00:48 -0700993 @Deprecated
Winson Chunga29eb982016-12-14 12:01:27 -0800994 public static int getMaxNumPictureInPictureActions() {
Winson Chung709904f2017-04-25 11:00:48 -0700995 return 3;
Winson Chunga29eb982016-12-14 12:01:27 -0800996 }
997
998 /**
Winson Chung1147c402014-05-14 11:05:00 -0700999 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -07001000 */
Winson Chunga449dc02014-05-16 11:15:04 -07001001 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -07001002 /** @hide */
1003 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
1004 private static final String ATTR_TASKDESCRIPTIONLABEL =
1005 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +00001006 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -07001007 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +00001008 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
1009 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Matthew Ng54bc9422017-10-02 17:16:28 -07001010 private static final String ATTR_TASKDESCRIPTIONICON_FILENAME =
Craig Mautner648f69b2014-09-18 14:16:26 -07001011 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
Matthew Ng54bc9422017-10-02 17:16:28 -07001012 private static final String ATTR_TASKDESCRIPTIONICON_RESOURCE =
1013 ATTR_TASKDESCRIPTION_PREFIX + "icon_resource";
Craig Mautner648f69b2014-09-18 14:16:26 -07001014
Winson Chunga449dc02014-05-16 11:15:04 -07001015 private String mLabel;
1016 private Bitmap mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001017 private int mIconRes;
Craig Mautner648f69b2014-09-18 14:16:26 -07001018 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001019 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +00001020 private int mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001021 private int mStatusBarColor;
1022 private int mNavigationBarColor;
Adrian Roos4c864592019-04-10 14:47:57 +02001023 private boolean mEnsureStatusBarContrastWhenTransparent;
1024 private boolean mEnsureNavigationBarContrastWhenTransparent;
Yunfan Chen674f9692019-11-05 14:41:08 -08001025 private int mResizeMode;
1026 private int mMinWidth;
1027 private int mMinHeight;
Winson Chung03a9bae2014-05-02 09:56:12 -07001028
1029 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001030 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001031 *
Winson Chunga449dc02014-05-16 11:15:04 -07001032 * @param label A label and description of the current state of this task.
1033 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +00001034 * @param colorPrimary A color to override the theme's primary color. This color must be
1035 * opaque.
Matthew Ng54bc9422017-10-02 17:16:28 -07001036 * @deprecated use TaskDescription constructor with icon resource instead
Winson Chung03a9bae2014-05-02 09:56:12 -07001037 */
Matthew Ng54bc9422017-10-02 17:16:28 -07001038 @Deprecated
Winson Chunga449dc02014-05-16 11:15:04 -07001039 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Yunfan Chen674f9692019-11-05 14:41:08 -08001040 this(label, icon, 0, null, colorPrimary, 0, 0, 0, false, false,
1041 RESIZE_MODE_RESIZEABLE, -1, -1);
Matthew Ng54bc9422017-10-02 17:16:28 -07001042 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1043 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1044 }
1045 }
1046
1047 /**
1048 * Creates the TaskDescription to the specified values.
1049 *
1050 * @param label A label and description of the current state of this task.
1051 * @param iconRes A drawable resource of an icon that represents the current state of this
1052 * activity.
1053 * @param colorPrimary A color to override the theme's primary color. This color must be
1054 * opaque.
1055 */
1056 public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary) {
Yunfan Chen674f9692019-11-05 14:41:08 -08001057 this(label, null, iconRes, null, colorPrimary, 0, 0, 0, false, false,
1058 RESIZE_MODE_RESIZEABLE, -1, -1);
Winson Chunga449dc02014-05-16 11:15:04 -07001059 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1060 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1061 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001062 }
1063
Winson Chung03a9bae2014-05-02 09:56:12 -07001064 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001065 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001066 *
1067 * @param label A label and description of the current state of this activity.
1068 * @param icon An icon that represents the current state of this activity.
Matthew Ng54bc9422017-10-02 17:16:28 -07001069 * @deprecated use TaskDescription constructor with icon resource instead
Winson Chung03a9bae2014-05-02 09:56:12 -07001070 */
Matthew Ng54bc9422017-10-02 17:16:28 -07001071 @Deprecated
Winson Chunga449dc02014-05-16 11:15:04 -07001072 public TaskDescription(String label, Bitmap icon) {
Yunfan Chen674f9692019-11-05 14:41:08 -08001073 this(label, icon, 0, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
Matthew Ng54bc9422017-10-02 17:16:28 -07001074 }
1075
1076 /**
1077 * Creates the TaskDescription to the specified values.
1078 *
1079 * @param label A label and description of the current state of this activity.
1080 * @param iconRes A drawable resource of an icon that represents the current state of this
1081 * activity.
1082 */
1083 public TaskDescription(String label, @DrawableRes int iconRes) {
Yunfan Chen674f9692019-11-05 14:41:08 -08001084 this(label, null, iconRes, null, 0, 0, 0, 0, false, false,
1085 RESIZE_MODE_RESIZEABLE, -1, -1);
Winson Chung03a9bae2014-05-02 09:56:12 -07001086 }
1087
1088 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001089 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001090 *
1091 * @param label A label and description of the current state of this activity.
1092 */
Winson Chunga449dc02014-05-16 11:15:04 -07001093 public TaskDescription(String label) {
Yunfan Chen674f9692019-11-05 14:41:08 -08001094 this(label, null, 0, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
Winson Chung03a9bae2014-05-02 09:56:12 -07001095 }
1096
Winson Chunga449dc02014-05-16 11:15:04 -07001097 /**
1098 * Creates an empty TaskDescription.
1099 */
1100 public TaskDescription() {
Yunfan Chen674f9692019-11-05 14:41:08 -08001101 this(null, null, 0, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1);
Winson Chung1af8eda2016-02-05 17:55:56 +00001102 }
1103
1104 /** @hide */
Matthew Ng54bc9422017-10-02 17:16:28 -07001105 public TaskDescription(String label, Bitmap bitmap, int iconRes, String iconFilename,
Adrian Roos4c864592019-04-10 14:47:57 +02001106 int colorPrimary, int colorBackground, int statusBarColor, int navigationBarColor,
1107 boolean ensureStatusBarContrastWhenTransparent,
Yunfan Chen674f9692019-11-05 14:41:08 -08001108 boolean ensureNavigationBarContrastWhenTransparent, int resizeMode, int minWidth,
1109 int minHeight) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001110 mLabel = label;
Matthew Ng54bc9422017-10-02 17:16:28 -07001111 mIcon = bitmap;
1112 mIconRes = iconRes;
Winson Chung1af8eda2016-02-05 17:55:56 +00001113 mIconFilename = iconFilename;
1114 mColorPrimary = colorPrimary;
1115 mColorBackground = colorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001116 mStatusBarColor = statusBarColor;
1117 mNavigationBarColor = navigationBarColor;
Adrian Roos4c864592019-04-10 14:47:57 +02001118 mEnsureStatusBarContrastWhenTransparent = ensureStatusBarContrastWhenTransparent;
1119 mEnsureNavigationBarContrastWhenTransparent =
1120 ensureNavigationBarContrastWhenTransparent;
Yunfan Chen674f9692019-11-05 14:41:08 -08001121 mResizeMode = resizeMode;
1122 mMinWidth = minWidth;
1123 mMinHeight = minHeight;
Winson Chung03a9bae2014-05-02 09:56:12 -07001124 }
1125
Winson Chunga449dc02014-05-16 11:15:04 -07001126 /**
1127 * Creates a copy of another TaskDescription.
1128 */
1129 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -08001130 copyFrom(td);
1131 }
1132
1133 /**
1134 * Copies this the values from another TaskDescription.
1135 * @hide
1136 */
1137 public void copyFrom(TaskDescription other) {
1138 mLabel = other.mLabel;
1139 mIcon = other.mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001140 mIconRes = other.mIconRes;
Winsonb6403152016-02-23 13:32:09 -08001141 mIconFilename = other.mIconFilename;
1142 mColorPrimary = other.mColorPrimary;
1143 mColorBackground = other.mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001144 mStatusBarColor = other.mStatusBarColor;
1145 mNavigationBarColor = other.mNavigationBarColor;
Adrian Roos4c864592019-04-10 14:47:57 +02001146 mEnsureStatusBarContrastWhenTransparent = other.mEnsureStatusBarContrastWhenTransparent;
1147 mEnsureNavigationBarContrastWhenTransparent =
1148 other.mEnsureNavigationBarContrastWhenTransparent;
Yunfan Chen674f9692019-11-05 14:41:08 -08001149 mResizeMode = other.mResizeMode;
1150 mMinWidth = other.mMinWidth;
1151 mMinHeight = other.mMinHeight;
Winson Chunga449dc02014-05-16 11:15:04 -07001152 }
1153
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001154 /**
Mehdi Alizadehc5e29902019-11-14 17:18:44 -08001155 * Copies values from another TaskDescription, but preserves the hidden fields if they
1156 * weren't set on {@code other}. Public fields will be overwritten anyway.
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001157 * @hide
1158 */
1159 public void copyFromPreserveHiddenFields(TaskDescription other) {
1160 mLabel = other.mLabel;
1161 mIcon = other.mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001162 mIconRes = other.mIconRes;
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001163 mIconFilename = other.mIconFilename;
1164 mColorPrimary = other.mColorPrimary;
Mehdi Alizadehc5e29902019-11-14 17:18:44 -08001165
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001166 if (other.mColorBackground != 0) {
1167 mColorBackground = other.mColorBackground;
1168 }
1169 if (other.mStatusBarColor != 0) {
1170 mStatusBarColor = other.mStatusBarColor;
1171 }
1172 if (other.mNavigationBarColor != 0) {
1173 mNavigationBarColor = other.mNavigationBarColor;
1174 }
Mehdi Alizadehc5e29902019-11-14 17:18:44 -08001175
Adrian Roos4c864592019-04-10 14:47:57 +02001176 mEnsureStatusBarContrastWhenTransparent = other.mEnsureStatusBarContrastWhenTransparent;
1177 mEnsureNavigationBarContrastWhenTransparent =
1178 other.mEnsureNavigationBarContrastWhenTransparent;
Mehdi Alizadehc5e29902019-11-14 17:18:44 -08001179
1180 if (other.mResizeMode != RESIZE_MODE_RESIZEABLE) {
1181 mResizeMode = other.mResizeMode;
1182 }
1183 if (other.mMinWidth != -1) {
1184 mMinWidth = other.mMinWidth;
1185 }
1186 if (other.mMinHeight != -1) {
1187 mMinHeight = other.mMinHeight;
1188 }
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001189 }
1190
Winson Chunga449dc02014-05-16 11:15:04 -07001191 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001192 readFromParcel(source);
1193 }
1194
1195 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001196 * Sets the label for this task description.
1197 * @hide
1198 */
1199 public void setLabel(String label) {
1200 mLabel = label;
1201 }
1202
1203 /**
1204 * Sets the primary color for this task description.
1205 * @hide
1206 */
1207 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001208 // Ensure that the given color is valid
1209 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1210 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1211 }
1212 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001213 }
1214
1215 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001216 * Sets the background color for this task description.
1217 * @hide
1218 */
1219 public void setBackgroundColor(int backgroundColor) {
1220 // Ensure that the given color is valid
1221 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1222 throw new RuntimeException("A TaskDescription's background color should be opaque");
1223 }
1224 mColorBackground = backgroundColor;
1225 }
1226
1227 /**
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001228 * @hide
1229 */
1230 public void setStatusBarColor(int statusBarColor) {
1231 mStatusBarColor = statusBarColor;
1232 }
1233
1234 /**
1235 * @hide
1236 */
1237 public void setNavigationBarColor(int navigationBarColor) {
1238 mNavigationBarColor = navigationBarColor;
1239 }
1240
1241 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001242 * Sets the icon for this task description.
1243 * @hide
1244 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001245 @UnsupportedAppUsage
Winson Chung2cb86c72014-06-25 12:03:30 -07001246 public void setIcon(Bitmap icon) {
1247 mIcon = icon;
1248 }
1249
1250 /**
Matthew Ng54bc9422017-10-02 17:16:28 -07001251 * Sets the icon resource for this task description.
1252 * @hide
1253 */
1254 public void setIcon(int iconRes) {
1255 mIconRes = iconRes;
1256 }
1257
1258 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001259 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1260 * bitmap.
1261 * @hide
1262 */
1263 public void setIconFilename(String iconFilename) {
1264 mIconFilename = iconFilename;
1265 mIcon = null;
1266 }
1267
1268 /**
Yunfan Chen674f9692019-11-05 14:41:08 -08001269 * Sets the resize mode for this task description. Resize mode as in
1270 * {@link android.content.pm.ActivityInfo}.
1271 * @hide
1272 */
1273 public void setResizeMode(int resizeMode) {
1274 mResizeMode = resizeMode;
1275 }
1276
1277 /**
1278 * The minimal width size to show the app content in freeform mode.
1279 * @param minWidth minimal width, -1 for system default.
1280 * @hide
1281 */
1282 public void setMinWidth(int minWidth) {
1283 mMinWidth = minWidth;
1284 }
1285
1286 /**
1287 * The minimal height size to show the app content in freeform mode.
1288 * @param minHeight minimal height, -1 for system default.
1289 * @hide
1290 */
1291 public void setMinHeight(int minHeight) {
1292 mMinHeight = minHeight;
1293 }
1294
1295 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001296 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001297 */
Winson Chunga449dc02014-05-16 11:15:04 -07001298 public String getLabel() {
1299 return mLabel;
1300 }
1301
1302 /**
1303 * @return The icon that represents the current state of this task.
1304 */
1305 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001306 if (mIcon != null) {
1307 return mIcon;
1308 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001309 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001310 }
1311
1312 /** @hide */
Matthew Ng54bc9422017-10-02 17:16:28 -07001313 @TestApi
1314 public int getIconResource() {
1315 return mIconRes;
1316 }
1317
1318 /** @hide */
1319 @TestApi
Craig Mautner648f69b2014-09-18 14:16:26 -07001320 public String getIconFilename() {
1321 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001322 }
1323
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001324 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001325 @UnsupportedAppUsage
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001326 public Bitmap getInMemoryIcon() {
1327 return mIcon;
1328 }
1329
1330 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01001331 @UnsupportedAppUsage
Suprabh Shukla23593142015-11-03 17:31:15 -08001332 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001333 if (iconFilename != null) {
1334 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001335 return getTaskService().getTaskDescriptionIcon(iconFilename,
Winson Chung1af8eda2016-02-05 17:55:56 +00001336 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001337 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001338 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001339 }
1340 }
1341 return null;
1342 }
1343
Winson Chunga449dc02014-05-16 11:15:04 -07001344 /**
1345 * @return The color override on the theme's primary color.
1346 */
1347 public int getPrimaryColor() {
1348 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001349 }
1350
Winson Chung1af8eda2016-02-05 17:55:56 +00001351 /**
1352 * @return The background color.
1353 * @hide
1354 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01001355 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Winson Chung1af8eda2016-02-05 17:55:56 +00001356 public int getBackgroundColor() {
1357 return mColorBackground;
1358 }
1359
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001360 /**
1361 * @hide
1362 */
1363 public int getStatusBarColor() {
1364 return mStatusBarColor;
1365 }
1366
1367 /**
1368 * @hide
1369 */
1370 public int getNavigationBarColor() {
1371 return mNavigationBarColor;
1372 }
1373
Adrian Roos4c864592019-04-10 14:47:57 +02001374 /**
1375 * @hide
1376 */
1377 public boolean getEnsureStatusBarContrastWhenTransparent() {
1378 return mEnsureStatusBarContrastWhenTransparent;
1379 }
1380
1381 /**
1382 * @hide
1383 */
1384 public void setEnsureStatusBarContrastWhenTransparent(
1385 boolean ensureStatusBarContrastWhenTransparent) {
1386 mEnsureStatusBarContrastWhenTransparent = ensureStatusBarContrastWhenTransparent;
1387 }
1388
1389 /**
1390 * @hide
1391 */
1392 public boolean getEnsureNavigationBarContrastWhenTransparent() {
1393 return mEnsureNavigationBarContrastWhenTransparent;
1394 }
1395
1396 /**
1397 * @hide
1398 */
1399 public void setEnsureNavigationBarContrastWhenTransparent(
1400 boolean ensureNavigationBarContrastWhenTransparent) {
1401 mEnsureNavigationBarContrastWhenTransparent =
1402 ensureNavigationBarContrastWhenTransparent;
1403 }
1404
Yunfan Chen674f9692019-11-05 14:41:08 -08001405 /**
1406 * @hide
1407 */
1408 public int getResizeMode() {
1409 return mResizeMode;
1410 }
1411
1412 /**
1413 * @hide
1414 */
1415 public int getMinWidth() {
1416 return mMinWidth;
1417 }
1418
1419 /**
1420 * @hide
1421 */
1422 public int getMinHeight() {
1423 return mMinHeight;
1424 }
1425
Craig Mautner648f69b2014-09-18 14:16:26 -07001426 /** @hide */
1427 public void saveToXml(XmlSerializer out) throws IOException {
1428 if (mLabel != null) {
1429 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1430 }
1431 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001432 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1433 Integer.toHexString(mColorPrimary));
1434 }
1435 if (mColorBackground != 0) {
1436 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1437 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001438 }
1439 if (mIconFilename != null) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001440 out.attribute(null, ATTR_TASKDESCRIPTIONICON_FILENAME, mIconFilename);
1441 }
1442 if (mIconRes != 0) {
1443 out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE, Integer.toString(mIconRes));
Craig Mautner648f69b2014-09-18 14:16:26 -07001444 }
1445 }
1446
1447 /** @hide */
1448 public void restoreFromXml(String attrName, String attrValue) {
1449 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1450 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001451 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001452 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001453 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1454 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Matthew Ng54bc9422017-10-02 17:16:28 -07001455 } else if (ATTR_TASKDESCRIPTIONICON_FILENAME.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001456 setIconFilename(attrValue);
Matthew Ng54bc9422017-10-02 17:16:28 -07001457 } else if (ATTR_TASKDESCRIPTIONICON_RESOURCE.equals(attrName)) {
1458 setIcon(Integer.parseInt(attrValue, 10));
Craig Mautner648f69b2014-09-18 14:16:26 -07001459 }
1460 }
1461
Winson Chung03a9bae2014-05-02 09:56:12 -07001462 @Override
1463 public int describeContents() {
1464 return 0;
1465 }
1466
1467 @Override
1468 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001469 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001470 dest.writeInt(0);
1471 } else {
1472 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001473 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001474 }
Yunfan Chen4df25f72020-02-05 14:48:26 +09001475 if (mIcon == null || mIcon.isRecycled()) {
Winson Chunga449dc02014-05-16 11:15:04 -07001476 dest.writeInt(0);
1477 } else {
1478 dest.writeInt(1);
1479 mIcon.writeToParcel(dest, 0);
1480 }
Matthew Ng54bc9422017-10-02 17:16:28 -07001481 dest.writeInt(mIconRes);
Winson Chunga449dc02014-05-16 11:15:04 -07001482 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001483 dest.writeInt(mColorBackground);
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001484 dest.writeInt(mStatusBarColor);
1485 dest.writeInt(mNavigationBarColor);
Adrian Roos4c864592019-04-10 14:47:57 +02001486 dest.writeBoolean(mEnsureStatusBarContrastWhenTransparent);
1487 dest.writeBoolean(mEnsureNavigationBarContrastWhenTransparent);
Yunfan Chen674f9692019-11-05 14:41:08 -08001488 dest.writeInt(mResizeMode);
1489 dest.writeInt(mMinWidth);
1490 dest.writeInt(mMinHeight);
Craig Mautner648f69b2014-09-18 14:16:26 -07001491 if (mIconFilename == null) {
1492 dest.writeInt(0);
1493 } else {
1494 dest.writeInt(1);
1495 dest.writeString(mIconFilename);
1496 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001497 }
1498
1499 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001500 mLabel = source.readInt() > 0 ? source.readString() : null;
1501 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
Matthew Ng54bc9422017-10-02 17:16:28 -07001502 mIconRes = source.readInt();
Winson Chunga449dc02014-05-16 11:15:04 -07001503 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001504 mColorBackground = source.readInt();
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001505 mStatusBarColor = source.readInt();
1506 mNavigationBarColor = source.readInt();
Adrian Roos4c864592019-04-10 14:47:57 +02001507 mEnsureStatusBarContrastWhenTransparent = source.readBoolean();
1508 mEnsureNavigationBarContrastWhenTransparent = source.readBoolean();
Yunfan Chen674f9692019-11-05 14:41:08 -08001509 mResizeMode = source.readInt();
1510 mMinWidth = source.readInt();
1511 mMinHeight = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001512 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001513 }
1514
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001515 public static final @android.annotation.NonNull Creator<TaskDescription> CREATOR
Winson Chunga449dc02014-05-16 11:15:04 -07001516 = new Creator<TaskDescription>() {
1517 public TaskDescription createFromParcel(Parcel source) {
1518 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001519 }
Winson Chunga449dc02014-05-16 11:15:04 -07001520 public TaskDescription[] newArray(int size) {
1521 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001522 }
1523 };
1524
1525 @Override
1526 public String toString() {
Yunfan Chen674f9692019-11-05 14:41:08 -08001527 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon
1528 + " IconRes: " + mIconRes + " IconFilename: " + mIconFilename
1529 + " colorPrimary: " + mColorPrimary + " colorBackground: " + mColorBackground
1530 + " statusBarColor: " + mStatusBarColor
1531 + (mEnsureStatusBarContrastWhenTransparent ? " (contrast when transparent)"
1532 : "") + " navigationBarColor: " + mNavigationBarColor
1533 + (mEnsureNavigationBarContrastWhenTransparent
1534 ? " (contrast when transparent)" : "")
1535 + " resizeMode: " + ActivityInfo.resizeModeToString(mResizeMode)
1536 + " minWidth: " + mMinWidth + " minHeight: " + mMinHeight;
Winson Chung03a9bae2014-05-02 09:56:12 -07001537 }
1538 }
1539
1540 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 * Information you can retrieve about tasks that the user has most recently
1542 * started or visited.
1543 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001544 public static class RecentTaskInfo extends TaskInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545 /**
1546 * If this task is currently running, this is the identifier for it.
1547 * If it is not running, this will be -1.
Winson Chungabfdcce2018-07-02 17:23:33 -07001548 *
1549 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, use
1550 * {@link RecentTaskInfo#taskId} to get the task id and {@link RecentTaskInfo#isRunning}
1551 * to determine if it is running.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001553 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001554 public int id;
1555
1556 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001557 * The true identifier of this task, valid even if it is not running.
Winson Chungabfdcce2018-07-02 17:23:33 -07001558 *
1559 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, use
1560 * {@link RecentTaskInfo#taskId}.
Dianne Hackbornd94df452011-02-16 18:53:31 -08001561 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001562 @Deprecated
Dianne Hackbornd94df452011-02-16 18:53:31 -08001563 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001564
Dianne Hackbornd94df452011-02-16 18:53:31 -08001565 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001566 * Description of the task's last state.
Winson Chungabfdcce2018-07-02 17:23:33 -07001567 *
1568 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always null.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001569 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001570 @Deprecated
Dianne Hackbornd2835932010-12-13 16:28:46 -08001571 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001572
1573 /**
Craig Mautnera228ae92014-07-09 05:44:55 -07001574 * Task affiliation for grouping with other tasks.
Winson Chungabfdcce2018-07-02 17:23:33 -07001575 *
1576 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always 0.
Craig Mautnera228ae92014-07-09 05:44:55 -07001577 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001578 @Deprecated
Craig Mautnera228ae92014-07-09 05:44:55 -07001579 public int affiliatedTaskId;
1580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 public RecentTaskInfo() {
1582 }
1583
Winson Chungabfdcce2018-07-02 17:23:33 -07001584 private RecentTaskInfo(Parcel source) {
1585 readFromParcel(source);
1586 }
1587
Craig Mautner6d90fed2013-05-22 15:03:10 -07001588 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 public int describeContents() {
1590 return 0;
1591 }
1592
Winson Chungabfdcce2018-07-02 17:23:33 -07001593 public void readFromParcel(Parcel source) {
1594 id = source.readInt();
1595 persistentId = source.readInt();
1596 super.readFromParcel(source);
1597 }
1598
Craig Mautner6d90fed2013-05-22 15:03:10 -07001599 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 public void writeToParcel(Parcel dest, int flags) {
1601 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001602 dest.writeInt(persistentId);
Winson Chungabfdcce2018-07-02 17:23:33 -07001603 super.writeToParcel(dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001605
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001606 public static final @android.annotation.NonNull Creator<RecentTaskInfo> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 = new Creator<RecentTaskInfo>() {
1608 public RecentTaskInfo createFromParcel(Parcel source) {
1609 return new RecentTaskInfo(source);
1610 }
1611 public RecentTaskInfo[] newArray(int size) {
1612 return new RecentTaskInfo[size];
1613 }
1614 };
Winson Chungb4132992018-07-03 15:52:38 -07001615
1616 /**
1617 * @hide
1618 */
1619 public void dump(PrintWriter pw, String indent) {
1620 final String activityType = WindowConfiguration.activityTypeToString(
1621 configuration.windowConfiguration.getActivityType());
1622 final String windowingMode = WindowConfiguration.activityTypeToString(
1623 configuration.windowConfiguration.getActivityType());
1624
1625 pw.println(); pw.print(" ");
1626 pw.print(" id=" + persistentId);
1627 pw.print(" stackId=" + stackId);
1628 pw.print(" userId=" + userId);
1629 pw.print(" hasTask=" + (id != -1));
1630 pw.print(" lastActiveTime=" + lastActiveTime);
1631 pw.println(); pw.print(" ");
1632 pw.print(" baseIntent=" + baseIntent);
1633 pw.println(); pw.print(" ");
1634 pw.print(" isExcluded="
1635 + ((baseIntent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) != 0));
1636 pw.print(" activityType=" + activityType);
1637 pw.print(" windowingMode=" + windowingMode);
1638 pw.print(" supportsSplitScreenMultiWindow=" + supportsSplitScreenMultiWindow);
1639 if (taskDescription != null) {
1640 pw.println(); pw.print(" ");
1641 final ActivityManager.TaskDescription td = taskDescription;
1642 pw.print(" taskDescription {");
1643 pw.print(" colorBackground=#" + Integer.toHexString(td.getBackgroundColor()));
1644 pw.print(" colorPrimary=#" + Integer.toHexString(td.getPrimaryColor()));
1645 pw.print(" iconRes=" + (td.getIconResource() != 0));
1646 pw.print(" iconBitmap=" + (td.getIconFilename() != null
1647 || td.getInMemoryIcon() != null));
Yunfan Chen674f9692019-11-05 14:41:08 -08001648 pw.print(" resizeMode=" + ActivityInfo.resizeModeToString(td.getResizeMode()));
1649 pw.print(" minWidth=" + td.getMinWidth());
1650 pw.print(" minHeight=" + td.getMinHeight());
Winson Chungb4132992018-07-03 15:52:38 -07001651 pw.println(" }");
1652 }
1653 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 }
1655
1656 /**
1657 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1658 * that have set their
1659 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1660 */
1661 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001664 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001665 * recent tasks that currently are not available to the user.
1666 */
1667 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001668
1669 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001670 * <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 -08001671 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001672 *
1673 * <p><b>Note: this method is only intended for debugging and presenting
1674 * task management user interfaces</b>. This should never be used for
1675 * core logic in an application, such as deciding between different
1676 * behaviors based on the information found here. Such uses are
1677 * <em>not</em> supported, and will likely break in the future. For
1678 * example, if multiple applications can be actively running at the
1679 * same time, assumptions made about the meaning of the data here for
1680 * purposes of control flow will be incorrect.</p>
1681 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001682 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001683 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001684 * document-centric recents means
1685 * it can leak personal information to the caller. For backwards compatibility,
1686 * it will still return a small subset of its data: at least the caller's
1687 * own tasks (though see {@link #getAppTasks()} for the correct supported
1688 * way to retrieve that information), and possibly some other tasks
1689 * such as home that are known to not be sensitive.
1690 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 * @param maxNum The maximum number of entries to return in the list. The
1692 * actual number returned may be smaller, depending on how many tasks the
1693 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001694 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001695 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001696 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 * @return Returns a list of RecentTaskInfo records describing each of
1698 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001700 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1702 throws SecurityException {
1703 try {
Winson Chungf067ac72017-10-24 17:32:32 -07001704 if (maxNum < 0) {
1705 throw new IllegalArgumentException("The requested number of tasks should be >= 0");
1706 }
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001707 return getTaskService().getRecentTasks(maxNum, flags, mContext.getUserId()).getList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001709 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 }
1711 }
1712
1713 /**
1714 * Information you can retrieve about a particular task that is currently
1715 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001716 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 * means that the user has gone to it and never closed it, but currently
1718 * the system may have killed its process and is only holding on to its
1719 * last state in order to restart it when the user returns.
1720 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001721 public static class RunningTaskInfo extends TaskInfo implements Parcelable {
1722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001723 /**
1724 * A unique identifier for this task.
Winson Chungabfdcce2018-07-02 17:23:33 -07001725 *
1726 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, use
1727 * {@link RunningTaskInfo#taskId}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001729 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 public int id;
1731
1732 /**
Winson Chungabfdcce2018-07-02 17:23:33 -07001733 * Thumbnail representation of the task's current state.
1734 *
1735 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always null.
Winson5510f6c2015-10-27 12:11:26 -07001736 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001737 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 public Bitmap thumbnail;
1739
1740 /**
1741 * Description of the task's current state.
Winson Chungabfdcce2018-07-02 17:23:33 -07001742 *
1743 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001744 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001745 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001746 public CharSequence description;
1747
1748 /**
Winson Chungabfdcce2018-07-02 17:23:33 -07001749 * Number of activities that are currently running (not stopped and persisted) in this task.
1750 *
1751 * @deprecated As of {@link android.os.Build.VERSION_CODES#Q}, currently always 0.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752 */
Winson Chungabfdcce2018-07-02 17:23:33 -07001753 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 public int numRunning;
1755
1756 public RunningTaskInfo() {
1757 }
1758
Winson Chungabfdcce2018-07-02 17:23:33 -07001759 private RunningTaskInfo(Parcel source) {
1760 readFromParcel(source);
1761 }
1762
1763 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 public int describeContents() {
1765 return 0;
1766 }
1767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001768 public void readFromParcel(Parcel source) {
1769 id = source.readInt();
Winson Chungabfdcce2018-07-02 17:23:33 -07001770 super.readFromParcel(source);
1771 }
1772
1773 @Override
1774 public void writeToParcel(Parcel dest, int flags) {
1775 dest.writeInt(id);
1776 super.writeToParcel(dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001777 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001778
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001779 public static final @android.annotation.NonNull Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 public RunningTaskInfo createFromParcel(Parcel source) {
1781 return new RunningTaskInfo(source);
1782 }
1783 public RunningTaskInfo[] newArray(int size) {
1784 return new RunningTaskInfo[size];
1785 }
1786 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 }
Winson Chung1147c402014-05-14 11:05:00 -07001788
1789 /**
1790 * Get the list of tasks associated with the calling application.
1791 *
1792 * @return The list of tasks associated with the application making this call.
1793 * @throws SecurityException
1794 */
1795 public List<ActivityManager.AppTask> getAppTasks() {
1796 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001797 List<IBinder> appTasks;
Winson Chung1147c402014-05-14 11:05:00 -07001798 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001799 appTasks = getTaskService().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001800 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001801 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001802 }
1803 int numAppTasks = appTasks.size();
1804 for (int i = 0; i < numAppTasks; i++) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001805 tasks.add(new AppTask(IAppTask.Stub.asInterface(appTasks.get(i))));
Winson Chung1147c402014-05-14 11:05:00 -07001806 }
1807 return tasks;
1808 }
1809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 /**
Winson Chung48a10a52014-08-27 14:36:51 -07001811 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001812 * with {@link #addAppTask}.
1813 */
Winson Chung48a10a52014-08-27 14:36:51 -07001814 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001815 synchronized (this) {
1816 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07001817 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001818 }
1819 }
1820
1821 private void ensureAppTaskThumbnailSizeLocked() {
1822 if (mAppTaskThumbnailSize == null) {
1823 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001824 mAppTaskThumbnailSize = getTaskService().getAppTaskThumbnailSize();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001825 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001826 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001827 }
1828 }
1829 }
1830
1831 /**
1832 * Add a new {@link AppTask} for the calling application. This will create a new
1833 * recents entry that is added to the <b>end</b> of all existing recents.
1834 *
1835 * @param activity The activity that is adding the entry. This is used to help determine
1836 * the context that the new recents entry will be in.
1837 * @param intent The Intent that describes the recents entry. This is the same Intent that
1838 * you would have used to launch the activity for it. In generally you will want to set
1839 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
1840 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
1841 * entry will exist without an activity, so it doesn't make sense to not retain it when
1842 * its activity disappears. The given Intent here also must have an explicit ComponentName
1843 * set on it.
1844 * @param description Optional additional description information.
1845 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07001846 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
1847 * recreated in your process, probably in a way you don't like, before the recents entry
1848 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001849 *
1850 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
1851 * most likely cause of failure is that there is no more room for more tasks for your app.
1852 */
1853 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
1854 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
1855 Point size;
1856 synchronized (this) {
1857 ensureAppTaskThumbnailSizeLocked();
1858 size = mAppTaskThumbnailSize;
1859 }
1860 final int tw = thumbnail.getWidth();
1861 final int th = thumbnail.getHeight();
1862 if (tw != size.x || th != size.y) {
1863 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
1864
1865 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
1866 float scale;
1867 float dx = 0, dy = 0;
1868 if (tw * size.x > size.y * th) {
1869 scale = (float) size.x / (float) th;
1870 dx = (size.y - tw * scale) * 0.5f;
1871 } else {
1872 scale = (float) size.y / (float) tw;
1873 dy = (size.x - th * scale) * 0.5f;
1874 }
1875 Matrix matrix = new Matrix();
1876 matrix.setScale(scale, scale);
1877 matrix.postTranslate((int) (dx + 0.5f), 0);
1878
1879 Canvas canvas = new Canvas(bm);
1880 canvas.drawBitmap(thumbnail, matrix, null);
1881 canvas.setBitmap(null);
1882
1883 thumbnail = bm;
1884 }
1885 if (description == null) {
1886 description = new TaskDescription();
1887 }
1888 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001889 return getTaskService().addAppTask(activity.getActivityToken(),
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001890 intent, description, thumbnail);
1891 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001892 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001893 }
1894 }
1895
1896 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 * Return a list of the tasks that are currently running, with
1898 * the most recent being first and older ones after in order. Note that
1899 * "running" does not mean any of the task's code is currently loaded or
1900 * activity -- the task may have been frozen by the system, so that it
1901 * can be restarted in its previous state when next brought to the
1902 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001903 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001904 * <p><b>Note: this method is only intended for debugging and presenting
1905 * task management user interfaces</b>. This should never be used for
1906 * core logic in an application, such as deciding between different
1907 * behaviors based on the information found here. Such uses are
1908 * <em>not</em> supported, and will likely break in the future. For
1909 * example, if multiple applications can be actively running at the
1910 * same time, assumptions made about the meaning of the data here for
1911 * purposes of control flow will be incorrect.</p>
1912 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001913 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001914 * is no longer available to third party
1915 * applications: the introduction of document-centric recents means
1916 * it can leak person information to the caller. For backwards compatibility,
Alan Stokes1e4e74a2017-08-02 11:17:37 +01001917 * it will still return a small subset of its data: at least the caller's
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001918 * own tasks, and possibly some other tasks
1919 * such as home that are known to not be sensitive.
1920 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07001921 * @param maxNum The maximum number of entries to return in the list. The
1922 * actual number returned may be smaller, depending on how many tasks the
1923 * user has started.
1924 *
1925 * @return Returns a list of RunningTaskInfo records describing each of
1926 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001927 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001928 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07001929 public List<RunningTaskInfo> getRunningTasks(int maxNum)
1930 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07001931 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001932 return getTaskService().getTasks(maxNum);
Dianne Hackborn09233282014-04-30 11:33:59 -07001933 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001934 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07001935 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07001936 }
1937
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001938 /**
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001939 * Represents a task snapshot.
1940 * @hide
1941 */
1942 public static class TaskSnapshot implements Parcelable {
Hongwei Wang3b9bdcf2019-07-15 10:23:03 -07001943 // Identifier of this snapshot
1944 private final long mId;
Winson Chung48b25652018-10-22 14:04:30 -07001945 // Top activity in task when snapshot was taken
1946 private final ComponentName mTopActivityComponent;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001947 private final GraphicBuffer mSnapshot;
Vinit Nayakffd9dff2019-11-05 15:20:11 -08001948 /** Indicates whether task was in landscape or portrait */
1949 @Configuration.Orientation
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001950 private final int mOrientation;
Vinit Nayakffd9dff2019-11-05 15:20:11 -08001951 /** See {@link android.view.Surface.Rotation} */
1952 @Surface.Rotation
1953 private int mRotation;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001954 private final Rect mContentInsets;
Winson Chunga4fa8d52018-04-20 15:54:51 -07001955 // Whether this snapshot is a down-sampled version of the full resolution, used mainly for
1956 // low-ram devices
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001957 private final boolean mReducedResolution;
Winson Chunga4fa8d52018-04-20 15:54:51 -07001958 // Whether or not the snapshot is a real snapshot or an app-theme generated snapshot due to
1959 // the task having a secure window or having previews disabled
Winson Chungf3e412e2018-03-08 11:07:40 -08001960 private final boolean mIsRealSnapshot;
Winson Chunga4fa8d52018-04-20 15:54:51 -07001961 private final int mWindowingMode;
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001962 private final float mScale;
Winson Chung173020c2018-05-04 15:36:47 -07001963 private final int mSystemUiVisibility;
1964 private final boolean mIsTranslucent;
Peiyong Lin21e499a2019-04-03 16:37:46 -07001965 // Must be one of the named color spaces, otherwise, always use SRGB color space.
1966 private final ColorSpace mColorSpace;
Peiyong Lin9d427402019-01-23 18:39:06 -08001967
Hongwei Wang3b9bdcf2019-07-15 10:23:03 -07001968 public TaskSnapshot(long id,
1969 @NonNull ComponentName topActivityComponent, GraphicBuffer snapshot,
Vinit Nayakffd9dff2019-11-05 15:20:11 -08001970 @NonNull ColorSpace colorSpace, int orientation, int rotation, Rect contentInsets,
Peiyong Lin21e499a2019-04-03 16:37:46 -07001971 boolean reducedResolution, float scale, boolean isRealSnapshot, int windowingMode,
1972 int systemUiVisibility, boolean isTranslucent) {
Hongwei Wang3b9bdcf2019-07-15 10:23:03 -07001973 mId = id;
Winson Chung48b25652018-10-22 14:04:30 -07001974 mTopActivityComponent = topActivityComponent;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001975 mSnapshot = snapshot;
Peiyong Lin21e499a2019-04-03 16:37:46 -07001976 mColorSpace = colorSpace.getId() < 0
1977 ? ColorSpace.get(ColorSpace.Named.SRGB) : colorSpace;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001978 mOrientation = orientation;
Vinit Nayakffd9dff2019-11-05 15:20:11 -08001979 mRotation = rotation;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001980 mContentInsets = new Rect(contentInsets);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01001981 mReducedResolution = reducedResolution;
1982 mScale = scale;
Winson Chungf3e412e2018-03-08 11:07:40 -08001983 mIsRealSnapshot = isRealSnapshot;
Winson Chunga4fa8d52018-04-20 15:54:51 -07001984 mWindowingMode = windowingMode;
Winson Chung173020c2018-05-04 15:36:47 -07001985 mSystemUiVisibility = systemUiVisibility;
1986 mIsTranslucent = isTranslucent;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001987 }
1988
1989 private TaskSnapshot(Parcel source) {
Hongwei Wang3b9bdcf2019-07-15 10:23:03 -07001990 mId = source.readLong();
Winson Chung48b25652018-10-22 14:04:30 -07001991 mTopActivityComponent = ComponentName.readFromParcel(source);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001992 mSnapshot = source.readParcelable(null /* classLoader */);
Peiyong Lin21e499a2019-04-03 16:37:46 -07001993 int colorSpaceId = source.readInt();
Peiyong Lind088e6b2019-04-16 14:04:43 -07001994 mColorSpace = colorSpaceId >= 0 && colorSpaceId < ColorSpace.Named.values().length
Peiyong Lin21e499a2019-04-03 16:37:46 -07001995 ? ColorSpace.get(ColorSpace.Named.values()[colorSpaceId])
1996 : ColorSpace.get(ColorSpace.Named.SRGB);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001997 mOrientation = source.readInt();
Vinit Nayakffd9dff2019-11-05 15:20:11 -08001998 mRotation = source.readInt();
Jorim Jaggie2c77f92016-12-29 14:57:22 +01001999 mContentInsets = source.readParcelable(null /* classLoader */);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002000 mReducedResolution = source.readBoolean();
2001 mScale = source.readFloat();
Winson Chungf3e412e2018-03-08 11:07:40 -08002002 mIsRealSnapshot = source.readBoolean();
Winson Chunga4fa8d52018-04-20 15:54:51 -07002003 mWindowingMode = source.readInt();
Winson Chung173020c2018-05-04 15:36:47 -07002004 mSystemUiVisibility = source.readInt();
2005 mIsTranslucent = source.readBoolean();
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002006 }
2007
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002008 /**
Hongwei Wang3b9bdcf2019-07-15 10:23:03 -07002009 * @return Identifier of this snapshot.
2010 */
2011 public long getId() {
2012 return mId;
2013 }
2014
2015 /**
Winson Chung48b25652018-10-22 14:04:30 -07002016 * @return The top activity component for the task at the point this snapshot was taken.
2017 */
2018 public ComponentName getTopActivityComponent() {
2019 return mTopActivityComponent;
2020 }
2021
2022 /**
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002023 * @return The graphic buffer representing the screenshot.
2024 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002025 @UnsupportedAppUsage
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002026 public GraphicBuffer getSnapshot() {
2027 return mSnapshot;
2028 }
2029
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002030 /**
Peiyong Lin9d427402019-01-23 18:39:06 -08002031 * @return The color space of graphic buffer representing the screenshot.
2032 */
2033 public ColorSpace getColorSpace() {
2034 return mColorSpace;
2035 }
2036
2037 /**
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002038 * @return The screen orientation the screenshot was taken in.
2039 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002040 @UnsupportedAppUsage
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002041 public int getOrientation() {
2042 return mOrientation;
2043 }
2044
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002045 /**
Vinit Nayakffd9dff2019-11-05 15:20:11 -08002046 * @return The screen rotation the screenshot was taken in.
2047 */
2048 public int getRotation() {
2049 return mRotation;
2050 }
2051
2052 /**
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002053 * @return The system/content insets on the snapshot. These can be clipped off in order to
2054 * remove any areas behind system bars in the snapshot.
2055 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002056 @UnsupportedAppUsage
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002057 public Rect getContentInsets() {
2058 return mContentInsets;
2059 }
2060
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002061 /**
2062 * @return Whether this snapshot is a down-sampled version of the full resolution.
2063 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002064 @UnsupportedAppUsage
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002065 public boolean isReducedResolution() {
2066 return mReducedResolution;
2067 }
2068
2069 /**
Winson Chungf3e412e2018-03-08 11:07:40 -08002070 * @return Whether or not the snapshot is a real snapshot or an app-theme generated snapshot
2071 * due to the task having a secure window or having previews disabled.
2072 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002073 @UnsupportedAppUsage
Winson Chungf3e412e2018-03-08 11:07:40 -08002074 public boolean isRealSnapshot() {
2075 return mIsRealSnapshot;
2076 }
2077
2078 /**
Winson Chung02378b42018-06-04 16:40:09 -07002079 * @return Whether or not the snapshot is of a translucent app window (non-fullscreen or has
2080 * a non-opaque pixel format).
Winson Chung173020c2018-05-04 15:36:47 -07002081 */
2082 public boolean isTranslucent() {
2083 return mIsTranslucent;
2084 }
2085
2086 /**
Winson Chunga4fa8d52018-04-20 15:54:51 -07002087 * @return The windowing mode of the task when this snapshot was taken.
2088 */
2089 public int getWindowingMode() {
2090 return mWindowingMode;
2091 }
2092
2093 /**
Winson Chung173020c2018-05-04 15:36:47 -07002094 * @return The system ui visibility flags for the top most visible fullscreen window at the
2095 * time that the snapshot was taken.
2096 */
2097 public int getSystemUiVisibility() {
2098 return mSystemUiVisibility;
2099 }
2100
2101 /**
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002102 * @return The scale this snapshot was taken in.
2103 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002104 @UnsupportedAppUsage
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002105 public float getScale() {
2106 return mScale;
2107 }
2108
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002109 @Override
2110 public int describeContents() {
2111 return 0;
2112 }
2113
2114 @Override
2115 public void writeToParcel(Parcel dest, int flags) {
Hongwei Wang3b9bdcf2019-07-15 10:23:03 -07002116 dest.writeLong(mId);
Winson Chung48b25652018-10-22 14:04:30 -07002117 ComponentName.writeToParcel(mTopActivityComponent, dest);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002118 dest.writeParcelable(mSnapshot, 0);
Peiyong Lin21e499a2019-04-03 16:37:46 -07002119 dest.writeInt(mColorSpace.getId());
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002120 dest.writeInt(mOrientation);
Vinit Nayakffd9dff2019-11-05 15:20:11 -08002121 dest.writeInt(mRotation);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002122 dest.writeParcelable(mContentInsets, 0);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002123 dest.writeBoolean(mReducedResolution);
2124 dest.writeFloat(mScale);
Winson Chungf3e412e2018-03-08 11:07:40 -08002125 dest.writeBoolean(mIsRealSnapshot);
Winson Chunga4fa8d52018-04-20 15:54:51 -07002126 dest.writeInt(mWindowingMode);
Winson Chung173020c2018-05-04 15:36:47 -07002127 dest.writeInt(mSystemUiVisibility);
2128 dest.writeBoolean(mIsTranslucent);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002129 }
2130
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002131 @Override
2132 public String toString() {
Winson Chunga4fa8d52018-04-20 15:54:51 -07002133 final int width = mSnapshot != null ? mSnapshot.getWidth() : 0;
2134 final int height = mSnapshot != null ? mSnapshot.getHeight() : 0;
Winson Chung48b25652018-10-22 14:04:30 -07002135 return "TaskSnapshot{"
Hongwei Wang3b9bdcf2019-07-15 10:23:03 -07002136 + " mId=" + mId
Winson Chung48b25652018-10-22 14:04:30 -07002137 + " mTopActivityComponent=" + mTopActivityComponent.flattenToShortString()
2138 + " mSnapshot=" + mSnapshot + " (" + width + "x" + height + ")"
Peiyong Lin21e499a2019-04-03 16:37:46 -07002139 + " mColorSpace=" + mColorSpace.toString()
Winson Chunga4fa8d52018-04-20 15:54:51 -07002140 + " mOrientation=" + mOrientation
Vinit Nayakffd9dff2019-11-05 15:20:11 -08002141 + " mRotation=" + mRotation
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002142 + " mContentInsets=" + mContentInsets.toShortString()
Winson Chungf3e412e2018-03-08 11:07:40 -08002143 + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale
Winson Chung173020c2018-05-04 15:36:47 -07002144 + " mIsRealSnapshot=" + mIsRealSnapshot + " mWindowingMode=" + mWindowingMode
2145 + " mSystemUiVisibility=" + mSystemUiVisibility
2146 + " mIsTranslucent=" + mIsTranslucent;
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002147 }
2148
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07002149 public static final @android.annotation.NonNull Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002150 public TaskSnapshot createFromParcel(Parcel source) {
2151 return new TaskSnapshot(source);
2152 }
2153 public TaskSnapshot[] newArray(int size) {
2154 return new TaskSnapshot[size];
2155 }
2156 };
Mark Renouf98ba8e62019-11-18 12:42:16 -05002157
2158 /** Builder for a {@link TaskSnapshot} object */
2159 public static final class Builder {
2160 private long mId;
2161 private ComponentName mTopActivity;
2162 private GraphicBuffer mSnapshot;
2163 private ColorSpace mColorSpace;
2164 private int mOrientation;
Vinit Nayakffd9dff2019-11-05 15:20:11 -08002165 private int mRotation;
Mark Renouf98ba8e62019-11-18 12:42:16 -05002166 private Rect mContentInsets;
2167 private boolean mReducedResolution;
2168 private float mScaleFraction;
2169 private boolean mIsRealSnapshot;
2170 private int mWindowingMode;
2171 private int mSystemUiVisibility;
2172 private boolean mIsTranslucent;
2173 private int mPixelFormat;
2174
2175 public Builder setId(long id) {
2176 mId = id;
2177 return this;
2178 }
2179
2180 public Builder setTopActivityComponent(ComponentName name) {
2181 mTopActivity = name;
2182 return this;
2183 }
2184
2185 public Builder setSnapshot(GraphicBuffer buffer) {
2186 mSnapshot = buffer;
2187 return this;
2188 }
2189
2190 public Builder setColorSpace(ColorSpace colorSpace) {
2191 mColorSpace = colorSpace;
2192 return this;
2193 }
2194
2195 public Builder setOrientation(int orientation) {
2196 mOrientation = orientation;
2197 return this;
2198 }
2199
Vinit Nayakffd9dff2019-11-05 15:20:11 -08002200 public Builder setRotation(int rotation) {
2201 mRotation = rotation;
2202 return this;
2203 }
2204
Mark Renouf98ba8e62019-11-18 12:42:16 -05002205 public Builder setContentInsets(Rect contentInsets) {
2206 mContentInsets = contentInsets;
2207 return this;
2208 }
2209
2210 public Builder setReducedResolution(boolean reducedResolution) {
2211 mReducedResolution = reducedResolution;
2212 return this;
2213 }
2214
2215 public float getScaleFraction() {
2216 return mScaleFraction;
2217 }
2218
2219 public Builder setScaleFraction(float scaleFraction) {
2220 mScaleFraction = scaleFraction;
2221 return this;
2222 }
2223
2224 public Builder setIsRealSnapshot(boolean realSnapshot) {
2225 mIsRealSnapshot = realSnapshot;
2226 return this;
2227 }
2228
2229 public Builder setWindowingMode(int windowingMode) {
2230 mWindowingMode = windowingMode;
2231 return this;
2232 }
2233
2234 public Builder setSystemUiVisibility(int systemUiVisibility) {
2235 mSystemUiVisibility = systemUiVisibility;
2236 return this;
2237 }
2238
2239 public Builder setIsTranslucent(boolean isTranslucent) {
2240 mIsTranslucent = isTranslucent;
2241 return this;
2242 }
2243
2244 public int getPixelFormat() {
2245 return mPixelFormat;
2246 }
2247
2248 public Builder setPixelFormat(int pixelFormat) {
2249 mPixelFormat = pixelFormat;
2250 return this;
2251 }
2252
2253 public TaskSnapshot build() {
2254 return new TaskSnapshot(
2255 mId,
2256 mTopActivity,
2257 mSnapshot,
2258 mColorSpace,
2259 mOrientation,
Vinit Nayakffd9dff2019-11-05 15:20:11 -08002260 mRotation,
Mark Renouf98ba8e62019-11-18 12:42:16 -05002261 mContentInsets,
2262 mReducedResolution,
2263 mScaleFraction,
2264 mIsRealSnapshot,
2265 mWindowingMode,
2266 mSystemUiVisibility,
2267 mIsTranslucent);
2268
2269 }
2270 }
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002271 }
2272
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002273 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002274 @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = {
2275 MOVE_TASK_WITH_HOME,
2276 MOVE_TASK_NO_USER_ACTION,
2277 })
2278 @Retention(RetentionPolicy.SOURCE)
2279 public @interface MoveTaskFlags {}
2280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002282 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
2283 * activity along with the task, so it is positioned immediately behind
2284 * the task.
2285 */
2286 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
2287
2288 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08002289 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
2290 * user-instigated action, so the current activity will not receive a
2291 * hint that the user is leaving.
2292 */
2293 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
2294
2295 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002296 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
2297 * with a null options argument.
2298 *
2299 * @param taskId The identifier of the task to be moved, as found in
2300 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002301 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002302 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002303 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2304 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002305 moveTaskToFront(taskId, flags, null);
2306 }
2307
2308 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002309 * Ask that the task associated with a given task ID be moved to the
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002310 * front of the stack, so it is now visible to the user.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002311 *
2312 * @param taskId The identifier of the task to be moved, as found in
2313 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002314 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002315 * @param options Additional options for the operation, either null or
2316 * as per {@link Context#startActivity(Intent, android.os.Bundle)
2317 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002318 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002319 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2320 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002321 try {
Ricky Waiaca8a772019-04-04 16:01:06 +01002322 ActivityThread thread = ActivityThread.currentActivityThread();
2323 IApplicationThread appThread = thread.getApplicationThread();
2324 String packageName = mContext.getPackageName();
2325 getTaskService().moveTaskToFront(appThread, packageName, taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002326 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002327 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002328 }
2329 }
2330
2331 /**
Andrii Kulian2eb84b22018-12-13 18:18:54 -08002332 * Check if the context is allowed to start an activity on specified display. Some launch
2333 * restrictions may apply to secondary displays that are private, virtual, or owned by the
2334 * system, in which case an activity start may throw a {@link SecurityException}. Call this
2335 * method prior to starting an activity on a secondary display to check if the current context
2336 * has access to it.
2337 *
2338 * @see ActivityOptions#setLaunchDisplayId(int)
2339 * @see android.view.Display.FLAG_PRIVATE
2340 * @see android.view.Display.TYPE_VIRTUAL
2341 *
2342 * @param context Source context, from which an activity will be started.
2343 * @param displayId Target display id.
2344 * @param intent Intent used to launch an activity.
2345 * @return {@code true} if a call to start an activity on the target display is allowed for the
2346 * provided context and no {@link SecurityException} will be thrown, {@code false} otherwise.
2347 */
wilsonshih40285442019-03-08 15:09:53 +08002348 public boolean isActivityStartAllowedOnDisplay(@NonNull Context context, int displayId,
2349 @NonNull Intent intent) {
Andrii Kulian2eb84b22018-12-13 18:18:54 -08002350 try {
2351 return getTaskService().isActivityStartAllowedOnDisplay(displayId, intent,
2352 intent.resolveTypeIfNeeded(context.getContentResolver()), context.getUserId());
2353 } catch (RemoteException e) {
Charles Chencfec9182019-02-12 20:58:12 +08002354 e.rethrowFromSystemServer();
Andrii Kulian2eb84b22018-12-13 18:18:54 -08002355 }
Charles Chencfec9182019-02-12 20:58:12 +08002356 return false;
Andrii Kulian2eb84b22018-12-13 18:18:54 -08002357 }
2358
2359 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 * Information you can retrieve about a particular Service that is
2361 * currently running in the system.
2362 */
2363 public static class RunningServiceInfo implements Parcelable {
2364 /**
2365 * The service component.
2366 */
2367 public ComponentName service;
2368
2369 /**
2370 * If non-zero, this is the process the service is running in.
2371 */
2372 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002375 * The UID that owns this service.
2376 */
2377 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002378
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002379 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 * The name of the process this service runs in.
2381 */
2382 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002384 /**
2385 * Set to true if the service has asked to run as a foreground process.
2386 */
2387 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002390 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002391 * starting or binding to it. This
2392 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 */
2394 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 /**
2397 * Set to true if this service has been explicitly started.
2398 */
2399 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 /**
2402 * Number of clients connected to the service.
2403 */
2404 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 /**
2407 * Number of times the service's process has crashed while the service
2408 * is running.
2409 */
2410 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 /**
2413 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002414 * explicit requests to start it or clients binding to it). This
2415 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 */
2417 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 /**
2420 * If non-zero, this service is not currently running, but scheduled to
2421 * restart at the given time.
2422 */
2423 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002424
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002425 /**
2426 * Bit for {@link #flags}: set if this service has been
2427 * explicitly started.
2428 */
2429 public static final int FLAG_STARTED = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002430
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002431 /**
2432 * Bit for {@link #flags}: set if the service has asked to
2433 * run as a foreground process.
2434 */
2435 public static final int FLAG_FOREGROUND = 1<<1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002436
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002437 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002438 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002439 * core system process.
2440 */
2441 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002442
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002443 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002444 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002445 * persistent process.
2446 */
2447 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002448
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002449 /**
2450 * Running flags.
2451 */
2452 public int flags;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002453
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002454 /**
2455 * For special services that are bound to by system code, this is
2456 * the package that holds the binding.
2457 */
2458 public String clientPackage;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002459
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002460 /**
2461 * For special services that are bound to by system code, this is
2462 * a string resource providing a user-visible label for who the
2463 * client is.
2464 */
2465 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 public RunningServiceInfo() {
2468 }
2469
2470 public int describeContents() {
2471 return 0;
2472 }
2473
2474 public void writeToParcel(Parcel dest, int flags) {
2475 ComponentName.writeToParcel(service, dest);
2476 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002477 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 dest.writeString(process);
2479 dest.writeInt(foreground ? 1 : 0);
2480 dest.writeLong(activeSince);
2481 dest.writeInt(started ? 1 : 0);
2482 dest.writeInt(clientCount);
2483 dest.writeInt(crashCount);
2484 dest.writeLong(lastActivityTime);
2485 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002486 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002487 dest.writeString(clientPackage);
2488 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 }
2490
2491 public void readFromParcel(Parcel source) {
2492 service = ComponentName.readFromParcel(source);
2493 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002494 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 process = source.readString();
2496 foreground = source.readInt() != 0;
2497 activeSince = source.readLong();
2498 started = source.readInt() != 0;
2499 clientCount = source.readInt();
2500 crashCount = source.readInt();
2501 lastActivityTime = source.readLong();
2502 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002503 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002504 clientPackage = source.readString();
2505 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002507
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07002508 public static final @android.annotation.NonNull Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 public RunningServiceInfo createFromParcel(Parcel source) {
2510 return new RunningServiceInfo(source);
2511 }
2512 public RunningServiceInfo[] newArray(int size) {
2513 return new RunningServiceInfo[size];
2514 }
2515 };
2516
2517 private RunningServiceInfo(Parcel source) {
2518 readFromParcel(source);
2519 }
2520 }
2521
2522 /**
2523 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002524 *
2525 * <p><b>Note: this method is only intended for debugging or implementing
2526 * service management type user interfaces.</b></p>
2527 *
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002528 * @deprecated As of {@link android.os.Build.VERSION_CODES#O}, this method
2529 * is no longer available to third party applications. For backwards compatibility,
2530 * it will still return the caller's own services.
2531 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 * @param maxNum The maximum number of entries to return in the list. The
2533 * actual number returned may be smaller, depending on how many services
2534 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002535 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 * @return Returns a list of RunningServiceInfo records describing each of
2537 * the running tasks.
2538 */
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002539 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 public List<RunningServiceInfo> getRunningServices(int maxNum)
2541 throws SecurityException {
2542 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002543 return getService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 .getServices(maxNum, 0);
2545 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002546 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 }
2548 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002551 * Returns a PendingIntent you can start to show a control panel for the
2552 * given running service. If the service does not have a control panel,
2553 * null is returned.
2554 */
2555 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2556 throws SecurityException {
2557 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002558 return getService()
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002559 .getRunningServiceControlPanel(service);
2560 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002561 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002562 }
2563 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002564
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002565 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 * Information you can retrieve about the available memory through
2567 * {@link ActivityManager#getMemoryInfo}.
2568 */
2569 public static class MemoryInfo implements Parcelable {
2570 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002571 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 * be considered absolute: due to the nature of the kernel, a significant
2573 * portion of this memory is actually in use and needed for the overall
2574 * system to run well.
2575 */
2576 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002577
2578 /**
2579 * The total memory accessible by the kernel. This is basically the
2580 * RAM size of the device, not including below-kernel fixed allocations
2581 * like DMA buffers, RAM for the baseband CPU, etc.
2582 */
2583 public long totalMem;
2584
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 /**
2586 * The threshold of {@link #availMem} at which we consider memory to be
2587 * low and start killing background services and other non-extraneous
2588 * processes.
2589 */
2590 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592 /**
2593 * Set to true if the system considers itself to currently be in a low
2594 * memory situation.
2595 */
2596 public boolean lowMemory;
2597
Dianne Hackborn7d608422011-08-07 16:24:18 -07002598 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002599 @UnsupportedAppUsage
Dianne Hackborn7d608422011-08-07 16:24:18 -07002600 public long hiddenAppThreshold;
2601 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002602 @UnsupportedAppUsage
Dianne Hackborn7d608422011-08-07 16:24:18 -07002603 public long secondaryServerThreshold;
2604 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002605 @UnsupportedAppUsage
Dianne Hackborn7d608422011-08-07 16:24:18 -07002606 public long visibleAppThreshold;
2607 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002608 @UnsupportedAppUsage
Dianne Hackborn7d608422011-08-07 16:24:18 -07002609 public long foregroundAppThreshold;
2610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 public MemoryInfo() {
2612 }
2613
2614 public int describeContents() {
2615 return 0;
2616 }
2617
2618 public void writeToParcel(Parcel dest, int flags) {
2619 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002620 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 dest.writeLong(threshold);
2622 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002623 dest.writeLong(hiddenAppThreshold);
2624 dest.writeLong(secondaryServerThreshold);
2625 dest.writeLong(visibleAppThreshold);
2626 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 public void readFromParcel(Parcel source) {
2630 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002631 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 threshold = source.readLong();
2633 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002634 hiddenAppThreshold = source.readLong();
2635 secondaryServerThreshold = source.readLong();
2636 visibleAppThreshold = source.readLong();
2637 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002638 }
2639
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07002640 public static final @android.annotation.NonNull Creator<MemoryInfo> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 = new Creator<MemoryInfo>() {
2642 public MemoryInfo createFromParcel(Parcel source) {
2643 return new MemoryInfo(source);
2644 }
2645 public MemoryInfo[] newArray(int size) {
2646 return new MemoryInfo[size];
2647 }
2648 };
2649
2650 private MemoryInfo(Parcel source) {
2651 readFromParcel(source);
2652 }
2653 }
2654
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002655 /**
2656 * Return general information about the memory state of the system. This
2657 * can be used to help decide how to manage your own memory, though note
2658 * that polling is not recommended and
2659 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2660 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2661 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2662 * level of your process as needed, which gives a better hint for how to
2663 * manage its memory.
2664 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002665 public void getMemoryInfo(MemoryInfo outInfo) {
2666 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002667 getService().getMemoryInfo(outInfo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002669 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002670 }
2671 }
Craig Mautner967212c2013-04-13 21:10:58 -07002672
Craig Mautner5ff12102013-05-24 12:50:15 -07002673 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002674 * Information you can retrieve about an ActivityStack in the system.
2675 * @hide
2676 */
2677 public static class StackInfo implements Parcelable {
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002678 @UnsupportedAppUsage
Craig Mautner967212c2013-04-13 21:10:58 -07002679 public int stackId;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002680 @UnsupportedAppUsage
Craig Mautnered6649f2013-12-02 14:08:25 -08002681 public Rect bounds = new Rect();
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002682 @UnsupportedAppUsage
Craig Mautner967212c2013-04-13 21:10:58 -07002683 public int[] taskIds;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002684 @UnsupportedAppUsage
Craig Mautner967212c2013-04-13 21:10:58 -07002685 public String[] taskNames;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002686 @UnsupportedAppUsage
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002687 public Rect[] taskBounds;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002688 @UnsupportedAppUsage
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002689 public int[] taskUserIds;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002690 @UnsupportedAppUsage
Winsond46b7272016-04-20 11:54:27 -07002691 public ComponentName topActivity;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002692 @UnsupportedAppUsage
Craig Mautnered6649f2013-12-02 14:08:25 -08002693 public int displayId;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002694 @UnsupportedAppUsage
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002695 public int userId;
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002696 @UnsupportedAppUsage
Winsond46b7272016-04-20 11:54:27 -07002697 public boolean visible;
Winson529c8e42016-05-17 11:08:40 -07002698 // 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 +01002699 @UnsupportedAppUsage
Winson529c8e42016-05-17 11:08:40 -07002700 public int position;
Evan Rosky282ee672019-11-13 15:50:46 -08002701 public IWindowContainer stackToken;
Wale Ogunwale68278562017-09-23 17:13:55 -07002702 /**
2703 * The full configuration the stack is currently running in.
2704 * @hide
2705 */
Wale Ogunwale89be5762017-10-04 13:27:49 -07002706 final public Configuration configuration = new Configuration();
Craig Mautner967212c2013-04-13 21:10:58 -07002707
Craig Mautner967212c2013-04-13 21:10:58 -07002708 @Override
2709 public int describeContents() {
2710 return 0;
2711 }
2712
2713 @Override
2714 public void writeToParcel(Parcel dest, int flags) {
2715 dest.writeInt(stackId);
2716 dest.writeInt(bounds.left);
2717 dest.writeInt(bounds.top);
2718 dest.writeInt(bounds.right);
2719 dest.writeInt(bounds.bottom);
2720 dest.writeIntArray(taskIds);
2721 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002722 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2723 dest.writeInt(boundsCount);
2724 for (int i = 0; i < boundsCount; i++) {
2725 dest.writeInt(taskBounds[i].left);
2726 dest.writeInt(taskBounds[i].top);
2727 dest.writeInt(taskBounds[i].right);
2728 dest.writeInt(taskBounds[i].bottom);
2729 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002730 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002731 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002732 dest.writeInt(userId);
Winsond46b7272016-04-20 11:54:27 -07002733 dest.writeInt(visible ? 1 : 0);
Winson529c8e42016-05-17 11:08:40 -07002734 dest.writeInt(position);
Evan Rosky282ee672019-11-13 15:50:46 -08002735 dest.writeStrongInterface(stackToken);
Winsond46b7272016-04-20 11:54:27 -07002736 if (topActivity != null) {
2737 dest.writeInt(1);
2738 topActivity.writeToParcel(dest, 0);
2739 } else {
2740 dest.writeInt(0);
2741 }
Wale Ogunwale68278562017-09-23 17:13:55 -07002742 configuration.writeToParcel(dest, flags);
Craig Mautner967212c2013-04-13 21:10:58 -07002743 }
2744
2745 public void readFromParcel(Parcel source) {
2746 stackId = source.readInt();
2747 bounds = new Rect(
2748 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2749 taskIds = source.createIntArray();
2750 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002751 final int boundsCount = source.readInt();
2752 if (boundsCount > 0) {
2753 taskBounds = new Rect[boundsCount];
2754 for (int i = 0; i < boundsCount; i++) {
2755 taskBounds[i] = new Rect();
2756 taskBounds[i].set(
2757 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2758 }
2759 } else {
2760 taskBounds = null;
2761 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002762 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002763 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002764 userId = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002765 visible = source.readInt() > 0;
Winson529c8e42016-05-17 11:08:40 -07002766 position = source.readInt();
Evan Rosky282ee672019-11-13 15:50:46 -08002767 stackToken = IWindowContainer.Stub.asInterface(source.readStrongBinder());
Winsond46b7272016-04-20 11:54:27 -07002768 if (source.readInt() > 0) {
2769 topActivity = ComponentName.readFromParcel(source);
2770 }
Wale Ogunwale68278562017-09-23 17:13:55 -07002771 configuration.readFromParcel(source);
Craig Mautner967212c2013-04-13 21:10:58 -07002772 }
2773
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07002774 public static final @android.annotation.NonNull Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
Craig Mautner967212c2013-04-13 21:10:58 -07002775 @Override
2776 public StackInfo createFromParcel(Parcel source) {
2777 return new StackInfo(source);
2778 }
2779 @Override
2780 public StackInfo[] newArray(int size) {
2781 return new StackInfo[size];
2782 }
2783 };
2784
Craig Mautner5ff12102013-05-24 12:50:15 -07002785 public StackInfo() {
2786 }
2787
Craig Mautner967212c2013-04-13 21:10:58 -07002788 private StackInfo(Parcel source) {
2789 readFromParcel(source);
2790 }
2791
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002792 @UnsupportedAppUsage
Craig Mautner5ff12102013-05-24 12:50:15 -07002793 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002794 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002795 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002796 sb.append(" bounds="); sb.append(bounds.toShortString());
2797 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002798 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002799 sb.append("\n");
Wale Ogunwale68278562017-09-23 17:13:55 -07002800 sb.append(" configuration="); sb.append(configuration);
2801 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002802 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002803 for (int i = 0; i < taskIds.length; ++i) {
2804 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002805 sb.append(": "); sb.append(taskNames[i]);
2806 if (taskBounds != null) {
2807 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2808 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002809 sb.append(" userId=").append(taskUserIds[i]);
Winsond46b7272016-04-20 11:54:27 -07002810 sb.append(" visible=").append(visible);
2811 if (topActivity != null) {
2812 sb.append(" topActivity=").append(topActivity);
2813 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002814 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002815 }
2816 return sb.toString();
2817 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002818
2819 @Override
2820 public String toString() {
2821 return toString("");
2822 }
Craig Mautner967212c2013-04-13 21:10:58 -07002823 }
2824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 /**
2826 * @hide
2827 */
Svet Ganovf935a702017-08-22 12:15:58 -07002828 @RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA,
2829 Manifest.permission.ACCESS_INSTANT_APPS})
Mathew Inwood61e8ae62018-08-14 14:17:44 +01002830 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2832 try {
Christopher Tate1d99c392017-12-07 16:54:04 -08002833 return getService().clearApplicationUserData(packageName, false,
Jeff Sharkeyad357d12018-02-02 13:25:31 -07002834 observer, mContext.getUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002836 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 }
2838 }
Christopher Tatea3664242013-06-26 15:00:18 -07002839
2840 /**
2841 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002842 * the user choosing to clear the app's data from within the device settings UI. It
2843 * erases all dynamic data associated with the app -- its private data and data in its
2844 * private area on external storage -- but does not remove the installed application
Benjamin Franza77e3572017-06-23 12:01:44 +01002845 * itself, nor any OBB files. It also revokes all runtime permissions that the app has acquired,
2846 * clears all notifications and removes all Uri grants related to this application.
Christopher Tatea3664242013-06-26 15:00:18 -07002847 *
2848 * @return {@code true} if the application successfully requested that the application's
2849 * data be erased; {@code false} otherwise.
2850 */
2851 public boolean clearApplicationUserData() {
2852 return clearApplicationUserData(mContext.getPackageName(), null);
2853 }
2854
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002855 /**
2856 * Permits an application to get the persistent URI permissions granted to another.
2857 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002858 * <p>Typically called by Settings or DocumentsUI, requires
2859 * {@code GET_APP_GRANTED_URI_PERMISSIONS}.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002860 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002861 * @param packageName application to look for the granted permissions, or {@code null} to get
2862 * granted permissions for all applications
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002863 * @return list of granted URI permissions
2864 *
2865 * @hide
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002866 * @deprecated use {@link UriGrantsManager#getGrantedUriPermissions(String)} instead.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002867 */
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002868 @Deprecated
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002869 public ParceledListSlice<GrantedUriPermission> getGrantedUriPermissions(
2870 @Nullable String packageName) {
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002871 return ((UriGrantsManager) mContext.getSystemService(Context.URI_GRANTS_SERVICE))
2872 .getGrantedUriPermissions(packageName);
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002873 }
2874
2875 /**
2876 * Permits an application to clear the persistent URI permissions granted to another.
2877 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002878 * <p>Typically called by Settings, requires {@code CLEAR_APP_GRANTED_URI_PERMISSIONS}.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002879 *
2880 * @param packageName application to clear its granted permissions
2881 *
2882 * @hide
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002883 * @deprecated use {@link UriGrantsManager#clearGrantedUriPermissions(String)} instead.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002884 */
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002885 @Deprecated
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002886 public void clearGrantedUriPermissions(String packageName) {
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07002887 ((UriGrantsManager) mContext.getSystemService(Context.URI_GRANTS_SERVICE))
2888 .clearGrantedUriPermissions(packageName);
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002889 }
2890
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 /**
2892 * Information you can retrieve about any processes that are in an error condition.
2893 */
2894 public static class ProcessErrorStateInfo implements Parcelable {
2895 /**
2896 * Condition codes
2897 */
2898 public static final int NO_ERROR = 0;
2899 public static final int CRASHED = 1;
2900 public static final int NOT_RESPONDING = 2;
2901
2902 /**
2903 * The condition that the process is in.
2904 */
2905 public int condition;
2906
2907 /**
2908 * The process name in which the crash or error occurred.
2909 */
2910 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 /**
2913 * The pid of this process; 0 if none
2914 */
2915 public int pid;
2916
2917 /**
2918 * The kernel user-ID that has been assigned to this process;
2919 * currently this is not a unique ID (multiple applications can have
2920 * the same uid).
2921 */
2922 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 /**
Dan Egnor60d87622009-12-16 16:32:58 -08002925 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 */
2927 public String tag;
2928
2929 /**
2930 * A short message describing the error condition.
2931 */
2932 public String shortMsg;
2933
2934 /**
2935 * A long message describing the error condition.
2936 */
2937 public String longMsg;
2938
2939 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08002940 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 */
Dan Egnorb7f03672009-12-09 16:22:32 -08002942 public String stackTrace;
2943
2944 /**
2945 * to be deprecated: This value will always be null.
2946 */
2947 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948
2949 public ProcessErrorStateInfo() {
2950 }
2951
Craig Mautner5ff12102013-05-24 12:50:15 -07002952 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002953 public int describeContents() {
2954 return 0;
2955 }
2956
Craig Mautner5ff12102013-05-24 12:50:15 -07002957 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 public void writeToParcel(Parcel dest, int flags) {
2959 dest.writeInt(condition);
2960 dest.writeString(processName);
2961 dest.writeInt(pid);
2962 dest.writeInt(uid);
2963 dest.writeString(tag);
2964 dest.writeString(shortMsg);
2965 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08002966 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969 public void readFromParcel(Parcel source) {
2970 condition = source.readInt();
2971 processName = source.readString();
2972 pid = source.readInt();
2973 uid = source.readInt();
2974 tag = source.readString();
2975 shortMsg = source.readString();
2976 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08002977 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002979
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07002980 public static final @android.annotation.NonNull Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 new Creator<ProcessErrorStateInfo>() {
2982 public ProcessErrorStateInfo createFromParcel(Parcel source) {
2983 return new ProcessErrorStateInfo(source);
2984 }
2985 public ProcessErrorStateInfo[] newArray(int size) {
2986 return new ProcessErrorStateInfo[size];
2987 }
2988 };
2989
2990 private ProcessErrorStateInfo(Parcel source) {
2991 readFromParcel(source);
2992 }
2993 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002996 * 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 -08002997 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002998 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
3000 * current error conditions (it will not return an empty list). This list ordering is not
3001 * specified.
3002 */
3003 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
3004 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003005 return getService().getProcessesInErrorState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003007 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003008 }
3009 }
3010
3011 /**
3012 * Information you can retrieve about a running process.
3013 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07003014 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015 /**
3016 * The name of the process that this object is associated with
3017 */
3018 public String processName;
3019
3020 /**
3021 * The pid of this process; 0 if none
3022 */
3023 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003024
Dianne Hackborneb034652009-09-07 00:49:58 -07003025 /**
3026 * The user id of this process.
3027 */
3028 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003029
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003030 /**
3031 * All packages that have been loaded into the process.
3032 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003033 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07003034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07003036 * Constant for {@link #flags}: this is an app that is unable to
3037 * correctly save its state when going to the background,
3038 * so it can not be killed while in the background.
3039 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003040 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07003041 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003042
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003043 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07003044 * Constant for {@link #flags}: this process is associated with a
3045 * persistent system app.
3046 * @hide
3047 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003048 @UnsupportedAppUsage
Dianne Hackborn42499172010-10-15 18:45:07 -07003049 public static final int FLAG_PERSISTENT = 1<<1;
3050
3051 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07003052 * Constant for {@link #flags}: this process is associated with a
3053 * persistent system app.
3054 * @hide
3055 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003056 @UnsupportedAppUsage
Dianne Hackborn0c380492012-08-20 17:23:30 -07003057 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
3058
3059 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003060 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07003061 * {@link #FLAG_CANT_SAVE_STATE}.
3062 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003063 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003064 @UnsupportedAppUsage
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003065 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003066
3067 /**
3068 * Last memory trim level reported to the process: corresponds to
3069 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
3070 * ComponentCallbacks2.onTrimMemory(int)}.
3071 */
3072 public int lastTrimLevel;
3073
Jeff Sharkey910e0812017-04-21 16:29:27 -06003074 /** @hide */
3075 @IntDef(prefix = { "IMPORTANCE_" }, value = {
3076 IMPORTANCE_FOREGROUND,
3077 IMPORTANCE_FOREGROUND_SERVICE,
3078 IMPORTANCE_TOP_SLEEPING,
3079 IMPORTANCE_VISIBLE,
3080 IMPORTANCE_PERCEPTIBLE,
3081 IMPORTANCE_CANT_SAVE_STATE,
3082 IMPORTANCE_SERVICE,
3083 IMPORTANCE_CACHED,
3084 IMPORTANCE_GONE,
3085 })
3086 @Retention(RetentionPolicy.SOURCE)
3087 public @interface Importance {}
3088
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003089 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003090 * Constant for {@link #importance}: This process is running the
3091 * foreground UI; that is, it is the thing currently at the top of the screen
3092 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003093 */
3094 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003096 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003097 * Constant for {@link #importance}: This process is running a foreground
3098 * service, for example to perform music playback even while the user is
3099 * not immediately in the app. This generally indicates that the process
3100 * is doing something the user actively cares about.
3101 */
3102 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
3103
3104 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003105 * @deprecated Pre-{@link android.os.Build.VERSION_CODES#P} version of
3106 * {@link #IMPORTANCE_TOP_SLEEPING}. As of Android
3107 * {@link android.os.Build.VERSION_CODES#P}, this is considered much less
3108 * important since we want to reduce what apps can do when the screen is off.
Dianne Hackborn1e383822015-04-10 14:02:33 -07003109 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003110 @Deprecated
3111 public static final int IMPORTANCE_TOP_SLEEPING_PRE_28 = 150;
Dianne Hackborn1e383822015-04-10 14:02:33 -07003112
3113 /**
3114 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003115 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07003116 * foreground. This may be running a window that is behind the current
3117 * foreground (so paused and with its state saved, not interacting with
3118 * the user, but visible to them to some degree); it may also be running
3119 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07003120 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003121 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003122
Dianne Hackborn860755f2010-06-03 18:47:52 -07003123 /**
Makoto Onukid7e40582017-04-13 14:54:56 -07003124 * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value
3125 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3126 * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed.
3127 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003128 * <p>The system will return this value instead of {@link #IMPORTANCE_PERCEPTIBLE}
3129 * on Android versions below {@link Build.VERSION_CODES#O}.
3130 *
3131 * <p>On Android version {@link Build.VERSION_CODES#O} and later, this value will still be
3132 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3133 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3134 * the correct value {@link #IMPORTANCE_PERCEPTIBLE} will be returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003136 public static final int IMPORTANCE_PERCEPTIBLE_PRE_26 = 130;
Makoto Onukid7e40582017-04-13 14:54:56 -07003137
3138 /**
3139 * Constant for {@link #importance}: This process is not something the user
3140 * is directly aware of, but is otherwise perceptible to them to some degree.
3141 */
3142 public static final int IMPORTANCE_PERCEPTIBLE = 230;
3143
3144 /**
3145 * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had
3146 * this wrong value
3147 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3148 * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed.
3149 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003150 * <p>The system will return this value instead of {@link #IMPORTANCE_CANT_SAVE_STATE}
3151 * on Android versions below {@link Build.VERSION_CODES#O}.
3152 *
3153 * <p>On Android version {@link Build.VERSION_CODES#O} after, this value will still be
3154 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3155 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3156 * the correct value {@link #IMPORTANCE_CANT_SAVE_STATE} will be returned.
3157 *
Makoto Onukid7e40582017-04-13 14:54:56 -07003158 * @hide
3159 */
Artur Satayevf0b7d0b2019-11-04 11:16:45 +00003160 @UnsupportedAppUsage
Sudheer Shankabe85ed62018-08-13 13:10:50 -07003161 @TestApi
Makoto Onukie92f7942017-04-26 14:38:18 -07003162 public static final int IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003163
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003164 /**
Kevin Hufnagle08a4e472020-01-03 20:05:28 +00003165 * Constant for {@link #importance}: This process contains services
Dianne Hackborn1e383822015-04-10 14:02:33 -07003166 * that should remain running. These are background services apps have
3167 * started, not something the user is aware of, so they may be killed by
3168 * the system relatively freely (though it is generally desired that they
3169 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 */
3171 public static final int IMPORTANCE_SERVICE = 300;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003173 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003174 * Constant for {@link #importance}: This process is running the foreground
3175 * UI, but the device is asleep so it is not visible to the user. Though the
3176 * system will try hard to keep its process from being killed, in all other
3177 * ways we consider it a kind of cached process, with the limitations that go
3178 * along with that state: network access, running background services, etc.
3179 */
3180 public static final int IMPORTANCE_TOP_SLEEPING = 325;
3181
3182 /**
Dianne Hackbornf097d422017-12-15 16:32:19 -08003183 * Constant for {@link #importance}: This process is running an
3184 * application that can not save its state, and thus can't be killed
3185 * while in the background. This will be used with apps that have
3186 * {@link android.R.attr#cantSaveState} set on their application tag.
3187 */
3188 public static final int IMPORTANCE_CANT_SAVE_STATE = 350;
3189
3190 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003191 * Constant for {@link #importance}: This process process contains
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003192 * cached code that is expendable, not actively running any app components
3193 * we care about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003195 public static final int IMPORTANCE_CACHED = 400;
3196
3197 /**
3198 * @deprecated Renamed to {@link #IMPORTANCE_CACHED}.
3199 */
3200 public static final int IMPORTANCE_BACKGROUND = IMPORTANCE_CACHED;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003203 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204 * actively running code.
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003205 * @deprecated This value is no longer reported, use {@link #IMPORTANCE_CACHED} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003207 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003209
3210 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003211 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003212 */
3213 public static final int IMPORTANCE_GONE = 1000;
3214
Makoto Onukid7e40582017-04-13 14:54:56 -07003215 /**
3216 * Convert a proc state to the correspondent IMPORTANCE_* constant. If the return value
3217 * will be passed to a client, use {@link #procStateToImportanceForClient}.
3218 * @hide
3219 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003220 @UnsupportedAppUsage
Jeff Sharkey910e0812017-04-21 16:29:27 -06003221 public static @Importance int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003222 if (procState == PROCESS_STATE_NONEXISTENT) {
3223 return IMPORTANCE_GONE;
3224 } else if (procState >= PROCESS_STATE_HOME) {
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003225 return IMPORTANCE_CACHED;
Dianne Hackbornf4ef6eb2017-12-07 13:57:21 -08003226 } else if (procState == PROCESS_STATE_HEAVY_WEIGHT) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003227 return IMPORTANCE_CANT_SAVE_STATE;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003228 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
3229 return IMPORTANCE_TOP_SLEEPING;
Dianne Hackbornf097d422017-12-15 16:32:19 -08003230 } else if (procState >= PROCESS_STATE_SERVICE) {
3231 return IMPORTANCE_SERVICE;
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003232 } else if (procState >= PROCESS_STATE_TRANSIENT_BACKGROUND) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003233 return IMPORTANCE_PERCEPTIBLE;
3234 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
3235 return IMPORTANCE_VISIBLE;
Hui Yu26969322019-08-21 14:56:35 -07003236 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003237 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003238 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003239 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003240 }
3241 }
3242
Makoto Onukid7e40582017-04-13 14:54:56 -07003243 /**
3244 * Convert a proc state to the correspondent IMPORTANCE_* constant for a client represented
3245 * by a given {@link Context}, with converting {@link #IMPORTANCE_PERCEPTIBLE}
3246 * and {@link #IMPORTANCE_CANT_SAVE_STATE} to the corresponding "wrong" value if the
3247 * client's target SDK < {@link VERSION_CODES#O}.
3248 * @hide
3249 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003250 public static @Importance int procStateToImportanceForClient(int procState,
3251 Context clientContext) {
Makoto Onukie92f7942017-04-26 14:38:18 -07003252 return procStateToImportanceForTargetSdk(procState,
3253 clientContext.getApplicationInfo().targetSdkVersion);
3254 }
3255
3256 /**
3257 * See {@link #procStateToImportanceForClient}.
3258 * @hide
3259 */
3260 public static @Importance int procStateToImportanceForTargetSdk(int procState,
3261 int targetSdkVersion) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003262 final int importance = procStateToImportance(procState);
3263
3264 // For pre O apps, convert to the old, wrong values.
Makoto Onukie92f7942017-04-26 14:38:18 -07003265 if (targetSdkVersion < VERSION_CODES.O) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003266 switch (importance) {
3267 case IMPORTANCE_PERCEPTIBLE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003268 return IMPORTANCE_PERCEPTIBLE_PRE_26;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003269 case IMPORTANCE_TOP_SLEEPING:
3270 return IMPORTANCE_TOP_SLEEPING_PRE_28;
Makoto Onukid7e40582017-04-13 14:54:56 -07003271 case IMPORTANCE_CANT_SAVE_STATE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003272 return IMPORTANCE_CANT_SAVE_STATE_PRE_26;
Makoto Onukid7e40582017-04-13 14:54:56 -07003273 }
3274 }
3275 return importance;
3276 }
3277
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003278 /** @hide */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003279 public static int importanceToProcState(@Importance int importance) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003280 if (importance == IMPORTANCE_GONE) {
3281 return PROCESS_STATE_NONEXISTENT;
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003282 } else if (importance >= IMPORTANCE_CACHED) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003283 return PROCESS_STATE_HOME;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003284 } else if (importance >= IMPORTANCE_CANT_SAVE_STATE) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003285 return PROCESS_STATE_HEAVY_WEIGHT;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003286 } else if (importance >= IMPORTANCE_TOP_SLEEPING) {
3287 return PROCESS_STATE_TOP_SLEEPING;
Dianne Hackbornf097d422017-12-15 16:32:19 -08003288 } else if (importance >= IMPORTANCE_SERVICE) {
3289 return PROCESS_STATE_SERVICE;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003290 } else if (importance >= IMPORTANCE_PERCEPTIBLE) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003291 return PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003292 } else if (importance >= IMPORTANCE_VISIBLE) {
3293 return PROCESS_STATE_IMPORTANT_FOREGROUND;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003294 } else if (importance >= IMPORTANCE_TOP_SLEEPING_PRE_28) {
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -08003295 return PROCESS_STATE_IMPORTANT_FOREGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003296 } else if (importance >= IMPORTANCE_FOREGROUND_SERVICE) {
3297 return PROCESS_STATE_FOREGROUND_SERVICE;
Amith Yamasania0a30a12019-01-22 11:38:06 -08003298 // TODO: Asymmetrical mapping for LOCATION service type. Ok?
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003299 } else {
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -08003300 return PROCESS_STATE_TOP;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003301 }
3302 }
3303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 /**
Jeff Sharkey910e0812017-04-21 16:29:27 -06003305 * The relative importance level that the system places on this process.
3306 * These constants are numbered so that "more important" values are
3307 * always smaller than "less important" values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003309 public @Importance int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 /**
3312 * An additional ordering within a particular {@link #importance}
3313 * category, providing finer-grained information about the relative
3314 * utility of processes within a category. This number means nothing
3315 * except that a smaller values are more recently used (and thus
3316 * more important). Currently an LRU value is only maintained for
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003317 * the {@link #IMPORTANCE_CACHED} category, though others may
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 * be maintained in the future.
3319 */
3320 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003321
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003322 /**
3323 * Constant for {@link #importanceReasonCode}: nothing special has
3324 * been specified for the reason for this level.
3325 */
3326 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003327
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003328 /**
3329 * Constant for {@link #importanceReasonCode}: one of the application's
3330 * content providers is being used by another process. The pid of
3331 * the client process is in {@link #importanceReasonPid} and the
3332 * target provider in this process is in
3333 * {@link #importanceReasonComponent}.
3334 */
3335 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003336
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003337 /**
3338 * Constant for {@link #importanceReasonCode}: one of the application's
3339 * content providers is being used by another process. The pid of
3340 * the client process is in {@link #importanceReasonPid} and the
3341 * target provider in this process is in
3342 * {@link #importanceReasonComponent}.
3343 */
3344 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003345
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003346 /**
3347 * The reason for {@link #importance}, if any.
3348 */
3349 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003350
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003351 /**
3352 * For the specified values of {@link #importanceReasonCode}, this
3353 * is the process ID of the other process that is a client of this
3354 * process. This will be 0 if no other process is using this one.
3355 */
3356 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003357
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003358 /**
3359 * For the specified values of {@link #importanceReasonCode}, this
3360 * is the name of the component that is being used in this process.
3361 */
3362 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003363
Dianne Hackborn905577f2011-09-07 18:31:28 -07003364 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003365 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07003366 * of the other pid. @hide
3367 */
3368 public int importanceReasonImportance;
3369
Dianne Hackborn684bf342014-04-29 17:56:57 -07003370 /**
3371 * Current process state, as per PROCESS_STATE_* constants.
3372 * @hide
3373 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003374 @UnsupportedAppUsage
Dianne Hackborn684bf342014-04-29 17:56:57 -07003375 public int processState;
3376
Chris Morin0260f3d2018-07-10 12:42:06 -07003377 /**
3378 * Whether the app is focused in multi-window environment.
3379 * @hide
3380 */
3381 public boolean isFocused;
3382
3383 /**
3384 * Copy of {@link com.android.server.am.ProcessRecord#lastActivityTime} of the process.
3385 * @hide
3386 */
3387 public long lastActivityTime;
3388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 public RunningAppProcessInfo() {
3390 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003391 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07003392 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
Chris Morin0260f3d2018-07-10 12:42:06 -07003393 isFocused = false;
3394 lastActivityTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
3398 processName = pProcessName;
3399 pid = pPid;
3400 pkgList = pArr;
Chris Morin0260f3d2018-07-10 12:42:06 -07003401 isFocused = false;
3402 lastActivityTime = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003403 }
3404
3405 public int describeContents() {
3406 return 0;
3407 }
3408
3409 public void writeToParcel(Parcel dest, int flags) {
3410 dest.writeString(processName);
3411 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07003412 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003414 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003415 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003416 dest.writeInt(importance);
3417 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003418 dest.writeInt(importanceReasonCode);
3419 dest.writeInt(importanceReasonPid);
3420 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003421 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07003422 dest.writeInt(processState);
Chris Morin0260f3d2018-07-10 12:42:06 -07003423 dest.writeInt(isFocused ? 1 : 0);
3424 dest.writeLong(lastActivityTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003425 }
3426
3427 public void readFromParcel(Parcel source) {
3428 processName = source.readString();
3429 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07003430 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003432 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003433 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 importance = source.readInt();
3435 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003436 importanceReasonCode = source.readInt();
3437 importanceReasonPid = source.readInt();
3438 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003439 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07003440 processState = source.readInt();
Chris Morin0260f3d2018-07-10 12:42:06 -07003441 isFocused = source.readInt() != 0;
3442 lastActivityTime = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443 }
3444
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07003445 public static final @android.annotation.NonNull Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 new Creator<RunningAppProcessInfo>() {
3447 public RunningAppProcessInfo createFromParcel(Parcel source) {
3448 return new RunningAppProcessInfo(source);
3449 }
3450 public RunningAppProcessInfo[] newArray(int size) {
3451 return new RunningAppProcessInfo[size];
3452 }
3453 };
3454
3455 private RunningAppProcessInfo(Parcel source) {
3456 readFromParcel(source);
3457 }
3458 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003459
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003461 * Returns a list of application processes installed on external media
3462 * that are running on the device.
3463 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003464 * <p><b>Note: this method is only intended for debugging or building
3465 * a user-facing process management UI.</b></p>
3466 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003467 * @return Returns a list of ApplicationInfo records, or null if none
3468 * This list ordering is not specified.
3469 * @hide
3470 */
3471 public List<ApplicationInfo> getRunningExternalApplications() {
3472 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003473 return getService().getRunningExternalApplications();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003474 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003475 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003476 }
3477 }
3478
3479 /**
Suprabh Shukla4d64c092018-02-21 20:06:14 -08003480 * Query whether the user has enabled background restrictions for this app.
3481 *
3482 * <p> The user may chose to do this, if they see that an app is consuming an unreasonable
3483 * amount of battery while in the background. </p>
3484 *
3485 * <p> If true, any work that the app tries to do will be aggressively restricted while it is in
3486 * the background. At a minimum, jobs and alarms will not execute and foreground services
3487 * cannot be started unless an app activity is in the foreground. </p>
3488 *
3489 * <p><b> Note that these restrictions stay in effect even when the device is charging.</b></p>
3490 *
3491 * @return true if user has enforced background restrictions for this app, false otherwise.
3492 */
3493 public boolean isBackgroundRestricted() {
3494 try {
3495 return getService().isBackgroundRestricted(mContext.getOpPackageName());
3496 } catch (RemoteException e) {
3497 throw e.rethrowFromSystemServer();
3498 }
3499 }
3500
3501 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003502 * Sets the memory trim mode for a process and schedules a memory trim operation.
3503 *
3504 * <p><b>Note: this method is only intended for testing framework.</b></p>
3505 *
3506 * @return Returns true if successful.
3507 * @hide
3508 */
3509 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
3510 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003511 return getService().setProcessMemoryTrimLevel(process, userId,
Stefan Kuhne16045c22015-06-05 07:18:06 -07003512 level);
3513 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003514 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07003515 }
3516 }
3517
3518 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003519 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003520 *
3521 * <p><b>Note: this method is only intended for debugging or building
3522 * a user-facing process management UI.</b></p>
3523 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
3525 * running processes (it will not return an empty list). This list ordering is not
3526 * specified.
3527 */
3528 public List<RunningAppProcessInfo> getRunningAppProcesses() {
3529 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003530 return getService().getRunningAppProcesses();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003531 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003532 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003533 }
3534 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003535
3536 /**
Jing Ji8055a3a2019-12-17 15:55:33 -08003537 * Return a list of {@link ApplicationExitInfo} records containing the reasons for the most
3538 * recent app deaths.
3539 *
3540 * <p class="note"> Note: System stores this historical information in a ring buffer and only
3541 * the most recent records will be returned. </p>
3542 *
3543 * <p class="note"> Note: In the case that this application was bound to an external service
3544 * with flag {@link android.content.Context#BIND_EXTERNAL_SERVICE}, the process of that external
3545 * service will be included in this package's exit info. </p>
3546 *
3547 * @param packageName Optional, a null value means match all packages belonging to the
3548 * caller's UID. If this package belongs to another UID, you must hold
3549 * {@link android.Manifest.permission#DUMP} in order to retrieve it.
3550 * @param pid A process ID that used to belong to this package but died later; a value
3551 * of 0 means to ignore this parameter and return all matching records.
3552 * @param maxNum The maximum number of results to be returned; a value of 0
3553 * means to ignore this parameter and return all matching records
3554 *
3555 * @return a list of {@link ApplicationExitInfo} records matching the criteria, sorted in
3556 * the order from most recent to least recent.
3557 */
3558 @Nullable
3559 public List<ApplicationExitInfo> getHistoricalProcessExitReasons(@Nullable String packageName,
3560 @IntRange(from = 0) int pid, @IntRange(from = 0) int maxNum) {
3561 try {
3562 ParceledListSlice<ApplicationExitInfo> r = getService().getHistoricalProcessExitReasons(
3563 packageName, pid, maxNum, mContext.getUserId());
3564 return r == null ? null : r.getList();
3565 } catch (RemoteException e) {
3566 throw e.rethrowFromSystemServer();
3567 }
3568 }
3569
3570 /*
3571 * @return Whether or not the low memory kill will be reported in
3572 * {@link #getHistoricalProcessExitReasons}.
3573 *
3574 * @see {@link ApplicationExitInfo#REASON_LOW_MEMORY}
3575 */
3576 public static boolean isLowMemoryKillReportSupported() {
3577 return SystemProperties.getBoolean("persist.sys.lmk.reportkills", false);
3578 }
3579
3580 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003581 * Return the importance of a given package name, based on the processes that are
3582 * currently running. The return value is one of the importance constants defined
3583 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3584 * processes that this package has code running inside of. If there are no processes
3585 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07003586 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07003587 */
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003588 @SystemApi @TestApi
Dianne Hackborn9df8f512016-10-24 17:58:30 -07003589 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003590 public @RunningAppProcessInfo.Importance int getPackageImportance(String packageName) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003591 try {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003592 int procState = getService().getPackageProcessState(packageName,
Adam Lesinskic30454c2015-06-24 13:24:35 -07003593 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003594 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn1e383822015-04-10 14:02:33 -07003595 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003596 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07003597 }
3598 }
3599
3600 /**
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003601 * Return the importance of a given uid, based on the processes that are
3602 * currently running. The return value is one of the importance constants defined
3603 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3604 * processes that this uid has running. If there are no processes
3605 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
3606 * @hide
3607 */
3608 @SystemApi @TestApi
3609 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003610 public @RunningAppProcessInfo.Importance int getUidImportance(int uid) {
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003611 try {
3612 int procState = getService().getUidProcessState(uid,
3613 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003614 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003615 } catch (RemoteException e) {
3616 throw e.rethrowFromSystemServer();
3617 }
3618 }
3619
3620 /**
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003621 * Callback to get reports about changes to the importance of a uid. Use with
3622 * {@link #addOnUidImportanceListener}.
3623 * @hide
3624 */
3625 @SystemApi @TestApi
3626 public interface OnUidImportanceListener {
3627 /**
3628 * The importance if a given uid has changed. Will be one of the importance
3629 * values in {@link RunningAppProcessInfo};
3630 * {@link RunningAppProcessInfo#IMPORTANCE_GONE IMPORTANCE_GONE} will be reported
3631 * when the uid is no longer running at all. This callback will happen on a thread
3632 * from a thread pool, not the main UI thread.
3633 * @param uid The uid whose importance has changed.
3634 * @param importance The new importance value as per {@link RunningAppProcessInfo}.
3635 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003636 void onUidImportance(int uid, @RunningAppProcessInfo.Importance int importance);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003637 }
3638
3639 /**
3640 * Start monitoring changes to the imoportance of uids running in the system.
3641 * @param listener The listener callback that will receive change reports.
3642 * @param importanceCutpoint The level of importance in which the caller is interested
3643 * in differences. For example, if {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}
3644 * is used here, you will receive a call each time a uids importance transitions between
3645 * being <= {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE} and
3646 * > {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.
3647 *
3648 * <p>The caller must hold the {@link android.Manifest.permission#PACKAGE_USAGE_STATS}
3649 * permission to use this feature.</p>
3650 *
3651 * @throws IllegalArgumentException If the listener is already registered.
3652 * @throws SecurityException If the caller does not hold
3653 * {@link android.Manifest.permission#PACKAGE_USAGE_STATS}.
3654 * @hide
3655 */
3656 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003657 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003658 public void addOnUidImportanceListener(OnUidImportanceListener listener,
Jeff Sharkey910e0812017-04-21 16:29:27 -06003659 @RunningAppProcessInfo.Importance int importanceCutpoint) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003660 synchronized (this) {
3661 if (mImportanceListeners.containsKey(listener)) {
3662 throw new IllegalArgumentException("Listener already registered: " + listener);
3663 }
3664 // TODO: implement the cut point in the system process to avoid IPCs.
Makoto Onukid7e40582017-04-13 14:54:56 -07003665 UidObserver observer = new UidObserver(listener, mContext);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003666 try {
3667 getService().registerUidObserver(observer,
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003668 UID_OBSERVER_PROCSTATE | UID_OBSERVER_GONE,
3669 RunningAppProcessInfo.importanceToProcState(importanceCutpoint),
3670 mContext.getOpPackageName());
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003671 } catch (RemoteException e) {
3672 throw e.rethrowFromSystemServer();
3673 }
3674 mImportanceListeners.put(listener, observer);
3675 }
3676 }
3677
3678 /**
3679 * Remove an importance listener that was previously registered with
3680 * {@link #addOnUidImportanceListener}.
3681 *
3682 * @throws IllegalArgumentException If the listener is not registered.
3683 * @hide
3684 */
3685 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003686 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003687 public void removeOnUidImportanceListener(OnUidImportanceListener listener) {
3688 synchronized (this) {
3689 UidObserver observer = mImportanceListeners.remove(listener);
3690 if (observer == null) {
3691 throw new IllegalArgumentException("Listener not registered: " + listener);
3692 }
3693 try {
3694 getService().unregisterUidObserver(observer);
3695 } catch (RemoteException e) {
3696 throw e.rethrowFromSystemServer();
3697 }
3698 }
3699 }
3700
3701 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003702 * Return global memory state information for the calling process. This
3703 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
3704 * only fields that will be filled in are
3705 * {@link RunningAppProcessInfo#pid},
3706 * {@link RunningAppProcessInfo#uid},
3707 * {@link RunningAppProcessInfo#lastTrimLevel},
3708 * {@link RunningAppProcessInfo#importance},
3709 * {@link RunningAppProcessInfo#lru}, and
3710 * {@link RunningAppProcessInfo#importanceReasonCode}.
3711 */
3712 static public void getMyMemoryState(RunningAppProcessInfo outState) {
3713 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003714 getService().getMyMemoryState(outState);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003715 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003716 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003717 }
3718 }
3719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003721 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003722 *
3723 * <p><b>Note: this method is only intended for debugging or building
3724 * a user-facing process management UI.</b></p>
3725 *
Dianne Hackborn8c76d912018-08-23 15:20:05 -07003726 * <p>As of {@link android.os.Build.VERSION_CODES#Q Android Q}, for regular apps this method
3727 * will only return information about the memory info for the processes running as the
3728 * caller's uid; no other process memory info is available and will be zero.
3729 * Also of {@link android.os.Build.VERSION_CODES#Q Android Q} the sample rate allowed
3730 * by this API is significantly limited, if called faster the limit you will receive the
3731 * same data as the previous call.</p>
3732 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003733 * @param pids The pids of the processes whose memory usage is to be
3734 * retrieved.
3735 * @return Returns an array of memory information, one for each
3736 * requested pid.
3737 */
3738 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
3739 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003740 return getService().getProcessMemoryInfo(pids);
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003741 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003742 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003743 }
3744 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003745
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003746 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003747 * @deprecated This is now just a wrapper for
3748 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3749 * is no longer available to applications because it allows them to
3750 * break other applications by removing their alarms, stopping their
3751 * services, etc.
3752 */
3753 @Deprecated
3754 public void restartPackage(String packageName) {
3755 killBackgroundProcesses(packageName);
3756 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003757
Dianne Hackborn03abb812010-01-04 18:43:19 -08003758 /**
3759 * Have the system immediately kill all background processes associated
3760 * with the given package. This is the same as the kernel killing those
3761 * processes to reclaim memory; the system will take care of restarting
3762 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003763 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003764 * @param packageName The name of the package whose processes are to
3765 * be killed.
3766 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003767 @RequiresPermission(Manifest.permission.KILL_BACKGROUND_PROCESSES)
Dianne Hackborn03abb812010-01-04 18:43:19 -08003768 public void killBackgroundProcesses(String packageName) {
3769 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003770 getService().killBackgroundProcesses(packageName,
Jeff Sharkeyad357d12018-02-02 13:25:31 -07003771 mContext.getUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003772 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003773 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003774 }
3775 }
Svet Ganov019d2302015-05-04 11:07:38 -07003776
3777 /**
3778 * Kills the specified UID.
3779 * @param uid The UID to kill.
3780 * @param reason The reason for the kill.
3781 *
3782 * @hide
3783 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08003784 @SystemApi
Svet Ganov019d2302015-05-04 11:07:38 -07003785 @RequiresPermission(Manifest.permission.KILL_UID)
3786 public void killUid(int uid, String reason) {
3787 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003788 getService().killUid(UserHandle.getAppId(uid),
Svetoslavaa41add2015-08-06 15:03:55 -07003789 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003790 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003791 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003792 }
3793 }
3794
Dianne Hackborn03abb812010-01-04 18:43:19 -08003795 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003796 * Have the system perform a force stop of everything associated with
3797 * the given application package. All processes that share its uid
3798 * will be killed, all services it has running stopped, all activities
3799 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3800 * broadcast will be sent, so that any of its registered alarms can
3801 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003802 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003804 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003806 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003808 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003809 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003810 * @hide This is not available to third party applications due to
3811 * it allowing them to break other applications by stopping their
3812 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01003814 @UnsupportedAppUsage
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003815 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003816 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003817 getService().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003819 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 }
3821 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003822
3823 /**
3824 * @see #forceStopPackageAsUser(String, int)
3825 * @hide
3826 */
lumark793e0562018-07-09 22:14:33 +08003827 @SystemApi @TestApi
Jeff Schumacherb8cadef2017-01-03 13:52:48 -08003828 @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES)
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003829 public void forceStopPackage(String packageName) {
Jeff Sharkeyad357d12018-02-02 13:25:31 -07003830 forceStopPackageAsUser(packageName, mContext.getUserId());
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003831 }
3832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 /**
Maurice Lam522ecbe2018-12-04 20:21:40 -08003834 * Sets the current locales of the device. Calling app must have the permission
3835 * {@code android.permission.CHANGE_CONFIGURATION} and
3836 * {@code android.permission.WRITE_SETTINGS}.
3837 *
3838 * @hide
3839 */
3840 @SystemApi
3841 public void setDeviceLocales(@NonNull LocaleList locales) {
3842 LocalePicker.updateLocales(locales);
3843 }
3844
3845 /**
3846 * Returns a list of supported locales by this system. It includes all locales that are
3847 * selectable by the user, potentially including locales that the framework does not have
3848 * translated resources for. To get locales that the framework has translated resources for, use
3849 * {@code Resources.getSystem().getAssets().getLocales()} instead.
3850 *
3851 * @hide
3852 */
3853 @SystemApi
3854 public @NonNull Collection<Locale> getSupportedLocales() {
3855 ArrayList<Locale> locales = new ArrayList<>();
3856 for (String localeTag : LocalePicker.getSupportedLocales(mContext)) {
3857 locales.add(Locale.forLanguageTag(localeTag));
3858 }
3859 return locales;
3860 }
3861
3862 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863 * Get the device configuration attributes.
3864 */
3865 public ConfigurationInfo getDeviceConfigurationInfo() {
3866 try {
Yunfan Chen75157d72018-07-27 14:47:21 +09003867 return getTaskService().getDeviceConfigurationInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003869 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003870 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003871 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003872
3873 /**
3874 * Get the preferred density of icons for the launcher. This is used when
3875 * custom drawables are created (e.g., for shortcuts).
3876 *
3877 * @return density in terms of DPI
3878 */
3879 public int getLauncherLargeIconDensity() {
3880 final Resources res = mContext.getResources();
3881 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003882 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003883
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003884 if (sw < 600) {
3885 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003886 return density;
3887 }
3888
3889 switch (density) {
3890 case DisplayMetrics.DENSITY_LOW:
3891 return DisplayMetrics.DENSITY_MEDIUM;
3892 case DisplayMetrics.DENSITY_MEDIUM:
3893 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003894 case DisplayMetrics.DENSITY_TV:
3895 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003896 case DisplayMetrics.DENSITY_HIGH:
3897 return DisplayMetrics.DENSITY_XHIGH;
3898 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003899 return DisplayMetrics.DENSITY_XXHIGH;
3900 case DisplayMetrics.DENSITY_XXHIGH:
3901 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003902 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003903 // The density is some abnormal value. Return some other
3904 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003905 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003906 }
3907 }
3908
3909 /**
3910 * Get the preferred launcher icon size. This is used when custom drawables
3911 * are created (e.g., for shortcuts).
3912 *
3913 * @return dimensions of square icons in terms of pixels
3914 */
3915 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003916 return getLauncherLargeIconSizeInner(mContext);
3917 }
3918
3919 static int getLauncherLargeIconSizeInner(Context context) {
3920 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003921 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003922 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003923
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003924 if (sw < 600) {
3925 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003926 return size;
3927 }
3928
3929 final int density = res.getDisplayMetrics().densityDpi;
3930
3931 switch (density) {
3932 case DisplayMetrics.DENSITY_LOW:
3933 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3934 case DisplayMetrics.DENSITY_MEDIUM:
3935 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003936 case DisplayMetrics.DENSITY_TV:
3937 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003938 case DisplayMetrics.DENSITY_HIGH:
3939 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3940 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003941 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3942 case DisplayMetrics.DENSITY_XXHIGH:
3943 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003944 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003945 // The density is some abnormal value. Return some other
3946 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003947 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003948 }
3949 }
3950
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003951 /**
3952 * Returns "true" if the user interface is currently being messed with
3953 * by a monkey.
3954 */
3955 public static boolean isUserAMonkey() {
3956 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003957 return getService().isUserAMonkey();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003958 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003959 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003960 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003961 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003962
3963 /**
3964 * Returns "true" if device is running in a test harness.
William Hestera96d3d32018-12-19 13:14:51 -08003965 *
3966 * @deprecated this method is false for all user builds. Users looking to check if their device
3967 * is running in a device farm should see {@link #isRunningInUserTestHarness()}.
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003968 */
William Hestera96d3d32018-12-19 13:14:51 -08003969 @Deprecated
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003970 public static boolean isRunningInTestHarness() {
3971 return SystemProperties.getBoolean("ro.test_harness", false);
3972 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003973
3974 /**
William Hestera96d3d32018-12-19 13:14:51 -08003975 * Returns "true" if the device is running in Test Harness Mode.
3976 *
3977 * <p>Test Harness Mode is a feature that allows devices to run without human interaction in a
3978 * device farm/testing harness (such as Firebase Test Lab). You should check this method if you
3979 * want your app to behave differently when running in a test harness to skip setup screens that
3980 * would impede UI testing. e.g. a keyboard application that has a full screen setup page for
3981 * the first time it is launched.
3982 *
3983 * <p>Note that you should <em>not</em> use this to determine whether or not your app is running
3984 * an instrumentation test, as it is not set for a standard device running a test.
3985 */
3986 public static boolean isRunningInUserTestHarness() {
3987 return SystemProperties.getBoolean("persist.sys.test_harness", false);
3988 }
3989
3990 /**
Wale Ogunwale402de822018-03-22 10:03:06 -07003991 * Unsupported compiled sdk warning should always be shown for the intput activity
3992 * even in cases where the system would normally not show the warning. E.g. when running in a
3993 * test harness.
3994 *
3995 * @param activity The component name of the activity to always show the warning for.
3996 *
3997 * @hide
3998 */
3999 @TestApi
4000 public void alwaysShowUnsupportedCompileSdkWarning(ComponentName activity) {
4001 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07004002 getTaskService().alwaysShowUnsupportedCompileSdkWarning(activity);
Wale Ogunwale402de822018-03-22 10:03:06 -07004003 } catch (RemoteException e) {
4004 throw e.rethrowFromSystemServer();
4005 }
4006 }
4007
4008 /**
Peter Visontay8d224ca2011-02-18 16:39:19 +00004009 * Returns the launch count of each installed package.
4010 *
4011 * @hide
4012 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07004013 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00004014 try {
4015 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
4016 ServiceManager.getService("usagestats"));
4017 if (usageStatsService == null) {
4018 return new HashMap<String, Integer>();
4019 }
4020
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004021 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
4022 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00004023 if (allPkgUsageStats == null) {
4024 return new HashMap<String, Integer>();
4025 }
4026
Peter Visontay8d224ca2011-02-18 16:39:19 +00004027 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004028 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
4029 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00004030 }
4031
4032 return launchCounts;
4033 } catch (RemoteException e) {
4034 Log.w(TAG, "Could not query launch counts", e);
4035 return new HashMap<String, Integer>();
4036 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07004037 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004038
Dianne Hackborn5320eb82012-05-18 12:05:04 -07004039 /** @hide */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01004040 @UnsupportedAppUsage
Dianne Hackborn5320eb82012-05-18 12:05:04 -07004041 public static int checkComponentPermission(String permission, int uid,
4042 int owningUid, boolean exported) {
4043 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08004044 final int appId = UserHandle.getAppId(uid);
4045 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07004046 return PackageManager.PERMISSION_GRANTED;
4047 }
4048 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07004049 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07004050 return PackageManager.PERMISSION_DENIED;
4051 }
4052 // If there is a uid that owns whatever is being accessed, it has
4053 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07004054 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07004055 return PackageManager.PERMISSION_GRANTED;
4056 }
4057 // If the target is not exported, then nobody else can get to it.
4058 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07004059 /*
4060 RuntimeException here = new RuntimeException("here");
4061 here.fillInStackTrace();
4062 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
4063 here);
4064 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07004065 return PackageManager.PERMISSION_DENIED;
4066 }
4067 if (permission == null) {
4068 return PackageManager.PERMISSION_GRANTED;
4069 }
Tim Murrayd06c6d292019-05-07 06:53:55 +00004070 try {
4071 return AppGlobals.getPackageManager()
4072 .checkUidPermission(permission, uid);
4073 } catch (RemoteException e) {
4074 throw e.rethrowFromSystemServer();
4075 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07004076 }
4077
Dianne Hackborn7d19e022012-08-07 19:12:33 -07004078 /** @hide */
4079 public static int checkUidPermission(String permission, int uid) {
4080 try {
Tim Murrayd06c6d292019-05-07 06:53:55 +00004081 return AppGlobals.getPackageManager()
4082 .checkUidPermission(permission, uid);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07004083 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004084 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07004085 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07004086 }
4087
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08004088 /**
4089 * @hide
4090 * Helper for dealing with incoming user arguments to system service calls.
4091 * Takes care of checking permissions and converting USER_CURRENT to the
4092 * actual current user.
4093 *
4094 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
4095 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
4096 * @param userId The user id argument supplied by the caller -- this is the user
4097 * they want to run as.
4098 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
4099 * to get a USER_ALL returned and deal with it correctly. If false,
4100 * an exception will be thrown if USER_ALL is supplied.
4101 * @param requireFull If true, the caller must hold
4102 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
4103 * different user than their current process; otherwise they must hold
4104 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
4105 * @param name Optional textual name of the incoming call; only for generating error messages.
4106 * @param callerPackage Optional package name of caller; only for error messages.
4107 *
4108 * @return Returns the user ID that the call should run as. Will always be a concrete
4109 * user number, unless <var>allowAll</var> is true in which case it could also be
4110 * USER_ALL.
4111 */
Dianne Hackborn41203752012-08-31 14:05:51 -07004112 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
4113 boolean allowAll, boolean requireFull, String name, String callerPackage) {
4114 if (UserHandle.getUserId(callingUid) == userId) {
4115 return userId;
4116 }
4117 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004118 return getService().handleIncomingUser(callingPid,
Dianne Hackborn41203752012-08-31 14:05:51 -07004119 callingUid, userId, allowAll, requireFull, name, callerPackage);
4120 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004121 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07004122 }
4123 }
4124
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07004125 /**
4126 * Gets the userId of the current foreground user. Requires system permissions.
4127 * @hide
4128 */
4129 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06004130 @RequiresPermission(anyOf = {
4131 "android.permission.INTERACT_ACROSS_USERS",
4132 "android.permission.INTERACT_ACROSS_USERS_FULL"
4133 })
Dianne Hackborn41203752012-08-31 14:05:51 -07004134 public static int getCurrentUser() {
4135 UserInfo ui;
4136 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004137 ui = getService().getCurrentUser();
Dianne Hackborn41203752012-08-31 14:05:51 -07004138 return ui != null ? ui.id : 0;
4139 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004140 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07004141 }
4142 }
4143
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004144 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07004145 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004146 * @hide
4147 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01004148 @UnsupportedAppUsage
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004149 public boolean switchUser(int userid) {
4150 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004151 return getService().switchUser(userid);
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004152 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004153 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07004154 }
4155 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004156
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08004157 /**
Varun Shah3e75d752018-11-30 18:47:05 -08004158 * Returns whether switching to provided user was successful.
4159 *
4160 * @param user the user to switch to.
Varun Shahe7f6b542019-01-15 17:04:59 -08004161 *
4162 * @throws IllegalArgumentException if the user is null.
Varun Shah3e75d752018-11-30 18:47:05 -08004163 * @hide
4164 */
4165 @SystemApi
Nate Myren3f262712019-05-31 09:36:08 -07004166 @TestApi
Varun Shah3e75d752018-11-30 18:47:05 -08004167 @RequiresPermission(android.Manifest.permission.MANAGE_USERS)
Varun Shahe7f6b542019-01-15 17:04:59 -08004168 public boolean switchUser(@NonNull UserHandle user) {
4169 if (user == null) {
4170 throw new IllegalArgumentException("UserHandle cannot be null.");
4171 }
Varun Shah3e75d752018-11-30 18:47:05 -08004172 return switchUser(user.getIdentifier());
4173 }
4174
4175 /**
Shuo Qianb9c9bfa2020-01-08 17:59:42 -08004176 * Updates mcc mnc configuration and applies changes to the entire system.
4177 *
4178 * @param mcc mcc configuration to update.
4179 * @param mnc mnc configuration to update.
4180 * @throws RemoteException; IllegalArgumentException if mcc or mnc is null;
4181 * @return Returns {@code true} if the configuration was updated successfully;
4182 * {@code false} otherwise.
4183 * @hide
4184 */
4185 @SystemApi
4186 @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION)
4187 public boolean updateMccMncConfiguration(@NonNull String mcc, @NonNull String mnc) {
4188 if (mcc == null || mnc == null) {
4189 throw new IllegalArgumentException("mcc or mnc cannot be null.");
4190 }
4191 try {
4192 return getService().updateMccMncConfiguration(mcc, mnc);
4193 } catch (RemoteException e) {
4194 throw e.rethrowFromSystemServer();
4195 }
4196 }
4197
4198 /**
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08004199 * Logs out current current foreground user by switching to the system user and stopping the
4200 * user being switched from.
4201 * @hide
4202 */
4203 public static void logoutCurrentUser() {
4204 int currentUser = ActivityManager.getCurrentUser();
4205 if (currentUser != UserHandle.USER_SYSTEM) {
4206 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004207 getService().switchUser(UserHandle.USER_SYSTEM);
4208 getService().stopUser(currentUser, /* force= */ false, null);
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08004209 } catch (RemoteException e) {
4210 e.rethrowFromSystemServer();
4211 }
4212 }
4213 }
4214
Jeff Sharkeye17ac152015-11-06 22:40:29 -08004215 /** {@hide} */
4216 public static final int FLAG_OR_STOPPED = 1 << 0;
4217 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07004218 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07004219 /** {@hide} */
4220 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeyce18c812016-04-27 16:00:41 -06004221 /** {@hide} */
4222 public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08004223
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004224 /**
4225 * Return whether the given user is actively running. This means that
4226 * the user is in the "started" state, not "stopped" -- it is currently
4227 * allowed to run code through scheduled alarms, receiving broadcasts,
4228 * etc. A started user may be either the current foreground user or a
4229 * background user; the result here does not distinguish between the two.
Dianne Hackborn5614bf52016-11-07 17:26:41 -08004230 * @param userId the user's id. Zero indicates the default user.
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004231 * @hide
4232 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01004233 @UnsupportedAppUsage
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004234 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004235 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004236 return getService().isUserRunning(userId, 0);
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004237 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004238 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07004239 }
4240 }
4241
4242 /** {@hide} */
Ruben Brunke24b9a62016-02-16 21:38:24 -08004243 public boolean isVrModePackageEnabled(ComponentName component) {
4244 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004245 return getService().isVrModePackageEnabled(component);
Ruben Brunke24b9a62016-02-16 21:38:24 -08004246 } catch (RemoteException e) {
4247 throw e.rethrowFromSystemServer();
4248 }
4249 }
4250
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004251 /**
4252 * Perform a system dump of various state associated with the given application
4253 * package name. This call blocks while the dump is being performed, so should
4254 * not be done on a UI thread. The data will be written to the given file
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004255 * descriptor as text.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07004256 * @param fd The file descriptor that the dump should be written to. The file
4257 * descriptor is <em>not</em> closed by this function; the caller continues to
4258 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004259 * @param packageName The name of the package that is to be dumped.
4260 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004261 @RequiresPermission(Manifest.permission.DUMP)
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004262 public void dumpPackageState(FileDescriptor fd, String packageName) {
4263 dumpPackageStateStatic(fd, packageName);
4264 }
4265
4266 /**
4267 * @hide
4268 */
4269 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
4270 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07004271 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004272 dumpService(pw, fd, "package", new String[] { packageName });
4273 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08004274 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
4275 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004276 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004277 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08004278 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07004279 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004280 pw.println();
Esteban Talavera838ea242017-12-19 11:48:43 +00004281 dumpService(pw, fd, "usagestats", new String[] { packageName });
Dianne Hackborn904a8572013-06-28 18:12:31 -07004282 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07004283 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004284 pw.flush();
4285 }
4286
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004287 /**
4288 * @hide
4289 */
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004290 public static boolean isSystemReady() {
4291 if (!sSystemReady) {
4292 if (ActivityThread.isSystem()) {
4293 sSystemReady =
4294 LocalServices.getService(ActivityManagerInternal.class).isSystemReady();
4295 } else {
4296 // Since this is being called from outside system server, system should be
4297 // ready by now.
4298 sSystemReady = true;
4299 }
4300 }
4301 return sSystemReady;
4302 }
4303
4304 /**
4305 * @hide
4306 */
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004307 public static void broadcastStickyIntent(Intent intent, int userId) {
4308 broadcastStickyIntent(intent, AppOpsManager.OP_NONE, userId);
4309 }
4310
4311 /**
4312 * Convenience for sending a sticky broadcast. For internal use only.
4313 *
4314 * @hide
4315 */
4316 public static void broadcastStickyIntent(Intent intent, int appOp, int userId) {
4317 try {
Philip P. Moltmann9c5226f2020-01-10 08:53:43 -08004318 getService().broadcastIntentWithFeature(
4319 null, null, intent, null, null, Activity.RESULT_OK, null, null,
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004320 null /*permission*/, appOp, null, false, true, userId);
4321 } catch (RemoteException ex) {
4322 }
4323 }
4324
4325 /**
4326 * @hide
4327 */
Wale Ogunwale691af682019-02-11 03:09:10 -08004328 @TestApi
4329 public static void resumeAppSwitches() throws RemoteException {
4330 getService().resumeAppSwitches();
4331 }
4332
4333 /**
4334 * @hide
4335 */
Narayan Kamath695cf722017-12-21 18:32:47 +00004336 public static void noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid,
4337 String sourcePkg, String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004338 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00004339 getService().noteWakeupAlarm((ps != null) ? ps.getTarget() : null, workSource,
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004340 sourceUid, sourcePkg, tag);
4341 } catch (RemoteException ex) {
4342 }
4343 }
4344
4345 /**
4346 * @hide
4347 */
Narayan Kamath695cf722017-12-21 18:32:47 +00004348 public static void noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid,
4349 String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004350 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00004351 getService().noteAlarmStart((ps != null) ? ps.getTarget() : null, workSource,
4352 sourceUid, tag);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004353 } catch (RemoteException ex) {
4354 }
4355 }
4356
Narayan Kamath695cf722017-12-21 18:32:47 +00004357
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004358 /**
4359 * @hide
4360 */
Narayan Kamath695cf722017-12-21 18:32:47 +00004361 public static void noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid,
4362 String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004363 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00004364 getService().noteAlarmFinish((ps != null) ? ps.getTarget() : null, workSource,
4365 sourceUid, tag);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004366 } catch (RemoteException ex) {
4367 }
4368 }
4369
4370 /**
4371 * @hide
4372 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +01004373 @UnsupportedAppUsage
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004374 public static IActivityManager getService() {
4375 return IActivityManagerSingleton.get();
4376 }
4377
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07004378 private static IActivityTaskManager getTaskService() {
4379 return ActivityTaskManager.getService();
4380 }
4381
Mathew Inwood61e8ae62018-08-14 14:17:44 +01004382 @UnsupportedAppUsage
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004383 private static final Singleton<IActivityManager> IActivityManagerSingleton =
4384 new Singleton<IActivityManager>() {
4385 @Override
4386 protected IActivityManager create() {
4387 final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE);
4388 final IActivityManager am = IActivityManager.Stub.asInterface(b);
4389 return am;
4390 }
4391 };
4392
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004393 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
4394 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
4395 IBinder service = ServiceManager.checkService(name);
4396 if (service == null) {
4397 pw.println(" (Service not found)");
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004398 pw.flush();
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004399 return;
4400 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004401 pw.flush();
4402 if (service instanceof Binder) {
4403 // If this is a local object, it doesn't make sense to do an async dump with it,
4404 // just directly dump.
4405 try {
4406 service.dump(fd, args);
4407 } catch (Throwable e) {
4408 pw.println("Failure dumping service:");
4409 e.printStackTrace(pw);
4410 pw.flush();
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004411 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004412 } else {
4413 // Otherwise, it is remote, do the dump asynchronously to avoid blocking.
4414 TransferPipe tp = null;
4415 try {
4416 pw.flush();
4417 tp = new TransferPipe();
4418 tp.setBufferPrefix(" ");
4419 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
4420 tp.go(fd, 10000);
4421 } catch (Throwable e) {
4422 if (tp != null) {
4423 tp.kill();
4424 }
4425 pw.println("Failure dumping service:");
4426 e.printStackTrace(pw);
4427 }
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004428 }
4429 }
Craig Mautneraea74a52014-03-08 14:23:10 -08004430
4431 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004432 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07004433 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004434 * sees the associated process with a larger pss size and, when this happens, automatically
4435 * pull a heap dump from it and allow the user to share the data. Note that this request
4436 * continues running even if the process is killed and restarted. To remove the watch,
4437 * use {@link #clearWatchHeapLimit()}.
4438 *
Kweku Adamsfa825632019-03-04 16:19:19 -08004439 * <p>This API only works if the calling process has been marked as
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07004440 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
4441 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004442 *
4443 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
4444 * handle heap limit reports themselves.</p>
4445 *
4446 * @param pssSize The size in bytes to set the limit at.
4447 */
4448 public void setWatchHeapLimit(long pssSize) {
4449 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004450 getService().setDumpHeapDebugLimit(null, 0, pssSize,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004451 mContext.getPackageName());
4452 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004453 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004454 }
4455 }
4456
4457 /**
4458 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
4459 * If your package has an activity handling this action, it will be launched with the
4460 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
Kweku Adams6d4bd8e2019-06-26 17:05:55 -07004461 * match, the activity must support this action and a MIME type of "*&#47;*".
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004462 */
4463 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
4464
4465 /**
4466 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
4467 */
4468 public void clearWatchHeapLimit() {
4469 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004470 getService().setDumpHeapDebugLimit(null, 0, 0, null);
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004471 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004472 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004473 }
4474 }
4475
4476 /**
Jason Monk386c94f2014-07-14 16:42:24 -04004477 * Return whether currently in lock task mode. When in this mode
4478 * no new tasks can be created or switched to.
4479 *
4480 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00004481 *
4482 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08004483 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004484 @Deprecated
Craig Mautneraea74a52014-03-08 14:23:10 -08004485 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00004486 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
4487 }
4488
4489 /**
4490 * Return the current state of task locking. The three possible outcomes
4491 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
4492 * and {@link #LOCK_TASK_MODE_PINNED}.
4493 *
4494 * @see Activity#startLockTask()
4495 */
4496 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08004497 try {
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07004498 return getTaskService().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08004499 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004500 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004501 }
4502 }
Winson Chung1147c402014-05-14 11:05:00 -07004503
4504 /**
Srinath Sridharane535a582016-06-27 18:13:47 -07004505 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one
4506 * thread can be a VR thread in a process at a time, and that thread may be subject to
4507 * restrictions on the amount of time it can run.
4508 *
Craig Donnerdc4796c2017-03-08 09:51:47 -08004509 * If persistent VR mode is set, whatever thread has been granted aggressive scheduling via this
4510 * method will return to normal operation, and calling this method will do nothing while
4511 * persistent VR mode is enabled.
4512 *
Srinath Sridharane535a582016-06-27 18:13:47 -07004513 * To reset the VR thread for an application, a tid of 0 can be passed.
4514 *
4515 * @see android.os.Process#myTid()
4516 * @param tid tid of the VR thread
4517 */
4518 public static void setVrThread(int tid) {
4519 try {
Wale Ogunwaled0412b32018-05-08 09:25:50 -07004520 getTaskService().setVrThread(tid);
Srinath Sridharane535a582016-06-27 18:13:47 -07004521 } catch (RemoteException e) {
4522 // pass
4523 }
4524 }
4525
4526 /**
Craig Donnerdc4796c2017-03-08 09:51:47 -08004527 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads that persist
Jeff Sharkey910e0812017-04-21 16:29:27 -06004528 * beyond a single process. Only one thread can be a
Craig Donnerdc4796c2017-03-08 09:51:47 -08004529 * persistent VR thread at a time, and that thread may be subject to restrictions on the amount
4530 * of time it can run. Calling this method will disable aggressive scheduling for non-persistent
4531 * VR threads set via {@link #setVrThread}. If persistent VR mode is disabled then the
4532 * persistent VR thread loses its new scheduling priority; this method must be called again to
4533 * set the persistent thread.
4534 *
4535 * To reset the persistent VR thread, a tid of 0 can be passed.
4536 *
4537 * @see android.os.Process#myTid()
4538 * @param tid tid of the VR thread
4539 * @hide
4540 */
rongliu55492662018-03-21 14:34:58 -07004541 @SystemApi
Craig Donnerdc4796c2017-03-08 09:51:47 -08004542 @RequiresPermission(Manifest.permission.RESTRICTED_VR_ACCESS)
4543 public static void setPersistentVrThread(int tid) {
4544 try {
4545 getService().setPersistentVrThread(tid);
4546 } catch (RemoteException e) {
4547 // pass
4548 }
4549 }
4550
4551 /**
lumark793e0562018-07-09 22:14:33 +08004552 * @hide
4553 */
4554 @TestApi
4555 @RequiresPermission(Manifest.permission.CHANGE_CONFIGURATION)
4556 public void scheduleApplicationInfoChanged(List<String> packages, int userId) {
4557 try {
4558 getService().scheduleApplicationInfoChanged(packages, userId);
4559 } catch (RemoteException e) {
4560 throw e.rethrowFromSystemServer();
4561 }
4562 }
4563
4564 /**
Grace Jia15b4c262020-01-07 14:25:24 -08004565 * Return if a given profile is in the foreground.
4566 * @param userHandle UserHandle to check
4567 * @return Returns the boolean result.
4568 * @hide
4569 */
4570 @SystemApi
4571 @RequiresPermission(anyOf = {
4572 android.Manifest.permission.MANAGE_USERS,
4573 android.Manifest.permission.CREATE_USERS
4574 })
4575 public boolean isProfileForeground(@NonNull UserHandle userHandle) {
4576 UserManager userManager = mContext.getSystemService(UserManager.class);
4577 if (userManager != null) {
4578 for (UserInfo userInfo : userManager.getProfiles(getCurrentUser())) {
4579 if (userInfo.id == userHandle.getIdentifier()) {
4580 return true;
4581 }
4582 }
4583 }
4584 return false;
4585 }
4586
4587 /**
Jing Jie423f762019-12-10 15:05:18 -08004588 * Kill the given PIDs, but the killing will be delayed until the device is idle
4589 * and the given process is imperceptible.
4590 *
4591 * <p>You must hold the permission
4592 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
4593 * call this method.
4594 * </p>
4595 *
4596 * @param pids The list of the pids to be killed
4597 * @pram reason The reason of the kill
4598 *
4599 * @hide
4600 */
4601 @SystemApi @TestApi
4602 @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES)
4603 public void killProcessesWhenImperceptible(@NonNull int[] pids, @NonNull String reason) {
4604 try {
4605 getService().killProcessesWhenImperceptible(pids, reason);
4606 } catch (RemoteException e) {
4607 throw e.rethrowFromSystemServer();
4608 }
4609 }
4610
4611 /**
Winson Chung1147c402014-05-14 11:05:00 -07004612 * The AppTask allows you to manage your own application's tasks.
4613 * See {@link android.app.ActivityManager#getAppTasks()}
4614 */
4615 public static class AppTask {
4616 private IAppTask mAppTaskImpl;
4617
4618 /** @hide */
4619 public AppTask(IAppTask task) {
4620 mAppTaskImpl = task;
4621 }
4622
4623 /**
4624 * Finishes all activities in this task and removes it from the recent tasks list.
4625 */
4626 public void finishAndRemoveTask() {
4627 try {
4628 mAppTaskImpl.finishAndRemoveTask();
4629 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004630 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004631 }
4632 }
4633
4634 /**
4635 * Get the RecentTaskInfo associated with this task.
4636 *
4637 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
4638 */
4639 public RecentTaskInfo getTaskInfo() {
4640 try {
4641 return mAppTaskImpl.getTaskInfo();
4642 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004643 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004644 }
4645 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004646
4647 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004648 * Bring this task to the foreground. If it contains activities, they will be
4649 * brought to the foreground with it and their instances re-created if needed.
4650 * If it doesn't contain activities, the root activity of the task will be
4651 * re-launched.
4652 */
4653 public void moveToFront() {
4654 try {
Ricky Waiaca8a772019-04-04 16:01:06 +01004655 ActivityThread thread = ActivityThread.currentActivityThread();
4656 IApplicationThread appThread = thread.getApplicationThread();
4657 String packageName = ActivityThread.currentPackageName();
4658 mAppTaskImpl.moveToFront(appThread, packageName);
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004659 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004660 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004661 }
4662 }
4663
4664 /**
4665 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004666 * is not currently active (that is, its id < 0), then a new activity for the given
4667 * Intent will be launched as the root of the task and the task brought to the
4668 * foreground. Otherwise, if this task is currently active and the Intent does not specify
4669 * an activity to launch in a new task, then a new activity for the given Intent will
4670 * be launched on top of the task and the task brought to the foreground. If this
4671 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
4672 * or would otherwise be launched in to a new task, then the activity not launched but
4673 * this task be brought to the foreground and a new intent delivered to the top
4674 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004675 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004676 * <p>In other words, you generally want to use an Intent here that does not specify
4677 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
4678 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004679 *
4680 * @param intent The Intent describing the new activity to be launched on the task.
4681 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004682 *
4683 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004684 */
4685 public void startActivity(Context context, Intent intent, Bundle options) {
4686 ActivityThread thread = ActivityThread.currentActivityThread();
4687 thread.getInstrumentation().execStartActivityFromAppTask(context,
4688 thread.getApplicationThread(), mAppTaskImpl, intent, options);
4689 }
4690
4691 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004692 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
4693 * Intent of this AppTask.
4694 *
4695 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
4696 * be set; otherwise, it will be cleared.
4697 */
4698 public void setExcludeFromRecents(boolean exclude) {
4699 try {
4700 mAppTaskImpl.setExcludeFromRecents(exclude);
4701 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004702 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004703 }
4704 }
Winson Chung1147c402014-05-14 11:05:00 -07004705 }
Paul Changc4153512019-12-08 21:35:27 +08004706
4707 /**
4708 * Get packages of bugreport-whitelisted apps to handle a bug report.
4709 *
4710 * @return packages of bugreport-whitelisted apps to handle a bug report.
4711 * @hide
4712 */
4713 public List<String> getBugreportWhitelistedPackages() {
4714 try {
4715 return getService().getBugreportWhitelistedPackages();
4716 } catch (RemoteException e) {
4717 throw e.rethrowFromSystemServer();
4718 }
4719 }
Jing Ji83c6bc52019-12-19 11:53:31 -08004720
4721 /**
4722 * Method for the app to tell system that it's wedged and would like to trigger an ANR.
4723 *
4724 * @param reason The description of that what happened
4725 */
4726 public void appNotResponding(@NonNull final String reason) {
4727 try {
4728 getService().appNotResponding(reason);
4729 } catch (RemoteException e) {
4730 throw e.rethrowFromSystemServer();
4731 }
4732 }
Malcolm Chenc99b83b2020-01-10 15:55:30 -08004733
4734 /**
4735 * Register with {@link HomeVisibilityObserver} with ActivityManager.
4736 * @hide
4737 */
4738 @SystemApi
4739 public void registerHomeVisibilityObserver(@NonNull HomeVisibilityObserver observer) {
4740 Preconditions.checkNotNull(observer);
4741 try {
4742 observer.init(mContext, this);
4743 getService().registerProcessObserver(observer.mObserver);
4744 // Notify upon first registration.
4745 observer.onHomeVisibilityChanged(observer.mIsHomeActivityVisible);
4746 } catch (RemoteException e) {
4747 throw e.rethrowFromSystemServer();
4748 }
4749 }
4750
4751 /**
4752 * Unregister with {@link HomeVisibilityObserver} with ActivityManager.
4753 * @hide
4754 */
4755 @SystemApi
4756 public void unregisterHomeVisibilityObserver(@NonNull HomeVisibilityObserver observer) {
4757 Preconditions.checkNotNull(observer);
4758 try {
4759 getService().unregisterProcessObserver(observer.mObserver);
4760 } catch (RemoteException e) {
4761 throw e.rethrowFromSystemServer();
4762 }
4763 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004764}