blob: 1931acf20bd125999f060378a301de15e8efb186 [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;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080031import android.content.UriPermission;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070032import android.content.pm.ActivityInfo;
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -070033import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.content.pm.ConfigurationInfo;
35import android.content.pm.IPackageDataObserver;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070036import android.content.pm.PackageManager;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080037import android.content.pm.ParceledListSlice;
Dianne Hackborn41203752012-08-31 14:05:51 -070038import android.content.pm.UserInfo;
Wale Ogunwale68278562017-09-23 17:13:55 -070039import android.content.res.Configuration;
Kenny Root5ef44b72011-01-26 17:22:20 -080040import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.graphics.Bitmap;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070042import android.graphics.Canvas;
Winson Chunga449dc02014-05-16 11:15:04 -070043import android.graphics.Color;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070044import android.graphics.GraphicBuffer;
45import android.graphics.Matrix;
46import android.graphics.Point;
Craig Mautner967212c2013-04-13 21:10:58 -070047import android.graphics.Rect;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070048import android.os.BatteryStats;
Dianne Hackbornc81983a2017-10-20 16:16:32 -070049import android.os.Binder;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070050import android.os.Build;
51import android.os.Build.VERSION_CODES;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070052import android.os.Bundle;
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -070053import android.os.Debug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.Handler;
Wale Ogunwalec981ad52017-06-13 11:40:06 -070055import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.os.Parcel;
57import android.os.Parcelable;
Dianne Hackborn5320eb82012-05-18 12:05:04 -070058import android.os.Process;
Amith Yamasani4b2e9342011-03-31 12:38:53 -070059import android.os.RemoteException;
Peter Visontay8d224ca2011-02-18 16:39:19 +000060import android.os.ServiceManager;
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -070061import android.os.SystemProperties;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070062import android.os.UserHandle;
Narayan Kamath695cf722017-12-21 18:32:47 +000063import android.os.WorkSource;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064import android.text.TextUtils;
Dianne Hackborn058f1e42016-11-02 17:18:35 -070065import android.util.ArrayMap;
Kenny Root5ef44b72011-01-26 17:22:20 -080066import android.util.DisplayMetrics;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070067import android.util.Singleton;
Winson Chung48a10a52014-08-27 14:36:51 -070068import android.util.Size;
Felipe Lemef3fa0f82016-01-07 12:08:19 -080069
Wale Ogunwalec981ad52017-06-13 11:40:06 -070070import com.android.internal.app.procstats.ProcessStats;
71import com.android.internal.os.RoSystemProperties;
72import com.android.internal.os.TransferPipe;
73import com.android.internal.util.FastPrintWriter;
74import com.android.server.LocalServices;
75
Craig Mautner648f69b2014-09-18 14:16:26 -070076import org.xmlpull.v1.XmlSerializer;
Kenny Root5ef44b72011-01-26 17:22:20 -080077
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070078import java.io.FileDescriptor;
79import java.io.FileOutputStream;
Craig Mautner648f69b2014-09-18 14:16:26 -070080import java.io.IOException;
Dianne Hackborncbfd23e2013-06-11 14:26:53 -070081import java.io.PrintWriter;
Michal Karpinski3da5c972015-12-11 18:16:30 +000082import java.lang.annotation.Retention;
83import java.lang.annotation.RetentionPolicy;
Winson Chung1147c402014-05-14 11:05:00 -070084import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085import java.util.List;
86
87/**
Dave Friedman2a3ebad2017-01-04 18:27:26 -080088 * <p>
89 * This class gives information about, and interacts
90 * with, activities, services, and the containing
91 * process.
92 * </p>
93 *
94 * <p>
95 * A number of the methods in this class are for
96 * debugging or informational purposes and they should
97 * not be used to affect any runtime behavior of
98 * your app. These methods are called out as such in
99 * the method level documentation.
100 * </p>
101 *
102 *<p>
103 * Most application developers should not have the need to
104 * use this class, most of whose methods are for specialized
105 * use cases. However, a few methods are more broadly applicable.
106 * For instance, {@link android.app.ActivityManager#isLowRamDevice() isLowRamDevice()}
107 * enables your app to detect whether it is running on a low-memory device,
108 * and behave accordingly.
109 * {@link android.app.ActivityManager#clearApplicationUserData() clearApplicationUserData()}
110 * is for apps with reset-data functionality.
111 * </p>
112 *
113 * <p>
114 * In some special use cases, where an app interacts with
115 * its Task stack, the app may use the
116 * {@link android.app.ActivityManager.AppTask} and
117 * {@link android.app.ActivityManager.RecentTaskInfo} inner
118 * classes. However, in general, the methods in this class should
119 * be used for testing and debugging purposes only.
120 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -0600122@SystemService(Context.ACTIVITY_SERVICE)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123public class ActivityManager {
124 private static String TAG = "ActivityManager";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125
Dianne Hackborn852975d2014-08-22 17:42:43 -0700126 private static int gMaxRecentTasks = -1;
127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 private final Context mContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800130 private static volatile boolean sSystemReady = false;
131
Bryce Lee7f936862017-05-09 15:33:18 -0700132
133 private static final int FIRST_START_FATAL_ERROR_CODE = -100;
134 private static final int LAST_START_FATAL_ERROR_CODE = -1;
135 private static final int FIRST_START_SUCCESS_CODE = 0;
136 private static final int LAST_START_SUCCESS_CODE = 99;
137 private static final int FIRST_START_NON_FATAL_ERROR_CODE = 100;
138 private static final int LAST_START_NON_FATAL_ERROR_CODE = 199;
139
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700140 static final class UidObserver extends IUidObserver.Stub {
141 final OnUidImportanceListener mListener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700142 final Context mContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700143
Makoto Onukid7e40582017-04-13 14:54:56 -0700144 UidObserver(OnUidImportanceListener listener, Context clientContext) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700145 mListener = listener;
Makoto Onukid7e40582017-04-13 14:54:56 -0700146 mContext = clientContext;
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700147 }
148
149 @Override
Sudheer Shanka80255802017-03-04 14:48:53 -0800150 public void onUidStateChanged(int uid, int procState, long procStateSeq) {
Makoto Onukid7e40582017-04-13 14:54:56 -0700151 mListener.onUidImportance(uid, RunningAppProcessInfo.procStateToImportanceForClient(
152 procState, mContext));
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700153 }
154
155 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800156 public void onUidGone(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700157 mListener.onUidImportance(uid, RunningAppProcessInfo.IMPORTANCE_GONE);
158 }
159
160 @Override
161 public void onUidActive(int uid) {
162 }
163
164 @Override
Dianne Hackborne07641d2016-11-09 15:07:23 -0800165 public void onUidIdle(int uid, boolean disabled) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700166 }
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700167
168 @Override public void onUidCachedChanged(int uid, boolean cached) {
169 }
Dianne Hackborn058f1e42016-11-02 17:18:35 -0700170 }
171
172 final ArrayMap<OnUidImportanceListener, UidObserver> mImportanceListeners = new ArrayMap<>();
173
Felipe Lemedc7af962016-01-22 18:27:03 -0800174 /**
175 * Defines acceptable types of bugreports.
176 * @hide
177 */
Michal Karpinski3da5c972015-12-11 18:16:30 +0000178 @Retention(RetentionPolicy.SOURCE)
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700179 @IntDef(prefix = { "BUGREPORT_OPTION_" }, value = {
Michal Karpinski3da5c972015-12-11 18:16:30 +0000180 BUGREPORT_OPTION_FULL,
181 BUGREPORT_OPTION_INTERACTIVE,
Wei Liu967fc8d2016-07-08 11:44:20 -0700182 BUGREPORT_OPTION_REMOTE,
Felipe Leme9606c3b2017-01-05 14:57:12 -0800183 BUGREPORT_OPTION_WEAR,
184 BUGREPORT_OPTION_TELEPHONY
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 /**
Scott Maincc2195b2013-10-16 13:57:46 -0700219 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000220 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be
Christopher Tatebd413f62013-09-18 18:31:59 -0700221 * uninstalled in lieu of the declaring one. The package named here must be
Neil Fuller71fbb812015-11-30 09:51:33 +0000222 * signed with the same certificate as the one declaring the {@code <meta-data>}.
Christopher Tatebd413f62013-09-18 18:31:59 -0700223 */
224 public static final String META_HOME_ALTERNATE = "android.app.home.alternate";
225
Bryce Lee7f936862017-05-09 15:33:18 -0700226 // NOTE: Before adding a new start result, please reference the defined ranges to ensure the
227 // result is properly categorized.
228
Christopher Tatebd413f62013-09-18 18:31:59 -0700229 /**
Amith Yamasani42449782016-04-19 11:45:51 -0700230 * Result for IActivityManager.startVoiceActivity: active session is currently hidden.
231 * @hide
232 */
Bryce Lee7f936862017-05-09 15:33:18 -0700233 public static final int START_VOICE_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE;
Amith Yamasani42449782016-04-19 11:45:51 -0700234
235 /**
236 * Result for IActivityManager.startVoiceActivity: active session does not match
237 * the requesting token.
238 * @hide
239 */
Bryce Lee7f936862017-05-09 15:33:18 -0700240 public static final int START_VOICE_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 1;
Amith Yamasani42449782016-04-19 11:45:51 -0700241
242 /**
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700243 * Result for IActivityManager.startActivity: trying to start a background user
244 * activity that shouldn't be displayed for all users.
245 * @hide
246 */
Bryce Lee7f936862017-05-09 15:33:18 -0700247 public static final int START_NOT_CURRENT_USER_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 2;
Wale Ogunwale0bd2aa72015-04-16 13:50:44 -0700248
249 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700250 * Result for IActivityManager.startActivity: trying to start an activity under voice
251 * control when that activity does not support the VOICE category.
252 * @hide
253 */
Bryce Lee7f936862017-05-09 15:33:18 -0700254 public static final int START_NOT_VOICE_COMPATIBLE = FIRST_START_FATAL_ERROR_CODE + 3;
Dianne Hackborn91097de2014-04-04 18:02:06 -0700255
256 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700257 * Result for IActivityManager.startActivity: an error where the
258 * start had to be canceled.
259 * @hide
260 */
Bryce Lee7f936862017-05-09 15:33:18 -0700261 public static final int START_CANCELED = FIRST_START_FATAL_ERROR_CODE + 4;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700262
263 /**
264 * Result for IActivityManager.startActivity: an error where the
265 * thing being started is not an activity.
266 * @hide
267 */
Bryce Lee7f936862017-05-09 15:33:18 -0700268 public static final int START_NOT_ACTIVITY = FIRST_START_FATAL_ERROR_CODE + 5;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700269
270 /**
271 * Result for IActivityManager.startActivity: an error where the
272 * caller does not have permission to start the activity.
273 * @hide
274 */
Bryce Lee7f936862017-05-09 15:33:18 -0700275 public static final int START_PERMISSION_DENIED = FIRST_START_FATAL_ERROR_CODE + 6;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700276
277 /**
278 * Result for IActivityManager.startActivity: an error where the
279 * caller has requested both to forward a result and to receive
280 * a result.
281 * @hide
282 */
Bryce Lee7f936862017-05-09 15:33:18 -0700283 public static final int START_FORWARD_AND_REQUEST_CONFLICT = FIRST_START_FATAL_ERROR_CODE + 7;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700284
285 /**
286 * Result for IActivityManager.startActivity: an error where the
287 * requested class is not found.
288 * @hide
289 */
Bryce Lee7f936862017-05-09 15:33:18 -0700290 public static final int START_CLASS_NOT_FOUND = FIRST_START_FATAL_ERROR_CODE + 8;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700291
292 /**
293 * Result for IActivityManager.startActivity: an error where the
294 * given Intent could not be resolved to an activity.
295 * @hide
296 */
Bryce Lee7f936862017-05-09 15:33:18 -0700297 public static final int START_INTENT_NOT_RESOLVED = FIRST_START_FATAL_ERROR_CODE + 9;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700298
299 /**
Winson Chungfc3ec4c2017-06-01 15:35:48 -0700300 * Result for IActivityManager.startAssistantActivity: active session is currently hidden.
301 * @hide
302 */
303 public static final int START_ASSISTANT_HIDDEN_SESSION = FIRST_START_FATAL_ERROR_CODE + 10;
304
305 /**
306 * Result for IActivityManager.startAssistantActivity: active session does not match
307 * the requesting token.
308 * @hide
309 */
310 public static final int START_ASSISTANT_NOT_ACTIVE_SESSION = FIRST_START_FATAL_ERROR_CODE + 11;
311
312 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700313 * Result for IActivityManaqer.startActivity: the activity was started
314 * successfully as normal.
315 * @hide
316 */
Bryce Lee7f936862017-05-09 15:33:18 -0700317 public static final int START_SUCCESS = FIRST_START_SUCCESS_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700318
319 /**
320 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not
321 * be executed if it is the recipient, and that is indeed the case.
322 * @hide
323 */
Bryce Lee7f936862017-05-09 15:33:18 -0700324 public static final int START_RETURN_INTENT_TO_CALLER = FIRST_START_SUCCESS_CODE + 1;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700325
326 /**
327 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
328 * a task was simply brought to the foreground.
329 * @hide
330 */
Bryce Lee7f936862017-05-09 15:33:18 -0700331 public static final int START_TASK_TO_FRONT = FIRST_START_SUCCESS_CODE + 2;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700332
333 /**
334 * Result for IActivityManaqer.startActivity: activity wasn't really started, but
335 * the given Intent was given to the existing top activity.
336 * @hide
337 */
Bryce Lee7f936862017-05-09 15:33:18 -0700338 public static final int START_DELIVERED_TO_TOP = FIRST_START_SUCCESS_CODE + 3;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700339
340 /**
341 * Result for IActivityManaqer.startActivity: request was canceled because
342 * app switches are temporarily canceled to ensure the user's last request
343 * (such as pressing home) is performed.
344 * @hide
345 */
Bryce Lee7f936862017-05-09 15:33:18 -0700346 public static final int START_SWITCHES_CANCELED = FIRST_START_NON_FATAL_ERROR_CODE;
Dianne Hackborna4972e92012-03-14 10:38:05 -0700347
348 /**
Craig Mautneraea74a52014-03-08 14:23:10 -0800349 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started
350 * while in Lock Task Mode.
351 * @hide
352 */
Bryce Lee7f936862017-05-09 15:33:18 -0700353 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION =
354 FIRST_START_NON_FATAL_ERROR_CODE + 1;
Craig Mautneraea74a52014-03-08 14:23:10 -0800355
356 /**
Bryce Leef9d49542017-06-26 16:27:32 -0700357 * Result for IActivityManaqer.startActivity: a new activity start was aborted. Never returned
358 * externally.
359 * @hide
360 */
361 public static final int START_ABORTED = FIRST_START_NON_FATAL_ERROR_CODE + 2;
362
363 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700364 * Flag for IActivityManaqer.startActivity: do special start mode where
365 * a new activity is launched only if it is needed.
366 * @hide
367 */
368 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0;
369
370 /**
371 * Flag for IActivityManaqer.startActivity: launch the app for
372 * debugging.
373 * @hide
374 */
375 public static final int START_FLAG_DEBUG = 1<<1;
376
377 /**
378 * Flag for IActivityManaqer.startActivity: launch the app for
Man Caocfa78b22015-06-11 20:14:34 -0700379 * allocation tracking.
380 * @hide
381 */
Pablo Ceballosa4d4e822015-10-05 10:27:52 -0700382 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2;
Man Caocfa78b22015-06-11 20:14:34 -0700383
384 /**
Tamas Berghammerdf6cb282016-01-29 12:07:00 +0000385 * Flag for IActivityManaqer.startActivity: launch the app with
386 * native debugging support.
387 * @hide
388 */
389 public static final int START_FLAG_NATIVE_DEBUGGING = 1<<3;
390
391 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700392 * Result for IActivityManaqer.broadcastIntent: success!
393 * @hide
394 */
395 public static final int BROADCAST_SUCCESS = 0;
396
397 /**
398 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast
399 * a sticky intent without appropriate permission.
400 * @hide
401 */
402 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1;
403
404 /**
Amith Yamasani83b6ef02014-11-07 15:34:04 -0800405 * Result for IActivityManager.broadcastIntent: trying to send a broadcast
406 * to a stopped user. Fail.
407 * @hide
408 */
409 public static final int BROADCAST_FAILED_USER_STOPPED = -2;
410
411 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700412 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
413 * for a sendBroadcast operation.
414 * @hide
415 */
416 public static final int INTENT_SENDER_BROADCAST = 1;
417
418 /**
419 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
420 * for a startActivity operation.
421 * @hide
422 */
423 public static final int INTENT_SENDER_ACTIVITY = 2;
424
425 /**
426 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
427 * for an activity result operation.
428 * @hide
429 */
430 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
431
432 /**
433 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
434 * for a startService operation.
435 * @hide
436 */
437 public static final int INTENT_SENDER_SERVICE = 4;
438
Christopher Tate08992ac2017-03-21 11:37:06 -0700439 /**
440 * Type for IActivityManaqer.getIntentSender: this PendingIntent is
441 * for a startForegroundService operation.
442 * @hide
443 */
444 public static final int INTENT_SENDER_FOREGROUND_SERVICE = 5;
445
Geoffrey Pitsch88f3d4d2017-11-22 13:31:11 -0500446 /**
447 * Extra included on intents that are delegating the call to
448 * ActivityManager#startActivityAsCaller to another app. This token is necessary for that call
449 * to succeed. Type is IBinder.
450 * @hide
451 */
452 public static final String EXTRA_PERMISSION_TOKEN = "android.app.extra.PERMISSION_TOKEN";
453
454 /**
455 * Extra included on intents that contain an EXTRA_INTENT, with options that the contained
456 * intent may want to be started with. Type is Bundle.
457 * TODO: remove once the ChooserActivity moves to systemui
458 * @hide
459 */
460 public static final String EXTRA_OPTIONS = "android.app.extra.OPTIONS";
461
462 /**
463 * Extra included on intents that contain an EXTRA_INTENT, use this boolean value for the
464 * parameter of the same name when starting the contained intent.
465 * TODO: remove once the ChooserActivity moves to systemui
466 * @hide
467 */
468 public static final String EXTRA_IGNORE_TARGET_SECURITY =
469 "android.app.extra.EXTRA_IGNORE_TARGET_SECURITY";
470
Dianne Hackborn80a4af22012-08-27 19:18:31 -0700471 /** @hide User operation call: success! */
472 public static final int USER_OP_SUCCESS = 0;
473
474 /** @hide User operation call: given user id is not known. */
475 public static final int USER_OP_UNKNOWN_USER = -1;
476
477 /** @hide User operation call: given user id is the current user, can't be stopped. */
478 public static final int USER_OP_IS_CURRENT = -2;
479
Fyodor Kupolov9cbfc9e2015-10-07 15:52:33 -0700480 /** @hide User operation call: system user can't be stopped. */
481 public static final int USER_OP_ERROR_IS_SYSTEM = -3;
482
483 /** @hide User operation call: one of related users cannot be stopped. */
484 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4;
485
Dianne Hackbornf097d422017-12-15 16:32:19 -0800486 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800487 * @hide
Dianne Hackbornf097d422017-12-15 16:32:19 -0800488 * Process states, describing the kind of state a particular process is in.
489 * When updating these, make sure to also check all related references to the
490 * constant in code, and update these arrays:
491 *
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800492 * @see com.android.internal.app.procstats.ProcessState#PROCESS_STATE_TO_STATE
493 * @see com.android.server.am.ProcessList#sProcStateToProcMem
494 * @see com.android.server.am.ProcessList#sFirstAwakePssTimes
495 * @see com.android.server.am.ProcessList#sSameAwakePssTimes
496 * @see com.android.server.am.ProcessList#sTestFirstPssTimes
497 * @see com.android.server.am.ProcessList#sTestSamePssTimes
Dianne Hackbornf097d422017-12-15 16:32:19 -0800498 */
499
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800500 /** @hide Not a real process state. */
501 public static final int PROCESS_STATE_UNKNOWN = -1;
Ruben Brunka27eef42015-01-28 15:04:16 -0800502
Dianne Hackborna413dc02013-07-12 12:02:55 -0700503 /** @hide Process is a persistent system process. */
504 public static final int PROCESS_STATE_PERSISTENT = 0;
505
506 /** @hide Process is a persistent system process and is doing UI. */
507 public static final int PROCESS_STATE_PERSISTENT_UI = 1;
508
Dianne Hackbornc8230512013-07-13 21:32:12 -0700509 /** @hide Process is hosting the current top activities. Note that this covers
510 * all activities that are visible to the user. */
Dianne Hackborna413dc02013-07-12 12:02:55 -0700511 public static final int PROCESS_STATE_TOP = 2;
512
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700513 /** @hide Process is hosting a foreground service. */
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -0800514 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 3;
515
516 /** @hide Process is hosting a foreground service due to a system binding. */
517 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 4;
Dianne Hackborn4870e9d2015-04-08 16:55:47 -0700518
Dianne Hackborna413dc02013-07-12 12:02:55 -0700519 /** @hide Process is important to the user, and something they are aware of. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800520 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 5;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700521
522 /** @hide Process is important to the user, but not something they are aware of. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800523 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 6;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700524
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700525 /** @hide Process is in the background transient so we will try to keep running. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800526 public static final int PROCESS_STATE_TRANSIENT_BACKGROUND = 7;
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700527
Dianne Hackborna413dc02013-07-12 12:02:55 -0700528 /** @hide Process is in the background running a backup/restore operation. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800529 public static final int PROCESS_STATE_BACKUP = 8;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700530
Dianne Hackbornc8230512013-07-13 21:32:12 -0700531 /** @hide Process is in the background running a service. Unlike oom_adj, this level
532 * is used for both the normal running in background state and the executing
533 * operations state. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800534 public static final int PROCESS_STATE_SERVICE = 9;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700535
Dianne Hackbornc8230512013-07-13 21:32:12 -0700536 /** @hide Process is in the background running a receiver. Note that from the
Kweku Adamse6b00c22017-10-23 16:46:45 -0700537 * perspective of oom_adj, receivers run at a higher foreground level, but for our
Dianne Hackbornc8230512013-07-13 21:32:12 -0700538 * prioritization here that is not necessary and putting them below services means
539 * many fewer changes in some process states as they receive broadcasts. */
Dianne Hackbornbad8d912017-12-18 16:45:52 -0800540 public static final int PROCESS_STATE_RECEIVER = 10;
541
542 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */
543 public static final int PROCESS_STATE_TOP_SLEEPING = 11;
Dianne Hackbornf097d422017-12-15 16:32:19 -0800544
545 /** @hide Process is in the background, but it can't restore its state so we want
546 * to try to avoid killing it. */
547 public static final int PROCESS_STATE_HEAVY_WEIGHT = 12;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700548
Dianne Hackborna413dc02013-07-12 12:02:55 -0700549 /** @hide Process is in the background but hosts the home activity. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700550 public static final int PROCESS_STATE_HOME = 13;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700551
552 /** @hide Process is in the background but hosts the last shown activity. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700553 public static final int PROCESS_STATE_LAST_ACTIVITY = 14;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700554
Dianne Hackbornc8230512013-07-13 21:32:12 -0700555 /** @hide Process is being cached for later use and contains activities. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700556 public static final int PROCESS_STATE_CACHED_ACTIVITY = 15;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700557
558 /** @hide Process is being cached for later use and is a client of another cached
559 * process that contains activities. */
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700560 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 16;
Dianne Hackbornc8230512013-07-13 21:32:12 -0700561
Dianne Hackborn68a06332017-11-15 17:54:18 -0800562 /** @hide Process is being cached for later use and has an activity that corresponds
563 * to an existing recent task. */
564 public static final int PROCESS_STATE_CACHED_RECENT = 17;
565
Dianne Hackbornc8230512013-07-13 21:32:12 -0700566 /** @hide Process is being cached for later use and is empty. */
Dianne Hackborn68a06332017-11-15 17:54:18 -0800567 public static final int PROCESS_STATE_CACHED_EMPTY = 18;
Dianne Hackborna413dc02013-07-12 12:02:55 -0700568
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800569 /** @hide Process does not exist. */
Dianne Hackborn68a06332017-11-15 17:54:18 -0800570 public static final int PROCESS_STATE_NONEXISTENT = 19;
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800571
Bookatzdb026a22018-01-10 19:01:56 -0800572 // NOTE: If PROCESS_STATEs are added, then new fields must be added
573 // to frameworks/base/core/proto/android/app/enums.proto and the following method must
Kweku Adamse6b00c22017-10-23 16:46:45 -0700574 // be updated to correctly map between them.
Bookatzdb026a22018-01-10 19:01:56 -0800575 // However, if the current ActivityManager values are merely modified, no update should be made
576 // to enums.proto, to which values can only be added but never modified. Note that the proto
577 // versions do NOT have the ordering restrictions of the ActivityManager process state.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700578 /**
Bookatzdb026a22018-01-10 19:01:56 -0800579 * Maps ActivityManager.PROCESS_STATE_ values to enums.proto ProcessStateEnum value.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700580 *
581 * @param amInt a process state of the form ActivityManager.PROCESS_STATE_
Bookatzdb026a22018-01-10 19:01:56 -0800582 * @return the value of the corresponding enums.proto ProcessStateEnum value.
Kweku Adamse6b00c22017-10-23 16:46:45 -0700583 * @hide
584 */
585 public static final int processStateAmToProto(int amInt) {
Bookatzdb026a22018-01-10 19:01:56 -0800586 switch (amInt) {
587 case PROCESS_STATE_UNKNOWN:
588 return AppProtoEnums.PROCESS_STATE_UNKNOWN;
589 case PROCESS_STATE_PERSISTENT:
590 return AppProtoEnums.PROCESS_STATE_PERSISTENT;
591 case PROCESS_STATE_PERSISTENT_UI:
592 return AppProtoEnums.PROCESS_STATE_PERSISTENT_UI;
593 case PROCESS_STATE_TOP:
594 return AppProtoEnums.PROCESS_STATE_TOP;
595 case PROCESS_STATE_FOREGROUND_SERVICE:
596 return AppProtoEnums.PROCESS_STATE_FOREGROUND_SERVICE;
597 case PROCESS_STATE_BOUND_FOREGROUND_SERVICE:
598 return AppProtoEnums.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
599 case PROCESS_STATE_IMPORTANT_FOREGROUND:
600 return AppProtoEnums.PROCESS_STATE_IMPORTANT_FOREGROUND;
601 case PROCESS_STATE_IMPORTANT_BACKGROUND:
602 return AppProtoEnums.PROCESS_STATE_IMPORTANT_BACKGROUND;
603 case PROCESS_STATE_TRANSIENT_BACKGROUND:
604 return AppProtoEnums.PROCESS_STATE_TRANSIENT_BACKGROUND;
605 case PROCESS_STATE_BACKUP:
606 return AppProtoEnums.PROCESS_STATE_BACKUP;
607 case PROCESS_STATE_SERVICE:
608 return AppProtoEnums.PROCESS_STATE_SERVICE;
609 case PROCESS_STATE_RECEIVER:
610 return AppProtoEnums.PROCESS_STATE_RECEIVER;
611 case PROCESS_STATE_TOP_SLEEPING:
612 return AppProtoEnums.PROCESS_STATE_TOP_SLEEPING;
613 case PROCESS_STATE_HEAVY_WEIGHT:
614 return AppProtoEnums.PROCESS_STATE_HEAVY_WEIGHT;
615 case PROCESS_STATE_HOME:
616 return AppProtoEnums.PROCESS_STATE_HOME;
617 case PROCESS_STATE_LAST_ACTIVITY:
618 return AppProtoEnums.PROCESS_STATE_LAST_ACTIVITY;
619 case PROCESS_STATE_CACHED_ACTIVITY:
620 return AppProtoEnums.PROCESS_STATE_CACHED_ACTIVITY;
621 case PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
622 return AppProtoEnums.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
623 case PROCESS_STATE_CACHED_RECENT:
624 return AppProtoEnums.PROCESS_STATE_CACHED_RECENT;
625 case PROCESS_STATE_CACHED_EMPTY:
626 return AppProtoEnums.PROCESS_STATE_CACHED_EMPTY;
627 case PROCESS_STATE_NONEXISTENT:
628 return AppProtoEnums.PROCESS_STATE_NONEXISTENT;
629 default:
630 // ActivityManager process state (amInt)
631 // could not be mapped to an AppProtoEnums ProcessState state.
632 return AppProtoEnums.PROCESS_STATE_UNKNOWN_TO_PROTO;
633 }
Kweku Adamse6b00c22017-10-23 16:46:45 -0700634 }
635
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700636 /** @hide The lowest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800637 public static final int MIN_PROCESS_STATE = PROCESS_STATE_PERSISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700638
639 /** @hide The highest process state number */
Dianne Hackborn5614bf52016-11-07 17:26:41 -0800640 public static final int MAX_PROCESS_STATE = PROCESS_STATE_NONEXISTENT;
Joe Onorato05c9ecc2016-03-30 15:13:46 -0700641
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700642 /** @hide Should this process state be considered a background state? */
643 public static final boolean isProcStateBackground(int procState) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700644 return procState >= PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700645 }
646
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700647 /** @hide requestType for assist context: only basic information. */
648 public static final int ASSIST_CONTEXT_BASIC = 0;
649
650 /** @hide requestType for assist context: generate full AssistStructure. */
651 public static final int ASSIST_CONTEXT_FULL = 1;
652
Felipe Leme640f30a2017-03-06 15:44:06 -0800653 /** @hide requestType for assist context: generate full AssistStructure for autofill. */
654 public static final int ASSIST_CONTEXT_AUTOFILL = 2;
Felipe Leme6d553872016-12-08 17:13:25 -0800655
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700656 /** @hide Flag for registerUidObserver: report changes in process state. */
657 public static final int UID_OBSERVER_PROCSTATE = 1<<0;
658
659 /** @hide Flag for registerUidObserver: report uid gone. */
660 public static final int UID_OBSERVER_GONE = 1<<1;
661
662 /** @hide Flag for registerUidObserver: report uid has become idle. */
663 public static final int UID_OBSERVER_IDLE = 1<<2;
664
665 /** @hide Flag for registerUidObserver: report uid has become active. */
666 public static final int UID_OBSERVER_ACTIVE = 1<<3;
667
Dianne Hackborn3e99f652017-07-05 16:33:56 -0700668 /** @hide Flag for registerUidObserver: report uid cached state has changed. */
669 public static final int UID_OBSERVER_CACHED = 1<<4;
670
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800671 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700672 public static final int APP_START_MODE_NORMAL = 0;
673
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800674 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later. */
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700675 public static final int APP_START_MODE_DELAYED = 1;
676
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800677 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later, with
Dianne Hackborn85e35642017-01-12 15:10:57 -0800678 * rigid errors (throwing exception). */
679 public static final int APP_START_MODE_DELAYED_RIGID = 2;
680
Dianne Hackbornc3af19a2017-01-20 17:00:44 -0800681 /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: disable/cancel pending
Dianne Hackborn85e35642017-01-12 15:10:57 -0800682 * launches; this is the mode for ephemeral apps. */
683 public static final int APP_START_MODE_DISABLED = 3;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700684
Benjamin Franz43261142015-02-11 15:59:44 +0000685 /**
686 * Lock task mode is not active.
687 */
688 public static final int LOCK_TASK_MODE_NONE = 0;
689
690 /**
691 * Full lock task mode is active.
692 */
693 public static final int LOCK_TASK_MODE_LOCKED = 1;
694
695 /**
696 * App pinning mode is active.
697 */
698 public static final int LOCK_TASK_MODE_PINNED = 2;
699
Dianne Hackbornaec68bb2014-08-20 15:25:13 -0700700 Point mAppTaskThumbnailSize;
701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 /*package*/ ActivityManager(Context context, Handler handler) {
703 mContext = context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 }
705
706 /**
Bryce Lee7f936862017-05-09 15:33:18 -0700707 * Returns whether the launch was successful.
708 * @hide
709 */
710 public static final boolean isStartResultSuccessful(int result) {
711 return FIRST_START_SUCCESS_CODE <= result && result <= LAST_START_SUCCESS_CODE;
712 }
713
714 /**
715 * Returns whether the launch result was a fatal error.
716 * @hide
717 */
718 public static final boolean isStartResultFatalError(int result) {
719 return FIRST_START_FATAL_ERROR_CODE <= result && result <= LAST_START_FATAL_ERROR_CODE;
720 }
721
722 /**
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700723 * Screen compatibility mode: the application most always run in
724 * compatibility mode.
725 * @hide
726 */
727 public static final int COMPAT_MODE_ALWAYS = -1;
728
729 /**
730 * Screen compatibility mode: the application can never run in
731 * compatibility mode.
732 * @hide
733 */
734 public static final int COMPAT_MODE_NEVER = -2;
735
736 /**
737 * Screen compatibility mode: unknown.
738 * @hide
739 */
740 public static final int COMPAT_MODE_UNKNOWN = -3;
741
742 /**
743 * Screen compatibility mode: the application currently has compatibility
744 * mode disabled.
745 * @hide
746 */
747 public static final int COMPAT_MODE_DISABLED = 0;
748
749 /**
750 * Screen compatibility mode: the application currently has compatibility
751 * mode enabled.
752 * @hide
753 */
754 public static final int COMPAT_MODE_ENABLED = 1;
755
756 /**
757 * Screen compatibility mode: request to toggle the application's
758 * compatibility mode.
759 * @hide
760 */
761 public static final int COMPAT_MODE_TOGGLE = 2;
762
Marc Hittinger17fb5962017-04-05 15:34:38 -0700763 private static final boolean DEVELOPMENT_FORCE_LOW_RAM =
764 SystemProperties.getBoolean("debug.force_low_ram", false);
765
Wale Ogunwale3797c222015-10-27 14:21:58 -0700766 /** @hide */
Steven Timotiuse597ca12017-09-05 15:46:29 -0700767 @TestApi
Wale Ogunwale3797c222015-10-27 14:21:58 -0700768 public static class StackId {
Steven Timotiuse597ca12017-09-05 15:46:29 -0700769
770 private StackId() {
771 }
772
Wale Ogunwale3797c222015-10-27 14:21:58 -0700773 /** Invalid stack ID. */
774 public static final int INVALID_STACK_ID = -1;
Chong Zhang5dcb2752015-08-18 13:50:26 -0700775
Wale Ogunwale3797c222015-10-27 14:21:58 -0700776 }
Wale Ogunwaleddc1cb22015-07-25 19:23:04 -0700777
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700778 /**
Matthew Ngbf155872017-10-27 15:24:39 -0700779 * Parameter to {@link android.app.IActivityManager#setTaskWindowingModeSplitScreenPrimary}
780 * which specifies the position of the created docked stack at the top half of the screen if
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700781 * in portrait mode or at the left half of the screen if in landscape mode.
782 * @hide
783 */
Matthew Ngf59a4132017-10-25 12:03:22 -0700784 @TestApi
Matthew Ngbf155872017-10-27 15:24:39 -0700785 public static final int SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT = 0;
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700786
787 /**
Matthew Ngbf155872017-10-27 15:24:39 -0700788 * Parameter to {@link android.app.IActivityManager#setTaskWindowingModeSplitScreenPrimary}
789 * which
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700790 * specifies the position of the created docked stack at the bottom half of the screen if
791 * in portrait mode or at the right half of the screen if in landscape mode.
792 * @hide
793 */
Matthew Ngf59a4132017-10-25 12:03:22 -0700794 @TestApi
Matthew Ngbf155872017-10-27 15:24:39 -0700795 public static final int SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT = 1;
Wale Ogunwale59a73ca2015-09-14 12:54:50 -0700796
Chong Zhang87b21722015-09-21 15:39:51 -0700797 /**
798 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700799 * that the resize doesn't need to preserve the window, and can be skipped if bounds
800 * is unchanged. This mode is used by window manager in most cases.
Chong Zhang87b21722015-09-21 15:39:51 -0700801 * @hide
802 */
803 public static final int RESIZE_MODE_SYSTEM = 0;
804
805 /**
806 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
Chong Zhang6de2ae82015-09-30 18:25:21 -0700807 * that the resize should preserve the window if possible.
Wale Ogunwale1ed0d892015-09-28 13:27:44 -0700808 * @hide
809 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700810 public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0);
Chong Zhang87b21722015-09-21 15:39:51 -0700811
812 /**
813 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
814 * that the resize should be performed even if the bounds appears unchanged.
815 * @hide
816 */
Chong Zhang6de2ae82015-09-30 18:25:21 -0700817 public static final int RESIZE_MODE_FORCED = (0x1 << 1);
818
819 /**
820 * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window
821 * manager during a screen rotation.
822 * @hide
823 */
824 public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW;
825
826 /**
827 * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the
828 * resize is due to a drag action.
829 * @hide
830 */
831 public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW;
832
833 /**
834 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates
835 * that the resize should preserve the window if possible, and should not be skipped
836 * even if the bounds is unchanged. Usually used to force a resizing when a drag action
837 * is ending.
838 * @hide
839 */
840 public static final int RESIZE_MODE_USER_FORCED =
841 RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED;
Chong Zhang87b21722015-09-21 15:39:51 -0700842
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700843 /** @hide */
844 public int getFrontActivityScreenCompatMode() {
845 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800846 return getService().getFrontActivityScreenCompatMode();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700847 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700848 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700849 }
850 }
851
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700852 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700853 public void setFrontActivityScreenCompatMode(int mode) {
854 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800855 getService().setFrontActivityScreenCompatMode(mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700856 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700857 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700858 }
859 }
860
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700861 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700862 public int getPackageScreenCompatMode(String packageName) {
863 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800864 return getService().getPackageScreenCompatMode(packageName);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700865 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700866 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700867 }
868 }
869
Dianne Hackborndf9799f2011-05-12 15:16:33 -0700870 /** @hide */
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700871 public void setPackageScreenCompatMode(String packageName, int mode) {
872 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800873 getService().setPackageScreenCompatMode(packageName, mode);
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700874 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700875 throw e.rethrowFromSystemServer();
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700876 }
877 }
878
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700879 /** @hide */
880 public boolean getPackageAskScreenCompat(String packageName) {
881 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800882 return getService().getPackageAskScreenCompat(packageName);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700883 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700884 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700885 }
886 }
887
888 /** @hide */
889 public void setPackageAskScreenCompat(String packageName, boolean ask) {
890 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800891 getService().setPackageAskScreenCompat(packageName, ask);
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700892 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -0700893 throw e.rethrowFromSystemServer();
Dianne Hackborn36cd41f2011-05-25 21:00:46 -0700894 }
895 }
896
Dianne Hackborn0f1de9a2011-05-11 17:34:49 -0700897 /**
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700898 * Return the approximate per-application memory class of the current
899 * device. This gives you an idea of how hard a memory limit you should
900 * impose on your application to let the overall system work best. The
901 * returned value is in megabytes; the baseline Android memory class is
902 * 16 (which happens to be the Java heap limit of those devices); some
Kweku Adams983829f2017-12-06 14:53:50 -0800903 * devices with more memory may return 24 or even higher numbers.
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700904 */
905 public int getMemoryClass() {
906 return staticGetMemoryClass();
907 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700908
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700909 /** @hide */
910 static public int staticGetMemoryClass() {
911 // Really brain dead right now -- just take this from the configured
912 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn7ad33c82011-03-08 15:53:25 -0800913 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", "");
Dianne Hackbornde398512011-01-18 18:45:21 -0800914 if (vmHeapSize != null && !"".equals(vmHeapSize)) {
915 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1));
916 }
917 return staticGetLargeMemoryClass();
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800918 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700919
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800920 /**
921 * Return the approximate per-application memory class of the current
922 * device when an application is running with a large heap. This is the
923 * space available for memory-intensive applications; most applications
924 * should not need this amount of memory, and should instead stay with the
925 * {@link #getMemoryClass()} limit. The returned value is in megabytes.
926 * This may be the same size as {@link #getMemoryClass()} on memory
927 * constrained devices, or it may be significantly larger on devices with
928 * a large amount of available RAM.
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800929 *
Kweku Adams983829f2017-12-06 14:53:50 -0800930 * <p>This is the size of the application's Dalvik heap if it has
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800931 * specified <code>android:largeHeap="true"</code> in its manifest.
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800932 */
933 public int getLargeMemoryClass() {
934 return staticGetLargeMemoryClass();
935 }
Stefan Kuhne16045c22015-06-05 07:18:06 -0700936
Dianne Hackborn4e24aac2010-12-23 11:43:46 -0800937 /** @hide */
938 static public int staticGetLargeMemoryClass() {
939 // Really brain dead right now -- just take this from the configured
940 // vm heap size, and assume it is in megabytes and thus ends with "m".
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700941 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m");
Dianne Hackborn852975d2014-08-22 17:42:43 -0700942 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1));
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700943 }
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700944
945 /**
946 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM
947 * is ultimately up to the device configuration, but currently it generally means
Greg Kaisere2c459e2017-10-26 10:36:37 -0700948 * something with 1GB or less of RAM. This is mostly intended to be used by apps
949 * to determine whether they should turn off certain features that require more RAM.
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700950 */
951 public boolean isLowRamDevice() {
952 return isLowRamDeviceStatic();
953 }
954
955 /** @hide */
956 public static boolean isLowRamDeviceStatic() {
Marc Hittinger17fb5962017-04-05 15:34:38 -0700957 return RoSystemProperties.CONFIG_LOW_RAM ||
958 (Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700959 }
960
Dianne Hackborn2c6c5e62009-10-08 17:55:49 -0700961 /**
Michael Kwan15eb9982017-04-14 12:34:46 -0700962 * Returns true if this is a small battery device. Exactly whether a device is considered to be
963 * small battery is ultimately up to the device configuration, but currently it generally means
964 * something in the class of a device with 1000 mAh or less. This is mostly intended to be used
965 * to determine whether certain features should be altered to account for a drastically smaller
966 * battery.
967 * @hide
968 */
969 public static boolean isSmallBatteryDevice() {
970 return RoSystemProperties.CONFIG_SMALL_BATTERY;
971 }
972
973 /**
Dianne Hackbornb3756322011-08-12 13:58:13 -0700974 * Used by persistent processes to determine if they are running on a
975 * higher-end device so should be okay using hardware drawing acceleration
976 * (which tends to consume a lot more RAM).
977 * @hide
978 */
Jeff Brown98365d72012-08-19 20:30:52 -0700979 static public boolean isHighEndGfx() {
Dianne Hackbornb4e12492013-06-26 15:08:19 -0700980 return !isLowRamDeviceStatic() &&
981 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel);
Dianne Hackborn49d228b32011-08-24 17:37:31 -0700982 }
983
984 /**
Dianne Hackborn852975d2014-08-22 17:42:43 -0700985 * Return the maximum number of recents entries that we will maintain and show.
986 * @hide
987 */
988 static public int getMaxRecentTasksStatic() {
989 if (gMaxRecentTasks < 0) {
Winson7c402912016-05-10 13:59:36 -0700990 return gMaxRecentTasks = isLowRamDeviceStatic() ? 36 : 48;
Dianne Hackborn852975d2014-08-22 17:42:43 -0700991 }
992 return gMaxRecentTasks;
993 }
994
995 /**
996 * Return the default limit on the number of recents that an app can make.
997 * @hide
998 */
999 static public int getDefaultAppRecentsLimitStatic() {
1000 return getMaxRecentTasksStatic() / 6;
1001 }
1002
1003 /**
1004 * Return the maximum limit on the number of recents that an app can make.
1005 * @hide
1006 */
1007 static public int getMaxAppRecentsLimitStatic() {
1008 return getMaxRecentTasksStatic() / 2;
1009 }
1010
1011 /**
Wale Ogunwalefb1c8642016-03-02 08:28:08 -08001012 * Returns true if the system supports at least one form of multi-window.
1013 * E.g. freeform, split-screen, picture-in-picture.
1014 * @hide
1015 */
Wale Ogunwale9dcf9462017-09-19 15:13:01 -07001016 @TestApi
Erik Wolsheimer9be3a062017-05-31 14:59:57 -07001017 static public boolean supportsMultiWindow(Context context) {
1018 // On watches, multi-window is used to present essential system UI, and thus it must be
1019 // supported regardless of device memory characteristics.
1020 boolean isWatch = context.getPackageManager().hasSystemFeature(
1021 PackageManager.FEATURE_WATCH);
1022 return (!isLowRamDeviceStatic() || isWatch)
Wale Ogunwalefb1c8642016-03-02 08:28:08 -08001023 && Resources.getSystem().getBoolean(
1024 com.android.internal.R.bool.config_supportsMultiWindow);
1025 }
1026
1027 /**
Matthew Ng626e0cc2016-12-07 17:25:53 -08001028 * Returns true if the system supports split screen multi-window.
1029 * @hide
1030 */
Wale Ogunwale9dcf9462017-09-19 15:13:01 -07001031 @TestApi
Erik Wolsheimer9be3a062017-05-31 14:59:57 -07001032 static public boolean supportsSplitScreenMultiWindow(Context context) {
1033 return supportsMultiWindow(context)
Matthew Ng626e0cc2016-12-07 17:25:53 -08001034 && Resources.getSystem().getBoolean(
1035 com.android.internal.R.bool.config_supportsSplitScreenMultiWindow);
1036 }
1037
Jeff Sharkey000ce802017-04-29 13:13:27 -06001038 /** @removed */
Winson Chung709904f2017-04-25 11:00:48 -07001039 @Deprecated
Winson Chunga29eb982016-12-14 12:01:27 -08001040 public static int getMaxNumPictureInPictureActions() {
Winson Chung709904f2017-04-25 11:00:48 -07001041 return 3;
Winson Chunga29eb982016-12-14 12:01:27 -08001042 }
1043
1044 /**
Winson Chung1147c402014-05-14 11:05:00 -07001045 * Information you can set and retrieve about the current activity within the recent task list.
Winson Chung03a9bae2014-05-02 09:56:12 -07001046 */
Winson Chunga449dc02014-05-16 11:15:04 -07001047 public static class TaskDescription implements Parcelable {
Craig Mautner648f69b2014-09-18 14:16:26 -07001048 /** @hide */
1049 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_";
1050 private static final String ATTR_TASKDESCRIPTIONLABEL =
1051 ATTR_TASKDESCRIPTION_PREFIX + "label";
Winson Chung1af8eda2016-02-05 17:55:56 +00001052 private static final String ATTR_TASKDESCRIPTIONCOLOR_PRIMARY =
Craig Mautner648f69b2014-09-18 14:16:26 -07001053 ATTR_TASKDESCRIPTION_PREFIX + "color";
Winson Chung1af8eda2016-02-05 17:55:56 +00001054 private static final String ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND =
1055 ATTR_TASKDESCRIPTION_PREFIX + "colorBackground";
Matthew Ng54bc9422017-10-02 17:16:28 -07001056 private static final String ATTR_TASKDESCRIPTIONICON_FILENAME =
Craig Mautner648f69b2014-09-18 14:16:26 -07001057 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename";
Matthew Ng54bc9422017-10-02 17:16:28 -07001058 private static final String ATTR_TASKDESCRIPTIONICON_RESOURCE =
1059 ATTR_TASKDESCRIPTION_PREFIX + "icon_resource";
Craig Mautner648f69b2014-09-18 14:16:26 -07001060
Winson Chunga449dc02014-05-16 11:15:04 -07001061 private String mLabel;
1062 private Bitmap mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001063 private int mIconRes;
Craig Mautner648f69b2014-09-18 14:16:26 -07001064 private String mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001065 private int mColorPrimary;
Winson Chung1af8eda2016-02-05 17:55:56 +00001066 private int mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001067 private int mStatusBarColor;
1068 private int mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001069
1070 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001071 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001072 *
Winson Chunga449dc02014-05-16 11:15:04 -07001073 * @param label A label and description of the current state of this task.
1074 * @param icon An icon that represents the current state of this task.
Winson Chung1af8eda2016-02-05 17:55:56 +00001075 * @param colorPrimary A color to override the theme's primary color. This color must be
1076 * opaque.
Matthew Ng54bc9422017-10-02 17:16:28 -07001077 * @deprecated use TaskDescription constructor with icon resource instead
Winson Chung03a9bae2014-05-02 09:56:12 -07001078 */
Matthew Ng54bc9422017-10-02 17:16:28 -07001079 @Deprecated
Winson Chunga449dc02014-05-16 11:15:04 -07001080 public TaskDescription(String label, Bitmap icon, int colorPrimary) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001081 this(label, icon, 0, null, colorPrimary, 0, 0, 0);
1082 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1083 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1084 }
1085 }
1086
1087 /**
1088 * Creates the TaskDescription to the specified values.
1089 *
1090 * @param label A label and description of the current state of this task.
1091 * @param iconRes A drawable resource of an icon that represents the current state of this
1092 * activity.
1093 * @param colorPrimary A color to override the theme's primary color. This color must be
1094 * opaque.
1095 */
1096 public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary) {
1097 this(label, null, iconRes, null, colorPrimary, 0, 0, 0);
Winson Chunga449dc02014-05-16 11:15:04 -07001098 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
1099 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1100 }
Craig Mautner648f69b2014-09-18 14:16:26 -07001101 }
1102
Winson Chung03a9bae2014-05-02 09:56:12 -07001103 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001104 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001105 *
1106 * @param label A label and description of the current state of this activity.
1107 * @param icon An icon that represents the current state of this activity.
Matthew Ng54bc9422017-10-02 17:16:28 -07001108 * @deprecated use TaskDescription constructor with icon resource instead
Winson Chung03a9bae2014-05-02 09:56:12 -07001109 */
Matthew Ng54bc9422017-10-02 17:16:28 -07001110 @Deprecated
Winson Chunga449dc02014-05-16 11:15:04 -07001111 public TaskDescription(String label, Bitmap icon) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001112 this(label, icon, 0, null, 0, 0, 0, 0);
1113 }
1114
1115 /**
1116 * Creates the TaskDescription to the specified values.
1117 *
1118 * @param label A label and description of the current state of this activity.
1119 * @param iconRes A drawable resource of an icon that represents the current state of this
1120 * activity.
1121 */
1122 public TaskDescription(String label, @DrawableRes int iconRes) {
1123 this(label, null, iconRes, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001124 }
1125
1126 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001127 * Creates the TaskDescription to the specified values.
Winson Chung03a9bae2014-05-02 09:56:12 -07001128 *
1129 * @param label A label and description of the current state of this activity.
1130 */
Winson Chunga449dc02014-05-16 11:15:04 -07001131 public TaskDescription(String label) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001132 this(label, null, 0, null, 0, 0, 0, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001133 }
1134
Winson Chunga449dc02014-05-16 11:15:04 -07001135 /**
1136 * Creates an empty TaskDescription.
1137 */
1138 public TaskDescription() {
Matthew Ng54bc9422017-10-02 17:16:28 -07001139 this(null, null, 0, null, 0, 0, 0, 0);
Winson Chung1af8eda2016-02-05 17:55:56 +00001140 }
1141
1142 /** @hide */
Matthew Ng54bc9422017-10-02 17:16:28 -07001143 public TaskDescription(String label, Bitmap bitmap, int iconRes, String iconFilename,
1144 int colorPrimary, int colorBackground, int statusBarColor, int navigationBarColor) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001145 mLabel = label;
Matthew Ng54bc9422017-10-02 17:16:28 -07001146 mIcon = bitmap;
1147 mIconRes = iconRes;
Winson Chung1af8eda2016-02-05 17:55:56 +00001148 mIconFilename = iconFilename;
1149 mColorPrimary = colorPrimary;
1150 mColorBackground = colorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001151 mStatusBarColor = statusBarColor;
1152 mNavigationBarColor = navigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001153 }
1154
Winson Chunga449dc02014-05-16 11:15:04 -07001155 /**
1156 * Creates a copy of another TaskDescription.
1157 */
1158 public TaskDescription(TaskDescription td) {
Winsonb6403152016-02-23 13:32:09 -08001159 copyFrom(td);
1160 }
1161
1162 /**
1163 * Copies this the values from another TaskDescription.
1164 * @hide
1165 */
1166 public void copyFrom(TaskDescription other) {
1167 mLabel = other.mLabel;
1168 mIcon = other.mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001169 mIconRes = other.mIconRes;
Winsonb6403152016-02-23 13:32:09 -08001170 mIconFilename = other.mIconFilename;
1171 mColorPrimary = other.mColorPrimary;
1172 mColorBackground = other.mColorBackground;
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001173 mStatusBarColor = other.mStatusBarColor;
1174 mNavigationBarColor = other.mNavigationBarColor;
Winson Chunga449dc02014-05-16 11:15:04 -07001175 }
1176
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001177 /**
1178 * Copies this the values from another TaskDescription, but preserves the hidden fields
1179 * if they weren't set on {@code other}
1180 * @hide
1181 */
1182 public void copyFromPreserveHiddenFields(TaskDescription other) {
1183 mLabel = other.mLabel;
1184 mIcon = other.mIcon;
Matthew Ng54bc9422017-10-02 17:16:28 -07001185 mIconRes = other.mIconRes;
Jorim Jaggif4156ea2017-04-10 18:39:04 -07001186 mIconFilename = other.mIconFilename;
1187 mColorPrimary = other.mColorPrimary;
1188 if (other.mColorBackground != 0) {
1189 mColorBackground = other.mColorBackground;
1190 }
1191 if (other.mStatusBarColor != 0) {
1192 mStatusBarColor = other.mStatusBarColor;
1193 }
1194 if (other.mNavigationBarColor != 0) {
1195 mNavigationBarColor = other.mNavigationBarColor;
1196 }
1197 }
1198
Winson Chunga449dc02014-05-16 11:15:04 -07001199 private TaskDescription(Parcel source) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001200 readFromParcel(source);
1201 }
1202
1203 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001204 * Sets the label for this task description.
1205 * @hide
1206 */
1207 public void setLabel(String label) {
1208 mLabel = label;
1209 }
1210
1211 /**
1212 * Sets the primary color for this task description.
1213 * @hide
1214 */
1215 public void setPrimaryColor(int primaryColor) {
Winson Chungae12dae2014-09-29 14:21:26 -07001216 // Ensure that the given color is valid
1217 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) {
1218 throw new RuntimeException("A TaskDescription's primary color should be opaque");
1219 }
1220 mColorPrimary = primaryColor;
Winson Chung2cb86c72014-06-25 12:03:30 -07001221 }
1222
1223 /**
Winson Chung1af8eda2016-02-05 17:55:56 +00001224 * Sets the background color for this task description.
1225 * @hide
1226 */
1227 public void setBackgroundColor(int backgroundColor) {
1228 // Ensure that the given color is valid
1229 if ((backgroundColor != 0) && (Color.alpha(backgroundColor) != 255)) {
1230 throw new RuntimeException("A TaskDescription's background color should be opaque");
1231 }
1232 mColorBackground = backgroundColor;
1233 }
1234
1235 /**
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001236 * @hide
1237 */
1238 public void setStatusBarColor(int statusBarColor) {
1239 mStatusBarColor = statusBarColor;
1240 }
1241
1242 /**
1243 * @hide
1244 */
1245 public void setNavigationBarColor(int navigationBarColor) {
1246 mNavigationBarColor = navigationBarColor;
1247 }
1248
1249 /**
Winson Chung2cb86c72014-06-25 12:03:30 -07001250 * Sets the icon for this task description.
1251 * @hide
1252 */
1253 public void setIcon(Bitmap icon) {
1254 mIcon = icon;
1255 }
1256
1257 /**
Matthew Ng54bc9422017-10-02 17:16:28 -07001258 * Sets the icon resource for this task description.
1259 * @hide
1260 */
1261 public void setIcon(int iconRes) {
1262 mIconRes = iconRes;
1263 }
1264
1265 /**
Craig Mautner648f69b2014-09-18 14:16:26 -07001266 * Moves the icon bitmap reference from an actual Bitmap to a file containing the
1267 * bitmap.
1268 * @hide
1269 */
1270 public void setIconFilename(String iconFilename) {
1271 mIconFilename = iconFilename;
1272 mIcon = null;
1273 }
1274
1275 /**
Winson Chunga449dc02014-05-16 11:15:04 -07001276 * @return The label and description of the current state of this task.
Winson Chung03a9bae2014-05-02 09:56:12 -07001277 */
Winson Chunga449dc02014-05-16 11:15:04 -07001278 public String getLabel() {
1279 return mLabel;
1280 }
1281
1282 /**
1283 * @return The icon that represents the current state of this task.
1284 */
1285 public Bitmap getIcon() {
Craig Mautner648f69b2014-09-18 14:16:26 -07001286 if (mIcon != null) {
1287 return mIcon;
1288 }
Suprabh Shukla23593142015-11-03 17:31:15 -08001289 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId());
Craig Mautner648f69b2014-09-18 14:16:26 -07001290 }
1291
1292 /** @hide */
Matthew Ng54bc9422017-10-02 17:16:28 -07001293 @TestApi
1294 public int getIconResource() {
1295 return mIconRes;
1296 }
1297
1298 /** @hide */
1299 @TestApi
Craig Mautner648f69b2014-09-18 14:16:26 -07001300 public String getIconFilename() {
1301 return mIconFilename;
Winson Chunga449dc02014-05-16 11:15:04 -07001302 }
1303
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001304 /** @hide */
1305 public Bitmap getInMemoryIcon() {
1306 return mIcon;
1307 }
1308
1309 /** @hide */
Suprabh Shukla23593142015-11-03 17:31:15 -08001310 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) {
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001311 if (iconFilename != null) {
1312 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001313 return getService().getTaskDescriptionIcon(iconFilename,
Winson Chung1af8eda2016-02-05 17:55:56 +00001314 userId);
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001315 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001316 throw e.rethrowFromSystemServer();
Jorim Jaggibdd4b202014-09-26 18:29:07 +02001317 }
1318 }
1319 return null;
1320 }
1321
Winson Chunga449dc02014-05-16 11:15:04 -07001322 /**
1323 * @return The color override on the theme's primary color.
1324 */
1325 public int getPrimaryColor() {
1326 return mColorPrimary;
Winson Chung03a9bae2014-05-02 09:56:12 -07001327 }
1328
Winson Chung1af8eda2016-02-05 17:55:56 +00001329 /**
1330 * @return The background color.
1331 * @hide
1332 */
1333 public int getBackgroundColor() {
1334 return mColorBackground;
1335 }
1336
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001337 /**
1338 * @hide
1339 */
1340 public int getStatusBarColor() {
1341 return mStatusBarColor;
1342 }
1343
1344 /**
1345 * @hide
1346 */
1347 public int getNavigationBarColor() {
1348 return mNavigationBarColor;
1349 }
1350
Craig Mautner648f69b2014-09-18 14:16:26 -07001351 /** @hide */
1352 public void saveToXml(XmlSerializer out) throws IOException {
1353 if (mLabel != null) {
1354 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel);
1355 }
1356 if (mColorPrimary != 0) {
Winson Chung1af8eda2016-02-05 17:55:56 +00001357 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_PRIMARY,
1358 Integer.toHexString(mColorPrimary));
1359 }
1360 if (mColorBackground != 0) {
1361 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND,
1362 Integer.toHexString(mColorBackground));
Craig Mautner648f69b2014-09-18 14:16:26 -07001363 }
1364 if (mIconFilename != null) {
Matthew Ng54bc9422017-10-02 17:16:28 -07001365 out.attribute(null, ATTR_TASKDESCRIPTIONICON_FILENAME, mIconFilename);
1366 }
1367 if (mIconRes != 0) {
1368 out.attribute(null, ATTR_TASKDESCRIPTIONICON_RESOURCE, Integer.toString(mIconRes));
Craig Mautner648f69b2014-09-18 14:16:26 -07001369 }
1370 }
1371
1372 /** @hide */
1373 public void restoreFromXml(String attrName, String attrValue) {
1374 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) {
1375 setLabel(attrValue);
Winson Chung1af8eda2016-02-05 17:55:56 +00001376 } else if (ATTR_TASKDESCRIPTIONCOLOR_PRIMARY.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001377 setPrimaryColor((int) Long.parseLong(attrValue, 16));
Winson Chung1af8eda2016-02-05 17:55:56 +00001378 } else if (ATTR_TASKDESCRIPTIONCOLOR_BACKGROUND.equals(attrName)) {
1379 setBackgroundColor((int) Long.parseLong(attrValue, 16));
Matthew Ng54bc9422017-10-02 17:16:28 -07001380 } else if (ATTR_TASKDESCRIPTIONICON_FILENAME.equals(attrName)) {
Craig Mautner648f69b2014-09-18 14:16:26 -07001381 setIconFilename(attrValue);
Matthew Ng54bc9422017-10-02 17:16:28 -07001382 } else if (ATTR_TASKDESCRIPTIONICON_RESOURCE.equals(attrName)) {
1383 setIcon(Integer.parseInt(attrValue, 10));
Craig Mautner648f69b2014-09-18 14:16:26 -07001384 }
1385 }
1386
Winson Chung03a9bae2014-05-02 09:56:12 -07001387 @Override
1388 public int describeContents() {
1389 return 0;
1390 }
1391
1392 @Override
1393 public void writeToParcel(Parcel dest, int flags) {
Winson Chunga449dc02014-05-16 11:15:04 -07001394 if (mLabel == null) {
Winson Chung03a9bae2014-05-02 09:56:12 -07001395 dest.writeInt(0);
1396 } else {
1397 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001398 dest.writeString(mLabel);
Winson Chung03a9bae2014-05-02 09:56:12 -07001399 }
Winson Chunga449dc02014-05-16 11:15:04 -07001400 if (mIcon == null) {
1401 dest.writeInt(0);
1402 } else {
1403 dest.writeInt(1);
1404 mIcon.writeToParcel(dest, 0);
1405 }
Matthew Ng54bc9422017-10-02 17:16:28 -07001406 dest.writeInt(mIconRes);
Winson Chunga449dc02014-05-16 11:15:04 -07001407 dest.writeInt(mColorPrimary);
Winson Chung1af8eda2016-02-05 17:55:56 +00001408 dest.writeInt(mColorBackground);
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001409 dest.writeInt(mStatusBarColor);
1410 dest.writeInt(mNavigationBarColor);
Craig Mautner648f69b2014-09-18 14:16:26 -07001411 if (mIconFilename == null) {
1412 dest.writeInt(0);
1413 } else {
1414 dest.writeInt(1);
1415 dest.writeString(mIconFilename);
1416 }
Winson Chung03a9bae2014-05-02 09:56:12 -07001417 }
1418
1419 public void readFromParcel(Parcel source) {
Winson Chunga449dc02014-05-16 11:15:04 -07001420 mLabel = source.readInt() > 0 ? source.readString() : null;
1421 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null;
Matthew Ng54bc9422017-10-02 17:16:28 -07001422 mIconRes = source.readInt();
Winson Chunga449dc02014-05-16 11:15:04 -07001423 mColorPrimary = source.readInt();
Winson Chung1af8eda2016-02-05 17:55:56 +00001424 mColorBackground = source.readInt();
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001425 mStatusBarColor = source.readInt();
1426 mNavigationBarColor = source.readInt();
Craig Mautner648f69b2014-09-18 14:16:26 -07001427 mIconFilename = source.readInt() > 0 ? source.readString() : null;
Winson Chung03a9bae2014-05-02 09:56:12 -07001428 }
1429
Winson Chunga449dc02014-05-16 11:15:04 -07001430 public static final Creator<TaskDescription> CREATOR
1431 = new Creator<TaskDescription>() {
1432 public TaskDescription createFromParcel(Parcel source) {
1433 return new TaskDescription(source);
Winson Chung03a9bae2014-05-02 09:56:12 -07001434 }
Winson Chunga449dc02014-05-16 11:15:04 -07001435 public TaskDescription[] newArray(int size) {
1436 return new TaskDescription[size];
Winson Chung03a9bae2014-05-02 09:56:12 -07001437 }
1438 };
1439
1440 @Override
1441 public String toString() {
Winson Chunga449dc02014-05-16 11:15:04 -07001442 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon +
Matthew Ng54bc9422017-10-02 17:16:28 -07001443 " IconRes: " + mIconRes + " IconFilename: " + mIconFilename +
1444 " colorPrimary: " + mColorPrimary + " colorBackground: " + mColorBackground +
Jorim Jaggi30d64f32017-04-07 16:33:17 +02001445 " statusBarColor: " + mColorBackground +
1446 " navigationBarColor: " + mNavigationBarColor;
Winson Chung03a9bae2014-05-02 09:56:12 -07001447 }
1448 }
1449
1450 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 * Information you can retrieve about tasks that the user has most recently
1452 * started or visited.
1453 */
1454 public static class RecentTaskInfo implements Parcelable {
1455 /**
1456 * If this task is currently running, this is the identifier for it.
1457 * If it is not running, this will be -1.
1458 */
1459 public int id;
1460
1461 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08001462 * The true identifier of this task, valid even if it is not running.
1463 */
1464 public int persistentId;
Stefan Kuhne16045c22015-06-05 07:18:06 -07001465
Dianne Hackbornd94df452011-02-16 18:53:31 -08001466 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001467 * The original Intent used to launch the task. You can use this
1468 * Intent to re-launch the task (if it is no longer running) or bring
1469 * the current task to the front.
1470 */
1471 public Intent baseIntent;
1472
1473 /**
1474 * If this task was started from an alias, this is the actual
1475 * activity component that was initially started; the component of
1476 * the baseIntent in this case is the name of the actual activity
1477 * implementation that the alias referred to. Otherwise, this is null.
1478 */
1479 public ComponentName origActivity;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001480
1481 /**
James Cook4d0ef042015-07-09 14:28:23 -07001482 * The actual activity component that started the task.
1483 * @hide
1484 */
1485 @Nullable
1486 public ComponentName realActivity;
1487
1488 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001489 * Description of the task's last state.
1490 */
1491 public CharSequence description;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001492
1493 /**
1494 * The id of the ActivityStack this Task was on most recently.
Craig Mautner27030522013-08-26 12:25:36 -07001495 * @hide
Craig Mautner6d90fed2013-05-22 15:03:10 -07001496 */
1497 public int stackId;
1498
Kenny Guy82326a92014-03-17 17:16:06 +00001499 /**
Craig Mautner2fbd7542014-03-21 09:34:07 -07001500 * The id of the user the task was running as.
Kenny Guy82326a92014-03-17 17:16:06 +00001501 * @hide
1502 */
1503 public int userId;
1504
Craig Mautner2fbd7542014-03-21 09:34:07 -07001505 /**
Winson Chungffa2ec62014-07-03 15:54:42 -07001506 * The first time this task was active.
1507 * @hide
1508 */
1509 public long firstActiveTime;
1510
1511 /**
Winson Chungf1fbd772014-06-24 18:06:58 -07001512 * The last time this task was active.
1513 * @hide
1514 */
1515 public long lastActiveTime;
1516
1517 /**
Winson Chung03a9bae2014-05-02 09:56:12 -07001518 * The recent activity values for the highest activity in the stack to have set the values.
Winson Chunga449dc02014-05-16 11:15:04 -07001519 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}.
Craig Mautner2fbd7542014-03-21 09:34:07 -07001520 */
Winson Chunga449dc02014-05-16 11:15:04 -07001521 public TaskDescription taskDescription;
Craig Mautner2fbd7542014-03-21 09:34:07 -07001522
Craig Mautnera228ae92014-07-09 05:44:55 -07001523 /**
1524 * Task affiliation for grouping with other tasks.
Craig Mautnera228ae92014-07-09 05:44:55 -07001525 */
1526 public int affiliatedTaskId;
1527
Winson Chungec396d62014-08-06 17:08:00 -07001528 /**
1529 * Task affiliation color of the source task with the affiliated task id.
1530 *
1531 * @hide
1532 */
1533 public int affiliatedTaskColor;
1534
Wale Ogunwale6035e012015-04-14 15:54:10 -07001535 /**
1536 * The component launched as the first activity in the task.
1537 * This can be considered the "application" of this task.
1538 */
1539 public ComponentName baseActivity;
1540
1541 /**
1542 * The activity component at the top of the history stack of the task.
1543 * This is what the user is currently doing.
1544 */
1545 public ComponentName topActivity;
1546
1547 /**
1548 * Number of activities in this task.
1549 */
1550 public int numActivities;
1551
Winson2dd76942015-11-02 09:20:01 -08001552 /**
1553 * The bounds of the task.
1554 * @hide
1555 */
1556 public Rect bounds;
1557
Wale Ogunwale21b60582016-01-27 12:34:16 -08001558 /**
1559 * True if the task can go in the docked stack.
1560 * @hide
1561 */
Winson Chungd3395382016-12-13 11:49:09 -08001562 public boolean supportsSplitScreenMultiWindow;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001563
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001564 /**
1565 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1566 * @hide
1567 */
1568 public int resizeMode;
1569
Wale Ogunwale89be5762017-10-04 13:27:49 -07001570 /**
1571 * The current configuration this task is in.
1572 * @hide
1573 */
1574 final public Configuration configuration = new Configuration();
1575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 public RecentTaskInfo() {
1577 }
1578
Craig Mautner6d90fed2013-05-22 15:03:10 -07001579 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 public int describeContents() {
1581 return 0;
1582 }
1583
Craig Mautner6d90fed2013-05-22 15:03:10 -07001584 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 public void writeToParcel(Parcel dest, int flags) {
1586 dest.writeInt(id);
Dianne Hackbornd94df452011-02-16 18:53:31 -08001587 dest.writeInt(persistentId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 if (baseIntent != null) {
1589 dest.writeInt(1);
1590 baseIntent.writeToParcel(dest, 0);
1591 } else {
1592 dest.writeInt(0);
1593 }
1594 ComponentName.writeToParcel(origActivity, dest);
James Cook4d0ef042015-07-09 14:28:23 -07001595 ComponentName.writeToParcel(realActivity, dest);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001596 TextUtils.writeToParcel(description, dest,
1597 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
Winson Chunga449dc02014-05-16 11:15:04 -07001598 if (taskDescription != null) {
Craig Mautner2fbd7542014-03-21 09:34:07 -07001599 dest.writeInt(1);
Winson Chunga449dc02014-05-16 11:15:04 -07001600 taskDescription.writeToParcel(dest, 0);
Winson Chung03a9bae2014-05-02 09:56:12 -07001601 } else {
1602 dest.writeInt(0);
Craig Mautner2fbd7542014-03-21 09:34:07 -07001603 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001604 dest.writeInt(stackId);
Kenny Guy82326a92014-03-17 17:16:06 +00001605 dest.writeInt(userId);
Winson Chungf1fbd772014-06-24 18:06:58 -07001606 dest.writeLong(lastActiveTime);
Craig Mautnera228ae92014-07-09 05:44:55 -07001607 dest.writeInt(affiliatedTaskId);
Winson Chungec396d62014-08-06 17:08:00 -07001608 dest.writeInt(affiliatedTaskColor);
Wale Ogunwale6035e012015-04-14 15:54:10 -07001609 ComponentName.writeToParcel(baseActivity, dest);
1610 ComponentName.writeToParcel(topActivity, dest);
1611 dest.writeInt(numActivities);
Winson2dd76942015-11-02 09:20:01 -08001612 if (bounds != null) {
1613 dest.writeInt(1);
1614 bounds.writeToParcel(dest, 0);
1615 } else {
1616 dest.writeInt(0);
1617 }
Winson Chungd3395382016-12-13 11:49:09 -08001618 dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001619 dest.writeInt(resizeMode);
Wale Ogunwale89be5762017-10-04 13:27:49 -07001620 configuration.writeToParcel(dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 }
1622
1623 public void readFromParcel(Parcel source) {
1624 id = source.readInt();
Dianne Hackbornd94df452011-02-16 18:53:31 -08001625 persistentId = source.readInt();
Craig Mautner688b5102014-03-27 16:55:03 -07001626 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 origActivity = ComponentName.readFromParcel(source);
James Cook4d0ef042015-07-09 14:28:23 -07001628 realActivity = ComponentName.readFromParcel(source);
Dianne Hackbornd2835932010-12-13 16:28:46 -08001629 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Winson Chunga449dc02014-05-16 11:15:04 -07001630 taskDescription = source.readInt() > 0 ?
1631 TaskDescription.CREATOR.createFromParcel(source) : null;
Craig Mautner6d90fed2013-05-22 15:03:10 -07001632 stackId = source.readInt();
Kenny Guy82326a92014-03-17 17:16:06 +00001633 userId = source.readInt();
Winson Chungf1fbd772014-06-24 18:06:58 -07001634 lastActiveTime = source.readLong();
Craig Mautnera228ae92014-07-09 05:44:55 -07001635 affiliatedTaskId = source.readInt();
Winson Chungec396d62014-08-06 17:08:00 -07001636 affiliatedTaskColor = source.readInt();
Wale Ogunwale6035e012015-04-14 15:54:10 -07001637 baseActivity = ComponentName.readFromParcel(source);
1638 topActivity = ComponentName.readFromParcel(source);
1639 numActivities = source.readInt();
Winson2dd76942015-11-02 09:20:01 -08001640 bounds = source.readInt() > 0 ?
1641 Rect.CREATOR.createFromParcel(source) : null;
Winson Chungd3395382016-12-13 11:49:09 -08001642 supportsSplitScreenMultiWindow = source.readInt() == 1;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001643 resizeMode = source.readInt();
Wale Ogunwale89be5762017-10-04 13:27:49 -07001644 configuration.readFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 }
Craig Mautner6d90fed2013-05-22 15:03:10 -07001646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 public static final Creator<RecentTaskInfo> CREATOR
1648 = new Creator<RecentTaskInfo>() {
1649 public RecentTaskInfo createFromParcel(Parcel source) {
1650 return new RecentTaskInfo(source);
1651 }
1652 public RecentTaskInfo[] newArray(int size) {
1653 return new RecentTaskInfo[size];
1654 }
1655 };
1656
1657 private RecentTaskInfo(Parcel source) {
1658 readFromParcel(source);
1659 }
1660 }
1661
1662 /**
1663 * Flag for use with {@link #getRecentTasks}: return all tasks, even those
1664 * that have set their
1665 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag.
1666 */
1667 public static final int RECENT_WITH_EXCLUDED = 0x0001;
Kenny Guy82326a92014-03-17 17:16:06 +00001668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 /**
Dianne Hackbornd2835932010-12-13 16:28:46 -08001670 * Provides a list that does not contain any
Dianne Hackborn53d9264d2010-04-13 12:49:14 -07001671 * recent tasks that currently are not available to the user.
1672 */
1673 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002;
Dianne Hackbornd2835932010-12-13 16:28:46 -08001674
1675 /**
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001676 * <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 -08001677 * the most recent being first and older ones after in order.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001678 *
1679 * <p><b>Note: this method is only intended for debugging and presenting
1680 * task management user interfaces</b>. This should never be used for
1681 * core logic in an application, such as deciding between different
1682 * behaviors based on the information found here. Such uses are
1683 * <em>not</em> supported, and will likely break in the future. For
1684 * example, if multiple applications can be actively running at the
1685 * same time, assumptions made about the meaning of the data here for
1686 * purposes of control flow will be incorrect.</p>
1687 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001688 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is
Dianne Hackborn2d7576b2014-10-03 16:26:04 -07001689 * no longer available to third party applications: the introduction of
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001690 * document-centric recents means
1691 * it can leak personal information to the caller. For backwards compatibility,
1692 * it will still return a small subset of its data: at least the caller's
1693 * own tasks (though see {@link #getAppTasks()} for the correct supported
1694 * way to retrieve that information), and possibly some other tasks
1695 * such as home that are known to not be sensitive.
1696 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 * @param maxNum The maximum number of entries to return in the list. The
1698 * actual number returned may be smaller, depending on how many tasks the
1699 * user has started and the maximum number the system can remember.
Dianne Hackbornd2835932010-12-13 16:28:46 -08001700 * @param flags Information about what to return. May be any combination
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001701 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}.
Stefan Kuhne16045c22015-06-05 07:18:06 -07001702 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 * @return Returns a list of RecentTaskInfo records describing each of
1704 * the recent tasks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001706 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags)
1708 throws SecurityException {
1709 try {
Winson Chungf067ac72017-10-24 17:32:32 -07001710 if (maxNum < 0) {
1711 throw new IllegalArgumentException("The requested number of tasks should be >= 0");
1712 }
Winson Chung5fa39752017-10-04 14:50:15 -07001713 return getService().getRecentTasks(maxNum, flags, UserHandle.myUserId()).getList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001715 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 }
1717 }
1718
1719 /**
1720 * Information you can retrieve about a particular task that is currently
1721 * "running" in the system. Note that a running task does not mean the
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07001722 * given task actually has a process it is actively running in; it simply
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001723 * means that the user has gone to it and never closed it, but currently
1724 * the system may have killed its process and is only holding on to its
1725 * last state in order to restart it when the user returns.
1726 */
1727 public static class RunningTaskInfo implements Parcelable {
1728 /**
1729 * A unique identifier for this task.
1730 */
1731 public int id;
1732
1733 /**
Winson5510f6c2015-10-27 12:11:26 -07001734 * The stack that currently contains this task.
1735 * @hide
1736 */
1737 public int stackId;
1738
1739 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 * The component launched as the first activity in the task. This can
1741 * be considered the "application" of this task.
1742 */
1743 public ComponentName baseActivity;
1744
1745 /**
1746 * The activity component at the top of the history stack of the task.
1747 * This is what the user is currently doing.
1748 */
1749 public ComponentName topActivity;
1750
1751 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001752 * Thumbnail representation of the task's current state. Currently
1753 * always null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 */
1755 public Bitmap thumbnail;
1756
1757 /**
1758 * Description of the task's current state.
1759 */
1760 public CharSequence description;
1761
1762 /**
1763 * Number of activities in this task.
1764 */
1765 public int numActivities;
1766
1767 /**
1768 * Number of activities that are currently running (not stopped
1769 * and persisted) in this task.
1770 */
1771 public int numRunning;
1772
Craig Mautnerc0fd8052013-09-19 11:20:17 -07001773 /**
1774 * Last time task was run. For sorting.
1775 * @hide
1776 */
1777 public long lastActiveTime;
1778
Wale Ogunwale21b60582016-01-27 12:34:16 -08001779 /**
1780 * True if the task can go in the docked stack.
1781 * @hide
1782 */
Winson Chungd3395382016-12-13 11:49:09 -08001783 public boolean supportsSplitScreenMultiWindow;
Wale Ogunwale21b60582016-01-27 12:34:16 -08001784
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001785 /**
1786 * The resize mode of the task. See {@link ActivityInfo#resizeMode}.
1787 * @hide
1788 */
1789 public int resizeMode;
1790
Wale Ogunwale68278562017-09-23 17:13:55 -07001791 /**
1792 * The full configuration the task is currently running in.
1793 * @hide
1794 */
Wale Ogunwale89be5762017-10-04 13:27:49 -07001795 final public Configuration configuration = new Configuration();
Wale Ogunwale68278562017-09-23 17:13:55 -07001796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 public RunningTaskInfo() {
1798 }
1799
1800 public int describeContents() {
1801 return 0;
1802 }
1803
1804 public void writeToParcel(Parcel dest, int flags) {
1805 dest.writeInt(id);
Winson5510f6c2015-10-27 12:11:26 -07001806 dest.writeInt(stackId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 ComponentName.writeToParcel(baseActivity, dest);
1808 ComponentName.writeToParcel(topActivity, dest);
1809 if (thumbnail != null) {
1810 dest.writeInt(1);
1811 thumbnail.writeToParcel(dest, 0);
1812 } else {
1813 dest.writeInt(0);
1814 }
1815 TextUtils.writeToParcel(description, dest,
1816 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
1817 dest.writeInt(numActivities);
1818 dest.writeInt(numRunning);
Winson Chungd3395382016-12-13 11:49:09 -08001819 dest.writeInt(supportsSplitScreenMultiWindow ? 1 : 0);
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001820 dest.writeInt(resizeMode);
Wale Ogunwale68278562017-09-23 17:13:55 -07001821 configuration.writeToParcel(dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 }
1823
1824 public void readFromParcel(Parcel source) {
1825 id = source.readInt();
Winson5510f6c2015-10-27 12:11:26 -07001826 stackId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001827 baseActivity = ComponentName.readFromParcel(source);
1828 topActivity = ComponentName.readFromParcel(source);
1829 if (source.readInt() != 0) {
1830 thumbnail = Bitmap.CREATOR.createFromParcel(source);
1831 } else {
1832 thumbnail = null;
1833 }
1834 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
1835 numActivities = source.readInt();
1836 numRunning = source.readInt();
Winson Chungd3395382016-12-13 11:49:09 -08001837 supportsSplitScreenMultiWindow = source.readInt() != 0;
Jorim Jaggi29379ec2016-04-11 23:43:42 -07001838 resizeMode = source.readInt();
Wale Ogunwale68278562017-09-23 17:13:55 -07001839 configuration.readFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07001841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() {
1843 public RunningTaskInfo createFromParcel(Parcel source) {
1844 return new RunningTaskInfo(source);
1845 }
1846 public RunningTaskInfo[] newArray(int size) {
1847 return new RunningTaskInfo[size];
1848 }
1849 };
1850
1851 private RunningTaskInfo(Parcel source) {
1852 readFromParcel(source);
1853 }
1854 }
Winson Chung1147c402014-05-14 11:05:00 -07001855
1856 /**
1857 * Get the list of tasks associated with the calling application.
1858 *
1859 * @return The list of tasks associated with the application making this call.
1860 * @throws SecurityException
1861 */
1862 public List<ActivityManager.AppTask> getAppTasks() {
1863 ArrayList<AppTask> tasks = new ArrayList<AppTask>();
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001864 List<IBinder> appTasks;
Winson Chung1147c402014-05-14 11:05:00 -07001865 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001866 appTasks = getService().getAppTasks(mContext.getPackageName());
Winson Chung1147c402014-05-14 11:05:00 -07001867 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001868 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07001869 }
1870 int numAppTasks = appTasks.size();
1871 for (int i = 0; i < numAppTasks; i++) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001872 tasks.add(new AppTask(IAppTask.Stub.asInterface(appTasks.get(i))));
Winson Chung1147c402014-05-14 11:05:00 -07001873 }
1874 return tasks;
1875 }
1876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 /**
Winson Chung48a10a52014-08-27 14:36:51 -07001878 * Return the current design dimensions for {@link AppTask} thumbnails, for use
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001879 * with {@link #addAppTask}.
1880 */
Winson Chung48a10a52014-08-27 14:36:51 -07001881 public Size getAppTaskThumbnailSize() {
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001882 synchronized (this) {
1883 ensureAppTaskThumbnailSizeLocked();
Winson Chung48a10a52014-08-27 14:36:51 -07001884 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y);
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001885 }
1886 }
1887
1888 private void ensureAppTaskThumbnailSizeLocked() {
1889 if (mAppTaskThumbnailSize == null) {
1890 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001891 mAppTaskThumbnailSize = getService().getAppTaskThumbnailSize();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001892 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001893 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001894 }
1895 }
1896 }
1897
1898 /**
1899 * Add a new {@link AppTask} for the calling application. This will create a new
1900 * recents entry that is added to the <b>end</b> of all existing recents.
1901 *
1902 * @param activity The activity that is adding the entry. This is used to help determine
1903 * the context that the new recents entry will be in.
1904 * @param intent The Intent that describes the recents entry. This is the same Intent that
1905 * you would have used to launch the activity for it. In generally you will want to set
1906 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and
1907 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents
1908 * entry will exist without an activity, so it doesn't make sense to not retain it when
1909 * its activity disappears. The given Intent here also must have an explicit ComponentName
1910 * set on it.
1911 * @param description Optional additional description information.
1912 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by
Winson Chung48a10a52014-08-27 14:36:51 -07001913 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be
1914 * recreated in your process, probably in a way you don't like, before the recents entry
1915 * is added.
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001916 *
1917 * @return Returns the task id of the newly added app task, or -1 if the add failed. The
1918 * most likely cause of failure is that there is no more room for more tasks for your app.
1919 */
1920 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent,
1921 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) {
1922 Point size;
1923 synchronized (this) {
1924 ensureAppTaskThumbnailSizeLocked();
1925 size = mAppTaskThumbnailSize;
1926 }
1927 final int tw = thumbnail.getWidth();
1928 final int th = thumbnail.getHeight();
1929 if (tw != size.x || th != size.y) {
1930 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig());
1931
1932 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top.
1933 float scale;
1934 float dx = 0, dy = 0;
1935 if (tw * size.x > size.y * th) {
1936 scale = (float) size.x / (float) th;
1937 dx = (size.y - tw * scale) * 0.5f;
1938 } else {
1939 scale = (float) size.y / (float) tw;
1940 dy = (size.x - th * scale) * 0.5f;
1941 }
1942 Matrix matrix = new Matrix();
1943 matrix.setScale(scale, scale);
1944 matrix.postTranslate((int) (dx + 0.5f), 0);
1945
1946 Canvas canvas = new Canvas(bm);
1947 canvas.drawBitmap(thumbnail, matrix, null);
1948 canvas.setBitmap(null);
1949
1950 thumbnail = bm;
1951 }
1952 if (description == null) {
1953 description = new TaskDescription();
1954 }
1955 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001956 return getService().addAppTask(activity.getActivityToken(),
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001957 intent, description, thumbnail);
1958 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001959 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07001960 }
1961 }
1962
1963 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 * Return a list of the tasks that are currently running, with
1965 * the most recent being first and older ones after in order. Note that
1966 * "running" does not mean any of the task's code is currently loaded or
1967 * activity -- the task may have been frozen by the system, so that it
1968 * can be restarted in its previous state when next brought to the
1969 * foreground.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001970 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07001971 * <p><b>Note: this method is only intended for debugging and presenting
1972 * task management user interfaces</b>. This should never be used for
1973 * core logic in an application, such as deciding between different
1974 * behaviors based on the information found here. Such uses are
1975 * <em>not</em> supported, and will likely break in the future. For
1976 * example, if multiple applications can be actively running at the
1977 * same time, assumptions made about the meaning of the data here for
1978 * purposes of control flow will be incorrect.</p>
1979 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07001980 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001981 * is no longer available to third party
1982 * applications: the introduction of document-centric recents means
1983 * it can leak person information to the caller. For backwards compatibility,
Alan Stokes1e4e74a2017-08-02 11:17:37 +01001984 * it will still return a small subset of its data: at least the caller's
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001985 * own tasks, and possibly some other tasks
1986 * such as home that are known to not be sensitive.
1987 *
Jim Miller0b2a6d02010-07-13 18:01:29 -07001988 * @param maxNum The maximum number of entries to return in the list. The
1989 * actual number returned may be smaller, depending on how many tasks the
1990 * user has started.
1991 *
1992 * @return Returns a list of RunningTaskInfo records describing each of
1993 * the running tasks.
Jim Miller0b2a6d02010-07-13 18:01:29 -07001994 */
Dianne Hackborna25a8b22014-05-30 12:30:35 -07001995 @Deprecated
Jim Miller0b2a6d02010-07-13 18:01:29 -07001996 public List<RunningTaskInfo> getRunningTasks(int maxNum)
1997 throws SecurityException {
Dianne Hackborn09233282014-04-30 11:33:59 -07001998 try {
Winson Chung61c9e5a2017-10-11 10:39:32 -07001999 return getService().getTasks(maxNum);
Dianne Hackborn09233282014-04-30 11:33:59 -07002000 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002001 throw e.rethrowFromSystemServer();
Dianne Hackborn09233282014-04-30 11:33:59 -07002002 }
Jim Miller0b2a6d02010-07-13 18:01:29 -07002003 }
2004
Dianne Hackborn0c5001d2011-04-12 18:16:08 -07002005 /**
Wale Ogunwale388945c2017-10-04 12:13:46 -07002006 * Sets the windowing mode for a specific task. Only works on tasks of type
2007 * {@link WindowConfiguration#ACTIVITY_TYPE_STANDARD}
2008 * @param taskId The id of the task to set the windowing mode for.
2009 * @param windowingMode The windowing mode to set for the task.
2010 * @param toTop If the task should be moved to the top once the windowing mode changes.
2011 * @hide
2012 */
2013 @TestApi
2014 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
2015 public void setTaskWindowingMode(int taskId, int windowingMode, boolean toTop)
2016 throws SecurityException {
2017 try {
2018 getService().setTaskWindowingMode(taskId, windowingMode, toTop);
2019 } catch (RemoteException e) {
2020 throw e.rethrowFromSystemServer();
2021 }
2022 }
2023
2024 /**
Matthew Ngf59a4132017-10-25 12:03:22 -07002025 * Moves the input task to the primary-split-screen stack.
2026 * @param taskId Id of task to move.
2027 * @param createMode The mode the primary split screen stack should be created in if it doesn't
2028 * exist already. See
2029 * {@link android.app.ActivityManager#SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT}
2030 * and
2031 * {@link android.app.ActivityManager
2032 * #SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT}
2033 * @param toTop If the task and stack should be moved to the top.
2034 * @param animate Whether we should play an animation for the moving the task
2035 * @param initialBounds If the primary stack gets created, it will use these bounds for the
2036 * docked stack. Pass {@code null} to use default bounds.
Wale Ogunwalec59b4f62017-11-30 11:05:43 -08002037 * @param showRecents If the recents activity should be shown on the other side of the task
2038 * going into split-screen mode.
Matthew Ngf59a4132017-10-25 12:03:22 -07002039 * @hide
2040 */
2041 @TestApi
2042 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
2043 public void setTaskWindowingModeSplitScreenPrimary(int taskId, int createMode, boolean toTop,
Wale Ogunwalec59b4f62017-11-30 11:05:43 -08002044 boolean animate, Rect initialBounds, boolean showRecents) throws SecurityException {
Matthew Ngf59a4132017-10-25 12:03:22 -07002045 try {
2046 getService().setTaskWindowingModeSplitScreenPrimary(taskId, createMode, toTop, animate,
Wale Ogunwalec59b4f62017-11-30 11:05:43 -08002047 initialBounds, showRecents);
Matthew Ngf59a4132017-10-25 12:03:22 -07002048 } catch (RemoteException e) {
2049 throw e.rethrowFromSystemServer();
2050 }
2051 }
2052
2053 /**
Wale Ogunwale388945c2017-10-04 12:13:46 -07002054 * Resizes the input stack id to the given bounds.
2055 * @param stackId Id of the stack to resize.
2056 * @param bounds Bounds to resize the stack to or {@code null} for fullscreen.
2057 * @hide
2058 */
2059 @TestApi
2060 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
2061 public void resizeStack(int stackId, Rect bounds) throws SecurityException {
2062 try {
2063 getService().resizeStack(stackId, bounds, false /* allowResizeInDockedMode */,
2064 false /* preserveWindows */, false /* animate */, -1 /* animationDuration */);
2065 } catch (RemoteException e) {
2066 throw e.rethrowFromSystemServer();
2067 }
2068 }
2069
2070 /**
Wale Ogunwale68278562017-09-23 17:13:55 -07002071 * Removes stacks in the windowing modes from the system if they are of activity type
2072 * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED
2073 *
2074 * @hide
2075 */
2076 @TestApi
Wale Ogunwale388945c2017-10-04 12:13:46 -07002077 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
Wale Ogunwale68278562017-09-23 17:13:55 -07002078 public void removeStacksInWindowingModes(int[] windowingModes) throws SecurityException {
2079 try {
2080 getService().removeStacksInWindowingModes(windowingModes);
2081 } catch (RemoteException e) {
2082 throw e.rethrowFromSystemServer();
2083 }
2084 }
2085
2086 /**
2087 * Removes stack of the activity types from the system.
2088 *
2089 * @hide
2090 */
2091 @TestApi
Wale Ogunwale388945c2017-10-04 12:13:46 -07002092 @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
Wale Ogunwale68278562017-09-23 17:13:55 -07002093 public void removeStacksWithActivityTypes(int[] activityTypes) throws SecurityException {
2094 try {
2095 getService().removeStacksWithActivityTypes(activityTypes);
2096 } catch (RemoteException e) {
2097 throw e.rethrowFromSystemServer();
2098 }
2099 }
2100
2101 /**
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002102 * Represents a task snapshot.
2103 * @hide
2104 */
2105 public static class TaskSnapshot implements Parcelable {
2106
2107 private final GraphicBuffer mSnapshot;
2108 private final int mOrientation;
2109 private final Rect mContentInsets;
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002110 private final boolean mReducedResolution;
2111 private final float mScale;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002112
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002113 public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets,
2114 boolean reducedResolution, float scale) {
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002115 mSnapshot = snapshot;
2116 mOrientation = orientation;
2117 mContentInsets = new Rect(contentInsets);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002118 mReducedResolution = reducedResolution;
2119 mScale = scale;
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002120 }
2121
2122 private TaskSnapshot(Parcel source) {
2123 mSnapshot = source.readParcelable(null /* classLoader */);
2124 mOrientation = source.readInt();
2125 mContentInsets = source.readParcelable(null /* classLoader */);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002126 mReducedResolution = source.readBoolean();
2127 mScale = source.readFloat();
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002128 }
2129
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002130 /**
2131 * @return The graphic buffer representing the screenshot.
2132 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002133 public GraphicBuffer getSnapshot() {
2134 return mSnapshot;
2135 }
2136
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002137 /**
2138 * @return The screen orientation the screenshot was taken in.
2139 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002140 public int getOrientation() {
2141 return mOrientation;
2142 }
2143
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002144 /**
2145 * @return The system/content insets on the snapshot. These can be clipped off in order to
2146 * remove any areas behind system bars in the snapshot.
2147 */
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002148 public Rect getContentInsets() {
2149 return mContentInsets;
2150 }
2151
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002152 /**
2153 * @return Whether this snapshot is a down-sampled version of the full resolution.
2154 */
2155 public boolean isReducedResolution() {
2156 return mReducedResolution;
2157 }
2158
2159 /**
2160 * @return The scale this snapshot was taken in.
2161 */
2162 public float getScale() {
2163 return mScale;
2164 }
2165
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002166 @Override
2167 public int describeContents() {
2168 return 0;
2169 }
2170
2171 @Override
2172 public void writeToParcel(Parcel dest, int flags) {
2173 dest.writeParcelable(mSnapshot, 0);
2174 dest.writeInt(mOrientation);
2175 dest.writeParcelable(mContentInsets, 0);
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002176 dest.writeBoolean(mReducedResolution);
2177 dest.writeFloat(mScale);
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002178 }
2179
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002180 @Override
2181 public String toString() {
2182 return "TaskSnapshot{mSnapshot=" + mSnapshot + " mOrientation=" + mOrientation
Jorim Jaggi35e3f532017-03-17 17:06:50 +01002183 + " mContentInsets=" + mContentInsets.toShortString()
2184 + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale;
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002185 }
2186
Jorim Jaggie2c77f92016-12-29 14:57:22 +01002187 public static final Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
2188 public TaskSnapshot createFromParcel(Parcel source) {
2189 return new TaskSnapshot(source);
2190 }
2191 public TaskSnapshot[] newArray(int size) {
2192 return new TaskSnapshot[size];
2193 }
2194 };
2195 }
2196
Dianne Hackbornf26fd992011-04-08 18:14:09 -07002197 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002198 @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = {
2199 MOVE_TASK_WITH_HOME,
2200 MOVE_TASK_NO_USER_ACTION,
2201 })
2202 @Retention(RetentionPolicy.SOURCE)
2203 public @interface MoveTaskFlags {}
2204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002206 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home"
2207 * activity along with the task, so it is positioned immediately behind
2208 * the task.
2209 */
2210 public static final int MOVE_TASK_WITH_HOME = 0x00000001;
2211
2212 /**
Dianne Hackbornd94df452011-02-16 18:53:31 -08002213 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a
2214 * user-instigated action, so the current activity will not receive a
2215 * hint that the user is leaving.
2216 */
2217 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002;
2218
2219 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002220 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)}
2221 * with a null options argument.
2222 *
2223 * @param taskId The identifier of the task to be moved, as found in
2224 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002225 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002226 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002227 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2228 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002229 moveTaskToFront(taskId, flags, null);
2230 }
2231
2232 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002233 * Ask that the task associated with a given task ID be moved to the
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002234 * front of the stack, so it is now visible to the user.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002235 *
2236 * @param taskId The identifier of the task to be moved, as found in
2237 * {@link RunningTaskInfo} or {@link RecentTaskInfo}.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002238 * @param flags Additional operational flags.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07002239 * @param options Additional options for the operation, either null or
2240 * as per {@link Context#startActivity(Intent, android.os.Bundle)
2241 * Context.startActivity(Intent, Bundle)}.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002242 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002243 @RequiresPermission(android.Manifest.permission.REORDER_TASKS)
2244 public void moveTaskToFront(int taskId, @MoveTaskFlags int flags, Bundle options) {
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002245 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002246 getService().moveTaskToFront(taskId, flags, options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002247 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002248 throw e.rethrowFromSystemServer();
Dianne Hackborn621e17d2010-11-22 15:59:56 -08002249 }
2250 }
2251
2252 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 * Information you can retrieve about a particular Service that is
2254 * currently running in the system.
2255 */
2256 public static class RunningServiceInfo implements Parcelable {
2257 /**
2258 * The service component.
2259 */
2260 public ComponentName service;
2261
2262 /**
2263 * If non-zero, this is the process the service is running in.
2264 */
2265 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002268 * The UID that owns this service.
2269 */
2270 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002271
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002272 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 * The name of the process this service runs in.
2274 */
2275 public String process;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002276
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 /**
2278 * Set to true if the service has asked to run as a foreground process.
2279 */
2280 public boolean foreground;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 /**
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002283 * The time when the service was first made active, either by someone
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002284 * starting or binding to it. This
2285 * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 */
2287 public long activeSince;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 /**
2290 * Set to true if this service has been explicitly started.
2291 */
2292 public boolean started;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 /**
2295 * Number of clients connected to the service.
2296 */
2297 public int clientCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 /**
2300 * Number of times the service's process has crashed while the service
2301 * is running.
2302 */
2303 public int crashCount;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002304
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 /**
2306 * The time when there was last activity in the service (either
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002307 * explicit requests to start it or clients binding to it). This
2308 * is in units of {@link android.os.SystemClock#uptimeMillis()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 */
2310 public long lastActivityTime;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002311
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002312 /**
2313 * If non-zero, this service is not currently running, but scheduled to
2314 * restart at the given time.
2315 */
2316 public long restarting;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002317
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002318 /**
2319 * Bit for {@link #flags}: set if this service has been
2320 * explicitly started.
2321 */
2322 public static final int FLAG_STARTED = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002323
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002324 /**
2325 * Bit for {@link #flags}: set if the service has asked to
2326 * run as a foreground process.
2327 */
2328 public static final int FLAG_FOREGROUND = 1<<1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002329
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002330 /**
Elliot Waite54de7742017-01-11 15:30:35 -08002331 * Bit for {@link #flags}: set if the service is running in a
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002332 * core system process.
2333 */
2334 public static final int FLAG_SYSTEM_PROCESS = 1<<2;
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 * persistent process.
2339 */
2340 public static final int FLAG_PERSISTENT_PROCESS = 1<<3;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002341
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002342 /**
2343 * Running flags.
2344 */
2345 public int flags;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002346
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002347 /**
2348 * For special services that are bound to by system code, this is
2349 * the package that holds the binding.
2350 */
2351 public String clientPackage;
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 * a string resource providing a user-visible label for who the
2356 * client is.
2357 */
2358 public int clientLabel;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 public RunningServiceInfo() {
2361 }
2362
2363 public int describeContents() {
2364 return 0;
2365 }
2366
2367 public void writeToParcel(Parcel dest, int flags) {
2368 ComponentName.writeToParcel(service, dest);
2369 dest.writeInt(pid);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002370 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 dest.writeString(process);
2372 dest.writeInt(foreground ? 1 : 0);
2373 dest.writeLong(activeSince);
2374 dest.writeInt(started ? 1 : 0);
2375 dest.writeInt(clientCount);
2376 dest.writeInt(crashCount);
2377 dest.writeLong(lastActivityTime);
2378 dest.writeLong(restarting);
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002379 dest.writeInt(this.flags);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002380 dest.writeString(clientPackage);
2381 dest.writeInt(clientLabel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 }
2383
2384 public void readFromParcel(Parcel source) {
2385 service = ComponentName.readFromParcel(source);
2386 pid = source.readInt();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002387 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 process = source.readString();
2389 foreground = source.readInt() != 0;
2390 activeSince = source.readLong();
2391 started = source.readInt() != 0;
2392 clientCount = source.readInt();
2393 crashCount = source.readInt();
2394 lastActivityTime = source.readLong();
2395 restarting = source.readLong();
Dianne Hackborn3025ef32009-08-31 21:31:47 -07002396 flags = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002397 clientPackage = source.readString();
2398 clientLabel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002401 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() {
2402 public RunningServiceInfo createFromParcel(Parcel source) {
2403 return new RunningServiceInfo(source);
2404 }
2405 public RunningServiceInfo[] newArray(int size) {
2406 return new RunningServiceInfo[size];
2407 }
2408 };
2409
2410 private RunningServiceInfo(Parcel source) {
2411 readFromParcel(source);
2412 }
2413 }
2414
2415 /**
2416 * Return a list of the services that are currently running.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002417 *
2418 * <p><b>Note: this method is only intended for debugging or implementing
2419 * service management type user interfaces.</b></p>
2420 *
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002421 * @deprecated As of {@link android.os.Build.VERSION_CODES#O}, this method
2422 * is no longer available to third party applications. For backwards compatibility,
2423 * it will still return the caller's own services.
2424 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 * @param maxNum The maximum number of entries to return in the list. The
2426 * actual number returned may be smaller, depending on how many services
2427 * are running.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002428 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 * @return Returns a list of RunningServiceInfo records describing each of
2430 * the running tasks.
2431 */
Bryce Leef17e1d1a42017-04-17 15:52:50 -07002432 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 public List<RunningServiceInfo> getRunningServices(int maxNum)
2434 throws SecurityException {
2435 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002436 return getService()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 .getServices(maxNum, 0);
2438 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002439 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 }
2441 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 /**
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002444 * Returns a PendingIntent you can start to show a control panel for the
2445 * given running service. If the service does not have a control panel,
2446 * null is returned.
2447 */
2448 public PendingIntent getRunningServiceControlPanel(ComponentName service)
2449 throws SecurityException {
2450 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002451 return getService()
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002452 .getRunningServiceControlPanel(service);
2453 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002454 throw e.rethrowFromSystemServer();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002455 }
2456 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002457
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07002458 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 * Information you can retrieve about the available memory through
2460 * {@link ActivityManager#getMemoryInfo}.
2461 */
2462 public static class MemoryInfo implements Parcelable {
2463 /**
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002464 * The available memory on the system. This number should not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 * be considered absolute: due to the nature of the kernel, a significant
2466 * portion of this memory is actually in use and needed for the overall
2467 * system to run well.
2468 */
2469 public long availMem;
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002470
2471 /**
2472 * The total memory accessible by the kernel. This is basically the
2473 * RAM size of the device, not including below-kernel fixed allocations
2474 * like DMA buffers, RAM for the baseband CPU, etc.
2475 */
2476 public long totalMem;
2477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 /**
2479 * The threshold of {@link #availMem} at which we consider memory to be
2480 * low and start killing background services and other non-extraneous
2481 * processes.
2482 */
2483 public long threshold;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 /**
2486 * Set to true if the system considers itself to currently be in a low
2487 * memory situation.
2488 */
2489 public boolean lowMemory;
2490
Dianne Hackborn7d608422011-08-07 16:24:18 -07002491 /** @hide */
2492 public long hiddenAppThreshold;
2493 /** @hide */
2494 public long secondaryServerThreshold;
2495 /** @hide */
2496 public long visibleAppThreshold;
2497 /** @hide */
2498 public long foregroundAppThreshold;
2499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 public MemoryInfo() {
2501 }
2502
2503 public int describeContents() {
2504 return 0;
2505 }
2506
2507 public void writeToParcel(Parcel dest, int flags) {
2508 dest.writeLong(availMem);
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002509 dest.writeLong(totalMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002510 dest.writeLong(threshold);
2511 dest.writeInt(lowMemory ? 1 : 0);
Dianne Hackborn7d608422011-08-07 16:24:18 -07002512 dest.writeLong(hiddenAppThreshold);
2513 dest.writeLong(secondaryServerThreshold);
2514 dest.writeLong(visibleAppThreshold);
2515 dest.writeLong(foregroundAppThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 public void readFromParcel(Parcel source) {
2519 availMem = source.readLong();
Dianne Hackborn59325eb2012-05-09 18:45:20 -07002520 totalMem = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 threshold = source.readLong();
2522 lowMemory = source.readInt() != 0;
Dianne Hackborn7d608422011-08-07 16:24:18 -07002523 hiddenAppThreshold = source.readLong();
2524 secondaryServerThreshold = source.readLong();
2525 visibleAppThreshold = source.readLong();
2526 foregroundAppThreshold = source.readLong();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 }
2528
2529 public static final Creator<MemoryInfo> CREATOR
2530 = new Creator<MemoryInfo>() {
2531 public MemoryInfo createFromParcel(Parcel source) {
2532 return new MemoryInfo(source);
2533 }
2534 public MemoryInfo[] newArray(int size) {
2535 return new MemoryInfo[size];
2536 }
2537 };
2538
2539 private MemoryInfo(Parcel source) {
2540 readFromParcel(source);
2541 }
2542 }
2543
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07002544 /**
2545 * Return general information about the memory state of the system. This
2546 * can be used to help decide how to manage your own memory, though note
2547 * that polling is not recommended and
2548 * {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2549 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this.
2550 * Also see {@link #getMyMemoryState} for how to retrieve the current trim
2551 * level of your process as needed, which gives a better hint for how to
2552 * manage its memory.
2553 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 public void getMemoryInfo(MemoryInfo outInfo) {
2555 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002556 getService().getMemoryInfo(outInfo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002558 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 }
2560 }
Craig Mautner967212c2013-04-13 21:10:58 -07002561
Craig Mautner5ff12102013-05-24 12:50:15 -07002562 /**
Craig Mautner967212c2013-04-13 21:10:58 -07002563 * Information you can retrieve about an ActivityStack in the system.
2564 * @hide
2565 */
2566 public static class StackInfo implements Parcelable {
2567 public int stackId;
Craig Mautnered6649f2013-12-02 14:08:25 -08002568 public Rect bounds = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -07002569 public int[] taskIds;
2570 public String[] taskNames;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002571 public Rect[] taskBounds;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002572 public int[] taskUserIds;
Winsond46b7272016-04-20 11:54:27 -07002573 public ComponentName topActivity;
Craig Mautnered6649f2013-12-02 14:08:25 -08002574 public int displayId;
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002575 public int userId;
Winsond46b7272016-04-20 11:54:27 -07002576 public boolean visible;
Winson529c8e42016-05-17 11:08:40 -07002577 // Index of the stack in the display's stack list, can be used for comparison of stack order
2578 public int position;
Wale Ogunwale68278562017-09-23 17:13:55 -07002579 /**
2580 * The full configuration the stack is currently running in.
2581 * @hide
2582 */
Wale Ogunwale89be5762017-10-04 13:27:49 -07002583 final public Configuration configuration = new Configuration();
Craig Mautner967212c2013-04-13 21:10:58 -07002584
Craig Mautner967212c2013-04-13 21:10:58 -07002585 @Override
2586 public int describeContents() {
2587 return 0;
2588 }
2589
2590 @Override
2591 public void writeToParcel(Parcel dest, int flags) {
2592 dest.writeInt(stackId);
2593 dest.writeInt(bounds.left);
2594 dest.writeInt(bounds.top);
2595 dest.writeInt(bounds.right);
2596 dest.writeInt(bounds.bottom);
2597 dest.writeIntArray(taskIds);
2598 dest.writeStringArray(taskNames);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002599 final int boundsCount = taskBounds == null ? 0 : taskBounds.length;
2600 dest.writeInt(boundsCount);
2601 for (int i = 0; i < boundsCount; i++) {
2602 dest.writeInt(taskBounds[i].left);
2603 dest.writeInt(taskBounds[i].top);
2604 dest.writeInt(taskBounds[i].right);
2605 dest.writeInt(taskBounds[i].bottom);
2606 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002607 dest.writeIntArray(taskUserIds);
Craig Mautnered6649f2013-12-02 14:08:25 -08002608 dest.writeInt(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002609 dest.writeInt(userId);
Winsond46b7272016-04-20 11:54:27 -07002610 dest.writeInt(visible ? 1 : 0);
Winson529c8e42016-05-17 11:08:40 -07002611 dest.writeInt(position);
Winsond46b7272016-04-20 11:54:27 -07002612 if (topActivity != null) {
2613 dest.writeInt(1);
2614 topActivity.writeToParcel(dest, 0);
2615 } else {
2616 dest.writeInt(0);
2617 }
Wale Ogunwale68278562017-09-23 17:13:55 -07002618 configuration.writeToParcel(dest, flags);
Craig Mautner967212c2013-04-13 21:10:58 -07002619 }
2620
2621 public void readFromParcel(Parcel source) {
2622 stackId = source.readInt();
2623 bounds = new Rect(
2624 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2625 taskIds = source.createIntArray();
2626 taskNames = source.createStringArray();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002627 final int boundsCount = source.readInt();
2628 if (boundsCount > 0) {
2629 taskBounds = new Rect[boundsCount];
2630 for (int i = 0; i < boundsCount; i++) {
2631 taskBounds[i] = new Rect();
2632 taskBounds[i].set(
2633 source.readInt(), source.readInt(), source.readInt(), source.readInt());
2634 }
2635 } else {
2636 taskBounds = null;
2637 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002638 taskUserIds = source.createIntArray();
Craig Mautnered6649f2013-12-02 14:08:25 -08002639 displayId = source.readInt();
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002640 userId = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002641 visible = source.readInt() > 0;
Winson529c8e42016-05-17 11:08:40 -07002642 position = source.readInt();
Winsond46b7272016-04-20 11:54:27 -07002643 if (source.readInt() > 0) {
2644 topActivity = ComponentName.readFromParcel(source);
2645 }
Wale Ogunwale68278562017-09-23 17:13:55 -07002646 configuration.readFromParcel(source);
Craig Mautner967212c2013-04-13 21:10:58 -07002647 }
2648
2649 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
2650 @Override
2651 public StackInfo createFromParcel(Parcel source) {
2652 return new StackInfo(source);
2653 }
2654 @Override
2655 public StackInfo[] newArray(int size) {
2656 return new StackInfo[size];
2657 }
2658 };
2659
Craig Mautner5ff12102013-05-24 12:50:15 -07002660 public StackInfo() {
2661 }
2662
Craig Mautner967212c2013-04-13 21:10:58 -07002663 private StackInfo(Parcel source) {
2664 readFromParcel(source);
2665 }
2666
Craig Mautner5ff12102013-05-24 12:50:15 -07002667 public String toString(String prefix) {
Craig Mautner967212c2013-04-13 21:10:58 -07002668 StringBuilder sb = new StringBuilder(256);
Craig Mautner5ff12102013-05-24 12:50:15 -07002669 sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002670 sb.append(" bounds="); sb.append(bounds.toShortString());
2671 sb.append(" displayId="); sb.append(displayId);
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002672 sb.append(" userId="); sb.append(userId);
Craig Mautnered6649f2013-12-02 14:08:25 -08002673 sb.append("\n");
Wale Ogunwale68278562017-09-23 17:13:55 -07002674 sb.append(" configuration="); sb.append(configuration);
2675 sb.append("\n");
Craig Mautner5ff12102013-05-24 12:50:15 -07002676 prefix = prefix + " ";
Craig Mautner967212c2013-04-13 21:10:58 -07002677 for (int i = 0; i < taskIds.length; ++i) {
2678 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002679 sb.append(": "); sb.append(taskNames[i]);
2680 if (taskBounds != null) {
2681 sb.append(" bounds="); sb.append(taskBounds[i].toShortString());
2682 }
Filip Gruszczynski21199bd2015-12-02 12:49:58 -08002683 sb.append(" userId=").append(taskUserIds[i]);
Winsond46b7272016-04-20 11:54:27 -07002684 sb.append(" visible=").append(visible);
2685 if (topActivity != null) {
2686 sb.append(" topActivity=").append(topActivity);
2687 }
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002688 sb.append("\n");
Craig Mautner967212c2013-04-13 21:10:58 -07002689 }
2690 return sb.toString();
2691 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002692
2693 @Override
2694 public String toString() {
2695 return toString("");
2696 }
Craig Mautner967212c2013-04-13 21:10:58 -07002697 }
2698
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002699 /**
2700 * @hide
2701 */
Svet Ganovf935a702017-08-22 12:15:58 -07002702 @RequiresPermission(anyOf={Manifest.permission.CLEAR_APP_USER_DATA,
2703 Manifest.permission.ACCESS_INSTANT_APPS})
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
2705 try {
Christopher Tate1d99c392017-12-07 16:54:04 -08002706 return getService().clearApplicationUserData(packageName, false,
Dianne Hackborn41203752012-08-31 14:05:51 -07002707 observer, UserHandle.myUserId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002709 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 }
2711 }
Christopher Tatea3664242013-06-26 15:00:18 -07002712
2713 /**
2714 * Permits an application to erase its own data from disk. This is equivalent to
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07002715 * the user choosing to clear the app's data from within the device settings UI. It
2716 * erases all dynamic data associated with the app -- its private data and data in its
2717 * private area on external storage -- but does not remove the installed application
Benjamin Franza77e3572017-06-23 12:01:44 +01002718 * itself, nor any OBB files. It also revokes all runtime permissions that the app has acquired,
2719 * clears all notifications and removes all Uri grants related to this application.
Christopher Tatea3664242013-06-26 15:00:18 -07002720 *
2721 * @return {@code true} if the application successfully requested that the application's
2722 * data be erased; {@code false} otherwise.
2723 */
2724 public boolean clearApplicationUserData() {
2725 return clearApplicationUserData(mContext.getPackageName(), null);
2726 }
2727
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002728
2729 /**
2730 * Permits an application to get the persistent URI permissions granted to another.
2731 *
2732 * <p>Typically called by Settings.
2733 *
2734 * @param packageName application to look for the granted permissions
2735 * @return list of granted URI permissions
2736 *
2737 * @hide
2738 */
2739 public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName) {
2740 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002741 return getService().getGrantedUriPermissions(packageName,
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002742 UserHandle.myUserId());
2743 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002744 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002745 }
2746 }
2747
2748 /**
2749 * Permits an application to clear the persistent URI permissions granted to another.
2750 *
2751 * <p>Typically called by Settings.
2752 *
2753 * @param packageName application to clear its granted permissions
2754 *
2755 * @hide
2756 */
2757 public void clearGrantedUriPermissions(String packageName) {
2758 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002759 getService().clearGrantedUriPermissions(packageName,
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002760 UserHandle.myUserId());
2761 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002762 throw e.rethrowFromSystemServer();
Felipe Lemef3fa0f82016-01-07 12:08:19 -08002763 }
2764 }
2765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 /**
2767 * Information you can retrieve about any processes that are in an error condition.
2768 */
2769 public static class ProcessErrorStateInfo implements Parcelable {
2770 /**
2771 * Condition codes
2772 */
2773 public static final int NO_ERROR = 0;
2774 public static final int CRASHED = 1;
2775 public static final int NOT_RESPONDING = 2;
2776
2777 /**
2778 * The condition that the process is in.
2779 */
2780 public int condition;
2781
2782 /**
2783 * The process name in which the crash or error occurred.
2784 */
2785 public String processName;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 /**
2788 * The pid of this process; 0 if none
2789 */
2790 public int pid;
2791
2792 /**
2793 * The kernel user-ID that has been assigned to this process;
2794 * currently this is not a unique ID (multiple applications can have
2795 * the same uid).
2796 */
2797 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002799 /**
Dan Egnor60d87622009-12-16 16:32:58 -08002800 * The activity name associated with the error, if known. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 */
2802 public String tag;
2803
2804 /**
2805 * A short message describing the error condition.
2806 */
2807 public String shortMsg;
2808
2809 /**
2810 * A long message describing the error condition.
2811 */
2812 public String longMsg;
2813
2814 /**
Dan Egnorb7f03672009-12-09 16:22:32 -08002815 * The stack trace where the error originated. May be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 */
Dan Egnorb7f03672009-12-09 16:22:32 -08002817 public String stackTrace;
2818
2819 /**
2820 * to be deprecated: This value will always be null.
2821 */
2822 public byte[] crashData = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823
2824 public ProcessErrorStateInfo() {
2825 }
2826
Craig Mautner5ff12102013-05-24 12:50:15 -07002827 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 public int describeContents() {
2829 return 0;
2830 }
2831
Craig Mautner5ff12102013-05-24 12:50:15 -07002832 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 public void writeToParcel(Parcel dest, int flags) {
2834 dest.writeInt(condition);
2835 dest.writeString(processName);
2836 dest.writeInt(pid);
2837 dest.writeInt(uid);
2838 dest.writeString(tag);
2839 dest.writeString(shortMsg);
2840 dest.writeString(longMsg);
Dan Egnorb7f03672009-12-09 16:22:32 -08002841 dest.writeString(stackTrace);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 }
Craig Mautner5ff12102013-05-24 12:50:15 -07002843
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844 public void readFromParcel(Parcel source) {
2845 condition = source.readInt();
2846 processName = source.readString();
2847 pid = source.readInt();
2848 uid = source.readInt();
2849 tag = source.readString();
2850 shortMsg = source.readString();
2851 longMsg = source.readString();
Dan Egnorb7f03672009-12-09 16:22:32 -08002852 stackTrace = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002854
2855 public static final Creator<ProcessErrorStateInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 new Creator<ProcessErrorStateInfo>() {
2857 public ProcessErrorStateInfo createFromParcel(Parcel source) {
2858 return new ProcessErrorStateInfo(source);
2859 }
2860 public ProcessErrorStateInfo[] newArray(int size) {
2861 return new ProcessErrorStateInfo[size];
2862 }
2863 };
2864
2865 private ProcessErrorStateInfo(Parcel source) {
2866 readFromParcel(source);
2867 }
2868 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07002869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07002871 * 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 -08002872 * will be null if all processes are running properly at this time.
Stefan Kuhne16045c22015-06-05 07:18:06 -07002873 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no
2875 * current error conditions (it will not return an empty list). This list ordering is not
2876 * specified.
2877 */
2878 public List<ProcessErrorStateInfo> getProcessesInErrorState() {
2879 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08002880 return getService().getProcessesInErrorState();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002882 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 }
2884 }
2885
2886 /**
2887 * Information you can retrieve about a running process.
2888 */
Stefan Kuhne16045c22015-06-05 07:18:06 -07002889 public static class RunningAppProcessInfo implements Parcelable {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 /**
2891 * The name of the process that this object is associated with
2892 */
2893 public String processName;
2894
2895 /**
2896 * The pid of this process; 0 if none
2897 */
2898 public int pid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002899
Dianne Hackborneb034652009-09-07 00:49:58 -07002900 /**
2901 * The user id of this process.
2902 */
2903 public int uid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002904
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002905 /**
2906 * All packages that have been loaded into the process.
2907 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 public String pkgList[];
Stefan Kuhne16045c22015-06-05 07:18:06 -07002909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 /**
Dianne Hackborn482566e2010-09-03 12:51:28 -07002911 * Constant for {@link #flags}: this is an app that is unable to
2912 * correctly save its state when going to the background,
2913 * so it can not be killed while in the background.
2914 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002915 */
Dianne Hackborn482566e2010-09-03 12:51:28 -07002916 public static final int FLAG_CANT_SAVE_STATE = 1<<0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002917
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002918 /**
Dianne Hackborn42499172010-10-15 18:45:07 -07002919 * Constant for {@link #flags}: this process is associated with a
2920 * persistent system app.
2921 * @hide
2922 */
2923 public static final int FLAG_PERSISTENT = 1<<1;
2924
2925 /**
Dianne Hackborn0c380492012-08-20 17:23:30 -07002926 * Constant for {@link #flags}: this process is associated with a
2927 * persistent system app.
2928 * @hide
2929 */
2930 public static final int FLAG_HAS_ACTIVITIES = 1<<2;
2931
2932 /**
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002933 * Flags of information. May be any of
Dianne Hackborn482566e2010-09-03 12:51:28 -07002934 * {@link #FLAG_CANT_SAVE_STATE}.
2935 * @hide
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002936 */
2937 public int flags;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08002938
2939 /**
2940 * Last memory trim level reported to the process: corresponds to
2941 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int)
2942 * ComponentCallbacks2.onTrimMemory(int)}.
2943 */
2944 public int lastTrimLevel;
2945
Jeff Sharkey910e0812017-04-21 16:29:27 -06002946 /** @hide */
2947 @IntDef(prefix = { "IMPORTANCE_" }, value = {
2948 IMPORTANCE_FOREGROUND,
2949 IMPORTANCE_FOREGROUND_SERVICE,
2950 IMPORTANCE_TOP_SLEEPING,
2951 IMPORTANCE_VISIBLE,
2952 IMPORTANCE_PERCEPTIBLE,
2953 IMPORTANCE_CANT_SAVE_STATE,
2954 IMPORTANCE_SERVICE,
2955 IMPORTANCE_CACHED,
2956 IMPORTANCE_GONE,
2957 })
2958 @Retention(RetentionPolicy.SOURCE)
2959 public @interface Importance {}
2960
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07002961 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002962 * Constant for {@link #importance}: This process is running the
2963 * foreground UI; that is, it is the thing currently at the top of the screen
2964 * that the user is interacting with.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 */
2966 public static final int IMPORTANCE_FOREGROUND = 100;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07002969 * Constant for {@link #importance}: This process is running a foreground
2970 * service, for example to perform music playback even while the user is
2971 * not immediately in the app. This generally indicates that the process
2972 * is doing something the user actively cares about.
2973 */
2974 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125;
2975
2976 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002977 * @deprecated Pre-{@link android.os.Build.VERSION_CODES#P} version of
2978 * {@link #IMPORTANCE_TOP_SLEEPING}. As of Android
2979 * {@link android.os.Build.VERSION_CODES#P}, this is considered much less
2980 * important since we want to reduce what apps can do when the screen is off.
Dianne Hackborn1e383822015-04-10 14:02:33 -07002981 */
Dianne Hackbornbad8d912017-12-18 16:45:52 -08002982 @Deprecated
2983 public static final int IMPORTANCE_TOP_SLEEPING_PRE_28 = 150;
Dianne Hackborn1e383822015-04-10 14:02:33 -07002984
2985 /**
2986 * Constant for {@link #importance}: This process is running something
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002987 * that is actively visible to the user, though not in the immediate
Dianne Hackborn1e383822015-04-10 14:02:33 -07002988 * foreground. This may be running a window that is behind the current
2989 * foreground (so paused and with its state saved, not interacting with
2990 * the user, but visible to them to some degree); it may also be running
2991 * other services under the system's control that it inconsiders important.
Dianne Hackborn860755f2010-06-03 18:47:52 -07002992 */
Dianne Hackborn32907cf2010-06-10 17:50:20 -07002993 public static final int IMPORTANCE_VISIBLE = 200;
Stefan Kuhne16045c22015-06-05 07:18:06 -07002994
Dianne Hackborn860755f2010-06-03 18:47:52 -07002995 /**
Makoto Onukid7e40582017-04-13 14:54:56 -07002996 * Constant for {@link #importance}: {@link #IMPORTANCE_PERCEPTIBLE} had this wrong value
2997 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
2998 * the value of {@link #IMPORTANCE_PERCEPTIBLE} has been fixed.
2999 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003000 * <p>The system will return this value instead of {@link #IMPORTANCE_PERCEPTIBLE}
3001 * on Android versions below {@link Build.VERSION_CODES#O}.
3002 *
3003 * <p>On Android version {@link Build.VERSION_CODES#O} and later, this value will still be
3004 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3005 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3006 * the correct value {@link #IMPORTANCE_PERCEPTIBLE} will be returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003008 public static final int IMPORTANCE_PERCEPTIBLE_PRE_26 = 130;
Makoto Onukid7e40582017-04-13 14:54:56 -07003009
3010 /**
3011 * Constant for {@link #importance}: This process is not something the user
3012 * is directly aware of, but is otherwise perceptible to them to some degree.
3013 */
3014 public static final int IMPORTANCE_PERCEPTIBLE = 230;
3015
3016 /**
3017 * Constant for {@link #importance}: {@link #IMPORTANCE_CANT_SAVE_STATE} had
3018 * this wrong value
3019 * before {@link Build.VERSION_CODES#O}. Since the {@link Build.VERSION_CODES#O} SDK,
3020 * the value of {@link #IMPORTANCE_CANT_SAVE_STATE} has been fixed.
3021 *
Makoto Onukie92f7942017-04-26 14:38:18 -07003022 * <p>The system will return this value instead of {@link #IMPORTANCE_CANT_SAVE_STATE}
3023 * on Android versions below {@link Build.VERSION_CODES#O}.
3024 *
3025 * <p>On Android version {@link Build.VERSION_CODES#O} after, this value will still be
3026 * returned for apps with the target API level below {@link Build.VERSION_CODES#O}.
3027 * For apps targeting version {@link Build.VERSION_CODES#O} and later,
3028 * the correct value {@link #IMPORTANCE_CANT_SAVE_STATE} will be returned.
3029 *
Makoto Onukid7e40582017-04-13 14:54:56 -07003030 * @hide
3031 */
Makoto Onukie92f7942017-04-26 14:38:18 -07003032 public static final int IMPORTANCE_CANT_SAVE_STATE_PRE_26 = 170;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003033
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003034 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003035 * Constant for {@link #importance}: This process is contains services
3036 * that should remain running. These are background services apps have
3037 * started, not something the user is aware of, so they may be killed by
3038 * the system relatively freely (though it is generally desired that they
3039 * stay running as long as they want to).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 */
3041 public static final int IMPORTANCE_SERVICE = 300;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 /**
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003044 * Constant for {@link #importance}: This process is running the foreground
3045 * UI, but the device is asleep so it is not visible to the user. Though the
3046 * system will try hard to keep its process from being killed, in all other
3047 * ways we consider it a kind of cached process, with the limitations that go
3048 * along with that state: network access, running background services, etc.
3049 */
3050 public static final int IMPORTANCE_TOP_SLEEPING = 325;
3051
3052 /**
Dianne Hackbornf097d422017-12-15 16:32:19 -08003053 * Constant for {@link #importance}: This process is running an
3054 * application that can not save its state, and thus can't be killed
3055 * while in the background. This will be used with apps that have
3056 * {@link android.R.attr#cantSaveState} set on their application tag.
3057 */
3058 public static final int IMPORTANCE_CANT_SAVE_STATE = 350;
3059
3060 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003061 * Constant for {@link #importance}: This process process contains
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003062 * cached code that is expendable, not actively running any app components
3063 * we care about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003065 public static final int IMPORTANCE_CACHED = 400;
3066
3067 /**
3068 * @deprecated Renamed to {@link #IMPORTANCE_CACHED}.
3069 */
3070 public static final int IMPORTANCE_BACKGROUND = IMPORTANCE_CACHED;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003073 * Constant for {@link #importance}: This process is empty of any
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 * actively running code.
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003075 * @deprecated This value is no longer reported, use {@link #IMPORTANCE_CACHED} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 */
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003077 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 public static final int IMPORTANCE_EMPTY = 500;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003079
3080 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003081 * Constant for {@link #importance}: This process does not exist.
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003082 */
3083 public static final int IMPORTANCE_GONE = 1000;
3084
Makoto Onukid7e40582017-04-13 14:54:56 -07003085 /**
3086 * Convert a proc state to the correspondent IMPORTANCE_* constant. If the return value
3087 * will be passed to a client, use {@link #procStateToImportanceForClient}.
3088 * @hide
3089 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003090 public static @Importance int procStateToImportance(int procState) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003091 if (procState == PROCESS_STATE_NONEXISTENT) {
3092 return IMPORTANCE_GONE;
3093 } else if (procState >= PROCESS_STATE_HOME) {
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003094 return IMPORTANCE_CACHED;
Dianne Hackbornf4ef6eb2017-12-07 13:57:21 -08003095 } else if (procState == PROCESS_STATE_HEAVY_WEIGHT) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003096 return IMPORTANCE_CANT_SAVE_STATE;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003097 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) {
3098 return IMPORTANCE_TOP_SLEEPING;
Dianne Hackbornf097d422017-12-15 16:32:19 -08003099 } else if (procState >= PROCESS_STATE_SERVICE) {
3100 return IMPORTANCE_SERVICE;
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003101 } else if (procState >= PROCESS_STATE_TRANSIENT_BACKGROUND) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003102 return IMPORTANCE_PERCEPTIBLE;
3103 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) {
3104 return IMPORTANCE_VISIBLE;
Dianne Hackborn1e383822015-04-10 14:02:33 -07003105 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) {
3106 return IMPORTANCE_FOREGROUND_SERVICE;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003107 } else {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003108 return IMPORTANCE_FOREGROUND;
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003109 }
3110 }
3111
Makoto Onukid7e40582017-04-13 14:54:56 -07003112 /**
3113 * Convert a proc state to the correspondent IMPORTANCE_* constant for a client represented
3114 * by a given {@link Context}, with converting {@link #IMPORTANCE_PERCEPTIBLE}
3115 * and {@link #IMPORTANCE_CANT_SAVE_STATE} to the corresponding "wrong" value if the
3116 * client's target SDK < {@link VERSION_CODES#O}.
3117 * @hide
3118 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003119 public static @Importance int procStateToImportanceForClient(int procState,
3120 Context clientContext) {
Makoto Onukie92f7942017-04-26 14:38:18 -07003121 return procStateToImportanceForTargetSdk(procState,
3122 clientContext.getApplicationInfo().targetSdkVersion);
3123 }
3124
3125 /**
3126 * See {@link #procStateToImportanceForClient}.
3127 * @hide
3128 */
3129 public static @Importance int procStateToImportanceForTargetSdk(int procState,
3130 int targetSdkVersion) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003131 final int importance = procStateToImportance(procState);
3132
3133 // For pre O apps, convert to the old, wrong values.
Makoto Onukie92f7942017-04-26 14:38:18 -07003134 if (targetSdkVersion < VERSION_CODES.O) {
Makoto Onukid7e40582017-04-13 14:54:56 -07003135 switch (importance) {
3136 case IMPORTANCE_PERCEPTIBLE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003137 return IMPORTANCE_PERCEPTIBLE_PRE_26;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003138 case IMPORTANCE_TOP_SLEEPING:
3139 return IMPORTANCE_TOP_SLEEPING_PRE_28;
Makoto Onukid7e40582017-04-13 14:54:56 -07003140 case IMPORTANCE_CANT_SAVE_STATE:
Makoto Onukie92f7942017-04-26 14:38:18 -07003141 return IMPORTANCE_CANT_SAVE_STATE_PRE_26;
Makoto Onukid7e40582017-04-13 14:54:56 -07003142 }
3143 }
3144 return importance;
3145 }
3146
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003147 /** @hide */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003148 public static int importanceToProcState(@Importance int importance) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003149 if (importance == IMPORTANCE_GONE) {
3150 return PROCESS_STATE_NONEXISTENT;
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003151 } else if (importance >= IMPORTANCE_CACHED) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003152 return PROCESS_STATE_HOME;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003153 } else if (importance >= IMPORTANCE_CANT_SAVE_STATE) {
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003154 return PROCESS_STATE_HEAVY_WEIGHT;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003155 } else if (importance >= IMPORTANCE_TOP_SLEEPING) {
3156 return PROCESS_STATE_TOP_SLEEPING;
Dianne Hackbornf097d422017-12-15 16:32:19 -08003157 } else if (importance >= IMPORTANCE_SERVICE) {
3158 return PROCESS_STATE_SERVICE;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003159 } else if (importance >= IMPORTANCE_PERCEPTIBLE) {
Dianne Hackborn83b40f62017-04-26 13:59:47 -07003160 return PROCESS_STATE_TRANSIENT_BACKGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003161 } else if (importance >= IMPORTANCE_VISIBLE) {
3162 return PROCESS_STATE_IMPORTANT_FOREGROUND;
Dianne Hackbornbad8d912017-12-18 16:45:52 -08003163 } else if (importance >= IMPORTANCE_TOP_SLEEPING_PRE_28) {
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -08003164 return PROCESS_STATE_IMPORTANT_FOREGROUND;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003165 } else if (importance >= IMPORTANCE_FOREGROUND_SERVICE) {
3166 return PROCESS_STATE_FOREGROUND_SERVICE;
3167 } else {
Dianne Hackborn10fc4fd2017-12-19 17:23:13 -08003168 return PROCESS_STATE_TOP;
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003169 }
3170 }
3171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 /**
Jeff Sharkey910e0812017-04-21 16:29:27 -06003173 * The relative importance level that the system places on this process.
3174 * These constants are numbered so that "more important" values are
3175 * always smaller than "less important" values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003177 public @Importance int importance;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179 /**
3180 * An additional ordering within a particular {@link #importance}
3181 * category, providing finer-grained information about the relative
3182 * utility of processes within a category. This number means nothing
3183 * except that a smaller values are more recently used (and thus
3184 * more important). Currently an LRU value is only maintained for
Dianne Hackborn45e69d62017-03-01 16:02:15 -08003185 * the {@link #IMPORTANCE_CACHED} category, though others may
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003186 * be maintained in the future.
3187 */
3188 public int lru;
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003189
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003190 /**
3191 * Constant for {@link #importanceReasonCode}: nothing special has
3192 * been specified for the reason for this level.
3193 */
3194 public static final int REASON_UNKNOWN = 0;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003195
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003196 /**
3197 * Constant for {@link #importanceReasonCode}: one of the application's
3198 * content providers is being used by another process. The pid of
3199 * the client process is in {@link #importanceReasonPid} and the
3200 * target provider in this process is in
3201 * {@link #importanceReasonComponent}.
3202 */
3203 public static final int REASON_PROVIDER_IN_USE = 1;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003204
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003205 /**
3206 * Constant for {@link #importanceReasonCode}: one of the application's
3207 * content providers is being used by another process. The pid of
3208 * the client process is in {@link #importanceReasonPid} and the
3209 * target provider in this process is in
3210 * {@link #importanceReasonComponent}.
3211 */
3212 public static final int REASON_SERVICE_IN_USE = 2;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003213
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003214 /**
3215 * The reason for {@link #importance}, if any.
3216 */
3217 public int importanceReasonCode;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003218
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003219 /**
3220 * For the specified values of {@link #importanceReasonCode}, this
3221 * is the process ID of the other process that is a client of this
3222 * process. This will be 0 if no other process is using this one.
3223 */
3224 public int importanceReasonPid;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003225
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003226 /**
3227 * For the specified values of {@link #importanceReasonCode}, this
3228 * is the name of the component that is being used in this process.
3229 */
3230 public ComponentName importanceReasonComponent;
Stefan Kuhne16045c22015-06-05 07:18:06 -07003231
Dianne Hackborn905577f2011-09-07 18:31:28 -07003232 /**
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003233 * When {@link #importanceReasonPid} is non-0, this is the importance
Dianne Hackborn905577f2011-09-07 18:31:28 -07003234 * of the other pid. @hide
3235 */
3236 public int importanceReasonImportance;
3237
Dianne Hackborn684bf342014-04-29 17:56:57 -07003238 /**
3239 * Current process state, as per PROCESS_STATE_* constants.
3240 * @hide
3241 */
3242 public int processState;
3243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003244 public RunningAppProcessInfo() {
3245 importance = IMPORTANCE_FOREGROUND;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003246 importanceReasonCode = REASON_UNKNOWN;
Dianne Hackborn684bf342014-04-29 17:56:57 -07003247 processState = PROCESS_STATE_IMPORTANT_FOREGROUND;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003250 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) {
3251 processName = pProcessName;
3252 pid = pPid;
3253 pkgList = pArr;
3254 }
3255
3256 public int describeContents() {
3257 return 0;
3258 }
3259
3260 public void writeToParcel(Parcel dest, int flags) {
3261 dest.writeString(processName);
3262 dest.writeInt(pid);
Dianne Hackborneb034652009-09-07 00:49:58 -07003263 dest.writeInt(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 dest.writeStringArray(pkgList);
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003265 dest.writeInt(this.flags);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003266 dest.writeInt(lastTrimLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 dest.writeInt(importance);
3268 dest.writeInt(lru);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003269 dest.writeInt(importanceReasonCode);
3270 dest.writeInt(importanceReasonPid);
3271 ComponentName.writeToParcel(importanceReasonComponent, dest);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003272 dest.writeInt(importanceReasonImportance);
Dianne Hackborn684bf342014-04-29 17:56:57 -07003273 dest.writeInt(processState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 }
3275
3276 public void readFromParcel(Parcel source) {
3277 processName = source.readString();
3278 pid = source.readInt();
Dianne Hackborneb034652009-09-07 00:49:58 -07003279 uid = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 pkgList = source.readStringArray();
Dianne Hackbornbaf42c62010-06-24 11:23:39 -07003281 flags = source.readInt();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003282 lastTrimLevel = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003283 importance = source.readInt();
3284 lru = source.readInt();
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07003285 importanceReasonCode = source.readInt();
3286 importanceReasonPid = source.readInt();
3287 importanceReasonComponent = ComponentName.readFromParcel(source);
Dianne Hackborn905577f2011-09-07 18:31:28 -07003288 importanceReasonImportance = source.readInt();
Dianne Hackborn684bf342014-04-29 17:56:57 -07003289 processState = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003290 }
3291
Stefan Kuhne16045c22015-06-05 07:18:06 -07003292 public static final Creator<RunningAppProcessInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 new Creator<RunningAppProcessInfo>() {
3294 public RunningAppProcessInfo createFromParcel(Parcel source) {
3295 return new RunningAppProcessInfo(source);
3296 }
3297 public RunningAppProcessInfo[] newArray(int size) {
3298 return new RunningAppProcessInfo[size];
3299 }
3300 };
3301
3302 private RunningAppProcessInfo(Parcel source) {
3303 readFromParcel(source);
3304 }
3305 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 /**
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003308 * Returns a list of application processes installed on external media
3309 * that are running on the device.
3310 *
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003311 * <p><b>Note: this method is only intended for debugging or building
3312 * a user-facing process management UI.</b></p>
3313 *
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003314 * @return Returns a list of ApplicationInfo records, or null if none
3315 * This list ordering is not specified.
3316 * @hide
3317 */
3318 public List<ApplicationInfo> getRunningExternalApplications() {
3319 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003320 return getService().getRunningExternalApplications();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003321 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003322 throw e.rethrowFromSystemServer();
Suchi Amalapurapuf7f5dda2010-03-23 10:34:28 -07003323 }
3324 }
3325
3326 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003327 * Sets the memory trim mode for a process and schedules a memory trim operation.
3328 *
3329 * <p><b>Note: this method is only intended for testing framework.</b></p>
3330 *
3331 * @return Returns true if successful.
3332 * @hide
3333 */
3334 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
3335 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003336 return getService().setProcessMemoryTrimLevel(process, userId,
Stefan Kuhne16045c22015-06-05 07:18:06 -07003337 level);
3338 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003339 throw e.rethrowFromSystemServer();
Stefan Kuhne16045c22015-06-05 07:18:06 -07003340 }
3341 }
3342
3343 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 * Returns a list of application processes that are running on the device.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003345 *
3346 * <p><b>Note: this method is only intended for debugging or building
3347 * a user-facing process management UI.</b></p>
3348 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003349 * @return Returns a list of RunningAppProcessInfo records, or null if there are no
3350 * running processes (it will not return an empty list). This list ordering is not
3351 * specified.
3352 */
3353 public List<RunningAppProcessInfo> getRunningAppProcesses() {
3354 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003355 return getService().getRunningAppProcesses();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003357 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 }
3359 }
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003360
3361 /**
Dianne Hackborn1e383822015-04-10 14:02:33 -07003362 * Return the importance of a given package name, based on the processes that are
3363 * currently running. The return value is one of the importance constants defined
3364 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3365 * processes that this package has code running inside of. If there are no processes
3366 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
Jeff Sharkeyf85ac772015-05-13 12:52:06 -07003367 * @hide
Dianne Hackborn1e383822015-04-10 14:02:33 -07003368 */
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003369 @SystemApi @TestApi
Dianne Hackborn9df8f512016-10-24 17:58:30 -07003370 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003371 public @RunningAppProcessInfo.Importance int getPackageImportance(String packageName) {
Dianne Hackborn1e383822015-04-10 14:02:33 -07003372 try {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003373 int procState = getService().getPackageProcessState(packageName,
Adam Lesinskic30454c2015-06-24 13:24:35 -07003374 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003375 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn1e383822015-04-10 14:02:33 -07003376 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003377 throw e.rethrowFromSystemServer();
Dianne Hackborn1e383822015-04-10 14:02:33 -07003378 }
3379 }
3380
3381 /**
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003382 * Return the importance of a given uid, based on the processes that are
3383 * currently running. The return value is one of the importance constants defined
3384 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the
3385 * processes that this uid has running. If there are no processes
3386 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned.
3387 * @hide
3388 */
3389 @SystemApi @TestApi
3390 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Jeff Sharkey910e0812017-04-21 16:29:27 -06003391 public @RunningAppProcessInfo.Importance int getUidImportance(int uid) {
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003392 try {
3393 int procState = getService().getUidProcessState(uid,
3394 mContext.getOpPackageName());
Makoto Onukid7e40582017-04-13 14:54:56 -07003395 return RunningAppProcessInfo.procStateToImportanceForClient(procState, mContext);
Dianne Hackborn83249ec2017-04-12 10:54:03 -07003396 } catch (RemoteException e) {
3397 throw e.rethrowFromSystemServer();
3398 }
3399 }
3400
3401 /**
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003402 * Callback to get reports about changes to the importance of a uid. Use with
3403 * {@link #addOnUidImportanceListener}.
3404 * @hide
3405 */
3406 @SystemApi @TestApi
3407 public interface OnUidImportanceListener {
3408 /**
3409 * The importance if a given uid has changed. Will be one of the importance
3410 * values in {@link RunningAppProcessInfo};
3411 * {@link RunningAppProcessInfo#IMPORTANCE_GONE IMPORTANCE_GONE} will be reported
3412 * when the uid is no longer running at all. This callback will happen on a thread
3413 * from a thread pool, not the main UI thread.
3414 * @param uid The uid whose importance has changed.
3415 * @param importance The new importance value as per {@link RunningAppProcessInfo}.
3416 */
Jeff Sharkey910e0812017-04-21 16:29:27 -06003417 void onUidImportance(int uid, @RunningAppProcessInfo.Importance int importance);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003418 }
3419
3420 /**
3421 * Start monitoring changes to the imoportance of uids running in the system.
3422 * @param listener The listener callback that will receive change reports.
3423 * @param importanceCutpoint The level of importance in which the caller is interested
3424 * in differences. For example, if {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}
3425 * is used here, you will receive a call each time a uids importance transitions between
3426 * being <= {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE} and
3427 * > {@link RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.
3428 *
3429 * <p>The caller must hold the {@link android.Manifest.permission#PACKAGE_USAGE_STATS}
3430 * permission to use this feature.</p>
3431 *
3432 * @throws IllegalArgumentException If the listener is already registered.
3433 * @throws SecurityException If the caller does not hold
3434 * {@link android.Manifest.permission#PACKAGE_USAGE_STATS}.
3435 * @hide
3436 */
3437 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003438 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003439 public void addOnUidImportanceListener(OnUidImportanceListener listener,
Jeff Sharkey910e0812017-04-21 16:29:27 -06003440 @RunningAppProcessInfo.Importance int importanceCutpoint) {
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003441 synchronized (this) {
3442 if (mImportanceListeners.containsKey(listener)) {
3443 throw new IllegalArgumentException("Listener already registered: " + listener);
3444 }
3445 // TODO: implement the cut point in the system process to avoid IPCs.
Makoto Onukid7e40582017-04-13 14:54:56 -07003446 UidObserver observer = new UidObserver(listener, mContext);
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003447 try {
3448 getService().registerUidObserver(observer,
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003449 UID_OBSERVER_PROCSTATE | UID_OBSERVER_GONE,
3450 RunningAppProcessInfo.importanceToProcState(importanceCutpoint),
3451 mContext.getOpPackageName());
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003452 } catch (RemoteException e) {
3453 throw e.rethrowFromSystemServer();
3454 }
3455 mImportanceListeners.put(listener, observer);
3456 }
3457 }
3458
3459 /**
3460 * Remove an importance listener that was previously registered with
3461 * {@link #addOnUidImportanceListener}.
3462 *
3463 * @throws IllegalArgumentException If the listener is not registered.
3464 * @hide
3465 */
3466 @SystemApi @TestApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003467 @RequiresPermission(Manifest.permission.PACKAGE_USAGE_STATS)
Dianne Hackborn058f1e42016-11-02 17:18:35 -07003468 public void removeOnUidImportanceListener(OnUidImportanceListener listener) {
3469 synchronized (this) {
3470 UidObserver observer = mImportanceListeners.remove(listener);
3471 if (observer == null) {
3472 throw new IllegalArgumentException("Listener not registered: " + listener);
3473 }
3474 try {
3475 getService().unregisterUidObserver(observer);
3476 } catch (RemoteException e) {
3477 throw e.rethrowFromSystemServer();
3478 }
3479 }
3480 }
3481
3482 /**
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003483 * Return global memory state information for the calling process. This
3484 * does not fill in all fields of the {@link RunningAppProcessInfo}. The
3485 * only fields that will be filled in are
3486 * {@link RunningAppProcessInfo#pid},
3487 * {@link RunningAppProcessInfo#uid},
3488 * {@link RunningAppProcessInfo#lastTrimLevel},
3489 * {@link RunningAppProcessInfo#importance},
3490 * {@link RunningAppProcessInfo#lru}, and
3491 * {@link RunningAppProcessInfo#importanceReasonCode}.
3492 */
3493 static public void getMyMemoryState(RunningAppProcessInfo outState) {
3494 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003495 getService().getMyMemoryState(outState);
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003496 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003497 throw e.rethrowFromSystemServer();
Dianne Hackborn27ff9132012-03-06 14:57:58 -08003498 }
3499 }
3500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 /**
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003502 * Return information about the memory usage of one or more processes.
Dianne Hackbornc5bf7582012-04-25 19:12:07 -07003503 *
3504 * <p><b>Note: this method is only intended for debugging or building
3505 * a user-facing process management UI.</b></p>
3506 *
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003507 * @param pids The pids of the processes whose memory usage is to be
3508 * retrieved.
3509 * @return Returns an array of memory information, one for each
3510 * requested pid.
3511 */
3512 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
3513 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003514 return getService().getProcessMemoryInfo(pids);
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003515 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003516 throw e.rethrowFromSystemServer();
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003517 }
3518 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003519
Dianne Hackborn4f21c4c2009-09-17 10:24:05 -07003520 /**
Dianne Hackborn03abb812010-01-04 18:43:19 -08003521 * @deprecated This is now just a wrapper for
3522 * {@link #killBackgroundProcesses(String)}; the previous behavior here
3523 * is no longer available to applications because it allows them to
3524 * break other applications by removing their alarms, stopping their
3525 * services, etc.
3526 */
3527 @Deprecated
3528 public void restartPackage(String packageName) {
3529 killBackgroundProcesses(packageName);
3530 }
Stefan Kuhne16045c22015-06-05 07:18:06 -07003531
Dianne Hackborn03abb812010-01-04 18:43:19 -08003532 /**
3533 * Have the system immediately kill all background processes associated
3534 * with the given package. This is the same as the kernel killing those
3535 * processes to reclaim memory; the system will take care of restarting
3536 * these processes in the future as needed.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003537 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003538 * @param packageName The name of the package whose processes are to
3539 * be killed.
3540 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003541 @RequiresPermission(Manifest.permission.KILL_BACKGROUND_PROCESSES)
Dianne Hackborn03abb812010-01-04 18:43:19 -08003542 public void killBackgroundProcesses(String packageName) {
3543 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003544 getService().killBackgroundProcesses(packageName,
Dianne Hackborn1676c852012-09-10 14:52:30 -07003545 UserHandle.myUserId());
Dianne Hackborn03abb812010-01-04 18:43:19 -08003546 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003547 throw e.rethrowFromSystemServer();
Dianne Hackborn03abb812010-01-04 18:43:19 -08003548 }
3549 }
Svet Ganov019d2302015-05-04 11:07:38 -07003550
3551 /**
3552 * Kills the specified UID.
3553 * @param uid The UID to kill.
3554 * @param reason The reason for the kill.
3555 *
3556 * @hide
3557 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08003558 @SystemApi
Svet Ganov019d2302015-05-04 11:07:38 -07003559 @RequiresPermission(Manifest.permission.KILL_UID)
3560 public void killUid(int uid, String reason) {
3561 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003562 getService().killUid(UserHandle.getAppId(uid),
Svetoslavaa41add2015-08-06 15:03:55 -07003563 UserHandle.getUserId(uid), reason);
Svet Ganov019d2302015-05-04 11:07:38 -07003564 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003565 throw e.rethrowFromSystemServer();
Svet Ganov019d2302015-05-04 11:07:38 -07003566 }
3567 }
3568
Dianne Hackborn03abb812010-01-04 18:43:19 -08003569 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 * Have the system perform a force stop of everything associated with
3571 * the given application package. All processes that share its uid
3572 * will be killed, all services it has running stopped, all activities
3573 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED}
3574 * broadcast will be sent, so that any of its registered alarms can
3575 * be stopped, notifications removed, etc.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003576 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 * <p>You must hold the permission
Dianne Hackborn03abb812010-01-04 18:43:19 -08003578 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 * call this method.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003580 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 * @param packageName The name of the package to be stopped.
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003582 * @param userId The user for which the running package is to be stopped.
Stefan Kuhne16045c22015-06-05 07:18:06 -07003583 *
Dianne Hackborn03abb812010-01-04 18:43:19 -08003584 * @hide This is not available to third party applications due to
3585 * it allowing them to break other applications by stopping their
3586 * services, removing their alarms, etc.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 */
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003588 public void forceStopPackageAsUser(String packageName, int userId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003589 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003590 getService().forceStopPackage(packageName, userId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003592 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003593 }
3594 }
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003595
3596 /**
3597 * @see #forceStopPackageAsUser(String, int)
3598 * @hide
3599 */
Jeff Schumacherb8cadef2017-01-03 13:52:48 -08003600 @SystemApi
3601 @RequiresPermission(Manifest.permission.FORCE_STOP_PACKAGES)
Zoltan Szatmary-Ban0bec95d2014-09-23 17:27:17 +01003602 public void forceStopPackage(String packageName) {
3603 forceStopPackageAsUser(packageName, UserHandle.myUserId());
3604 }
3605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 /**
3607 * Get the device configuration attributes.
3608 */
3609 public ConfigurationInfo getDeviceConfigurationInfo() {
3610 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003611 return getService().getDeviceConfigurationInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003613 throw e.rethrowFromSystemServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 }
Kenny Root5ef44b72011-01-26 17:22:20 -08003616
3617 /**
3618 * Get the preferred density of icons for the launcher. This is used when
3619 * custom drawables are created (e.g., for shortcuts).
3620 *
3621 * @return density in terms of DPI
3622 */
3623 public int getLauncherLargeIconDensity() {
3624 final Resources res = mContext.getResources();
3625 final int density = res.getDisplayMetrics().densityDpi;
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003626 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003627
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003628 if (sw < 600) {
3629 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003630 return density;
3631 }
3632
3633 switch (density) {
3634 case DisplayMetrics.DENSITY_LOW:
3635 return DisplayMetrics.DENSITY_MEDIUM;
3636 case DisplayMetrics.DENSITY_MEDIUM:
3637 return DisplayMetrics.DENSITY_HIGH;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003638 case DisplayMetrics.DENSITY_TV:
3639 return DisplayMetrics.DENSITY_XHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003640 case DisplayMetrics.DENSITY_HIGH:
3641 return DisplayMetrics.DENSITY_XHIGH;
3642 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003643 return DisplayMetrics.DENSITY_XXHIGH;
3644 case DisplayMetrics.DENSITY_XXHIGH:
3645 return DisplayMetrics.DENSITY_XHIGH * 2;
Kenny Root5ef44b72011-01-26 17:22:20 -08003646 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003647 // The density is some abnormal value. Return some other
3648 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003649 return (int)((density*1.5f)+.5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003650 }
3651 }
3652
3653 /**
3654 * Get the preferred launcher icon size. This is used when custom drawables
3655 * are created (e.g., for shortcuts).
3656 *
3657 * @return dimensions of square icons in terms of pixels
3658 */
3659 public int getLauncherLargeIconSize() {
Craig Mautner2fbd7542014-03-21 09:34:07 -07003660 return getLauncherLargeIconSizeInner(mContext);
3661 }
3662
3663 static int getLauncherLargeIconSizeInner(Context context) {
3664 final Resources res = context.getResources();
Kenny Root5ef44b72011-01-26 17:22:20 -08003665 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size);
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003666 final int sw = res.getConfiguration().smallestScreenWidthDp;
Kenny Root5ef44b72011-01-26 17:22:20 -08003667
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003668 if (sw < 600) {
3669 // Smaller than approx 7" tablets, use the regular icon size.
Kenny Root5ef44b72011-01-26 17:22:20 -08003670 return size;
3671 }
3672
3673 final int density = res.getDisplayMetrics().densityDpi;
3674
3675 switch (density) {
3676 case DisplayMetrics.DENSITY_LOW:
3677 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW;
3678 case DisplayMetrics.DENSITY_MEDIUM:
3679 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM;
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003680 case DisplayMetrics.DENSITY_TV:
3681 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003682 case DisplayMetrics.DENSITY_HIGH:
3683 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH;
3684 case DisplayMetrics.DENSITY_XHIGH:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003685 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH;
3686 case DisplayMetrics.DENSITY_XXHIGH:
3687 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH;
Kenny Root5ef44b72011-01-26 17:22:20 -08003688 default:
Dianne Hackbornd96e3df2012-01-25 15:12:23 -08003689 // The density is some abnormal value. Return some other
3690 // abnormal value that is a reasonable scaling of it.
Dianne Hackbornd0356a12012-04-26 19:03:12 -07003691 return (int)((size*1.5f) + .5f);
Kenny Root5ef44b72011-01-26 17:22:20 -08003692 }
3693 }
3694
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003695 /**
3696 * Returns "true" if the user interface is currently being messed with
3697 * by a monkey.
3698 */
3699 public static boolean isUserAMonkey() {
3700 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003701 return getService().isUserAMonkey();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003702 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003703 throw e.rethrowFromSystemServer();
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003704 }
Dianne Hackborn9327f4f2010-01-29 10:38:29 -08003705 }
Brett Chabot3b4fcbc2011-01-09 13:41:02 -08003706
3707 /**
3708 * Returns "true" if device is running in a test harness.
3709 */
3710 public static boolean isRunningInTestHarness() {
3711 return SystemProperties.getBoolean("ro.test_harness", false);
3712 }
Peter Visontay8d224ca2011-02-18 16:39:19 +00003713
3714 /**
3715 * Returns the launch count of each installed package.
3716 *
3717 * @hide
3718 */
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003719 /*public Map<String, Integer> getAllPackageLaunchCounts() {
Peter Visontay8d224ca2011-02-18 16:39:19 +00003720 try {
3721 IUsageStats usageStatsService = IUsageStats.Stub.asInterface(
3722 ServiceManager.getService("usagestats"));
3723 if (usageStatsService == null) {
3724 return new HashMap<String, Integer>();
3725 }
3726
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003727 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(
3728 ActivityThread.currentPackageName());
Peter Visontaybfcda392011-03-02 18:53:37 +00003729 if (allPkgUsageStats == null) {
3730 return new HashMap<String, Integer>();
3731 }
3732
Peter Visontay8d224ca2011-02-18 16:39:19 +00003733 Map<String, Integer> launchCounts = new HashMap<String, Integer>();
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003734 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) {
3735 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount());
Peter Visontay8d224ca2011-02-18 16:39:19 +00003736 }
3737
3738 return launchCounts;
3739 } catch (RemoteException e) {
3740 Log.w(TAG, "Could not query launch counts", e);
3741 return new HashMap<String, Integer>();
3742 }
Adam Lesinski0debc9a2014-07-16 19:09:13 -07003743 }*/
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003744
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003745 /** @hide */
3746 public static int checkComponentPermission(String permission, int uid,
3747 int owningUid, boolean exported) {
3748 // Root, system server get to do everything.
Svetoslavc6d1c342015-02-26 14:44:43 -08003749 final int appId = UserHandle.getAppId(uid);
3750 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003751 return PackageManager.PERMISSION_GRANTED;
3752 }
3753 // Isolated processes don't get any permissions.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003754 if (UserHandle.isIsolated(uid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003755 return PackageManager.PERMISSION_DENIED;
3756 }
3757 // If there is a uid that owns whatever is being accessed, it has
3758 // blanket access to it regardless of the permissions it requires.
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07003759 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) {
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003760 return PackageManager.PERMISSION_GRANTED;
3761 }
3762 // If the target is not exported, then nobody else can get to it.
3763 if (!exported) {
Dianne Hackbornbe4c1d72013-09-09 09:44:05 -07003764 /*
3765 RuntimeException here = new RuntimeException("here");
3766 here.fillInStackTrace();
3767 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid,
3768 here);
3769 */
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003770 return PackageManager.PERMISSION_DENIED;
3771 }
3772 if (permission == null) {
3773 return PackageManager.PERMISSION_GRANTED;
3774 }
3775 try {
3776 return AppGlobals.getPackageManager()
3777 .checkUidPermission(permission, uid);
3778 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003779 throw e.rethrowFromSystemServer();
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003780 }
Dianne Hackborn5320eb82012-05-18 12:05:04 -07003781 }
3782
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003783 /** @hide */
3784 public static int checkUidPermission(String permission, int uid) {
3785 try {
3786 return AppGlobals.getPackageManager()
3787 .checkUidPermission(permission, uid);
3788 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003789 throw e.rethrowFromSystemServer();
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003790 }
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003791 }
3792
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08003793 /**
3794 * @hide
3795 * Helper for dealing with incoming user arguments to system service calls.
3796 * Takes care of checking permissions and converting USER_CURRENT to the
3797 * actual current user.
3798 *
3799 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid().
3800 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid().
3801 * @param userId The user id argument supplied by the caller -- this is the user
3802 * they want to run as.
3803 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared
3804 * to get a USER_ALL returned and deal with it correctly. If false,
3805 * an exception will be thrown if USER_ALL is supplied.
3806 * @param requireFull If true, the caller must hold
3807 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a
3808 * different user than their current process; otherwise they must hold
3809 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
3810 * @param name Optional textual name of the incoming call; only for generating error messages.
3811 * @param callerPackage Optional package name of caller; only for error messages.
3812 *
3813 * @return Returns the user ID that the call should run as. Will always be a concrete
3814 * user number, unless <var>allowAll</var> is true in which case it could also be
3815 * USER_ALL.
3816 */
Dianne Hackborn41203752012-08-31 14:05:51 -07003817 public static int handleIncomingUser(int callingPid, int callingUid, int userId,
3818 boolean allowAll, boolean requireFull, String name, String callerPackage) {
3819 if (UserHandle.getUserId(callingUid) == userId) {
3820 return userId;
3821 }
3822 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003823 return getService().handleIncomingUser(callingPid,
Dianne Hackborn41203752012-08-31 14:05:51 -07003824 callingUid, userId, allowAll, requireFull, name, callerPackage);
3825 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003826 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003827 }
3828 }
3829
Amith Yamasani0e8d7d62014-09-03 13:17:28 -07003830 /**
3831 * Gets the userId of the current foreground user. Requires system permissions.
3832 * @hide
3833 */
3834 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003835 @RequiresPermission(anyOf = {
3836 "android.permission.INTERACT_ACROSS_USERS",
3837 "android.permission.INTERACT_ACROSS_USERS_FULL"
3838 })
Dianne Hackborn41203752012-08-31 14:05:51 -07003839 public static int getCurrentUser() {
3840 UserInfo ui;
3841 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003842 ui = getService().getCurrentUser();
Dianne Hackborn41203752012-08-31 14:05:51 -07003843 return ui != null ? ui.id : 0;
3844 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003845 throw e.rethrowFromSystemServer();
Dianne Hackborn41203752012-08-31 14:05:51 -07003846 }
3847 }
3848
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003849 /**
Stefan Kuhne16045c22015-06-05 07:18:06 -07003850 * @param userid the user's id. Zero indicates the default user.
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003851 * @hide
3852 */
3853 public boolean switchUser(int userid) {
3854 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003855 return getService().switchUser(userid);
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003856 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003857 throw e.rethrowFromSystemServer();
Amith Yamasani4b2e9342011-03-31 12:38:53 -07003858 }
3859 }
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003860
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003861 /**
3862 * Logs out current current foreground user by switching to the system user and stopping the
3863 * user being switched from.
3864 * @hide
3865 */
3866 public static void logoutCurrentUser() {
3867 int currentUser = ActivityManager.getCurrentUser();
3868 if (currentUser != UserHandle.USER_SYSTEM) {
3869 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003870 getService().switchUser(UserHandle.USER_SYSTEM);
3871 getService().stopUser(currentUser, /* force= */ false, null);
Fyodor Kupolovb5690bc32016-03-02 17:50:58 -08003872 } catch (RemoteException e) {
3873 e.rethrowFromSystemServer();
3874 }
3875 }
3876 }
3877
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003878 /** {@hide} */
3879 public static final int FLAG_OR_STOPPED = 1 << 0;
3880 /** {@hide} */
Jeff Sharkey8924e872015-11-30 12:52:10 -07003881 public static final int FLAG_AND_LOCKED = 1 << 1;
Jeff Sharkey0825ab22015-12-02 13:04:49 -07003882 /** {@hide} */
3883 public static final int FLAG_AND_UNLOCKED = 1 << 2;
Jeff Sharkeyce18c812016-04-27 16:00:41 -06003884 /** {@hide} */
3885 public static final int FLAG_AND_UNLOCKING_OR_UNLOCKED = 1 << 3;
Jeff Sharkeye17ac152015-11-06 22:40:29 -08003886
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003887 /**
3888 * Return whether the given user is actively running. This means that
3889 * the user is in the "started" state, not "stopped" -- it is currently
3890 * allowed to run code through scheduled alarms, receiving broadcasts,
3891 * etc. A started user may be either the current foreground user or a
3892 * background user; the result here does not distinguish between the two.
Dianne Hackborn5614bf52016-11-07 17:26:41 -08003893 * @param userId the user's id. Zero indicates the default user.
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003894 * @hide
3895 */
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003896 public boolean isUserRunning(int userId) {
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07003897 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003898 return getService().isUserRunning(userId, 0);
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003899 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07003900 throw e.rethrowFromSystemServer();
Jeff Sharkey9d8a1042015-12-03 17:56:20 -07003901 }
3902 }
3903
3904 /** {@hide} */
Ruben Brunke24b9a62016-02-16 21:38:24 -08003905 public boolean isVrModePackageEnabled(ComponentName component) {
3906 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003907 return getService().isVrModePackageEnabled(component);
Ruben Brunke24b9a62016-02-16 21:38:24 -08003908 } catch (RemoteException e) {
3909 throw e.rethrowFromSystemServer();
3910 }
3911 }
3912
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003913 /**
3914 * Perform a system dump of various state associated with the given application
3915 * package name. This call blocks while the dump is being performed, so should
3916 * not be done on a UI thread. The data will be written to the given file
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003917 * descriptor as text.
Dianne Hackbornebc15ef2013-10-09 17:36:57 -07003918 * @param fd The file descriptor that the dump should be written to. The file
3919 * descriptor is <em>not</em> closed by this function; the caller continues to
3920 * own it.
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003921 * @param packageName The name of the package that is to be dumped.
3922 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003923 @RequiresPermission(Manifest.permission.DUMP)
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003924 public void dumpPackageState(FileDescriptor fd, String packageName) {
3925 dumpPackageStateStatic(fd, packageName);
3926 }
3927
3928 /**
3929 * @hide
3930 */
3931 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) {
3932 FileOutputStream fout = new FileOutputStream(fd);
Dianne Hackborn8c841092013-06-24 13:46:13 -07003933 PrintWriter pw = new FastPrintWriter(fout);
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003934 dumpService(pw, fd, "package", new String[] { packageName });
3935 pw.println();
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003936 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] {
3937 "-a", "package", packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003938 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003939 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName });
Dianne Hackborndaa0d5c2013-11-06 16:30:29 -08003940 pw.println();
Dianne Hackbornab4a81b2014-10-09 17:59:38 -07003941 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003942 pw.println();
Esteban Talavera838ea242017-12-19 11:48:43 +00003943 dumpService(pw, fd, "usagestats", new String[] { packageName });
Dianne Hackborn904a8572013-06-28 18:12:31 -07003944 pw.println();
Dianne Hackborn8c841092013-06-24 13:46:13 -07003945 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName });
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07003946 pw.flush();
3947 }
3948
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003949 /**
3950 * @hide
3951 */
Sudheer Shankadc589ac2016-11-10 15:30:17 -08003952 public static boolean isSystemReady() {
3953 if (!sSystemReady) {
3954 if (ActivityThread.isSystem()) {
3955 sSystemReady =
3956 LocalServices.getService(ActivityManagerInternal.class).isSystemReady();
3957 } else {
3958 // Since this is being called from outside system server, system should be
3959 // ready by now.
3960 sSystemReady = true;
3961 }
3962 }
3963 return sSystemReady;
3964 }
3965
3966 /**
3967 * @hide
3968 */
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003969 public static void broadcastStickyIntent(Intent intent, int userId) {
3970 broadcastStickyIntent(intent, AppOpsManager.OP_NONE, userId);
3971 }
3972
3973 /**
3974 * Convenience for sending a sticky broadcast. For internal use only.
3975 *
3976 * @hide
3977 */
3978 public static void broadcastStickyIntent(Intent intent, int appOp, int userId) {
3979 try {
3980 getService().broadcastIntent(
3981 null, intent, null, null, Activity.RESULT_OK, null, null,
3982 null /*permission*/, appOp, null, false, true, userId);
3983 } catch (RemoteException ex) {
3984 }
3985 }
3986
3987 /**
3988 * @hide
3989 */
Narayan Kamath695cf722017-12-21 18:32:47 +00003990 public static void noteWakeupAlarm(PendingIntent ps, WorkSource workSource, int sourceUid,
3991 String sourcePkg, String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003992 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00003993 getService().noteWakeupAlarm((ps != null) ? ps.getTarget() : null, workSource,
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07003994 sourceUid, sourcePkg, tag);
3995 } catch (RemoteException ex) {
3996 }
3997 }
3998
3999 /**
4000 * @hide
4001 */
Narayan Kamath695cf722017-12-21 18:32:47 +00004002 public static void noteAlarmStart(PendingIntent ps, WorkSource workSource, int sourceUid,
4003 String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004004 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00004005 getService().noteAlarmStart((ps != null) ? ps.getTarget() : null, workSource,
4006 sourceUid, tag);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004007 } catch (RemoteException ex) {
4008 }
4009 }
4010
Narayan Kamath695cf722017-12-21 18:32:47 +00004011
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004012 /**
4013 * @hide
4014 */
Narayan Kamath695cf722017-12-21 18:32:47 +00004015 public static void noteAlarmFinish(PendingIntent ps, WorkSource workSource, int sourceUid,
4016 String tag) {
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004017 try {
Narayan Kamath695cf722017-12-21 18:32:47 +00004018 getService().noteAlarmFinish((ps != null) ? ps.getTarget() : null, workSource,
4019 sourceUid, tag);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07004020 } catch (RemoteException ex) {
4021 }
4022 }
4023
4024 /**
4025 * @hide
4026 */
4027 public static IActivityManager getService() {
4028 return IActivityManagerSingleton.get();
4029 }
4030
4031 private static final Singleton<IActivityManager> IActivityManagerSingleton =
4032 new Singleton<IActivityManager>() {
4033 @Override
4034 protected IActivityManager create() {
4035 final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE);
4036 final IActivityManager am = IActivityManager.Stub.asInterface(b);
4037 return am;
4038 }
4039 };
4040
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004041 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) {
4042 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":");
4043 IBinder service = ServiceManager.checkService(name);
4044 if (service == null) {
4045 pw.println(" (Service not found)");
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004046 pw.flush();
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004047 return;
4048 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004049 pw.flush();
4050 if (service instanceof Binder) {
4051 // If this is a local object, it doesn't make sense to do an async dump with it,
4052 // just directly dump.
4053 try {
4054 service.dump(fd, args);
4055 } catch (Throwable e) {
4056 pw.println("Failure dumping service:");
4057 e.printStackTrace(pw);
4058 pw.flush();
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004059 }
Dianne Hackbornc81983a2017-10-20 16:16:32 -07004060 } else {
4061 // Otherwise, it is remote, do the dump asynchronously to avoid blocking.
4062 TransferPipe tp = null;
4063 try {
4064 pw.flush();
4065 tp = new TransferPipe();
4066 tp.setBufferPrefix(" ");
4067 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args);
4068 tp.go(fd, 10000);
4069 } catch (Throwable e) {
4070 if (tp != null) {
4071 tp.kill();
4072 }
4073 pw.println("Failure dumping service:");
4074 e.printStackTrace(pw);
4075 }
Dianne Hackborncbfd23e2013-06-11 14:26:53 -07004076 }
4077 }
Craig Mautneraea74a52014-03-08 14:23:10 -08004078
4079 /**
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004080 * Request that the system start watching for the calling process to exceed a pss
Dianne Hackborn17f69352015-07-17 18:04:14 -07004081 * size as given here. Once called, the system will look for any occasions where it
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004082 * sees the associated process with a larger pss size and, when this happens, automatically
4083 * pull a heap dump from it and allow the user to share the data. Note that this request
4084 * continues running even if the process is killed and restarted. To remove the watch,
4085 * use {@link #clearWatchHeapLimit()}.
4086 *
Dianne Hackbornece0f4f2015-06-11 13:29:01 -07004087 * <p>This API only work if the calling process has been marked as
4088 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable
4089 * (userdebug or eng) build.</p>
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004090 *
4091 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly
4092 * handle heap limit reports themselves.</p>
4093 *
4094 * @param pssSize The size in bytes to set the limit at.
4095 */
4096 public void setWatchHeapLimit(long pssSize) {
4097 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004098 getService().setDumpHeapDebugLimit(null, 0, pssSize,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004099 mContext.getPackageName());
4100 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004101 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004102 }
4103 }
4104
4105 /**
4106 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}.
4107 * If your package has an activity handling this action, it will be launched with the
4108 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to
4109 * match the activty must support this action and a MIME type of "*&#47;*".
4110 */
4111 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT";
4112
4113 /**
4114 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}.
4115 */
4116 public void clearWatchHeapLimit() {
4117 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004118 getService().setDumpHeapDebugLimit(null, 0, 0, null);
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004119 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004120 throw e.rethrowFromSystemServer();
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07004121 }
4122 }
4123
4124 /**
Jason Monk386c94f2014-07-14 16:42:24 -04004125 * Return whether currently in lock task mode. When in this mode
4126 * no new tasks can be created or switched to.
4127 *
4128 * @see Activity#startLockTask()
Benjamin Franz43261142015-02-11 15:59:44 +00004129 *
4130 * @deprecated Use {@link #getLockTaskModeState} instead.
Craig Mautneraea74a52014-03-08 14:23:10 -08004131 */
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -07004132 @Deprecated
Craig Mautneraea74a52014-03-08 14:23:10 -08004133 public boolean isInLockTaskMode() {
Benjamin Franz43261142015-02-11 15:59:44 +00004134 return getLockTaskModeState() != LOCK_TASK_MODE_NONE;
4135 }
4136
4137 /**
4138 * Return the current state of task locking. The three possible outcomes
4139 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED}
4140 * and {@link #LOCK_TASK_MODE_PINNED}.
4141 *
4142 * @see Activity#startLockTask()
4143 */
4144 public int getLockTaskModeState() {
Craig Mautneraea74a52014-03-08 14:23:10 -08004145 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004146 return getService().getLockTaskModeState();
Craig Mautneraea74a52014-03-08 14:23:10 -08004147 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004148 throw e.rethrowFromSystemServer();
Craig Mautneraea74a52014-03-08 14:23:10 -08004149 }
4150 }
Winson Chung1147c402014-05-14 11:05:00 -07004151
4152 /**
Srinath Sridharane535a582016-06-27 18:13:47 -07004153 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one
4154 * thread can be a VR thread in a process at a time, and that thread may be subject to
4155 * restrictions on the amount of time it can run.
4156 *
Craig Donnerdc4796c2017-03-08 09:51:47 -08004157 * If persistent VR mode is set, whatever thread has been granted aggressive scheduling via this
4158 * method will return to normal operation, and calling this method will do nothing while
4159 * persistent VR mode is enabled.
4160 *
Srinath Sridharane535a582016-06-27 18:13:47 -07004161 * To reset the VR thread for an application, a tid of 0 can be passed.
4162 *
4163 * @see android.os.Process#myTid()
4164 * @param tid tid of the VR thread
4165 */
4166 public static void setVrThread(int tid) {
4167 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -08004168 getService().setVrThread(tid);
Srinath Sridharane535a582016-06-27 18:13:47 -07004169 } catch (RemoteException e) {
4170 // pass
4171 }
4172 }
4173
4174 /**
Craig Donnerdc4796c2017-03-08 09:51:47 -08004175 * Enable more aggressive scheduling for latency-sensitive low-runtime VR threads that persist
Jeff Sharkey910e0812017-04-21 16:29:27 -06004176 * beyond a single process. Only one thread can be a
Craig Donnerdc4796c2017-03-08 09:51:47 -08004177 * persistent VR thread at a time, and that thread may be subject to restrictions on the amount
4178 * of time it can run. Calling this method will disable aggressive scheduling for non-persistent
4179 * VR threads set via {@link #setVrThread}. If persistent VR mode is disabled then the
4180 * persistent VR thread loses its new scheduling priority; this method must be called again to
4181 * set the persistent thread.
4182 *
4183 * To reset the persistent VR thread, a tid of 0 can be passed.
4184 *
4185 * @see android.os.Process#myTid()
4186 * @param tid tid of the VR thread
4187 * @hide
4188 */
4189 @RequiresPermission(Manifest.permission.RESTRICTED_VR_ACCESS)
4190 public static void setPersistentVrThread(int tid) {
4191 try {
4192 getService().setPersistentVrThread(tid);
4193 } catch (RemoteException e) {
4194 // pass
4195 }
4196 }
4197
4198 /**
Winson Chung1147c402014-05-14 11:05:00 -07004199 * The AppTask allows you to manage your own application's tasks.
4200 * See {@link android.app.ActivityManager#getAppTasks()}
4201 */
4202 public static class AppTask {
4203 private IAppTask mAppTaskImpl;
4204
4205 /** @hide */
4206 public AppTask(IAppTask task) {
4207 mAppTaskImpl = task;
4208 }
4209
4210 /**
4211 * Finishes all activities in this task and removes it from the recent tasks list.
4212 */
4213 public void finishAndRemoveTask() {
4214 try {
4215 mAppTaskImpl.finishAndRemoveTask();
4216 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004217 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004218 }
4219 }
4220
4221 /**
4222 * Get the RecentTaskInfo associated with this task.
4223 *
4224 * @return The RecentTaskInfo for this task, or null if the task no longer exists.
4225 */
4226 public RecentTaskInfo getTaskInfo() {
4227 try {
4228 return mAppTaskImpl.getTaskInfo();
4229 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004230 throw e.rethrowFromSystemServer();
Winson Chung1147c402014-05-14 11:05:00 -07004231 }
4232 }
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004233
4234 /**
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004235 * Bring this task to the foreground. If it contains activities, they will be
4236 * brought to the foreground with it and their instances re-created if needed.
4237 * If it doesn't contain activities, the root activity of the task will be
4238 * re-launched.
4239 */
4240 public void moveToFront() {
4241 try {
4242 mAppTaskImpl.moveToFront();
4243 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004244 throw e.rethrowFromSystemServer();
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004245 }
4246 }
4247
4248 /**
4249 * Start an activity in this task. Brings the task to the foreground. If this task
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004250 * is not currently active (that is, its id < 0), then a new activity for the given
4251 * Intent will be launched as the root of the task and the task brought to the
4252 * foreground. Otherwise, if this task is currently active and the Intent does not specify
4253 * an activity to launch in a new task, then a new activity for the given Intent will
4254 * be launched on top of the task and the task brought to the foreground. If this
4255 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK}
4256 * or would otherwise be launched in to a new task, then the activity not launched but
4257 * this task be brought to the foreground and a new intent delivered to the top
4258 * activity if appropriate.
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004259 *
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004260 * <p>In other words, you generally want to use an Intent here that does not specify
4261 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT},
4262 * and let the system do the right thing.</p>
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004263 *
4264 * @param intent The Intent describing the new activity to be launched on the task.
4265 * @param options Optional launch options.
Dianne Hackborna4e102e2014-09-04 22:52:27 -07004266 *
4267 * @see Activity#startActivity(android.content.Intent, android.os.Bundle)
Dianne Hackborn89ad4562014-08-24 16:45:38 -07004268 */
4269 public void startActivity(Context context, Intent intent, Bundle options) {
4270 ActivityThread thread = ActivityThread.currentActivityThread();
4271 thread.getInstrumentation().execStartActivityFromAppTask(context,
4272 thread.getApplicationThread(), mAppTaskImpl, intent, options);
4273 }
4274
4275 /**
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004276 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root
4277 * Intent of this AppTask.
4278 *
4279 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will
4280 * be set; otherwise, it will be cleared.
4281 */
4282 public void setExcludeFromRecents(boolean exclude) {
4283 try {
4284 mAppTaskImpl.setExcludeFromRecents(exclude);
4285 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07004286 throw e.rethrowFromSystemServer();
Dianne Hackbornaec68bb2014-08-20 15:25:13 -07004287 }
4288 }
Winson Chung1147c402014-05-14 11:05:00 -07004289 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004290}