blob: 4d5ac6f457035f6f29d0611d5a9a3c60992f859d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Svet Ganov019d2302015-05-04 11:07:38 -070019import android.Manifest;
Matthew Ng54bc9422017-10-02 17:16:28 -070020import android.annotation.DrawableRes;
Michal Karpinski3da5c972015-12-11 18:16:30 +000021import android.annotation.IntDef;
Dianne Hackbornaec68bb2014-08-20 15:25:13 -070022import android.annotation.NonNull;
23import android.annotation.Nullable;
Svet Ganov019d2302015-05-04 11:07:38 -070024import android.annotation.RequiresPermission;
Amith Yamasani0e8d7d62014-09-03 13:17:28 -070025import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060026import android.annotation.SystemService;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070027import android.annotation.TestApi;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.content.ComponentName;
29import android.content.Context;
30import android.content.Intent;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070031import android.content.pm.ActivityInfo;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070032import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.pm.ConfigurationInfo;
34import android.content.pm.IPackageDataObserver;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070035import android.content.pm.PackageManager;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080036import android.content.pm.ParceledListSlice;
Dianne Hackborn41203752012-08-31 14:05:51 -070037import android.content.pm.UserInfo;
Wale Ogunwale68278562017-09-23 17:13:55 -070038import android.content.res.Configuration;
Kenny Root5ef44b72011-01-26 17:22:20 -080039import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.graphics.Bitmap;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070041import android.graphics.Canvas;
Winson Chunga449dc02014-05-16 11:15:04 -070042import android.graphics.Color;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070043import android.graphics.GraphicBuffer;
44import android.graphics.Matrix;
45import android.graphics.Point;
Craig Mautner967212c2013-04-13 21:10:58 -070046import android.graphics.Rect;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070047import android.os.BatteryStats;
Dianne Hackbornc81983a2017-10-20 16:16:32 -070048import android.os.Binder;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070049import android.os.Build;
50import android.os.Build.VERSION_CODES;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070051import android.os.Bundle;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070052import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.os.Handler;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070054import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.Parcel;
56import android.os.Parcelable;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070057import android.os.Process;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070058import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000059import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070060import android.os.SystemProperties;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070061import android.os.UserHandle;
Narayan Kamath695cf722017-12-21 18:32:47 +000062import android.os.WorkSource;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.text.TextUtils;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070064import android.util.ArrayMap;
Kenny Root5ef44b72011-01-26 17:22:20 -080065import android.util.DisplayMetrics;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070066import android.util.Singleton;
Winson Chung48a10a52014-08-27 14:36:51 -070067import android.util.Size;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080068
Wale Ogunwalec981ad52017-06-13 11:40:06 -070069import com.android.internal.app.procstats.ProcessStats;
70import com.android.internal.os.RoSystemProperties;
71import com.android.internal.os.TransferPipe;
72import com.android.internal.util.FastPrintWriter;
73import com.android.server.LocalServices;
74
Craig Mautner648f69b2014-09-18 14:16:26 -070075import org.xmlpull.v1.XmlSerializer;
Kenny Root5ef44b72011-01-26 17:22:20 -080076
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070077import java.io.FileDescriptor;
78import java.io.FileOutputStream;
Craig Mautner648f69b2014-09-18 14:16:26 -070079import java.io.IOException;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070080import java.io.PrintWriter;
Michal Karpinski3da5c972015-12-11 18:16:30 +000081import java.lang.annotation.Retention;
82import java.lang.annotation.RetentionPolicy;
Winson Chung1147c402014-05-14 11:05:00 -070083import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084import java.util.List;
85
86/**
Dave Friedman2a3ebad2017-01-04 18:27:26 -080087 * <p>
88 * This class gives information about, and interacts
89 * with, activities, services, and the containing
90 * process.
91 * </p>
92 *
93 * <p>
94 * A number of the methods in this class are for
95 * debugging or informational purposes and they should
96 * not be used to affect any runtime behavior of
97 * your app. These methods are called out as such in
98 * the method level documentation.
99 * </p>
100 *
101 *<p>
102 * Most application developers should not have the need to
103 * use this class, most of whose methods are for specialized
104 * use cases. However, a few methods are more broadly applicable.
105 * For instance, {@link android.app.ActivityManager#isLowRamDevice() isLowRamDevice()}
106 * enables your app to detect whether it is running on a low-memory device,
107 * and behave accordingly.
108 * {@link android.app.ActivityManager#clearApplicationUserData() clearApplicationUserData()}
109 * is for apps with reset-data functionality.
110 * </p>
111 *
112 * <p>
113 * In some special use cases, where an app interacts with
114 * its Task stack, the app may use the
115 * {@link android.app.ActivityManager.AppTask} and
116 * {@link android.app.ActivityManager.RecentTaskInfo} inner
117 * classes. However, in general, the methods in this class should
118 * be used for testing and debugging purposes only.
119 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600121@SystemService(Context.ACTIVITY_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122public class ActivityManager {
123 private static String TAG = "ActivityManager";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124
Dianne Hackborn852975d2014-08-22 17:42:43 -0700125 private static int gMaxRecentTasks = -1;
126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800129 private static volatile boolean sSystemReady = false;
130
Bryce Lee7f936862017-05-09 15:33:18 -0700131
132 private static final int FIRST_START_FATAL_ERROR_CODE = -100;
133 private static final int LAST_START_FATAL_ERROR_CODE = -1;
134 private static final int FIRST_START_SUCCESS_CODE = 0;
135 private static final int LAST_START_SUCCESS_CODE = 99;
136 private static final int FIRST_START_NON_FATAL_ERROR_CODE = 100;
137 private static final int LAST_START_NON_FATAL_ERROR_CODE = 199;
138
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700139 static final class UidObserver extends IUidObserver.Stub {
140 final OnUidImportanceListener mListener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700141 final Context mContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700142
Makoto Onukid7e40582017-04-13 14:54:56 -0700143 UidObserver(OnUidImportanceListener listener, Context clientContext) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700144 mListener = listener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700145 mContext = clientContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700146 }
147
148 @Override
Sudheer Shanka80255802017-03-04 14:48:53 -0800149 public void onUidStateChanged(int uid, int procState, long procStateSeq) {
Makoto Onukid7e40582017-04-13 14:54:56 -0700150 mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportanceForClient(
151 procState, mContext));
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700152 }
153
154 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800155 public void onUidGone(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700156 mListener.onUidImportance(uid, RunningAppProcessInfo.IMPORTANCE_GONE);
157 }
158
159 @Override
160 public void onUidActive(int uid) {
161 }
162
163 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800164 public void onUidIdle(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700165 }
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700166
167 @Override public void onUidCachedChanged(int uid, boolean cached) {
168 }
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700169 }
170
171 final ArrayMap<OnUidImportanceListener, UidObserver> mImportanceListeners = new ArrayMap<>();
172
Felipe Lemedc7af962016-01-22 18:27:03 -0800173 /**
174 * Defines acceptable types of bugreports.
175 * @hide
176 */
Michal Karpinski3da5c972015-12-11 18:16:30 +0000177 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700178 @IntDef(prefix = { "BUGREPORT_OPTION_" }, value = {
Michal Karpinski3da5c972015-12-11 18:16:30 +0000179 BUGREPORT_OPTION_FULL,
180 BUGREPORT_OPTION_INTERACTIVE,
Wei Liu967fc8d2016-07-08 11:44:20 -0700181 BUGREPORT_OPTION_REMOTE,
Felipe Leme9606c3b2017-01-05 14:57:12 -0800182 BUGREPORT_OPTION_WEAR,
mukesh agrawald9e1df52018-01-22 14:07:31 -0800183 BUGREPORT_OPTION_TELEPHONY,
184 BUGREPORT_OPTION_WIFI
Michal Karpinski3da5c972015-12-11 18:16:30 +0000185 })
Michal Karpinski3da5c972015-12-11 18:16:30 +0000186 public @interface BugreportMode {}
187 /**
188 * Takes a bugreport without user interference (and hence causing less
189 * interference to the system), but includes all sections.
190 * @hide
191 */
192 public static final int BUGREPORT_OPTION_FULL = 0;
193 /**
194 * Allows user to monitor progress and enter additional data; might not include all
195 * sections.
196 * @hide
197 */
198 public static final int BUGREPORT_OPTION_INTERACTIVE = 1;
199 /**
200 * Takes a bugreport requested remotely by administrator of the Device Owner app,
201 * not the device's user.
202 * @hide
203 */
204 public static final int BUGREPORT_OPTION_REMOTE = 2;
Wei Liu967fc8d2016-07-08 11:44:20 -0700205 /**
206 * Takes a bugreport on a wearable device.
207 * @hide
208 */
209 public static final int BUGREPORT_OPTION_WEAR = 3;
Michal Karpinski3da5c972015-12-11 18:16:30 +0000210
Dianne Hackborna4972e92012-03-14 10:38:05 -0700211 /**
Felipe Leme9606c3b2017-01-05 14:57:12 -0800212 * Takes a lightweight version of bugreport that only includes a few, urgent sections
213 * used to report telephony bugs.
214 * @hide
215 */
216 public static final int BUGREPORT_OPTION_TELEPHONY = 4;
217
218 /**
mukesh agrawald9e1df52018-01-22 14:07:31 -0800219 * Takes a lightweight bugreport that only includes a few sections related to Wifi.
220 * @hide
221 */
222 public static final int BUGREPORT_OPTION_WIFI = 5;
223
224 /**
Scott Maincc2195b2013-10-16 13:57:46 -0700225 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000226 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
Christopher Tatebd413f62013-09-18 18:31:59 -0700227 * uninstalled in lieu of the declaring one. The package named here must be
Neil Fuller71fbb812015-11-30 09:51:33 +0000228 * signed with the same certificate as the one declaring the {@code <meta-data>}.
Christopher Tatebd413f62013-09-18 18:31:59 -0700229 */
230 public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
231
Bryce Lee7f936862017-05-09 15:33:18 -0700232 // NOTE: Before adding a new start result, please reference the defined ranges to ensure the
233 // result is properly categorized.
234
Christopher Tatebd413f62013-09-18 18:31:59 -0700235 /**
Amith Yamasani42449782016-04-19 11:45:51 -0700236 * Result for IActivityManager.startVoiceActivity: active session is currently hidden.
237 * @hide
238 */
Bryce Lee7f936862017-05-09 15:33:18 -0700239 public static final int START_VOICE_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE;
Amith Yamasani42449782016-04-19 11:45:51 -0700240
241 /**
242 * Result for IActivityManager.startVoiceActivity: active session does not match
243 * the requesting token.
244 * @hide
245 */
Bryce Lee7f936862017-05-09 15:33:18 -0700246 public static final int START_VOICE_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 1;
Amith Yamasani42449782016-04-19 11:45:51 -0700247
248 /**
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700249 * Result for IActivityManager.startActivity: trying to start a background user
250 * activity that shouldn't be displayed for all users.
251 * @hide
252 */
Bryce Lee7f936862017-05-09 15:33:18 -0700253 public static final int START_NOT_CURRENT_USER_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 2;
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700254
255 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700256 * Result for IActivityManager.startActivity: trying to start an activity under voice
257 * control when that activity does not support the VOICE category.
258 * @hide
259 */
Bryce Lee7f936862017-05-09 15:33:18 -0700260 public static final int START_NOT_VOICE_COMPATIBLE = FIRST_START_FATAL_ERROR_CODE + 3;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700261
262 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700263 * Result for IActivityManager.startActivity: an error where the
264 * start had to be canceled.
265 * @hide
266 */
Bryce Lee7f936862017-05-09 15:33:18 -0700267 public static final int START_CANCELED = FIRST_START_FATAL_ERROR_CODE + 4;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700268
269 /**
270 * Result for IActivityManager.startActivity: an error where the
271 * thing being started is not an activity.
272 * @hide
273 */
Bryce Lee7f936862017-05-09 15:33:18 -0700274 public static final int START_NOT_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 5;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700275
276 /**
277 * Result for IActivityManager.startActivity: an error where the
278 * caller does not have permission to start the activity.
279 * @hide
280 */
Bryce Lee7f936862017-05-09 15:33:18 -0700281 public static final int START_PERMISSION_DENIED = FIRST_START_FATAL_ERROR_CODE + 6;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700282
283 /**
284 * Result for IActivityManager.startActivity: an error where the
285 * caller has requested both to forward a result and to receive
286 * a result.
287 * @hide
288 */
Bryce Lee7f936862017-05-09 15:33:18 -0700289 public static final int START_FORWARD_AND_REQUEST_CONFLICT = FIRST_START_FATAL_ERROR_CODE + 7;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700290
291 /**
292 * Result for IActivityManager.startActivity: an error where the
293 * requested class is not found.
294 * @hide
295 */
Bryce Lee7f936862017-05-09 15:33:18 -0700296 public static final int START_CLASS_NOT_FOUND = FIRST_START_FATAL_ERROR_CODE + 8;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700297
298 /**
299 * Result for IActivityManager.startActivity: an error where the
300 * given Intent could not be resolved to an activity.
301 * @hide
302 */
Bryce Lee7f936862017-05-09 15:33:18 -0700303 public static final int START_INTENT_NOT_RESOLVED = FIRST_START_FATAL_ERROR_CODE + 9;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700304
305 /**
Winson Chungfc3ec4c2017-06-01 15:35:48 -0700306 * Result for IActivityManager.startAssistantActivity: active session is currently hidden.
307 * @hide
308 */
309 public static final int START_ASSISTANT_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE + 10;
310
311 /**
312 * Result for IActivityManager.startAssistantActivity: active session does not match
313 * the requesting token.
314 * @hide
315 */
316 public static final int START_ASSISTANT_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 11;
317
318 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700319 * Result for IActivityManaqer.startActivity: the activity was started
320 * successfully as normal.
321 * @hide
322 */
Bryce Lee7f936862017-05-09 15:33:18 -0700323 public static final int START_SUCCESS = FIRST_START_SUCCESS_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700324
325 /**
326 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not
327 * be executed if it is the recipient, and that is indeed the case.
328 * @hide
329 */
Bryce Lee7f936862017-05-09 15:33:18 -0700330 public static final int START_RETURN_INTENT_TO_CALLER = FIRST_START_SUCCESS_CODE + 1;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700331
332 /**
333 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
334 * a task was simply brought to the foreground.
335 * @hide
336 */
Bryce Lee7f936862017-05-09 15:33:18 -0700337 public static final int START_TASK_TO_FRONT = FIRST_START_SUCCESS_CODE + 2;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700338
339 /**
340 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
341 * the given Intent was given to the existing top activity.
342 * @hide
343 */
Bryce Lee7f936862017-05-09 15:33:18 -0700344 public static final int START_DELIVERED_TO_TOP = FIRST_START_SUCCESS_CODE + 3;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700345
346 /**
347 * Result for IActivityManaqer.startActivity: request was canceled because
348 * app switches are temporarily canceled to ensure the user's last request
349 * (such as pressing home) is performed.
350 * @hide
351 */
Bryce Lee7f936862017-05-09 15:33:18 -0700352 public static final int START_SWITCHES_CANCELED = FIRST_START_NON_FATAL_ERROR_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700353
354 /**
Craig Mautneraea74a52014-03-08 14:23:10 -0800355 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started
356 * while in Lock Task Mode.
357 * @hide
358 */
Bryce Lee7f936862017-05-09 15:33:18 -0700359 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION =
360 FIRST_START_NON_FATAL_ERROR_CODE + 1;
Craig Mautneraea74a52014-03-08 14:23:10 -0800361
362 /**
Bryce Leef9d49542017-06-26 16:27:32 -0700363 * Result for IActivityManaqer.startActivity: a new activity start was aborted. Never returned
364 * externally.
365 * @hide
366 */
367 public static final int START_ABORTED = FIRST_START_NON_FATAL_ERROR_CODE + 2;
368
369 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700370 * Flag for IActivityManaqer.startActivity: do special start mode where
371 * a new activity is launched only if it is needed.
372 * @hide
373 */
374 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
375
376 /**
377 * Flag for IActivityManaqer.startActivity: launch the app for
378 * debugging.
379 * @hide
380 */
381 public static final int START_FLAG_DEBUG = 1<<1;
382
383 /**
384 * Flag for IActivityManaqer.startActivity: launch the app for
Man Caocfa78b22015-06-11 20:14:34 -0700385 * allocation tracking.
386 * @hide
387 */
Pablo Ceballosa4d4e822015-10-05 10:27:52 -0700388 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2;
Man Caocfa78b22015-06-11 20:14:34 -0700389
390 /**
Tamas Berghammerdf6cb282016-01-29 12:07:00 +0000391 * Flag for IActivityManaqer.startActivity: launch the app with
392 * native debugging support.
393 * @hide
394 */
395 public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3;
396
397 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700398 * Result for IActivityManaqer.broadcastIntent: success!
399 * @hide
400 */
401 public static final int BROADCAST_SUCCESS = 0;
402
403 /**
404 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast
405 * a sticky intent without appropriate permission.
406 * @hide
407 */
408 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
409
410 /**
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800411 * Result for IActivityManager.broadcastIntent: trying to send a broadcast
412 * to a stopped user. Fail.
413 * @hide
414 */
415 public static final int BROADCAST_FAILED_USER_STOPPED = -2;
416
417 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700418 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
419 * for a sendBroadcast operation.
420 * @hide
421 */
422 public static final int INTENT_SENDER_BROADCAST = 1;
423
424 /**
425 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
426 * for a startActivity operation.
427 * @hide
428 */
429 public static final int INTENT_SENDER_ACTIVITY = 2;
430
431 /**
432 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
433 * for an activity result operation.
434 * @hide
435 */
436 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
437
438 /**
439 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
440 * for a startService operation.
441 * @hide
442 */
443 public static final int INTENT_SENDER_SERVICE = 4;
444
Christopher Tate08992ac2017-03-21 11:37:06 -0700445 /**
446 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
447 * for a startForegroundService operation.
448 * @hide
449 */
450 public static final int INTENT_SENDER_FOREGROUND_SERVICE = 5;
451
Geoffrey Pitsch88f3d4d2017-11-22 13:31:11 -0500452 /**
453 * Extra included on intents that are delegating the call to
454 * ActivityManager#startActivityAsCaller to another app. This token is necessary for that call
455 * to succeed. Type is IBinder.
456 * @hide
457 */
458 public static final String EXTRA_PERMISSION_TOKEN = "android.app.extra.PERMISSION_TOKEN";
459
460 /**
461 * Extra included on intents that contain an EXTRA_INTENT, with options that the contained
462 * intent may want to be started with. Type is Bundle.
463 * TODO: remove once the ChooserActivity moves to systemui
464 * @hide
465 */
466 public static final String EXTRA_OPTIONS = "android.app.extra.OPTIONS";
467
468 /**
469 * Extra included on intents that contain an EXTRA_INTENT, use this boolean value for the
470 * parameter of the same name when starting the contained intent.
471 * TODO: remove once the ChooserActivity moves to systemui
472 * @hide
473 */
474 public static final String EXTRA_IGNORE_TARGET_SECURITY =
475 "android.app.extra.EXTRA_IGNORE_TARGET_SECURITY";
476
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700477 /** @hide User operation call: success! */
478 public static final int USER_OP_SUCCESS = 0;
479
480 /** @hide User operation call: given user id is not known. */
481 public static final int USER_OP_UNKNOWN_USER = -1;
482
483 /** @hide User operation call: given user id is the current user, can't be stopped. */
484 public static final int USER_OP_IS_CURRENT = -2;
485
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700486 /** @hide User operation call: system user can't be stopped. */
487 public static final int USER_OP_ERROR_IS_SYSTEM = -3;
488
489 /** @hide User operation call: one of related users cannot be stopped. */
490 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4;
491
Dianne Hackbornf097d422017-12-15 16:32:19 -0800492 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800493 * @hide
Dianne Hackbornf097d422017-12-15 16:32:19 -0800494 * Process states, describing the kind of state a particular process is in.
495 * When updating these, make sure to also check all related references to the
496 * constant in code, and update these arrays:
497 *
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800498 * @see com.android.internal.app.procstats.ProcessState#PROCESS_STATE_TO_STATE
499 * @see com.android.server.am.ProcessList#sProcStateToProcMem
500 * @see com.android.server.am.ProcessList#sFirstAwakePssTimes
501 * @see com.android.server.am.ProcessList#sSameAwakePssTimes
502 * @see com.android.server.am.ProcessList#sTestFirstPssTimes
503 * @see com.android.server.am.ProcessList#sTestSamePssTimes
Dianne Hackbornf097d422017-12-15 16:32:19 -0800504 */
505
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800506 /** @hide Not a real process state. */
507 public static final int PROCESS_STATE_UNKNOWN = -1;
Ruben Brunka27eef42015-01-28 15:04:16 -0800508
Dianne Hackborna413dc02013-07-12 12:02:55 -0700509 /** @hide Process is a persistent system process. */
510 public static final int PROCESS_STATE_PERSISTENT = 0;
511
512 /** @hide Process is a persistent system process and is doing UI. */
513 public static final int PROCESS_STATE_PERSISTENT_UI = 1;
514
Dianne Hackbornc8230512013-07-13 21:32:12 -0700515 /** @hide Process is hosting the current top activities. Note that this covers
516 * all activities that are visible to the user. */
Dianne Hackborna413dc02013-07-12 12:02:55 -0700517 public static final int PROCESS_STATE_TOP = 2;
518
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700519 /** @hide Process is hosting a foreground service. */
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -0800520 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 3;
521
522 /** @hide Process is hosting a foreground service due to a system binding. */
523 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 4;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700524
Dianne Hackborna413dc02013-07-12 12:02:55 -0700525 /** @hide Process is important to the user, and something they are aware of. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800526 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 5;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700527
528 /** @hide Process is important to the user, but not something they are aware of. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800529 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 6;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700530
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700531 /** @hide Process is in the background transient so we will try to keep running. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800532 public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 7;
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700533
Dianne Hackborna413dc02013-07-12 12:02:55 -0700534 /** @hide Process is in the background running a backup/restore operation. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800535 public static final int PROCESS_STATE_BACKUP = 8;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700536
Dianne Hackbornc8230512013-07-13 21:32:12 -0700537 /** @hide Process is in the background running a service. Unlike oom_adj, this level
538 * is used for both the normal running in background state and the executing
539 * operations state. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800540 public static final int PROCESS_STATE_SERVICE = 9;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700541
Dianne Hackbornc8230512013-07-13 21:32:12 -0700542 /** @hide Process is in the background running a receiver. Note that from the
Kweku Adamse6b00c22017-10-23 16:46:45 -0700543 * perspective of oom_adj, receivers run at a higher foreground level, but for our
Dianne Hackbornc8230512013-07-13 21:32:12 -0700544 * prioritization here that is not necessary and putting them below services means
545 * many fewer changes in some process states as they receive broadcasts. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800546 public static final int PROCESS_STATE_RECEIVER = 10;
547
548 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
549 public static final int PROCESS_STATE_TOP_SLEEPING = 11;
Dianne Hackbornf097d422017-12-15 16:32:19 -0800550
551 /** @hide Process is in the background, but it can't restore its state so we want
552 * to try to avoid killing it. */
553 public static final int PROCESS_STATE_HEAVY_WEIGHT = 12;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700554
Dianne Hackborna413dc02013-07-12 12:02:55 -0700555 /** @hide Process is in the background but hosts the home activity. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700556 public static final int PROCESS_STATE_HOME = 13;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700557
558 /** @hide Process is in the background but hosts the last shown activity. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700559 public static final int PROCESS_STATE_LAST_ACTIVITY = 14;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700560
Dianne Hackbornc8230512013-07-13 21:32:12 -0700561 /** @hide Process is being cached for later use and contains activities. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700562 public static final int PROCESS_STATE_CACHED_ACTIVITY = 15;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700563
564 /** @hide Process is being cached for later use and is a client of another cached
565 * process that contains activities. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700566 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 16;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700567
Dianne Hackborn68a06332017-11-15 17:54:18 -0800568 /** @hide Process is being cached for later use and has an activity that corresponds
569 * to an existing recent task. */
570 public static final int PROCESS_STATE_CACHED_RECENT = 17;
571
Dianne Hackbornc8230512013-07-13 21:32:12 -0700572 /** @hide Process is being cached for later use and is empty. */
Dianne Hackborn68a06332017-11-15 17:54:18 -0800573 public static final int PROCESS_STATE_CACHED_EMPTY = 18;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700574
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800575 /** @hide Process does not exist. */
Dianne Hackborn68a06332017-11-15 17:54:18 -0800576 public static final int PROCESS_STATE_NONEXISTENT = 19;
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800577
Bookatzdb026a22018-01-10 19:01:56 -0800578 // NOTE: If PROCESS_STATEs are added, then new fields must be added
579 // to frameworks/base/core/proto/android/app/enums.proto and the following method must
Kweku Adamse6b00c22017-10-23 16:46:45 -0700580 // be updated to correctly map between them.
Bookatzdb026a22018-01-10 19:01:56 -0800581 // However, if the current ActivityManager values are merely modified, no update should be made
582 // to enums.proto, to which values can only be added but never modified. Note that the proto
583 // versions do NOT have the ordering restrictions of the ActivityManager process state.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700584 /**
Bookatzdb026a22018-01-10 19:01:56 -0800585 * Maps ActivityManager.PROCESS_STATE_ values to enums.proto ProcessStateEnum value.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700586 *
587 * @param amInt a process state of the form ActivityManager.PROCESS_STATE_
Bookatzdb026a22018-01-10 19:01:56 -0800588 * @return the value of the corresponding enums.proto ProcessStateEnum value.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700589 * @hide
590 */
591 public static final int processStateAmToProto(int amInt) {
Bookatzdb026a22018-01-10 19:01:56 -0800592 switch (amInt) {
593 case PROCESS_STATE_UNKNOWN:
594 return AppProtoEnums.PROCESS_STATE_UNKNOWN;
595 case PROCESS_STATE_PERSISTENT:
596 return AppProtoEnums.PROCESS_STATE_PERSISTENT;
597 case PROCESS_STATE_PERSISTENT_UI:
598 return AppProtoEnums.PROCESS_STATE_PERSISTENT_UI;
599 case PROCESS_STATE_TOP:
600 return AppProtoEnums.PROCESS_STATE_TOP;
601 case PROCESS_STATE_FOREGROUND_SERVICE:
602 return AppProtoEnums.PROCESS_STATE_FOREGROUND_SERVICE;
603 case PROCESS_STATE_BOUND_FOREGROUND_SERVICE:
604 return AppProtoEnums.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
605 case PROCESS_STATE_IMPORTANT_FOREGROUND:
606 return AppProtoEnums.PROCESS_STATE_IMPORTANT_FOREGROUND;
607 case PROCESS_STATE_IMPORTANT_BACKGROUND:
608 return AppProtoEnums.PROCESS_STATE_IMPORTANT_BACKGROUND;
609 case PROCESS_STATE_TRANSIENT_BACKGROUND:
610 return AppProtoEnums.PROCESS_STATE_TRANSIENT_BACKGROUND;
611 case PROCESS_STATE_BACKUP:
612 return AppProtoEnums.PROCESS_STATE_BACKUP;
613 case PROCESS_STATE_SERVICE:
614 return AppProtoEnums.PROCESS_STATE_SERVICE;
615 case PROCESS_STATE_RECEIVER:
616 return AppProtoEnums.PROCESS_STATE_RECEIVER;
617 case PROCESS_STATE_TOP_SLEEPING:
618 return AppProtoEnums.PROCESS_STATE_TOP_SLEEPING;
619 case PROCESS_STATE_HEAVY_WEIGHT:
620 return AppProtoEnums.PROCESS_STATE_HEAVY_WEIGHT;
621 case PROCESS_STATE_HOME:
622 return AppProtoEnums.PROCESS_STATE_HOME;
623 case PROCESS_STATE_LAST_ACTIVITY:
624 return AppProtoEnums.PROCESS_STATE_LAST_ACTIVITY;
625 case PROCESS_STATE_CACHED_ACTIVITY:
626 return AppProtoEnums.PROCESS_STATE_CACHED_ACTIVITY;
627 case PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
628 return AppProtoEnums.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
629 case PROCESS_STATE_CACHED_RECENT:
630 return AppProtoEnums.PROCESS_STATE_CACHED_RECENT;
631 case PROCESS_STATE_CACHED_EMPTY:
632 return AppProtoEnums.PROCESS_STATE_CACHED_EMPTY;
633 case PROCESS_STATE_NONEXISTENT:
634 return AppProtoEnums.PROCESS_STATE_NONEXISTENT;
635 default:
636 // ActivityManager process state (amInt)
637 // could not be mapped to an AppProtoEnums ProcessState state.
638 return AppProtoEnums.PROCESS_STATE_UNKNOWN_TO_PROTO;
639 }
Kweku Adamse6b00c22017-10-23 16:46:45 -0700640 }
641
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700642 /** @hide The lowest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800643 public static final int MIN_PROCESS_STATE = PROCESS_STATE_PERSISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700644
645 /** @hide The highest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800646 public static final int MAX_PROCESS_STATE = PROCESS_STATE_NONEXISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700647
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700648 /** @hide Should this process state be considered a background state? */
649 public static final boolean isProcStateBackground(int procState) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700650 return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700651 }
652
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700653 /** @hide requestType for assist context: only basic information. */
654 public static final int ASSIST_CONTEXT_BASIC = 0;
655
656 /** @hide requestType for assist context: generate full AssistStructure. */
657 public static final int ASSIST_CONTEXT_FULL = 1;
658
Felipe Leme640f30a2017-03-06 15:44:06 -0800659 /** @hide requestType for assist context: generate full AssistStructure for autofill. */
660 public static final int ASSIST_CONTEXT_AUTOFILL = 2;
Felipe Leme6d553872016-12-08 17:13:25 -0800661
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700662 /** @hide Flag for registerUidObserver: report changes in process state. */
663 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
664
665 /** @hide Flag for registerUidObserver: report uid gone. */
666 public static final int UID_OBSERVER_GONE = 1<<1;
667
668 /** @hide Flag for registerUidObserver: report uid has become idle. */
669 public static final int UID_OBSERVER_IDLE = 1<<2;
670
671 /** @hide Flag for registerUidObserver: report uid has become active. */
672 public static final int UID_OBSERVER_ACTIVE = 1<<3;
673
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700674 /** @hide Flag for registerUidObserver: report uid cached state has changed. */
675 public static final int UID_OBSERVER_CACHED = 1<<4;
676
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800677 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700678 public static final int APP_START_MODE_NORMAL = 0;
679
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800680 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700681 public static final int APP_START_MODE_DELAYED = 1;
682
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800683 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later, with
Dianne Hackborn85e35642017-01-12 15:10:57 -0800684 * rigid errors (throwing exception). */
685 public static final int APP_START_MODE_DELAYED_RIGID = 2;
686
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800687 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: disable/cancel pending
Dianne Hackborn85e35642017-01-12 15:10:57 -0800688 * launches; this is the mode for ephemeral apps. */
689 public static final int APP_START_MODE_DISABLED = 3;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700690
Benjamin Franz43261142015-02-11 15:59:44 +0000691 /**
692 * Lock task mode is not active.
693 */
694 public static final int LOCK_TASK_MODE_NONE = 0;
695
696 /**
697 * Full lock task mode is active.
698 */
699 public static final int LOCK_TASK_MODE_LOCKED = 1;
700
701 /**
702 * App pinning mode is active.
703 */
704 public static final int LOCK_TASK_MODE_PINNED = 2;
705
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700706 Point mAppTaskThumbnailSize;
707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 /*package*/ ActivityManager(Context context, Handler handler) {
709 mContext = context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 }
711
712 /**
Bryce Lee7f936862017-05-09 15:33:18 -0700713 * Returns whether the launch was successful.
714 * @hide
715 */
716 public static final boolean isStartResultSuccessful(int result) {
717 return FIRST_START_SUCCESS_CODE <= result && result <= LAST_START_SUCCESS_CODE;
718 }
719
720 /**
721 * Returns whether the launch result was a fatal error.
722 * @hide
723 */
724 public static final boolean isStartResultFatalError(int result) {
725 return FIRST_START_FATAL_ERROR_CODE <= result && result <= LAST_START_FATAL_ERROR_CODE;
726 }
727
728 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700729 * Screen compatibility mode: the application most always run in
730 * compatibility mode.
731 * @hide
732 */
733 public static final int COMPAT_MODE_ALWAYS = -1;
734
735 /**
736 * Screen compatibility mode: the application can never run in
737 * compatibility mode.
738 * @hide
739 */
740 public static final int COMPAT_MODE_NEVER = -2;
741
742 /**
743 * Screen compatibility mode: unknown.
744 * @hide
745 */
746 public static final int COMPAT_MODE_UNKNOWN = -3;
747
748 /**
749 * Screen compatibility mode: the application currently has compatibility
750 * mode disabled.
751 * @hide
752 */
753 public static final int COMPAT_MODE_DISABLED = 0;
754
755 /**
756 * Screen compatibility mode: the application currently has compatibility
757 * mode enabled.
758 * @hide
759 */
760 public static final int COMPAT_MODE_ENABLED = 1;
761
762 /**
763 * Screen compatibility mode: request to toggle the application's
764 * compatibility mode.
765 * @hide
766 */
767 public static final int COMPAT_MODE_TOGGLE = 2;
768
Marc Hittinger17fb5962017-04-05 15:34:38 -0700769 private static final boolean DEVELOPMENT_FORCE_LOW_RAM =
770 SystemProperties.getBoolean("debug.force_low_ram", false);
771
Wale Ogunwale3797c222015-10-27 14:21:58 -0700772 /** @hide */
Steven Timotiuse597ca12017-09-05 15:46:29 -0700773 @TestApi
Wale Ogunwale3797c222015-10-27 14:21:58 -0700774 public static class StackId {
Steven Timotiuse597ca12017-09-05 15:46:29 -0700775
776 private StackId() {
777 }
778
Wale Ogunwale3797c222015-10-27 14:21:58 -0700779 /** Invalid stack ID. */
780 public static final int INVALID_STACK_ID = -1;
Chong Zhang5dcb2752015-08-18 13:50:26 -0700781
Wale Ogunwale3797c222015-10-27 14:21:58 -0700782 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700783
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700784 /**
Matthew Ngbf155872017-10-27 15:24:39 -0700785 * Parameter to {@link android.app.IActivityManager#setTaskWindowingModeSplitScreenPrimary}
786 * which specifies the position of the created docked stack at the top half of the screen if
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700787 * in portrait mode or at the left half of the screen if in landscape mode.
788 * @hide
789 */
Matthew Ngf59a4132017-10-25 12:03:22 -0700790 @TestApi
Matthew Ngbf155872017-10-27 15:24:39 -0700791 public static final int SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT = 0;
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700792
793 /**
Matthew Ngbf155872017-10-27 15:24:39 -0700794 * Parameter to {@link android.app.IActivityManager#setTaskWindowingModeSplitScreenPrimary}
795 * which
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700796 * specifies the position of the created docked stack at the bottom half of the screen if
797 * in portrait mode or at the right half of the screen if in landscape mode.
798 * @hide
799 */
Matthew Ngf59a4132017-10-25 12:03:22 -0700800 @TestApi
Matthew Ngbf155872017-10-27 15:24:39 -0700801 public static final int SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT = 1;
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700802
Chong Zhang87b21722015-09-21 15:39:51 -0700803 /**
804 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700805 * that the resize doesn't need to preserve the window, and can be skipped if bounds
806 * is unchanged. This mode is used by window manager in most cases.
Chong Zhang87b21722015-09-21 15:39:51 -0700807 * @hide
808 */
809 public static final int RESIZE_MODE_SYSTEM = 0;
810
811 /**
812 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700813 * that the resize should preserve the window if possible.
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700814 * @hide
815 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700816 public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0);
Chong Zhang87b21722015-09-21 15:39:51 -0700817
818 /**
819 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
820 * that the resize should be performed even if the bounds appears unchanged.
821 * @hide
822 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700823 public static final int RESIZE_MODE_FORCED = (0x1 << 1);
824
825 /**
826 * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window
827 * manager during a screen rotation.
828 * @hide
829 */
830 public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW;
831
832 /**
833 * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the
834 * resize is due to a drag action.
835 * @hide
836 */
837 public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW;
838
839 /**
840 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
841 * that the resize should preserve the window if possible, and should not be skipped
842 * even if the bounds is unchanged. Usually used to force a resizing when a drag action
843 * is ending.
844 * @hide
845 */
846 public static final int RESIZE_MODE_USER_FORCED =
847 RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED;
Chong Zhang87b21722015-09-21 15:39:51 -0700848
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700849 /** @hide */
850 public int getFrontActivityScreenCompatMode() {
851 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800852 return getService().getFrontActivityScreenCompatMode();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700853 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700854 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700855 }
856 }
857
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700858 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700859 public void setFrontActivityScreenCompatMode(int mode) {
860 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800861 getService().setFrontActivityScreenCompatMode(mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700862 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700863 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700864 }
865 }
866
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700867 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700868 public int getPackageScreenCompatMode(String packageName) {
869 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800870 return getService().getPackageScreenCompatMode(packageName);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700871 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700872 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700873 }
874 }
875
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700876 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700877 public void setPackageScreenCompatMode(String packageName, int mode) {
878 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800879 getService().setPackageScreenCompatMode(packageName, mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700880 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700881 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700882 }
883 }
884
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700885 /** @hide */
886 public boolean getPackageAskScreenCompat(String packageName) {
887 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800888 return getService().getPackageAskScreenCompat(packageName);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700889 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700890 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700891 }
892 }
893
894 /** @hide */
895 public void setPackageAskScreenCompat(String packageName, boolean ask) {
896 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800897 getService().setPackageAskScreenCompat(packageName, ask);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700898 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700899 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700900 }
901 }
902
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700903 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700904 * Return the approximate per-application memory class of the current
905 * device. This gives you an idea of how hard a memory limit you should
906 * impose on your application to let the overall system work best. The
907 * returned value is in megabytes; the baseline Android memory class is
908 * 16 (which happens to be the Java heap limit of those devices); some
Kweku Adams983829f2017-12-06 14:53:50 -0800909 * devices with more memory may return 24 or even higher numbers.
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700910 */
911 public int getMemoryClass() {
912 return staticGetMemoryClass();
913 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700914
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700915 /** @hide */
916 static public int staticGetMemoryClass() {
917 // Really brain dead right now -- just take this from the configured
918 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -0800919 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -0800920 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
921 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
922 }
923 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800924 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700925
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800926 /**
927 * Return the approximate per-application memory class of the current
928 * device when an application is running with a large heap. This is the
929 * space available for memory-intensive applications; most applications
930 * should not need this amount of memory, and should instead stay with the
931 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
932 * This may be the same size as {@link #getMemoryClass()} on memory
933 * constrained devices, or it may be significantly larger on devices with
934 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800935 *
Kweku Adams983829f2017-12-06 14:53:50 -0800936 * <p>This is the size of the application's Dalvik heap if it has
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800937 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800938 */
939 public int getLargeMemoryClass() {
940 return staticGetLargeMemoryClass();
941 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700942
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800943 /** @hide */
944 static public int staticGetLargeMemoryClass() {
945 // Really brain dead right now -- just take this from the configured
946 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700947 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -0700948 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700949 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700950
951 /**
952 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
953 * is ultimately up to the device configuration, but currently it generally means
Greg Kaisere2c459e2017-10-26 10:36:37 -0700954 * something with 1GB or less of RAM. This is mostly intended to be used by apps
955 * to determine whether they should turn off certain features that require more RAM.
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700956 */
957 public boolean isLowRamDevice() {
958 return isLowRamDeviceStatic();
959 }
960
961 /** @hide */
962 public static boolean isLowRamDeviceStatic() {
Marc Hittinger17fb5962017-04-05 15:34:38 -0700963 return RoSystemProperties.CONFIG_LOW_RAM ||
964 (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700965 }
966
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700967 /**
Michael Kwan15eb9982017-04-14 12:34:46 -0700968 * Returns true if this is a small battery device. Exactly whether a device is considered to be
969 * small battery is ultimately up to the device configuration, but currently it generally means
970 * something in the class of a device with 1000 mAh or less. This is mostly intended to be used
971 * to determine whether certain features should be altered to account for a drastically smaller
972 * battery.
973 * @hide
974 */
975 public static boolean isSmallBatteryDevice() {
976 return RoSystemProperties.CONFIG_SMALL_BATTERY;
977 }
978
979 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -0700980 * Used by persistent processes to determine if they are running on a
981 * higher-end device so should be okay using hardware drawing acceleration
982 * (which tends to consume a lot more RAM).
983 * @hide
984 */
Jeff Brown98365d72012-08-19 20:30:52 -0700985 static public boolean isHighEndGfx() {
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700986 return !isLowRamDeviceStatic() &&
987 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -0700988 }
989
990 /**
Dianne Hackborn852975d2014-08-22 17:42:43 -0700991 * Return the maximum number of recents entries that we will maintain and show.
992 * @hide
993 */
994 static public int getMaxRecentTasksStatic() {
995 if (gMaxRecentTasks < 0) {
Winson7c402912016-05-10 13:59:36 -0700996 return gMaxRecentTasks = isLowRamDeviceStatic() ? 36 : 48;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700997 }
998 return gMaxRecentTasks;
999 }
1000
1001 /**
1002 * Return the default limit on the number of recents that an app can make.
1003 * @hide
1004 */
1005 static public int getDefaultAppRecentsLimitStatic() {
1006 return getMaxRecentTasksStatic() / 6;
1007 }
1008
1009 /**
1010 * Return the maximum limit on the number of recents that an app can make.
1011 * @hide
1012 */
1013 static public int getMaxAppRecentsLimitStatic() {
1014 return getMaxRecentTasksStatic() / 2;
1015 }
1016
1017 /**
Wale Ogunwalefb1c8642016-03-02 08:28:08 -08001018 * Returns true if the system supports at least one form of multi-window.
1019 * E.g. freeform, split-screen, picture-in-picture.
1020 * @hide
1021 */
Wale Ogunwale9dcf9462017-09-19 15:13:01 -07001022 @TestApi
Erik Wolsheimer9be3a062017-05-31 14:59:57 -07001023 static public boolean supportsMultiWindow(Context context) {
1024 // On watches, multi-window is used to present essential system UI, and thus it must be
1025 // supported regardless of device memory characteristics.
1026 boolean isWatch = context.getPackageManager().hasSystemFeature(
1027 PackageManager.FEATURE_WATCH);
1028 return (!isLowRamDeviceStatic() || isWatch)
Wale Ogunwalefb1c8642016-03-02 08:28:08 -08001029 && Resources.getSystem().getBoolean(
1030 com.android.internal.R.bool.config_supportsMultiWindow);
1031 }
1032
1033 /**
Matthew Ng626e0cc2016-12-07 17:25:53 -08001034 * Returns true if the system supports split screen multi-window.
1035 * @hide
1036 */
Wale Ogunwale9dcf9462017-09-19 15:13:01 -07001037 @TestApi
Erik Wolsheimer9be3a062017-05-31 14:59:57 -07001038 static public boolean supportsSplitScreenMultiWindow(Context context) {
1039 return supportsMultiWindow(context)
Matthew Ng626e0cc2016-12-07 17:25:53 -08001040 && Resources.getSystem().getBoolean(
1041 com.android.internal.R.bool.config_supportsSplitScreenMultiWindow);
1042 }
1043
Jeff Sharkey000ce802017-04-29 13:13:27 -06001044 /** @removed */
Winson Chung709904f2017-04-25 11:00:48 -07001045 @Deprecated
Winson Chunga29eb982016-12-14 12:01:27 -08001046 public static int getMaxNumPictureInPictureActions() {
Winson Chung709904f2017-04-25 11:00:48 -07001047 return 3;
Winson Chunga29eb982016-12-14 12:01:27 -08001048 }
1049
1050 /**
Winson Chung1147c402014-05-14 11:05:00 -07001051 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -07001052 */
Winson Chunga449dc02014-05-16 11:15:04 -07001053 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -07001054 /** @hide */
1055 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
1056 private static final String ATTR_TASKDESCRIPTIONLABEL =
1057 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +00001058 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -07001059 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +00001060 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
1061 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Matthew Ng54bc9422017-10-02 17:16:28 -07001062 private static final String ATTR_TASKDESCRIPTIONICON_FILENAME =
Craig Mautner648f69b2014-09-18 14:16:26 -07001063 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
Matthew Ng54bc9422017-10-02 17:16:28 -07001064 private static final String ATTR_TASKDESCRIPTIONICON_RESOURCE =
1065 ATTR_TASKDESCRIPTION_PREFIX + "icon_resource";
Craig Mautner648f69b2014-09-18 14:16:26 -07001066
Winson Chunga449dc02014-05-16 11:15:04 -07001067 private String mLabel;
1068 private Bitmap mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001069 private int mIconRes;
Craig Mautner648f69b2014-09-18 14:16:26 -07001070 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001071 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +00001072 private int mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001073 private int mStatusBarColor;
1074 private int mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001075
1076 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001077 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001078 *
Winson Chunga449dc02014-05-16 11:15:04 -07001079 * @param label A label and description of the current state of this task.
1080 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +00001081 * @param colorPrimary A color to override the theme's primary color. This color must be
1082 * opaque.
Matthew Ng54bc9422017-10-02 17:16:28 -07001083 * @deprecated use TaskDescription constructor with icon resource instead
Winson Chung03a9bae2014-05-02 09:56:12 -07001084 */
Matthew Ng54bc9422017-10-02 17:16:28 -07001085 @Deprecated
Winson Chunga449dc02014-05-16 11:15:04 -07001086 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001087 this(label, icon, 0, null, colorPrimary, 0, 0, 0);
1088 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1089 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1090 }
1091 }
1092
1093 /**
1094 * Creates the TaskDescription to the specified values.
1095 *
1096 * @param label A label and description of the current state of this task.
1097 * @param iconRes A drawable resource of an icon that represents the current state of this
1098 * activity.
1099 * @param colorPrimary A color to override the theme's primary color. This color must be
1100 * opaque.
1101 */
1102 public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary) {
1103 this(label, null, iconRes, null, colorPrimary, 0, 0, 0);
Winson Chunga449dc02014-05-16 11:15:04 -07001104 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1105 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1106 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001107 }
1108
Winson Chung03a9bae2014-05-02 09:56:12 -07001109 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001110 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001111 *
1112 * @param label A label and description of the current state of this activity.
1113 * @param icon An icon that represents the current state of this activity.
Matthew Ng54bc9422017-10-02 17:16:28 -07001114 * @deprecated use TaskDescription constructor with icon resource instead
Winson Chung03a9bae2014-05-02 09:56:12 -07001115 */
Matthew Ng54bc9422017-10-02 17:16:28 -07001116 @Deprecated
Winson Chunga449dc02014-05-16 11:15:04 -07001117 public TaskDescription(String label, Bitmap icon) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001118 this(label, icon, 0, null, 0, 0, 0, 0);
1119 }
1120
1121 /**
1122 * Creates the TaskDescription to the specified values.
1123 *
1124 * @param label A label and description of the current state of this activity.
1125 * @param iconRes A drawable resource of an icon that represents the current state of this
1126 * activity.
1127 */
1128 public TaskDescription(String label, @DrawableRes int iconRes) {
1129 this(label, null, iconRes, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001130 }
1131
1132 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001133 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001134 *
1135 * @param label A label and description of the current state of this activity.
1136 */
Winson Chunga449dc02014-05-16 11:15:04 -07001137 public TaskDescription(String label) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001138 this(label, null, 0, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001139 }
1140
Winson Chunga449dc02014-05-16 11:15:04 -07001141 /**
1142 * Creates an empty TaskDescription.
1143 */
1144 public TaskDescription() {
Matthew Ng54bc9422017-10-02 17:16:28 -07001145 this(null, null, 0, null, 0, 0, 0, 0);
Winson Chung1af8eda2016-02-05 17:55:56 +00001146 }
1147
1148 /** @hide */
Matthew Ng54bc9422017-10-02 17:16:28 -07001149 public TaskDescription(String label, Bitmap bitmap, int iconRes, String iconFilename,
1150 int colorPrimary, int colorBackground, int statusBarColor, int navigationBarColor) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001151 mLabel = label;
Matthew Ng54bc9422017-10-02 17:16:28 -07001152 mIcon = bitmap;
1153 mIconRes = iconRes;
Winson Chung1af8eda2016-02-05 17:55:56 +00001154 mIconFilename = iconFilename;
1155 mColorPrimary = colorPrimary;
1156 mColorBackground = colorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001157 mStatusBarColor = statusBarColor;
1158 mNavigationBarColor = navigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001159 }
1160
Winson Chunga449dc02014-05-16 11:15:04 -07001161 /**
1162 * Creates a copy of another TaskDescription.
1163 */
1164 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -08001165 copyFrom(td);
1166 }
1167
1168 /**
1169 * Copies this the values from another TaskDescription.
1170 * @hide
1171 */
1172 public void copyFrom(TaskDescription other) {
1173 mLabel = other.mLabel;
1174 mIcon = other.mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001175 mIconRes = other.mIconRes;
Winsonb6403152016-02-23 13:32:09 -08001176 mIconFilename = other.mIconFilename;
1177 mColorPrimary = other.mColorPrimary;
1178 mColorBackground = other.mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001179 mStatusBarColor = other.mStatusBarColor;
1180 mNavigationBarColor = other.mNavigationBarColor;
Winson Chunga449dc02014-05-16 11:15:04 -07001181 }
1182
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001183 /**
1184 * Copies this the values from another TaskDescription, but preserves the hidden fields
1185 * if they weren't set on {@code other}
1186 * @hide
1187 */
1188 public void copyFromPreserveHiddenFields(TaskDescription other) {
1189 mLabel = other.mLabel;
1190 mIcon = other.mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001191 mIconRes = other.mIconRes;
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001192 mIconFilename = other.mIconFilename;
1193 mColorPrimary = other.mColorPrimary;
1194 if (other.mColorBackground != 0) {
1195 mColorBackground = other.mColorBackground;
1196 }
1197 if (other.mStatusBarColor != 0) {
1198 mStatusBarColor = other.mStatusBarColor;
1199 }
1200 if (other.mNavigationBarColor != 0) {
1201 mNavigationBarColor = other.mNavigationBarColor;
1202 }
1203 }
1204
Winson Chunga449dc02014-05-16 11:15:04 -07001205 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001206 readFromParcel(source);
1207 }
1208
1209 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001210 * Sets the label for this task description.
1211 * @hide
1212 */
1213 public void setLabel(String label) {
1214 mLabel = label;
1215 }
1216
1217 /**
1218 * Sets the primary color for this task description.
1219 * @hide
1220 */
1221 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001222 // Ensure that the given color is valid
1223 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1224 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1225 }
1226 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001227 }
1228
1229 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001230 * Sets the background color for this task description.
1231 * @hide
1232 */
1233 public void setBackgroundColor(int backgroundColor) {
1234 // Ensure that the given color is valid
1235 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1236 throw new RuntimeException("A TaskDescription's background color should be opaque");
1237 }
1238 mColorBackground = backgroundColor;
1239 }
1240
1241 /**
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001242 * @hide
1243 */
1244 public void setStatusBarColor(int statusBarColor) {
1245 mStatusBarColor = statusBarColor;
1246 }
1247
1248 /**
1249 * @hide
1250 */
1251 public void setNavigationBarColor(int navigationBarColor) {
1252 mNavigationBarColor = navigationBarColor;
1253 }
1254
1255 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001256 * Sets the icon for this task description.
1257 * @hide
1258 */
1259 public void setIcon(Bitmap icon) {
1260 mIcon = icon;
1261 }
1262
1263 /**
Matthew Ng54bc9422017-10-02 17:16:28 -07001264 * Sets the icon resource for this task description.
1265 * @hide
1266 */
1267 public void setIcon(int iconRes) {
1268 mIconRes = iconRes;
1269 }
1270
1271 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001272 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1273 * bitmap.
1274 * @hide
1275 */
1276 public void setIconFilename(String iconFilename) {
1277 mIconFilename = iconFilename;
1278 mIcon = null;
1279 }
1280
1281 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001282 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001283 */
Winson Chunga449dc02014-05-16 11:15:04 -07001284 public String getLabel() {
1285 return mLabel;
1286 }
1287
1288 /**
1289 * @return The icon that represents the current state of this task.
1290 */
1291 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001292 if (mIcon != null) {
1293 return mIcon;
1294 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001295 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001296 }
1297
1298 /** @hide */
Matthew Ng54bc9422017-10-02 17:16:28 -07001299 @TestApi
1300 public int getIconResource() {
1301 return mIconRes;
1302 }
1303
1304 /** @hide */
1305 @TestApi
Craig Mautner648f69b2014-09-18 14:16:26 -07001306 public String getIconFilename() {
1307 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001308 }
1309
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001310 /** @hide */
1311 public Bitmap getInMemoryIcon() {
1312 return mIcon;
1313 }
1314
1315 /** @hide */
Suprabh Shukla23593142015-11-03 17:31:15 -08001316 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001317 if (iconFilename != null) {
1318 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001319 return getService().getTaskDescriptionIcon(iconFilename,
Winson Chung1af8eda2016-02-05 17:55:56 +00001320 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001321 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001322 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001323 }
1324 }
1325 return null;
1326 }
1327
Winson Chunga449dc02014-05-16 11:15:04 -07001328 /**
1329 * @return The color override on the theme's primary color.
1330 */
1331 public int getPrimaryColor() {
1332 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001333 }
1334
Winson Chung1af8eda2016-02-05 17:55:56 +00001335 /**
1336 * @return The background color.
1337 * @hide
1338 */
1339 public int getBackgroundColor() {
1340 return mColorBackground;
1341 }
1342
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001343 /**
1344 * @hide
1345 */
1346 public int getStatusBarColor() {
1347 return mStatusBarColor;
1348 }
1349
1350 /**
1351 * @hide
1352 */
1353 public int getNavigationBarColor() {
1354 return mNavigationBarColor;
1355 }
1356
Craig Mautner648f69b2014-09-18 14:16:26 -07001357 /** @hide */
1358 public void saveToXml(XmlSerializer out) throws IOException {
1359 if (mLabel != null) {
1360 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1361 }
1362 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001363 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1364 Integer.toHexString(mColorPrimary));
1365 }
1366 if (mColorBackground != 0) {
1367 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1368 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001369 }
1370 if (mIconFilename != null) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001371 out.attribute(null, ATTR_TASKDESCRIPTIONICON_FILENAME, mIconFilename);
1372 }
1373 if (mIconRes != 0) {
1374 out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE, Integer.toString(mIconRes));
Craig Mautner648f69b2014-09-18 14:16:26 -07001375 }
1376 }
1377
1378 /** @hide */
1379 public void restoreFromXml(String attrName, String attrValue) {
1380 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1381 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001382 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001383 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001384 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1385 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Matthew Ng54bc9422017-10-02 17:16:28 -07001386 } else if (ATTR_TASKDESCRIPTIONICON_FILENAME.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001387 setIconFilename(attrValue);
Matthew Ng54bc9422017-10-02 17:16:28 -07001388 } else if (ATTR_TASKDESCRIPTIONICON_RESOURCE.equals(attrName)) {
1389 setIcon(Integer.parseInt(attrValue, 10));
Craig Mautner648f69b2014-09-18 14:16:26 -07001390 }
1391 }
1392
Winson Chung03a9bae2014-05-02 09:56:12 -07001393 @Override
1394 public int describeContents() {
1395 return 0;
1396 }
1397
1398 @Override
1399 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001400 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001401 dest.writeInt(0);
1402 } else {
1403 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001404 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001405 }
Winson Chunga449dc02014-05-16 11:15:04 -07001406 if (mIcon == null) {
1407 dest.writeInt(0);
1408 } else {
1409 dest.writeInt(1);
1410 mIcon.writeToParcel(dest, 0);
1411 }
Matthew Ng54bc9422017-10-02 17:16:28 -07001412 dest.writeInt(mIconRes);
Winson Chunga449dc02014-05-16 11:15:04 -07001413 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001414 dest.writeInt(mColorBackground);
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001415 dest.writeInt(mStatusBarColor);
1416 dest.writeInt(mNavigationBarColor);
Craig Mautner648f69b2014-09-18 14:16:26 -07001417 if (mIconFilename == null) {
1418 dest.writeInt(0);
1419 } else {
1420 dest.writeInt(1);
1421 dest.writeString(mIconFilename);
1422 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001423 }
1424
1425 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001426 mLabel = source.readInt() > 0 ? source.readString() : null;
1427 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
Matthew Ng54bc9422017-10-02 17:16:28 -07001428 mIconRes = source.readInt();
Winson Chunga449dc02014-05-16 11:15:04 -07001429 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001430 mColorBackground = source.readInt();
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001431 mStatusBarColor = source.readInt();
1432 mNavigationBarColor = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001433 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001434 }
1435
Winson Chunga449dc02014-05-16 11:15:04 -07001436 public static final Creator<TaskDescription> CREATOR
1437 = new Creator<TaskDescription>() {
1438 public TaskDescription createFromParcel(Parcel source) {
1439 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001440 }
Winson Chunga449dc02014-05-16 11:15:04 -07001441 public TaskDescription[] newArray(int size) {
1442 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001443 }
1444 };
1445
1446 @Override
1447 public String toString() {
Winson Chunga449dc02014-05-16 11:15:04 -07001448 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
Matthew Ng54bc9422017-10-02 17:16:28 -07001449 " IconRes: " + mIconRes + " IconFilename: " + mIconFilename +
1450 " colorPrimary: " + mColorPrimary + " colorBackground: " + mColorBackground +
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001451 " statusBarColor: " + mColorBackground +
1452 " navigationBarColor: " + mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001453 }
1454 }
1455
1456 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 * Information you can retrieve about tasks that the user has most recently
1458 * started or visited.
1459 */
1460 public static class RecentTaskInfo implements Parcelable {
1461 /**
1462 * If this task is currently running, this is the identifier for it.
1463 * If it is not running, this will be -1.
1464 */
1465 public int id;
1466
1467 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001468 * The true identifier of this task, valid even if it is not running.
1469 */
1470 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001471
Dianne Hackbornd94df452011-02-16 18:53:31 -08001472 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 * The original Intent used to launch the task. You can use this
1474 * Intent to re-launch the task (if it is no longer running) or bring
1475 * the current task to the front.
1476 */
1477 public Intent baseIntent;
1478
1479 /**
1480 * If this task was started from an alias, this is the actual
1481 * activity component that was initially started; the component of
1482 * the baseIntent in this case is the name of the actual activity
1483 * implementation that the alias referred to. Otherwise, this is null.
1484 */
1485 public ComponentName origActivity;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001486
1487 /**
James Cook4d0ef042015-07-09 14:28:23 -07001488 * The actual activity component that started the task.
1489 * @hide
1490 */
1491 @Nullable
1492 public ComponentName realActivity;
1493
1494 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001495 * Description of the task's last state.
1496 */
1497 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001498
1499 /**
1500 * The id of the ActivityStack this Task was on most recently.
Craig Mautner27030522013-08-26 12:25:36 -07001501 * @hide
Craig Mautner6d90fed2013-05-22 15:03:10 -07001502 */
1503 public int stackId;
1504
Kenny Guy82326a92014-03-17 17:16:06 +00001505 /**
Craig Mautner2fbd7542014-03-21 09:34:07 -07001506 * The id of the user the task was running as.
Kenny Guy82326a92014-03-17 17:16:06 +00001507 * @hide
1508 */
1509 public int userId;
1510
Craig Mautner2fbd7542014-03-21 09:34:07 -07001511 /**
Winson Chungffa2ec62014-07-03 15:54:42 -07001512 * The first time this task was active.
1513 * @hide
1514 */
1515 public long firstActiveTime;
1516
1517 /**
Winson Chungf1fbd772014-06-24 18:06:58 -07001518 * The last time this task was active.
1519 * @hide
1520 */
1521 public long lastActiveTime;
1522
1523 /**
Winson Chung03a9bae2014-05-02 09:56:12 -07001524 * The recent activity values for the highest activity in the stack to have set the values.
Winson Chunga449dc02014-05-16 11:15:04 -07001525 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
Craig Mautner2fbd7542014-03-21 09:34:07 -07001526 */
Winson Chunga449dc02014-05-16 11:15:04 -07001527 public TaskDescription taskDescription;
Craig Mautner2fbd7542014-03-21 09:34:07 -07001528
Craig Mautnera228ae92014-07-09 05:44:55 -07001529 /**
1530 * Task affiliation for grouping with other tasks.
Craig Mautnera228ae92014-07-09 05:44:55 -07001531 */
1532 public int affiliatedTaskId;
1533
Winson Chungec396d62014-08-06 17:08:00 -07001534 /**
1535 * Task affiliation color of the source task with the affiliated task id.
1536 *
1537 * @hide
1538 */
1539 public int affiliatedTaskColor;
1540
Wale Ogunwale6035e012015-04-14 15:54:10 -07001541 /**
1542 * The component launched as the first activity in the task.
1543 * This can be considered the "application" of this task.
1544 */
1545 public ComponentName baseActivity;
1546
1547 /**
1548 * The activity component at the top of the history stack of the task.
1549 * This is what the user is currently doing.
1550 */
1551 public ComponentName topActivity;
1552
1553 /**
1554 * Number of activities in this task.
1555 */
1556 public int numActivities;
1557
Winson2dd76942015-11-02 09:20:01 -08001558 /**
1559 * The bounds of the task.
1560 * @hide
1561 */
1562 public Rect bounds;
1563
Wale Ogunwale21b60582016-01-27 12:34:16 -08001564 /**
1565 * True if the task can go in the docked stack.
1566 * @hide
1567 */
Winson Chungd3395382016-12-13 11:49:09 -08001568 public boolean supportsSplitScreenMultiWindow;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001569
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001570 /**
1571 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1572 * @hide
1573 */
1574 public int resizeMode;
1575
Wale Ogunwale89be5762017-10-04 13:27:49 -07001576 /**
1577 * The current configuration this task is in.
1578 * @hide
1579 */
1580 final public Configuration configuration = new Configuration();
1581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 public RecentTaskInfo() {
1583 }
1584
Craig Mautner6d90fed2013-05-22 15:03:10 -07001585 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 public int describeContents() {
1587 return 0;
1588 }
1589
Craig Mautner6d90fed2013-05-22 15:03:10 -07001590 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 public void writeToParcel(Parcel dest, int flags) {
1592 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001593 dest.writeInt(persistentId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 if (baseIntent != null) {
1595 dest.writeInt(1);
1596 baseIntent.writeToParcel(dest, 0);
1597 } else {
1598 dest.writeInt(0);
1599 }
1600 ComponentName.writeToParcel(origActivity, dest);
James Cook4d0ef042015-07-09 14:28:23 -07001601 ComponentName.writeToParcel(realActivity, dest);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001602 TextUtils.writeToParcel(description, dest,
1603 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
Winson Chunga449dc02014-05-16 11:15:04 -07001604 if (taskDescription != null) {
Craig Mautner2fbd7542014-03-21 09:34:07 -07001605 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001606 taskDescription.writeToParcel(dest, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001607 } else {
1608 dest.writeInt(0);
Craig Mautner2fbd7542014-03-21 09:34:07 -07001609 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001610 dest.writeInt(stackId);
Kenny Guy82326a92014-03-17 17:16:06 +00001611 dest.writeInt(userId);
Winson Chungf1fbd772014-06-24 18:06:58 -07001612 dest.writeLong(lastActiveTime);
Craig Mautnera228ae92014-07-09 05:44:55 -07001613 dest.writeInt(affiliatedTaskId);
Winson Chungec396d62014-08-06 17:08:00 -07001614 dest.writeInt(affiliatedTaskColor);
Wale Ogunwale6035e012015-04-14 15:54:10 -07001615 ComponentName.writeToParcel(baseActivity, dest);
1616 ComponentName.writeToParcel(topActivity, dest);
1617 dest.writeInt(numActivities);
Winson2dd76942015-11-02 09:20:01 -08001618 if (bounds != null) {
1619 dest.writeInt(1);
1620 bounds.writeToParcel(dest, 0);
1621 } else {
1622 dest.writeInt(0);
1623 }
Winson Chungd3395382016-12-13 11:49:09 -08001624 dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001625 dest.writeInt(resizeMode);
Wale Ogunwale89be5762017-10-04 13:27:49 -07001626 configuration.writeToParcel(dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 }
1628
1629 public void readFromParcel(Parcel source) {
1630 id = source.readInt();
Dianne Hackbornd94df452011-02-16 18:53:31 -08001631 persistentId = source.readInt();
Craig Mautner688b5102014-03-27 16:55:03 -07001632 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 origActivity = ComponentName.readFromParcel(source);
James Cook4d0ef042015-07-09 14:28:23 -07001634 realActivity = ComponentName.readFromParcel(source);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001635 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Winson Chunga449dc02014-05-16 11:15:04 -07001636 taskDescription = source.readInt() > 0 ?
1637 TaskDescription.CREATOR.createFromParcel(source) : null;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001638 stackId = source.readInt();
Kenny Guy82326a92014-03-17 17:16:06 +00001639 userId = source.readInt();
Winson Chungf1fbd772014-06-24 18:06:58 -07001640 lastActiveTime = source.readLong();
Craig Mautnera228ae92014-07-09 05:44:55 -07001641 affiliatedTaskId = source.readInt();
Winson Chungec396d62014-08-06 17:08:00 -07001642 affiliatedTaskColor = source.readInt();
Wale Ogunwale6035e012015-04-14 15:54:10 -07001643 baseActivity = ComponentName.readFromParcel(source);
1644 topActivity = ComponentName.readFromParcel(source);
1645 numActivities = source.readInt();
Winson2dd76942015-11-02 09:20:01 -08001646 bounds = source.readInt() > 0 ?
1647 Rect.CREATOR.createFromParcel(source) : null;
Winson Chungd3395382016-12-13 11:49:09 -08001648 supportsSplitScreenMultiWindow = source.readInt() == 1;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001649 resizeMode = source.readInt();
Wale Ogunwale89be5762017-10-04 13:27:49 -07001650 configuration.readFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 public static final Creator<RecentTaskInfo> CREATOR
1654 = new Creator<RecentTaskInfo>() {
1655 public RecentTaskInfo createFromParcel(Parcel source) {
1656 return new RecentTaskInfo(source);
1657 }
1658 public RecentTaskInfo[] newArray(int size) {
1659 return new RecentTaskInfo[size];
1660 }
1661 };
1662
1663 private RecentTaskInfo(Parcel source) {
1664 readFromParcel(source);
1665 }
1666 }
1667
1668 /**
1669 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1670 * that have set their
1671 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1672 */
1673 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001676 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001677 * recent tasks that currently are not available to the user.
1678 */
1679 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001680
1681 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001682 * <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 -08001683 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001684 *
1685 * <p><b>Note: this method is only intended for debugging and presenting
1686 * task management user interfaces</b>. This should never be used for
1687 * core logic in an application, such as deciding between different
1688 * behaviors based on the information found here. Such uses are
1689 * <em>not</em> supported, and will likely break in the future. For
1690 * example, if multiple applications can be actively running at the
1691 * same time, assumptions made about the meaning of the data here for
1692 * purposes of control flow will be incorrect.</p>
1693 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001694 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001695 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001696 * document-centric recents means
1697 * it can leak personal information to the caller. For backwards compatibility,
1698 * it will still return a small subset of its data: at least the caller's
1699 * own tasks (though see {@link #getAppTasks()} for the correct supported
1700 * way to retrieve that information), and possibly some other tasks
1701 * such as home that are known to not be sensitive.
1702 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 * @param maxNum The maximum number of entries to return in the list. The
1704 * actual number returned may be smaller, depending on how many tasks the
1705 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001706 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001707 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001708 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 * @return Returns a list of RecentTaskInfo records describing each of
1710 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001712 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1714 throws SecurityException {
1715 try {
Winson Chungf067ac72017-10-24 17:32:32 -07001716 if (maxNum < 0) {
1717 throw new IllegalArgumentException("The requested number of tasks should be >= 0");
1718 }
Winson Chung5fa39752017-10-04 14:50:15 -07001719 return getService().getRecentTasks(maxNum, flags, UserHandle.myUserId()).getList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001721 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 }
1723 }
1724
1725 /**
1726 * Information you can retrieve about a particular task that is currently
1727 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001728 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001729 * means that the user has gone to it and never closed it, but currently
1730 * the system may have killed its process and is only holding on to its
1731 * last state in order to restart it when the user returns.
1732 */
1733 public static class RunningTaskInfo implements Parcelable {
1734 /**
1735 * A unique identifier for this task.
1736 */
1737 public int id;
1738
1739 /**
Winson5510f6c2015-10-27 12:11:26 -07001740 * The stack that currently contains this task.
1741 * @hide
1742 */
1743 public int stackId;
1744
1745 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001746 * The component launched as the first activity in the task. This can
1747 * be considered the "application" of this task.
1748 */
1749 public ComponentName baseActivity;
1750
1751 /**
1752 * The activity component at the top of the history stack of the task.
1753 * This is what the user is currently doing.
1754 */
1755 public ComponentName topActivity;
1756
1757 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001758 * Thumbnail representation of the task's current state. Currently
1759 * always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 */
1761 public Bitmap thumbnail;
1762
1763 /**
1764 * Description of the task's current state.
1765 */
1766 public CharSequence description;
1767
1768 /**
1769 * Number of activities in this task.
1770 */
1771 public int numActivities;
1772
1773 /**
1774 * Number of activities that are currently running (not stopped
1775 * and persisted) in this task.
1776 */
1777 public int numRunning;
1778
Craig Mautnerc0fd8052013-09-19 11:20:17 -07001779 /**
1780 * Last time task was run. For sorting.
1781 * @hide
1782 */
1783 public long lastActiveTime;
1784
Wale Ogunwale21b60582016-01-27 12:34:16 -08001785 /**
1786 * True if the task can go in the docked stack.
1787 * @hide
1788 */
Winson Chungd3395382016-12-13 11:49:09 -08001789 public boolean supportsSplitScreenMultiWindow;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001790
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001791 /**
1792 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1793 * @hide
1794 */
1795 public int resizeMode;
1796
Wale Ogunwale68278562017-09-23 17:13:55 -07001797 /**
1798 * The full configuration the task is currently running in.
1799 * @hide
1800 */
Wale Ogunwale89be5762017-10-04 13:27:49 -07001801 final public Configuration configuration = new Configuration();
Wale Ogunwale68278562017-09-23 17:13:55 -07001802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 public RunningTaskInfo() {
1804 }
1805
1806 public int describeContents() {
1807 return 0;
1808 }
1809
1810 public void writeToParcel(Parcel dest, int flags) {
1811 dest.writeInt(id);
Winson5510f6c2015-10-27 12:11:26 -07001812 dest.writeInt(stackId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 ComponentName.writeToParcel(baseActivity, dest);
1814 ComponentName.writeToParcel(topActivity, dest);
1815 if (thumbnail != null) {
1816 dest.writeInt(1);
1817 thumbnail.writeToParcel(dest, 0);
1818 } else {
1819 dest.writeInt(0);
1820 }
1821 TextUtils.writeToParcel(description, dest,
1822 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1823 dest.writeInt(numActivities);
1824 dest.writeInt(numRunning);
Winson Chungd3395382016-12-13 11:49:09 -08001825 dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001826 dest.writeInt(resizeMode);
Wale Ogunwale68278562017-09-23 17:13:55 -07001827 configuration.writeToParcel(dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 }
1829
1830 public void readFromParcel(Parcel source) {
1831 id = source.readInt();
Winson5510f6c2015-10-27 12:11:26 -07001832 stackId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 baseActivity = ComponentName.readFromParcel(source);
1834 topActivity = ComponentName.readFromParcel(source);
1835 if (source.readInt() != 0) {
1836 thumbnail = Bitmap.CREATOR.createFromParcel(source);
1837 } else {
1838 thumbnail = null;
1839 }
1840 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
1841 numActivities = source.readInt();
1842 numRunning = source.readInt();
Winson Chungd3395382016-12-13 11:49:09 -08001843 supportsSplitScreenMultiWindow = source.readInt() != 0;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001844 resizeMode = source.readInt();
Wale Ogunwale68278562017-09-23 17:13:55 -07001845 configuration.readFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
1849 public RunningTaskInfo createFromParcel(Parcel source) {
1850 return new RunningTaskInfo(source);
1851 }
1852 public RunningTaskInfo[] newArray(int size) {
1853 return new RunningTaskInfo[size];
1854 }
1855 };
1856
1857 private RunningTaskInfo(Parcel source) {
1858 readFromParcel(source);
1859 }
1860 }
Winson Chung1147c402014-05-14 11:05:00 -07001861
1862 /**
1863 * Get the list of tasks associated with the calling application.
1864 *
1865 * @return The list of tasks associated with the application making this call.
1866 * @throws SecurityException
1867 */
1868 public List<ActivityManager.AppTask> getAppTasks() {
1869 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001870 List<IBinder> appTasks;
Winson Chung1147c402014-05-14 11:05:00 -07001871 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001872 appTasks = getService().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001873 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001874 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001875 }
1876 int numAppTasks = appTasks.size();
1877 for (int i = 0; i < numAppTasks; i++) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001878 tasks.add(new AppTask(IAppTask.Stub.asInterface(appTasks.get(i))));
Winson Chung1147c402014-05-14 11:05:00 -07001879 }
1880 return tasks;
1881 }
1882
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 /**
Winson Chung48a10a52014-08-27 14:36:51 -07001884 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001885 * with {@link #addAppTask}.
1886 */
Winson Chung48a10a52014-08-27 14:36:51 -07001887 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001888 synchronized (this) {
1889 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07001890 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001891 }
1892 }
1893
1894 private void ensureAppTaskThumbnailSizeLocked() {
1895 if (mAppTaskThumbnailSize == null) {
1896 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001897 mAppTaskThumbnailSize = getService().getAppTaskThumbnailSize();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001898 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001899 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001900 }
1901 }
1902 }
1903
1904 /**
1905 * Add a new {@link AppTask} for the calling application. This will create a new
1906 * recents entry that is added to the <b>end</b> of all existing recents.
1907 *
1908 * @param activity The activity that is adding the entry. This is used to help determine
1909 * the context that the new recents entry will be in.
1910 * @param intent The Intent that describes the recents entry. This is the same Intent that
1911 * you would have used to launch the activity for it. In generally you will want to set
1912 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
1913 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
1914 * entry will exist without an activity, so it doesn't make sense to not retain it when
1915 * its activity disappears. The given Intent here also must have an explicit ComponentName
1916 * set on it.
1917 * @param description Optional additional description information.
1918 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07001919 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
1920 * recreated in your process, probably in a way you don't like, before the recents entry
1921 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001922 *
1923 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
1924 * most likely cause of failure is that there is no more room for more tasks for your app.
1925 */
1926 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
1927 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
1928 Point size;
1929 synchronized (this) {
1930 ensureAppTaskThumbnailSizeLocked();
1931 size = mAppTaskThumbnailSize;
1932 }
1933 final int tw = thumbnail.getWidth();
1934 final int th = thumbnail.getHeight();
1935 if (tw != size.x || th != size.y) {
1936 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
1937
1938 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
1939 float scale;
1940 float dx = 0, dy = 0;
1941 if (tw * size.x > size.y * th) {
1942 scale = (float) size.x / (float) th;
1943 dx = (size.y - tw * scale) * 0.5f;
1944 } else {
1945 scale = (float) size.y / (float) tw;
1946 dy = (size.x - th * scale) * 0.5f;
1947 }
1948 Matrix matrix = new Matrix();
1949 matrix.setScale(scale, scale);
1950 matrix.postTranslate((int) (dx + 0.5f), 0);
1951
1952 Canvas canvas = new Canvas(bm);
1953 canvas.drawBitmap(thumbnail, matrix, null);
1954 canvas.setBitmap(null);
1955
1956 thumbnail = bm;
1957 }
1958 if (description == null) {
1959 description = new TaskDescription();
1960 }
1961 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001962 return getService().addAppTask(activity.getActivityToken(),
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001963 intent, description, thumbnail);
1964 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001965 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001966 }
1967 }
1968
1969 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001970 * Return a list of the tasks that are currently running, with
1971 * the most recent being first and older ones after in order. Note that
1972 * "running" does not mean any of the task's code is currently loaded or
1973 * activity -- the task may have been frozen by the system, so that it
1974 * can be restarted in its previous state when next brought to the
1975 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001976 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001977 * <p><b>Note: this method is only intended for debugging and presenting
1978 * task management user interfaces</b>. This should never be used for
1979 * core logic in an application, such as deciding between different
1980 * behaviors based on the information found here. Such uses are
1981 * <em>not</em> supported, and will likely break in the future. For
1982 * example, if multiple applications can be actively running at the
1983 * same time, assumptions made about the meaning of the data here for
1984 * purposes of control flow will be incorrect.</p>
1985 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001986 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001987 * is no longer available to third party
1988 * applications: the introduction of document-centric recents means
1989 * it can leak person information to the caller. For backwards compatibility,
Alan Stokes1e4e74a2017-08-02 11:17:37 +01001990 * it will still return a small subset of its data: at least the caller's
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001991 * own tasks, and possibly some other tasks
1992 * such as home that are known to not be sensitive.
1993 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07001994 * @param maxNum The maximum number of entries to return in the list. The
1995 * actual number returned may be smaller, depending on how many tasks the
1996 * user has started.
1997 *
1998 * @return Returns a list of RunningTaskInfo records describing each of
1999 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07002000 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07002001 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07002002 public List<RunningTaskInfo> getRunningTasks(int maxNum)
2003 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07002004 try {
Winson Chung61c9e5a2017-10-11 10:39:32 -07002005 return getService().getTasks(maxNum);
Dianne Hackborn09233282014-04-30 11:33:59 -07002006 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002007 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07002008 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07002009 }
2010
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002011 /**
Wale Ogunwale388945c2017-10-04 12:13:46 -07002012 * Sets the windowing mode for a specific task. Only works on tasks of type
2013 * {@link WindowConfiguration#ACTIVITY_TYPE_STANDARD}
2014 * @param taskId The id of the task to set the windowing mode for.
2015 * @param windowingMode The windowing mode to set for the task.
2016 * @param toTop If the task should be moved to the top once the windowing mode changes.
2017 * @hide
2018 */
2019 @TestApi
2020 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
2021 public void setTaskWindowingMode(int taskId, int windowingMode, boolean toTop)
2022 throws SecurityException {
2023 try {
2024 getService().setTaskWindowingMode(taskId, windowingMode, toTop);
2025 } catch (RemoteException e) {
2026 throw e.rethrowFromSystemServer();
2027 }
2028 }
2029
2030 /**
Matthew Ngf59a4132017-10-25 12:03:22 -07002031 * Moves the input task to the primary-split-screen stack.
2032 * @param taskId Id of task to move.
2033 * @param createMode The mode the primary split screen stack should be created in if it doesn't
2034 * exist already. See
2035 * {@link android.app.ActivityManager#SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT}
2036 * and
2037 * {@link android.app.ActivityManager
2038 * #SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT}
2039 * @param toTop If the task and stack should be moved to the top.
2040 * @param animate Whether we should play an animation for the moving the task
2041 * @param initialBounds If the primary stack gets created, it will use these bounds for the
2042 * docked stack. Pass {@code null} to use default bounds.
Wale Ogunwalec59b4f62017-11-30 11:05:43 -08002043 * @param showRecents If the recents activity should be shown on the other side of the task
2044 * going into split-screen mode.
Matthew Ngf59a4132017-10-25 12:03:22 -07002045 * @hide
2046 */
2047 @TestApi
2048 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
2049 public void setTaskWindowingModeSplitScreenPrimary(int taskId, int createMode, boolean toTop,
Wale Ogunwalec59b4f62017-11-30 11:05:43 -08002050 boolean animate, Rect initialBounds, boolean showRecents) throws SecurityException {
Matthew Ngf59a4132017-10-25 12:03:22 -07002051 try {
2052 getService().setTaskWindowingModeSplitScreenPrimary(taskId, createMode, toTop, animate,
Wale Ogunwalec59b4f62017-11-30 11:05:43 -08002053 initialBounds, showRecents);
Matthew Ngf59a4132017-10-25 12:03:22 -07002054 } catch (RemoteException e) {
2055 throw e.rethrowFromSystemServer();
2056 }
2057 }
2058
2059 /**
Wale Ogunwale388945c2017-10-04 12:13:46 -07002060 * Resizes the input stack id to the given bounds.
2061 * @param stackId Id of the stack to resize.
2062 * @param bounds Bounds to resize the stack to or {@code null} for fullscreen.
2063 * @hide
2064 */
2065 @TestApi
2066 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
2067 public void resizeStack(int stackId, Rect bounds) throws SecurityException {
2068 try {
2069 getService().resizeStack(stackId, bounds, false /* allowResizeInDockedMode */,
2070 false /* preserveWindows */, false /* animate */, -1 /* animationDuration */);
2071 } catch (RemoteException e) {
2072 throw e.rethrowFromSystemServer();
2073 }
2074 }
2075
2076 /**
Wale Ogunwale68278562017-09-23 17:13:55 -07002077 * Removes stacks in the windowing modes from the system if they are of activity type
2078 * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED
2079 *
2080 * @hide
2081 */
2082 @TestApi
Wale Ogunwale388945c2017-10-04 12:13:46 -07002083 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
Wale Ogunwale68278562017-09-23 17:13:55 -07002084 public void removeStacksInWindowingModes(int[] windowingModes) throws SecurityException {
2085 try {
2086 getService().removeStacksInWindowingModes(windowingModes);
2087 } catch (RemoteException e) {
2088 throw e.rethrowFromSystemServer();
2089 }
2090 }
2091
2092 /**
2093 * Removes stack of the activity types from the system.
2094 *
2095 * @hide
2096 */
2097 @TestApi
Wale Ogunwale388945c2017-10-04 12:13:46 -07002098 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
Wale Ogunwale68278562017-09-23 17:13:55 -07002099 public void removeStacksWithActivityTypes(int[] activityTypes) throws SecurityException {
2100 try {
2101 getService().removeStacksWithActivityTypes(activityTypes);
2102 } catch (RemoteException e) {
2103 throw e.rethrowFromSystemServer();
2104 }
2105 }
2106
2107 /**
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002108 * Represents a task snapshot.
2109 * @hide
2110 */
2111 public static class TaskSnapshot implements Parcelable {
2112
2113 private final GraphicBuffer mSnapshot;
2114 private final int mOrientation;
2115 private final Rect mContentInsets;
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002116 private final boolean mReducedResolution;
2117 private final float mScale;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002118
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002119 public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets,
2120 boolean reducedResolution, float scale) {
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002121 mSnapshot = snapshot;
2122 mOrientation = orientation;
2123 mContentInsets = new Rect(contentInsets);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002124 mReducedResolution = reducedResolution;
2125 mScale = scale;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002126 }
2127
2128 private TaskSnapshot(Parcel source) {
2129 mSnapshot = source.readParcelable(null /* classLoader */);
2130 mOrientation = source.readInt();
2131 mContentInsets = source.readParcelable(null /* classLoader */);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002132 mReducedResolution = source.readBoolean();
2133 mScale = source.readFloat();
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002134 }
2135
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002136 /**
2137 * @return The graphic buffer representing the screenshot.
2138 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002139 public GraphicBuffer getSnapshot() {
2140 return mSnapshot;
2141 }
2142
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002143 /**
2144 * @return The screen orientation the screenshot was taken in.
2145 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002146 public int getOrientation() {
2147 return mOrientation;
2148 }
2149
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002150 /**
2151 * @return The system/content insets on the snapshot. These can be clipped off in order to
2152 * remove any areas behind system bars in the snapshot.
2153 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002154 public Rect getContentInsets() {
2155 return mContentInsets;
2156 }
2157
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002158 /**
2159 * @return Whether this snapshot is a down-sampled version of the full resolution.
2160 */
2161 public boolean isReducedResolution() {
2162 return mReducedResolution;
2163 }
2164
2165 /**
2166 * @return The scale this snapshot was taken in.
2167 */
2168 public float getScale() {
2169 return mScale;
2170 }
2171
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002172 @Override
2173 public int describeContents() {
2174 return 0;
2175 }
2176
2177 @Override
2178 public void writeToParcel(Parcel dest, int flags) {
2179 dest.writeParcelable(mSnapshot, 0);
2180 dest.writeInt(mOrientation);
2181 dest.writeParcelable(mContentInsets, 0);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002182 dest.writeBoolean(mReducedResolution);
2183 dest.writeFloat(mScale);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002184 }
2185
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002186 @Override
2187 public String toString() {
2188 return "TaskSnapshot{mSnapshot=" + mSnapshot + " mOrientation=" + mOrientation
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002189 + " mContentInsets=" + mContentInsets.toShortString()
2190 + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale;
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002191 }
2192
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002193 public static final Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
2194 public TaskSnapshot createFromParcel(Parcel source) {
2195 return new TaskSnapshot(source);
2196 }
2197 public TaskSnapshot[] newArray(int size) {
2198 return new TaskSnapshot[size];
2199 }
2200 };
2201 }
2202
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002203 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002204 @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = {
2205 MOVE_TASK_WITH_HOME,
2206 MOVE_TASK_NO_USER_ACTION,
2207 })
2208 @Retention(RetentionPolicy.SOURCE)
2209 public @interface MoveTaskFlags {}
2210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002211 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002212 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
2213 * activity along with the task, so it is positioned immediately behind
2214 * the task.
2215 */
2216 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
2217
2218 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08002219 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
2220 * user-instigated action, so the current activity will not receive a
2221 * hint that the user is leaving.
2222 */
2223 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
2224
2225 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002226 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
2227 * with a null options argument.
2228 *
2229 * @param taskId The identifier of the task to be moved, as found in
2230 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002231 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002232 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002233 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2234 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002235 moveTaskToFront(taskId, flags, null);
2236 }
2237
2238 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002239 * Ask that the task associated with a given task ID be moved to the
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002240 * front of the stack, so it is now visible to the user.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002241 *
2242 * @param taskId The identifier of the task to be moved, as found in
2243 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002244 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002245 * @param options Additional options for the operation, either null or
2246 * as per {@link Context#startActivity(Intent, android.os.Bundle)
2247 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002248 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002249 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2250 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002251 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002252 getService().moveTaskToFront(taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002253 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002254 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002255 }
2256 }
2257
2258 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 * Information you can retrieve about a particular Service that is
2260 * currently running in the system.
2261 */
2262 public static class RunningServiceInfo implements Parcelable {
2263 /**
2264 * The service component.
2265 */
2266 public ComponentName service;
2267
2268 /**
2269 * If non-zero, this is the process the service is running in.
2270 */
2271 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002274 * The UID that owns this service.
2275 */
2276 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002277
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002278 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 * The name of the process this service runs in.
2280 */
2281 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 /**
2284 * Set to true if the service has asked to run as a foreground process.
2285 */
2286 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002288 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002289 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002290 * starting or binding to it. This
2291 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 */
2293 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 /**
2296 * Set to true if this service has been explicitly started.
2297 */
2298 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 /**
2301 * Number of clients connected to the service.
2302 */
2303 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 /**
2306 * Number of times the service's process has crashed while the service
2307 * is running.
2308 */
2309 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 /**
2312 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002313 * explicit requests to start it or clients binding to it). This
2314 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 */
2316 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002318 /**
2319 * If non-zero, this service is not currently running, but scheduled to
2320 * restart at the given time.
2321 */
2322 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002323
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002324 /**
2325 * Bit for {@link #flags}: set if this service has been
2326 * explicitly started.
2327 */
2328 public static final int FLAG_STARTED = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002329
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002330 /**
2331 * Bit for {@link #flags}: set if the service has asked to
2332 * run as a foreground process.
2333 */
2334 public static final int FLAG_FOREGROUND = 1<<1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002335
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002336 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002337 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002338 * core system process.
2339 */
2340 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002341
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002342 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002343 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002344 * persistent process.
2345 */
2346 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002347
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002348 /**
2349 * Running flags.
2350 */
2351 public int flags;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002352
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002353 /**
2354 * For special services that are bound to by system code, this is
2355 * the package that holds the binding.
2356 */
2357 public String clientPackage;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002358
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002359 /**
2360 * For special services that are bound to by system code, this is
2361 * a string resource providing a user-visible label for who the
2362 * client is.
2363 */
2364 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 public RunningServiceInfo() {
2367 }
2368
2369 public int describeContents() {
2370 return 0;
2371 }
2372
2373 public void writeToParcel(Parcel dest, int flags) {
2374 ComponentName.writeToParcel(service, dest);
2375 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002376 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 dest.writeString(process);
2378 dest.writeInt(foreground ? 1 : 0);
2379 dest.writeLong(activeSince);
2380 dest.writeInt(started ? 1 : 0);
2381 dest.writeInt(clientCount);
2382 dest.writeInt(crashCount);
2383 dest.writeLong(lastActivityTime);
2384 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002385 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002386 dest.writeString(clientPackage);
2387 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 }
2389
2390 public void readFromParcel(Parcel source) {
2391 service = ComponentName.readFromParcel(source);
2392 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002393 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394 process = source.readString();
2395 foreground = source.readInt() != 0;
2396 activeSince = source.readLong();
2397 started = source.readInt() != 0;
2398 clientCount = source.readInt();
2399 crashCount = source.readInt();
2400 lastActivityTime = source.readLong();
2401 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002402 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002403 clientPackage = source.readString();
2404 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
2408 public RunningServiceInfo createFromParcel(Parcel source) {
2409 return new RunningServiceInfo(source);
2410 }
2411 public RunningServiceInfo[] newArray(int size) {
2412 return new RunningServiceInfo[size];
2413 }
2414 };
2415
2416 private RunningServiceInfo(Parcel source) {
2417 readFromParcel(source);
2418 }
2419 }
2420
2421 /**
2422 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002423 *
2424 * <p><b>Note: this method is only intended for debugging or implementing
2425 * service management type user interfaces.</b></p>
2426 *
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002427 * @deprecated As of {@link android.os.Build.VERSION_CODES#O}, this method
2428 * is no longer available to third party applications. For backwards compatibility,
2429 * it will still return the caller's own services.
2430 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 * @param maxNum The maximum number of entries to return in the list. The
2432 * actual number returned may be smaller, depending on how many services
2433 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002434 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 * @return Returns a list of RunningServiceInfo records describing each of
2436 * the running tasks.
2437 */
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002438 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 public List<RunningServiceInfo> getRunningServices(int maxNum)
2440 throws SecurityException {
2441 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002442 return getService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 .getServices(maxNum, 0);
2444 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002445 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446 }
2447 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002450 * Returns a PendingIntent you can start to show a control panel for the
2451 * given running service. If the service does not have a control panel,
2452 * null is returned.
2453 */
2454 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2455 throws SecurityException {
2456 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002457 return getService()
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002458 .getRunningServiceControlPanel(service);
2459 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002460 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002461 }
2462 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002463
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002464 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 * Information you can retrieve about the available memory through
2466 * {@link ActivityManager#getMemoryInfo}.
2467 */
2468 public static class MemoryInfo implements Parcelable {
2469 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002470 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002471 * be considered absolute: due to the nature of the kernel, a significant
2472 * portion of this memory is actually in use and needed for the overall
2473 * system to run well.
2474 */
2475 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002476
2477 /**
2478 * The total memory accessible by the kernel. This is basically the
2479 * RAM size of the device, not including below-kernel fixed allocations
2480 * like DMA buffers, RAM for the baseband CPU, etc.
2481 */
2482 public long totalMem;
2483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 /**
2485 * The threshold of {@link #availMem} at which we consider memory to be
2486 * low and start killing background services and other non-extraneous
2487 * processes.
2488 */
2489 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 /**
2492 * Set to true if the system considers itself to currently be in a low
2493 * memory situation.
2494 */
2495 public boolean lowMemory;
2496
Dianne Hackborn7d608422011-08-07 16:24:18 -07002497 /** @hide */
2498 public long hiddenAppThreshold;
2499 /** @hide */
2500 public long secondaryServerThreshold;
2501 /** @hide */
2502 public long visibleAppThreshold;
2503 /** @hide */
2504 public long foregroundAppThreshold;
2505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 public MemoryInfo() {
2507 }
2508
2509 public int describeContents() {
2510 return 0;
2511 }
2512
2513 public void writeToParcel(Parcel dest, int flags) {
2514 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002515 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 dest.writeLong(threshold);
2517 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002518 dest.writeLong(hiddenAppThreshold);
2519 dest.writeLong(secondaryServerThreshold);
2520 dest.writeLong(visibleAppThreshold);
2521 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 public void readFromParcel(Parcel source) {
2525 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002526 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 threshold = source.readLong();
2528 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002529 hiddenAppThreshold = source.readLong();
2530 secondaryServerThreshold = source.readLong();
2531 visibleAppThreshold = source.readLong();
2532 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 }
2534
2535 public static final Creator<MemoryInfo> CREATOR
2536 = new Creator<MemoryInfo>() {
2537 public MemoryInfo createFromParcel(Parcel source) {
2538 return new MemoryInfo(source);
2539 }
2540 public MemoryInfo[] newArray(int size) {
2541 return new MemoryInfo[size];
2542 }
2543 };
2544
2545 private MemoryInfo(Parcel source) {
2546 readFromParcel(source);
2547 }
2548 }
2549
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002550 /**
2551 * Return general information about the memory state of the system. This
2552 * can be used to help decide how to manage your own memory, though note
2553 * that polling is not recommended and
2554 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2555 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2556 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2557 * level of your process as needed, which gives a better hint for how to
2558 * manage its memory.
2559 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 public void getMemoryInfo(MemoryInfo outInfo) {
2561 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002562 getService().getMemoryInfo(outInfo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002564 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 }
2566 }
Craig Mautner967212c2013-04-13 21:10:58 -07002567
Craig Mautner5ff12102013-05-24 12:50:15 -07002568 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002569 * Information you can retrieve about an ActivityStack in the system.
2570 * @hide
2571 */
2572 public static class StackInfo implements Parcelable {
2573 public int stackId;
Craig Mautnered6649f2013-12-02 14:08:25 -08002574 public Rect bounds = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -07002575 public int[] taskIds;
2576 public String[] taskNames;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002577 public Rect[] taskBounds;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002578 public int[] taskUserIds;
Winsond46b7272016-04-20 11:54:27 -07002579 public ComponentName topActivity;
Craig Mautnered6649f2013-12-02 14:08:25 -08002580 public int displayId;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002581 public int userId;
Winsond46b7272016-04-20 11:54:27 -07002582 public boolean visible;
Winson529c8e42016-05-17 11:08:40 -07002583 // Index of the stack in the display's stack list, can be used for comparison of stack order
2584 public int position;
Wale Ogunwale68278562017-09-23 17:13:55 -07002585 /**
2586 * The full configuration the stack is currently running in.
2587 * @hide
2588 */
Wale Ogunwale89be5762017-10-04 13:27:49 -07002589 final public Configuration configuration = new Configuration();
Craig Mautner967212c2013-04-13 21:10:58 -07002590
Craig Mautner967212c2013-04-13 21:10:58 -07002591 @Override
2592 public int describeContents() {
2593 return 0;
2594 }
2595
2596 @Override
2597 public void writeToParcel(Parcel dest, int flags) {
2598 dest.writeInt(stackId);
2599 dest.writeInt(bounds.left);
2600 dest.writeInt(bounds.top);
2601 dest.writeInt(bounds.right);
2602 dest.writeInt(bounds.bottom);
2603 dest.writeIntArray(taskIds);
2604 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002605 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2606 dest.writeInt(boundsCount);
2607 for (int i = 0; i < boundsCount; i++) {
2608 dest.writeInt(taskBounds[i].left);
2609 dest.writeInt(taskBounds[i].top);
2610 dest.writeInt(taskBounds[i].right);
2611 dest.writeInt(taskBounds[i].bottom);
2612 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002613 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002614 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002615 dest.writeInt(userId);
Winsond46b7272016-04-20 11:54:27 -07002616 dest.writeInt(visible ? 1 : 0);
Winson529c8e42016-05-17 11:08:40 -07002617 dest.writeInt(position);
Winsond46b7272016-04-20 11:54:27 -07002618 if (topActivity != null) {
2619 dest.writeInt(1);
2620 topActivity.writeToParcel(dest, 0);
2621 } else {
2622 dest.writeInt(0);
2623 }
Wale Ogunwale68278562017-09-23 17:13:55 -07002624 configuration.writeToParcel(dest, flags);
Craig Mautner967212c2013-04-13 21:10:58 -07002625 }
2626
2627 public void readFromParcel(Parcel source) {
2628 stackId = source.readInt();
2629 bounds = new Rect(
2630 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2631 taskIds = source.createIntArray();
2632 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002633 final int boundsCount = source.readInt();
2634 if (boundsCount > 0) {
2635 taskBounds = new Rect[boundsCount];
2636 for (int i = 0; i < boundsCount; i++) {
2637 taskBounds[i] = new Rect();
2638 taskBounds[i].set(
2639 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2640 }
2641 } else {
2642 taskBounds = null;
2643 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002644 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002645 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002646 userId = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002647 visible = source.readInt() > 0;
Winson529c8e42016-05-17 11:08:40 -07002648 position = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002649 if (source.readInt() > 0) {
2650 topActivity = ComponentName.readFromParcel(source);
2651 }
Wale Ogunwale68278562017-09-23 17:13:55 -07002652 configuration.readFromParcel(source);
Craig Mautner967212c2013-04-13 21:10:58 -07002653 }
2654
2655 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
2656 @Override
2657 public StackInfo createFromParcel(Parcel source) {
2658 return new StackInfo(source);
2659 }
2660 @Override
2661 public StackInfo[] newArray(int size) {
2662 return new StackInfo[size];
2663 }
2664 };
2665
Craig Mautner5ff12102013-05-24 12:50:15 -07002666 public StackInfo() {
2667 }
2668
Craig Mautner967212c2013-04-13 21:10:58 -07002669 private StackInfo(Parcel source) {
2670 readFromParcel(source);
2671 }
2672
Craig Mautner5ff12102013-05-24 12:50:15 -07002673 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002674 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002675 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002676 sb.append(" bounds="); sb.append(bounds.toShortString());
2677 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002678 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002679 sb.append("\n");
Wale Ogunwale68278562017-09-23 17:13:55 -07002680 sb.append(" configuration="); sb.append(configuration);
2681 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002682 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002683 for (int i = 0; i < taskIds.length; ++i) {
2684 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002685 sb.append(": "); sb.append(taskNames[i]);
2686 if (taskBounds != null) {
2687 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2688 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002689 sb.append(" userId=").append(taskUserIds[i]);
Winsond46b7272016-04-20 11:54:27 -07002690 sb.append(" visible=").append(visible);
2691 if (topActivity != null) {
2692 sb.append(" topActivity=").append(topActivity);
2693 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002694 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002695 }
2696 return sb.toString();
2697 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002698
2699 @Override
2700 public String toString() {
2701 return toString("");
2702 }
Craig Mautner967212c2013-04-13 21:10:58 -07002703 }
2704
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705 /**
2706 * @hide
2707 */
Svet Ganovf935a702017-08-22 12:15:58 -07002708 @RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA,
2709 Manifest.permission.ACCESS_INSTANT_APPS})
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2711 try {
Christopher Tate1d99c392017-12-07 16:54:04 -08002712 return getService().clearApplicationUserData(packageName, false,
Dianne Hackborn41203752012-08-31 14:05:51 -07002713 observer, UserHandle.myUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002715 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002716 }
2717 }
Christopher Tatea3664242013-06-26 15:00:18 -07002718
2719 /**
2720 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002721 * the user choosing to clear the app's data from within the device settings UI. It
2722 * erases all dynamic data associated with the app -- its private data and data in its
2723 * private area on external storage -- but does not remove the installed application
Benjamin Franza77e3572017-06-23 12:01:44 +01002724 * itself, nor any OBB files. It also revokes all runtime permissions that the app has acquired,
2725 * clears all notifications and removes all Uri grants related to this application.
Christopher Tatea3664242013-06-26 15:00:18 -07002726 *
2727 * @return {@code true} if the application successfully requested that the application's
2728 * data be erased; {@code false} otherwise.
2729 */
2730 public boolean clearApplicationUserData() {
2731 return clearApplicationUserData(mContext.getPackageName(), null);
2732 }
2733
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002734
2735 /**
2736 * Permits an application to get the persistent URI permissions granted to another.
2737 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002738 * <p>Typically called by Settings or DocumentsUI, requires
2739 * {@code GET_APP_GRANTED_URI_PERMISSIONS}.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002740 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002741 * @param packageName application to look for the granted permissions, or {@code null} to get
2742 * granted permissions for all applications
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002743 * @return list of granted URI permissions
2744 *
2745 * @hide
2746 */
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002747 public ParceledListSlice<GrantedUriPermission> getGrantedUriPermissions(
2748 @Nullable String packageName) {
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002749 try {
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002750 @SuppressWarnings("unchecked")
2751 final ParceledListSlice<GrantedUriPermission> castedList = getService()
2752 .getGrantedUriPermissions(packageName, UserHandle.myUserId());
2753 return castedList;
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002754 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002755 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002756 }
2757 }
2758
2759 /**
2760 * Permits an application to clear the persistent URI permissions granted to another.
2761 *
Felipe Leme23a0c7a2018-01-24 08:43:34 -08002762 * <p>Typically called by Settings, requires {@code CLEAR_APP_GRANTED_URI_PERMISSIONS}.
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002763 *
2764 * @param packageName application to clear its granted permissions
2765 *
2766 * @hide
2767 */
2768 public void clearGrantedUriPermissions(String packageName) {
2769 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002770 getService().clearGrantedUriPermissions(packageName,
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002771 UserHandle.myUserId());
2772 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002773 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002774 }
2775 }
2776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 /**
2778 * Information you can retrieve about any processes that are in an error condition.
2779 */
2780 public static class ProcessErrorStateInfo implements Parcelable {
2781 /**
2782 * Condition codes
2783 */
2784 public static final int NO_ERROR = 0;
2785 public static final int CRASHED = 1;
2786 public static final int NOT_RESPONDING = 2;
2787
2788 /**
2789 * The condition that the process is in.
2790 */
2791 public int condition;
2792
2793 /**
2794 * The process name in which the crash or error occurred.
2795 */
2796 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 /**
2799 * The pid of this process; 0 if none
2800 */
2801 public int pid;
2802
2803 /**
2804 * The kernel user-ID that has been assigned to this process;
2805 * currently this is not a unique ID (multiple applications can have
2806 * the same uid).
2807 */
2808 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 /**
Dan Egnor60d87622009-12-16 16:32:58 -08002811 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 */
2813 public String tag;
2814
2815 /**
2816 * A short message describing the error condition.
2817 */
2818 public String shortMsg;
2819
2820 /**
2821 * A long message describing the error condition.
2822 */
2823 public String longMsg;
2824
2825 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08002826 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 */
Dan Egnorb7f03672009-12-09 16:22:32 -08002828 public String stackTrace;
2829
2830 /**
2831 * to be deprecated: This value will always be null.
2832 */
2833 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834
2835 public ProcessErrorStateInfo() {
2836 }
2837
Craig Mautner5ff12102013-05-24 12:50:15 -07002838 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 public int describeContents() {
2840 return 0;
2841 }
2842
Craig Mautner5ff12102013-05-24 12:50:15 -07002843 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 public void writeToParcel(Parcel dest, int flags) {
2845 dest.writeInt(condition);
2846 dest.writeString(processName);
2847 dest.writeInt(pid);
2848 dest.writeInt(uid);
2849 dest.writeString(tag);
2850 dest.writeString(shortMsg);
2851 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08002852 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 public void readFromParcel(Parcel source) {
2856 condition = source.readInt();
2857 processName = source.readString();
2858 pid = source.readInt();
2859 uid = source.readInt();
2860 tag = source.readString();
2861 shortMsg = source.readString();
2862 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08002863 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002865
2866 public static final Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 new Creator<ProcessErrorStateInfo>() {
2868 public ProcessErrorStateInfo createFromParcel(Parcel source) {
2869 return new ProcessErrorStateInfo(source);
2870 }
2871 public ProcessErrorStateInfo[] newArray(int size) {
2872 return new ProcessErrorStateInfo[size];
2873 }
2874 };
2875
2876 private ProcessErrorStateInfo(Parcel source) {
2877 readFromParcel(source);
2878 }
2879 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002882 * 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 -08002883 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002884 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002885 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
2886 * current error conditions (it will not return an empty list). This list ordering is not
2887 * specified.
2888 */
2889 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
2890 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002891 return getService().getProcessesInErrorState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002893 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 }
2895 }
2896
2897 /**
2898 * Information you can retrieve about a running process.
2899 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07002900 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 /**
2902 * The name of the process that this object is associated with
2903 */
2904 public String processName;
2905
2906 /**
2907 * The pid of this process; 0 if none
2908 */
2909 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002910
Dianne Hackborneb034652009-09-07 00:49:58 -07002911 /**
2912 * The user id of this process.
2913 */
2914 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002915
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002916 /**
2917 * All packages that have been loaded into the process.
2918 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07002920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07002922 * Constant for {@link #flags}: this is an app that is unable to
2923 * correctly save its state when going to the background,
2924 * so it can not be killed while in the background.
2925 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002926 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07002927 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002928
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002929 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002930 * Constant for {@link #flags}: this process is associated with a
2931 * persistent system app.
2932 * @hide
2933 */
2934 public static final int FLAG_PERSISTENT = 1<<1;
2935
2936 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07002937 * Constant for {@link #flags}: this process is associated with a
2938 * persistent system app.
2939 * @hide
2940 */
2941 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
2942
2943 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002944 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07002945 * {@link #FLAG_CANT_SAVE_STATE}.
2946 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002947 */
2948 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002949
2950 /**
2951 * Last memory trim level reported to the process: corresponds to
2952 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2953 * ComponentCallbacks2.onTrimMemory(int)}.
2954 */
2955 public int lastTrimLevel;
2956
Jeff Sharkey910e0812017-04-21 16:29:27 -06002957 /** @hide */
2958 @IntDef(prefix = { "IMPORTANCE_" }, value = {
2959 IMPORTANCE_FOREGROUND,
2960 IMPORTANCE_FOREGROUND_SERVICE,
2961 IMPORTANCE_TOP_SLEEPING,
2962 IMPORTANCE_VISIBLE,
2963 IMPORTANCE_PERCEPTIBLE,
2964 IMPORTANCE_CANT_SAVE_STATE,
2965 IMPORTANCE_SERVICE,
2966 IMPORTANCE_CACHED,
2967 IMPORTANCE_GONE,
2968 })
2969 @Retention(RetentionPolicy.SOURCE)
2970 public @interface Importance {}
2971
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002972 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002973 * Constant for {@link #importance}: This process is running the
2974 * foreground UI; that is, it is the thing currently at the top of the screen
2975 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 */
2977 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002980 * Constant for {@link #importance}: This process is running a foreground
2981 * service, for example to perform music playback even while the user is
2982 * not immediately in the app. This generally indicates that the process
2983 * is doing something the user actively cares about.
2984 */
2985 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
2986
2987 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002988 * @deprecated Pre-{@link android.os.Build.VERSION_CODES#P} version of
2989 * {@link #IMPORTANCE_TOP_SLEEPING}. As of Android
2990 * {@link android.os.Build.VERSION_CODES#P}, this is considered much less
2991 * important since we want to reduce what apps can do when the screen is off.
Dianne Hackborn1e383822015-04-10 14:02:33 -07002992 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002993 @Deprecated
2994 public static final int IMPORTANCE_TOP_SLEEPING_PRE_28 = 150;
Dianne Hackborn1e383822015-04-10 14:02:33 -07002995
2996 /**
2997 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002998 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07002999 * foreground. This may be running a window that is behind the current
3000 * foreground (so paused and with its state saved, not interacting with
3001 * the user, but visible to them to some degree); it may also be running
3002 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07003003 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003004 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003005
Dianne Hackborn860755f2010-06-03 18:47:52 -07003006 /**
Makoto Onukid7e40582017-04-13 14:54:56 -07003007 * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value
3008 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3009 * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed.
3010 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003011 * <p>The system will return this value instead of {@link #IMPORTANCE_PERCEPTIBLE}
3012 * on Android versions below {@link Build.VERSION_CODES#O}.
3013 *
3014 * <p>On Android version {@link Build.VERSION_CODES#O} and later, this value will still be
3015 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3016 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3017 * the correct value {@link #IMPORTANCE_PERCEPTIBLE} will be returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003018 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003019 public static final int IMPORTANCE_PERCEPTIBLE_PRE_26 = 130;
Makoto Onukid7e40582017-04-13 14:54:56 -07003020
3021 /**
3022 * Constant for {@link #importance}: This process is not something the user
3023 * is directly aware of, but is otherwise perceptible to them to some degree.
3024 */
3025 public static final int IMPORTANCE_PERCEPTIBLE = 230;
3026
3027 /**
3028 * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had
3029 * this wrong value
3030 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3031 * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed.
3032 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003033 * <p>The system will return this value instead of {@link #IMPORTANCE_CANT_SAVE_STATE}
3034 * on Android versions below {@link Build.VERSION_CODES#O}.
3035 *
3036 * <p>On Android version {@link Build.VERSION_CODES#O} after, this value will still be
3037 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3038 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3039 * the correct value {@link #IMPORTANCE_CANT_SAVE_STATE} will be returned.
3040 *
Makoto Onukid7e40582017-04-13 14:54:56 -07003041 * @hide
3042 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003043 public static final int IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003044
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003045 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003046 * Constant for {@link #importance}: This process is contains services
3047 * that should remain running. These are background services apps have
3048 * started, not something the user is aware of, so they may be killed by
3049 * the system relatively freely (though it is generally desired that they
3050 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051 */
3052 public static final int IMPORTANCE_SERVICE = 300;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003053
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003054 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003055 * Constant for {@link #importance}: This process is running the foreground
3056 * UI, but the device is asleep so it is not visible to the user. Though the
3057 * system will try hard to keep its process from being killed, in all other
3058 * ways we consider it a kind of cached process, with the limitations that go
3059 * along with that state: network access, running background services, etc.
3060 */
3061 public static final int IMPORTANCE_TOP_SLEEPING = 325;
3062
3063 /**
Dianne Hackbornf097d422017-12-15 16:32:19 -08003064 * Constant for {@link #importance}: This process is running an
3065 * application that can not save its state, and thus can't be killed
3066 * while in the background. This will be used with apps that have
3067 * {@link android.R.attr#cantSaveState} set on their application tag.
3068 */
3069 public static final int IMPORTANCE_CANT_SAVE_STATE = 350;
3070
3071 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003072 * Constant for {@link #importance}: This process process contains
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003073 * cached code that is expendable, not actively running any app components
3074 * we care about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003075 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003076 public static final int IMPORTANCE_CACHED = 400;
3077
3078 /**
3079 * @deprecated Renamed to {@link #IMPORTANCE_CACHED}.
3080 */
3081 public static final int IMPORTANCE_BACKGROUND = IMPORTANCE_CACHED;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003083 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003084 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003085 * actively running code.
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003086 * @deprecated This value is no longer reported, use {@link #IMPORTANCE_CACHED} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003087 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003088 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003090
3091 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003092 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003093 */
3094 public static final int IMPORTANCE_GONE = 1000;
3095
Makoto Onukid7e40582017-04-13 14:54:56 -07003096 /**
3097 * Convert a proc state to the correspondent IMPORTANCE_* constant. If the return value
3098 * will be passed to a client, use {@link #procStateToImportanceForClient}.
3099 * @hide
3100 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003101 public static @Importance int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003102 if (procState == PROCESS_STATE_NONEXISTENT) {
3103 return IMPORTANCE_GONE;
3104 } else if (procState >= PROCESS_STATE_HOME) {
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003105 return IMPORTANCE_CACHED;
Dianne Hackbornf4ef6eb2017-12-07 13:57:21 -08003106 } else if (procState == PROCESS_STATE_HEAVY_WEIGHT) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003107 return IMPORTANCE_CANT_SAVE_STATE;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003108 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
3109 return IMPORTANCE_TOP_SLEEPING;
Dianne Hackbornf097d422017-12-15 16:32:19 -08003110 } else if (procState >= PROCESS_STATE_SERVICE) {
3111 return IMPORTANCE_SERVICE;
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003112 } else if (procState >= PROCESS_STATE_TRANSIENT_BACKGROUND) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003113 return IMPORTANCE_PERCEPTIBLE;
3114 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
3115 return IMPORTANCE_VISIBLE;
Dianne Hackborn1e383822015-04-10 14:02:33 -07003116 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) {
3117 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003118 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003119 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003120 }
3121 }
3122
Makoto Onukid7e40582017-04-13 14:54:56 -07003123 /**
3124 * Convert a proc state to the correspondent IMPORTANCE_* constant for a client represented
3125 * by a given {@link Context}, with converting {@link #IMPORTANCE_PERCEPTIBLE}
3126 * and {@link #IMPORTANCE_CANT_SAVE_STATE} to the corresponding "wrong" value if the
3127 * client's target SDK < {@link VERSION_CODES#O}.
3128 * @hide
3129 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003130 public static @Importance int procStateToImportanceForClient(int procState,
3131 Context clientContext) {
Makoto Onukie92f7942017-04-26 14:38:18 -07003132 return procStateToImportanceForTargetSdk(procState,
3133 clientContext.getApplicationInfo().targetSdkVersion);
3134 }
3135
3136 /**
3137 * See {@link #procStateToImportanceForClient}.
3138 * @hide
3139 */
3140 public static @Importance int procStateToImportanceForTargetSdk(int procState,
3141 int targetSdkVersion) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003142 final int importance = procStateToImportance(procState);
3143
3144 // For pre O apps, convert to the old, wrong values.
Makoto Onukie92f7942017-04-26 14:38:18 -07003145 if (targetSdkVersion < VERSION_CODES.O) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003146 switch (importance) {
3147 case IMPORTANCE_PERCEPTIBLE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003148 return IMPORTANCE_PERCEPTIBLE_PRE_26;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003149 case IMPORTANCE_TOP_SLEEPING:
3150 return IMPORTANCE_TOP_SLEEPING_PRE_28;
Makoto Onukid7e40582017-04-13 14:54:56 -07003151 case IMPORTANCE_CANT_SAVE_STATE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003152 return IMPORTANCE_CANT_SAVE_STATE_PRE_26;
Makoto Onukid7e40582017-04-13 14:54:56 -07003153 }
3154 }
3155 return importance;
3156 }
3157
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003158 /** @hide */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003159 public static int importanceToProcState(@Importance int importance) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003160 if (importance == IMPORTANCE_GONE) {
3161 return PROCESS_STATE_NONEXISTENT;
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003162 } else if (importance >= IMPORTANCE_CACHED) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003163 return PROCESS_STATE_HOME;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003164 } else if (importance >= IMPORTANCE_CANT_SAVE_STATE) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003165 return PROCESS_STATE_HEAVY_WEIGHT;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003166 } else if (importance >= IMPORTANCE_TOP_SLEEPING) {
3167 return PROCESS_STATE_TOP_SLEEPING;
Dianne Hackbornf097d422017-12-15 16:32:19 -08003168 } else if (importance >= IMPORTANCE_SERVICE) {
3169 return PROCESS_STATE_SERVICE;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003170 } else if (importance >= IMPORTANCE_PERCEPTIBLE) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003171 return PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003172 } else if (importance >= IMPORTANCE_VISIBLE) {
3173 return PROCESS_STATE_IMPORTANT_FOREGROUND;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003174 } else if (importance >= IMPORTANCE_TOP_SLEEPING_PRE_28) {
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -08003175 return PROCESS_STATE_IMPORTANT_FOREGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003176 } else if (importance >= IMPORTANCE_FOREGROUND_SERVICE) {
3177 return PROCESS_STATE_FOREGROUND_SERVICE;
3178 } else {
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -08003179 return PROCESS_STATE_TOP;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003180 }
3181 }
3182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 /**
Jeff Sharkey910e0812017-04-21 16:29:27 -06003184 * The relative importance level that the system places on this process.
3185 * These constants are numbered so that "more important" values are
3186 * always smaller than "less important" values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003188 public @Importance int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 /**
3191 * An additional ordering within a particular {@link #importance}
3192 * category, providing finer-grained information about the relative
3193 * utility of processes within a category. This number means nothing
3194 * except that a smaller values are more recently used (and thus
3195 * more important). Currently an LRU value is only maintained for
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003196 * the {@link #IMPORTANCE_CACHED} category, though others may
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 * be maintained in the future.
3198 */
3199 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003200
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003201 /**
3202 * Constant for {@link #importanceReasonCode}: nothing special has
3203 * been specified for the reason for this level.
3204 */
3205 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003206
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003207 /**
3208 * Constant for {@link #importanceReasonCode}: one of the application's
3209 * content providers is being used by another process. The pid of
3210 * the client process is in {@link #importanceReasonPid} and the
3211 * target provider in this process is in
3212 * {@link #importanceReasonComponent}.
3213 */
3214 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003215
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003216 /**
3217 * Constant for {@link #importanceReasonCode}: one of the application's
3218 * content providers is being used by another process. The pid of
3219 * the client process is in {@link #importanceReasonPid} and the
3220 * target provider in this process is in
3221 * {@link #importanceReasonComponent}.
3222 */
3223 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003224
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003225 /**
3226 * The reason for {@link #importance}, if any.
3227 */
3228 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003229
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003230 /**
3231 * For the specified values of {@link #importanceReasonCode}, this
3232 * is the process ID of the other process that is a client of this
3233 * process. This will be 0 if no other process is using this one.
3234 */
3235 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003236
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003237 /**
3238 * For the specified values of {@link #importanceReasonCode}, this
3239 * is the name of the component that is being used in this process.
3240 */
3241 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003242
Dianne Hackborn905577f2011-09-07 18:31:28 -07003243 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003244 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07003245 * of the other pid. @hide
3246 */
3247 public int importanceReasonImportance;
3248
Dianne Hackborn684bf342014-04-29 17:56:57 -07003249 /**
3250 * Current process state, as per PROCESS_STATE_* constants.
3251 * @hide
3252 */
3253 public int processState;
3254
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 public RunningAppProcessInfo() {
3256 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003257 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07003258 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
3262 processName = pProcessName;
3263 pid = pPid;
3264 pkgList = pArr;
3265 }
3266
3267 public int describeContents() {
3268 return 0;
3269 }
3270
3271 public void writeToParcel(Parcel dest, int flags) {
3272 dest.writeString(processName);
3273 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07003274 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003276 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003277 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 dest.writeInt(importance);
3279 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003280 dest.writeInt(importanceReasonCode);
3281 dest.writeInt(importanceReasonPid);
3282 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003283 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07003284 dest.writeInt(processState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 }
3286
3287 public void readFromParcel(Parcel source) {
3288 processName = source.readString();
3289 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07003290 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003291 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003292 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003293 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 importance = source.readInt();
3295 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003296 importanceReasonCode = source.readInt();
3297 importanceReasonPid = source.readInt();
3298 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003299 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07003300 processState = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 }
3302
Stefan Kuhne16045c22015-06-05 07:18:06 -07003303 public static final Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 new Creator<RunningAppProcessInfo>() {
3305 public RunningAppProcessInfo createFromParcel(Parcel source) {
3306 return new RunningAppProcessInfo(source);
3307 }
3308 public RunningAppProcessInfo[] newArray(int size) {
3309 return new RunningAppProcessInfo[size];
3310 }
3311 };
3312
3313 private RunningAppProcessInfo(Parcel source) {
3314 readFromParcel(source);
3315 }
3316 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003319 * Returns a list of application processes installed on external media
3320 * that are running on the device.
3321 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003322 * <p><b>Note: this method is only intended for debugging or building
3323 * a user-facing process management UI.</b></p>
3324 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003325 * @return Returns a list of ApplicationInfo records, or null if none
3326 * This list ordering is not specified.
3327 * @hide
3328 */
3329 public List<ApplicationInfo> getRunningExternalApplications() {
3330 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003331 return getService().getRunningExternalApplications();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003332 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003333 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003334 }
3335 }
3336
3337 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003338 * Sets the memory trim mode for a process and schedules a memory trim operation.
3339 *
3340 * <p><b>Note: this method is only intended for testing framework.</b></p>
3341 *
3342 * @return Returns true if successful.
3343 * @hide
3344 */
3345 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
3346 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003347 return getService().setProcessMemoryTrimLevel(process, userId,
Stefan Kuhne16045c22015-06-05 07:18:06 -07003348 level);
3349 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003350 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07003351 }
3352 }
3353
3354 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003355 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003356 *
3357 * <p><b>Note: this method is only intended for debugging or building
3358 * a user-facing process management UI.</b></p>
3359 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003360 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
3361 * running processes (it will not return an empty list). This list ordering is not
3362 * specified.
3363 */
3364 public List<RunningAppProcessInfo> getRunningAppProcesses() {
3365 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003366 return getService().getRunningAppProcesses();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003368 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 }
3370 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003371
3372 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003373 * Return the importance of a given package name, based on the processes that are
3374 * currently running. The return value is one of the importance constants defined
3375 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3376 * processes that this package has code running inside of. If there are no processes
3377 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07003378 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07003379 */
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003380 @SystemApi @TestApi
Dianne Hackborn9df8f512016-10-24 17:58:30 -07003381 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003382 public @RunningAppProcessInfo.Importance int getPackageImportance(String packageName) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003383 try {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003384 int procState = getService().getPackageProcessState(packageName,
Adam Lesinskic30454c2015-06-24 13:24:35 -07003385 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003386 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn1e383822015-04-10 14:02:33 -07003387 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003388 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07003389 }
3390 }
3391
3392 /**
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003393 * Return the importance of a given uid, based on the processes that are
3394 * currently running. The return value is one of the importance constants defined
3395 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3396 * processes that this uid has running. If there are no processes
3397 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
3398 * @hide
3399 */
3400 @SystemApi @TestApi
3401 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003402 public @RunningAppProcessInfo.Importance int getUidImportance(int uid) {
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003403 try {
3404 int procState = getService().getUidProcessState(uid,
3405 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003406 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003407 } catch (RemoteException e) {
3408 throw e.rethrowFromSystemServer();
3409 }
3410 }
3411
3412 /**
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003413 * Callback to get reports about changes to the importance of a uid. Use with
3414 * {@link #addOnUidImportanceListener}.
3415 * @hide
3416 */
3417 @SystemApi @TestApi
3418 public interface OnUidImportanceListener {
3419 /**
3420 * The importance if a given uid has changed. Will be one of the importance
3421 * values in {@link RunningAppProcessInfo};
3422 * {@link RunningAppProcessInfo#IMPORTANCE_GONE IMPORTANCE_GONE} will be reported
3423 * when the uid is no longer running at all. This callback will happen on a thread
3424 * from a thread pool, not the main UI thread.
3425 * @param uid The uid whose importance has changed.
3426 * @param importance The new importance value as per {@link RunningAppProcessInfo}.
3427 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003428 void onUidImportance(int uid, @RunningAppProcessInfo.Importance int importance);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003429 }
3430
3431 /**
3432 * Start monitoring changes to the imoportance of uids running in the system.
3433 * @param listener The listener callback that will receive change reports.
3434 * @param importanceCutpoint The level of importance in which the caller is interested
3435 * in differences. For example, if {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}
3436 * is used here, you will receive a call each time a uids importance transitions between
3437 * being <= {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE} and
3438 * > {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.
3439 *
3440 * <p>The caller must hold the {@link android.Manifest.permission#PACKAGE_USAGE_STATS}
3441 * permission to use this feature.</p>
3442 *
3443 * @throws IllegalArgumentException If the listener is already registered.
3444 * @throws SecurityException If the caller does not hold
3445 * {@link android.Manifest.permission#PACKAGE_USAGE_STATS}.
3446 * @hide
3447 */
3448 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003449 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003450 public void addOnUidImportanceListener(OnUidImportanceListener listener,
Jeff Sharkey910e0812017-04-21 16:29:27 -06003451 @RunningAppProcessInfo.Importance int importanceCutpoint) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003452 synchronized (this) {
3453 if (mImportanceListeners.containsKey(listener)) {
3454 throw new IllegalArgumentException("Listener already registered: " + listener);
3455 }
3456 // TODO: implement the cut point in the system process to avoid IPCs.
Makoto Onukid7e40582017-04-13 14:54:56 -07003457 UidObserver observer = new UidObserver(listener, mContext);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003458 try {
3459 getService().registerUidObserver(observer,
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003460 UID_OBSERVER_PROCSTATE | UID_OBSERVER_GONE,
3461 RunningAppProcessInfo.importanceToProcState(importanceCutpoint),
3462 mContext.getOpPackageName());
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003463 } catch (RemoteException e) {
3464 throw e.rethrowFromSystemServer();
3465 }
3466 mImportanceListeners.put(listener, observer);
3467 }
3468 }
3469
3470 /**
3471 * Remove an importance listener that was previously registered with
3472 * {@link #addOnUidImportanceListener}.
3473 *
3474 * @throws IllegalArgumentException If the listener is not registered.
3475 * @hide
3476 */
3477 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003478 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003479 public void removeOnUidImportanceListener(OnUidImportanceListener listener) {
3480 synchronized (this) {
3481 UidObserver observer = mImportanceListeners.remove(listener);
3482 if (observer == null) {
3483 throw new IllegalArgumentException("Listener not registered: " + listener);
3484 }
3485 try {
3486 getService().unregisterUidObserver(observer);
3487 } catch (RemoteException e) {
3488 throw e.rethrowFromSystemServer();
3489 }
3490 }
3491 }
3492
3493 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003494 * Return global memory state information for the calling process. This
3495 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
3496 * only fields that will be filled in are
3497 * {@link RunningAppProcessInfo#pid},
3498 * {@link RunningAppProcessInfo#uid},
3499 * {@link RunningAppProcessInfo#lastTrimLevel},
3500 * {@link RunningAppProcessInfo#importance},
3501 * {@link RunningAppProcessInfo#lru}, and
3502 * {@link RunningAppProcessInfo#importanceReasonCode}.
3503 */
3504 static public void getMyMemoryState(RunningAppProcessInfo outState) {
3505 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003506 getService().getMyMemoryState(outState);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003507 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003508 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003509 }
3510 }
3511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003513 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003514 *
3515 * <p><b>Note: this method is only intended for debugging or building
3516 * a user-facing process management UI.</b></p>
3517 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003518 * @param pids The pids of the processes whose memory usage is to be
3519 * retrieved.
3520 * @return Returns an array of memory information, one for each
3521 * requested pid.
3522 */
3523 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
3524 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003525 return getService().getProcessMemoryInfo(pids);
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003526 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003527 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003528 }
3529 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003530
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003531 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003532 * @deprecated This is now just a wrapper for
3533 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3534 * is no longer available to applications because it allows them to
3535 * break other applications by removing their alarms, stopping their
3536 * services, etc.
3537 */
3538 @Deprecated
3539 public void restartPackage(String packageName) {
3540 killBackgroundProcesses(packageName);
3541 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003542
Dianne Hackborn03abb812010-01-04 18:43:19 -08003543 /**
3544 * Have the system immediately kill all background processes associated
3545 * with the given package. This is the same as the kernel killing those
3546 * processes to reclaim memory; the system will take care of restarting
3547 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003548 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003549 * @param packageName The name of the package whose processes are to
3550 * be killed.
3551 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003552 @RequiresPermission(Manifest.permission.KILL_BACKGROUND_PROCESSES)
Dianne Hackborn03abb812010-01-04 18:43:19 -08003553 public void killBackgroundProcesses(String packageName) {
3554 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003555 getService().killBackgroundProcesses(packageName,
Dianne Hackborn1676c852012-09-10 14:52:30 -07003556 UserHandle.myUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003557 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003558 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003559 }
3560 }
Svet Ganov019d2302015-05-04 11:07:38 -07003561
3562 /**
3563 * Kills the specified UID.
3564 * @param uid The UID to kill.
3565 * @param reason The reason for the kill.
3566 *
3567 * @hide
3568 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08003569 @SystemApi
Svet Ganov019d2302015-05-04 11:07:38 -07003570 @RequiresPermission(Manifest.permission.KILL_UID)
3571 public void killUid(int uid, String reason) {
3572 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003573 getService().killUid(UserHandle.getAppId(uid),
Svetoslavaa41add2015-08-06 15:03:55 -07003574 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003575 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003576 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003577 }
3578 }
3579
Dianne Hackborn03abb812010-01-04 18:43:19 -08003580 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 * Have the system perform a force stop of everything associated with
3582 * the given application package. All processes that share its uid
3583 * will be killed, all services it has running stopped, all activities
3584 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3585 * broadcast will be sent, so that any of its registered alarms can
3586 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003587 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003589 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003591 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003593 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003594 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003595 * @hide This is not available to third party applications due to
3596 * it allowing them to break other applications by stopping their
3597 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003598 */
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003599 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003601 getService().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003602 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003603 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 }
3605 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003606
3607 /**
3608 * @see #forceStopPackageAsUser(String, int)
3609 * @hide
3610 */
Jeff Schumacherb8cadef2017-01-03 13:52:48 -08003611 @SystemApi
3612 @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES)
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003613 public void forceStopPackage(String packageName) {
3614 forceStopPackageAsUser(packageName, UserHandle.myUserId());
3615 }
3616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 /**
3618 * Get the device configuration attributes.
3619 */
3620 public ConfigurationInfo getDeviceConfigurationInfo() {
3621 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003622 return getService().getDeviceConfigurationInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003624 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003627
3628 /**
3629 * Get the preferred density of icons for the launcher. This is used when
3630 * custom drawables are created (e.g., for shortcuts).
3631 *
3632 * @return density in terms of DPI
3633 */
3634 public int getLauncherLargeIconDensity() {
3635 final Resources res = mContext.getResources();
3636 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003637 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003638
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003639 if (sw < 600) {
3640 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003641 return density;
3642 }
3643
3644 switch (density) {
3645 case DisplayMetrics.DENSITY_LOW:
3646 return DisplayMetrics.DENSITY_MEDIUM;
3647 case DisplayMetrics.DENSITY_MEDIUM:
3648 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003649 case DisplayMetrics.DENSITY_TV:
3650 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003651 case DisplayMetrics.DENSITY_HIGH:
3652 return DisplayMetrics.DENSITY_XHIGH;
3653 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003654 return DisplayMetrics.DENSITY_XXHIGH;
3655 case DisplayMetrics.DENSITY_XXHIGH:
3656 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003657 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003658 // The density is some abnormal value. Return some other
3659 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003660 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003661 }
3662 }
3663
3664 /**
3665 * Get the preferred launcher icon size. This is used when custom drawables
3666 * are created (e.g., for shortcuts).
3667 *
3668 * @return dimensions of square icons in terms of pixels
3669 */
3670 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003671 return getLauncherLargeIconSizeInner(mContext);
3672 }
3673
3674 static int getLauncherLargeIconSizeInner(Context context) {
3675 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003676 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003677 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003678
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003679 if (sw < 600) {
3680 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003681 return size;
3682 }
3683
3684 final int density = res.getDisplayMetrics().densityDpi;
3685
3686 switch (density) {
3687 case DisplayMetrics.DENSITY_LOW:
3688 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3689 case DisplayMetrics.DENSITY_MEDIUM:
3690 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003691 case DisplayMetrics.DENSITY_TV:
3692 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003693 case DisplayMetrics.DENSITY_HIGH:
3694 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3695 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003696 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3697 case DisplayMetrics.DENSITY_XXHIGH:
3698 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003699 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003700 // The density is some abnormal value. Return some other
3701 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003702 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003703 }
3704 }
3705
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003706 /**
3707 * Returns "true" if the user interface is currently being messed with
3708 * by a monkey.
3709 */
3710 public static boolean isUserAMonkey() {
3711 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003712 return getService().isUserAMonkey();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003713 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003714 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003715 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003716 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003717
3718 /**
3719 * Returns "true" if device is running in a test harness.
3720 */
3721 public static boolean isRunningInTestHarness() {
3722 return SystemProperties.getBoolean("ro.test_harness", false);
3723 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003724
3725 /**
3726 * Returns the launch count of each installed package.
3727 *
3728 * @hide
3729 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003730 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00003731 try {
3732 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
3733 ServiceManager.getService("usagestats"));
3734 if (usageStatsService == null) {
3735 return new HashMap<String, Integer>();
3736 }
3737
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003738 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
3739 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00003740 if (allPkgUsageStats == null) {
3741 return new HashMap<String, Integer>();
3742 }
3743
Peter Visontay8d224ca2011-02-18 16:39:19 +00003744 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003745 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
3746 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00003747 }
3748
3749 return launchCounts;
3750 } catch (RemoteException e) {
3751 Log.w(TAG, "Could not query launch counts", e);
3752 return new HashMap<String, Integer>();
3753 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003754 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003755
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003756 /** @hide */
3757 public static int checkComponentPermission(String permission, int uid,
3758 int owningUid, boolean exported) {
3759 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08003760 final int appId = UserHandle.getAppId(uid);
3761 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003762 return PackageManager.PERMISSION_GRANTED;
3763 }
3764 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003765 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003766 return PackageManager.PERMISSION_DENIED;
3767 }
3768 // If there is a uid that owns whatever is being accessed, it has
3769 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003770 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003771 return PackageManager.PERMISSION_GRANTED;
3772 }
3773 // If the target is not exported, then nobody else can get to it.
3774 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07003775 /*
3776 RuntimeException here = new RuntimeException("here");
3777 here.fillInStackTrace();
3778 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
3779 here);
3780 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003781 return PackageManager.PERMISSION_DENIED;
3782 }
3783 if (permission == null) {
3784 return PackageManager.PERMISSION_GRANTED;
3785 }
3786 try {
3787 return AppGlobals.getPackageManager()
3788 .checkUidPermission(permission, uid);
3789 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003790 throw e.rethrowFromSystemServer();
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003791 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003792 }
3793
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003794 /** @hide */
3795 public static int checkUidPermission(String permission, int uid) {
3796 try {
3797 return AppGlobals.getPackageManager()
3798 .checkUidPermission(permission, uid);
3799 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003800 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003801 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003802 }
3803
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08003804 /**
3805 * @hide
3806 * Helper for dealing with incoming user arguments to system service calls.
3807 * Takes care of checking permissions and converting USER_CURRENT to the
3808 * actual current user.
3809 *
3810 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
3811 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
3812 * @param userId The user id argument supplied by the caller -- this is the user
3813 * they want to run as.
3814 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
3815 * to get a USER_ALL returned and deal with it correctly. If false,
3816 * an exception will be thrown if USER_ALL is supplied.
3817 * @param requireFull If true, the caller must hold
3818 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
3819 * different user than their current process; otherwise they must hold
3820 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
3821 * @param name Optional textual name of the incoming call; only for generating error messages.
3822 * @param callerPackage Optional package name of caller; only for error messages.
3823 *
3824 * @return Returns the user ID that the call should run as. Will always be a concrete
3825 * user number, unless <var>allowAll</var> is true in which case it could also be
3826 * USER_ALL.
3827 */
Dianne Hackborn41203752012-08-31 14:05:51 -07003828 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
3829 boolean allowAll, boolean requireFull, String name, String callerPackage) {
3830 if (UserHandle.getUserId(callingUid) == userId) {
3831 return userId;
3832 }
3833 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003834 return getService().handleIncomingUser(callingPid,
Dianne Hackborn41203752012-08-31 14:05:51 -07003835 callingUid, userId, allowAll, requireFull, name, callerPackage);
3836 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003837 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003838 }
3839 }
3840
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07003841 /**
3842 * Gets the userId of the current foreground user. Requires system permissions.
3843 * @hide
3844 */
3845 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003846 @RequiresPermission(anyOf = {
3847 "android.permission.INTERACT_ACROSS_USERS",
3848 "android.permission.INTERACT_ACROSS_USERS_FULL"
3849 })
Dianne Hackborn41203752012-08-31 14:05:51 -07003850 public static int getCurrentUser() {
3851 UserInfo ui;
3852 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003853 ui = getService().getCurrentUser();
Dianne Hackborn41203752012-08-31 14:05:51 -07003854 return ui != null ? ui.id : 0;
3855 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003856 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003857 }
3858 }
3859
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003860 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003861 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003862 * @hide
3863 */
3864 public boolean switchUser(int userid) {
3865 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003866 return getService().switchUser(userid);
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003867 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003868 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003869 }
3870 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003871
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003872 /**
3873 * Logs out current current foreground user by switching to the system user and stopping the
3874 * user being switched from.
3875 * @hide
3876 */
3877 public static void logoutCurrentUser() {
3878 int currentUser = ActivityManager.getCurrentUser();
3879 if (currentUser != UserHandle.USER_SYSTEM) {
3880 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003881 getService().switchUser(UserHandle.USER_SYSTEM);
3882 getService().stopUser(currentUser, /* force= */ false, null);
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003883 } catch (RemoteException e) {
3884 e.rethrowFromSystemServer();
3885 }
3886 }
3887 }
3888
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003889 /** {@hide} */
3890 public static final int FLAG_OR_STOPPED = 1 << 0;
3891 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07003892 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07003893 /** {@hide} */
3894 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeyce18c812016-04-27 16:00:41 -06003895 /** {@hide} */
3896 public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003897
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003898 /**
3899 * Return whether the given user is actively running. This means that
3900 * the user is in the "started" state, not "stopped" -- it is currently
3901 * allowed to run code through scheduled alarms, receiving broadcasts,
3902 * etc. A started user may be either the current foreground user or a
3903 * background user; the result here does not distinguish between the two.
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003904 * @param userId the user's id. Zero indicates the default user.
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003905 * @hide
3906 */
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003907 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003908 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003909 return getService().isUserRunning(userId, 0);
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003910 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003911 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003912 }
3913 }
3914
3915 /** {@hide} */
Ruben Brunke24b9a62016-02-16 21:38:24 -08003916 public boolean isVrModePackageEnabled(ComponentName component) {
3917 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003918 return getService().isVrModePackageEnabled(component);
Ruben Brunke24b9a62016-02-16 21:38:24 -08003919 } catch (RemoteException e) {
3920 throw e.rethrowFromSystemServer();
3921 }
3922 }
3923
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003924 /**
3925 * Perform a system dump of various state associated with the given application
3926 * package name. This call blocks while the dump is being performed, so should
3927 * not be done on a UI thread. The data will be written to the given file
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003928 * descriptor as text.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07003929 * @param fd The file descriptor that the dump should be written to. The file
3930 * descriptor is <em>not</em> closed by this function; the caller continues to
3931 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003932 * @param packageName The name of the package that is to be dumped.
3933 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003934 @RequiresPermission(Manifest.permission.DUMP)
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003935 public void dumpPackageState(FileDescriptor fd, String packageName) {
3936 dumpPackageStateStatic(fd, packageName);
3937 }
3938
3939 /**
3940 * @hide
3941 */
3942 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
3943 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07003944 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003945 dumpService(pw, fd, "package", new String[] { packageName });
3946 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003947 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
3948 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003949 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003950 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003951 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003952 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003953 pw.println();
Esteban Talavera838ea242017-12-19 11:48:43 +00003954 dumpService(pw, fd, "usagestats", new String[] { packageName });
Dianne Hackborn904a8572013-06-28 18:12:31 -07003955 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07003956 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003957 pw.flush();
3958 }
3959
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003960 /**
3961 * @hide
3962 */
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003963 public static boolean isSystemReady() {
3964 if (!sSystemReady) {
3965 if (ActivityThread.isSystem()) {
3966 sSystemReady =
3967 LocalServices.getService(ActivityManagerInternal.class).isSystemReady();
3968 } else {
3969 // Since this is being called from outside system server, system should be
3970 // ready by now.
3971 sSystemReady = true;
3972 }
3973 }
3974 return sSystemReady;
3975 }
3976
3977 /**
3978 * @hide
3979 */
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003980 public static void broadcastStickyIntent(Intent intent, int userId) {
3981 broadcastStickyIntent(intent, AppOpsManager.OP_NONE, userId);
3982 }
3983
3984 /**
3985 * Convenience for sending a sticky broadcast. For internal use only.
3986 *
3987 * @hide
3988 */
3989 public static void broadcastStickyIntent(Intent intent, int appOp, int userId) {
3990 try {
3991 getService().broadcastIntent(
3992 null, intent, null, null, Activity.RESULT_OK, null, null,
3993 null /*permission*/, appOp, null, false, true, userId);
3994 } catch (RemoteException ex) {
3995 }
3996 }
3997
3998 /**
3999 * @hide
4000 */
Narayan Kamath695cf722017-12-21 18:32:47 +00004001 public static void noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid,
4002 String sourcePkg, String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004003 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00004004 getService().noteWakeupAlarm((ps != null) ? ps.getTarget() : null, workSource,
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004005 sourceUid, sourcePkg, tag);
4006 } catch (RemoteException ex) {
4007 }
4008 }
4009
4010 /**
4011 * @hide
4012 */
Narayan Kamath695cf722017-12-21 18:32:47 +00004013 public static void noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid,
4014 String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004015 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00004016 getService().noteAlarmStart((ps != null) ? ps.getTarget() : null, workSource,
4017 sourceUid, tag);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004018 } catch (RemoteException ex) {
4019 }
4020 }
4021
Narayan Kamath695cf722017-12-21 18:32:47 +00004022
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004023 /**
4024 * @hide
4025 */
Narayan Kamath695cf722017-12-21 18:32:47 +00004026 public static void noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid,
4027 String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004028 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00004029 getService().noteAlarmFinish((ps != null) ? ps.getTarget() : null, workSource,
4030 sourceUid, tag);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004031 } catch (RemoteException ex) {
4032 }
4033 }
4034
4035 /**
4036 * @hide
4037 */
4038 public static IActivityManager getService() {
4039 return IActivityManagerSingleton.get();
4040 }
4041
4042 private static final Singleton<IActivityManager> IActivityManagerSingleton =
4043 new Singleton<IActivityManager>() {
4044 @Override
4045 protected IActivityManager create() {
4046 final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE);
4047 final IActivityManager am = IActivityManager.Stub.asInterface(b);
4048 return am;
4049 }
4050 };
4051
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004052 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
4053 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
4054 IBinder service = ServiceManager.checkService(name);
4055 if (service == null) {
4056 pw.println(" (Service not found)");
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004057 pw.flush();
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004058 return;
4059 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004060 pw.flush();
4061 if (service instanceof Binder) {
4062 // If this is a local object, it doesn't make sense to do an async dump with it,
4063 // just directly dump.
4064 try {
4065 service.dump(fd, args);
4066 } catch (Throwable e) {
4067 pw.println("Failure dumping service:");
4068 e.printStackTrace(pw);
4069 pw.flush();
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004070 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004071 } else {
4072 // Otherwise, it is remote, do the dump asynchronously to avoid blocking.
4073 TransferPipe tp = null;
4074 try {
4075 pw.flush();
4076 tp = new TransferPipe();
4077 tp.setBufferPrefix(" ");
4078 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
4079 tp.go(fd, 10000);
4080 } catch (Throwable e) {
4081 if (tp != null) {
4082 tp.kill();
4083 }
4084 pw.println("Failure dumping service:");
4085 e.printStackTrace(pw);
4086 }
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004087 }
4088 }
Craig Mautneraea74a52014-03-08 14:23:10 -08004089
4090 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004091 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07004092 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004093 * sees the associated process with a larger pss size and, when this happens, automatically
4094 * pull a heap dump from it and allow the user to share the data. Note that this request
4095 * continues running even if the process is killed and restarted. To remove the watch,
4096 * use {@link #clearWatchHeapLimit()}.
4097 *
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07004098 * <p>This API only work if the calling process has been marked as
4099 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
4100 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004101 *
4102 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
4103 * handle heap limit reports themselves.</p>
4104 *
4105 * @param pssSize The size in bytes to set the limit at.
4106 */
4107 public void setWatchHeapLimit(long pssSize) {
4108 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004109 getService().setDumpHeapDebugLimit(null, 0, pssSize,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004110 mContext.getPackageName());
4111 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004112 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004113 }
4114 }
4115
4116 /**
4117 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
4118 * If your package has an activity handling this action, it will be launched with the
4119 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
4120 * match the activty must support this action and a MIME type of "*&#47;*".
4121 */
4122 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
4123
4124 /**
4125 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
4126 */
4127 public void clearWatchHeapLimit() {
4128 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004129 getService().setDumpHeapDebugLimit(null, 0, 0, null);
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004130 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004131 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004132 }
4133 }
4134
4135 /**
Jason Monk386c94f2014-07-14 16:42:24 -04004136 * Return whether currently in lock task mode. When in this mode
4137 * no new tasks can be created or switched to.
4138 *
4139 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00004140 *
4141 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08004142 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004143 @Deprecated
Craig Mautneraea74a52014-03-08 14:23:10 -08004144 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00004145 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
4146 }
4147
4148 /**
4149 * Return the current state of task locking. The three possible outcomes
4150 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
4151 * and {@link #LOCK_TASK_MODE_PINNED}.
4152 *
4153 * @see Activity#startLockTask()
4154 */
4155 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08004156 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004157 return getService().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08004158 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004159 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004160 }
4161 }
Winson Chung1147c402014-05-14 11:05:00 -07004162
4163 /**
Srinath Sridharane535a582016-06-27 18:13:47 -07004164 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one
4165 * thread can be a VR thread in a process at a time, and that thread may be subject to
4166 * restrictions on the amount of time it can run.
4167 *
Craig Donnerdc4796c2017-03-08 09:51:47 -08004168 * If persistent VR mode is set, whatever thread has been granted aggressive scheduling via this
4169 * method will return to normal operation, and calling this method will do nothing while
4170 * persistent VR mode is enabled.
4171 *
Srinath Sridharane535a582016-06-27 18:13:47 -07004172 * To reset the VR thread for an application, a tid of 0 can be passed.
4173 *
4174 * @see android.os.Process#myTid()
4175 * @param tid tid of the VR thread
4176 */
4177 public static void setVrThread(int tid) {
4178 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004179 getService().setVrThread(tid);
Srinath Sridharane535a582016-06-27 18:13:47 -07004180 } catch (RemoteException e) {
4181 // pass
4182 }
4183 }
4184
4185 /**
Craig Donnerdc4796c2017-03-08 09:51:47 -08004186 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads that persist
Jeff Sharkey910e0812017-04-21 16:29:27 -06004187 * beyond a single process. Only one thread can be a
Craig Donnerdc4796c2017-03-08 09:51:47 -08004188 * persistent VR thread at a time, and that thread may be subject to restrictions on the amount
4189 * of time it can run. Calling this method will disable aggressive scheduling for non-persistent
4190 * VR threads set via {@link #setVrThread}. If persistent VR mode is disabled then the
4191 * persistent VR thread loses its new scheduling priority; this method must be called again to
4192 * set the persistent thread.
4193 *
4194 * To reset the persistent VR thread, a tid of 0 can be passed.
4195 *
4196 * @see android.os.Process#myTid()
4197 * @param tid tid of the VR thread
4198 * @hide
4199 */
4200 @RequiresPermission(Manifest.permission.RESTRICTED_VR_ACCESS)
4201 public static void setPersistentVrThread(int tid) {
4202 try {
4203 getService().setPersistentVrThread(tid);
4204 } catch (RemoteException e) {
4205 // pass
4206 }
4207 }
4208
4209 /**
Winson Chung1147c402014-05-14 11:05:00 -07004210 * The AppTask allows you to manage your own application's tasks.
4211 * See {@link android.app.ActivityManager#getAppTasks()}
4212 */
4213 public static class AppTask {
4214 private IAppTask mAppTaskImpl;
4215
4216 /** @hide */
4217 public AppTask(IAppTask task) {
4218 mAppTaskImpl = task;
4219 }
4220
4221 /**
4222 * Finishes all activities in this task and removes it from the recent tasks list.
4223 */
4224 public void finishAndRemoveTask() {
4225 try {
4226 mAppTaskImpl.finishAndRemoveTask();
4227 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004228 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004229 }
4230 }
4231
4232 /**
4233 * Get the RecentTaskInfo associated with this task.
4234 *
4235 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
4236 */
4237 public RecentTaskInfo getTaskInfo() {
4238 try {
4239 return mAppTaskImpl.getTaskInfo();
4240 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004241 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004242 }
4243 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004244
4245 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004246 * Bring this task to the foreground. If it contains activities, they will be
4247 * brought to the foreground with it and their instances re-created if needed.
4248 * If it doesn't contain activities, the root activity of the task will be
4249 * re-launched.
4250 */
4251 public void moveToFront() {
4252 try {
4253 mAppTaskImpl.moveToFront();
4254 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004255 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004256 }
4257 }
4258
4259 /**
4260 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004261 * is not currently active (that is, its id < 0), then a new activity for the given
4262 * Intent will be launched as the root of the task and the task brought to the
4263 * foreground. Otherwise, if this task is currently active and the Intent does not specify
4264 * an activity to launch in a new task, then a new activity for the given Intent will
4265 * be launched on top of the task and the task brought to the foreground. If this
4266 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
4267 * or would otherwise be launched in to a new task, then the activity not launched but
4268 * this task be brought to the foreground and a new intent delivered to the top
4269 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004270 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004271 * <p>In other words, you generally want to use an Intent here that does not specify
4272 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
4273 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004274 *
4275 * @param intent The Intent describing the new activity to be launched on the task.
4276 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004277 *
4278 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004279 */
4280 public void startActivity(Context context, Intent intent, Bundle options) {
4281 ActivityThread thread = ActivityThread.currentActivityThread();
4282 thread.getInstrumentation().execStartActivityFromAppTask(context,
4283 thread.getApplicationThread(), mAppTaskImpl, intent, options);
4284 }
4285
4286 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004287 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
4288 * Intent of this AppTask.
4289 *
4290 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
4291 * be set; otherwise, it will be cleared.
4292 */
4293 public void setExcludeFromRecents(boolean exclude) {
4294 try {
4295 mAppTaskImpl.setExcludeFromRecents(exclude);
4296 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004297 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004298 }
4299 }
Winson Chung1147c402014-05-14 11:05:00 -07004300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301}